ASoC: DaVinci: pcm, don't play 1st sound period twice
[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>
17#include <sound/core.h>
18#include <sound/pcm.h>
19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
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
VB
28
29#include "../codecs/tlv320aic3x.h"
04f80f5c 30#include "../codecs/spdif_transciever.h"
310355c1
VB
31#include "davinci-pcm.h"
32#include "davinci-i2s.h"
04f80f5c 33#include "davinci-mcasp.h"
310355c1 34
d6f83396
TK
35#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
36 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
310355c1
VB
37static int evm_hw_params(struct snd_pcm_substream *substream,
38 struct snd_pcm_hw_params *params)
39{
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
9cb132d7
LG
41 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
42 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
310355c1 43 int ret = 0;
05d5e991
DB
44 unsigned sysclk;
45
46 /* ASP1 on DM355 EVM is clocked by an external oscillator */
04f80f5c 47 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm())
05d5e991
DB
48 sysclk = 27000000;
49
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.
53 */
54 else if (machine_is_davinci_evm())
55 sysclk = 12288000;
56
57 else
58 return -EINVAL;
310355c1
VB
59
60 /* set codec DAI configuration */
9e031624 61 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
310355c1
VB
62 if (ret < 0)
63 return ret;
64
65 /* set cpu DAI configuration */
9e031624 66 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
310355c1
VB
67 if (ret < 0)
68 return ret;
69
70 /* set the codec system clock */
05d5e991 71 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
310355c1
VB
72 if (ret < 0)
73 return ret;
74
75 return 0;
76}
77
78static struct snd_soc_ops evm_ops = {
79 .hw_params = evm_hw_params,
80};
81
82/* davinci-evm machine dapm widgets */
83static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
84 SND_SOC_DAPM_HP("Headphone Jack", NULL),
85 SND_SOC_DAPM_LINE("Line Out", NULL),
86 SND_SOC_DAPM_MIC("Mic Jack", NULL),
87 SND_SOC_DAPM_LINE("Line In", NULL),
88};
89
90/* davinci-evm machine audio_mapnections to the codec pins */
acf497f9 91static const struct snd_soc_dapm_route audio_map[] = {
310355c1
VB
92 /* Headphone connected to HPLOUT, HPROUT */
93 {"Headphone Jack", NULL, "HPLOUT"},
94 {"Headphone Jack", NULL, "HPROUT"},
95
96 /* Line Out connected to LLOUT, RLOUT */
97 {"Line Out", NULL, "LLOUT"},
98 {"Line Out", NULL, "RLOUT"},
99
100 /* Mic connected to (MIC3L | MIC3R) */
101 {"MIC3L", NULL, "Mic Bias 2V"},
102 {"MIC3R", NULL, "Mic Bias 2V"},
103 {"Mic Bias 2V", NULL, "Mic Jack"},
104
105 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
106 {"LINE1L", NULL, "Line In"},
107 {"LINE2L", NULL, "Line In"},
108 {"LINE1R", NULL, "Line In"},
109 {"LINE2R", NULL, "Line In"},
310355c1
VB
110};
111
112/* Logic for a aic3x as connected on a davinci-evm */
113static int evm_aic3x_init(struct snd_soc_codec *codec)
114{
310355c1 115 /* Add davinci-evm specific widgets */
acf497f9
MB
116 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
117 ARRAY_SIZE(aic3x_dapm_widgets));
310355c1
VB
118
119 /* Set up davinci-evm specific audio path audio_map */
acf497f9 120 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
310355c1
VB
121
122 /* not connected */
a5302181
LG
123 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
124 snd_soc_dapm_disable_pin(codec, "HPLCOM");
125 snd_soc_dapm_disable_pin(codec, "HPRCOM");
310355c1
VB
126
127 /* always connected */
a5302181
LG
128 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
129 snd_soc_dapm_enable_pin(codec, "Line Out");
130 snd_soc_dapm_enable_pin(codec, "Mic Jack");
131 snd_soc_dapm_enable_pin(codec, "Line In");
310355c1 132
a5302181 133 snd_soc_dapm_sync(codec);
310355c1
VB
134
135 return 0;
136}
137
138/* davinci-evm digital audio interface glue - connects codec <--> CPU */
139static struct snd_soc_dai_link evm_dai = {
140 .name = "TLV320AIC3X",
141 .stream_name = "AIC3X",
142 .cpu_dai = &davinci_i2s_dai,
143 .codec_dai = &aic3x_dai,
144 .init = evm_aic3x_init,
145 .ops = &evm_ops,
146};
147
04f80f5c
C
148static struct snd_soc_dai_link dm6467_evm_dai[] = {
149 {
150 .name = "TLV320AIC3X",
151 .stream_name = "AIC3X",
152 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
153 .codec_dai = &aic3x_dai,
154 .init = evm_aic3x_init,
155 .ops = &evm_ops,
156 },
157 {
158 .name = "McASP",
159 .stream_name = "spdif",
160 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
161 .codec_dai = &dit_stub_dai,
162 .ops = &evm_ops,
163 },
164};
165
310355c1 166/* davinci-evm audio machine driver */
87506549 167static struct snd_soc_card snd_soc_card_evm = {
310355c1 168 .name = "DaVinci EVM",
87689d56 169 .platform = &davinci_soc_platform,
310355c1
VB
170 .dai_link = &evm_dai,
171 .num_links = 1,
172};
173
04f80f5c
C
174/* davinci dm6467 evm audio machine driver */
175static struct snd_soc_card dm6467_snd_soc_card_evm = {
176 .name = "DaVinci DM6467 EVM",
177 .platform = &davinci_soc_platform,
178 .dai_link = dm6467_evm_dai,
179 .num_links = ARRAY_SIZE(dm6467_evm_dai),
180};
181
310355c1
VB
182/* evm audio private data */
183static struct aic3x_setup_data evm_aic3x_setup = {
f492ec9f 184 .i2c_bus = 1,
310355c1
VB
185 .i2c_address = 0x1b,
186};
187
04f80f5c
C
188/* dm6467 evm audio private data */
189static struct aic3x_setup_data dm6467_evm_aic3x_setup = {
190 .i2c_bus = 1,
191 .i2c_address = 0x18,
192};
193
310355c1
VB
194/* evm audio subsystem */
195static struct snd_soc_device evm_snd_devdata = {
87506549 196 .card = &snd_soc_card_evm,
310355c1
VB
197 .codec_dev = &soc_codec_dev_aic3x,
198 .codec_data = &evm_aic3x_setup,
199};
200
04f80f5c
C
201/* evm audio subsystem */
202static struct snd_soc_device dm6467_evm_snd_devdata = {
203 .card = &dm6467_snd_soc_card_evm,
204 .codec_dev = &soc_codec_dev_aic3x,
205 .codec_data = &dm6467_evm_aic3x_setup,
310355c1
VB
206};
207
208static struct platform_device *evm_snd_device;
209
210static int __init evm_init(void)
211{
04f80f5c 212 struct snd_soc_device *evm_snd_dev_data;
f492ec9f 213 int index;
310355c1
VB
214 int ret;
215
f492ec9f 216 if (machine_is_davinci_evm()) {
04f80f5c 217 evm_snd_dev_data = &evm_snd_devdata;
f492ec9f
DB
218 index = 0;
219 } else if (machine_is_davinci_dm355_evm()) {
04f80f5c 220 evm_snd_dev_data = &evm_snd_devdata;
f492ec9f 221 index = 1;
04f80f5c
C
222 } else if (machine_is_davinci_dm6467_evm()) {
223 evm_snd_dev_data = &dm6467_evm_snd_devdata;
224 index = 0;
f492ec9f
DB
225 } else
226 return -EINVAL;
227
228 evm_snd_device = platform_device_alloc("soc-audio", index);
310355c1
VB
229 if (!evm_snd_device)
230 return -ENOMEM;
231
04f80f5c
C
232 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
233 evm_snd_dev_data->dev = &evm_snd_device->dev;
310355c1
VB
234 ret = platform_device_add(evm_snd_device);
235 if (ret)
236 platform_device_put(evm_snd_device);
237
238 return ret;
239}
240
241static void __exit evm_exit(void)
242{
243 platform_device_unregister(evm_snd_device);
244}
245
246module_init(evm_init);
247module_exit(evm_exit);
248
249MODULE_AUTHOR("Vladimir Barinov");
250MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
251MODULE_LICENSE("GPL");
This page took 0.212632 seconds and 5 git commands to generate.