2 * rk29_es8323.c -- SoC audio for rockchip
4 * Driver for rockchip es8323 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/es8323.h"
24 #include "card_info.h"
28 #ifdef CONFIG_MACH_RK_FAC
29 #include <plat/config.h>
30 extern int codec_type;
34 #define DBG(x...) printk(KERN_INFO x)
39 //static void *rk29_speaker = NULL;
41 static int rk29_hw_params(struct snd_pcm_substream *substream,
42 struct snd_pcm_hw_params *params)
44 struct snd_soc_pcm_runtime *rtd = substream->private_data;
45 struct snd_soc_dai *codec_dai = rtd->codec_dai;
46 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
47 unsigned int pll_out = 0, dai_fmt = rtd->card->dai_link->dai_fmt;
50 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
52 /* set codec DAI configuration */
53 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
55 printk("%s():failed to set the format for codec side\n", __FUNCTION__);
59 /* set cpu DAI configuration */
60 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
62 printk("%s():failed to set the format for cpu side\n", __FUNCTION__);
66 switch(params_rate(params)) {
80 DBG("Enter:%s, %d, Error rate=%d\n",__FUNCTION__,__LINE__,params_rate(params));
84 DBG("Enter:%s, %d, rate=%d\n",__FUNCTION__,__LINE__,params_rate(params));
86 if ((dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBS_CFS) {
87 snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
88 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
89 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
92 DBG("Enter:%s, %d, LRCK=%d\n",__FUNCTION__,__LINE__,(pll_out/4)/params_rate(params));
96 static const struct snd_soc_dapm_widget rk29_dapm_widgets[] = {
97 SND_SOC_DAPM_LINE("Audio Out", NULL),
98 SND_SOC_DAPM_LINE("Line in", NULL),
99 SND_SOC_DAPM_MIC("Micn", NULL),
100 SND_SOC_DAPM_MIC("Micp", NULL),
103 static const struct snd_soc_dapm_route audio_map[]= {
105 {"Audio Out", NULL, "LOUT1"},
106 {"Audio Out", NULL, "ROUT1"},
107 {"Line in", NULL, "RINPUT1"},
108 {"Line in", NULL, "LINPUT1"},
109 {"Micn", NULL, "RINPUT2"},
110 {"Micp", NULL, "LINPUT2"},
114 * Logic for a es8323 as connected on a rockchip board.
116 static int rk29_es8323_init(struct snd_soc_pcm_runtime *rtd)
118 struct snd_soc_dai *codec_dai = rtd->codec_dai;
119 struct snd_soc_codec *codec = rtd->codec;
120 struct snd_soc_dapm_context *dapm = &codec->dapm;
123 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
125 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
126 /*12000000*/11289600, SND_SOC_CLOCK_IN);
128 printk(KERN_ERR "Failed to set es8323 SYSCLK: %d\n", ret);
132 /* Add specific widgets */
134 snd_soc_dapm_new_controls(dapm, rk29_dapm_widgets,
135 ARRAY_SIZE(rk29_dapm_widgets));
136 //snd_soc_dapm_nc_pin(codec, "LOUT2");
137 //snd_soc_dapm_nc_pin(codec, "ROUT2");
139 /* Set up specific audio path audio_mapnects */
140 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
142 snd_soc_dapm_sync(dapm);
147 static struct snd_soc_ops rk29_ops = {
148 .hw_params = rk29_hw_params,
151 static struct snd_soc_dai_link rk29_dai = {
153 .stream_name = "ES8323 PCM",
154 .codec_dai_name = "ES8323 HiFi",
155 .init = rk29_es8323_init,
159 static struct snd_soc_card rockchip_es8323_snd_card = {
161 .dai_link = &rk29_dai,
165 static int rockchip_es8323_audio_probe(struct platform_device *pdev)
168 struct snd_soc_card *card = &rockchip_es8323_snd_card;
170 card->dev = &pdev->dev;
172 ret = rockchip_of_get_sound_card_info(card);
174 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
178 ret = snd_soc_register_card(card);
180 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
185 static int rockchip_es8323_audio_remove(struct platform_device *pdev)
187 struct snd_soc_card *card = platform_get_drvdata(pdev);
189 snd_soc_unregister_card(card);
195 static const struct of_device_id rockchip_es8323_of_match[] = {
196 { .compatible = "rockchip-es8323", },
199 MODULE_DEVICE_TABLE(of, rockchip_es8323_of_match);
200 #endif /* CONFIG_OF */
202 static struct platform_driver rockchip_es8323_audio_driver = {
204 .name = "rockchip-es8323",
205 .owner = THIS_MODULE,
206 .pm = &snd_soc_pm_ops,
207 .of_match_table = of_match_ptr(rockchip_es8323_of_match),
209 .probe = rockchip_es8323_audio_probe,
210 .remove = rockchip_es8323_audio_remove,
213 module_platform_driver(rockchip_es8323_audio_driver);
215 /* Module information */
216 MODULE_AUTHOR("rockchip");
217 MODULE_DESCRIPTION("ROCKCHIP i2s ASoC Interface");
218 MODULE_LICENSE("GPL");