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/i2c.h>
18 #include <sound/core.h>
19 #include <sound/pcm.h>
20 #include <sound/soc.h>
21 #include <sound/soc-dapm.h>
24 #include <asm/mach-types.h>
27 #include <mach/edma.h>
30 #include "../codecs/tlv320aic3x.h"
31 #include "../codecs/spdif_transciever.h"
32 #include "davinci-pcm.h"
33 #include "davinci-i2s.h"
34 #include "davinci-mcasp.h"
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
->dai
->codec_dai
;
43 struct snd_soc_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
47 /* ASP1 on DM355 EVM is clocked by an external oscillator */
48 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm())
51 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
52 * board-dm644x-evm.c using GPIOs from U18. There are six
53 * options; here we "know" we use a 48 KHz sample rate.
55 else if (machine_is_davinci_evm())
58 else if (machine_is_davinci_da830_evm() ||
59 machine_is_davinci_da850_evm())
65 /* set codec DAI configuration */
66 ret
= snd_soc_dai_set_fmt(codec_dai
, AUDIO_FORMAT
);
70 /* set cpu DAI configuration */
71 ret
= snd_soc_dai_set_fmt(cpu_dai
, AUDIO_FORMAT
);
75 /* set the codec system clock */
76 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, sysclk
, SND_SOC_CLOCK_OUT
);
83 static struct snd_soc_ops evm_ops
= {
84 .hw_params
= evm_hw_params
,
87 /* davinci-evm machine dapm widgets */
88 static const struct snd_soc_dapm_widget aic3x_dapm_widgets
[] = {
89 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
90 SND_SOC_DAPM_LINE("Line Out", NULL
),
91 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
92 SND_SOC_DAPM_LINE("Line In", NULL
),
95 /* davinci-evm machine audio_mapnections to the codec pins */
96 static const struct snd_soc_dapm_route audio_map
[] = {
97 /* Headphone connected to HPLOUT, HPROUT */
98 {"Headphone Jack", NULL
, "HPLOUT"},
99 {"Headphone Jack", NULL
, "HPROUT"},
101 /* Line Out connected to LLOUT, RLOUT */
102 {"Line Out", NULL
, "LLOUT"},
103 {"Line Out", NULL
, "RLOUT"},
105 /* Mic connected to (MIC3L | MIC3R) */
106 {"MIC3L", NULL
, "Mic Bias 2V"},
107 {"MIC3R", NULL
, "Mic Bias 2V"},
108 {"Mic Bias 2V", NULL
, "Mic Jack"},
110 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
111 {"LINE1L", NULL
, "Line In"},
112 {"LINE2L", NULL
, "Line In"},
113 {"LINE1R", NULL
, "Line In"},
114 {"LINE2R", NULL
, "Line In"},
117 /* Logic for a aic3x as connected on a davinci-evm */
118 static int evm_aic3x_init(struct snd_soc_codec
*codec
)
120 /* Add davinci-evm specific widgets */
121 snd_soc_dapm_new_controls(codec
, aic3x_dapm_widgets
,
122 ARRAY_SIZE(aic3x_dapm_widgets
));
124 /* Set up davinci-evm specific audio path audio_map */
125 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
128 snd_soc_dapm_disable_pin(codec
, "MONO_LOUT");
129 snd_soc_dapm_disable_pin(codec
, "HPLCOM");
130 snd_soc_dapm_disable_pin(codec
, "HPRCOM");
132 /* always connected */
133 snd_soc_dapm_enable_pin(codec
, "Headphone Jack");
134 snd_soc_dapm_enable_pin(codec
, "Line Out");
135 snd_soc_dapm_enable_pin(codec
, "Mic Jack");
136 snd_soc_dapm_enable_pin(codec
, "Line In");
138 snd_soc_dapm_sync(codec
);
143 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
144 static struct snd_soc_dai_link evm_dai
= {
145 .name
= "TLV320AIC3X",
146 .stream_name
= "AIC3X",
147 .cpu_dai
= &davinci_i2s_dai
,
148 .codec_dai
= &aic3x_dai
,
149 .init
= evm_aic3x_init
,
153 static struct snd_soc_dai_link dm6467_evm_dai
[] = {
155 .name
= "TLV320AIC3X",
156 .stream_name
= "AIC3X",
157 .cpu_dai
= &davinci_mcasp_dai
[DAVINCI_MCASP_I2S_DAI
],
158 .codec_dai
= &aic3x_dai
,
159 .init
= evm_aic3x_init
,
164 .stream_name
= "spdif",
165 .cpu_dai
= &davinci_mcasp_dai
[DAVINCI_MCASP_DIT_DAI
],
166 .codec_dai
= &dit_stub_dai
,
170 static struct snd_soc_dai_link da8xx_evm_dai
= {
171 .name
= "TLV320AIC3X",
172 .stream_name
= "AIC3X",
173 .cpu_dai
= &davinci_mcasp_dai
[DAVINCI_MCASP_I2S_DAI
],
174 .codec_dai
= &aic3x_dai
,
175 .init
= evm_aic3x_init
,
179 /* davinci-evm audio machine driver */
180 static struct snd_soc_card snd_soc_card_evm
= {
181 .name
= "DaVinci EVM",
182 .platform
= &davinci_soc_platform
,
183 .dai_link
= &evm_dai
,
187 /* davinci dm6467 evm audio machine driver */
188 static struct snd_soc_card dm6467_snd_soc_card_evm
= {
189 .name
= "DaVinci DM6467 EVM",
190 .platform
= &davinci_soc_platform
,
191 .dai_link
= dm6467_evm_dai
,
192 .num_links
= ARRAY_SIZE(dm6467_evm_dai
),
195 static struct snd_soc_card da830_snd_soc_card
= {
196 .name
= "DA830/OMAP-L137 EVM",
197 .dai_link
= &da8xx_evm_dai
,
198 .platform
= &davinci_soc_platform
,
202 static struct snd_soc_card da850_snd_soc_card
= {
203 .name
= "DA850/OMAP-L138 EVM",
204 .dai_link
= &da8xx_evm_dai
,
205 .platform
= &davinci_soc_platform
,
209 static struct aic3x_setup_data aic3x_setup
;
211 /* evm audio subsystem */
212 static struct snd_soc_device evm_snd_devdata
= {
213 .card
= &snd_soc_card_evm
,
214 .codec_dev
= &soc_codec_dev_aic3x
,
215 .codec_data
= &aic3x_setup
,
218 /* evm audio subsystem */
219 static struct snd_soc_device dm6467_evm_snd_devdata
= {
220 .card
= &dm6467_snd_soc_card_evm
,
221 .codec_dev
= &soc_codec_dev_aic3x
,
222 .codec_data
= &aic3x_setup
,
225 /* evm audio subsystem */
226 static struct snd_soc_device da830_evm_snd_devdata
= {
227 .card
= &da830_snd_soc_card
,
228 .codec_dev
= &soc_codec_dev_aic3x
,
229 .codec_data
= &aic3x_setup
,
232 static struct snd_soc_device da850_evm_snd_devdata
= {
233 .card
= &da850_snd_soc_card
,
234 .codec_dev
= &soc_codec_dev_aic3x
,
235 .codec_data
= &aic3x_setup
,
238 static struct platform_device
*evm_snd_device
;
240 static int __init
evm_init(void)
242 struct snd_soc_device
*evm_snd_dev_data
;
246 if (machine_is_davinci_evm()) {
247 evm_snd_dev_data
= &evm_snd_devdata
;
249 } else if (machine_is_davinci_dm355_evm()) {
250 evm_snd_dev_data
= &evm_snd_devdata
;
252 } else if (machine_is_davinci_dm6467_evm()) {
253 evm_snd_dev_data
= &dm6467_evm_snd_devdata
;
255 } else if (machine_is_davinci_da830_evm()) {
256 evm_snd_dev_data
= &da830_evm_snd_devdata
;
258 } else if (machine_is_davinci_da850_evm()) {
259 evm_snd_dev_data
= &da850_evm_snd_devdata
;
264 evm_snd_device
= platform_device_alloc("soc-audio", index
);
268 platform_set_drvdata(evm_snd_device
, evm_snd_dev_data
);
269 evm_snd_dev_data
->dev
= &evm_snd_device
->dev
;
270 ret
= platform_device_add(evm_snd_device
);
272 platform_device_put(evm_snd_device
);
277 static void __exit
evm_exit(void)
279 platform_device_unregister(evm_snd_device
);
282 module_init(evm_init
);
283 module_exit(evm_exit
);
285 MODULE_AUTHOR("Vladimir Barinov");
286 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
287 MODULE_LICENSE("GPL");