blob: 2b07b17a6b2d68f3173380bc16de4eb07b921689 [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>
21#include <sound/soc-dapm.h>
22
Vladimir Barinov310355c2008-02-18 11:40:22 +010023#include <asm/dma.h>
David Brownellf492ec92009-05-14 13:01:59 -070024#include <asm/mach-types.h>
25
26#include <mach/asp.h>
27#include <mach/edma.h>
28#include <mach/mux.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010029
30#include "../codecs/tlv320aic3x.h"
31#include "davinci-pcm.h"
32#include "davinci-i2s.h"
Chaithrika U S04f80f52009-06-05 06:28:49 -040033#include "davinci-mcasp.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010034
Troy Kiskyd6f83392008-12-19 13:05:25 -070035#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
36 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
Vladimir Barinov310355c2008-02-18 11:40:22 +010037static 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;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000041 struct snd_soc_dai *codec_dai = rtd->codec_dai;
42 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010043 int ret = 0;
David Brownell05d5e992009-01-04 02:50:10 -080044 unsigned sysclk;
45
46 /* ASP1 on DM355 EVM is clocked by an external oscillator */
Miguel Aguilar9b95b162009-09-02 15:33:59 -060047 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
48 machine_is_davinci_dm365_evm())
David Brownell05d5e992009-01-04 02:50:10 -080049 sysclk = 27000000;
50
51 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
52 * board-dm644x-evm.c using GPIOs from U18. There are six
53 * options; here we "know" we use a 48 KHz sample rate.
54 */
55 else if (machine_is_davinci_evm())
56 sysclk = 12288000;
57
Chaithrika U S30230f42009-08-11 16:59:21 -040058 else if (machine_is_davinci_da830_evm() ||
59 machine_is_davinci_da850_evm())
Chaithrika U S7ae59452009-08-07 10:07:51 -040060 sysclk = 24576000;
61
David Brownell05d5e992009-01-04 02:50:10 -080062 else
63 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010064
65 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070066 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010067 if (ret < 0)
68 return ret;
69
70 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070071 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010072 if (ret < 0)
73 return ret;
74
75 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080076 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010077 if (ret < 0)
78 return ret;
79
80 return 0;
81}
82
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053083static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
84 struct snd_pcm_hw_params *params)
85{
86 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000087 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053088
89 /* set cpu DAI configuration */
90 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
91}
92
Vladimir Barinov310355c2008-02-18 11:40:22 +010093static struct snd_soc_ops evm_ops = {
94 .hw_params = evm_hw_params,
95};
96
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053097static struct snd_soc_ops evm_spdif_ops = {
98 .hw_params = evm_spdif_hw_params,
99};
100
Vladimir Barinov310355c2008-02-18 11:40:22 +0100101/* davinci-evm machine dapm widgets */
102static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
103 SND_SOC_DAPM_HP("Headphone Jack", NULL),
104 SND_SOC_DAPM_LINE("Line Out", NULL),
105 SND_SOC_DAPM_MIC("Mic Jack", NULL),
106 SND_SOC_DAPM_LINE("Line In", NULL),
107};
108
109/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +0200110static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100111 /* Headphone connected to HPLOUT, HPROUT */
112 {"Headphone Jack", NULL, "HPLOUT"},
113 {"Headphone Jack", NULL, "HPROUT"},
114
115 /* Line Out connected to LLOUT, RLOUT */
116 {"Line Out", NULL, "LLOUT"},
117 {"Line Out", NULL, "RLOUT"},
118
119 /* Mic connected to (MIC3L | MIC3R) */
120 {"MIC3L", NULL, "Mic Bias 2V"},
121 {"MIC3R", NULL, "Mic Bias 2V"},
122 {"Mic Bias 2V", NULL, "Mic Jack"},
123
124 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
125 {"LINE1L", NULL, "Line In"},
126 {"LINE2L", NULL, "Line In"},
127 {"LINE1R", NULL, "Line In"},
128 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100129};
130
131/* Logic for a aic3x as connected on a davinci-evm */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000132static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100133{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000134 struct snd_soc_codec *codec = rtd->codec;
135
Vladimir Barinov310355c2008-02-18 11:40:22 +0100136 /* Add davinci-evm specific widgets */
Mark Brownacf497f2008-05-13 14:58:30 +0200137 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
138 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100139
140 /* Set up davinci-evm specific audio path audio_map */
Mark Brownacf497f2008-05-13 14:58:30 +0200141 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100142
143 /* not connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100144 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
145 snd_soc_dapm_disable_pin(codec, "HPLCOM");
146 snd_soc_dapm_disable_pin(codec, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100147
148 /* always connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100149 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
150 snd_soc_dapm_enable_pin(codec, "Line Out");
151 snd_soc_dapm_enable_pin(codec, "Mic Jack");
152 snd_soc_dapm_enable_pin(codec, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100153
Liam Girdwooda5302182008-07-07 13:35:17 +0100154 snd_soc_dapm_sync(codec);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100155
156 return 0;
157}
158
159/* davinci-evm digital audio interface glue - connects codec <--> CPU */
160static struct snd_soc_dai_link evm_dai = {
161 .name = "TLV320AIC3X",
162 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000163 .cpu_dai_name = "davinci-mcasp.0",
164 .codec_dai_name = "tlv320aic3x-hifi",
165 .codec_name = "tlv320aic3x-codec.0-001a",
166 .platform_name = "davinci-pcm-audio",
Vladimir Barinov310355c2008-02-18 11:40:22 +0100167 .init = evm_aic3x_init,
168 .ops = &evm_ops,
169};
170
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600171static struct snd_soc_dai_link dm365_evm_dai = {
172#ifdef CONFIG_SND_DM365_AIC3X_CODEC
173 .name = "TLV320AIC3X",
174 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000175 .cpu_dai_name = "davinci-i2s",
176 .codec_dai_name = "tlv320aic3x-hifi",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600177 .init = evm_aic3x_init,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000178 .codec_name = "tlv320aic3x-codec.0-001a",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600179 .ops = &evm_ops,
180#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
181 .name = "Voice Codec - CQ93VC",
182 .stream_name = "CQ93",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000183 .cpu_dai_name = "davinci-vcif",
184 .codec_dai_name = "cq93vc-hifi",
185 .codec_name = "cq93vc-codec",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600186#endif
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000187 .platform_name = "davinci-pcm-audio",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600188};
189
Chaithrika U S04f80f52009-06-05 06:28:49 -0400190static struct snd_soc_dai_link dm6467_evm_dai[] = {
191 {
192 .name = "TLV320AIC3X",
193 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000194 .cpu_dai_name= "davinci-mcasp.0",
195 .codec_dai_name = "tlv320aic3x-hifi",
196 .platform_name ="davinci-pcm-audio",
197 .codec_name = "tlv320aic3x-codec.0-001a",
Chaithrika U S04f80f52009-06-05 06:28:49 -0400198 .init = evm_aic3x_init,
199 .ops = &evm_ops,
200 },
201 {
202 .name = "McASP",
203 .stream_name = "spdif",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000204 .cpu_dai_name= "davinci-mcasp.1",
205 .codec_dai_name = "dit-hifi",
206 .codec_name = "spdif_dit",
207 .platform_name = "davinci-pcm-audio",
Chaithrika U S8d43d1b2010-03-10 14:48:33 +0530208 .ops = &evm_spdif_ops,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400209 },
210};
Chaithrika U S30230f42009-08-11 16:59:21 -0400211static struct snd_soc_dai_link da8xx_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400212 .name = "TLV320AIC3X",
213 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000214 .cpu_dai_name= "davinci-mcasp.0",
215 .codec_dai_name = "tlv320aic3x-hifi",
216 .codec_name = "tlv320aic3x-codec.0-001a",
217 .platform_name = "davinci-pcm-audio",
Chaithrika U S7ae59452009-08-07 10:07:51 -0400218 .init = evm_aic3x_init,
219 .ops = &evm_ops,
220};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400221
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600222/* davinci dm6446, dm355 evm audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000223static struct snd_soc_card snd_soc_card_evm = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100224 .name = "DaVinci EVM",
225 .dai_link = &evm_dai,
226 .num_links = 1,
227};
228
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600229/* davinci dm365 evm audio machine driver */
230static struct snd_soc_card dm365_snd_soc_card_evm = {
231 .name = "DaVinci DM365 EVM",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600232 .dai_link = &dm365_evm_dai,
233 .num_links = 1,
234};
235
Chaithrika U S04f80f52009-06-05 06:28:49 -0400236/* davinci dm6467 evm audio machine driver */
237static struct snd_soc_card dm6467_snd_soc_card_evm = {
238 .name = "DaVinci DM6467 EVM",
Chaithrika U S04f80f52009-06-05 06:28:49 -0400239 .dai_link = dm6467_evm_dai,
240 .num_links = ARRAY_SIZE(dm6467_evm_dai),
241};
242
Chaithrika U S7ae59452009-08-07 10:07:51 -0400243static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400244 .name = "DA830/OMAP-L137 EVM",
245 .dai_link = &da8xx_evm_dai,
Chaithrika U S30230f42009-08-11 16:59:21 -0400246 .num_links = 1,
247};
248
249static struct snd_soc_card da850_snd_soc_card = {
250 .name = "DA850/OMAP-L138 EVM",
251 .dai_link = &da8xx_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400252 .num_links = 1,
253};
254
Vladimir Barinov310355c2008-02-18 11:40:22 +0100255static struct platform_device *evm_snd_device;
256
257static int __init evm_init(void)
258{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000259 struct snd_soc_card *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700260 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100261 int ret;
262
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600263 if (machine_is_davinci_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000264 evm_snd_dev_data = &snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700265 index = 0;
266 } else if (machine_is_davinci_dm355_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000267 evm_snd_dev_data = &snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700268 index = 1;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600269 } else if (machine_is_davinci_dm365_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000270 evm_snd_dev_data = &dm365_snd_soc_card_evm;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600271 index = 0;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400272 } else if (machine_is_davinci_dm6467_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000273 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400274 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400275 } else if (machine_is_davinci_da830_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000276 evm_snd_dev_data = &da830_snd_soc_card;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400277 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400278 } else if (machine_is_davinci_da850_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000279 evm_snd_dev_data = &da850_snd_soc_card;
Chaithrika U S30230f42009-08-11 16:59:21 -0400280 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700281 } else
282 return -EINVAL;
283
284 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100285 if (!evm_snd_device)
286 return -ENOMEM;
287
Chaithrika U S04f80f52009-06-05 06:28:49 -0400288 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100289 ret = platform_device_add(evm_snd_device);
290 if (ret)
291 platform_device_put(evm_snd_device);
292
293 return ret;
294}
295
296static void __exit evm_exit(void)
297{
298 platform_device_unregister(evm_snd_device);
299}
300
301module_init(evm_init);
302module_exit(evm_exit);
303
304MODULE_AUTHOR("Vladimir Barinov");
305MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
306MODULE_LICENSE("GPL");