2 * rk_rk3190.c -- SoC audio for rockchip
4 * Driver for rockchip rk3190 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>
22 #include "../codecs/rk3190_codec.h"
23 #include "card_info.h"
28 #define DBG(x...) printk(KERN_INFO x)
33 static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
34 SND_SOC_DAPM_MIC("Mic Jack", NULL),
35 SND_SOC_DAPM_MIC("Headset Jack", NULL),
36 SND_SOC_DAPM_SPK("Ext Spk", NULL),
37 SND_SOC_DAPM_HP("Headphone Jack", NULL),
40 static const struct snd_soc_dapm_route rk_audio_map[]={
42 /* Mic Jack --> MIC_IN*/
43 {"Mic Bias", NULL, "Mic Jack"},
44 {"MICP", NULL, "Mic Bias"},
45 {"MICN", NULL, "Mic Bias"},
48 {"Mic Bias", NULL, "Headset Jack"},
50 {"Ext Spk", NULL, "HPOUTR"},
51 {"Ext Spk", NULL, "HPOUTL"},
53 {"Headphone Jack", NULL, "HPOUTR"},
54 {"Headphone Jack", NULL, "HPOUTL"},
57 static const struct snd_kcontrol_new rk_controls[] = {
58 SOC_DAPM_PIN_SWITCH("Mic Jack"),
59 SOC_DAPM_PIN_SWITCH("Headset Jack"),
60 SOC_DAPM_PIN_SWITCH("Ext Spk"),
61 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
64 static int rk3190_init(struct snd_soc_pcm_runtime *rtd)
66 struct snd_soc_codec *codec = rtd->codec;
67 struct snd_soc_dapm_context *dapm = &codec->dapm;
69 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
74 static int rk_hifi_hw_params(struct snd_pcm_substream *substream,
75 struct snd_pcm_hw_params *params)
77 struct snd_soc_pcm_runtime *rtd = substream->private_data;
78 struct snd_soc_dai *codec_dai = rtd->codec_dai;
79 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80 unsigned int pll_out = 0, dai_fmt = rtd->dai_link->dai_fmt;
83 DBG("Enter::%s----%d\n", __FUNCTION__, __LINE__);
85 /* set codec DAI configuration */
86 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
88 printk("%s():failed to set the format for codec side\n", __FUNCTION__);
92 /* set cpu DAI configuration */
93 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
95 printk("%s():failed to set the format for cpu side\n", __FUNCTION__);
99 switch(params_rate(params)) {
113 DBG("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
118 DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
120 /*Set the system clk for codec*/
121 ret = snd_soc_dai_set_sysclk(codec_dai, 0, pll_out, SND_SOC_CLOCK_IN);
123 DBG("rk_hifi_hw_params:failed to set the sysclk for codec side\n");
127 snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
128 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
129 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
131 DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
136 static int rk_voice_hw_params(struct snd_pcm_substream *substream,
137 struct snd_pcm_hw_params *params)
139 struct snd_soc_pcm_runtime *rtd = substream->private_data;
140 struct snd_soc_dai *codec_dai = rtd->codec_dai;
141 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
142 unsigned int pll_out = 0, dai_fmt = rtd->dai_link->dai_fmt;
145 DBG("Enter::%s----%d\n", __FUNCTION__, __LINE__);
147 /* set codec DAI configuration */
148 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
150 printk("%s():failed to set the format for codec side\n", __FUNCTION__);
154 switch(params_rate(params)) {
168 DBG("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
173 /*Set the system clk for codec*/
174 ret = snd_soc_dai_set_sysclk(codec_dai, 0, pll_out, SND_SOC_CLOCK_IN);
177 printk("rk_voice_hw_params:failed to set the sysclk for codec side\n");
181 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
186 static struct snd_soc_ops rk3190_hifi_ops = {
187 .hw_params = rk_hifi_hw_params,
190 static struct snd_soc_ops rk3190_voice_ops = {
191 .hw_params = rk_voice_hw_params,
194 static struct snd_soc_dai_link rk_dai[] = {
196 .name = "RK3190 I2S1",
197 .stream_name = "RK3190 PCM",
198 .codec_dai_name = "rk3190-hifi",
200 .ops = &rk3190_hifi_ops,
203 .name = "RK3190 I2S2",
204 .stream_name = "RK3190 PCM",
205 .codec_dai_name = "rk3190-voice",
206 .ops = &rk3190_voice_ops,
210 static struct snd_soc_card rockchip_rk3190_snd_card = {
216 static int rockchip_rk3190_audio_probe(struct platform_device *pdev)
219 struct snd_soc_card *card = &rockchip_rk3190_snd_card;
221 card->dev = &pdev->dev;
223 ret = rockchip_of_get_sound_card_info(card);
225 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
229 ret = snd_soc_register_card(card);
231 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
236 static int rockchip_rk3190_audio_remove(struct platform_device *pdev)
238 struct snd_soc_card *card = platform_get_drvdata(pdev);
240 snd_soc_unregister_card(card);
246 static const struct of_device_id rockchip_rk3190_of_match[] = {
247 { .compatible = "rockchip-rk3190", },
250 MODULE_DEVICE_TABLE(of, rockchip_rk3190_of_match);
251 #endif /* CONFIG_OF */
253 static struct platform_driver rockchip_rk3190_audio_driver = {
255 .name = "rockchip-rk3190",
256 .owner = THIS_MODULE,
257 .pm = &snd_soc_pm_ops,
258 .of_match_table = of_match_ptr(rockchip_rk3190_of_match),
260 .probe = rockchip_rk3190_audio_probe,
261 .remove = rockchip_rk3190_audio_remove,
264 module_platform_driver(rockchip_rk3190_audio_driver);
266 /* Module information */
267 MODULE_AUTHOR("rockchip");
268 MODULE_DESCRIPTION("ROCKCHIP i2s ASoC Interface");
269 MODULE_LICENSE("GPL");