ASoC: DaVinci: CQ93VC Voice Codec
[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>
aa6b904e 17#include <linux/i2c.h>
310355c1
VB
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22
310355c1 23#include <asm/dma.h>
f492ec9f
DB
24#include <asm/mach-types.h>
25
26#include <mach/asp.h>
27#include <mach/edma.h>
28#include <mach/mux.h>
310355c1
VB
29
30#include "../codecs/tlv320aic3x.h"
04f80f5c 31#include "../codecs/spdif_transciever.h"
310355c1
VB
32#include "davinci-pcm.h"
33#include "davinci-i2s.h"
04f80f5c 34#include "davinci-mcasp.h"
310355c1 35
d6f83396
TK
36#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
37 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
310355c1
VB
38static int evm_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
40{
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
9cb132d7
LG
42 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
310355c1 44 int ret = 0;
05d5e991
DB
45 unsigned sysclk;
46
47 /* ASP1 on DM355 EVM is clocked by an external oscillator */
9b95b166
MA
48 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
49 machine_is_davinci_dm365_evm())
05d5e991
DB
50 sysclk = 27000000;
51
52 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
53 * board-dm644x-evm.c using GPIOs from U18. There are six
54 * options; here we "know" we use a 48 KHz sample rate.
55 */
56 else if (machine_is_davinci_evm())
57 sysclk = 12288000;
58
30230f4c
C
59 else if (machine_is_davinci_da830_evm() ||
60 machine_is_davinci_da850_evm())
7ae5945f
C
61 sysclk = 24576000;
62
05d5e991
DB
63 else
64 return -EINVAL;
310355c1
VB
65
66 /* set codec DAI configuration */
9e031624 67 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
310355c1
VB
68 if (ret < 0)
69 return ret;
70
71 /* set cpu DAI configuration */
9e031624 72 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
310355c1
VB
73 if (ret < 0)
74 return ret;
75
76 /* set the codec system clock */
05d5e991 77 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
310355c1
VB
78 if (ret < 0)
79 return ret;
80
81 return 0;
82}
83
8d43d1bc
C
84static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
85 struct snd_pcm_hw_params *params)
86{
87 struct snd_soc_pcm_runtime *rtd = substream->private_data;
88 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
89
90 /* set cpu DAI configuration */
91 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
92}
93
310355c1
VB
94static struct snd_soc_ops evm_ops = {
95 .hw_params = evm_hw_params,
96};
97
8d43d1bc
C
98static struct snd_soc_ops evm_spdif_ops = {
99 .hw_params = evm_spdif_hw_params,
100};
101
310355c1
VB
102/* davinci-evm machine dapm widgets */
103static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
104 SND_SOC_DAPM_HP("Headphone Jack", NULL),
105 SND_SOC_DAPM_LINE("Line Out", NULL),
106 SND_SOC_DAPM_MIC("Mic Jack", NULL),
107 SND_SOC_DAPM_LINE("Line In", NULL),
108};
109
110/* davinci-evm machine audio_mapnections to the codec pins */
acf497f9 111static const struct snd_soc_dapm_route audio_map[] = {
310355c1
VB
112 /* Headphone connected to HPLOUT, HPROUT */
113 {"Headphone Jack", NULL, "HPLOUT"},
114 {"Headphone Jack", NULL, "HPROUT"},
115
116 /* Line Out connected to LLOUT, RLOUT */
117 {"Line Out", NULL, "LLOUT"},
118 {"Line Out", NULL, "RLOUT"},
119
120 /* Mic connected to (MIC3L | MIC3R) */
121 {"MIC3L", NULL, "Mic Bias 2V"},
122 {"MIC3R", NULL, "Mic Bias 2V"},
123 {"Mic Bias 2V", NULL, "Mic Jack"},
124
125 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
126 {"LINE1L", NULL, "Line In"},
127 {"LINE2L", NULL, "Line In"},
128 {"LINE1R", NULL, "Line In"},
129 {"LINE2R", NULL, "Line In"},
310355c1
VB
130};
131
132/* Logic for a aic3x as connected on a davinci-evm */
133static int evm_aic3x_init(struct snd_soc_codec *codec)
134{
310355c1 135 /* Add davinci-evm specific widgets */
acf497f9
MB
136 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
137 ARRAY_SIZE(aic3x_dapm_widgets));
310355c1
VB
138
139 /* Set up davinci-evm specific audio path audio_map */
acf497f9 140 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
310355c1
VB
141
142 /* not connected */
a5302181
LG
143 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
144 snd_soc_dapm_disable_pin(codec, "HPLCOM");
145 snd_soc_dapm_disable_pin(codec, "HPRCOM");
310355c1
VB
146
147 /* always connected */
a5302181
LG
148 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
149 snd_soc_dapm_enable_pin(codec, "Line Out");
150 snd_soc_dapm_enable_pin(codec, "Mic Jack");
151 snd_soc_dapm_enable_pin(codec, "Line In");
310355c1 152
a5302181 153 snd_soc_dapm_sync(codec);
310355c1
VB
154
155 return 0;
156}
157
158/* davinci-evm digital audio interface glue - connects codec <--> CPU */
159static struct snd_soc_dai_link evm_dai = {
160 .name = "TLV320AIC3X",
161 .stream_name = "AIC3X",
162 .cpu_dai = &davinci_i2s_dai,
163 .codec_dai = &aic3x_dai,
164 .init = evm_aic3x_init,
165 .ops = &evm_ops,
166};
167
04f80f5c
C
168static struct snd_soc_dai_link dm6467_evm_dai[] = {
169 {
170 .name = "TLV320AIC3X",
171 .stream_name = "AIC3X",
172 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
173 .codec_dai = &aic3x_dai,
174 .init = evm_aic3x_init,
175 .ops = &evm_ops,
176 },
177 {
178 .name = "McASP",
179 .stream_name = "spdif",
180 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
181 .codec_dai = &dit_stub_dai,
8d43d1bc 182 .ops = &evm_spdif_ops,
04f80f5c
C
183 },
184};
30230f4c 185static struct snd_soc_dai_link da8xx_evm_dai = {
7ae5945f
C
186 .name = "TLV320AIC3X",
187 .stream_name = "AIC3X",
188 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
189 .codec_dai = &aic3x_dai,
190 .init = evm_aic3x_init,
191 .ops = &evm_ops,
192};
04f80f5c 193
9b95b166 194/* davinci dm6446, dm355 or dm365 evm audio machine driver */
87506549 195static struct snd_soc_card snd_soc_card_evm = {
310355c1 196 .name = "DaVinci EVM",
87689d56 197 .platform = &davinci_soc_platform,
310355c1
VB
198 .dai_link = &evm_dai,
199 .num_links = 1,
200};
201
04f80f5c
C
202/* davinci dm6467 evm audio machine driver */
203static struct snd_soc_card dm6467_snd_soc_card_evm = {
204 .name = "DaVinci DM6467 EVM",
205 .platform = &davinci_soc_platform,
206 .dai_link = dm6467_evm_dai,
207 .num_links = ARRAY_SIZE(dm6467_evm_dai),
208};
209
7ae5945f 210static struct snd_soc_card da830_snd_soc_card = {
30230f4c
C
211 .name = "DA830/OMAP-L137 EVM",
212 .dai_link = &da8xx_evm_dai,
213 .platform = &davinci_soc_platform,
214 .num_links = 1,
215};
216
217static struct snd_soc_card da850_snd_soc_card = {
218 .name = "DA850/OMAP-L138 EVM",
219 .dai_link = &da8xx_evm_dai,
7ae5945f
C
220 .platform = &davinci_soc_platform,
221 .num_links = 1,
222};
223
f4890b5c 224static struct aic3x_setup_data aic3x_setup;
7ae5945f 225
310355c1
VB
226/* evm audio subsystem */
227static struct snd_soc_device evm_snd_devdata = {
87506549 228 .card = &snd_soc_card_evm,
310355c1 229 .codec_dev = &soc_codec_dev_aic3x,
f4890b5c 230 .codec_data = &aic3x_setup,
310355c1
VB
231};
232
04f80f5c
C
233/* evm audio subsystem */
234static struct snd_soc_device dm6467_evm_snd_devdata = {
235 .card = &dm6467_snd_soc_card_evm,
236 .codec_dev = &soc_codec_dev_aic3x,
f4890b5c 237 .codec_data = &aic3x_setup,
310355c1
VB
238};
239
7ae5945f
C
240/* evm audio subsystem */
241static struct snd_soc_device da830_evm_snd_devdata = {
242 .card = &da830_snd_soc_card,
243 .codec_dev = &soc_codec_dev_aic3x,
f4890b5c 244 .codec_data = &aic3x_setup,
30230f4c
C
245};
246
247static struct snd_soc_device da850_evm_snd_devdata = {
248 .card = &da850_snd_soc_card,
249 .codec_dev = &soc_codec_dev_aic3x,
f4890b5c 250 .codec_data = &aic3x_setup,
7ae5945f
C
251};
252
310355c1
VB
253static struct platform_device *evm_snd_device;
254
255static int __init evm_init(void)
256{
04f80f5c 257 struct snd_soc_device *evm_snd_dev_data;
f492ec9f 258 int index;
310355c1
VB
259 int ret;
260
9b95b166 261 if (machine_is_davinci_evm() || machine_is_davinci_dm365_evm()) {
04f80f5c 262 evm_snd_dev_data = &evm_snd_devdata;
f492ec9f
DB
263 index = 0;
264 } else if (machine_is_davinci_dm355_evm()) {
04f80f5c 265 evm_snd_dev_data = &evm_snd_devdata;
f492ec9f 266 index = 1;
04f80f5c
C
267 } else if (machine_is_davinci_dm6467_evm()) {
268 evm_snd_dev_data = &dm6467_evm_snd_devdata;
269 index = 0;
7ae5945f
C
270 } else if (machine_is_davinci_da830_evm()) {
271 evm_snd_dev_data = &da830_evm_snd_devdata;
272 index = 1;
30230f4c
C
273 } else if (machine_is_davinci_da850_evm()) {
274 evm_snd_dev_data = &da850_evm_snd_devdata;
275 index = 0;
f492ec9f
DB
276 } else
277 return -EINVAL;
278
279 evm_snd_device = platform_device_alloc("soc-audio", index);
310355c1
VB
280 if (!evm_snd_device)
281 return -ENOMEM;
282
04f80f5c
C
283 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
284 evm_snd_dev_data->dev = &evm_snd_device->dev;
310355c1
VB
285 ret = platform_device_add(evm_snd_device);
286 if (ret)
287 platform_device_put(evm_snd_device);
288
289 return ret;
290}
291
292static void __exit evm_exit(void)
293{
294 platform_device_unregister(evm_snd_device);
295}
296
297module_init(evm_init);
298module_exit(evm_exit);
299
300MODULE_AUTHOR("Vladimir Barinov");
301MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
302MODULE_LICENSE("GPL");
This page took 0.134917 seconds and 5 git commands to generate.