blob: 58fd1cbedd88eb4dba2e64b05bf189801b1239c2 [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"
30#include "davinci-pcm.h"
31#include "davinci-i2s.h"
32
Vladimir Barinov310355c2008-02-18 11:40:22 +010033
Troy Kiskyd6f833962008-12-19 13:05:25 -070034#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
35 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
Vladimir Barinov310355c2008-02-18 11:40:22 +010036static int evm_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params)
38{
39 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood9cb132d2008-07-07 16:07:42 +010040 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
41 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010042 int ret = 0;
David Brownell05d5e992009-01-04 02:50:10 -080043 unsigned sysclk;
44
45 /* ASP1 on DM355 EVM is clocked by an external oscillator */
46 if (machine_is_davinci_dm355_evm())
47 sysclk = 27000000;
48
49 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
50 * board-dm644x-evm.c using GPIOs from U18. There are six
51 * options; here we "know" we use a 48 KHz sample rate.
52 */
53 else if (machine_is_davinci_evm())
54 sysclk = 12288000;
55
56 else
57 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010058
59 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070060 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010061 if (ret < 0)
62 return ret;
63
64 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070065 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010066 if (ret < 0)
67 return ret;
68
69 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080070 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010071 if (ret < 0)
72 return ret;
73
74 return 0;
75}
76
77static struct snd_soc_ops evm_ops = {
78 .hw_params = evm_hw_params,
79};
80
81/* davinci-evm machine dapm widgets */
82static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
83 SND_SOC_DAPM_HP("Headphone Jack", NULL),
84 SND_SOC_DAPM_LINE("Line Out", NULL),
85 SND_SOC_DAPM_MIC("Mic Jack", NULL),
86 SND_SOC_DAPM_LINE("Line In", NULL),
87};
88
89/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +020090static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010091 /* Headphone connected to HPLOUT, HPROUT */
92 {"Headphone Jack", NULL, "HPLOUT"},
93 {"Headphone Jack", NULL, "HPROUT"},
94
95 /* Line Out connected to LLOUT, RLOUT */
96 {"Line Out", NULL, "LLOUT"},
97 {"Line Out", NULL, "RLOUT"},
98
99 /* Mic connected to (MIC3L | MIC3R) */
100 {"MIC3L", NULL, "Mic Bias 2V"},
101 {"MIC3R", NULL, "Mic Bias 2V"},
102 {"Mic Bias 2V", NULL, "Mic Jack"},
103
104 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
105 {"LINE1L", NULL, "Line In"},
106 {"LINE2L", NULL, "Line In"},
107 {"LINE1R", NULL, "Line In"},
108 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100109};
110
111/* Logic for a aic3x as connected on a davinci-evm */
112static int evm_aic3x_init(struct snd_soc_codec *codec)
113{
Vladimir Barinov310355c2008-02-18 11:40:22 +0100114 /* Add davinci-evm specific widgets */
Mark Brownacf497f2008-05-13 14:58:30 +0200115 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
116 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100117
118 /* Set up davinci-evm specific audio path audio_map */
Mark Brownacf497f2008-05-13 14:58:30 +0200119 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100120
121 /* not connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100122 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
123 snd_soc_dapm_disable_pin(codec, "HPLCOM");
124 snd_soc_dapm_disable_pin(codec, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100125
126 /* always connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100127 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
128 snd_soc_dapm_enable_pin(codec, "Line Out");
129 snd_soc_dapm_enable_pin(codec, "Mic Jack");
130 snd_soc_dapm_enable_pin(codec, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100131
Liam Girdwooda5302182008-07-07 13:35:17 +0100132 snd_soc_dapm_sync(codec);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100133
134 return 0;
135}
136
137/* davinci-evm digital audio interface glue - connects codec <--> CPU */
138static struct snd_soc_dai_link evm_dai = {
139 .name = "TLV320AIC3X",
140 .stream_name = "AIC3X",
141 .cpu_dai = &davinci_i2s_dai,
142 .codec_dai = &aic3x_dai,
143 .init = evm_aic3x_init,
144 .ops = &evm_ops,
145};
146
147/* davinci-evm audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000148static struct snd_soc_card snd_soc_card_evm = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100149 .name = "DaVinci EVM",
Mark Brown87689d52008-12-02 16:01:14 +0000150 .platform = &davinci_soc_platform,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100151 .dai_link = &evm_dai,
152 .num_links = 1,
153};
154
155/* evm audio private data */
156static struct aic3x_setup_data evm_aic3x_setup = {
David Brownellf492ec92009-05-14 13:01:59 -0700157 .i2c_bus = 1,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100158 .i2c_address = 0x1b,
159};
160
161/* evm audio subsystem */
162static struct snd_soc_device evm_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000163 .card = &snd_soc_card_evm,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100164 .codec_dev = &soc_codec_dev_aic3x,
165 .codec_data = &evm_aic3x_setup,
166};
167
David Brownellf492ec92009-05-14 13:01:59 -0700168/* DM6446 EVM uses ASP0; line-out is a pair of RCA jacks */
Vladimir Barinov310355c2008-02-18 11:40:22 +0100169static struct resource evm_snd_resources[] = {
170 {
David Brownellf492ec92009-05-14 13:01:59 -0700171 .start = DAVINCI_ASP0_BASE,
172 .end = DAVINCI_ASP0_BASE + SZ_8K - 1,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100173 .flags = IORESOURCE_MEM,
174 },
175};
176
177static struct evm_snd_platform_data evm_snd_data = {
David Brownellf492ec92009-05-14 13:01:59 -0700178 .tx_dma_ch = DAVINCI_DMA_ASP0_TX,
179 .rx_dma_ch = DAVINCI_DMA_ASP0_RX,
180};
181
182/* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
183static struct resource dm335evm_snd_resources[] = {
184 {
185 .start = DAVINCI_ASP1_BASE,
186 .end = DAVINCI_ASP1_BASE + SZ_8K - 1,
187 .flags = IORESOURCE_MEM,
188 },
189};
190
191static struct evm_snd_platform_data dm335evm_snd_data = {
192 .tx_dma_ch = DAVINCI_DMA_ASP1_TX,
193 .rx_dma_ch = DAVINCI_DMA_ASP1_RX,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100194};
195
196static struct platform_device *evm_snd_device;
197
198static int __init evm_init(void)
199{
David Brownellf492ec92009-05-14 13:01:59 -0700200 struct resource *resources;
201 unsigned num_resources;
202 struct evm_snd_platform_data *data;
203 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100204 int ret;
205
David Brownellf492ec92009-05-14 13:01:59 -0700206 if (machine_is_davinci_evm()) {
207 davinci_cfg_reg(DM644X_MCBSP);
208
209 resources = evm_snd_resources;
210 num_resources = ARRAY_SIZE(evm_snd_resources);
211 data = &evm_snd_data;
212 index = 0;
213 } else if (machine_is_davinci_dm355_evm()) {
214 /* we don't use ASP1 IRQs, or we'd need to mux them ... */
215 davinci_cfg_reg(DM355_EVT8_ASP1_TX);
216 davinci_cfg_reg(DM355_EVT9_ASP1_RX);
217
218 resources = dm335evm_snd_resources;
219 num_resources = ARRAY_SIZE(dm335evm_snd_resources);
220 data = &dm335evm_snd_data;
221 index = 1;
222 } else
223 return -EINVAL;
224
225 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100226 if (!evm_snd_device)
227 return -ENOMEM;
228
229 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
230 evm_snd_devdata.dev = &evm_snd_device->dev;
David Brownellf492ec92009-05-14 13:01:59 -0700231 platform_device_add_data(evm_snd_device, data, sizeof(*data));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100232
David Brownellf492ec92009-05-14 13:01:59 -0700233 ret = platform_device_add_resources(evm_snd_device, resources,
234 num_resources);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100235 if (ret) {
236 platform_device_put(evm_snd_device);
237 return ret;
238 }
239
240 ret = platform_device_add(evm_snd_device);
241 if (ret)
242 platform_device_put(evm_snd_device);
243
244 return ret;
245}
246
247static void __exit evm_exit(void)
248{
249 platform_device_unregister(evm_snd_device);
250}
251
252module_init(evm_init);
253module_exit(evm_exit);
254
255MODULE_AUTHOR("Vladimir Barinov");
256MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
257MODULE_LICENSE("GPL");