blob: 67414f65940577c745913ba7050f854b7527e0b7 [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 */
Chaithrika U S04f80f52009-06-05 06:28:49 -040048 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_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
83static struct snd_soc_ops evm_ops = {
84 .hw_params = evm_hw_params,
85};
86
87/* davinci-evm machine dapm widgets */
88static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
89 SND_SOC_DAPM_HP("Headphone Jack", NULL),
90 SND_SOC_DAPM_LINE("Line Out", NULL),
91 SND_SOC_DAPM_MIC("Mic Jack", NULL),
92 SND_SOC_DAPM_LINE("Line In", NULL),
93};
94
95/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +020096static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010097 /* Headphone connected to HPLOUT, HPROUT */
98 {"Headphone Jack", NULL, "HPLOUT"},
99 {"Headphone Jack", NULL, "HPROUT"},
100
101 /* Line Out connected to LLOUT, RLOUT */
102 {"Line Out", NULL, "LLOUT"},
103 {"Line Out", NULL, "RLOUT"},
104
105 /* Mic connected to (MIC3L | MIC3R) */
106 {"MIC3L", NULL, "Mic Bias 2V"},
107 {"MIC3R", NULL, "Mic Bias 2V"},
108 {"Mic Bias 2V", NULL, "Mic Jack"},
109
110 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
111 {"LINE1L", NULL, "Line In"},
112 {"LINE2L", NULL, "Line In"},
113 {"LINE1R", NULL, "Line In"},
114 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100115};
116
117/* Logic for a aic3x as connected on a davinci-evm */
118static int evm_aic3x_init(struct snd_soc_codec *codec)
119{
Vladimir Barinov310355c2008-02-18 11:40:22 +0100120 /* Add davinci-evm specific widgets */
Mark Brownacf497f2008-05-13 14:58:30 +0200121 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
122 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100123
124 /* Set up davinci-evm specific audio path audio_map */
Mark Brownacf497f2008-05-13 14:58:30 +0200125 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100126
127 /* not connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100128 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
129 snd_soc_dapm_disable_pin(codec, "HPLCOM");
130 snd_soc_dapm_disable_pin(codec, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100131
132 /* always connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100133 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
134 snd_soc_dapm_enable_pin(codec, "Line Out");
135 snd_soc_dapm_enable_pin(codec, "Mic Jack");
136 snd_soc_dapm_enable_pin(codec, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100137
Liam Girdwooda5302182008-07-07 13:35:17 +0100138 snd_soc_dapm_sync(codec);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100139
140 return 0;
141}
142
143/* davinci-evm digital audio interface glue - connects codec <--> CPU */
144static struct snd_soc_dai_link evm_dai = {
145 .name = "TLV320AIC3X",
146 .stream_name = "AIC3X",
147 .cpu_dai = &davinci_i2s_dai,
148 .codec_dai = &aic3x_dai,
149 .init = evm_aic3x_init,
150 .ops = &evm_ops,
151};
152
Chaithrika U S04f80f52009-06-05 06:28:49 -0400153static struct snd_soc_dai_link dm6467_evm_dai[] = {
154 {
155 .name = "TLV320AIC3X",
156 .stream_name = "AIC3X",
157 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
158 .codec_dai = &aic3x_dai,
159 .init = evm_aic3x_init,
160 .ops = &evm_ops,
161 },
162 {
163 .name = "McASP",
164 .stream_name = "spdif",
165 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
166 .codec_dai = &dit_stub_dai,
167 .ops = &evm_ops,
168 },
169};
Chaithrika U S30230f42009-08-11 16:59:21 -0400170static struct snd_soc_dai_link da8xx_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400171 .name = "TLV320AIC3X",
172 .stream_name = "AIC3X",
173 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
174 .codec_dai = &aic3x_dai,
175 .init = evm_aic3x_init,
176 .ops = &evm_ops,
177};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400178
Vladimir Barinov310355c2008-02-18 11:40:22 +0100179/* davinci-evm audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000180static struct snd_soc_card snd_soc_card_evm = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100181 .name = "DaVinci EVM",
Mark Brown87689d52008-12-02 16:01:14 +0000182 .platform = &davinci_soc_platform,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100183 .dai_link = &evm_dai,
184 .num_links = 1,
185};
186
Chaithrika U S04f80f52009-06-05 06:28:49 -0400187/* davinci dm6467 evm audio machine driver */
188static struct snd_soc_card dm6467_snd_soc_card_evm = {
189 .name = "DaVinci DM6467 EVM",
190 .platform = &davinci_soc_platform,
191 .dai_link = dm6467_evm_dai,
192 .num_links = ARRAY_SIZE(dm6467_evm_dai),
193};
194
Chaithrika U S7ae59452009-08-07 10:07:51 -0400195static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400196 .name = "DA830/OMAP-L137 EVM",
197 .dai_link = &da8xx_evm_dai,
198 .platform = &davinci_soc_platform,
199 .num_links = 1,
200};
201
202static struct snd_soc_card da850_snd_soc_card = {
203 .name = "DA850/OMAP-L138 EVM",
204 .dai_link = &da8xx_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400205 .platform = &davinci_soc_platform,
206 .num_links = 1,
207};
208
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300209static struct aic3x_setup_data aic3x_setup;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400210
Vladimir Barinov310355c2008-02-18 11:40:22 +0100211/* evm audio subsystem */
212static struct snd_soc_device evm_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000213 .card = &snd_soc_card_evm,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100214 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300215 .codec_data = &aic3x_setup,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100216};
217
Chaithrika U S04f80f52009-06-05 06:28:49 -0400218/* evm audio subsystem */
219static struct snd_soc_device dm6467_evm_snd_devdata = {
220 .card = &dm6467_snd_soc_card_evm,
221 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300222 .codec_data = &aic3x_setup,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100223};
224
Chaithrika U S7ae59452009-08-07 10:07:51 -0400225/* evm audio subsystem */
226static struct snd_soc_device da830_evm_snd_devdata = {
227 .card = &da830_snd_soc_card,
228 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300229 .codec_data = &aic3x_setup,
Chaithrika U S30230f42009-08-11 16:59:21 -0400230};
231
232static struct snd_soc_device da850_evm_snd_devdata = {
233 .card = &da850_snd_soc_card,
234 .codec_dev = &soc_codec_dev_aic3x,
Chaithrika U Sf4890b52009-08-25 15:22:21 +0300235 .codec_data = &aic3x_setup,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400236};
237
Vladimir Barinov310355c2008-02-18 11:40:22 +0100238static struct platform_device *evm_snd_device;
239
240static int __init evm_init(void)
241{
Chaithrika U S04f80f52009-06-05 06:28:49 -0400242 struct snd_soc_device *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700243 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100244 int ret;
245
David Brownellf492ec92009-05-14 13:01:59 -0700246 if (machine_is_davinci_evm()) {
Chaithrika U S04f80f52009-06-05 06:28:49 -0400247 evm_snd_dev_data = &evm_snd_devdata;
David Brownellf492ec92009-05-14 13:01:59 -0700248 index = 0;
249 } else if (machine_is_davinci_dm355_evm()) {
Chaithrika U S04f80f52009-06-05 06:28:49 -0400250 evm_snd_dev_data = &evm_snd_devdata;
David Brownellf492ec92009-05-14 13:01:59 -0700251 index = 1;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400252 } else if (machine_is_davinci_dm6467_evm()) {
253 evm_snd_dev_data = &dm6467_evm_snd_devdata;
254 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400255 } else if (machine_is_davinci_da830_evm()) {
256 evm_snd_dev_data = &da830_evm_snd_devdata;
257 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400258 } else if (machine_is_davinci_da850_evm()) {
259 evm_snd_dev_data = &da850_evm_snd_devdata;
260 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700261 } else
262 return -EINVAL;
263
264 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100265 if (!evm_snd_device)
266 return -ENOMEM;
267
Chaithrika U S04f80f52009-06-05 06:28:49 -0400268 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
269 evm_snd_dev_data->dev = &evm_snd_device->dev;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100270 ret = platform_device_add(evm_snd_device);
271 if (ret)
272 platform_device_put(evm_snd_device);
273
274 return ret;
275}
276
277static void __exit evm_exit(void)
278{
279 platform_device_unregister(evm_snd_device);
280}
281
282module_init(evm_init);
283module_exit(evm_exit);
284
285MODULE_AUTHOR("Vladimir Barinov");
286MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
287MODULE_LICENSE("GPL");