]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/soc/davinci/davinci-evm.c
ASoC: tlv320aic3x: Change to use device model
[mv-sheeva.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                                 machine_is_davinci_da850_evm())
59                 sysclk = 24576000;
60
61         else
62                 return -EINVAL;
63
64         /* set codec DAI configuration */
65         ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
66         if (ret < 0)
67                 return ret;
68
69         /* set cpu DAI configuration */
70         ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
71         if (ret < 0)
72                 return ret;
73
74         /* set the codec system clock */
75         ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
76         if (ret < 0)
77                 return ret;
78
79         return 0;
80 }
81
82 static struct snd_soc_ops evm_ops = {
83         .hw_params = evm_hw_params,
84 };
85
86 /* davinci-evm machine dapm widgets */
87 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
88         SND_SOC_DAPM_HP("Headphone Jack", NULL),
89         SND_SOC_DAPM_LINE("Line Out", NULL),
90         SND_SOC_DAPM_MIC("Mic Jack", NULL),
91         SND_SOC_DAPM_LINE("Line In", NULL),
92 };
93
94 /* davinci-evm machine audio_mapnections to the codec pins */
95 static const struct snd_soc_dapm_route audio_map[] = {
96         /* Headphone connected to HPLOUT, HPROUT */
97         {"Headphone Jack", NULL, "HPLOUT"},
98         {"Headphone Jack", NULL, "HPROUT"},
99
100         /* Line Out connected to LLOUT, RLOUT */
101         {"Line Out", NULL, "LLOUT"},
102         {"Line Out", NULL, "RLOUT"},
103
104         /* Mic connected to (MIC3L | MIC3R) */
105         {"MIC3L", NULL, "Mic Bias 2V"},
106         {"MIC3R", NULL, "Mic Bias 2V"},
107         {"Mic Bias 2V", NULL, "Mic Jack"},
108
109         /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
110         {"LINE1L", NULL, "Line In"},
111         {"LINE2L", NULL, "Line In"},
112         {"LINE1R", NULL, "Line In"},
113         {"LINE2R", NULL, "Line In"},
114 };
115
116 /* Logic for a aic3x as connected on a davinci-evm */
117 static int evm_aic3x_init(struct snd_soc_codec *codec)
118 {
119         /* Add davinci-evm specific widgets */
120         snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
121                                   ARRAY_SIZE(aic3x_dapm_widgets));
122
123         /* Set up davinci-evm specific audio path audio_map */
124         snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
125
126         /* not connected */
127         snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
128         snd_soc_dapm_disable_pin(codec, "HPLCOM");
129         snd_soc_dapm_disable_pin(codec, "HPRCOM");
130
131         /* always connected */
132         snd_soc_dapm_enable_pin(codec, "Headphone Jack");
133         snd_soc_dapm_enable_pin(codec, "Line Out");
134         snd_soc_dapm_enable_pin(codec, "Mic Jack");
135         snd_soc_dapm_enable_pin(codec, "Line In");
136
137         snd_soc_dapm_sync(codec);
138
139         return 0;
140 }
141
142 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
143 static struct snd_soc_dai_link evm_dai = {
144         .name = "TLV320AIC3X",
145         .stream_name = "AIC3X",
146         .cpu_dai = &davinci_i2s_dai,
147         .codec_dai = &aic3x_dai,
148         .init = evm_aic3x_init,
149         .ops = &evm_ops,
150 };
151
152 static struct snd_soc_dai_link dm6467_evm_dai[] = {
153         {
154                 .name = "TLV320AIC3X",
155                 .stream_name = "AIC3X",
156                 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
157                 .codec_dai = &aic3x_dai,
158                 .init = evm_aic3x_init,
159                 .ops = &evm_ops,
160         },
161         {
162                 .name = "McASP",
163                 .stream_name = "spdif",
164                 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
165                 .codec_dai = &dit_stub_dai,
166                 .ops = &evm_ops,
167         },
168 };
169 static struct snd_soc_dai_link da8xx_evm_dai = {
170         .name = "TLV320AIC3X",
171         .stream_name = "AIC3X",
172         .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
173         .codec_dai = &aic3x_dai,
174         .init = evm_aic3x_init,
175         .ops = &evm_ops,
176 };
177
178 /* davinci-evm audio machine driver */
179 static struct snd_soc_card snd_soc_card_evm = {
180         .name = "DaVinci EVM",
181         .platform = &davinci_soc_platform,
182         .dai_link = &evm_dai,
183         .num_links = 1,
184 };
185
186 /* davinci dm6467 evm audio machine driver */
187 static struct snd_soc_card dm6467_snd_soc_card_evm = {
188         .name = "DaVinci DM6467 EVM",
189         .platform = &davinci_soc_platform,
190         .dai_link = dm6467_evm_dai,
191         .num_links = ARRAY_SIZE(dm6467_evm_dai),
192 };
193
194 static struct snd_soc_card da830_snd_soc_card = {
195         .name = "DA830/OMAP-L137 EVM",
196         .dai_link = &da8xx_evm_dai,
197         .platform = &davinci_soc_platform,
198         .num_links = 1,
199 };
200
201 static struct snd_soc_card da850_snd_soc_card = {
202         .name = "DA850/OMAP-L138 EVM",
203         .dai_link = &da8xx_evm_dai,
204         .platform = &davinci_soc_platform,
205         .num_links = 1,
206 };
207
208 /* evm audio private data */
209 static struct aic3x_setup_data evm_aic3x_setup = {
210 };
211
212 /* dm6467 evm audio private data */
213 static struct aic3x_setup_data dm6467_evm_aic3x_setup = {
214        .i2c_bus = 1,
215        .i2c_address = 0x18,
216 };
217
218 static struct aic3x_setup_data da8xx_evm_aic3x_setup = {
219         .i2c_bus = 1,
220         .i2c_address = 0x18,
221 };
222
223 /* evm audio subsystem */
224 static struct snd_soc_device evm_snd_devdata = {
225         .card = &snd_soc_card_evm,
226         .codec_dev = &soc_codec_dev_aic3x,
227         .codec_data = &evm_aic3x_setup,
228 };
229
230 /* evm audio subsystem */
231 static struct snd_soc_device dm6467_evm_snd_devdata = {
232         .card = &dm6467_snd_soc_card_evm,
233         .codec_dev = &soc_codec_dev_aic3x,
234         .codec_data = &dm6467_evm_aic3x_setup,
235 };
236
237 /* evm audio subsystem */
238 static struct snd_soc_device da830_evm_snd_devdata = {
239         .card = &da830_snd_soc_card,
240         .codec_dev = &soc_codec_dev_aic3x,
241         .codec_data = &da8xx_evm_aic3x_setup,
242 };
243
244 static struct snd_soc_device da850_evm_snd_devdata = {
245         .card           = &da850_snd_soc_card,
246         .codec_dev      = &soc_codec_dev_aic3x,
247         .codec_data     = &da8xx_evm_aic3x_setup,
248 };
249
250 static struct platform_device *evm_snd_device;
251
252 static int __init evm_init(void)
253 {
254         struct snd_soc_device *evm_snd_dev_data;
255         int index;
256         int ret;
257
258         if (machine_is_davinci_evm()) {
259                 evm_snd_dev_data = &evm_snd_devdata;
260                 index = 0;
261         } else if (machine_is_davinci_dm355_evm()) {
262                 evm_snd_dev_data = &evm_snd_devdata;
263                 index = 1;
264         } else if (machine_is_davinci_dm6467_evm()) {
265                 evm_snd_dev_data = &dm6467_evm_snd_devdata;
266                 index = 0;
267         } else if (machine_is_davinci_da830_evm()) {
268                 evm_snd_dev_data = &da830_evm_snd_devdata;
269                 index = 1;
270         } else if (machine_is_davinci_da850_evm()) {
271                 evm_snd_dev_data = &da850_evm_snd_devdata;
272                 index = 0;
273         } else
274                 return -EINVAL;
275
276         evm_snd_device = platform_device_alloc("soc-audio", index);
277         if (!evm_snd_device)
278                 return -ENOMEM;
279
280         platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
281         evm_snd_dev_data->dev = &evm_snd_device->dev;
282         ret = platform_device_add(evm_snd_device);
283         if (ret)
284                 platform_device_put(evm_snd_device);
285
286         return ret;
287 }
288
289 static void __exit evm_exit(void)
290 {
291         platform_device_unregister(evm_snd_device);
292 }
293
294 module_init(evm_init);
295 module_exit(evm_exit);
296
297 MODULE_AUTHOR("Vladimir Barinov");
298 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
299 MODULE_LICENSE("GPL");