blob: b36f0b39b0908017cd2b0c716e0447b42d08b564 [file] [log] [blame]
Vladimir Barinov310355c2008-02-18 11:40:22 +01001/*
2 * ASoC driver for TI DAVINCI EVM platform
3 *
Vladimir Barinovd6b52032008-09-29 23:14:11 +04004 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
Vladimir Barinov310355c2008-02-18 11:40:22 +01005 * 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>
Ben Dooksaa6b9042009-08-20 22:50:42 +010017#include <linux/i2c.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010018#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/soc.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010021
Vladimir Barinov310355c2008-02-18 11:40:22 +010022#include <asm/dma.h>
David Brownellf492ec92009-05-14 13:01:59 -070023#include <asm/mach-types.h>
24
25#include <mach/asp.h>
26#include <mach/edma.h>
27#include <mach/mux.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010028
Vladimir Barinov310355c2008-02-18 11:40:22 +010029#include "davinci-pcm.h"
30#include "davinci-i2s.h"
Chaithrika U S04f80f52009-06-05 06:28:49 -040031#include "davinci-mcasp.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010032
Troy Kiskyd6f83392008-12-19 13:05:25 -070033#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
34 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
Vladimir Barinov310355c2008-02-18 11:40:22 +010035static int evm_hw_params(struct snd_pcm_substream *substream,
36 struct snd_pcm_hw_params *params)
37{
38 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000039 struct snd_soc_dai *codec_dai = rtd->codec_dai;
40 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010041 int ret = 0;
David Brownell05d5e992009-01-04 02:50:10 -080042 unsigned sysclk;
43
44 /* ASP1 on DM355 EVM is clocked by an external oscillator */
Miguel Aguilar9b95b162009-09-02 15:33:59 -060045 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
46 machine_is_davinci_dm365_evm())
David Brownell05d5e992009-01-04 02:50:10 -080047 sysclk = 27000000;
48
49 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
50 * board-dm644x-evm.c using GPIOs from U18. There are six
51 * options; here we "know" we use a 48 KHz sample rate.
52 */
53 else if (machine_is_davinci_evm())
54 sysclk = 12288000;
55
Chaithrika U S30230f42009-08-11 16:59:21 -040056 else if (machine_is_davinci_da830_evm() ||
57 machine_is_davinci_da850_evm())
Chaithrika U S7ae59452009-08-07 10:07:51 -040058 sysclk = 24576000;
59
David Brownell05d5e992009-01-04 02:50:10 -080060 else
61 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010062
63 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070064 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010065 if (ret < 0)
66 return ret;
67
68 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070069 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010070 if (ret < 0)
71 return ret;
72
73 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080074 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010075 if (ret < 0)
76 return ret;
77
78 return 0;
79}
80
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053081static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
82 struct snd_pcm_hw_params *params)
83{
84 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000085 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053086
87 /* set cpu DAI configuration */
88 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
89}
90
Vladimir Barinov310355c2008-02-18 11:40:22 +010091static struct snd_soc_ops evm_ops = {
92 .hw_params = evm_hw_params,
93};
94
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053095static struct snd_soc_ops evm_spdif_ops = {
96 .hw_params = evm_spdif_hw_params,
97};
98
Vladimir Barinov310355c2008-02-18 11:40:22 +010099/* davinci-evm machine dapm widgets */
100static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
101 SND_SOC_DAPM_HP("Headphone Jack", NULL),
102 SND_SOC_DAPM_LINE("Line Out", NULL),
103 SND_SOC_DAPM_MIC("Mic Jack", NULL),
104 SND_SOC_DAPM_LINE("Line In", NULL),
105};
106
107/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +0200108static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100109 /* Headphone connected to HPLOUT, HPROUT */
110 {"Headphone Jack", NULL, "HPLOUT"},
111 {"Headphone Jack", NULL, "HPROUT"},
112
113 /* Line Out connected to LLOUT, RLOUT */
114 {"Line Out", NULL, "LLOUT"},
115 {"Line Out", NULL, "RLOUT"},
116
117 /* Mic connected to (MIC3L | MIC3R) */
118 {"MIC3L", NULL, "Mic Bias 2V"},
119 {"MIC3R", NULL, "Mic Bias 2V"},
120 {"Mic Bias 2V", NULL, "Mic Jack"},
121
122 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
123 {"LINE1L", NULL, "Line In"},
124 {"LINE2L", NULL, "Line In"},
125 {"LINE1R", NULL, "Line In"},
126 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100127};
128
129/* Logic for a aic3x as connected on a davinci-evm */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000130static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100131{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000132 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200133 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000134
Vladimir Barinov310355c2008-02-18 11:40:22 +0100135 /* Add davinci-evm specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200136 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
Mark Brownacf497f2008-05-13 14:58:30 +0200137 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100138
139 /* Set up davinci-evm specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200140 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100141
142 /* not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200143 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
144 snd_soc_dapm_disable_pin(dapm, "HPLCOM");
145 snd_soc_dapm_disable_pin(dapm, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100146
147 /* always connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200148 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
149 snd_soc_dapm_enable_pin(dapm, "Line Out");
150 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
151 snd_soc_dapm_enable_pin(dapm, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100152
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200153 snd_soc_dapm_sync(dapm);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100154
155 return 0;
156}
157
158/* davinci-evm digital audio interface glue - connects codec <--> CPU */
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000159static struct snd_soc_dai_link dm6446_evm_dai = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100160 .name = "TLV320AIC3X",
161 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000162 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000163 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000164 .codec_name = "tlv320aic3x-codec.1-001b",
165 .platform_name = "davinci-pcm-audio",
166 .init = evm_aic3x_init,
167 .ops = &evm_ops,
168};
169
170static struct snd_soc_dai_link dm355_evm_dai = {
171 .name = "TLV320AIC3X",
172 .stream_name = "AIC3X",
173 .cpu_dai_name = "davinci-mcbsp.1",
174 .codec_dai_name = "tlv320aic3x-hifi",
175 .codec_name = "tlv320aic3x-codec.1-001b",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000176 .platform_name = "davinci-pcm-audio",
Vladimir Barinov310355c2008-02-18 11:40:22 +0100177 .init = evm_aic3x_init,
178 .ops = &evm_ops,
179};
180
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600181static struct snd_soc_dai_link dm365_evm_dai = {
182#ifdef CONFIG_SND_DM365_AIC3X_CODEC
183 .name = "TLV320AIC3X",
184 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000185 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000186 .codec_dai_name = "tlv320aic3x-hifi",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600187 .init = evm_aic3x_init,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000188 .codec_name = "tlv320aic3x-codec.1-0018",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600189 .ops = &evm_ops,
190#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
191 .name = "Voice Codec - CQ93VC",
192 .stream_name = "CQ93",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000193 .cpu_dai_name = "davinci-vcif",
194 .codec_dai_name = "cq93vc-hifi",
195 .codec_name = "cq93vc-codec",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600196#endif
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000197 .platform_name = "davinci-pcm-audio",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600198};
199
Chaithrika U S04f80f52009-06-05 06:28:49 -0400200static struct snd_soc_dai_link dm6467_evm_dai[] = {
201 {
202 .name = "TLV320AIC3X",
203 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000204 .cpu_dai_name= "davinci-mcasp.0",
205 .codec_dai_name = "tlv320aic3x-hifi",
206 .platform_name ="davinci-pcm-audio",
207 .codec_name = "tlv320aic3x-codec.0-001a",
Chaithrika U S04f80f52009-06-05 06:28:49 -0400208 .init = evm_aic3x_init,
209 .ops = &evm_ops,
210 },
211 {
212 .name = "McASP",
213 .stream_name = "spdif",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000214 .cpu_dai_name= "davinci-mcasp.1",
215 .codec_dai_name = "dit-hifi",
216 .codec_name = "spdif_dit",
217 .platform_name = "davinci-pcm-audio",
Chaithrika U S8d43d1b2010-03-10 14:48:33 +0530218 .ops = &evm_spdif_ops,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400219 },
220};
Chaithrika U S30230f42009-08-11 16:59:21 -0400221static struct snd_soc_dai_link da8xx_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400222 .name = "TLV320AIC3X",
223 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000224 .cpu_dai_name= "davinci-mcasp.0",
225 .codec_dai_name = "tlv320aic3x-hifi",
Rajashekhara, Sudhakardc5a4602011-01-21 20:10:01 +0530226 .codec_name = "tlv320aic3x-codec.1-0018",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000227 .platform_name = "davinci-pcm-audio",
Chaithrika U S7ae59452009-08-07 10:07:51 -0400228 .init = evm_aic3x_init,
229 .ops = &evm_ops,
230};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400231
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000232/* davinci dm6446 evm audio machine driver */
233static struct snd_soc_card dm6446_snd_soc_card_evm = {
234 .name = "DaVinci DM6446 EVM",
235 .dai_link = &dm6446_evm_dai,
236 .num_links = 1,
237};
238
239/* davinci dm355 evm audio machine driver */
240static struct snd_soc_card dm355_snd_soc_card_evm = {
241 .name = "DaVinci DM355 EVM",
242 .dai_link = &dm355_evm_dai,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100243 .num_links = 1,
244};
245
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600246/* davinci dm365 evm audio machine driver */
247static struct snd_soc_card dm365_snd_soc_card_evm = {
248 .name = "DaVinci DM365 EVM",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600249 .dai_link = &dm365_evm_dai,
250 .num_links = 1,
251};
252
Chaithrika U S04f80f52009-06-05 06:28:49 -0400253/* davinci dm6467 evm audio machine driver */
254static struct snd_soc_card dm6467_snd_soc_card_evm = {
255 .name = "DaVinci DM6467 EVM",
Chaithrika U S04f80f52009-06-05 06:28:49 -0400256 .dai_link = dm6467_evm_dai,
257 .num_links = ARRAY_SIZE(dm6467_evm_dai),
258};
259
Chaithrika U S7ae59452009-08-07 10:07:51 -0400260static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400261 .name = "DA830/OMAP-L137 EVM",
262 .dai_link = &da8xx_evm_dai,
Chaithrika U S30230f42009-08-11 16:59:21 -0400263 .num_links = 1,
264};
265
266static struct snd_soc_card da850_snd_soc_card = {
267 .name = "DA850/OMAP-L138 EVM",
268 .dai_link = &da8xx_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400269 .num_links = 1,
270};
271
Vladimir Barinov310355c2008-02-18 11:40:22 +0100272static struct platform_device *evm_snd_device;
273
274static int __init evm_init(void)
275{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000276 struct snd_soc_card *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700277 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100278 int ret;
279
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600280 if (machine_is_davinci_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000281 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700282 index = 0;
283 } else if (machine_is_davinci_dm355_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000284 evm_snd_dev_data = &dm355_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700285 index = 1;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600286 } else if (machine_is_davinci_dm365_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000287 evm_snd_dev_data = &dm365_snd_soc_card_evm;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600288 index = 0;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400289 } else if (machine_is_davinci_dm6467_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000290 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400291 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400292 } else if (machine_is_davinci_da830_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000293 evm_snd_dev_data = &da830_snd_soc_card;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400294 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400295 } else if (machine_is_davinci_da850_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000296 evm_snd_dev_data = &da850_snd_soc_card;
Chaithrika U S30230f42009-08-11 16:59:21 -0400297 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700298 } else
299 return -EINVAL;
300
301 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100302 if (!evm_snd_device)
303 return -ENOMEM;
304
Chaithrika U S04f80f52009-06-05 06:28:49 -0400305 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100306 ret = platform_device_add(evm_snd_device);
307 if (ret)
308 platform_device_put(evm_snd_device);
309
310 return ret;
311}
312
313static void __exit evm_exit(void)
314{
315 platform_device_unregister(evm_snd_device);
316}
317
318module_init(evm_init);
319module_exit(evm_exit);
320
321MODULE_AUTHOR("Vladimir Barinov");
322MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
323MODULE_LICENSE("GPL");