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