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>
16 #include <sound/core.h>
17 #include <sound/pcm.h>
18 #include <sound/soc.h>
19 #include <sound/soc-dapm.h>
21 #include <mach/hardware.h>
22 #include "../codecs/rk3026_codec.h"
27 #define DBG(x...) printk(KERN_INFO x)
32 static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
33 SND_SOC_DAPM_MIC("Mic Jack", NULL),
34 SND_SOC_DAPM_MIC("Headset Jack", NULL),
35 SND_SOC_DAPM_SPK("Ext Spk", NULL),
36 SND_SOC_DAPM_HP("Headphone Jack", NULL),
39 static const struct snd_soc_dapm_route rk_audio_map[]={
41 /* Mic Jack --> MIC_IN*/
42 {"Mic Bias", NULL, "Mic Jack"},
43 {"MICP", NULL, "Mic Bias"},
44 {"MICN", NULL, "Mic Bias"},
47 {"Mic Bias", NULL, "Headset Jack"},
49 {"Ext Spk", NULL, "HPOUTR"},
50 {"Ext Spk", NULL, "HPOUTL"},
52 {"Headphone Jack", NULL, "HPOUTR"},
53 {"Headphone Jack", NULL, "HPOUTL"},
56 static const struct snd_kcontrol_new rk_controls[] = {
57 SOC_DAPM_PIN_SWITCH("Mic Jack"),
58 SOC_DAPM_PIN_SWITCH("Headset Jack"),
59 SOC_DAPM_PIN_SWITCH("Ext Spk"),
60 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
63 static int rk3026_init(struct snd_soc_pcm_runtime *rtd)
65 struct snd_soc_codec *codec = rtd->codec;
66 struct snd_soc_dapm_context *dapm = &codec->dapm;
68 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
70 snd_soc_add_codec_controls(codec, rk_controls,
71 ARRAY_SIZE(rk_controls));
73 /* Add specific widgets */
74 snd_soc_dapm_new_controls(dapm, rk_dapm_widgets,
75 ARRAY_SIZE(rk_dapm_widgets));
76 /* Set up specific audio path audio_mapnects */
77 snd_soc_dapm_add_routes(dapm, rk_audio_map, ARRAY_SIZE(rk_audio_map));
79 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
80 snd_soc_dapm_enable_pin(dapm, "Headset Jack");
81 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
82 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
84 snd_soc_dapm_sync(dapm);
89 static int rk_hifi_hw_params(struct snd_pcm_substream *substream,
90 struct snd_pcm_hw_params *params)
92 struct snd_soc_pcm_runtime *rtd = substream->private_data;
93 struct snd_soc_dai *codec_dai = rtd->codec_dai;
94 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
95 unsigned int pll_out = 0;
98 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
100 /* set codec DAI configuration */
101 #if defined (CONFIG_SND_RK_CODEC_SOC_SLAVE)
103 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
104 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
106 #if defined (CONFIG_SND_RK_CODEC_SOC_MASTER)
108 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
109 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM );
114 /* set cpu DAI configuration */
115 #if defined (CONFIG_SND_RK_CODEC_SOC_SLAVE)
116 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
117 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
119 #if defined (CONFIG_SND_RK_CODEC_SOC_MASTER)
120 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
121 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
126 switch(params_rate(params)) {
140 DBG("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
145 DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
147 /*Set the system clk for codec*/
148 ret = snd_soc_dai_set_sysclk(codec_dai, 0, pll_out, SND_SOC_CLOCK_IN);
150 DBG("rk_hifi_hw_params:failed to set the sysclk for codec side\n");
154 snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
155 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
156 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
158 DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
163 static int rk_voice_hw_params(struct snd_pcm_substream *substream,
164 struct snd_pcm_hw_params *params)
166 struct snd_soc_pcm_runtime *rtd = substream->private_data;
167 struct snd_soc_dai *codec_dai = rtd->codec_dai;
168 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
169 unsigned int pll_out = 0;
172 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
174 /* set codec DAI configuration */
175 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A |
176 SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS);
178 switch(params_rate(params)) {
192 DBG("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
197 /*Set the system clk for codec*/
198 ret = snd_soc_dai_set_sysclk(codec_dai, 0, pll_out, SND_SOC_CLOCK_IN);
201 printk("rk_voice_hw_params:failed to set the sysclk for codec side\n");
205 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
210 static struct snd_soc_ops rk3026_hifi_ops = {
211 .hw_params = rk_hifi_hw_params,
214 static struct snd_soc_ops rk3026_voice_ops = {
215 .hw_params = rk_voice_hw_params,
218 static struct snd_soc_dai_link rk_dai[] = {
220 .name = "RK3026 I2S1",
221 .stream_name = "RK3026 PCM",
222 .codec_name = "rk3026-codec",
223 .platform_name = "rockchip-audio",
224 #if defined(CONFIG_SND_RK_SOC_I2S_8CH)
225 .cpu_dai_name = "rk_i2s.0",
226 #elif defined(CONFIG_SND_RK_SOC_I2S_2CH)
227 .cpu_dai_name = "rk_i2s.1",
229 .codec_dai_name = "rk3026-hifi",
231 .ops = &rk3026_hifi_ops,
234 .name = "RK3026 I2S2",
235 .stream_name = "RK3026 PCM",
236 .codec_name = "rk3026-codec",
237 .platform_name = "rockchip-audio",
238 #if defined(CONFIG_SND_RK_SOC_I2S_8CH)
239 .cpu_dai_name = "rk_i2s.0",
240 #elif defined(CONFIG_SND_RK_SOC_I2S_2CH)
241 .cpu_dai_name = "rk_i2s.1",
243 .codec_dai_name = "rk3026-voice",
244 .ops = &rk3026_voice_ops,
248 static struct snd_soc_card snd_soc_card_rk = {
254 static struct platform_device *rk_snd_device;
256 static int __init audio_card_init(void)
260 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
262 rk_snd_device = platform_device_alloc("soc-audio", -1);
263 if (!rk_snd_device) {
264 printk("platform device allocation failed\n");
268 platform_set_drvdata(rk_snd_device, &snd_soc_card_rk);
269 ret = platform_device_add(rk_snd_device);
271 printk("platform device add failed\n");
273 platform_device_put(rk_snd_device);
280 static void __exit audio_card_exit(void)
282 platform_device_unregister(rk_snd_device);
285 module_init(audio_card_init);
286 module_exit(audio_card_exit);
287 /* Module information */
288 MODULE_AUTHOR("rockchip");
289 MODULE_DESCRIPTION("ROCKCHIP i2s ASoC Interface");
290 MODULE_LICENSE("GPL");