a5a92124b6d53b9f3193604c742238c2172f1c32
[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 <sound/core.h>
18 #include <sound/pcm.h>
19 #include <sound/soc.h>
20 #include <sound/soc-dapm.h>
21
22 #include <asm/dma.h>
23 #include <asm/mach-types.h>
24
25 #include <mach/asp.h>
26 #include <mach/edma.h>
27 #include <mach/mux.h>
28
29 #include "../codecs/tlv320aic3x.h"
30 #include "../codecs/spdif_transciever.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->dai->codec_dai;
42         struct snd_soc_dai *cpu_dai = rtd->dai->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                 sysclk = 27000000;
49
50         /* ASP0 in DM6446 EVM is clocked by U55, as configured by
51          * board-dm644x-evm.c using GPIOs from U18.  There are six
52          * options; here we "know" we use a 48 KHz sample rate.
53          */
54         else if (machine_is_davinci_evm())
55                 sysclk = 12288000;
56
57         else if (machine_is_davinci_da830_evm())
58                 sysclk = 24576000;
59
60         else
61                 return -EINVAL;
62
63         /* set codec DAI configuration */
64         ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
65         if (ret < 0)
66                 return ret;
67
68         /* set cpu DAI configuration */
69         ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
70         if (ret < 0)
71                 return ret;
72
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;
77
78         return 0;
79 }
80
81 static struct snd_soc_ops evm_ops = {
82         .hw_params = evm_hw_params,
83 };
84
85 /* davinci-evm machine dapm widgets */
86 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
87         SND_SOC_DAPM_HP("Headphone Jack", NULL),
88         SND_SOC_DAPM_LINE("Line Out", NULL),
89         SND_SOC_DAPM_MIC("Mic Jack", NULL),
90         SND_SOC_DAPM_LINE("Line In", NULL),
91 };
92
93 /* davinci-evm machine audio_mapnections to the codec pins */
94 static const struct snd_soc_dapm_route audio_map[] = {
95         /* Headphone connected to HPLOUT, HPROUT */
96         {"Headphone Jack", NULL, "HPLOUT"},
97         {"Headphone Jack", NULL, "HPROUT"},
98
99         /* Line Out connected to LLOUT, RLOUT */
100         {"Line Out", NULL, "LLOUT"},
101         {"Line Out", NULL, "RLOUT"},
102
103         /* Mic connected to (MIC3L | MIC3R) */
104         {"MIC3L", NULL, "Mic Bias 2V"},
105         {"MIC3R", NULL, "Mic Bias 2V"},
106         {"Mic Bias 2V", NULL, "Mic Jack"},
107
108         /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
109         {"LINE1L", NULL, "Line In"},
110         {"LINE2L", NULL, "Line In"},
111         {"LINE1R", NULL, "Line In"},
112         {"LINE2R", NULL, "Line In"},
113 };
114
115 /* Logic for a aic3x as connected on a davinci-evm */
116 static int evm_aic3x_init(struct snd_soc_codec *codec)
117 {
118         /* Add davinci-evm specific widgets */
119         snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
120                                   ARRAY_SIZE(aic3x_dapm_widgets));
121
122         /* Set up davinci-evm specific audio path audio_map */
123         snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
124
125         /* not connected */
126         snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
127         snd_soc_dapm_disable_pin(codec, "HPLCOM");
128         snd_soc_dapm_disable_pin(codec, "HPRCOM");
129
130         /* always connected */
131         snd_soc_dapm_enable_pin(codec, "Headphone Jack");
132         snd_soc_dapm_enable_pin(codec, "Line Out");
133         snd_soc_dapm_enable_pin(codec, "Mic Jack");
134         snd_soc_dapm_enable_pin(codec, "Line In");
135
136         snd_soc_dapm_sync(codec);
137
138         return 0;
139 }
140
141 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
142 static struct snd_soc_dai_link evm_dai = {
143         .name = "TLV320AIC3X",
144         .stream_name = "AIC3X",
145         .cpu_dai = &davinci_i2s_dai,
146         .codec_dai = &aic3x_dai,
147         .init = evm_aic3x_init,
148         .ops = &evm_ops,
149 };
150
151 static struct snd_soc_dai_link dm6467_evm_dai[] = {
152         {
153                 .name = "TLV320AIC3X",
154                 .stream_name = "AIC3X",
155                 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
156                 .codec_dai = &aic3x_dai,
157                 .init = evm_aic3x_init,
158                 .ops = &evm_ops,
159         },
160         {
161                 .name = "McASP",
162                 .stream_name = "spdif",
163                 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
164                 .codec_dai = &dit_stub_dai,
165                 .ops = &evm_ops,
166         },
167 };
168 static struct snd_soc_dai_link da830_evm_dai = {
169         .name = "TLV320AIC3X",
170         .stream_name = "AIC3X",
171         .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
172         .codec_dai = &aic3x_dai,
173         .init = evm_aic3x_init,
174         .ops = &evm_ops,
175 };
176
177 /* davinci-evm audio machine driver */
178 static struct snd_soc_card snd_soc_card_evm = {
179         .name = "DaVinci EVM",
180         .platform = &davinci_soc_platform,
181         .dai_link = &evm_dai,
182         .num_links = 1,
183 };
184
185 /* davinci dm6467 evm audio machine driver */
186 static struct snd_soc_card dm6467_snd_soc_card_evm = {
187         .name = "DaVinci DM6467 EVM",
188         .platform = &davinci_soc_platform,
189         .dai_link = dm6467_evm_dai,
190         .num_links = ARRAY_SIZE(dm6467_evm_dai),
191 };
192
193 static struct snd_soc_card da830_snd_soc_card = {
194         .name = "DA830 EVM",
195         .dai_link = &da830_evm_dai,
196         .platform = &davinci_soc_platform,
197         .num_links = 1,
198 };
199
200 /* evm audio private data */
201 static struct aic3x_setup_data evm_aic3x_setup = {
202         .i2c_bus = 1,
203         .i2c_address = 0x1b,
204 };
205
206 /* dm6467 evm audio private data */
207 static struct aic3x_setup_data dm6467_evm_aic3x_setup = {
208        .i2c_bus = 1,
209        .i2c_address = 0x18,
210 };
211
212 static struct aic3x_setup_data da830_evm_aic3x_setup = {
213         .i2c_bus = 1,
214         .i2c_address = 0x18,
215 };
216
217 /* evm audio subsystem */
218 static struct snd_soc_device evm_snd_devdata = {
219         .card = &snd_soc_card_evm,
220         .codec_dev = &soc_codec_dev_aic3x,
221         .codec_data = &evm_aic3x_setup,
222 };
223
224 /* evm audio subsystem */
225 static struct snd_soc_device dm6467_evm_snd_devdata = {
226         .card = &dm6467_snd_soc_card_evm,
227         .codec_dev = &soc_codec_dev_aic3x,
228         .codec_data = &dm6467_evm_aic3x_setup,
229 };
230
231 /* evm audio subsystem */
232 static struct snd_soc_device da830_evm_snd_devdata = {
233         .card = &da830_snd_soc_card,
234         .codec_dev = &soc_codec_dev_aic3x,
235         .codec_data = &da830_evm_aic3x_setup,
236 };
237
238 static struct platform_device *evm_snd_device;
239
240 static int __init evm_init(void)
241 {
242         struct snd_soc_device *evm_snd_dev_data;
243         int index;
244         int ret;
245
246         if (machine_is_davinci_evm()) {
247                 evm_snd_dev_data = &evm_snd_devdata;
248                 index = 0;
249         } else if (machine_is_davinci_dm355_evm()) {
250                 evm_snd_dev_data = &evm_snd_devdata;
251                 index = 1;
252         } else if (machine_is_davinci_dm6467_evm()) {
253                 evm_snd_dev_data = &dm6467_evm_snd_devdata;
254                 index = 0;
255         } else if (machine_is_davinci_da830_evm()) {
256                 evm_snd_dev_data = &da830_evm_snd_devdata;
257                 index = 1;
258         } else
259                 return -EINVAL;
260
261         evm_snd_device = platform_device_alloc("soc-audio", index);
262         if (!evm_snd_device)
263                 return -ENOMEM;
264
265         platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
266         evm_snd_dev_data->dev = &evm_snd_device->dev;
267         ret = platform_device_add(evm_snd_device);
268         if (ret)
269                 platform_device_put(evm_snd_device);
270
271         return ret;
272 }
273
274 static void __exit evm_exit(void)
275 {
276         platform_device_unregister(evm_snd_device);
277 }
278
279 module_init(evm_init);
280 module_exit(evm_exit);
281
282 MODULE_AUTHOR("Vladimir Barinov");
283 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
284 MODULE_LICENSE("GPL");