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