ASoC: davinci-evm: Do not include davinci-mcasp.h
[deliverable/linux.git] / sound / soc / davinci / davinci-evm.c
CommitLineData
310355c1
VB
1/*
2 * ASoC driver for TI DAVINCI EVM platform
3 *
d6b52039 4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
310355c1
VB
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>
3ad7a42d 17#include <linux/platform_data/edma.h>
aa6b904e 18#include <linux/i2c.h>
ee2f615d 19#include <linux/of_platform.h>
310355c1
VB
20#include <sound/core.h>
21#include <sound/pcm.h>
22#include <sound/soc.h>
310355c1 23
310355c1 24#include <asm/dma.h>
f492ec9f
DB
25#include <asm/mach-types.h>
26
ee2f615d
HG
27#include <linux/edma.h>
28
310355c1
VB
29#include "davinci-pcm.h"
30#include "davinci-i2s.h"
310355c1 31
bcf25567
JS
32struct snd_soc_card_drvdata_davinci {
33 unsigned sysclk;
34};
35
d6f83396
TK
36#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
37 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
310355c1
VB
38static int evm_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
40{
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad
LG
42 struct snd_soc_dai *codec_dai = rtd->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
bcf25567
JS
44 struct snd_soc_codec *codec = rtd->codec;
45 struct snd_soc_card *soc_card = codec->card;
310355c1 46 int ret = 0;
bcf25567
JS
47 unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *)
48 snd_soc_card_get_drvdata(soc_card))->sysclk;
310355c1
VB
49
50 /* set codec DAI configuration */
9e031624 51 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
310355c1
VB
52 if (ret < 0)
53 return ret;
54
55 /* set cpu DAI configuration */
9e031624 56 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
310355c1
VB
57 if (ret < 0)
58 return ret;
59
60 /* set the codec system clock */
05d5e991 61 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
310355c1
VB
62 if (ret < 0)
63 return ret;
64
5b66aa2d
DM
65 /* set the CPU system clock */
66 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
67 if (ret < 0)
68 return ret;
69
310355c1
VB
70 return 0;
71}
72
8d43d1bc
C
73static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
74 struct snd_pcm_hw_params *params)
75{
76 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad 77 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
8d43d1bc
C
78
79 /* set cpu DAI configuration */
80 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
81}
82
310355c1
VB
83static struct snd_soc_ops evm_ops = {
84 .hw_params = evm_hw_params,
85};
86
8d43d1bc
C
87static struct snd_soc_ops evm_spdif_ops = {
88 .hw_params = evm_spdif_hw_params,
89};
90
310355c1
VB
91/* davinci-evm machine dapm widgets */
92static 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),
97};
98
99/* davinci-evm machine audio_mapnections to the codec pins */
acf497f9 100static const struct snd_soc_dapm_route audio_map[] = {
310355c1
VB
101 /* Headphone connected to HPLOUT, HPROUT */
102 {"Headphone Jack", NULL, "HPLOUT"},
103 {"Headphone Jack", NULL, "HPROUT"},
104
105 /* Line Out connected to LLOUT, RLOUT */
106 {"Line Out", NULL, "LLOUT"},
107 {"Line Out", NULL, "RLOUT"},
108
109 /* Mic connected to (MIC3L | MIC3R) */
e2e8bfdf
HG
110 {"MIC3L", NULL, "Mic Bias"},
111 {"MIC3R", NULL, "Mic Bias"},
112 {"Mic Bias", NULL, "Mic Jack"},
310355c1
VB
113
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"},
310355c1
VB
119};
120
121/* Logic for a aic3x as connected on a davinci-evm */
f0fba2ad 122static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
310355c1 123{
f0fba2ad 124 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 125 struct snd_soc_dapm_context *dapm = &codec->dapm;
ee2f615d
HG
126 struct device_node *np = codec->card->dev->of_node;
127 int ret;
f0fba2ad 128
310355c1 129 /* Add davinci-evm specific widgets */
ce6120cc 130 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
acf497f9 131 ARRAY_SIZE(aic3x_dapm_widgets));
310355c1 132
ee2f615d
HG
133 if (np) {
134 ret = snd_soc_of_parse_audio_routing(codec->card,
135 "ti,audio-routing");
136 if (ret)
137 return ret;
138 } else {
139 /* Set up davinci-evm specific audio path audio_map */
140 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
141 }
310355c1
VB
142
143 /* not connected */
ce6120cc
LG
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");
310355c1
VB
147
148 /* always connected */
ce6120cc
LG
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");
310355c1 153
310355c1
VB
154 return 0;
155}
156
157/* davinci-evm digital audio interface glue - connects codec <--> CPU */
bedad0ca 158static struct snd_soc_dai_link dm6446_evm_dai = {
310355c1
VB
159 .name = "TLV320AIC3X",
160 .stream_name = "AIC3X",
bedad0ca 161 .cpu_dai_name = "davinci-mcbsp",
f0fba2ad 162 .codec_dai_name = "tlv320aic3x-hifi",
bedad0ca 163 .codec_name = "tlv320aic3x-codec.1-001b",
f08095a4 164 .platform_name = "davinci-mcbsp",
bedad0ca
CPE
165 .init = evm_aic3x_init,
166 .ops = &evm_ops,
167};
168
169static 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",
f08095a4 175 .platform_name = "davinci-mcbsp.1",
310355c1
VB
176 .init = evm_aic3x_init,
177 .ops = &evm_ops,
178};
179
aa9b88ee
MA
180static struct snd_soc_dai_link dm365_evm_dai = {
181#ifdef CONFIG_SND_DM365_AIC3X_CODEC
182 .name = "TLV320AIC3X",
183 .stream_name = "AIC3X",
bedad0ca 184 .cpu_dai_name = "davinci-mcbsp",
f0fba2ad 185 .codec_dai_name = "tlv320aic3x-hifi",
aa9b88ee 186 .init = evm_aic3x_init,
bedad0ca 187 .codec_name = "tlv320aic3x-codec.1-0018",
aa9b88ee 188 .ops = &evm_ops,
f08095a4 189 .platform_name = "davinci-mcbsp",
aa9b88ee
MA
190#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
191 .name = "Voice Codec - CQ93VC",
192 .stream_name = "CQ93",
f0fba2ad
LG
193 .cpu_dai_name = "davinci-vcif",
194 .codec_dai_name = "cq93vc-hifi",
195 .codec_name = "cq93vc-codec",
ffb690d5 196 .platform_name = "davinci-vcif",
aa9b88ee
MA
197#endif
198};
199
04f80f5c
C
200static struct snd_soc_dai_link dm6467_evm_dai[] = {
201 {
202 .name = "TLV320AIC3X",
203 .stream_name = "AIC3X",
f0fba2ad
LG
204 .cpu_dai_name= "davinci-mcasp.0",
205 .codec_dai_name = "tlv320aic3x-hifi",
f08095a4 206 .platform_name = "davinci-mcasp.0",
f0fba2ad 207 .codec_name = "tlv320aic3x-codec.0-001a",
04f80f5c
C
208 .init = evm_aic3x_init,
209 .ops = &evm_ops,
210 },
211 {
212 .name = "McASP",
213 .stream_name = "spdif",
f0fba2ad
LG
214 .cpu_dai_name= "davinci-mcasp.1",
215 .codec_dai_name = "dit-hifi",
216 .codec_name = "spdif_dit",
f08095a4 217 .platform_name = "davinci-mcasp.1",
8d43d1bc 218 .ops = &evm_spdif_ops,
04f80f5c
C
219 },
220};
f9eb9dd1
VB
221
222static 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",
f08095a4 228 .platform_name = "davinci-mcasp.1",
f9eb9dd1
VB
229 .init = evm_aic3x_init,
230 .ops = &evm_ops,
231};
232
233static struct snd_soc_dai_link da850_evm_dai = {
7ae5945f
C
234 .name = "TLV320AIC3X",
235 .stream_name = "AIC3X",
f0fba2ad
LG
236 .cpu_dai_name= "davinci-mcasp.0",
237 .codec_dai_name = "tlv320aic3x-hifi",
dc5a460a 238 .codec_name = "tlv320aic3x-codec.1-0018",
f08095a4 239 .platform_name = "davinci-mcasp.0",
7ae5945f
C
240 .init = evm_aic3x_init,
241 .ops = &evm_ops,
242};
04f80f5c 243
bedad0ca 244/* davinci dm6446 evm audio machine driver */
bcf25567
JS
245/*
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.
249 */
250static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = {
251 .sysclk = 12288000,
252};
253
bedad0ca
CPE
254static struct snd_soc_card dm6446_snd_soc_card_evm = {
255 .name = "DaVinci DM6446 EVM",
36a16d1a 256 .owner = THIS_MODULE,
bedad0ca
CPE
257 .dai_link = &dm6446_evm_dai,
258 .num_links = 1,
bcf25567 259 .drvdata = &dm6446_snd_soc_card_drvdata,
bedad0ca
CPE
260};
261
262/* davinci dm355 evm audio machine driver */
bcf25567
JS
263/* ASP1 on DM355 EVM is clocked by an external oscillator */
264static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = {
265 .sysclk = 27000000,
266};
267
bedad0ca
CPE
268static struct snd_soc_card dm355_snd_soc_card_evm = {
269 .name = "DaVinci DM355 EVM",
36a16d1a 270 .owner = THIS_MODULE,
bedad0ca 271 .dai_link = &dm355_evm_dai,
310355c1 272 .num_links = 1,
bcf25567 273 .drvdata = &dm355_snd_soc_card_drvdata,
310355c1
VB
274};
275
aa9b88ee 276/* davinci dm365 evm audio machine driver */
bcf25567
JS
277static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = {
278 .sysclk = 27000000,
279};
280
aa9b88ee
MA
281static struct snd_soc_card dm365_snd_soc_card_evm = {
282 .name = "DaVinci DM365 EVM",
36a16d1a 283 .owner = THIS_MODULE,
aa9b88ee
MA
284 .dai_link = &dm365_evm_dai,
285 .num_links = 1,
bcf25567 286 .drvdata = &dm365_snd_soc_card_drvdata,
aa9b88ee
MA
287};
288
04f80f5c 289/* davinci dm6467 evm audio machine driver */
bcf25567
JS
290static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = {
291 .sysclk = 27000000,
292};
293
04f80f5c
C
294static struct snd_soc_card dm6467_snd_soc_card_evm = {
295 .name = "DaVinci DM6467 EVM",
36a16d1a 296 .owner = THIS_MODULE,
04f80f5c
C
297 .dai_link = dm6467_evm_dai,
298 .num_links = ARRAY_SIZE(dm6467_evm_dai),
bcf25567
JS
299 .drvdata = &dm6467_snd_soc_card_drvdata,
300};
301
302static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = {
303 .sysclk = 24576000,
04f80f5c
C
304};
305
7ae5945f 306static struct snd_soc_card da830_snd_soc_card = {
30230f4c 307 .name = "DA830/OMAP-L137 EVM",
36a16d1a 308 .owner = THIS_MODULE,
f9eb9dd1 309 .dai_link = &da830_evm_dai,
30230f4c 310 .num_links = 1,
bcf25567
JS
311 .drvdata = &da830_snd_soc_card_drvdata,
312};
313
314static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = {
315 .sysclk = 24576000,
30230f4c
C
316};
317
318static struct snd_soc_card da850_snd_soc_card = {
319 .name = "DA850/OMAP-L138 EVM",
36a16d1a 320 .owner = THIS_MODULE,
f9eb9dd1 321 .dai_link = &da850_evm_dai,
7ae5945f 322 .num_links = 1,
bcf25567 323 .drvdata = &da850_snd_soc_card_drvdata,
7ae5945f
C
324};
325
ee2f615d
HG
326#if defined(CONFIG_OF)
327
328/*
329 * The struct is used as place holder. It will be completely
330 * filled with data from dt node.
331 */
332static struct snd_soc_dai_link evm_dai_tlv320aic3x = {
333 .name = "TLV320AIC3X",
334 .stream_name = "AIC3X",
335 .codec_dai_name = "tlv320aic3x-hifi",
336 .ops = &evm_ops,
337 .init = evm_aic3x_init,
338};
339
340static const struct of_device_id davinci_evm_dt_ids[] = {
341 {
342 .compatible = "ti,da830-evm-audio",
343 .data = (void *) &evm_dai_tlv320aic3x,
344 },
345 { /* sentinel */ }
346};
347MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids);
348
349/* davinci evm audio machine driver */
350static struct snd_soc_card evm_soc_card = {
351 .owner = THIS_MODULE,
352 .num_links = 1,
353};
354
355static int davinci_evm_probe(struct platform_device *pdev)
356{
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;
362 int ret = 0;
363
364 evm_soc_card.dai_link = dai;
365
366 dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0);
367 if (!dai->codec_of_node)
368 return -EINVAL;
369
370 dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
371 if (!dai->cpu_of_node)
372 return -EINVAL;
373
374 dai->platform_of_node = dai->cpu_of_node;
375
376 evm_soc_card.dev = &pdev->dev;
377 ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model");
378 if (ret)
379 return ret;
380
381 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
382 if (!drvdata)
383 return -ENOMEM;
384
385 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
386 if (ret < 0)
387 return -EINVAL;
388
389 snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
390 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
391
392 if (ret)
393 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
394
395 return ret;
396}
397
398static int davinci_evm_remove(struct platform_device *pdev)
399{
400 struct snd_soc_card *card = platform_get_drvdata(pdev);
401
402 snd_soc_unregister_card(card);
403
404 return 0;
405}
406
407static struct platform_driver davinci_evm_driver = {
408 .probe = davinci_evm_probe,
409 .remove = davinci_evm_remove,
410 .driver = {
411 .name = "davinci_evm",
412 .owner = THIS_MODULE,
413 .of_match_table = of_match_ptr(davinci_evm_dt_ids),
414 },
415};
416#endif
417
310355c1
VB
418static struct platform_device *evm_snd_device;
419
420static int __init evm_init(void)
421{
f0fba2ad 422 struct snd_soc_card *evm_snd_dev_data;
f492ec9f 423 int index;
310355c1
VB
424 int ret;
425
ee2f615d
HG
426 /*
427 * If dtb is there, the devices will be created dynamically.
428 * Only register platfrom driver structure.
429 */
430#if defined(CONFIG_OF)
431 if (of_have_populated_dt())
432 return platform_driver_register(&davinci_evm_driver);
433#endif
434
aa9b88ee 435 if (machine_is_davinci_evm()) {
bedad0ca 436 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
f492ec9f
DB
437 index = 0;
438 } else if (machine_is_davinci_dm355_evm()) {
bedad0ca 439 evm_snd_dev_data = &dm355_snd_soc_card_evm;
f492ec9f 440 index = 1;
aa9b88ee 441 } else if (machine_is_davinci_dm365_evm()) {
f0fba2ad 442 evm_snd_dev_data = &dm365_snd_soc_card_evm;
aa9b88ee 443 index = 0;
04f80f5c 444 } else if (machine_is_davinci_dm6467_evm()) {
f0fba2ad 445 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
04f80f5c 446 index = 0;
7ae5945f 447 } else if (machine_is_davinci_da830_evm()) {
f0fba2ad 448 evm_snd_dev_data = &da830_snd_soc_card;
7ae5945f 449 index = 1;
30230f4c 450 } else if (machine_is_davinci_da850_evm()) {
f0fba2ad 451 evm_snd_dev_data = &da850_snd_soc_card;
30230f4c 452 index = 0;
f492ec9f
DB
453 } else
454 return -EINVAL;
455
456 evm_snd_device = platform_device_alloc("soc-audio", index);
310355c1
VB
457 if (!evm_snd_device)
458 return -ENOMEM;
459
04f80f5c 460 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
310355c1
VB
461 ret = platform_device_add(evm_snd_device);
462 if (ret)
463 platform_device_put(evm_snd_device);
464
465 return ret;
466}
467
468static void __exit evm_exit(void)
469{
ee2f615d
HG
470#if defined(CONFIG_OF)
471 if (of_have_populated_dt()) {
472 platform_driver_unregister(&davinci_evm_driver);
473 return;
474 }
475#endif
476
310355c1
VB
477 platform_device_unregister(evm_snd_device);
478}
479
480module_init(evm_init);
481module_exit(evm_exit);
482
483MODULE_AUTHOR("Vladimir Barinov");
484MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
485MODULE_LICENSE("GPL");
This page took 0.232311 seconds and 5 git commands to generate.