2 * ASoC driver for TI DAVINCI EVM platform
4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
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.
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>
23 #include <asm/mach-types.h>
25 #include "davinci-pcm.h"
26 #include "davinci-i2s.h"
27 #include "davinci-mcasp.h"
29 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
30 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
31 static int evm_hw_params(struct snd_pcm_substream
*substream
,
32 struct snd_pcm_hw_params
*params
)
34 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
35 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
36 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
40 /* ASP1 on DM355 EVM is clocked by an external oscillator */
41 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
42 machine_is_davinci_dm365_evm())
45 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
46 * board-dm644x-evm.c using GPIOs from U18. There are six
47 * options; here we "know" we use a 48 KHz sample rate.
49 else if (machine_is_davinci_evm())
52 else if (machine_is_davinci_da830_evm() ||
53 machine_is_davinci_da850_evm())
59 /* set codec DAI configuration */
60 ret
= snd_soc_dai_set_fmt(codec_dai
, AUDIO_FORMAT
);
64 /* set cpu DAI configuration */
65 ret
= snd_soc_dai_set_fmt(cpu_dai
, AUDIO_FORMAT
);
69 /* set the codec system clock */
70 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, sysclk
, SND_SOC_CLOCK_OUT
);
74 /* set the CPU system clock */
75 ret
= snd_soc_dai_set_sysclk(cpu_dai
, 0, sysclk
, SND_SOC_CLOCK_OUT
);
82 static int evm_spdif_hw_params(struct snd_pcm_substream
*substream
,
83 struct snd_pcm_hw_params
*params
)
85 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
86 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
88 /* set cpu DAI configuration */
89 return snd_soc_dai_set_fmt(cpu_dai
, AUDIO_FORMAT
);
92 static struct snd_soc_ops evm_ops
= {
93 .hw_params
= evm_hw_params
,
96 static struct snd_soc_ops evm_spdif_ops
= {
97 .hw_params
= evm_spdif_hw_params
,
100 /* davinci-evm machine dapm widgets */
101 static const struct snd_soc_dapm_widget aic3x_dapm_widgets
[] = {
102 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
103 SND_SOC_DAPM_LINE("Line Out", NULL
),
104 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
105 SND_SOC_DAPM_LINE("Line In", NULL
),
108 /* davinci-evm machine audio_mapnections to the codec pins */
109 static const struct snd_soc_dapm_route audio_map
[] = {
110 /* Headphone connected to HPLOUT, HPROUT */
111 {"Headphone Jack", NULL
, "HPLOUT"},
112 {"Headphone Jack", NULL
, "HPROUT"},
114 /* Line Out connected to LLOUT, RLOUT */
115 {"Line Out", NULL
, "LLOUT"},
116 {"Line Out", NULL
, "RLOUT"},
118 /* Mic connected to (MIC3L | MIC3R) */
119 {"MIC3L", NULL
, "Mic Bias 2V"},
120 {"MIC3R", NULL
, "Mic Bias 2V"},
121 {"Mic Bias 2V", NULL
, "Mic Jack"},
123 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
124 {"LINE1L", NULL
, "Line In"},
125 {"LINE2L", NULL
, "Line In"},
126 {"LINE1R", NULL
, "Line In"},
127 {"LINE2R", NULL
, "Line In"},
130 /* Logic for a aic3x as connected on a davinci-evm */
131 static int evm_aic3x_init(struct snd_soc_pcm_runtime
*rtd
)
133 struct snd_soc_codec
*codec
= rtd
->codec
;
134 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
136 /* Add davinci-evm specific widgets */
137 snd_soc_dapm_new_controls(dapm
, aic3x_dapm_widgets
,
138 ARRAY_SIZE(aic3x_dapm_widgets
));
140 /* Set up davinci-evm specific audio path audio_map */
141 snd_soc_dapm_add_routes(dapm
, audio_map
, ARRAY_SIZE(audio_map
));
144 snd_soc_dapm_disable_pin(dapm
, "MONO_LOUT");
145 snd_soc_dapm_disable_pin(dapm
, "HPLCOM");
146 snd_soc_dapm_disable_pin(dapm
, "HPRCOM");
148 /* always connected */
149 snd_soc_dapm_enable_pin(dapm
, "Headphone Jack");
150 snd_soc_dapm_enable_pin(dapm
, "Line Out");
151 snd_soc_dapm_enable_pin(dapm
, "Mic Jack");
152 snd_soc_dapm_enable_pin(dapm
, "Line In");
157 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
158 static struct snd_soc_dai_link dm6446_evm_dai
= {
159 .name
= "TLV320AIC3X",
160 .stream_name
= "AIC3X",
161 .cpu_dai_name
= "davinci-mcbsp",
162 .codec_dai_name
= "tlv320aic3x-hifi",
163 .codec_name
= "tlv320aic3x-codec.1-001b",
164 .platform_name
= "davinci-mcbsp",
165 .init
= evm_aic3x_init
,
169 static struct snd_soc_dai_link dm355_evm_dai
= {
170 .name
= "TLV320AIC3X",
171 .stream_name
= "AIC3X",
172 .cpu_dai_name
= "davinci-mcbsp.1",
173 .codec_dai_name
= "tlv320aic3x-hifi",
174 .codec_name
= "tlv320aic3x-codec.1-001b",
175 .platform_name
= "davinci-mcbsp.1",
176 .init
= evm_aic3x_init
,
180 static struct snd_soc_dai_link dm365_evm_dai
= {
181 #ifdef CONFIG_SND_DM365_AIC3X_CODEC
182 .name
= "TLV320AIC3X",
183 .stream_name
= "AIC3X",
184 .cpu_dai_name
= "davinci-mcbsp",
185 .codec_dai_name
= "tlv320aic3x-hifi",
186 .init
= evm_aic3x_init
,
187 .codec_name
= "tlv320aic3x-codec.1-0018",
189 .platform_name
= "davinci-mcbsp",
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 .platform_name
= "davinci-vcif",
200 static struct snd_soc_dai_link dm6467_evm_dai
[] = {
202 .name
= "TLV320AIC3X",
203 .stream_name
= "AIC3X",
204 .cpu_dai_name
= "davinci-mcasp.0",
205 .codec_dai_name
= "tlv320aic3x-hifi",
206 .platform_name
= "davinci-mcasp.0",
207 .codec_name
= "tlv320aic3x-codec.0-001a",
208 .init
= evm_aic3x_init
,
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-mcasp.1",
218 .ops
= &evm_spdif_ops
,
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-mcasp.1",
229 .init
= evm_aic3x_init
,
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-mcasp.0",
240 .init
= evm_aic3x_init
,
244 /* davinci dm6446 evm audio machine driver */
245 static struct snd_soc_card dm6446_snd_soc_card_evm
= {
246 .name
= "DaVinci DM6446 EVM",
247 .owner
= THIS_MODULE
,
248 .dai_link
= &dm6446_evm_dai
,
252 /* davinci dm355 evm audio machine driver */
253 static struct snd_soc_card dm355_snd_soc_card_evm
= {
254 .name
= "DaVinci DM355 EVM",
255 .owner
= THIS_MODULE
,
256 .dai_link
= &dm355_evm_dai
,
260 /* davinci dm365 evm audio machine driver */
261 static struct snd_soc_card dm365_snd_soc_card_evm
= {
262 .name
= "DaVinci DM365 EVM",
263 .owner
= THIS_MODULE
,
264 .dai_link
= &dm365_evm_dai
,
268 /* davinci dm6467 evm audio machine driver */
269 static struct snd_soc_card dm6467_snd_soc_card_evm
= {
270 .name
= "DaVinci DM6467 EVM",
271 .owner
= THIS_MODULE
,
272 .dai_link
= dm6467_evm_dai
,
273 .num_links
= ARRAY_SIZE(dm6467_evm_dai
),
276 static struct snd_soc_card da830_snd_soc_card
= {
277 .name
= "DA830/OMAP-L137 EVM",
278 .owner
= THIS_MODULE
,
279 .dai_link
= &da830_evm_dai
,
283 static struct snd_soc_card da850_snd_soc_card
= {
284 .name
= "DA850/OMAP-L138 EVM",
285 .owner
= THIS_MODULE
,
286 .dai_link
= &da850_evm_dai
,
290 static struct platform_device
*evm_snd_device
;
292 static int __init
evm_init(void)
294 struct snd_soc_card
*evm_snd_dev_data
;
298 if (machine_is_davinci_evm()) {
299 evm_snd_dev_data
= &dm6446_snd_soc_card_evm
;
301 } else if (machine_is_davinci_dm355_evm()) {
302 evm_snd_dev_data
= &dm355_snd_soc_card_evm
;
304 } else if (machine_is_davinci_dm365_evm()) {
305 evm_snd_dev_data
= &dm365_snd_soc_card_evm
;
307 } else if (machine_is_davinci_dm6467_evm()) {
308 evm_snd_dev_data
= &dm6467_snd_soc_card_evm
;
310 } else if (machine_is_davinci_da830_evm()) {
311 evm_snd_dev_data
= &da830_snd_soc_card
;
313 } else if (machine_is_davinci_da850_evm()) {
314 evm_snd_dev_data
= &da850_snd_soc_card
;
319 evm_snd_device
= platform_device_alloc("soc-audio", index
);
323 platform_set_drvdata(evm_snd_device
, evm_snd_dev_data
);
324 ret
= platform_device_add(evm_snd_device
);
326 platform_device_put(evm_snd_device
);
331 static void __exit
evm_exit(void)
333 platform_device_unregister(evm_snd_device
);
336 module_init(evm_init
);
337 module_exit(evm_exit
);
339 MODULE_AUTHOR("Vladimir Barinov");
340 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
341 MODULE_LICENSE("GPL");