blob: 54851f318568b7ba277284bf65d9f01077f64527 [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>
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/hardware.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010024
25#include "../codecs/tlv320aic3x.h"
26#include "davinci-pcm.h"
27#include "davinci-i2s.h"
28
Vladimir Barinov310355c2008-02-18 11:40:22 +010029
Troy Kiskyd6f83392008-12-19 13:05:25 -070030#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
31 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
Vladimir Barinov310355c2008-02-18 11:40:22 +010032static int evm_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
34{
35 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood9cb132d2008-07-07 16:07:42 +010036 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
37 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010038 int ret = 0;
David Brownell05d5e992009-01-04 02:50:10 -080039 unsigned sysclk;
40
41 /* ASP1 on DM355 EVM is clocked by an external oscillator */
42 if (machine_is_davinci_dm355_evm())
43 sysclk = 27000000;
44
45 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
46 * board-dm644x-evm.c using GPIOs from U18. There are six
47 * options; here we "know" we use a 48 KHz sample rate.
48 */
49 else if (machine_is_davinci_evm())
50 sysclk = 12288000;
51
52 else
53 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010054
55 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070056 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010057 if (ret < 0)
58 return ret;
59
60 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070061 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010062 if (ret < 0)
63 return ret;
64
65 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080066 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010067 if (ret < 0)
68 return ret;
69
70 return 0;
71}
72
73static struct snd_soc_ops evm_ops = {
74 .hw_params = evm_hw_params,
75};
76
77/* davinci-evm machine dapm widgets */
78static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
79 SND_SOC_DAPM_HP("Headphone Jack", NULL),
80 SND_SOC_DAPM_LINE("Line Out", NULL),
81 SND_SOC_DAPM_MIC("Mic Jack", NULL),
82 SND_SOC_DAPM_LINE("Line In", NULL),
83};
84
85/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +020086static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010087 /* Headphone connected to HPLOUT, HPROUT */
88 {"Headphone Jack", NULL, "HPLOUT"},
89 {"Headphone Jack", NULL, "HPROUT"},
90
91 /* Line Out connected to LLOUT, RLOUT */
92 {"Line Out", NULL, "LLOUT"},
93 {"Line Out", NULL, "RLOUT"},
94
95 /* Mic connected to (MIC3L | MIC3R) */
96 {"MIC3L", NULL, "Mic Bias 2V"},
97 {"MIC3R", NULL, "Mic Bias 2V"},
98 {"Mic Bias 2V", NULL, "Mic Jack"},
99
100 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
101 {"LINE1L", NULL, "Line In"},
102 {"LINE2L", NULL, "Line In"},
103 {"LINE1R", NULL, "Line In"},
104 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100105};
106
107/* Logic for a aic3x as connected on a davinci-evm */
108static int evm_aic3x_init(struct snd_soc_codec *codec)
109{
Vladimir Barinov310355c2008-02-18 11:40:22 +0100110 /* Add davinci-evm specific widgets */
Mark Brownacf497f2008-05-13 14:58:30 +0200111 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
112 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100113
114 /* Set up davinci-evm specific audio path audio_map */
Mark Brownacf497f2008-05-13 14:58:30 +0200115 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100116
117 /* not connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100118 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
119 snd_soc_dapm_disable_pin(codec, "HPLCOM");
120 snd_soc_dapm_disable_pin(codec, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100121
122 /* always connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100123 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
124 snd_soc_dapm_enable_pin(codec, "Line Out");
125 snd_soc_dapm_enable_pin(codec, "Mic Jack");
126 snd_soc_dapm_enable_pin(codec, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100127
Liam Girdwooda5302182008-07-07 13:35:17 +0100128 snd_soc_dapm_sync(codec);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100129
130 return 0;
131}
132
133/* davinci-evm digital audio interface glue - connects codec <--> CPU */
134static struct snd_soc_dai_link evm_dai = {
135 .name = "TLV320AIC3X",
136 .stream_name = "AIC3X",
137 .cpu_dai = &davinci_i2s_dai,
138 .codec_dai = &aic3x_dai,
139 .init = evm_aic3x_init,
140 .ops = &evm_ops,
141};
142
143/* davinci-evm audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000144static struct snd_soc_card snd_soc_card_evm = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100145 .name = "DaVinci EVM",
Mark Brown87689d52008-12-02 16:01:14 +0000146 .platform = &davinci_soc_platform,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100147 .dai_link = &evm_dai,
148 .num_links = 1,
149};
150
151/* evm audio private data */
152static struct aic3x_setup_data evm_aic3x_setup = {
Jean Delvareba8ed122008-09-22 14:15:53 +0200153 .i2c_bus = 0,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100154 .i2c_address = 0x1b,
155};
156
157/* evm audio subsystem */
158static struct snd_soc_device evm_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000159 .card = &snd_soc_card_evm,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100160 .codec_dev = &soc_codec_dev_aic3x,
161 .codec_data = &evm_aic3x_setup,
162};
163
164static struct resource evm_snd_resources[] = {
165 {
166 .start = DAVINCI_MCBSP_BASE,
167 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
168 .flags = IORESOURCE_MEM,
169 },
170};
171
172static struct evm_snd_platform_data evm_snd_data = {
173 .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
174 .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
175};
176
177static struct platform_device *evm_snd_device;
178
179static int __init evm_init(void)
180{
181 int ret;
182
183 evm_snd_device = platform_device_alloc("soc-audio", 0);
184 if (!evm_snd_device)
185 return -ENOMEM;
186
187 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
188 evm_snd_devdata.dev = &evm_snd_device->dev;
189 evm_snd_device->dev.platform_data = &evm_snd_data;
190
191 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
192 ARRAY_SIZE(evm_snd_resources));
193 if (ret) {
194 platform_device_put(evm_snd_device);
195 return ret;
196 }
197
198 ret = platform_device_add(evm_snd_device);
199 if (ret)
200 platform_device_put(evm_snd_device);
201
202 return ret;
203}
204
205static void __exit evm_exit(void)
206{
207 platform_device_unregister(evm_snd_device);
208}
209
210module_init(evm_init);
211module_exit(evm_exit);
212
213MODULE_AUTHOR("Vladimir Barinov");
214MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
215MODULE_LICENSE("GPL");