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