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/i2c.h>
21 #include <linux/interrupt.h>
22 #include <linux/platform_device.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/soc.h>
26 #include <sound/soc-dapm.h>
28 #include <asm/mach-types.h>
29 #include <asm/hardware/locomo.h>
30 #include <mach/poodle.h>
31 #include <mach/audio.h>
33 #include "../codecs/wm8731.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
->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
->codec_dai
;
100 struct snd_soc_dai
*cpu_dai
= rtd
->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_pcm_runtime
*rtd
)
241 struct snd_soc_codec
*codec
= rtd
->codec
;
244 snd_soc_dapm_nc_pin(codec
, "LLINEIN");
245 snd_soc_dapm_nc_pin(codec
, "RLINEIN");
246 snd_soc_dapm_enable_pin(codec
, "MICIN");
248 /* Add poodle specific controls */
249 err
= snd_soc_add_controls(codec
, wm8731_poodle_controls
,
250 ARRAY_SIZE(wm8731_poodle_controls
));
254 /* Add poodle specific widgets */
255 snd_soc_dapm_new_controls(codec
, wm8731_dapm_widgets
,
256 ARRAY_SIZE(wm8731_dapm_widgets
));
258 /* Set up poodle specific audio path audio_map */
259 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
261 snd_soc_dapm_sync(codec
);
265 /* poodle digital audio interface glue - connects codec <--> CPU */
266 static struct snd_soc_dai_link poodle_dai
= {
268 .stream_name
= "WM8731",
269 .cpu_dai_name
= "pxa-i2s",
270 .codec_dai_name
= "wm8731-hifi"
271 .platform_name
= "pxa-pcm-audio",
272 .codec_name
= "wm8731-codec.0-001a",
273 .init
= poodle_wm8731_init
,
277 /* poodle audio machine driver */
278 static struct snd_soc_card snd_soc_poodle
= {
280 .dai_link
= &poodle_dai
,
282 .owner
= THIS_MODULE
,
285 static struct platform_device
*poodle_snd_device
;
287 static int __init
poodle_init(void)
291 if (!machine_is_poodle())
294 locomo_gpio_set_dir(&poodle_locomo_device
.dev
,
295 POODLE_LOCOMO_GPIO_AMP_ON
, 0);
296 /* should we mute HP at startup - burning power ?*/
297 locomo_gpio_set_dir(&poodle_locomo_device
.dev
,
298 POODLE_LOCOMO_GPIO_MUTE_L
, 0);
299 locomo_gpio_set_dir(&poodle_locomo_device
.dev
,
300 POODLE_LOCOMO_GPIO_MUTE_R
, 0);
302 poodle_snd_device
= platform_device_alloc("soc-audio", -1);
303 if (!poodle_snd_device
)
306 platform_set_drvdata(poodle_snd_device
, &snd_soc_poodle
);
307 ret
= platform_device_add(poodle_snd_device
);
310 platform_device_put(poodle_snd_device
);
315 static void __exit
poodle_exit(void)
317 platform_device_unregister(poodle_snd_device
);
320 module_init(poodle_init
);
321 module_exit(poodle_exit
);
323 /* Module information */
324 MODULE_AUTHOR("Richard Purdie");
325 MODULE_DESCRIPTION("ALSA SoC Poodle");
326 MODULE_LICENSE("GPL");