blob: dba6651547c1da81308a0f94517e8270cc3dbe43 [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"
Chaithrika U S04f80f52009-06-05 06:28:49 -040031#include "../codecs/spdif_transciever.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010032#include "davinci-pcm.h"
33#include "davinci-i2s.h"
Chaithrika U S04f80f52009-06-05 06:28:49 -040034#include "davinci-mcasp.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010035
Troy Kiskyd6f83392008-12-19 13:05:25 -070036#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
37 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
Vladimir Barinov310355c2008-02-18 11:40:22 +010038static 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;
Liam Girdwood9cb132d2008-07-07 16:07:42 +010042 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010044 int ret = 0;
David Brownell05d5e992009-01-04 02:50:10 -080045 unsigned sysclk;
46
47 /* ASP1 on DM355 EVM is clocked by an external oscillator */
Miguel Aguilar9b95b162009-09-02 15:33:59 -060048 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
49 machine_is_davinci_dm365_evm())
David Brownell05d5e992009-01-04 02:50:10 -080050 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
Chaithrika U S30230f42009-08-11 16:59:21 -040059 else if (machine_is_davinci_da830_evm() ||
60 machine_is_davinci_da850_evm())
Chaithrika U S7ae59452009-08-07 10:07:51 -040061 sysclk = 24576000;
62
David Brownell05d5e992009-01-04 02:50:10 -080063 else
64 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010065
66 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070067 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010068 if (ret < 0)
69 return ret;
70
71 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070072 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010073 if (ret < 0)
74 return ret;
75
76 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080077 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010078 if (ret < 0)
79 return ret;
80
81 return 0;
82}
83
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053084static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
85 struct snd_pcm_hw_params *params)
86{
87 struct snd_soc_pcm_runtime *rtd = substream->private_data;
88 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
89
90 /* set cpu DAI configuration */
91 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
92}
93
Vladimir Barinov310355c2008-02-18 11:40:22 +010094static struct snd_soc_ops evm_ops = {
95 .hw_params = evm_hw_params,
96};
97
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053098static struct snd_soc_ops evm_spdif_ops = {
99 .hw_params = evm_spdif_hw_params,
100};
101
Vladimir Barinov310355c2008-02-18 11:40:22 +0100102/* davinci-evm machine dapm widgets */
103static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
104 SND_SOC_DAPM_HP("Headphone Jack", NULL),
105 SND_SOC_DAPM_LINE("Line Out", NULL),
106 SND_SOC_DAPM_MIC("Mic Jack", NULL),
107 SND_SOC_DAPM_LINE("Line In", NULL),
108};
109
110/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +0200111static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100112 /* Headphone connected to HPLOUT, HPROUT */
113 {"Headphone Jack", NULL, "HPLOUT"},
114 {"Headphone Jack", NULL, "HPROUT"},
115
116 /* Line Out connected to LLOUT, RLOUT */
117 {"Line Out", NULL, "LLOUT"},
118 {"Line Out", NULL, "RLOUT"},
119
120 /* Mic connected to (MIC3L | MIC3R) */
121 {"MIC3L", NULL, "Mic Bias 2V"},
122 {"MIC3R", NULL, "Mic Bias 2V"},
123 {"Mic Bias 2V", NULL, "Mic Jack"},
124
125 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
126 {"LINE1L", NULL, "Line In"},
127 {"LINE2L", NULL, "Line In"},
128 {"LINE1R", NULL, "Line In"},
129 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100130};
131
132/* Logic for a aic3x as connected on a davinci-evm */
133static int evm_aic3x_init(struct snd_soc_codec *codec)
134{
Vladimir Barinov310355c2008-02-18 11:40:22 +0100135 /* Add davinci-evm specific widgets */
Mark Brownacf497f2008-05-13 14:58:30 +0200136 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
137 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100138
139 /* Set up davinci-evm specific audio path audio_map */
Mark Brownacf497f2008-05-13 14:58:30 +0200140 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100141
142 /* not connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100143 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
144 snd_soc_dapm_disable_pin(codec, "HPLCOM");
145 snd_soc_dapm_disable_pin(codec, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100146
147 /* always connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100148 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
149 snd_soc_dapm_enable_pin(codec, "Line Out");
150 snd_soc_dapm_enable_pin(codec, "Mic Jack");
151 snd_soc_dapm_enable_pin(codec, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100152
Liam Girdwooda5302182008-07-07 13:35:17 +0100153 snd_soc_dapm_sync(codec);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100154
155 return 0;
156}
157
158/* davinci-evm digital audio interface glue - connects codec <--> CPU */
159static struct snd_soc_dai_link evm_dai = {
160 .name = "TLV320AIC3X",
161 .stream_name = "AIC3X",
162 .cpu_dai = &davinci_i2s_dai,
163 .codec_dai = &aic3x_dai,
164 .init = evm_aic3x_init,
165 .ops = &evm_ops,
166};
167
Chaithrika U S04f80f52009-06-05 06:28:49 -0400168static struct snd_soc_dai_link dm6467_evm_dai[] = {
169 {
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 },
177 {
178 .name = "McASP",
179 .stream_name = "spdif",
180 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
181 .codec_dai = &dit_stub_dai,
Chaithrika U S8d43d1b2010-03-10 14:48:33 +0530182 .ops = &evm_spdif_ops,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400183 },
184};
Chaithrika U S30230f42009-08-11 16:59:21 -0400185static struct snd_soc_dai_link da8xx_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400186 .name = "TLV320AIC3X",
187 .stream_name = "AIC3X",
188 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
189 .codec_dai = &aic3x_dai,
190 .init = evm_aic3x_init,
191 .ops = &evm_ops,
192};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400193
Miguel Aguilar9b95b162009-09-02 15:33:59 -0600194/* davinci dm6446, dm355 or dm365 evm audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000195static struct snd_soc_card snd_soc_card_evm = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100196 .name = "DaVinci EVM",
Mark Brown87689d52008-12-02 16:01:14 +0000197 .platform = &davinci_soc_platform,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100198 .dai_link = &evm_dai,
199 .num_links = 1,
200};
201
Chaithrika U S04f80f52009-06-05 06:28:49 -0400202/* davinci dm6467 evm audio machine driver */
203static struct snd_soc_card dm6467_snd_soc_card_evm = {
204 .name = "DaVinci DM6467 EVM",
205 .platform = &davinci_soc_platform,
206 .dai_link = dm6467_evm_dai,
207 .num_links = ARRAY_SIZE(dm6467_evm_dai),
208};
209
Chaithrika U S7ae59452009-08-07 10:07:51 -0400210static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400211 .name = "DA830/OMAP-L137 EVM",
212 .dai_link = &da8xx_evm_dai,
213 .platform = &davinci_soc_platform,
214 .num_links = 1,
215};
216
217static struct snd_soc_card da850_snd_soc_card = {
218 .name = "DA850/OMAP-L138 EVM",
219 .dai_link = &da8xx_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400220 .platform = &davinci_soc_platform,
221 .num_links = 1,
222};
223
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300224static struct aic3x_setup_data aic3x_setup;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400225
Vladimir Barinov310355c2008-02-18 11:40:22 +0100226/* evm audio subsystem */
227static struct snd_soc_device evm_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000228 .card = &snd_soc_card_evm,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100229 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300230 .codec_data = &aic3x_setup,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100231};
232
Chaithrika U S04f80f52009-06-05 06:28:49 -0400233/* evm audio subsystem */
234static struct snd_soc_device dm6467_evm_snd_devdata = {
235 .card = &dm6467_snd_soc_card_evm,
236 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300237 .codec_data = &aic3x_setup,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100238};
239
Chaithrika U S7ae59452009-08-07 10:07:51 -0400240/* evm audio subsystem */
241static struct snd_soc_device da830_evm_snd_devdata = {
242 .card = &da830_snd_soc_card,
243 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300244 .codec_data = &aic3x_setup,
Chaithrika U S30230f42009-08-11 16:59:21 -0400245};
246
247static struct snd_soc_device da850_evm_snd_devdata = {
248 .card = &da850_snd_soc_card,
249 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300250 .codec_data = &aic3x_setup,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400251};
252
Vladimir Barinov310355c2008-02-18 11:40:22 +0100253static struct platform_device *evm_snd_device;
254
255static int __init evm_init(void)
256{
Chaithrika U S04f80f52009-06-05 06:28:49 -0400257 struct snd_soc_device *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700258 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100259 int ret;
260
Miguel Aguilar9b95b162009-09-02 15:33:59 -0600261 if (machine_is_davinci_evm() || machine_is_davinci_dm365_evm()) {
Chaithrika U S04f80f52009-06-05 06:28:49 -0400262 evm_snd_dev_data = &evm_snd_devdata;
David Brownellf492ec92009-05-14 13:01:59 -0700263 index = 0;
264 } else if (machine_is_davinci_dm355_evm()) {
Chaithrika U S04f80f52009-06-05 06:28:49 -0400265 evm_snd_dev_data = &evm_snd_devdata;
David Brownellf492ec92009-05-14 13:01:59 -0700266 index = 1;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400267 } else if (machine_is_davinci_dm6467_evm()) {
268 evm_snd_dev_data = &dm6467_evm_snd_devdata;
269 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400270 } else if (machine_is_davinci_da830_evm()) {
271 evm_snd_dev_data = &da830_evm_snd_devdata;
272 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400273 } else if (machine_is_davinci_da850_evm()) {
274 evm_snd_dev_data = &da850_evm_snd_devdata;
275 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700276 } else
277 return -EINVAL;
278
279 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100280 if (!evm_snd_device)
281 return -ENOMEM;
282
Chaithrika U S04f80f52009-06-05 06:28:49 -0400283 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
284 evm_snd_dev_data->dev = &evm_snd_device->dev;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100285 ret = platform_device_add(evm_snd_device);
286 if (ret)
287 platform_device_put(evm_snd_device);
288
289 return ret;
290}
291
292static void __exit evm_exit(void)
293{
294 platform_device_unregister(evm_snd_device);
295}
296
297module_init(evm_init);
298module_exit(evm_exit);
299
300MODULE_AUTHOR("Vladimir Barinov");
301MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
302MODULE_LICENSE("GPL");