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