conn rcv_lock converted to spinlock, struct cor_sock created, kernel_packet skb_clone...
[cor_2_6_31.git] / sound / soc / davinci / davinci-evm.c
blob58fd1cbedd88eb4dba2e64b05bf189801b1239c2
1 /*
2 * ASoC driver for TI DAVINCI EVM platform
4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
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.
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>
22 #include <asm/dma.h>
23 #include <asm/mach-types.h>
25 #include <mach/asp.h>
26 #include <mach/edma.h>
27 #include <mach/mux.h>
29 #include "../codecs/tlv320aic3x.h"
30 #include "davinci-pcm.h"
31 #include "davinci-i2s.h"
34 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
35 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
36 static int evm_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params)
39 struct snd_soc_pcm_runtime *rtd = substream->private_data;
40 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
41 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
42 int ret = 0;
43 unsigned sysclk;
45 /* ASP1 on DM355 EVM is clocked by an external oscillator */
46 if (machine_is_davinci_dm355_evm())
47 sysclk = 27000000;
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.
53 else if (machine_is_davinci_evm())
54 sysclk = 12288000;
56 else
57 return -EINVAL;
59 /* set codec DAI configuration */
60 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
61 if (ret < 0)
62 return ret;
64 /* set cpu DAI configuration */
65 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
66 if (ret < 0)
67 return ret;
69 /* set the codec system clock */
70 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
71 if (ret < 0)
72 return ret;
74 return 0;
77 static struct snd_soc_ops evm_ops = {
78 .hw_params = evm_hw_params,
81 /* davinci-evm machine dapm widgets */
82 static 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),
89 /* davinci-evm machine audio_mapnections to the codec pins */
90 static const struct snd_soc_dapm_route audio_map[] = {
91 /* Headphone connected to HPLOUT, HPROUT */
92 {"Headphone Jack", NULL, "HPLOUT"},
93 {"Headphone Jack", NULL, "HPROUT"},
95 /* Line Out connected to LLOUT, RLOUT */
96 {"Line Out", NULL, "LLOUT"},
97 {"Line Out", NULL, "RLOUT"},
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"},
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"},
111 /* Logic for a aic3x as connected on a davinci-evm */
112 static int evm_aic3x_init(struct snd_soc_codec *codec)
114 /* Add davinci-evm specific widgets */
115 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
116 ARRAY_SIZE(aic3x_dapm_widgets));
118 /* Set up davinci-evm specific audio path audio_map */
119 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
121 /* not connected */
122 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
123 snd_soc_dapm_disable_pin(codec, "HPLCOM");
124 snd_soc_dapm_disable_pin(codec, "HPRCOM");
126 /* always connected */
127 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");
132 snd_soc_dapm_sync(codec);
134 return 0;
137 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
138 static 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,
147 /* davinci-evm audio machine driver */
148 static struct snd_soc_card snd_soc_card_evm = {
149 .name = "DaVinci EVM",
150 .platform = &davinci_soc_platform,
151 .dai_link = &evm_dai,
152 .num_links = 1,
155 /* evm audio private data */
156 static struct aic3x_setup_data evm_aic3x_setup = {
157 .i2c_bus = 1,
158 .i2c_address = 0x1b,
161 /* evm audio subsystem */
162 static struct snd_soc_device evm_snd_devdata = {
163 .card = &snd_soc_card_evm,
164 .codec_dev = &soc_codec_dev_aic3x,
165 .codec_data = &evm_aic3x_setup,
168 /* DM6446 EVM uses ASP0; line-out is a pair of RCA jacks */
169 static struct resource evm_snd_resources[] = {
171 .start = DAVINCI_ASP0_BASE,
172 .end = DAVINCI_ASP0_BASE + SZ_8K - 1,
173 .flags = IORESOURCE_MEM,
177 static struct evm_snd_platform_data evm_snd_data = {
178 .tx_dma_ch = DAVINCI_DMA_ASP0_TX,
179 .rx_dma_ch = DAVINCI_DMA_ASP0_RX,
182 /* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
183 static struct resource dm335evm_snd_resources[] = {
185 .start = DAVINCI_ASP1_BASE,
186 .end = DAVINCI_ASP1_BASE + SZ_8K - 1,
187 .flags = IORESOURCE_MEM,
191 static struct evm_snd_platform_data dm335evm_snd_data = {
192 .tx_dma_ch = DAVINCI_DMA_ASP1_TX,
193 .rx_dma_ch = DAVINCI_DMA_ASP1_RX,
196 static struct platform_device *evm_snd_device;
198 static int __init evm_init(void)
200 struct resource *resources;
201 unsigned num_resources;
202 struct evm_snd_platform_data *data;
203 int index;
204 int ret;
206 if (machine_is_davinci_evm()) {
207 davinci_cfg_reg(DM644X_MCBSP);
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);
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;
225 evm_snd_device = platform_device_alloc("soc-audio", index);
226 if (!evm_snd_device)
227 return -ENOMEM;
229 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
230 evm_snd_devdata.dev = &evm_snd_device->dev;
231 platform_device_add_data(evm_snd_device, data, sizeof(*data));
233 ret = platform_device_add_resources(evm_snd_device, resources,
234 num_resources);
235 if (ret) {
236 platform_device_put(evm_snd_device);
237 return ret;
240 ret = platform_device_add(evm_snd_device);
241 if (ret)
242 platform_device_put(evm_snd_device);
244 return ret;
247 static void __exit evm_exit(void)
249 platform_device_unregister(evm_snd_device);
252 module_init(evm_init);
253 module_exit(evm_exit);
255 MODULE_AUTHOR("Vladimir Barinov");
256 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
257 MODULE_LICENSE("GPL");