2 * rk_rk3026.c -- SoC audio for rockchip
4 * Driver for rockchip rk3026 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/rk3026_codec.h"
24 #include "card_info.h"
29 #define DBG(x...) printk(KERN_INFO x)
34 static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
35 SND_SOC_DAPM_MIC("Mic Jack", NULL),
36 SND_SOC_DAPM_MIC("Headset Jack", NULL),
37 SND_SOC_DAPM_SPK("Ext Spk", NULL),
38 SND_SOC_DAPM_HP("Headphone Jack", NULL),
41 static const struct snd_soc_dapm_route rk_audio_map[]={
43 /* Mic Jack --> MIC_IN*/
44 {"Mic Bias", NULL, "Mic Jack"},
45 {"MICP", NULL, "Mic Bias"},
46 {"MICN", NULL, "Mic Bias"},
49 {"Mic Bias", NULL, "Headset Jack"},
51 {"Ext Spk", NULL, "HPOUTR"},
52 {"Ext Spk", NULL, "HPOUTL"},
54 {"Headphone Jack", NULL, "HPOUTR"},
55 {"Headphone Jack", NULL, "HPOUTL"},
58 static const struct snd_kcontrol_new rk_controls[] = {
59 SOC_DAPM_PIN_SWITCH("Mic Jack"),
60 SOC_DAPM_PIN_SWITCH("Headset Jack"),
61 SOC_DAPM_PIN_SWITCH("Ext Spk"),
62 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
65 static int rk3026_init(struct snd_soc_pcm_runtime *rtd)
67 struct snd_soc_codec *codec = rtd->codec;
68 struct snd_soc_dapm_context *dapm = &codec->dapm;
70 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
72 mutex_lock(&dapm->card->dapm_mutex);
74 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
75 snd_soc_dapm_enable_pin(dapm, "Headset Jack");
76 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
77 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
79 mutex_unlock(&dapm->card->dapm_mutex);
81 snd_soc_dapm_sync(dapm);
86 static int rk_hifi_hw_params(struct snd_pcm_substream *substream,
87 struct snd_pcm_hw_params *params)
89 struct snd_soc_pcm_runtime *rtd = substream->private_data;
90 struct snd_soc_dai *codec_dai = rtd->codec_dai;
91 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
92 unsigned int pll_out = 0, dai_fmt = rtd->dai_link->dai_fmt;
95 DBG("Enter::%s----%d\n", __FUNCTION__, __LINE__);
97 /* set codec DAI configuration */
98 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
100 printk("%s():failed to set the format for codec side\n", __FUNCTION__);
104 /* set cpu DAI configuration */
105 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
107 printk("%s():failed to set the format for cpu side\n", __FUNCTION__);
111 switch(params_rate(params)) {
125 DBG("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
130 DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
132 /*Set the system clk for codec*/
133 ret = snd_soc_dai_set_sysclk(codec_dai, 0, pll_out, SND_SOC_CLOCK_IN);
135 DBG("rk_hifi_hw_params:failed to set the sysclk for codec side\n");
139 snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
140 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
141 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
143 DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
148 static int rk_voice_hw_params(struct snd_pcm_substream *substream,
149 struct snd_pcm_hw_params *params)
151 struct snd_soc_pcm_runtime *rtd = substream->private_data;
152 struct snd_soc_dai *codec_dai = rtd->codec_dai;
153 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
154 unsigned int pll_out = 0, dai_fmt = rtd->dai_link->dai_fmt;
157 DBG("Enter::%s----%d\n", __FUNCTION__, __LINE__);
159 /* set codec DAI configuration */
160 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
162 printk("%s():failed to set the format for codec side\n", __FUNCTION__);
166 /* set codec DAI configuration */
167 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A |
168 SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS);
170 switch(params_rate(params)) {
184 DBG("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
189 /*Set the system clk for codec*/
190 ret = snd_soc_dai_set_sysclk(codec_dai, 0, pll_out, SND_SOC_CLOCK_IN);
193 printk("rk_voice_hw_params:failed to set the sysclk for codec side\n");
197 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
202 static struct snd_soc_ops rk3026_hifi_ops = {
203 .hw_params = rk_hifi_hw_params,
206 static struct snd_soc_ops rk3026_voice_ops = {
207 .hw_params = rk_voice_hw_params,
210 static struct snd_soc_dai_link rk_dai[] = {
212 .name = "RK3026 I2S1",
213 .stream_name = "RK3026 PCM",
214 .codec_dai_name = "rk3026-hifi",
216 .ops = &rk3026_hifi_ops,
219 .name = "RK3026 I2S2",
220 .stream_name = "RK3026 PCM",
221 .codec_dai_name = "rk3026-voice",
222 .ops = &rk3026_voice_ops,
226 static struct snd_soc_card rockchip_rk3026_snd_card = {
230 .controls = rk_controls,
231 .num_controls = ARRAY_SIZE(rk_controls),
232 .dapm_widgets = rk_dapm_widgets,
233 .num_dapm_widgets = ARRAY_SIZE(rk_dapm_widgets),
234 .dapm_routes = rk_audio_map,
235 .num_dapm_routes = ARRAY_SIZE(rk_audio_map),
238 static int rockchip_rk3026_audio_probe(struct platform_device *pdev)
241 struct snd_soc_card *card = &rockchip_rk3026_snd_card;
243 card->dev = &pdev->dev;
245 ret = rockchip_of_get_sound_card_info(card);
247 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
251 ret = snd_soc_register_card(card);
253 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
258 static int rockchip_rk3026_audio_remove(struct platform_device *pdev)
260 struct snd_soc_card *card = platform_get_drvdata(pdev);
262 snd_soc_unregister_card(card);
268 static const struct of_device_id rockchip_rk3026_of_match[] = {
269 { .compatible = "rockchip-rk3026", },
272 MODULE_DEVICE_TABLE(of, rockchip_rk3026_of_match);
273 #endif /* CONFIG_OF */
275 static struct platform_driver rockchip_rk3026_audio_driver = {
277 .name = "rockchip-rk3026",
278 .owner = THIS_MODULE,
279 .pm = &snd_soc_pm_ops,
280 .of_match_table = of_match_ptr(rockchip_rk3026_of_match),
282 .probe = rockchip_rk3026_audio_probe,
283 .remove = rockchip_rk3026_audio_remove,
286 module_platform_driver(rockchip_rk3026_audio_driver);
288 /* Module information */
289 MODULE_AUTHOR("rockchip");
290 MODULE_DESCRIPTION("ROCKCHIP i2s ASoC Interface");
291 MODULE_LICENSE("GPL");