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