2 * rk29_tlv320dac3100.c -- SoC audio for rockchip
4 * Driver for rockchip tlv320aic3100 audio
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
14 #include <linux/module.h>
15 #include <linux/device.h>
17 #include <linux/of_gpio.h>
18 #include <sound/core.h>
19 #include <sound/pcm.h>
20 #include <sound/soc.h>
21 #include <sound/soc-dapm.h>
23 #include "../codecs/tlv320aic3111.h"
24 #include "card_info.h"
29 #define AIC_DBG(x...) printk(KERN_INFO x)
31 #define AIC_DBG(x...) do { } while (0)
35 #define HP_DET_PIN RK29_PIN6_PA0
40 static int rk29_hw_params(struct snd_pcm_substream *substream,
41 struct snd_pcm_hw_params *params)
43 struct snd_soc_pcm_runtime *rtd = substream->private_data;
44 struct snd_soc_dai *codec_dai = rtd->codec_dai;
45 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
46 unsigned int pll_out = 0, dai_fmt = rtd->dai_link->dai_fmt;
49 AIC_DBG("Enter::%s----%d\n", __FUNCTION__, __LINE__);
51 /* set codec DAI configuration */
52 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
54 printk("%s():failed to set the format for codec side\n", __FUNCTION__);
58 /* set cpu DAI configuration */
59 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
61 printk("%s():failed to set the format for cpu side\n", __FUNCTION__);
65 switch(params_rate(params)) {
79 printk("Enter:%s, %d, Error rate=%d\n",__FUNCTION__,__LINE__,params_rate(params));
83 AIC_DBG("Enter:%s, %d, rate=%d, pll_out = %d\n",__FUNCTION__,__LINE__,params_rate(params), pll_out);
85 snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
86 snd_soc_dai_set_sysclk(codec_dai, 0, pll_out, SND_SOC_CLOCK_IN);
91 static const struct snd_soc_dapm_widget dac3100_dapm_widgets[] = {
92 /* SND_SOC_DAPM_LINE("Audio Out", NULL),
93 SND_SOC_DAPM_LINE("Line in", NULL),
94 SND_SOC_DAPM_MIC("Micn", NULL),
95 SND_SOC_DAPM_MIC("Micp", NULL),*/
98 static const struct snd_soc_dapm_route audio_map[]= {
99 /* {"Audio Out", NULL, "HPL"},
100 {"Audio Out", NULL, "HPR"},
101 {"Line in", NULL, "RINPUT1"},
102 {"Line in", NULL, "LINPUT1"},
103 {"Micn", NULL, "RINPUT2"},
104 {"Micp", NULL, "LINPUT2"},*/
108 * Logic for a tlv320dac3100 as connected on a rockchip board.
110 static int rk29_aic3111_init(struct snd_soc_pcm_runtime *rtd)
112 struct snd_soc_codec *codec = rtd->codec;
113 struct snd_soc_dapm_context *dapm = &codec->dapm;
115 AIC_DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
117 /* Add specific widgets */
118 snd_soc_dapm_new_controls(dapm, dac3100_dapm_widgets,
119 ARRAY_SIZE(dac3100_dapm_widgets));
121 /* Set up specific audio path audio_mapnects */
122 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
123 AIC_DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
124 snd_soc_dapm_nc_pin(dapm, "HPL");
125 AIC_DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
126 snd_soc_dapm_nc_pin(dapm, "HPR");
127 AIC_DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
128 snd_soc_dapm_sync(dapm);
129 AIC_DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
133 static struct snd_soc_ops rk29_ops = {
134 .hw_params = rk29_hw_params,
137 static struct snd_soc_dai_link rk29_dai = {
139 .stream_name = "AIC3111 PCM",
140 .codec_dai_name = "AIC3111 HiFi",
141 .init = rk29_aic3111_init,
145 static struct snd_soc_card rockchip_aic3111_snd_card = {
146 .name = "RK_AIC3111",
147 .dai_link = &rk29_dai,
151 static int rockchip_aic3111_audio_probe(struct platform_device *pdev)
154 struct snd_soc_card *card = &rockchip_aic3111_snd_card;
156 card->dev = &pdev->dev;
158 ret = rockchip_of_get_sound_card_info(card);
160 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
164 ret = snd_soc_register_card(card);
166 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
171 static int rockchip_aic3111_audio_remove(struct platform_device *pdev)
173 struct snd_soc_card *card = platform_get_drvdata(pdev);
175 snd_soc_unregister_card(card);
181 static const struct of_device_id rockchip_aic3111_of_match[] = {
182 { .compatible = "rockchip-aic3111", },
185 MODULE_DEVICE_TABLE(of, rockchip_aic3111_of_match);
186 #endif /* CONFIG_OF */
188 static struct platform_driver rockchip_aic3111_audio_driver = {
190 .name = "rockchip-aic3111",
191 .owner = THIS_MODULE,
192 .pm = &snd_soc_pm_ops,
193 .of_match_table = of_match_ptr(rockchip_aic3111_of_match),
195 .probe = rockchip_aic3111_audio_probe,
196 .remove = rockchip_aic3111_audio_remove,
199 module_platform_driver(rockchip_aic3111_audio_driver);
201 /* Module information */
202 MODULE_AUTHOR("rockchip");
203 MODULE_DESCRIPTION("ROCKCHIP i2s ASoC Interface");
204 MODULE_LICENSE("GPL");