Merge branch 'core-futexes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.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  */
11
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>
21 #include <sound/soc-dapm.h>
22
23 #include <asm/dma.h>
24 #include <asm/mach-types.h>
25
26 #include <mach/asp.h>
27 #include <mach/edma.h>
28 #include <mach/mux.h>
29
30 #include "../codecs/tlv320aic3x.h"
31 #include "davinci-pcm.h"
32 #include "davinci-i2s.h"
33 #include "davinci-mcasp.h"
34
35 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
36                 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
37 static int evm_hw_params(struct snd_pcm_substream *substream,
38                          struct snd_pcm_hw_params *params)
39 {
40         struct snd_soc_pcm_runtime *rtd = substream->private_data;
41         struct snd_soc_dai *codec_dai = rtd->codec_dai;
42         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
43         int ret = 0;
44         unsigned sysclk;
45
46         /* ASP1 on DM355 EVM is clocked by an external oscillator */
47         if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
48             machine_is_davinci_dm365_evm())
49                 sysclk = 27000000;
50
51         /* ASP0 in DM6446 EVM is clocked by U55, as configured by
52          * board-dm644x-evm.c using GPIOs from U18.  There are six
53          * options; here we "know" we use a 48 KHz sample rate.
54          */
55         else if (machine_is_davinci_evm())
56                 sysclk = 12288000;
57
58         else if (machine_is_davinci_da830_evm() ||
59                                 machine_is_davinci_da850_evm())
60                 sysclk = 24576000;
61
62         else
63                 return -EINVAL;
64
65         /* set codec DAI configuration */
66         ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
67         if (ret < 0)
68                 return ret;
69
70         /* set cpu DAI configuration */
71         ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
72         if (ret < 0)
73                 return ret;
74
75         /* set the codec system clock */
76         ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
77         if (ret < 0)
78                 return ret;
79
80         return 0;
81 }
82
83 static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
84                                 struct snd_pcm_hw_params *params)
85 {
86         struct snd_soc_pcm_runtime *rtd = substream->private_data;
87         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
88
89         /* set cpu DAI configuration */
90         return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
91 }
92
93 static struct snd_soc_ops evm_ops = {
94         .hw_params = evm_hw_params,
95 };
96
97 static struct snd_soc_ops evm_spdif_ops = {
98         .hw_params = evm_spdif_hw_params,
99 };
100
101 /* davinci-evm machine dapm widgets */
102 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
103         SND_SOC_DAPM_HP("Headphone Jack", NULL),
104         SND_SOC_DAPM_LINE("Line Out", NULL),
105         SND_SOC_DAPM_MIC("Mic Jack", NULL),
106         SND_SOC_DAPM_LINE("Line In", NULL),
107 };
108
109 /* davinci-evm machine audio_mapnections to the codec pins */
110 static const struct snd_soc_dapm_route audio_map[] = {
111         /* Headphone connected to HPLOUT, HPROUT */
112         {"Headphone Jack", NULL, "HPLOUT"},
113         {"Headphone Jack", NULL, "HPROUT"},
114
115         /* Line Out connected to LLOUT, RLOUT */
116         {"Line Out", NULL, "LLOUT"},
117         {"Line Out", NULL, "RLOUT"},
118
119         /* Mic connected to (MIC3L | MIC3R) */
120         {"MIC3L", NULL, "Mic Bias 2V"},
121         {"MIC3R", NULL, "Mic Bias 2V"},
122         {"Mic Bias 2V", NULL, "Mic Jack"},
123
124         /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
125         {"LINE1L", NULL, "Line In"},
126         {"LINE2L", NULL, "Line In"},
127         {"LINE1R", NULL, "Line In"},
128         {"LINE2R", NULL, "Line In"},
129 };
130
131 /* Logic for a aic3x as connected on a davinci-evm */
132 static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
133 {
134         struct snd_soc_codec *codec = rtd->codec;
135
136         /* Add davinci-evm specific widgets */
137         snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
138                                   ARRAY_SIZE(aic3x_dapm_widgets));
139
140         /* Set up davinci-evm specific audio path audio_map */
141         snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
142
143         /* not connected */
144         snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
145         snd_soc_dapm_disable_pin(codec, "HPLCOM");
146         snd_soc_dapm_disable_pin(codec, "HPRCOM");
147
148         /* always connected */
149         snd_soc_dapm_enable_pin(codec, "Headphone Jack");
150         snd_soc_dapm_enable_pin(codec, "Line Out");
151         snd_soc_dapm_enable_pin(codec, "Mic Jack");
152         snd_soc_dapm_enable_pin(codec, "Line In");
153
154         snd_soc_dapm_sync(codec);
155
156         return 0;
157 }
158
159 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
160 static struct snd_soc_dai_link dm6446_evm_dai = {
161         .name = "TLV320AIC3X",
162         .stream_name = "AIC3X",
163         .cpu_dai_name = "davinci-mcbsp",
164         .codec_dai_name = "tlv320aic3x-hifi",
165         .codec_name = "tlv320aic3x-codec.1-001b",
166         .platform_name = "davinci-pcm-audio",
167         .init = evm_aic3x_init,
168         .ops = &evm_ops,
169 };
170
171 static struct snd_soc_dai_link dm355_evm_dai = {
172         .name = "TLV320AIC3X",
173         .stream_name = "AIC3X",
174         .cpu_dai_name = "davinci-mcbsp.1",
175         .codec_dai_name = "tlv320aic3x-hifi",
176         .codec_name = "tlv320aic3x-codec.1-001b",
177         .platform_name = "davinci-pcm-audio",
178         .init = evm_aic3x_init,
179         .ops = &evm_ops,
180 };
181
182 static struct snd_soc_dai_link dm365_evm_dai = {
183 #ifdef CONFIG_SND_DM365_AIC3X_CODEC
184         .name = "TLV320AIC3X",
185         .stream_name = "AIC3X",
186         .cpu_dai_name = "davinci-mcbsp",
187         .codec_dai_name = "tlv320aic3x-hifi",
188         .init = evm_aic3x_init,
189         .codec_name = "tlv320aic3x-codec.1-0018",
190         .ops = &evm_ops,
191 #elif defined(CONFIG_SND_DM365_VOICE_CODEC)
192         .name = "Voice Codec - CQ93VC",
193         .stream_name = "CQ93",
194         .cpu_dai_name = "davinci-vcif",
195         .codec_dai_name = "cq93vc-hifi",
196         .codec_name = "cq93vc-codec",
197 #endif
198         .platform_name = "davinci-pcm-audio",
199 };
200
201 static struct snd_soc_dai_link dm6467_evm_dai[] = {
202         {
203                 .name = "TLV320AIC3X",
204                 .stream_name = "AIC3X",
205                 .cpu_dai_name= "davinci-mcasp.0",
206                 .codec_dai_name = "tlv320aic3x-hifi",
207                 .platform_name ="davinci-pcm-audio",
208                 .codec_name = "tlv320aic3x-codec.0-001a",
209                 .init = evm_aic3x_init,
210                 .ops = &evm_ops,
211         },
212         {
213                 .name = "McASP",
214                 .stream_name = "spdif",
215                 .cpu_dai_name= "davinci-mcasp.1",
216                 .codec_dai_name = "dit-hifi",
217                 .codec_name = "spdif_dit",
218                 .platform_name = "davinci-pcm-audio",
219                 .ops = &evm_spdif_ops,
220         },
221 };
222 static struct snd_soc_dai_link da8xx_evm_dai = {
223         .name = "TLV320AIC3X",
224         .stream_name = "AIC3X",
225         .cpu_dai_name= "davinci-mcasp.0",
226         .codec_dai_name = "tlv320aic3x-hifi",
227         .codec_name = "tlv320aic3x-codec.0-001a",
228         .platform_name = "davinci-pcm-audio",
229         .init = evm_aic3x_init,
230         .ops = &evm_ops,
231 };
232
233 /* davinci dm6446 evm audio machine driver */
234 static struct snd_soc_card dm6446_snd_soc_card_evm = {
235         .name = "DaVinci DM6446 EVM",
236         .dai_link = &dm6446_evm_dai,
237         .num_links = 1,
238 };
239
240 /* davinci dm355 evm audio machine driver */
241 static struct snd_soc_card dm355_snd_soc_card_evm = {
242         .name = "DaVinci DM355 EVM",
243         .dai_link = &dm355_evm_dai,
244         .num_links = 1,
245 };
246
247 /* davinci dm365 evm audio machine driver */
248 static struct snd_soc_card dm365_snd_soc_card_evm = {
249         .name = "DaVinci DM365 EVM",
250         .dai_link = &dm365_evm_dai,
251         .num_links = 1,
252 };
253
254 /* davinci dm6467 evm audio machine driver */
255 static struct snd_soc_card dm6467_snd_soc_card_evm = {
256         .name = "DaVinci DM6467 EVM",
257         .dai_link = dm6467_evm_dai,
258         .num_links = ARRAY_SIZE(dm6467_evm_dai),
259 };
260
261 static struct snd_soc_card da830_snd_soc_card = {
262         .name = "DA830/OMAP-L137 EVM",
263         .dai_link = &da8xx_evm_dai,
264         .num_links = 1,
265 };
266
267 static struct snd_soc_card da850_snd_soc_card = {
268         .name = "DA850/OMAP-L138 EVM",
269         .dai_link = &da8xx_evm_dai,
270         .num_links = 1,
271 };
272
273 static struct platform_device *evm_snd_device;
274
275 static int __init evm_init(void)
276 {
277         struct snd_soc_card *evm_snd_dev_data;
278         int index;
279         int ret;
280
281         if (machine_is_davinci_evm()) {
282                 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
283                 index = 0;
284         } else if (machine_is_davinci_dm355_evm()) {
285                 evm_snd_dev_data = &dm355_snd_soc_card_evm;
286                 index = 1;
287         } else if (machine_is_davinci_dm365_evm()) {
288                 evm_snd_dev_data = &dm365_snd_soc_card_evm;
289                 index = 0;
290         } else if (machine_is_davinci_dm6467_evm()) {
291                 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
292                 index = 0;
293         } else if (machine_is_davinci_da830_evm()) {
294                 evm_snd_dev_data = &da830_snd_soc_card;
295                 index = 1;
296         } else if (machine_is_davinci_da850_evm()) {
297                 evm_snd_dev_data = &da850_snd_soc_card;
298                 index = 0;
299         } else
300                 return -EINVAL;
301
302         evm_snd_device = platform_device_alloc("soc-audio", index);
303         if (!evm_snd_device)
304                 return -ENOMEM;
305
306         platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
307         ret = platform_device_add(evm_snd_device);
308         if (ret)
309                 platform_device_put(evm_snd_device);
310
311         return ret;
312 }
313
314 static void __exit evm_exit(void)
315 {
316         platform_device_unregister(evm_snd_device);
317 }
318
319 module_init(evm_init);
320 module_exit(evm_exit);
321
322 MODULE_AUTHOR("Vladimir Barinov");
323 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
324 MODULE_LICENSE("GPL");