blob: f3bb6f60f205cf97c0af28d1d84d5bf61ad5d34a [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>
17#include <sound/core.h>
18#include <sound/pcm.h>
19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
21
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
29#include "../codecs/tlv320aic3x.h"
Chaithrika U S04f80f52009-06-05 06:28:49 -040030#include "../codecs/spdif_transciever.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010031#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 Girdwood9cb132d2008-07-07 16:07:42 +010041 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
42 struct snd_soc_dai *cpu_dai = rtd->dai->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 */
Chaithrika U S04f80f52009-06-05 06:28:49 -040047 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm())
David Brownell05d5e992009-01-04 02:50:10 -080048 sysclk = 27000000;
49
50 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
51 * board-dm644x-evm.c using GPIOs from U18. There are six
52 * options; here we "know" we use a 48 KHz sample rate.
53 */
54 else if (machine_is_davinci_evm())
55 sysclk = 12288000;
56
57 else
58 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010059
60 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070061 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010062 if (ret < 0)
63 return ret;
64
65 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070066 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010067 if (ret < 0)
68 return ret;
69
70 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080071 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010072 if (ret < 0)
73 return ret;
74
75 return 0;
76}
77
78static struct snd_soc_ops evm_ops = {
79 .hw_params = evm_hw_params,
80};
81
82/* davinci-evm machine dapm widgets */
83static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
84 SND_SOC_DAPM_HP("Headphone Jack", NULL),
85 SND_SOC_DAPM_LINE("Line Out", NULL),
86 SND_SOC_DAPM_MIC("Mic Jack", NULL),
87 SND_SOC_DAPM_LINE("Line In", NULL),
88};
89
90/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +020091static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010092 /* Headphone connected to HPLOUT, HPROUT */
93 {"Headphone Jack", NULL, "HPLOUT"},
94 {"Headphone Jack", NULL, "HPROUT"},
95
96 /* Line Out connected to LLOUT, RLOUT */
97 {"Line Out", NULL, "LLOUT"},
98 {"Line Out", NULL, "RLOUT"},
99
100 /* Mic connected to (MIC3L | MIC3R) */
101 {"MIC3L", NULL, "Mic Bias 2V"},
102 {"MIC3R", NULL, "Mic Bias 2V"},
103 {"Mic Bias 2V", NULL, "Mic Jack"},
104
105 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
106 {"LINE1L", NULL, "Line In"},
107 {"LINE2L", NULL, "Line In"},
108 {"LINE1R", NULL, "Line In"},
109 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100110};
111
112/* Logic for a aic3x as connected on a davinci-evm */
113static int evm_aic3x_init(struct snd_soc_codec *codec)
114{
Vladimir Barinov310355c2008-02-18 11:40:22 +0100115 /* Add davinci-evm specific widgets */
Mark Brownacf497f2008-05-13 14:58:30 +0200116 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
117 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100118
119 /* Set up davinci-evm specific audio path audio_map */
Mark Brownacf497f2008-05-13 14:58:30 +0200120 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100121
122 /* not connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100123 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
124 snd_soc_dapm_disable_pin(codec, "HPLCOM");
125 snd_soc_dapm_disable_pin(codec, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100126
127 /* always connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100128 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
129 snd_soc_dapm_enable_pin(codec, "Line Out");
130 snd_soc_dapm_enable_pin(codec, "Mic Jack");
131 snd_soc_dapm_enable_pin(codec, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100132
Liam Girdwooda5302182008-07-07 13:35:17 +0100133 snd_soc_dapm_sync(codec);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100134
135 return 0;
136}
137
138/* davinci-evm digital audio interface glue - connects codec <--> CPU */
139static struct snd_soc_dai_link evm_dai = {
140 .name = "TLV320AIC3X",
141 .stream_name = "AIC3X",
142 .cpu_dai = &davinci_i2s_dai,
143 .codec_dai = &aic3x_dai,
144 .init = evm_aic3x_init,
145 .ops = &evm_ops,
146};
147
Chaithrika U S04f80f52009-06-05 06:28:49 -0400148static struct snd_soc_dai_link dm6467_evm_dai[] = {
149 {
150 .name = "TLV320AIC3X",
151 .stream_name = "AIC3X",
152 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
153 .codec_dai = &aic3x_dai,
154 .init = evm_aic3x_init,
155 .ops = &evm_ops,
156 },
157 {
158 .name = "McASP",
159 .stream_name = "spdif",
160 .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
161 .codec_dai = &dit_stub_dai,
162 .ops = &evm_ops,
163 },
164};
165
Vladimir Barinov310355c2008-02-18 11:40:22 +0100166/* davinci-evm audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000167static struct snd_soc_card snd_soc_card_evm = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100168 .name = "DaVinci EVM",
Mark Brown87689d52008-12-02 16:01:14 +0000169 .platform = &davinci_soc_platform,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100170 .dai_link = &evm_dai,
171 .num_links = 1,
172};
173
Chaithrika U S04f80f52009-06-05 06:28:49 -0400174/* davinci dm6467 evm audio machine driver */
175static struct snd_soc_card dm6467_snd_soc_card_evm = {
176 .name = "DaVinci DM6467 EVM",
177 .platform = &davinci_soc_platform,
178 .dai_link = dm6467_evm_dai,
179 .num_links = ARRAY_SIZE(dm6467_evm_dai),
180};
181
Vladimir Barinov310355c2008-02-18 11:40:22 +0100182/* evm audio private data */
183static struct aic3x_setup_data evm_aic3x_setup = {
David Brownellf492ec92009-05-14 13:01:59 -0700184 .i2c_bus = 1,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100185 .i2c_address = 0x1b,
186};
187
Chaithrika U S04f80f52009-06-05 06:28:49 -0400188/* dm6467 evm audio private data */
189static struct aic3x_setup_data dm6467_evm_aic3x_setup = {
190 .i2c_bus = 1,
191 .i2c_address = 0x18,
192};
193
Vladimir Barinov310355c2008-02-18 11:40:22 +0100194/* evm audio subsystem */
195static struct snd_soc_device evm_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000196 .card = &snd_soc_card_evm,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100197 .codec_dev = &soc_codec_dev_aic3x,
198 .codec_data = &evm_aic3x_setup,
199};
200
Chaithrika U S04f80f52009-06-05 06:28:49 -0400201/* evm audio subsystem */
202static struct snd_soc_device dm6467_evm_snd_devdata = {
203 .card = &dm6467_snd_soc_card_evm,
204 .codec_dev = &soc_codec_dev_aic3x,
205 .codec_data = &dm6467_evm_aic3x_setup,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100206};
207
208static struct platform_device *evm_snd_device;
209
210static int __init evm_init(void)
211{
Chaithrika U S04f80f52009-06-05 06:28:49 -0400212 struct snd_soc_device *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700213 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100214 int ret;
215
David Brownellf492ec92009-05-14 13:01:59 -0700216 if (machine_is_davinci_evm()) {
Chaithrika U S04f80f52009-06-05 06:28:49 -0400217 evm_snd_dev_data = &evm_snd_devdata;
David Brownellf492ec92009-05-14 13:01:59 -0700218 index = 0;
219 } else if (machine_is_davinci_dm355_evm()) {
Chaithrika U S04f80f52009-06-05 06:28:49 -0400220 evm_snd_dev_data = &evm_snd_devdata;
David Brownellf492ec92009-05-14 13:01:59 -0700221 index = 1;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400222 } else if (machine_is_davinci_dm6467_evm()) {
223 evm_snd_dev_data = &dm6467_evm_snd_devdata;
224 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700225 } else
226 return -EINVAL;
227
228 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100229 if (!evm_snd_device)
230 return -ENOMEM;
231
Chaithrika U S04f80f52009-06-05 06:28:49 -0400232 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
233 evm_snd_dev_data->dev = &evm_snd_device->dev;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100234 ret = platform_device_add(evm_snd_device);
235 if (ret)
236 platform_device_put(evm_snd_device);
237
238 return ret;
239}
240
241static void __exit evm_exit(void)
242{
243 platform_device_unregister(evm_snd_device);
244}
245
246module_init(evm_init);
247module_exit(evm_exit);
248
249MODULE_AUTHOR("Vladimir Barinov");
250MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
251MODULE_LICENSE("GPL");