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 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
37 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
38 static int evm_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
42 struct snd_soc_dai *codec_dai = rtd->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
44 struct snd_soc_codec *codec = rtd->codec;
45 struct snd_soc_card *soc_card = codec->card;
47 unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *)
48 snd_soc_card_get_drvdata(soc_card))->sysclk;
50 /* set codec DAI configuration */
51 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
55 /* set cpu DAI configuration */
56 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
60 /* set the codec system clock */
61 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
65 /* set the CPU system clock */
66 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
73 static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
74 struct snd_pcm_hw_params *params)
76 struct snd_soc_pcm_runtime *rtd = substream->private_data;
77 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
79 /* set cpu DAI configuration */
80 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
83 static struct snd_soc_ops evm_ops = {
84 .hw_params = evm_hw_params,
87 static struct snd_soc_ops evm_spdif_ops = {
88 .hw_params = evm_spdif_hw_params,
91 /* davinci-evm machine dapm widgets */
92 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
93 SND_SOC_DAPM_HP("Headphone Jack", NULL),
94 SND_SOC_DAPM_LINE("Line Out", NULL),
95 SND_SOC_DAPM_MIC("Mic Jack", NULL),
96 SND_SOC_DAPM_LINE("Line In", NULL),
99 /* davinci-evm machine audio_mapnections to the codec pins */
100 static const struct snd_soc_dapm_route audio_map[] = {
101 /* Headphone connected to HPLOUT, HPROUT */
102 {"Headphone Jack", NULL, "HPLOUT"},
103 {"Headphone Jack", NULL, "HPROUT"},
105 /* Line Out connected to LLOUT, RLOUT */
106 {"Line Out", NULL, "LLOUT"},
107 {"Line Out", NULL, "RLOUT"},
109 /* Mic connected to (MIC3L | MIC3R) */
110 {"MIC3L", NULL, "Mic Bias"},
111 {"MIC3R", NULL, "Mic Bias"},
112 {"Mic Bias", NULL, "Mic Jack"},
114 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
115 {"LINE1L", NULL, "Line In"},
116 {"LINE2L", NULL, "Line In"},
117 {"LINE1R", NULL, "Line In"},
118 {"LINE2R", NULL, "Line In"},
121 /* Logic for a aic3x as connected on a davinci-evm */
122 static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
124 struct snd_soc_codec *codec = rtd->codec;
125 struct snd_soc_dapm_context *dapm = &codec->dapm;
126 struct device_node *np = codec->card->dev->of_node;
129 /* Add davinci-evm specific widgets */
130 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
131 ARRAY_SIZE(aic3x_dapm_widgets));
134 ret = snd_soc_of_parse_audio_routing(codec->card,
139 /* Set up davinci-evm specific audio path audio_map */
140 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 */
246 * ASP0 in DM6446 EVM is clocked by U55, as configured by
247 * board-dm644x-evm.c using GPIOs from U18. There are six
248 * options; here we "know" we use a 48 KHz sample rate.
250 static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = {
254 static struct snd_soc_card dm6446_snd_soc_card_evm = {
255 .name = "DaVinci DM6446 EVM",
256 .owner = THIS_MODULE,
257 .dai_link = &dm6446_evm_dai,
259 .drvdata = &dm6446_snd_soc_card_drvdata,
262 /* davinci dm355 evm audio machine driver */
263 /* ASP1 on DM355 EVM is clocked by an external oscillator */
264 static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = {
268 static struct snd_soc_card dm355_snd_soc_card_evm = {
269 .name = "DaVinci DM355 EVM",
270 .owner = THIS_MODULE,
271 .dai_link = &dm355_evm_dai,
273 .drvdata = &dm355_snd_soc_card_drvdata,
276 /* davinci dm365 evm audio machine driver */
277 static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = {
281 static struct snd_soc_card dm365_snd_soc_card_evm = {
282 .name = "DaVinci DM365 EVM",
283 .owner = THIS_MODULE,
284 .dai_link = &dm365_evm_dai,
286 .drvdata = &dm365_snd_soc_card_drvdata,
289 /* davinci dm6467 evm audio machine driver */
290 static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = {
294 static struct snd_soc_card dm6467_snd_soc_card_evm = {
295 .name = "DaVinci DM6467 EVM",
296 .owner = THIS_MODULE,
297 .dai_link = dm6467_evm_dai,
298 .num_links = ARRAY_SIZE(dm6467_evm_dai),
299 .drvdata = &dm6467_snd_soc_card_drvdata,
302 static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = {
306 static struct snd_soc_card da830_snd_soc_card = {
307 .name = "DA830/OMAP-L137 EVM",
308 .owner = THIS_MODULE,
309 .dai_link = &da830_evm_dai,
311 .drvdata = &da830_snd_soc_card_drvdata,
314 static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = {
318 static struct snd_soc_card da850_snd_soc_card = {
319 .name = "DA850/OMAP-L138 EVM",
320 .owner = THIS_MODULE,
321 .dai_link = &da850_evm_dai,
323 .drvdata = &da850_snd_soc_card_drvdata,
326 #if defined(CONFIG_OF)
329 * The struct is used as place holder. It will be completely
330 * filled with data from dt node.
332 static struct snd_soc_dai_link evm_dai_tlv320aic3x = {
333 .name = "TLV320AIC3X",
334 .stream_name = "AIC3X",
335 .codec_dai_name = "tlv320aic3x-hifi",
337 .init = evm_aic3x_init,
340 static const struct of_device_id davinci_evm_dt_ids[] = {
342 .compatible = "ti,da830-evm-audio",
343 .data = (void *) &evm_dai_tlv320aic3x,
347 MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids);
349 /* davinci evm audio machine driver */
350 static struct snd_soc_card evm_soc_card = {
351 .owner = THIS_MODULE,
355 static int davinci_evm_probe(struct platform_device *pdev)
357 struct device_node *np = pdev->dev.of_node;
358 const struct of_device_id *match =
359 of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev);
360 struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data;
361 struct snd_soc_card_drvdata_davinci *drvdata = NULL;
364 evm_soc_card.dai_link = dai;
366 dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0);
367 if (!dai->codec_of_node)
370 dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
371 if (!dai->cpu_of_node)
374 dai->platform_of_node = dai->cpu_of_node;
376 evm_soc_card.dev = &pdev->dev;
377 ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model");
381 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
385 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
389 snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
390 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
393 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
398 static int davinci_evm_remove(struct platform_device *pdev)
400 struct snd_soc_card *card = platform_get_drvdata(pdev);
402 snd_soc_unregister_card(card);
407 static struct platform_driver davinci_evm_driver = {
408 .probe = davinci_evm_probe,
409 .remove = davinci_evm_remove,
411 .name = "davinci_evm",
412 .owner = THIS_MODULE,
413 .of_match_table = of_match_ptr(davinci_evm_dt_ids),
418 static struct platform_device *evm_snd_device;
420 static int __init evm_init(void)
422 struct snd_soc_card *evm_snd_dev_data;
427 * If dtb is there, the devices will be created dynamically.
428 * Only register platfrom driver structure.
430 #if defined(CONFIG_OF)
431 if (of_have_populated_dt())
432 return platform_driver_register(&davinci_evm_driver);
435 if (machine_is_davinci_evm()) {
436 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
438 } else if (machine_is_davinci_dm355_evm()) {
439 evm_snd_dev_data = &dm355_snd_soc_card_evm;
441 } else if (machine_is_davinci_dm365_evm()) {
442 evm_snd_dev_data = &dm365_snd_soc_card_evm;
444 } else if (machine_is_davinci_dm6467_evm()) {
445 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
447 } else if (machine_is_davinci_da830_evm()) {
448 evm_snd_dev_data = &da830_snd_soc_card;
450 } else if (machine_is_davinci_da850_evm()) {
451 evm_snd_dev_data = &da850_snd_soc_card;
456 evm_snd_device = platform_device_alloc("soc-audio", index);
460 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
461 ret = platform_device_add(evm_snd_device);
463 platform_device_put(evm_snd_device);
468 static void __exit evm_exit(void)
470 #if defined(CONFIG_OF)
471 if (of_have_populated_dt()) {
472 platform_driver_unregister(&davinci_evm_driver);
477 platform_device_unregister(evm_snd_device);
480 module_init(evm_init);
481 module_exit(evm_exit);
483 MODULE_AUTHOR("Vladimir Barinov");
484 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
485 MODULE_LICENSE("GPL");