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