Merge branch 'devel' into for-linus
[sfrench/cifs-2.6.git] / sound / soc / davinci / davinci-evm.c
1 /*
2  * ASoC driver for TI DAVINCI EVM platform
3  *
4  * Author:      Vladimir Barinov, <vbarinov@embeddedalley.com>
5  * 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
22 #include <asm/dma.h>
23 #include <mach/hardware.h>
24
25 #include "../codecs/tlv320aic3x.h"
26 #include "davinci-pcm.h"
27 #include "davinci-i2s.h"
28
29
30 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
31                 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
32 static 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;
36         struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
37         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
38         int ret = 0;
39         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;
54
55         /* set codec DAI configuration */
56         ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
57         if (ret < 0)
58                 return ret;
59
60         /* set cpu DAI configuration */
61         ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
62         if (ret < 0)
63                 return ret;
64
65         /* set the codec system clock */
66         ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
67         if (ret < 0)
68                 return ret;
69
70         return 0;
71 }
72
73 static struct snd_soc_ops evm_ops = {
74         .hw_params = evm_hw_params,
75 };
76
77 /* davinci-evm machine dapm widgets */
78 static 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 */
86 static const struct snd_soc_dapm_route audio_map[] = {
87         /* 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"},
105 };
106
107 /* Logic for a aic3x as connected on a davinci-evm */
108 static int evm_aic3x_init(struct snd_soc_codec *codec)
109 {
110         /* Add davinci-evm specific widgets */
111         snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
112                                   ARRAY_SIZE(aic3x_dapm_widgets));
113
114         /* Set up davinci-evm specific audio path audio_map */
115         snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
116
117         /* not connected */
118         snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
119         snd_soc_dapm_disable_pin(codec, "HPLCOM");
120         snd_soc_dapm_disable_pin(codec, "HPRCOM");
121
122         /* always connected */
123         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");
127
128         snd_soc_dapm_sync(codec);
129
130         return 0;
131 }
132
133 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
134 static 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 */
144 static struct snd_soc_card snd_soc_card_evm = {
145         .name = "DaVinci EVM",
146         .platform = &davinci_soc_platform,
147         .dai_link = &evm_dai,
148         .num_links = 1,
149 };
150
151 /* evm audio private data */
152 static struct aic3x_setup_data evm_aic3x_setup = {
153         .i2c_bus = 0,
154         .i2c_address = 0x1b,
155 };
156
157 /* evm audio subsystem */
158 static struct snd_soc_device evm_snd_devdata = {
159         .card = &snd_soc_card_evm,
160         .codec_dev = &soc_codec_dev_aic3x,
161         .codec_data = &evm_aic3x_setup,
162 };
163
164 static 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
172 static 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
177 static struct platform_device *evm_snd_device;
178
179 static 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         platform_device_add_data(evm_snd_device, &evm_snd_data,
190                                  sizeof(evm_snd_data));
191
192         ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
193                                             ARRAY_SIZE(evm_snd_resources));
194         if (ret) {
195                 platform_device_put(evm_snd_device);
196                 return ret;
197         }
198
199         ret = platform_device_add(evm_snd_device);
200         if (ret)
201                 platform_device_put(evm_snd_device);
202
203         return ret;
204 }
205
206 static void __exit evm_exit(void)
207 {
208         platform_device_unregister(evm_snd_device);
209 }
210
211 module_init(evm_init);
212 module_exit(evm_exit);
213
214 MODULE_AUTHOR("Vladimir Barinov");
215 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
216 MODULE_LICENSE("GPL");