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 <sound/core.h>
18 #include <sound/pcm.h>
19 #include <sound/soc.h>
20 #include <sound/soc-dapm.h>
23 #include <asm/mach-types.h>
26 #include <mach/edma.h>
29 #include "../codecs/tlv320aic3x.h"
30 #include "../codecs/spdif_transciever.h"
31 #include "davinci-pcm.h"
32 #include "davinci-i2s.h"
33 #include "davinci-mcasp.h"
35 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
36 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
37 static int evm_hw_params(struct snd_pcm_substream *substream,
38 struct snd_pcm_hw_params *params)
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
41 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
42 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
46 /* ASP1 on DM355 EVM is clocked by an external oscillator */
47 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm())
50 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
51 * board-dm644x-evm.c using GPIOs from U18. There are six
52 * options; here we "know" we use a 48 KHz sample rate.
54 else if (machine_is_davinci_evm())
57 else if (machine_is_davinci_da830_evm())
63 /* set codec DAI configuration */
64 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
68 /* set cpu DAI configuration */
69 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
73 /* set the codec system clock */
74 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
81 static struct snd_soc_ops evm_ops = {
82 .hw_params = evm_hw_params,
85 /* davinci-evm machine dapm widgets */
86 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
87 SND_SOC_DAPM_HP("Headphone Jack", NULL),
88 SND_SOC_DAPM_LINE("Line Out", NULL),
89 SND_SOC_DAPM_MIC("Mic Jack", NULL),
90 SND_SOC_DAPM_LINE("Line In", NULL),
93 /* davinci-evm machine audio_mapnections to the codec pins */
94 static const struct snd_soc_dapm_route audio_map[] = {
95 /* Headphone connected to HPLOUT, HPROUT */
96 {"Headphone Jack", NULL, "HPLOUT"},
97 {"Headphone Jack", NULL, "HPROUT"},
99 /* Line Out connected to LLOUT, RLOUT */
100 {"Line Out", NULL, "LLOUT"},
101 {"Line Out", NULL, "RLOUT"},
103 /* Mic connected to (MIC3L | MIC3R) */
104 {"MIC3L", NULL, "Mic Bias 2V"},
105 {"MIC3R", NULL, "Mic Bias 2V"},
106 {"Mic Bias 2V", NULL, "Mic Jack"},
108 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
109 {"LINE1L", NULL, "Line In"},
110 {"LINE2L", NULL, "Line In"},
111 {"LINE1R", NULL, "Line In"},
112 {"LINE2R", NULL, "Line In"},
115 /* Logic for a aic3x as connected on a davinci-evm */
116 static int evm_aic3x_init(struct snd_soc_codec *codec)
118 /* Add davinci-evm specific widgets */
119 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
120 ARRAY_SIZE(aic3x_dapm_widgets));
122 /* Set up davinci-evm specific audio path audio_map */
123 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
126 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
127 snd_soc_dapm_disable_pin(codec, "HPLCOM");
128 snd_soc_dapm_disable_pin(codec, "HPRCOM");
130 /* always connected */
131 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
132 snd_soc_dapm_enable_pin(codec, "Line Out");
133 snd_soc_dapm_enable_pin(codec, "Mic Jack");
134 snd_soc_dapm_enable_pin(codec, "Line In");
136 snd_soc_dapm_sync(codec);
141 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
142 static struct snd_soc_dai_link evm_dai = {
143 .name = "TLV320AIC3X",
144 .stream_name = "AIC3X",
145 .cpu_dai = &davinci_i2s_dai,
146 .codec_dai = &aic3x_dai,
147 .init = evm_aic3x_init,
151 static struct snd_soc_dai_link dm6467_evm_dai[] = {
153 .name = "TLV320AIC3X",
154 .stream_name = "AIC3X",
155 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
156 .codec_dai = &aic3x_dai,
157 .init = evm_aic3x_init,
162 .stream_name = "spdif",
163 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
164 .codec_dai = &dit_stub_dai,
168 static struct snd_soc_dai_link da830_evm_dai = {
169 .name = "TLV320AIC3X",
170 .stream_name = "AIC3X",
171 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
172 .codec_dai = &aic3x_dai,
173 .init = evm_aic3x_init,
177 /* davinci-evm audio machine driver */
178 static struct snd_soc_card snd_soc_card_evm = {
179 .name = "DaVinci EVM",
180 .platform = &davinci_soc_platform,
181 .dai_link = &evm_dai,
185 /* davinci dm6467 evm audio machine driver */
186 static struct snd_soc_card dm6467_snd_soc_card_evm = {
187 .name = "DaVinci DM6467 EVM",
188 .platform = &davinci_soc_platform,
189 .dai_link = dm6467_evm_dai,
190 .num_links = ARRAY_SIZE(dm6467_evm_dai),
193 static struct snd_soc_card da830_snd_soc_card = {
195 .dai_link = &da830_evm_dai,
196 .platform = &davinci_soc_platform,
200 /* evm audio private data */
201 static struct aic3x_setup_data evm_aic3x_setup = {
206 /* dm6467 evm audio private data */
207 static struct aic3x_setup_data dm6467_evm_aic3x_setup = {
212 static struct aic3x_setup_data da830_evm_aic3x_setup = {
217 /* evm audio subsystem */
218 static struct snd_soc_device evm_snd_devdata = {
219 .card = &snd_soc_card_evm,
220 .codec_dev = &soc_codec_dev_aic3x,
221 .codec_data = &evm_aic3x_setup,
224 /* evm audio subsystem */
225 static struct snd_soc_device dm6467_evm_snd_devdata = {
226 .card = &dm6467_snd_soc_card_evm,
227 .codec_dev = &soc_codec_dev_aic3x,
228 .codec_data = &dm6467_evm_aic3x_setup,
231 /* evm audio subsystem */
232 static struct snd_soc_device da830_evm_snd_devdata = {
233 .card = &da830_snd_soc_card,
234 .codec_dev = &soc_codec_dev_aic3x,
235 .codec_data = &da830_evm_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;
261 evm_snd_device = platform_device_alloc("soc-audio", index);
265 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
266 evm_snd_dev_data->dev = &evm_snd_device->dev;
267 ret = platform_device_add(evm_snd_device);
269 platform_device_put(evm_snd_device);
274 static void __exit evm_exit(void)
276 platform_device_unregister(evm_snd_device);
279 module_init(evm_init);
280 module_exit(evm_exit);
282 MODULE_AUTHOR("Vladimir Barinov");
283 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
284 MODULE_LICENSE("GPL");