blob: 7ccbe6684fc2b30c96babcf5c6e497c5ef708cd9 [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
84static struct snd_soc_ops evm_ops = {
85 .hw_params = evm_hw_params,
86};
87
88/* davinci-evm machine dapm widgets */
89static 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 */
Mark Brownacf497f2008-05-13 14:58:30 +020097static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010098 /* 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"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100116};
117
118/* Logic for a aic3x as connected on a davinci-evm */
119static int evm_aic3x_init(struct snd_soc_codec *codec)
120{
Vladimir Barinov310355c2008-02-18 11:40:22 +0100121 /* Add davinci-evm specific widgets */
Mark Brownacf497f2008-05-13 14:58:30 +0200122 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
123 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100124
125 /* Set up davinci-evm specific audio path audio_map */
Mark Brownacf497f2008-05-13 14:58:30 +0200126 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100127
128 /* not connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100129 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
130 snd_soc_dapm_disable_pin(codec, "HPLCOM");
131 snd_soc_dapm_disable_pin(codec, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100132
133 /* always connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100134 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");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100138
Liam Girdwooda5302182008-07-07 13:35:17 +0100139 snd_soc_dapm_sync(codec);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100140
141 return 0;
142}
143
144/* davinci-evm digital audio interface glue - connects codec <--> CPU */
145static 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
Chaithrika U S04f80f52009-06-05 06:28:49 -0400154static 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};
Chaithrika U S30230f42009-08-11 16:59:21 -0400171static struct snd_soc_dai_link da8xx_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400172 .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};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400179
Miguel Aguilar9b95b162009-09-02 15:33:59 -0600180/* davinci dm6446, dm355 or dm365 evm audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000181static struct snd_soc_card snd_soc_card_evm = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100182 .name = "DaVinci EVM",
Mark Brown87689d52008-12-02 16:01:14 +0000183 .platform = &davinci_soc_platform,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100184 .dai_link = &evm_dai,
185 .num_links = 1,
186};
187
Chaithrika U S04f80f52009-06-05 06:28:49 -0400188/* davinci dm6467 evm audio machine driver */
189static 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
Chaithrika U S7ae59452009-08-07 10:07:51 -0400196static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400197 .name = "DA830/OMAP-L137 EVM",
198 .dai_link = &da8xx_evm_dai,
199 .platform = &davinci_soc_platform,
200 .num_links = 1,
201};
202
203static struct snd_soc_card da850_snd_soc_card = {
204 .name = "DA850/OMAP-L138 EVM",
205 .dai_link = &da8xx_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400206 .platform = &davinci_soc_platform,
207 .num_links = 1,
208};
209
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300210static struct aic3x_setup_data aic3x_setup;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400211
Vladimir Barinov310355c2008-02-18 11:40:22 +0100212/* evm audio subsystem */
213static struct snd_soc_device evm_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000214 .card = &snd_soc_card_evm,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100215 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300216 .codec_data = &aic3x_setup,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100217};
218
Chaithrika U S04f80f52009-06-05 06:28:49 -0400219/* evm audio subsystem */
220static struct snd_soc_device dm6467_evm_snd_devdata = {
221 .card = &dm6467_snd_soc_card_evm,
222 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300223 .codec_data = &aic3x_setup,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100224};
225
Chaithrika U S7ae59452009-08-07 10:07:51 -0400226/* evm audio subsystem */
227static struct snd_soc_device da830_evm_snd_devdata = {
228 .card = &da830_snd_soc_card,
229 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300230 .codec_data = &aic3x_setup,
Chaithrika U S30230f42009-08-11 16:59:21 -0400231};
232
233static struct snd_soc_device da850_evm_snd_devdata = {
234 .card = &da850_snd_soc_card,
235 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300236 .codec_data = &aic3x_setup,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400237};
238
Vladimir Barinov310355c2008-02-18 11:40:22 +0100239static struct platform_device *evm_snd_device;
240
241static int __init evm_init(void)
242{
Chaithrika U S04f80f52009-06-05 06:28:49 -0400243 struct snd_soc_device *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700244 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100245 int ret;
246
Miguel Aguilar9b95b162009-09-02 15:33:59 -0600247 if (machine_is_davinci_evm() || machine_is_davinci_dm365_evm()) {
Chaithrika U S04f80f52009-06-05 06:28:49 -0400248 evm_snd_dev_data = &evm_snd_devdata;
David Brownellf492ec92009-05-14 13:01:59 -0700249 index = 0;
250 } else if (machine_is_davinci_dm355_evm()) {
Chaithrika U S04f80f52009-06-05 06:28:49 -0400251 evm_snd_dev_data = &evm_snd_devdata;
David Brownellf492ec92009-05-14 13:01:59 -0700252 index = 1;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400253 } else if (machine_is_davinci_dm6467_evm()) {
254 evm_snd_dev_data = &dm6467_evm_snd_devdata;
255 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400256 } else if (machine_is_davinci_da830_evm()) {
257 evm_snd_dev_data = &da830_evm_snd_devdata;
258 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400259 } else if (machine_is_davinci_da850_evm()) {
260 evm_snd_dev_data = &da850_evm_snd_devdata;
261 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700262 } else
263 return -EINVAL;
264
265 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100266 if (!evm_snd_device)
267 return -ENOMEM;
268
Chaithrika U S04f80f52009-06-05 06:28:49 -0400269 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
270 evm_snd_dev_data->dev = &evm_snd_device->dev;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100271 ret = platform_device_add(evm_snd_device);
272 if (ret)
273 platform_device_put(evm_snd_device);
274
275 return ret;
276}
277
278static void __exit evm_exit(void)
279{
280 platform_device_unregister(evm_snd_device);
281}
282
283module_init(evm_init);
284module_exit(evm_exit);
285
286MODULE_AUTHOR("Vladimir Barinov");
287MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
288MODULE_LICENSE("GPL");