]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - sound/soc/davinci/davinci-evm.c
ASoC: davinci-mcasp: Fix ruledata setup in davinci_mcasp_startup
[mirror_ubuntu-hirsute-kernel.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>
aa6b904e 17#include <linux/i2c.h>
ee2f615d 18#include <linux/of_platform.h>
5ad8865b 19#include <linux/clk.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
bcf25567 27struct snd_soc_card_drvdata_davinci {
5ad8865b 28 struct clk *mclk;
bcf25567
JS
29 unsigned sysclk;
30};
31
5ad8865b
JS
32static int evm_startup(struct snd_pcm_substream *substream)
33{
34 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2896b8b4 35 struct snd_soc_card *soc_card = rtd->card;
5ad8865b
JS
36 struct snd_soc_card_drvdata_davinci *drvdata =
37 snd_soc_card_get_drvdata(soc_card);
38
39 if (drvdata->mclk)
40 return clk_prepare_enable(drvdata->mclk);
41
42 return 0;
43}
44
45static void evm_shutdown(struct snd_pcm_substream *substream)
46{
47 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2896b8b4 48 struct snd_soc_card *soc_card = rtd->card;
5ad8865b
JS
49 struct snd_soc_card_drvdata_davinci *drvdata =
50 snd_soc_card_get_drvdata(soc_card);
51
52 if (drvdata->mclk)
53 clk_disable_unprepare(drvdata->mclk);
54}
55
310355c1
VB
56static int evm_hw_params(struct snd_pcm_substream *substream,
57 struct snd_pcm_hw_params *params)
58{
59 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad
LG
60 struct snd_soc_dai *codec_dai = rtd->codec_dai;
61 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2896b8b4 62 struct snd_soc_card *soc_card = rtd->card;
310355c1 63 int ret = 0;
bcf25567
JS
64 unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *)
65 snd_soc_card_get_drvdata(soc_card))->sysclk;
310355c1 66
310355c1 67 /* set the codec system clock */
05d5e991 68 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
310355c1
VB
69 if (ret < 0)
70 return ret;
71
5b66aa2d
DM
72 /* set the CPU system clock */
73 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
74 if (ret < 0)
75 return ret;
76
310355c1
VB
77 return 0;
78}
79
80static struct snd_soc_ops evm_ops = {
5ad8865b
JS
81 .startup = evm_startup,
82 .shutdown = evm_shutdown,
310355c1
VB
83 .hw_params = evm_hw_params,
84};
85
86/* davinci-evm machine dapm widgets */
87static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
88 SND_SOC_DAPM_HP("Headphone Jack", NULL),
89 SND_SOC_DAPM_LINE("Line Out", NULL),
90 SND_SOC_DAPM_MIC("Mic Jack", NULL),
91 SND_SOC_DAPM_LINE("Line In", NULL),
92};
93
94/* davinci-evm machine audio_mapnections to the codec pins */
acf497f9 95static const struct snd_soc_dapm_route audio_map[] = {
310355c1
VB
96 /* Headphone connected to HPLOUT, HPROUT */
97 {"Headphone Jack", NULL, "HPLOUT"},
98 {"Headphone Jack", NULL, "HPROUT"},
99
100 /* Line Out connected to LLOUT, RLOUT */
101 {"Line Out", NULL, "LLOUT"},
102 {"Line Out", NULL, "RLOUT"},
103
104 /* Mic connected to (MIC3L | MIC3R) */
e2e8bfdf
HG
105 {"MIC3L", NULL, "Mic Bias"},
106 {"MIC3R", NULL, "Mic Bias"},
107 {"Mic Bias", NULL, "Mic Jack"},
310355c1
VB
108
109 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
110 {"LINE1L", NULL, "Line In"},
111 {"LINE2L", NULL, "Line In"},
112 {"LINE1R", NULL, "Line In"},
113 {"LINE2R", NULL, "Line In"},
310355c1
VB
114};
115
116/* Logic for a aic3x as connected on a davinci-evm */
f0fba2ad 117static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
310355c1 118{
d343a660 119 struct snd_soc_card *card = rtd->card;
f0fba2ad 120 struct snd_soc_codec *codec = rtd->codec;
2896b8b4 121 struct device_node *np = card->dev->of_node;
ee2f615d 122 int ret;
f0fba2ad 123
310355c1 124 /* Add davinci-evm specific widgets */
d343a660 125 snd_soc_dapm_new_controls(&card->dapm, aic3x_dapm_widgets,
acf497f9 126 ARRAY_SIZE(aic3x_dapm_widgets));
310355c1 127
ee2f615d 128 if (np) {
d343a660 129 ret = snd_soc_of_parse_audio_routing(card, "ti,audio-routing");
ee2f615d
HG
130 if (ret)
131 return ret;
132 } else {
133 /* Set up davinci-evm specific audio path audio_map */
d343a660
LPC
134 snd_soc_dapm_add_routes(&card->dapm, audio_map,
135 ARRAY_SIZE(audio_map));
ee2f615d 136 }
310355c1
VB
137
138 /* not connected */
d343a660
LPC
139 snd_soc_dapm_nc_pin(&codec->dapm, "MONO_LOUT");
140 snd_soc_dapm_nc_pin(&codec->dapm, "HPLCOM");
141 snd_soc_dapm_nc_pin(&codec->dapm, "HPRCOM");
310355c1 142
310355c1
VB
143 return 0;
144}
145
146/* davinci-evm digital audio interface glue - connects codec <--> CPU */
bedad0ca 147static struct snd_soc_dai_link dm6446_evm_dai = {
310355c1
VB
148 .name = "TLV320AIC3X",
149 .stream_name = "AIC3X",
bedad0ca 150 .cpu_dai_name = "davinci-mcbsp",
f0fba2ad 151 .codec_dai_name = "tlv320aic3x-hifi",
bedad0ca 152 .codec_name = "tlv320aic3x-codec.1-001b",
f08095a4 153 .platform_name = "davinci-mcbsp",
bedad0ca
CPE
154 .init = evm_aic3x_init,
155 .ops = &evm_ops,
d38970e1
PU
156 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
157 SND_SOC_DAIFMT_IB_NF,
bedad0ca
CPE
158};
159
160static struct snd_soc_dai_link dm355_evm_dai = {
161 .name = "TLV320AIC3X",
162 .stream_name = "AIC3X",
163 .cpu_dai_name = "davinci-mcbsp.1",
164 .codec_dai_name = "tlv320aic3x-hifi",
165 .codec_name = "tlv320aic3x-codec.1-001b",
f08095a4 166 .platform_name = "davinci-mcbsp.1",
310355c1
VB
167 .init = evm_aic3x_init,
168 .ops = &evm_ops,
d38970e1
PU
169 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
170 SND_SOC_DAIFMT_IB_NF,
310355c1
VB
171};
172
aa9b88ee
MA
173static struct snd_soc_dai_link dm365_evm_dai = {
174#ifdef CONFIG_SND_DM365_AIC3X_CODEC
175 .name = "TLV320AIC3X",
176 .stream_name = "AIC3X",
bedad0ca 177 .cpu_dai_name = "davinci-mcbsp",
f0fba2ad 178 .codec_dai_name = "tlv320aic3x-hifi",
bedad0ca 179 .codec_name = "tlv320aic3x-codec.1-0018",
f08095a4 180 .platform_name = "davinci-mcbsp",
d38970e1
PU
181 .init = evm_aic3x_init,
182 .ops = &evm_ops,
183 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
184 SND_SOC_DAIFMT_IB_NF,
aa9b88ee
MA
185#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
186 .name = "Voice Codec - CQ93VC",
187 .stream_name = "CQ93",
f0fba2ad
LG
188 .cpu_dai_name = "davinci-vcif",
189 .codec_dai_name = "cq93vc-hifi",
190 .codec_name = "cq93vc-codec",
ffb690d5 191 .platform_name = "davinci-vcif",
aa9b88ee
MA
192#endif
193};
194
04f80f5c
C
195static struct snd_soc_dai_link dm6467_evm_dai[] = {
196 {
197 .name = "TLV320AIC3X",
198 .stream_name = "AIC3X",
f0fba2ad
LG
199 .cpu_dai_name= "davinci-mcasp.0",
200 .codec_dai_name = "tlv320aic3x-hifi",
f08095a4 201 .platform_name = "davinci-mcasp.0",
f0fba2ad 202 .codec_name = "tlv320aic3x-codec.0-001a",
04f80f5c
C
203 .init = evm_aic3x_init,
204 .ops = &evm_ops,
d38970e1
PU
205 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
206 SND_SOC_DAIFMT_IB_NF,
04f80f5c
C
207 },
208 {
209 .name = "McASP",
210 .stream_name = "spdif",
f0fba2ad
LG
211 .cpu_dai_name= "davinci-mcasp.1",
212 .codec_dai_name = "dit-hifi",
213 .codec_name = "spdif_dit",
f08095a4 214 .platform_name = "davinci-mcasp.1",
d38970e1
PU
215 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
216 SND_SOC_DAIFMT_IB_NF,
04f80f5c
C
217 },
218};
f9eb9dd1
VB
219
220static struct snd_soc_dai_link da830_evm_dai = {
221 .name = "TLV320AIC3X",
222 .stream_name = "AIC3X",
223 .cpu_dai_name = "davinci-mcasp.1",
224 .codec_dai_name = "tlv320aic3x-hifi",
225 .codec_name = "tlv320aic3x-codec.1-0018",
f08095a4 226 .platform_name = "davinci-mcasp.1",
f9eb9dd1
VB
227 .init = evm_aic3x_init,
228 .ops = &evm_ops,
d38970e1
PU
229 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
230 SND_SOC_DAIFMT_IB_NF,
f9eb9dd1
VB
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,
d38970e1
PU
242 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
243 SND_SOC_DAIFMT_IB_NF,
7ae5945f 244};
04f80f5c 245
bedad0ca 246/* davinci dm6446 evm audio machine driver */
bcf25567
JS
247/*
248 * ASP0 in DM6446 EVM is clocked by U55, as configured by
249 * board-dm644x-evm.c using GPIOs from U18. There are six
250 * options; here we "know" we use a 48 KHz sample rate.
251 */
252static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = {
253 .sysclk = 12288000,
254};
255
bedad0ca
CPE
256static struct snd_soc_card dm6446_snd_soc_card_evm = {
257 .name = "DaVinci DM6446 EVM",
36a16d1a 258 .owner = THIS_MODULE,
bedad0ca
CPE
259 .dai_link = &dm6446_evm_dai,
260 .num_links = 1,
bcf25567 261 .drvdata = &dm6446_snd_soc_card_drvdata,
bedad0ca
CPE
262};
263
264/* davinci dm355 evm audio machine driver */
bcf25567
JS
265/* ASP1 on DM355 EVM is clocked by an external oscillator */
266static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = {
267 .sysclk = 27000000,
268};
269
bedad0ca
CPE
270static struct snd_soc_card dm355_snd_soc_card_evm = {
271 .name = "DaVinci DM355 EVM",
36a16d1a 272 .owner = THIS_MODULE,
bedad0ca 273 .dai_link = &dm355_evm_dai,
310355c1 274 .num_links = 1,
bcf25567 275 .drvdata = &dm355_snd_soc_card_drvdata,
310355c1
VB
276};
277
aa9b88ee 278/* davinci dm365 evm audio machine driver */
bcf25567
JS
279static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = {
280 .sysclk = 27000000,
281};
282
aa9b88ee
MA
283static struct snd_soc_card dm365_snd_soc_card_evm = {
284 .name = "DaVinci DM365 EVM",
36a16d1a 285 .owner = THIS_MODULE,
aa9b88ee
MA
286 .dai_link = &dm365_evm_dai,
287 .num_links = 1,
bcf25567 288 .drvdata = &dm365_snd_soc_card_drvdata,
aa9b88ee
MA
289};
290
04f80f5c 291/* davinci dm6467 evm audio machine driver */
bcf25567
JS
292static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = {
293 .sysclk = 27000000,
294};
295
04f80f5c
C
296static struct snd_soc_card dm6467_snd_soc_card_evm = {
297 .name = "DaVinci DM6467 EVM",
36a16d1a 298 .owner = THIS_MODULE,
04f80f5c
C
299 .dai_link = dm6467_evm_dai,
300 .num_links = ARRAY_SIZE(dm6467_evm_dai),
bcf25567
JS
301 .drvdata = &dm6467_snd_soc_card_drvdata,
302};
303
304static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = {
305 .sysclk = 24576000,
04f80f5c
C
306};
307
7ae5945f 308static struct snd_soc_card da830_snd_soc_card = {
30230f4c 309 .name = "DA830/OMAP-L137 EVM",
36a16d1a 310 .owner = THIS_MODULE,
f9eb9dd1 311 .dai_link = &da830_evm_dai,
30230f4c 312 .num_links = 1,
bcf25567
JS
313 .drvdata = &da830_snd_soc_card_drvdata,
314};
315
316static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = {
317 .sysclk = 24576000,
30230f4c
C
318};
319
320static struct snd_soc_card da850_snd_soc_card = {
321 .name = "DA850/OMAP-L138 EVM",
36a16d1a 322 .owner = THIS_MODULE,
f9eb9dd1 323 .dai_link = &da850_evm_dai,
7ae5945f 324 .num_links = 1,
bcf25567 325 .drvdata = &da850_snd_soc_card_drvdata,
7ae5945f
C
326};
327
ee2f615d
HG
328#if defined(CONFIG_OF)
329
330/*
331 * The struct is used as place holder. It will be completely
332 * filled with data from dt node.
333 */
334static struct snd_soc_dai_link evm_dai_tlv320aic3x = {
335 .name = "TLV320AIC3X",
336 .stream_name = "AIC3X",
337 .codec_dai_name = "tlv320aic3x-hifi",
338 .ops = &evm_ops,
339 .init = evm_aic3x_init,
d38970e1
PU
340 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
341 SND_SOC_DAIFMT_IB_NF,
ee2f615d
HG
342};
343
344static const struct of_device_id davinci_evm_dt_ids[] = {
345 {
346 .compatible = "ti,da830-evm-audio",
347 .data = (void *) &evm_dai_tlv320aic3x,
348 },
349 { /* sentinel */ }
350};
351MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids);
352
353/* davinci evm audio machine driver */
354static struct snd_soc_card evm_soc_card = {
355 .owner = THIS_MODULE,
356 .num_links = 1,
357};
358
359static int davinci_evm_probe(struct platform_device *pdev)
360{
361 struct device_node *np = pdev->dev.of_node;
362 const struct of_device_id *match =
363 of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev);
364 struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data;
365 struct snd_soc_card_drvdata_davinci *drvdata = NULL;
5ad8865b 366 struct clk *mclk;
ee2f615d
HG
367 int ret = 0;
368
369 evm_soc_card.dai_link = dai;
370
371 dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0);
372 if (!dai->codec_of_node)
373 return -EINVAL;
374
375 dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
376 if (!dai->cpu_of_node)
377 return -EINVAL;
378
379 dai->platform_of_node = dai->cpu_of_node;
380
381 evm_soc_card.dev = &pdev->dev;
382 ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model");
383 if (ret)
384 return ret;
385
5ad8865b
JS
386 mclk = devm_clk_get(&pdev->dev, "mclk");
387 if (PTR_ERR(mclk) == -EPROBE_DEFER) {
388 return -EPROBE_DEFER;
389 } else if (IS_ERR(mclk)) {
390 dev_dbg(&pdev->dev, "mclk not found.\n");
391 mclk = NULL;
392 }
393
ee2f615d
HG
394 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
395 if (!drvdata)
396 return -ENOMEM;
397
5ad8865b
JS
398 drvdata->mclk = mclk;
399
ee2f615d 400 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
5ad8865b
JS
401
402 if (ret < 0) {
403 if (!drvdata->mclk) {
404 dev_err(&pdev->dev,
405 "No clock or clock rate defined.\n");
406 return -EINVAL;
407 }
408 drvdata->sysclk = clk_get_rate(drvdata->mclk);
409 } else if (drvdata->mclk) {
410 unsigned int requestd_rate = drvdata->sysclk;
411 clk_set_rate(drvdata->mclk, drvdata->sysclk);
412 drvdata->sysclk = clk_get_rate(drvdata->mclk);
413 if (drvdata->sysclk != requestd_rate)
414 dev_warn(&pdev->dev,
415 "Could not get requested rate %u using %u.\n",
416 requestd_rate, drvdata->sysclk);
417 }
ee2f615d
HG
418
419 snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
420 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
421
422 if (ret)
423 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
424
425 return ret;
426}
427
428static int davinci_evm_remove(struct platform_device *pdev)
429{
430 struct snd_soc_card *card = platform_get_drvdata(pdev);
431
432 snd_soc_unregister_card(card);
433
434 return 0;
435}
436
437static struct platform_driver davinci_evm_driver = {
438 .probe = davinci_evm_probe,
439 .remove = davinci_evm_remove,
440 .driver = {
441 .name = "davinci_evm",
fb6d208d 442 .pm = &snd_soc_pm_ops,
ee2f615d
HG
443 .of_match_table = of_match_ptr(davinci_evm_dt_ids),
444 },
445};
446#endif
447
310355c1
VB
448static struct platform_device *evm_snd_device;
449
450static int __init evm_init(void)
451{
f0fba2ad 452 struct snd_soc_card *evm_snd_dev_data;
f492ec9f 453 int index;
310355c1
VB
454 int ret;
455
ee2f615d
HG
456 /*
457 * If dtb is there, the devices will be created dynamically.
458 * Only register platfrom driver structure.
459 */
460#if defined(CONFIG_OF)
461 if (of_have_populated_dt())
462 return platform_driver_register(&davinci_evm_driver);
463#endif
464
aa9b88ee 465 if (machine_is_davinci_evm()) {
bedad0ca 466 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
f492ec9f
DB
467 index = 0;
468 } else if (machine_is_davinci_dm355_evm()) {
bedad0ca 469 evm_snd_dev_data = &dm355_snd_soc_card_evm;
f492ec9f 470 index = 1;
aa9b88ee 471 } else if (machine_is_davinci_dm365_evm()) {
f0fba2ad 472 evm_snd_dev_data = &dm365_snd_soc_card_evm;
aa9b88ee 473 index = 0;
04f80f5c 474 } else if (machine_is_davinci_dm6467_evm()) {
f0fba2ad 475 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
04f80f5c 476 index = 0;
7ae5945f 477 } else if (machine_is_davinci_da830_evm()) {
f0fba2ad 478 evm_snd_dev_data = &da830_snd_soc_card;
7ae5945f 479 index = 1;
30230f4c 480 } else if (machine_is_davinci_da850_evm()) {
f0fba2ad 481 evm_snd_dev_data = &da850_snd_soc_card;
30230f4c 482 index = 0;
f492ec9f
DB
483 } else
484 return -EINVAL;
485
486 evm_snd_device = platform_device_alloc("soc-audio", index);
310355c1
VB
487 if (!evm_snd_device)
488 return -ENOMEM;
489
04f80f5c 490 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
310355c1
VB
491 ret = platform_device_add(evm_snd_device);
492 if (ret)
493 platform_device_put(evm_snd_device);
494
495 return ret;
496}
497
498static void __exit evm_exit(void)
499{
ee2f615d
HG
500#if defined(CONFIG_OF)
501 if (of_have_populated_dt()) {
502 platform_driver_unregister(&davinci_evm_driver);
503 return;
504 }
505#endif
506
310355c1
VB
507 platform_device_unregister(evm_snd_device);
508}
509
510module_init(evm_init);
511module_exit(evm_exit);
512
513MODULE_AUTHOR("Vladimir Barinov");
514MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
515MODULE_LICENSE("GPL");