f6a62c3cd0943e60195fa3b4af8ea0f569cb009b
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;
58 /* On AM335X, CODEC gets MCLK from external Xtal (12MHz). */
59 else if (machine_is_am335xevm())
60 sysclk = 12000000;
62 else
63 return -EINVAL;
65 /* set codec DAI configuration */
66 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
67 if (ret < 0)
68 return ret;
70 /* set cpu DAI configuration */
71 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
72 if (ret < 0)
73 return ret;
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;
80 return 0;
81 }
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;
89 /* set cpu DAI configuration */
90 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
91 }
93 static struct snd_soc_ops evm_ops = {
94 .hw_params = evm_hw_params,
95 };
97 static struct snd_soc_ops evm_spdif_ops = {
98 .hw_params = evm_spdif_hw_params,
99 };
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 };
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"},
115 /* Line Out connected to LLOUT, RLOUT */
116 {"Line Out", NULL, "LLOUT"},
117 {"Line Out", NULL, "RLOUT"},
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"},
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 };
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 struct snd_soc_dapm_context *dapm = &codec->dapm;
137 /* Add davinci-evm specific widgets */
138 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
139 ARRAY_SIZE(aic3x_dapm_widgets));
141 /* Set up davinci-evm specific audio path audio_map */
142 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
144 /* not connected */
145 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
146 snd_soc_dapm_disable_pin(dapm, "HPLCOM");
147 snd_soc_dapm_disable_pin(dapm, "HPRCOM");
149 /* always connected */
150 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
151 snd_soc_dapm_enable_pin(dapm, "Line Out");
152 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
153 snd_soc_dapm_enable_pin(dapm, "Line In");
155 return 0;
156 }
158 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
159 static struct snd_soc_dai_link dm6446_evm_dai = {
160 .name = "TLV320AIC3X",
161 .stream_name = "AIC3X",
162 .cpu_dai_name = "davinci-mcbsp",
163 .codec_dai_name = "tlv320aic3x-hifi",
164 .codec_name = "tlv320aic3x-codec.1-001b",
165 .platform_name = "davinci-pcm-audio",
166 .init = evm_aic3x_init,
167 .ops = &evm_ops,
168 };
170 static struct snd_soc_dai_link dm355_evm_dai = {
171 .name = "TLV320AIC3X",
172 .stream_name = "AIC3X",
173 .cpu_dai_name = "davinci-mcbsp.1",
174 .codec_dai_name = "tlv320aic3x-hifi",
175 .codec_name = "tlv320aic3x-codec.1-001b",
176 .platform_name = "davinci-pcm-audio",
177 .init = evm_aic3x_init,
178 .ops = &evm_ops,
179 };
181 static struct snd_soc_dai_link dm365_evm_dai = {
182 #ifdef CONFIG_SND_DM365_AIC3X_CODEC
183 .name = "TLV320AIC3X",
184 .stream_name = "AIC3X",
185 .cpu_dai_name = "davinci-mcbsp",
186 .codec_dai_name = "tlv320aic3x-hifi",
187 .init = evm_aic3x_init,
188 .codec_name = "tlv320aic3x-codec.1-0018",
189 .ops = &evm_ops,
190 #elif defined(CONFIG_SND_DM365_VOICE_CODEC)
191 .name = "Voice Codec - CQ93VC",
192 .stream_name = "CQ93",
193 .cpu_dai_name = "davinci-vcif",
194 .codec_dai_name = "cq93vc-hifi",
195 .codec_name = "cq93vc-codec",
196 #endif
197 .platform_name = "davinci-pcm-audio",
198 };
200 static struct snd_soc_dai_link dm6467_evm_dai[] = {
201 {
202 .name = "TLV320AIC3X",
203 .stream_name = "AIC3X",
204 .cpu_dai_name= "davinci-mcasp.0",
205 .codec_dai_name = "tlv320aic3x-hifi",
206 .platform_name ="davinci-pcm-audio",
207 .codec_name = "tlv320aic3x-codec.0-001a",
208 .init = evm_aic3x_init,
209 .ops = &evm_ops,
210 },
211 {
212 .name = "McASP",
213 .stream_name = "spdif",
214 .cpu_dai_name= "davinci-mcasp.1",
215 .codec_dai_name = "dit-hifi",
216 .codec_name = "spdif_dit",
217 .platform_name = "davinci-pcm-audio",
218 .ops = &evm_spdif_ops,
219 },
220 };
222 static struct snd_soc_dai_link da830_evm_dai = {
223 .name = "TLV320AIC3X",
224 .stream_name = "AIC3X",
225 .cpu_dai_name = "davinci-mcasp.1",
226 .codec_dai_name = "tlv320aic3x-hifi",
227 .codec_name = "tlv320aic3x-codec.1-0018",
228 .platform_name = "davinci-pcm-audio",
229 .init = evm_aic3x_init,
230 .ops = &evm_ops,
231 };
233 static struct snd_soc_dai_link da850_evm_dai = {
234 .name = "TLV320AIC3X",
235 .stream_name = "AIC3X",
236 .cpu_dai_name= "davinci-mcasp.0",
237 .codec_dai_name = "tlv320aic3x-hifi",
238 .codec_name = "tlv320aic3x-codec.1-0018",
239 .platform_name = "davinci-pcm-audio",
240 .init = evm_aic3x_init,
241 .ops = &evm_ops,
242 };
244 static struct snd_soc_dai_link am335x_evm_dai = {
245 .name = "TLV320AIC3X",
246 .stream_name = "AIC3X",
247 .cpu_dai_name = "davinci-mcasp.1",
248 .codec_dai_name = "tlv320aic3x-hifi",
249 .codec_name = "tlv320aic3x-codec.2-001b",
250 .platform_name = "davinci-pcm-audio",
251 .init = evm_aic3x_init,
252 .ops = &evm_ops,
253 };
255 /* davinci dm6446 evm audio machine driver */
256 static struct snd_soc_card dm6446_snd_soc_card_evm = {
257 .name = "DaVinci DM6446 EVM",
258 .dai_link = &dm6446_evm_dai,
259 .num_links = 1,
260 };
262 /* davinci dm355 evm audio machine driver */
263 static struct snd_soc_card dm355_snd_soc_card_evm = {
264 .name = "DaVinci DM355 EVM",
265 .dai_link = &dm355_evm_dai,
266 .num_links = 1,
267 };
269 /* davinci dm365 evm audio machine driver */
270 static struct snd_soc_card dm365_snd_soc_card_evm = {
271 .name = "DaVinci DM365 EVM",
272 .dai_link = &dm365_evm_dai,
273 .num_links = 1,
274 };
276 /* davinci dm6467 evm audio machine driver */
277 static struct snd_soc_card dm6467_snd_soc_card_evm = {
278 .name = "DaVinci DM6467 EVM",
279 .dai_link = dm6467_evm_dai,
280 .num_links = ARRAY_SIZE(dm6467_evm_dai),
281 };
283 static struct snd_soc_card da830_snd_soc_card = {
284 .name = "DA830/OMAP-L137 EVM",
285 .dai_link = &da830_evm_dai,
286 .num_links = 1,
287 };
289 static struct snd_soc_card da850_snd_soc_card = {
290 .name = "DA850/OMAP-L138 EVM",
291 .dai_link = &da850_evm_dai,
292 .num_links = 1,
293 };
295 static struct snd_soc_card am335x_snd_soc_card = {
296 .name = "AM335X EVM",
297 .dai_link = &am335x_evm_dai,
298 .num_links = 1,
299 };
301 static struct platform_device *evm_snd_device;
303 static int __init evm_init(void)
304 {
305 struct snd_soc_card *evm_snd_dev_data;
306 int index;
307 int ret;
309 if (machine_is_davinci_evm()) {
310 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
311 index = 0;
312 } else if (machine_is_davinci_dm355_evm()) {
313 evm_snd_dev_data = &dm355_snd_soc_card_evm;
314 index = 1;
315 } else if (machine_is_davinci_dm365_evm()) {
316 evm_snd_dev_data = &dm365_snd_soc_card_evm;
317 index = 0;
318 } else if (machine_is_davinci_dm6467_evm()) {
319 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
320 index = 0;
321 } else if (machine_is_davinci_da830_evm()) {
322 evm_snd_dev_data = &da830_snd_soc_card;
323 index = 1;
324 } else if (machine_is_davinci_da850_evm()) {
325 evm_snd_dev_data = &da850_snd_soc_card;
326 index = 0;
327 } else if (machine_is_am335xevm()) {
328 evm_snd_dev_data = &am335x_snd_soc_card;
329 index = 0;
330 } else
331 return -EINVAL;
333 evm_snd_device = platform_device_alloc("soc-audio", index);
334 if (!evm_snd_device)
335 return -ENOMEM;
337 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
338 ret = platform_device_add(evm_snd_device);
339 if (ret)
340 platform_device_put(evm_snd_device);
342 return ret;
343 }
345 static void __exit evm_exit(void)
346 {
347 platform_device_unregister(evm_snd_device);
348 }
350 module_init(evm_init);
351 module_exit(evm_exit);
353 MODULE_AUTHOR("Vladimir Barinov");
354 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
355 MODULE_LICENSE("GPL");