Commit | Line | Data |
---|---|---|
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 |
37 | static 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 | ||
30230f4c C |
57 | else if (machine_is_davinci_da830_evm() || |
58 | machine_is_davinci_da850_evm()) | |
7ae5945f C |
59 | sysclk = 24576000; |
60 | ||
05d5e991 DB |
61 | else |
62 | return -EINVAL; | |
310355c1 VB |
63 | |
64 | /* set codec DAI configuration */ | |
9e031624 | 65 | ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT); |
310355c1 VB |
66 | if (ret < 0) |
67 | return ret; | |
68 | ||
69 | /* set cpu DAI configuration */ | |
9e031624 | 70 | ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT); |
310355c1 VB |
71 | if (ret < 0) |
72 | return ret; | |
73 | ||
74 | /* set the codec system clock */ | |
05d5e991 | 75 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT); |
310355c1 VB |
76 | if (ret < 0) |
77 | return ret; | |
78 | ||
79 | return 0; | |
80 | } | |
81 | ||
82 | static struct snd_soc_ops evm_ops = { | |
83 | .hw_params = evm_hw_params, | |
84 | }; | |
85 | ||
86 | /* davinci-evm machine dapm widgets */ | |
87 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { | |
88 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | |
89 | SND_SOC_DAPM_LINE("Line Out", NULL), | |
90 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | |
91 | SND_SOC_DAPM_LINE("Line In", NULL), | |
92 | }; | |
93 | ||
94 | /* davinci-evm machine audio_mapnections to the codec pins */ | |
acf497f9 | 95 | static const struct snd_soc_dapm_route audio_map[] = { |
310355c1 VB |
96 | /* Headphone connected to HPLOUT, HPROUT */ |
97 | {"Headphone Jack", NULL, "HPLOUT"}, | |
98 | {"Headphone Jack", NULL, "HPROUT"}, | |
99 | ||
100 | /* Line Out connected to LLOUT, RLOUT */ | |
101 | {"Line Out", NULL, "LLOUT"}, | |
102 | {"Line Out", NULL, "RLOUT"}, | |
103 | ||
104 | /* Mic connected to (MIC3L | MIC3R) */ | |
105 | {"MIC3L", NULL, "Mic Bias 2V"}, | |
106 | {"MIC3R", NULL, "Mic Bias 2V"}, | |
107 | {"Mic Bias 2V", NULL, "Mic Jack"}, | |
108 | ||
109 | /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ | |
110 | {"LINE1L", NULL, "Line In"}, | |
111 | {"LINE2L", NULL, "Line In"}, | |
112 | {"LINE1R", NULL, "Line In"}, | |
113 | {"LINE2R", NULL, "Line In"}, | |
310355c1 VB |
114 | }; |
115 | ||
116 | /* Logic for a aic3x as connected on a davinci-evm */ | |
117 | static int evm_aic3x_init(struct snd_soc_codec *codec) | |
118 | { | |
310355c1 | 119 | /* Add davinci-evm specific widgets */ |
acf497f9 MB |
120 | snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, |
121 | ARRAY_SIZE(aic3x_dapm_widgets)); | |
310355c1 VB |
122 | |
123 | /* Set up davinci-evm specific audio path audio_map */ | |
acf497f9 | 124 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
310355c1 VB |
125 | |
126 | /* not connected */ | |
a5302181 LG |
127 | snd_soc_dapm_disable_pin(codec, "MONO_LOUT"); |
128 | snd_soc_dapm_disable_pin(codec, "HPLCOM"); | |
129 | snd_soc_dapm_disable_pin(codec, "HPRCOM"); | |
310355c1 VB |
130 | |
131 | /* always connected */ | |
a5302181 LG |
132 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); |
133 | snd_soc_dapm_enable_pin(codec, "Line Out"); | |
134 | snd_soc_dapm_enable_pin(codec, "Mic Jack"); | |
135 | snd_soc_dapm_enable_pin(codec, "Line In"); | |
310355c1 | 136 | |
a5302181 | 137 | snd_soc_dapm_sync(codec); |
310355c1 VB |
138 | |
139 | return 0; | |
140 | } | |
141 | ||
142 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ | |
143 | static struct snd_soc_dai_link evm_dai = { | |
144 | .name = "TLV320AIC3X", | |
145 | .stream_name = "AIC3X", | |
146 | .cpu_dai = &davinci_i2s_dai, | |
147 | .codec_dai = &aic3x_dai, | |
148 | .init = evm_aic3x_init, | |
149 | .ops = &evm_ops, | |
150 | }; | |
151 | ||
04f80f5c C |
152 | static struct snd_soc_dai_link dm6467_evm_dai[] = { |
153 | { | |
154 | .name = "TLV320AIC3X", | |
155 | .stream_name = "AIC3X", | |
156 | .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI], | |
157 | .codec_dai = &aic3x_dai, | |
158 | .init = evm_aic3x_init, | |
159 | .ops = &evm_ops, | |
160 | }, | |
161 | { | |
162 | .name = "McASP", | |
163 | .stream_name = "spdif", | |
164 | .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI], | |
165 | .codec_dai = &dit_stub_dai, | |
166 | .ops = &evm_ops, | |
167 | }, | |
168 | }; | |
30230f4c | 169 | static struct snd_soc_dai_link da8xx_evm_dai = { |
7ae5945f C |
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 | }; | |
04f80f5c | 177 | |
310355c1 | 178 | /* davinci-evm audio machine driver */ |
87506549 | 179 | static struct snd_soc_card snd_soc_card_evm = { |
310355c1 | 180 | .name = "DaVinci EVM", |
87689d56 | 181 | .platform = &davinci_soc_platform, |
310355c1 VB |
182 | .dai_link = &evm_dai, |
183 | .num_links = 1, | |
184 | }; | |
185 | ||
04f80f5c C |
186 | /* davinci dm6467 evm audio machine driver */ |
187 | static struct snd_soc_card dm6467_snd_soc_card_evm = { | |
188 | .name = "DaVinci DM6467 EVM", | |
189 | .platform = &davinci_soc_platform, | |
190 | .dai_link = dm6467_evm_dai, | |
191 | .num_links = ARRAY_SIZE(dm6467_evm_dai), | |
192 | }; | |
193 | ||
7ae5945f | 194 | static struct snd_soc_card da830_snd_soc_card = { |
30230f4c C |
195 | .name = "DA830/OMAP-L137 EVM", |
196 | .dai_link = &da8xx_evm_dai, | |
197 | .platform = &davinci_soc_platform, | |
198 | .num_links = 1, | |
199 | }; | |
200 | ||
201 | static struct snd_soc_card da850_snd_soc_card = { | |
202 | .name = "DA850/OMAP-L138 EVM", | |
203 | .dai_link = &da8xx_evm_dai, | |
7ae5945f C |
204 | .platform = &davinci_soc_platform, |
205 | .num_links = 1, | |
206 | }; | |
207 | ||
310355c1 VB |
208 | /* evm audio private data */ |
209 | static struct aic3x_setup_data evm_aic3x_setup = { | |
310355c1 VB |
210 | }; |
211 | ||
04f80f5c C |
212 | /* dm6467 evm audio private data */ |
213 | static struct aic3x_setup_data dm6467_evm_aic3x_setup = { | |
214 | .i2c_bus = 1, | |
215 | .i2c_address = 0x18, | |
216 | }; | |
217 | ||
30230f4c | 218 | static struct aic3x_setup_data da8xx_evm_aic3x_setup = { |
7ae5945f C |
219 | .i2c_bus = 1, |
220 | .i2c_address = 0x18, | |
221 | }; | |
222 | ||
310355c1 VB |
223 | /* evm audio subsystem */ |
224 | static struct snd_soc_device evm_snd_devdata = { | |
87506549 | 225 | .card = &snd_soc_card_evm, |
310355c1 VB |
226 | .codec_dev = &soc_codec_dev_aic3x, |
227 | .codec_data = &evm_aic3x_setup, | |
228 | }; | |
229 | ||
04f80f5c C |
230 | /* evm audio subsystem */ |
231 | static struct snd_soc_device dm6467_evm_snd_devdata = { | |
232 | .card = &dm6467_snd_soc_card_evm, | |
233 | .codec_dev = &soc_codec_dev_aic3x, | |
234 | .codec_data = &dm6467_evm_aic3x_setup, | |
310355c1 VB |
235 | }; |
236 | ||
7ae5945f C |
237 | /* evm audio subsystem */ |
238 | static struct snd_soc_device da830_evm_snd_devdata = { | |
239 | .card = &da830_snd_soc_card, | |
240 | .codec_dev = &soc_codec_dev_aic3x, | |
30230f4c C |
241 | .codec_data = &da8xx_evm_aic3x_setup, |
242 | }; | |
243 | ||
244 | static struct snd_soc_device da850_evm_snd_devdata = { | |
245 | .card = &da850_snd_soc_card, | |
246 | .codec_dev = &soc_codec_dev_aic3x, | |
247 | .codec_data = &da8xx_evm_aic3x_setup, | |
7ae5945f C |
248 | }; |
249 | ||
310355c1 VB |
250 | static struct platform_device *evm_snd_device; |
251 | ||
252 | static int __init evm_init(void) | |
253 | { | |
04f80f5c | 254 | struct snd_soc_device *evm_snd_dev_data; |
f492ec9f | 255 | int index; |
310355c1 VB |
256 | int ret; |
257 | ||
f492ec9f | 258 | if (machine_is_davinci_evm()) { |
04f80f5c | 259 | evm_snd_dev_data = &evm_snd_devdata; |
f492ec9f DB |
260 | index = 0; |
261 | } else if (machine_is_davinci_dm355_evm()) { | |
04f80f5c | 262 | evm_snd_dev_data = &evm_snd_devdata; |
f492ec9f | 263 | index = 1; |
04f80f5c C |
264 | } else if (machine_is_davinci_dm6467_evm()) { |
265 | evm_snd_dev_data = &dm6467_evm_snd_devdata; | |
266 | index = 0; | |
7ae5945f C |
267 | } else if (machine_is_davinci_da830_evm()) { |
268 | evm_snd_dev_data = &da830_evm_snd_devdata; | |
269 | index = 1; | |
30230f4c C |
270 | } else if (machine_is_davinci_da850_evm()) { |
271 | evm_snd_dev_data = &da850_evm_snd_devdata; | |
272 | index = 0; | |
f492ec9f DB |
273 | } else |
274 | return -EINVAL; | |
275 | ||
276 | evm_snd_device = platform_device_alloc("soc-audio", index); | |
310355c1 VB |
277 | if (!evm_snd_device) |
278 | return -ENOMEM; | |
279 | ||
04f80f5c C |
280 | platform_set_drvdata(evm_snd_device, evm_snd_dev_data); |
281 | evm_snd_dev_data->dev = &evm_snd_device->dev; | |
310355c1 VB |
282 | ret = platform_device_add(evm_snd_device); |
283 | if (ret) | |
284 | platform_device_put(evm_snd_device); | |
285 | ||
286 | return ret; | |
287 | } | |
288 | ||
289 | static void __exit evm_exit(void) | |
290 | { | |
291 | platform_device_unregister(evm_snd_device); | |
292 | } | |
293 | ||
294 | module_init(evm_init); | |
295 | module_exit(evm_exit); | |
296 | ||
297 | MODULE_AUTHOR("Vladimir Barinov"); | |
298 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); | |
299 | MODULE_LICENSE("GPL"); |