91bddb35678434007f741b4526ed3f0f5b5decd5
[sitara-epos/sitara-epos-kernel.git] / sound / soc / davinci / davinci-evm.c
1 /*
2  * ASoC driver for TI DAVINCI EVM platform
3  *
4  * Author:      Vladimir Barinov, <vbarinov@embeddedalley.com>
5  * Copyright:   (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/timer.h>
15 #include <linux/interrupt.h>
16 #include <linux/platform_device.h>
17 #include <linux/i2c.h>
18 #include <sound/core.h>
19 #include <sound/pcm.h>
20 #include <sound/soc.h>
22 #include <asm/dma.h>
23 #include <asm/mach-types.h>
25 #include <asm/hardware/asp.h>
26 #include <mach/edma.h>
27 #include <mach/mux.h>
29 #include "davinci-pcm.h"
30 #include "davinci-i2s.h"
31 #include "davinci-mcasp.h"
33 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
34                 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
35 static int evm_hw_params(struct snd_pcm_substream *substream,
36                          struct snd_pcm_hw_params *params)
37 {
38         struct snd_soc_pcm_runtime *rtd = substream->private_data;
39         struct snd_soc_dai *codec_dai = rtd->codec_dai;
40         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
41         int ret = 0;
42         unsigned sysclk;
44         /* ASP1 on DM355 EVM is clocked by an external oscillator */
45         if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
46             machine_is_davinci_dm365_evm())
47                 sysclk = 27000000;
49         /* ASP0 in DM6446 EVM is clocked by U55, as configured by
50          * board-dm644x-evm.c using GPIOs from U18.  There are six
51          * options; here we "know" we use a 48 KHz sample rate.
52          */
53         else if (machine_is_davinci_evm())
54                 sysclk = 12288000;
56         else if (machine_is_davinci_da830_evm() ||
57                                 machine_is_davinci_da850_evm())
58                 sysclk = 24576000;
60         else
61                 return -EINVAL;
63         /* set codec DAI configuration */
64         ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
65         if (ret < 0)
66                 return ret;
68         /* set cpu DAI configuration */
69         ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
70         if (ret < 0)
71                 return ret;
73         /* set the codec system clock */
74         ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
75         if (ret < 0)
76                 return ret;
78         return 0;
79 }
81 static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
82                                 struct snd_pcm_hw_params *params)
83 {
84         struct snd_soc_pcm_runtime *rtd = substream->private_data;
85         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
87         /* set cpu DAI configuration */
88         return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
89 }
91 static struct snd_soc_ops evm_ops = {
92         .hw_params = evm_hw_params,
93 };
95 static struct snd_soc_ops evm_spdif_ops = {
96         .hw_params = evm_spdif_hw_params,
97 };
99 /* davinci-evm machine dapm widgets */
100 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
101         SND_SOC_DAPM_HP("Headphone Jack", NULL),
102         SND_SOC_DAPM_LINE("Line Out", NULL),
103         SND_SOC_DAPM_MIC("Mic Jack", NULL),
104         SND_SOC_DAPM_LINE("Line In", NULL),
105 };
107 /* davinci-evm machine audio_mapnections to the codec pins */
108 static const struct snd_soc_dapm_route audio_map[] = {
109         /* Headphone connected to HPLOUT, HPROUT */
110         {"Headphone Jack", NULL, "HPLOUT"},
111         {"Headphone Jack", NULL, "HPROUT"},
113         /* Line Out connected to LLOUT, RLOUT */
114         {"Line Out", NULL, "LLOUT"},
115         {"Line Out", NULL, "RLOUT"},
117         /* Mic connected to (MIC3L | MIC3R) */
118         {"MIC3L", NULL, "Mic Bias 2V"},
119         {"MIC3R", NULL, "Mic Bias 2V"},
120         {"Mic Bias 2V", NULL, "Mic Jack"},
122         /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
123         {"LINE1L", NULL, "Line In"},
124         {"LINE2L", NULL, "Line In"},
125         {"LINE1R", NULL, "Line In"},
126         {"LINE2R", NULL, "Line In"},
127 };
129 /* Logic for a aic3x as connected on a davinci-evm */
130 static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
132         struct snd_soc_codec *codec = rtd->codec;
133         struct snd_soc_dapm_context *dapm = &codec->dapm;
135         /* Add davinci-evm specific widgets */
136         snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
137                                   ARRAY_SIZE(aic3x_dapm_widgets));
139         /* Set up davinci-evm specific audio path audio_map */
140         snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
142         /* not connected */
143         snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
144         snd_soc_dapm_disable_pin(dapm, "HPLCOM");
145         snd_soc_dapm_disable_pin(dapm, "HPRCOM");
147         /* always connected */
148         snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
149         snd_soc_dapm_enable_pin(dapm, "Line Out");
150         snd_soc_dapm_enable_pin(dapm, "Mic Jack");
151         snd_soc_dapm_enable_pin(dapm, "Line In");
153         return 0;
156 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
157 static struct snd_soc_dai_link dm6446_evm_dai = {
158         .name = "TLV320AIC3X",
159         .stream_name = "AIC3X",
160         .cpu_dai_name = "davinci-mcbsp",
161         .codec_dai_name = "tlv320aic3x-hifi",
162         .codec_name = "tlv320aic3x-codec.1-001b",
163         .platform_name = "davinci-pcm-audio",
164         .init = evm_aic3x_init,
165         .ops = &evm_ops,
166 };
168 static struct snd_soc_dai_link dm355_evm_dai = {
169         .name = "TLV320AIC3X",
170         .stream_name = "AIC3X",
171         .cpu_dai_name = "davinci-mcbsp.1",
172         .codec_dai_name = "tlv320aic3x-hifi",
173         .codec_name = "tlv320aic3x-codec.1-001b",
174         .platform_name = "davinci-pcm-audio",
175         .init = evm_aic3x_init,
176         .ops = &evm_ops,
177 };
179 static struct snd_soc_dai_link dm365_evm_dai = {
180 #ifdef CONFIG_SND_DM365_AIC3X_CODEC
181         .name = "TLV320AIC3X",
182         .stream_name = "AIC3X",
183         .cpu_dai_name = "davinci-mcbsp",
184         .codec_dai_name = "tlv320aic3x-hifi",
185         .init = evm_aic3x_init,
186         .codec_name = "tlv320aic3x-codec.1-0018",
187         .ops = &evm_ops,
188 #elif defined(CONFIG_SND_DM365_VOICE_CODEC)
189         .name = "Voice Codec - CQ93VC",
190         .stream_name = "CQ93",
191         .cpu_dai_name = "davinci-vcif",
192         .codec_dai_name = "cq93vc-hifi",
193         .codec_name = "cq93vc-codec",
194 #endif
195         .platform_name = "davinci-pcm-audio",
196 };
198 static struct snd_soc_dai_link dm6467_evm_dai[] = {
199         {
200                 .name = "TLV320AIC3X",
201                 .stream_name = "AIC3X",
202                 .cpu_dai_name= "davinci-mcasp.0",
203                 .codec_dai_name = "tlv320aic3x-hifi",
204                 .platform_name ="davinci-pcm-audio",
205                 .codec_name = "tlv320aic3x-codec.0-001a",
206                 .init = evm_aic3x_init,
207                 .ops = &evm_ops,
208         },
209         {
210                 .name = "McASP",
211                 .stream_name = "spdif",
212                 .cpu_dai_name= "davinci-mcasp.1",
213                 .codec_dai_name = "dit-hifi",
214                 .codec_name = "spdif_dit",
215                 .platform_name = "davinci-pcm-audio",
216                 .ops = &evm_spdif_ops,
217         },
218 };
220 static struct snd_soc_dai_link da830_evm_dai = {
221         .name = "TLV320AIC3X",
222         .stream_name = "AIC3X",
223         .cpu_dai_name = "davinci-mcasp.1",
224         .codec_dai_name = "tlv320aic3x-hifi",
225         .codec_name = "tlv320aic3x-codec.1-0018",
226         .platform_name = "davinci-pcm-audio",
227         .init = evm_aic3x_init,
228         .ops = &evm_ops,
229 };
231 static struct snd_soc_dai_link da850_evm_dai = {
232         .name = "TLV320AIC3X",
233         .stream_name = "AIC3X",
234         .cpu_dai_name= "davinci-mcasp.0",
235         .codec_dai_name = "tlv320aic3x-hifi",
236         .codec_name = "tlv320aic3x-codec.1-0018",
237         .platform_name = "davinci-pcm-audio",
238         .init = evm_aic3x_init,
239         .ops = &evm_ops,
240 };
242 /* davinci dm6446 evm audio machine driver */
243 static struct snd_soc_card dm6446_snd_soc_card_evm = {
244         .name = "DaVinci DM6446 EVM",
245         .dai_link = &dm6446_evm_dai,
246         .num_links = 1,
247 };
249 /* davinci dm355 evm audio machine driver */
250 static struct snd_soc_card dm355_snd_soc_card_evm = {
251         .name = "DaVinci DM355 EVM",
252         .dai_link = &dm355_evm_dai,
253         .num_links = 1,
254 };
256 /* davinci dm365 evm audio machine driver */
257 static struct snd_soc_card dm365_snd_soc_card_evm = {
258         .name = "DaVinci DM365 EVM",
259         .dai_link = &dm365_evm_dai,
260         .num_links = 1,
261 };
263 /* davinci dm6467 evm audio machine driver */
264 static struct snd_soc_card dm6467_snd_soc_card_evm = {
265         .name = "DaVinci DM6467 EVM",
266         .dai_link = dm6467_evm_dai,
267         .num_links = ARRAY_SIZE(dm6467_evm_dai),
268 };
270 static struct snd_soc_card da830_snd_soc_card = {
271         .name = "DA830/OMAP-L137 EVM",
272         .dai_link = &da830_evm_dai,
273         .num_links = 1,
274 };
276 static struct snd_soc_card da850_snd_soc_card = {
277         .name = "DA850/OMAP-L138 EVM",
278         .dai_link = &da850_evm_dai,
279         .num_links = 1,
280 };
282 static struct platform_device *evm_snd_device;
284 static int __init evm_init(void)
286         struct snd_soc_card *evm_snd_dev_data;
287         int index;
288         int ret;
290         if (machine_is_davinci_evm()) {
291                 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
292                 index = 0;
293         } else if (machine_is_davinci_dm355_evm()) {
294                 evm_snd_dev_data = &dm355_snd_soc_card_evm;
295                 index = 1;
296         } else if (machine_is_davinci_dm365_evm()) {
297                 evm_snd_dev_data = &dm365_snd_soc_card_evm;
298                 index = 0;
299         } else if (machine_is_davinci_dm6467_evm()) {
300                 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
301                 index = 0;
302         } else if (machine_is_davinci_da830_evm()) {
303                 evm_snd_dev_data = &da830_snd_soc_card;
304                 index = 1;
305         } else if (machine_is_davinci_da850_evm()) {
306                 evm_snd_dev_data = &da850_snd_soc_card;
307                 index = 0;
308         } else
309                 return -EINVAL;
311         evm_snd_device = platform_device_alloc("soc-audio", index);
312         if (!evm_snd_device)
313                 return -ENOMEM;
315         platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
316         ret = platform_device_add(evm_snd_device);
317         if (ret)
318                 platform_device_put(evm_snd_device);
320         return ret;
323 static void __exit evm_exit(void)
325         platform_device_unregister(evm_snd_device);
328 module_init(evm_init);
329 module_exit(evm_exit);
331 MODULE_AUTHOR("Vladimir Barinov");
332 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
333 MODULE_LICENSE("GPL");