1 // SPDX-License-Identifier: GPL-2.0-only
3 * ASoC driver for TI DAVINCI EVM platform
5 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
6 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/timer.h>
12 #include <linux/interrupt.h>
13 #include <linux/platform_device.h>
14 #include <linux/i2c.h>
15 #include <linux/of_platform.h>
16 #include <linux/clk.h>
17 #include <sound/core.h>
18 #include <sound/pcm.h>
19 #include <sound/soc.h>
22 #include <asm/mach-types.h>
24 struct snd_soc_card_drvdata_davinci
{
29 static int evm_startup(struct snd_pcm_substream
*substream
)
31 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
32 struct snd_soc_card
*soc_card
= rtd
->card
;
33 struct snd_soc_card_drvdata_davinci
*drvdata
=
34 snd_soc_card_get_drvdata(soc_card
);
37 return clk_prepare_enable(drvdata
->mclk
);
42 static void evm_shutdown(struct snd_pcm_substream
*substream
)
44 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
45 struct snd_soc_card
*soc_card
= rtd
->card
;
46 struct snd_soc_card_drvdata_davinci
*drvdata
=
47 snd_soc_card_get_drvdata(soc_card
);
49 clk_disable_unprepare(drvdata
->mclk
);
52 static int evm_hw_params(struct snd_pcm_substream
*substream
,
53 struct snd_pcm_hw_params
*params
)
55 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
56 struct snd_soc_dai
*codec_dai
= asoc_rtd_to_codec(rtd
, 0);
57 struct snd_soc_dai
*cpu_dai
= asoc_rtd_to_cpu(rtd
, 0);
58 struct snd_soc_card
*soc_card
= rtd
->card
;
60 unsigned sysclk
= ((struct snd_soc_card_drvdata_davinci
*)
61 snd_soc_card_get_drvdata(soc_card
))->sysclk
;
63 /* set the codec system clock */
64 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, sysclk
, SND_SOC_CLOCK_OUT
);
68 /* set the CPU system clock */
69 ret
= snd_soc_dai_set_sysclk(cpu_dai
, 0, sysclk
, SND_SOC_CLOCK_OUT
);
70 if (ret
< 0 && ret
!= -ENOTSUPP
)
76 static struct snd_soc_ops evm_ops
= {
77 .startup
= evm_startup
,
78 .shutdown
= evm_shutdown
,
79 .hw_params
= evm_hw_params
,
82 /* davinci-evm machine dapm widgets */
83 static const struct snd_soc_dapm_widget aic3x_dapm_widgets
[] = {
84 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
85 SND_SOC_DAPM_LINE("Line Out", NULL
),
86 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
87 SND_SOC_DAPM_LINE("Line In", NULL
),
90 /* davinci-evm machine audio_mapnections to the codec pins */
91 static const struct snd_soc_dapm_route audio_map
[] = {
92 /* Headphone connected to HPLOUT, HPROUT */
93 {"Headphone Jack", NULL
, "HPLOUT"},
94 {"Headphone Jack", NULL
, "HPROUT"},
96 /* Line Out connected to LLOUT, RLOUT */
97 {"Line Out", NULL
, "LLOUT"},
98 {"Line Out", NULL
, "RLOUT"},
100 /* Mic connected to (MIC3L | MIC3R) */
101 {"MIC3L", NULL
, "Mic Bias"},
102 {"MIC3R", NULL
, "Mic Bias"},
103 {"Mic Bias", NULL
, "Mic Jack"},
105 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
106 {"LINE1L", NULL
, "Line In"},
107 {"LINE2L", NULL
, "Line In"},
108 {"LINE1R", NULL
, "Line In"},
109 {"LINE2R", NULL
, "Line In"},
112 /* Logic for a aic3x as connected on a davinci-evm */
113 static int evm_aic3x_init(struct snd_soc_pcm_runtime
*rtd
)
115 struct snd_soc_card
*card
= rtd
->card
;
116 struct device_node
*np
= card
->dev
->of_node
;
119 /* Add davinci-evm specific widgets */
120 snd_soc_dapm_new_controls(&card
->dapm
, aic3x_dapm_widgets
,
121 ARRAY_SIZE(aic3x_dapm_widgets
));
124 ret
= snd_soc_of_parse_audio_routing(card
, "ti,audio-routing");
128 /* Set up davinci-evm specific audio path audio_map */
129 snd_soc_dapm_add_routes(&card
->dapm
, audio_map
,
130 ARRAY_SIZE(audio_map
));
134 snd_soc_dapm_nc_pin(&card
->dapm
, "MONO_LOUT");
135 snd_soc_dapm_nc_pin(&card
->dapm
, "HPLCOM");
136 snd_soc_dapm_nc_pin(&card
->dapm
, "HPRCOM");
141 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
142 SND_SOC_DAILINK_DEFS(dm6446
,
143 DAILINK_COMP_ARRAY(COMP_CPU("davinci-mcbsp")),
144 DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x-codec.1-001b",
145 "tlv320aic3x-hifi")),
146 DAILINK_COMP_ARRAY(COMP_PLATFORM("davinci-mcbsp")));
148 static struct snd_soc_dai_link dm6446_evm_dai
= {
149 .name
= "TLV320AIC3X",
150 .stream_name
= "AIC3X",
151 .init
= evm_aic3x_init
,
153 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
154 SND_SOC_DAIFMT_IB_NF
,
155 SND_SOC_DAILINK_REG(dm6446
),
158 SND_SOC_DAILINK_DEFS(dm355
,
159 DAILINK_COMP_ARRAY(COMP_CPU("davinci-mcbsp.1")),
160 DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x-codec.1-001b",
161 "tlv320aic3x-hifi")),
162 DAILINK_COMP_ARRAY(COMP_PLATFORM("davinci-mcbsp.1")));
164 static struct snd_soc_dai_link dm355_evm_dai
= {
165 .name
= "TLV320AIC3X",
166 .stream_name
= "AIC3X",
167 .init
= evm_aic3x_init
,
169 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
170 SND_SOC_DAIFMT_IB_NF
,
171 SND_SOC_DAILINK_REG(dm355
),
174 #ifdef CONFIG_SND_SOC_DM365_AIC3X_CODEC
175 SND_SOC_DAILINK_DEFS(dm365
,
176 DAILINK_COMP_ARRAY(COMP_CPU("davinci-mcbsp")),
177 DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x-codec.1-0018",
178 "tlv320aic3x-hifi")),
179 DAILINK_COMP_ARRAY(COMP_PLATFORM("davinci-mcbsp")));
180 #elif defined(CONFIG_SND_SOC_DM365_VOICE_CODEC)
181 SND_SOC_DAILINK_DEFS(dm365
,
182 DAILINK_COMP_ARRAY(COMP_CPU("davinci-vcif")),
183 DAILINK_COMP_ARRAY(COMP_CODEC("cq93vc-codec", "cq93vc-hifi")),
184 DAILINK_COMP_ARRAY(COMP_PLATFORM("davinci-vcif")));
187 static struct snd_soc_dai_link dm365_evm_dai
= {
188 #ifdef CONFIG_SND_SOC_DM365_AIC3X_CODEC
189 .name
= "TLV320AIC3X",
190 .stream_name
= "AIC3X",
191 .init
= evm_aic3x_init
,
193 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
194 SND_SOC_DAIFMT_IB_NF
,
195 SND_SOC_DAILINK_REG(dm365
),
196 #elif defined(CONFIG_SND_SOC_DM365_VOICE_CODEC)
197 .name
= "Voice Codec - CQ93VC",
198 .stream_name
= "CQ93",
199 SND_SOC_DAILINK_REG(dm365
),
203 SND_SOC_DAILINK_DEFS(dm6467_aic3x
,
204 DAILINK_COMP_ARRAY(COMP_CPU("davinci-mcasp.0")),
205 DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x-codec.0-001a",
206 "tlv320aic3x-hifi")),
207 DAILINK_COMP_ARRAY(COMP_PLATFORM("davinci-mcasp.0")));
209 SND_SOC_DAILINK_DEFS(dm6467_spdif
,
210 DAILINK_COMP_ARRAY(COMP_CPU("davinci-mcasp.1")),
211 DAILINK_COMP_ARRAY(COMP_CODEC("spdif_dit", "dit-hifi")),
212 DAILINK_COMP_ARRAY(COMP_PLATFORM("davinci-mcasp.1")));
214 static struct snd_soc_dai_link dm6467_evm_dai
[] = {
216 .name
= "TLV320AIC3X",
217 .stream_name
= "AIC3X",
218 .init
= evm_aic3x_init
,
220 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
221 SND_SOC_DAIFMT_IB_NF
,
222 SND_SOC_DAILINK_REG(dm6467_aic3x
),
226 .stream_name
= "spdif",
227 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
228 SND_SOC_DAIFMT_IB_NF
,
229 SND_SOC_DAILINK_REG(dm6467_spdif
),
233 SND_SOC_DAILINK_DEFS(da830
,
234 DAILINK_COMP_ARRAY(COMP_CPU("davinci-mcasp.1")),
235 DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x-codec.1-0018",
236 "tlv320aic3x-hifi")),
237 DAILINK_COMP_ARRAY(COMP_PLATFORM("davinci-mcasp.1")));
239 static struct snd_soc_dai_link da830_evm_dai
= {
240 .name
= "TLV320AIC3X",
241 .stream_name
= "AIC3X",
242 .init
= evm_aic3x_init
,
244 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
245 SND_SOC_DAIFMT_IB_NF
,
246 SND_SOC_DAILINK_REG(da830
),
249 SND_SOC_DAILINK_DEFS(da850
,
250 DAILINK_COMP_ARRAY(COMP_CPU("davinci-mcasp.0")),
251 DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x-codec.1-0018",
252 "tlv320aic3x-hifi")),
253 DAILINK_COMP_ARRAY(COMP_PLATFORM("davinci-mcasp.0")));
255 static struct snd_soc_dai_link da850_evm_dai
= {
256 .name
= "TLV320AIC3X",
257 .stream_name
= "AIC3X",
258 .init
= evm_aic3x_init
,
260 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
261 SND_SOC_DAIFMT_IB_NF
,
262 SND_SOC_DAILINK_REG(da850
),
265 /* davinci dm6446 evm audio machine driver */
267 * ASP0 in DM6446 EVM is clocked by U55, as configured by
268 * board-dm644x-evm.c using GPIOs from U18. There are six
269 * options; here we "know" we use a 48 KHz sample rate.
271 static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata
= {
275 static struct snd_soc_card dm6446_snd_soc_card_evm
= {
276 .name
= "DaVinci DM6446 EVM",
277 .owner
= THIS_MODULE
,
278 .dai_link
= &dm6446_evm_dai
,
280 .drvdata
= &dm6446_snd_soc_card_drvdata
,
283 /* davinci dm355 evm audio machine driver */
284 /* ASP1 on DM355 EVM is clocked by an external oscillator */
285 static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata
= {
289 static struct snd_soc_card dm355_snd_soc_card_evm
= {
290 .name
= "DaVinci DM355 EVM",
291 .owner
= THIS_MODULE
,
292 .dai_link
= &dm355_evm_dai
,
294 .drvdata
= &dm355_snd_soc_card_drvdata
,
297 /* davinci dm365 evm audio machine driver */
298 static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata
= {
302 static struct snd_soc_card dm365_snd_soc_card_evm
= {
303 .name
= "DaVinci DM365 EVM",
304 .owner
= THIS_MODULE
,
305 .dai_link
= &dm365_evm_dai
,
307 .drvdata
= &dm365_snd_soc_card_drvdata
,
310 /* davinci dm6467 evm audio machine driver */
311 static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata
= {
315 static struct snd_soc_card dm6467_snd_soc_card_evm
= {
316 .name
= "DaVinci DM6467 EVM",
317 .owner
= THIS_MODULE
,
318 .dai_link
= dm6467_evm_dai
,
319 .num_links
= ARRAY_SIZE(dm6467_evm_dai
),
320 .drvdata
= &dm6467_snd_soc_card_drvdata
,
323 static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata
= {
327 static struct snd_soc_card da830_snd_soc_card
= {
328 .name
= "DA830/OMAP-L137 EVM",
329 .owner
= THIS_MODULE
,
330 .dai_link
= &da830_evm_dai
,
332 .drvdata
= &da830_snd_soc_card_drvdata
,
335 static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata
= {
339 static struct snd_soc_card da850_snd_soc_card
= {
340 .name
= "DA850/OMAP-L138 EVM",
341 .owner
= THIS_MODULE
,
342 .dai_link
= &da850_evm_dai
,
344 .drvdata
= &da850_snd_soc_card_drvdata
,
347 #if defined(CONFIG_OF)
350 * The struct is used as place holder. It will be completely
351 * filled with data from dt node.
353 SND_SOC_DAILINK_DEFS(evm
,
354 DAILINK_COMP_ARRAY(COMP_EMPTY()),
355 DAILINK_COMP_ARRAY(COMP_CODEC(NULL
, "tlv320aic3x-hifi")),
356 DAILINK_COMP_ARRAY(COMP_EMPTY()));
358 static struct snd_soc_dai_link evm_dai_tlv320aic3x
= {
359 .name
= "TLV320AIC3X",
360 .stream_name
= "AIC3X",
362 .init
= evm_aic3x_init
,
363 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
|
364 SND_SOC_DAIFMT_IB_NF
,
365 SND_SOC_DAILINK_REG(evm
),
368 static const struct of_device_id davinci_evm_dt_ids
[] = {
370 .compatible
= "ti,da830-evm-audio",
371 .data
= (void *) &evm_dai_tlv320aic3x
,
375 MODULE_DEVICE_TABLE(of
, davinci_evm_dt_ids
);
377 /* davinci evm audio machine driver */
378 static struct snd_soc_card evm_soc_card
= {
379 .owner
= THIS_MODULE
,
383 static int davinci_evm_probe(struct platform_device
*pdev
)
385 struct device_node
*np
= pdev
->dev
.of_node
;
386 const struct of_device_id
*match
;
387 struct snd_soc_dai_link
*dai
;
388 struct snd_soc_card_drvdata_davinci
*drvdata
= NULL
;
392 match
= of_match_device(of_match_ptr(davinci_evm_dt_ids
), &pdev
->dev
);
394 dev_err(&pdev
->dev
, "Error: No device match found\n");
398 dai
= (struct snd_soc_dai_link
*) match
->data
;
400 evm_soc_card
.dai_link
= dai
;
402 dai
->codecs
->of_node
= of_parse_phandle(np
, "ti,audio-codec", 0);
403 if (!dai
->codecs
->of_node
)
406 dai
->cpus
->of_node
= of_parse_phandle(np
, "ti,mcasp-controller", 0);
407 if (!dai
->cpus
->of_node
)
410 dai
->platforms
->of_node
= dai
->cpus
->of_node
;
412 evm_soc_card
.dev
= &pdev
->dev
;
413 ret
= snd_soc_of_parse_card_name(&evm_soc_card
, "ti,model");
417 mclk
= devm_clk_get(&pdev
->dev
, "mclk");
418 if (PTR_ERR(mclk
) == -EPROBE_DEFER
) {
419 return -EPROBE_DEFER
;
420 } else if (IS_ERR(mclk
)) {
421 dev_dbg(&pdev
->dev
, "mclk not found.\n");
425 drvdata
= devm_kzalloc(&pdev
->dev
, sizeof(*drvdata
), GFP_KERNEL
);
429 drvdata
->mclk
= mclk
;
431 ret
= of_property_read_u32(np
, "ti,codec-clock-rate", &drvdata
->sysclk
);
434 if (!drvdata
->mclk
) {
436 "No clock or clock rate defined.\n");
439 drvdata
->sysclk
= clk_get_rate(drvdata
->mclk
);
440 } else if (drvdata
->mclk
) {
441 unsigned int requestd_rate
= drvdata
->sysclk
;
442 clk_set_rate(drvdata
->mclk
, drvdata
->sysclk
);
443 drvdata
->sysclk
= clk_get_rate(drvdata
->mclk
);
444 if (drvdata
->sysclk
!= requestd_rate
)
446 "Could not get requested rate %u using %u.\n",
447 requestd_rate
, drvdata
->sysclk
);
450 snd_soc_card_set_drvdata(&evm_soc_card
, drvdata
);
451 ret
= devm_snd_soc_register_card(&pdev
->dev
, &evm_soc_card
);
454 dev_err(&pdev
->dev
, "snd_soc_register_card failed (%d)\n", ret
);
459 static struct platform_driver davinci_evm_driver
= {
460 .probe
= davinci_evm_probe
,
462 .name
= "davinci_evm",
463 .pm
= &snd_soc_pm_ops
,
464 .of_match_table
= of_match_ptr(davinci_evm_dt_ids
),
469 static struct platform_device
*evm_snd_device
;
471 static int __init
evm_init(void)
473 struct snd_soc_card
*evm_snd_dev_data
;
478 * If dtb is there, the devices will be created dynamically.
479 * Only register platfrom driver structure.
481 #if defined(CONFIG_OF)
482 if (of_have_populated_dt())
483 return platform_driver_register(&davinci_evm_driver
);
486 if (machine_is_davinci_evm()) {
487 evm_snd_dev_data
= &dm6446_snd_soc_card_evm
;
489 } else if (machine_is_davinci_dm355_evm()) {
490 evm_snd_dev_data
= &dm355_snd_soc_card_evm
;
492 } else if (machine_is_davinci_dm365_evm()) {
493 evm_snd_dev_data
= &dm365_snd_soc_card_evm
;
495 } else if (machine_is_davinci_dm6467_evm()) {
496 evm_snd_dev_data
= &dm6467_snd_soc_card_evm
;
498 } else if (machine_is_davinci_da830_evm()) {
499 evm_snd_dev_data
= &da830_snd_soc_card
;
501 } else if (machine_is_davinci_da850_evm()) {
502 evm_snd_dev_data
= &da850_snd_soc_card
;
507 evm_snd_device
= platform_device_alloc("soc-audio", index
);
511 platform_set_drvdata(evm_snd_device
, evm_snd_dev_data
);
512 ret
= platform_device_add(evm_snd_device
);
514 platform_device_put(evm_snd_device
);
519 static void __exit
evm_exit(void)
521 #if defined(CONFIG_OF)
522 if (of_have_populated_dt()) {
523 platform_driver_unregister(&davinci_evm_driver
);
528 platform_device_unregister(evm_snd_device
);
531 module_init(evm_init
);
532 module_exit(evm_exit
);
534 MODULE_AUTHOR("Vladimir Barinov");
535 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
536 MODULE_LICENSE("GPL");