2 * poodle.c -- SoC audio for Poodle
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
7 * Authors: Liam Girdwood <lrg@slimlogic.co.uk>
8 * Richard Purdie <richard@openedhand.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/timer.h>
20 #include <linux/interrupt.h>
21 #include <linux/platform_device.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
27 #include <asm/mach-types.h>
28 #include <asm/hardware/locomo.h>
29 #include <mach/poodle.h>
30 #include <mach/audio.h>
32 #include "../codecs/wm8731.h"
33 #include "pxa2xx-pcm.h"
34 #include "pxa2xx-i2s.h"
37 #define POODLE_HP_OFF 0
38 #define POODLE_SPK_ON 1
39 #define POODLE_SPK_OFF 0
41 /* audio clock in Hz - rounded from 12.235MHz */
42 #define POODLE_AUDIO_CLOCK 12288000
44 static int poodle_jack_func;
45 static int poodle_spk_func;
47 static void poodle_ext_control(struct snd_soc_codec *codec)
49 /* set up jack connection */
50 if (poodle_jack_func == POODLE_HP) {
51 /* set = unmute headphone */
52 locomo_gpio_write(&poodle_locomo_device.dev,
53 POODLE_LOCOMO_GPIO_MUTE_L, 1);
54 locomo_gpio_write(&poodle_locomo_device.dev,
55 POODLE_LOCOMO_GPIO_MUTE_R, 1);
56 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
58 locomo_gpio_write(&poodle_locomo_device.dev,
59 POODLE_LOCOMO_GPIO_MUTE_L, 0);
60 locomo_gpio_write(&poodle_locomo_device.dev,
61 POODLE_LOCOMO_GPIO_MUTE_R, 0);
62 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
65 /* set the enpoints to their new connetion states */
66 if (poodle_spk_func == POODLE_SPK_ON)
67 snd_soc_dapm_enable_pin(codec, "Ext Spk");
69 snd_soc_dapm_disable_pin(codec, "Ext Spk");
71 /* signal a DAPM event */
72 snd_soc_dapm_sync(codec);
75 static int poodle_startup(struct snd_pcm_substream *substream)
77 struct snd_soc_pcm_runtime *rtd = substream->private_data;
78 struct snd_soc_codec *codec = rtd->socdev->codec;
80 /* check the jack status at stream startup */
81 poodle_ext_control(codec);
85 /* we need to unmute the HP at shutdown as the mute burns power on poodle */
86 static void poodle_shutdown(struct snd_pcm_substream *substream)
88 /* set = unmute headphone */
89 locomo_gpio_write(&poodle_locomo_device.dev,
90 POODLE_LOCOMO_GPIO_MUTE_L, 1);
91 locomo_gpio_write(&poodle_locomo_device.dev,
92 POODLE_LOCOMO_GPIO_MUTE_R, 1);
95 static int poodle_hw_params(struct snd_pcm_substream *substream,
96 struct snd_pcm_hw_params *params)
98 struct snd_soc_pcm_runtime *rtd = substream->private_data;
99 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
100 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
101 unsigned int clk = 0;
104 switch (params_rate(params)) {
118 /* set codec DAI configuration */
119 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
120 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
124 /* set cpu DAI configuration */
125 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
126 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
130 /* set the codec system clock for DAC and ADC */
131 ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK, clk,
136 /* set the I2S system clock as input (unused) */
137 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
145 static struct snd_soc_ops poodle_ops = {
146 .startup = poodle_startup,
147 .hw_params = poodle_hw_params,
148 .shutdown = poodle_shutdown,
151 static int poodle_get_jack(struct snd_kcontrol *kcontrol,
152 struct snd_ctl_elem_value *ucontrol)
154 ucontrol->value.integer.value[0] = poodle_jack_func;
158 static int poodle_set_jack(struct snd_kcontrol *kcontrol,
159 struct snd_ctl_elem_value *ucontrol)
161 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
163 if (poodle_jack_func == ucontrol->value.integer.value[0])
166 poodle_jack_func = ucontrol->value.integer.value[0];
167 poodle_ext_control(codec);
171 static int poodle_get_spk(struct snd_kcontrol *kcontrol,
172 struct snd_ctl_elem_value *ucontrol)
174 ucontrol->value.integer.value[0] = poodle_spk_func;
178 static int poodle_set_spk(struct snd_kcontrol *kcontrol,
179 struct snd_ctl_elem_value *ucontrol)
181 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
183 if (poodle_spk_func == ucontrol->value.integer.value[0])
186 poodle_spk_func = ucontrol->value.integer.value[0];
187 poodle_ext_control(codec);
191 static int poodle_amp_event(struct snd_soc_dapm_widget *w,
192 struct snd_kcontrol *k, int event)
194 if (SND_SOC_DAPM_EVENT_ON(event))
195 locomo_gpio_write(&poodle_locomo_device.dev,
196 POODLE_LOCOMO_GPIO_AMP_ON, 0);
198 locomo_gpio_write(&poodle_locomo_device.dev,
199 POODLE_LOCOMO_GPIO_AMP_ON, 1);
204 /* poodle machine dapm widgets */
205 static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
206 SND_SOC_DAPM_HP("Headphone Jack", NULL),
207 SND_SOC_DAPM_SPK("Ext Spk", poodle_amp_event),
210 /* Corgi machine connections to the codec pins */
211 static const struct snd_soc_dapm_route audio_map[] = {
213 /* headphone connected to LHPOUT1, RHPOUT1 */
214 {"Headphone Jack", NULL, "LHPOUT"},
215 {"Headphone Jack", NULL, "RHPOUT"},
217 /* speaker connected to LOUT, ROUT */
218 {"Ext Spk", NULL, "ROUT"},
219 {"Ext Spk", NULL, "LOUT"},
222 static const char *jack_function[] = {"Off", "Headphone"};
223 static const char *spk_function[] = {"Off", "On"};
224 static const struct soc_enum poodle_enum[] = {
225 SOC_ENUM_SINGLE_EXT(2, jack_function),
226 SOC_ENUM_SINGLE_EXT(2, spk_function),
229 static const struct snd_kcontrol_new wm8731_poodle_controls[] = {
230 SOC_ENUM_EXT("Jack Function", poodle_enum[0], poodle_get_jack,
232 SOC_ENUM_EXT("Speaker Function", poodle_enum[1], poodle_get_spk,
237 * Logic for a wm8731 as connected on a Sharp SL-C7x0 Device
239 static int poodle_wm8731_init(struct snd_soc_codec *codec)
243 snd_soc_dapm_nc_pin(codec, "LLINEIN");
244 snd_soc_dapm_nc_pin(codec, "RLINEIN");
245 snd_soc_dapm_enable_pin(codec, "MICIN");
247 /* Add poodle specific controls */
248 for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) {
249 err = snd_ctl_add(codec->card,
250 snd_soc_cnew(&wm8731_poodle_controls[i], codec, NULL));
255 /* Add poodle specific widgets */
256 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets,
257 ARRAY_SIZE(wm8731_dapm_widgets));
259 /* Set up poodle specific audio path audio_map */
260 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
262 snd_soc_dapm_sync(codec);
266 /* poodle digital audio interface glue - connects codec <--> CPU */
267 static struct snd_soc_dai_link poodle_dai = {
269 .stream_name = "WM8731",
270 .cpu_dai = &pxa_i2s_dai,
271 .codec_dai = &wm8731_dai,
272 .init = poodle_wm8731_init,
276 /* poodle audio machine driver */
277 static struct snd_soc_card snd_soc_poodle = {
279 .platform = &pxa2xx_soc_platform,
280 .dai_link = &poodle_dai,
284 /* poodle audio private data */
285 static struct wm8731_setup_data poodle_wm8731_setup = {
290 /* poodle audio subsystem */
291 static struct snd_soc_device poodle_snd_devdata = {
292 .card = &snd_soc_poodle,
293 .codec_dev = &soc_codec_dev_wm8731,
294 .codec_data = &poodle_wm8731_setup,
297 static struct platform_device *poodle_snd_device;
299 static int __init poodle_init(void)
303 if (!machine_is_poodle())
306 locomo_gpio_set_dir(&poodle_locomo_device.dev,
307 POODLE_LOCOMO_GPIO_AMP_ON, 0);
308 /* should we mute HP at startup - burning power ?*/
309 locomo_gpio_set_dir(&poodle_locomo_device.dev,
310 POODLE_LOCOMO_GPIO_MUTE_L, 0);
311 locomo_gpio_set_dir(&poodle_locomo_device.dev,
312 POODLE_LOCOMO_GPIO_MUTE_R, 0);
314 poodle_snd_device = platform_device_alloc("soc-audio", -1);
315 if (!poodle_snd_device)
318 platform_set_drvdata(poodle_snd_device, &poodle_snd_devdata);
319 poodle_snd_devdata.dev = &poodle_snd_device->dev;
320 ret = platform_device_add(poodle_snd_device);
323 platform_device_put(poodle_snd_device);
328 static void __exit poodle_exit(void)
330 platform_device_unregister(poodle_snd_device);
333 module_init(poodle_init);
334 module_exit(poodle_exit);
336 /* Module information */
337 MODULE_AUTHOR("Richard Purdie");
338 MODULE_DESCRIPTION("ALSA SoC Poodle");
339 MODULE_LICENSE("GPL");