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/platform_data/edma.h>
18 #include <linux/i2c.h>
19 #include <linux/of_platform.h>
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/soc.h>
25 #include <asm/mach-types.h>
27 #include <linux/edma.h>
29 #include "davinci-pcm.h"
30 #include "davinci-i2s.h"
32 struct snd_soc_card_drvdata_davinci
{
36 static int evm_hw_params(struct snd_pcm_substream
*substream
,
37 struct snd_pcm_hw_params
*params
)
39 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
40 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
41 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
42 struct snd_soc_codec
*codec
= rtd
->codec
;
43 struct snd_soc_card
*soc_card
= codec
->card
;
45 unsigned sysclk
= ((struct snd_soc_card_drvdata_davinci
*)
46 snd_soc_card_get_drvdata(soc_card
))->sysclk
;
48 /* set the codec system clock */
49 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, sysclk
, SND_SOC_CLOCK_OUT
);
53 /* set the CPU system clock */
54 ret
= snd_soc_dai_set_sysclk(cpu_dai
, 0, sysclk
, SND_SOC_CLOCK_OUT
);
61 static struct snd_soc_ops evm_ops
= {
62 .hw_params
= evm_hw_params
,
65 /* davinci-evm machine dapm widgets */
66 static const struct snd_soc_dapm_widget aic3x_dapm_widgets
[] = {
67 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
68 SND_SOC_DAPM_LINE("Line Out", NULL
),
69 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
70 SND_SOC_DAPM_LINE("Line In", NULL
),
73 /* davinci-evm machine audio_mapnections to the codec pins */
74 static const struct snd_soc_dapm_route audio_map
[] = {
75 /* Headphone connected to HPLOUT, HPROUT */
76 {"Headphone Jack", NULL
, "HPLOUT"},
77 {"Headphone Jack", NULL
, "HPROUT"},
79 /* Line Out connected to LLOUT, RLOUT */
80 {"Line Out", NULL
, "LLOUT"},
81 {"Line Out", NULL
, "RLOUT"},
83 /* Mic connected to (MIC3L | MIC3R) */
84 {"MIC3L", NULL
, "Mic Bias"},
85 {"MIC3R", NULL
, "Mic Bias"},
86 {"Mic Bias", NULL
, "Mic Jack"},
88 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
89 {"LINE1L", NULL
, "Line In"},
90 {"LINE2L", NULL
, "Line In"},
91 {"LINE1R", NULL
, "Line In"},
92 {"LINE2R", NULL
, "Line In"},
95 /* Logic for a aic3x as connected on a davinci-evm */
96 static int evm_aic3x_init(struct snd_soc_pcm_runtime
*rtd
)
98 struct snd_soc_codec
*codec
= rtd
->codec
;
99 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
100 struct device_node
*np
= codec
->card
->dev
->of_node
;
103 /* Add davinci-evm specific widgets */
104 snd_soc_dapm_new_controls(dapm
, aic3x_dapm_widgets
,
105 ARRAY_SIZE(aic3x_dapm_widgets
));
108 ret
= snd_soc_of_parse_audio_routing(codec
->card
,
113 /* Set up davinci-evm specific audio path audio_map */
114 snd_soc_dapm_add_routes(dapm
, audio_map
, ARRAY_SIZE(audio_map
));
118 snd_soc_dapm_disable_pin(dapm
, "MONO_LOUT");
119 snd_soc_dapm_disable_pin(dapm
, "HPLCOM");
120 snd_soc_dapm_disable_pin(dapm
, "HPRCOM");
122 /* always connected */
123 snd_soc_dapm_enable_pin(dapm
, "Headphone Jack");
124 snd_soc_dapm_enable_pin(dapm
, "Line Out");
125 snd_soc_dapm_enable_pin(dapm
, "Mic Jack");
126 snd_soc_dapm_enable_pin(dapm
, "Line In");
131 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
132 static struct snd_soc_dai_link dm6446_evm_dai
= {
133 .name
= "TLV320AIC3X",
134 .stream_name
= "AIC3X",
135 .cpu_dai_name
= "davinci-mcbsp",
136 .codec_dai_name
= "tlv320aic3x-hifi",
137 .codec_name
= "tlv320aic3x-codec.1-001b",
138 .platform_name
= "davinci-mcbsp",
139 .init
= evm_aic3x_init
,
141 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
142 SND_SOC_DAIFMT_IB_NF
,
145 static struct snd_soc_dai_link dm355_evm_dai
= {
146 .name
= "TLV320AIC3X",
147 .stream_name
= "AIC3X",
148 .cpu_dai_name
= "davinci-mcbsp.1",
149 .codec_dai_name
= "tlv320aic3x-hifi",
150 .codec_name
= "tlv320aic3x-codec.1-001b",
151 .platform_name
= "davinci-mcbsp.1",
152 .init
= evm_aic3x_init
,
154 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
155 SND_SOC_DAIFMT_IB_NF
,
158 static struct snd_soc_dai_link dm365_evm_dai
= {
159 #ifdef CONFIG_SND_DM365_AIC3X_CODEC
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-0018",
165 .platform_name
= "davinci-mcbsp",
166 .init
= evm_aic3x_init
,
168 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
169 SND_SOC_DAIFMT_IB_NF
,
170 #elif defined(CONFIG_SND_DM365_VOICE_CODEC)
171 .name
= "Voice Codec - CQ93VC",
172 .stream_name
= "CQ93",
173 .cpu_dai_name
= "davinci-vcif",
174 .codec_dai_name
= "cq93vc-hifi",
175 .codec_name
= "cq93vc-codec",
176 .platform_name
= "davinci-vcif",
180 static struct snd_soc_dai_link dm6467_evm_dai
[] = {
182 .name
= "TLV320AIC3X",
183 .stream_name
= "AIC3X",
184 .cpu_dai_name
= "davinci-mcasp.0",
185 .codec_dai_name
= "tlv320aic3x-hifi",
186 .platform_name
= "davinci-mcasp.0",
187 .codec_name
= "tlv320aic3x-codec.0-001a",
188 .init
= evm_aic3x_init
,
190 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
191 SND_SOC_DAIFMT_IB_NF
,
195 .stream_name
= "spdif",
196 .cpu_dai_name
= "davinci-mcasp.1",
197 .codec_dai_name
= "dit-hifi",
198 .codec_name
= "spdif_dit",
199 .platform_name
= "davinci-mcasp.1",
200 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
201 SND_SOC_DAIFMT_IB_NF
,
205 static struct snd_soc_dai_link da830_evm_dai
= {
206 .name
= "TLV320AIC3X",
207 .stream_name
= "AIC3X",
208 .cpu_dai_name
= "davinci-mcasp.1",
209 .codec_dai_name
= "tlv320aic3x-hifi",
210 .codec_name
= "tlv320aic3x-codec.1-0018",
211 .platform_name
= "davinci-mcasp.1",
212 .init
= evm_aic3x_init
,
214 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
215 SND_SOC_DAIFMT_IB_NF
,
218 static struct snd_soc_dai_link da850_evm_dai
= {
219 .name
= "TLV320AIC3X",
220 .stream_name
= "AIC3X",
221 .cpu_dai_name
= "davinci-mcasp.0",
222 .codec_dai_name
= "tlv320aic3x-hifi",
223 .codec_name
= "tlv320aic3x-codec.1-0018",
224 .platform_name
= "davinci-mcasp.0",
225 .init
= evm_aic3x_init
,
227 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
228 SND_SOC_DAIFMT_IB_NF
,
231 /* davinci dm6446 evm audio machine driver */
233 * ASP0 in DM6446 EVM is clocked by U55, as configured by
234 * board-dm644x-evm.c using GPIOs from U18. There are six
235 * options; here we "know" we use a 48 KHz sample rate.
237 static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata
= {
241 static struct snd_soc_card dm6446_snd_soc_card_evm
= {
242 .name
= "DaVinci DM6446 EVM",
243 .owner
= THIS_MODULE
,
244 .dai_link
= &dm6446_evm_dai
,
246 .drvdata
= &dm6446_snd_soc_card_drvdata
,
249 /* davinci dm355 evm audio machine driver */
250 /* ASP1 on DM355 EVM is clocked by an external oscillator */
251 static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata
= {
255 static struct snd_soc_card dm355_snd_soc_card_evm
= {
256 .name
= "DaVinci DM355 EVM",
257 .owner
= THIS_MODULE
,
258 .dai_link
= &dm355_evm_dai
,
260 .drvdata
= &dm355_snd_soc_card_drvdata
,
263 /* davinci dm365 evm audio machine driver */
264 static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata
= {
268 static struct snd_soc_card dm365_snd_soc_card_evm
= {
269 .name
= "DaVinci DM365 EVM",
270 .owner
= THIS_MODULE
,
271 .dai_link
= &dm365_evm_dai
,
273 .drvdata
= &dm365_snd_soc_card_drvdata
,
276 /* davinci dm6467 evm audio machine driver */
277 static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata
= {
281 static struct snd_soc_card dm6467_snd_soc_card_evm
= {
282 .name
= "DaVinci DM6467 EVM",
283 .owner
= THIS_MODULE
,
284 .dai_link
= dm6467_evm_dai
,
285 .num_links
= ARRAY_SIZE(dm6467_evm_dai
),
286 .drvdata
= &dm6467_snd_soc_card_drvdata
,
289 static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata
= {
293 static struct snd_soc_card da830_snd_soc_card
= {
294 .name
= "DA830/OMAP-L137 EVM",
295 .owner
= THIS_MODULE
,
296 .dai_link
= &da830_evm_dai
,
298 .drvdata
= &da830_snd_soc_card_drvdata
,
301 static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata
= {
305 static struct snd_soc_card da850_snd_soc_card
= {
306 .name
= "DA850/OMAP-L138 EVM",
307 .owner
= THIS_MODULE
,
308 .dai_link
= &da850_evm_dai
,
310 .drvdata
= &da850_snd_soc_card_drvdata
,
313 #if defined(CONFIG_OF)
316 * The struct is used as place holder. It will be completely
317 * filled with data from dt node.
319 static struct snd_soc_dai_link evm_dai_tlv320aic3x
= {
320 .name
= "TLV320AIC3X",
321 .stream_name
= "AIC3X",
322 .codec_dai_name
= "tlv320aic3x-hifi",
324 .init
= evm_aic3x_init
,
325 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
326 SND_SOC_DAIFMT_IB_NF
,
329 static const struct of_device_id davinci_evm_dt_ids
[] = {
331 .compatible
= "ti,da830-evm-audio",
332 .data
= (void *) &evm_dai_tlv320aic3x
,
336 MODULE_DEVICE_TABLE(of
, davinci_evm_dt_ids
);
338 /* davinci evm audio machine driver */
339 static struct snd_soc_card evm_soc_card
= {
340 .owner
= THIS_MODULE
,
344 static int davinci_evm_probe(struct platform_device
*pdev
)
346 struct device_node
*np
= pdev
->dev
.of_node
;
347 const struct of_device_id
*match
=
348 of_match_device(of_match_ptr(davinci_evm_dt_ids
), &pdev
->dev
);
349 struct snd_soc_dai_link
*dai
= (struct snd_soc_dai_link
*) match
->data
;
350 struct snd_soc_card_drvdata_davinci
*drvdata
= NULL
;
353 evm_soc_card
.dai_link
= dai
;
355 dai
->codec_of_node
= of_parse_phandle(np
, "ti,audio-codec", 0);
356 if (!dai
->codec_of_node
)
359 dai
->cpu_of_node
= of_parse_phandle(np
, "ti,mcasp-controller", 0);
360 if (!dai
->cpu_of_node
)
363 dai
->platform_of_node
= dai
->cpu_of_node
;
365 evm_soc_card
.dev
= &pdev
->dev
;
366 ret
= snd_soc_of_parse_card_name(&evm_soc_card
, "ti,model");
370 drvdata
= devm_kzalloc(&pdev
->dev
, sizeof(*drvdata
), GFP_KERNEL
);
374 ret
= of_property_read_u32(np
, "ti,codec-clock-rate", &drvdata
->sysclk
);
378 snd_soc_card_set_drvdata(&evm_soc_card
, drvdata
);
379 ret
= devm_snd_soc_register_card(&pdev
->dev
, &evm_soc_card
);
382 dev_err(&pdev
->dev
, "snd_soc_register_card failed (%d)\n", ret
);
387 static int davinci_evm_remove(struct platform_device
*pdev
)
389 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
391 snd_soc_unregister_card(card
);
396 static struct platform_driver davinci_evm_driver
= {
397 .probe
= davinci_evm_probe
,
398 .remove
= davinci_evm_remove
,
400 .name
= "davinci_evm",
401 .owner
= THIS_MODULE
,
402 .pm
= &snd_soc_pm_ops
,
403 .of_match_table
= of_match_ptr(davinci_evm_dt_ids
),
408 static struct platform_device
*evm_snd_device
;
410 static int __init
evm_init(void)
412 struct snd_soc_card
*evm_snd_dev_data
;
417 * If dtb is there, the devices will be created dynamically.
418 * Only register platfrom driver structure.
420 #if defined(CONFIG_OF)
421 if (of_have_populated_dt())
422 return platform_driver_register(&davinci_evm_driver
);
425 if (machine_is_davinci_evm()) {
426 evm_snd_dev_data
= &dm6446_snd_soc_card_evm
;
428 } else if (machine_is_davinci_dm355_evm()) {
429 evm_snd_dev_data
= &dm355_snd_soc_card_evm
;
431 } else if (machine_is_davinci_dm365_evm()) {
432 evm_snd_dev_data
= &dm365_snd_soc_card_evm
;
434 } else if (machine_is_davinci_dm6467_evm()) {
435 evm_snd_dev_data
= &dm6467_snd_soc_card_evm
;
437 } else if (machine_is_davinci_da830_evm()) {
438 evm_snd_dev_data
= &da830_snd_soc_card
;
440 } else if (machine_is_davinci_da850_evm()) {
441 evm_snd_dev_data
= &da850_snd_soc_card
;
446 evm_snd_device
= platform_device_alloc("soc-audio", index
);
450 platform_set_drvdata(evm_snd_device
, evm_snd_dev_data
);
451 ret
= platform_device_add(evm_snd_device
);
453 platform_device_put(evm_snd_device
);
458 static void __exit
evm_exit(void)
460 #if defined(CONFIG_OF)
461 if (of_have_populated_dt()) {
462 platform_driver_unregister(&davinci_evm_driver
);
467 platform_device_unregister(evm_snd_device
);
470 module_init(evm_init
);
471 module_exit(evm_exit
);
473 MODULE_AUTHOR("Vladimir Barinov");
474 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
475 MODULE_LICENSE("GPL");