ipv6: drop unused "dev" arg of icmpv6_send()
[linux-2.6/next.git] / sound / soc / omap / omap3pandora.c
blob68980c19a3bced48ed463460ba9e40454d36fcc4
1 /*
2 * omap3pandora.c -- SoC audio for Pandora Handheld Console
4 * Author: GraÅžvydas Ignotas <notasas@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
22 #include <linux/clk.h>
23 #include <linux/platform_device.h>
24 #include <linux/gpio.h>
25 #include <linux/delay.h>
27 #include <sound/core.h>
28 #include <sound/pcm.h>
29 #include <sound/soc.h>
30 #include <sound/soc-dapm.h>
32 #include <asm/mach-types.h>
34 #include "omap-mcbsp.h"
35 #include "omap-pcm.h"
36 #include "../codecs/twl4030.h"
38 #define OMAP3_PANDORA_DAC_POWER_GPIO 118
39 #define OMAP3_PANDORA_AMP_POWER_GPIO 14
41 #define PREFIX "ASoC omap3pandora: "
43 static int omap3pandora_cmn_hw_params(struct snd_pcm_substream *substream,
44 struct snd_pcm_hw_params *params, unsigned int fmt)
46 struct snd_soc_pcm_runtime *rtd = substream->private_data;
47 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
48 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
49 int ret;
51 /* Set codec DAI configuration */
52 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
53 if (ret < 0) {
54 pr_err(PREFIX "can't set codec DAI configuration\n");
55 return ret;
58 /* Set cpu DAI configuration */
59 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
60 if (ret < 0) {
61 pr_err(PREFIX "can't set cpu DAI configuration\n");
62 return ret;
65 /* Set the codec system clock for DAC and ADC */
66 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
67 SND_SOC_CLOCK_IN);
68 if (ret < 0) {
69 pr_err(PREFIX "can't set codec system clock\n");
70 return ret;
73 /* Set McBSP clock to external */
74 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_EXT,
75 256 * params_rate(params),
76 SND_SOC_CLOCK_IN);
77 if (ret < 0) {
78 pr_err(PREFIX "can't set cpu system clock\n");
79 return ret;
82 ret = snd_soc_dai_set_clkdiv(cpu_dai, OMAP_MCBSP_CLKGDV, 8);
83 if (ret < 0) {
84 pr_err(PREFIX "can't set SRG clock divider\n");
85 return ret;
88 return 0;
91 static int omap3pandora_out_hw_params(struct snd_pcm_substream *substream,
92 struct snd_pcm_hw_params *params)
94 return omap3pandora_cmn_hw_params(substream, params,
95 SND_SOC_DAIFMT_I2S |
96 SND_SOC_DAIFMT_IB_NF |
97 SND_SOC_DAIFMT_CBS_CFS);
100 static int omap3pandora_in_hw_params(struct snd_pcm_substream *substream,
101 struct snd_pcm_hw_params *params)
103 return omap3pandora_cmn_hw_params(substream, params,
104 SND_SOC_DAIFMT_I2S |
105 SND_SOC_DAIFMT_NB_NF |
106 SND_SOC_DAIFMT_CBS_CFS);
109 static int omap3pandora_hp_event(struct snd_soc_dapm_widget *w,
110 struct snd_kcontrol *k, int event)
112 if (SND_SOC_DAPM_EVENT_ON(event)) {
113 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 1);
114 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 1);
115 } else {
116 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 0);
117 mdelay(1);
118 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 0);
121 return 0;
125 * Audio paths on Pandora board:
127 * |O| ---> PCM DAC +-> AMP -> Headphone Jack
128 * |M| A +--------> Line Out
129 * |A| <~~clk~~+
130 * |P| <--- TWL4030 <--------- Line In and MICs
132 static const struct snd_soc_dapm_widget omap3pandora_out_dapm_widgets[] = {
133 SND_SOC_DAPM_DAC("PCM DAC", "HiFi Playback", SND_SOC_NOPM, 0, 0),
134 SND_SOC_DAPM_PGA_E("Headphone Amplifier", SND_SOC_NOPM,
135 0, 0, NULL, 0, omap3pandora_hp_event,
136 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
137 SND_SOC_DAPM_HP("Headphone Jack", NULL),
138 SND_SOC_DAPM_LINE("Line Out", NULL),
141 static const struct snd_soc_dapm_widget omap3pandora_in_dapm_widgets[] = {
142 SND_SOC_DAPM_MIC("Mic (internal)", NULL),
143 SND_SOC_DAPM_MIC("Mic (external)", NULL),
144 SND_SOC_DAPM_LINE("Line In", NULL),
147 static const struct snd_soc_dapm_route omap3pandora_out_map[] = {
148 {"PCM DAC", NULL, "APLL Enable"},
149 {"Headphone Amplifier", NULL, "PCM DAC"},
150 {"Line Out", NULL, "PCM DAC"},
151 {"Headphone Jack", NULL, "Headphone Amplifier"},
154 static const struct snd_soc_dapm_route omap3pandora_in_map[] = {
155 {"AUXL", NULL, "Line In"},
156 {"AUXR", NULL, "Line In"},
158 {"MAINMIC", NULL, "Mic Bias 1"},
159 {"Mic Bias 1", NULL, "Mic (internal)"},
161 {"SUBMIC", NULL, "Mic Bias 2"},
162 {"Mic Bias 2", NULL, "Mic (external)"},
165 static int omap3pandora_out_init(struct snd_soc_codec *codec)
167 int ret;
169 /* All TWL4030 output pins are floating */
170 snd_soc_dapm_nc_pin(codec, "OUTL");
171 snd_soc_dapm_nc_pin(codec, "OUTR");
172 snd_soc_dapm_nc_pin(codec, "EARPIECE");
173 snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
174 snd_soc_dapm_nc_pin(codec, "PREDRIVER");
175 snd_soc_dapm_nc_pin(codec, "HSOL");
176 snd_soc_dapm_nc_pin(codec, "HSOR");
177 snd_soc_dapm_nc_pin(codec, "CARKITL");
178 snd_soc_dapm_nc_pin(codec, "CARKITR");
179 snd_soc_dapm_nc_pin(codec, "HFL");
180 snd_soc_dapm_nc_pin(codec, "HFR");
181 snd_soc_dapm_nc_pin(codec, "VIBRA");
183 ret = snd_soc_dapm_new_controls(codec, omap3pandora_out_dapm_widgets,
184 ARRAY_SIZE(omap3pandora_out_dapm_widgets));
185 if (ret < 0)
186 return ret;
188 snd_soc_dapm_add_routes(codec, omap3pandora_out_map,
189 ARRAY_SIZE(omap3pandora_out_map));
191 return snd_soc_dapm_sync(codec);
194 static int omap3pandora_in_init(struct snd_soc_codec *codec)
196 int ret;
198 /* Not comnnected */
199 snd_soc_dapm_nc_pin(codec, "HSMIC");
200 snd_soc_dapm_nc_pin(codec, "CARKITMIC");
201 snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
202 snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
204 ret = snd_soc_dapm_new_controls(codec, omap3pandora_in_dapm_widgets,
205 ARRAY_SIZE(omap3pandora_in_dapm_widgets));
206 if (ret < 0)
207 return ret;
209 snd_soc_dapm_add_routes(codec, omap3pandora_in_map,
210 ARRAY_SIZE(omap3pandora_in_map));
212 return snd_soc_dapm_sync(codec);
215 static struct snd_soc_ops omap3pandora_out_ops = {
216 .hw_params = omap3pandora_out_hw_params,
219 static struct snd_soc_ops omap3pandora_in_ops = {
220 .hw_params = omap3pandora_in_hw_params,
223 /* Digital audio interface glue - connects codec <--> CPU */
224 static struct snd_soc_dai_link omap3pandora_dai[] = {
226 .name = "PCM1773",
227 .stream_name = "HiFi Out",
228 .cpu_dai = &omap_mcbsp_dai[0],
229 .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
230 .ops = &omap3pandora_out_ops,
231 .init = omap3pandora_out_init,
232 }, {
233 .name = "TWL4030",
234 .stream_name = "Line/Mic In",
235 .cpu_dai = &omap_mcbsp_dai[1],
236 .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
237 .ops = &omap3pandora_in_ops,
238 .init = omap3pandora_in_init,
242 /* SoC card */
243 static struct snd_soc_card snd_soc_card_omap3pandora = {
244 .name = "omap3pandora",
245 .platform = &omap_soc_platform,
246 .dai_link = omap3pandora_dai,
247 .num_links = ARRAY_SIZE(omap3pandora_dai),
250 /* Audio subsystem */
251 static struct snd_soc_device omap3pandora_snd_data = {
252 .card = &snd_soc_card_omap3pandora,
253 .codec_dev = &soc_codec_dev_twl4030,
256 static struct platform_device *omap3pandora_snd_device;
258 static int __init omap3pandora_soc_init(void)
260 int ret;
262 if (!machine_is_omap3_pandora())
263 return -ENODEV;
265 pr_info("OMAP3 Pandora SoC init\n");
267 ret = gpio_request(OMAP3_PANDORA_DAC_POWER_GPIO, "dac_power");
268 if (ret) {
269 pr_err(PREFIX "Failed to get DAC power GPIO\n");
270 return ret;
273 ret = gpio_direction_output(OMAP3_PANDORA_DAC_POWER_GPIO, 0);
274 if (ret) {
275 pr_err(PREFIX "Failed to set DAC power GPIO direction\n");
276 goto fail0;
279 ret = gpio_request(OMAP3_PANDORA_AMP_POWER_GPIO, "amp_power");
280 if (ret) {
281 pr_err(PREFIX "Failed to get amp power GPIO\n");
282 goto fail0;
285 ret = gpio_direction_output(OMAP3_PANDORA_AMP_POWER_GPIO, 0);
286 if (ret) {
287 pr_err(PREFIX "Failed to set amp power GPIO direction\n");
288 goto fail1;
291 omap3pandora_snd_device = platform_device_alloc("soc-audio", -1);
292 if (omap3pandora_snd_device == NULL) {
293 pr_err(PREFIX "Platform device allocation failed\n");
294 ret = -ENOMEM;
295 goto fail1;
298 platform_set_drvdata(omap3pandora_snd_device, &omap3pandora_snd_data);
299 omap3pandora_snd_data.dev = &omap3pandora_snd_device->dev;
300 *(unsigned int *)omap_mcbsp_dai[0].private_data = 1; /* McBSP2 */
301 *(unsigned int *)omap_mcbsp_dai[1].private_data = 3; /* McBSP4 */
303 ret = platform_device_add(omap3pandora_snd_device);
304 if (ret) {
305 pr_err(PREFIX "Unable to add platform device\n");
306 goto fail2;
309 return 0;
311 fail2:
312 platform_device_put(omap3pandora_snd_device);
313 fail1:
314 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO);
315 fail0:
316 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO);
317 return ret;
319 module_init(omap3pandora_soc_init);
321 static void __exit omap3pandora_soc_exit(void)
323 platform_device_unregister(omap3pandora_snd_device);
324 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO);
325 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO);
327 module_exit(omap3pandora_soc_exit);
329 MODULE_AUTHOR("Grazvydas Ignotas <notasas@gmail.com>");
330 MODULE_DESCRIPTION("ALSA SoC OMAP3 Pandora");
331 MODULE_LICENSE("GPL");