2 * linux/sound/soc/pxa/palm27x.c
4 * SoC Audio driver for Palm T|X, T5 and LifeDrive
8 * Copyright (C) 2008 Marek Vasut <marek.vasut@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/device.h>
19 #include <linux/gpio.h>
20 #include <linux/interrupt.h>
21 #include <linux/irq.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 <mach/audio.h>
30 #include <mach/palmasoc.h>
32 #include "../codecs/wm9712.h"
33 #include "pxa2xx-pcm.h"
34 #include "pxa2xx-ac97.h"
36 static int palm27x_jack_func = 1;
37 static int palm27x_spk_func = 1;
38 static int palm27x_ep_gpio = -1;
40 static void palm27x_ext_control(struct snd_soc_codec *codec)
42 if (!palm27x_spk_func)
43 snd_soc_dapm_enable_pin(codec, "Speaker");
45 snd_soc_dapm_disable_pin(codec, "Speaker");
47 if (!palm27x_jack_func)
48 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
50 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
52 snd_soc_dapm_sync(codec);
55 static int palm27x_startup(struct snd_pcm_substream *substream)
57 struct snd_soc_pcm_runtime *rtd = substream->private_data;
58 struct snd_soc_codec *codec = rtd->socdev->codec;
60 /* check the jack status at stream startup */
61 palm27x_ext_control(codec);
65 static struct snd_soc_ops palm27x_ops = {
66 .startup = palm27x_startup,
69 static irqreturn_t palm27x_interrupt(int irq, void *v)
71 palm27x_spk_func = gpio_get_value(palm27x_ep_gpio);
72 palm27x_jack_func = !palm27x_spk_func;
76 static int palm27x_get_jack(struct snd_kcontrol *kcontrol,
77 struct snd_ctl_elem_value *ucontrol)
79 ucontrol->value.integer.value[0] = palm27x_jack_func;
83 static int palm27x_set_jack(struct snd_kcontrol *kcontrol,
84 struct snd_ctl_elem_value *ucontrol)
86 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
88 if (palm27x_jack_func == ucontrol->value.integer.value[0])
91 palm27x_jack_func = ucontrol->value.integer.value[0];
92 palm27x_ext_control(codec);
96 static int palm27x_get_spk(struct snd_kcontrol *kcontrol,
97 struct snd_ctl_elem_value *ucontrol)
99 ucontrol->value.integer.value[0] = palm27x_spk_func;
103 static int palm27x_set_spk(struct snd_kcontrol *kcontrol,
104 struct snd_ctl_elem_value *ucontrol)
106 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
108 if (palm27x_spk_func == ucontrol->value.integer.value[0])
111 palm27x_spk_func = ucontrol->value.integer.value[0];
112 palm27x_ext_control(codec);
116 /* PalmTX machine dapm widgets */
117 static const struct snd_soc_dapm_widget palm27x_dapm_widgets[] = {
118 SND_SOC_DAPM_HP("Headphone Jack", NULL),
119 SND_SOC_DAPM_SPK("Speaker", NULL),
122 /* PalmTX audio map */
123 static const struct snd_soc_dapm_route audio_map[] = {
124 /* headphone connected to HPOUTL, HPOUTR */
125 {"Headphone Jack", NULL, "HPOUTL"},
126 {"Headphone Jack", NULL, "HPOUTR"},
128 /* ext speaker connected to ROUT2, LOUT2 */
129 {"Speaker", NULL, "LOUT2"},
130 {"Speaker", NULL, "ROUT2"},
133 static const char *jack_function[] = {"Headphone", "Off"};
134 static const char *spk_function[] = {"On", "Off"};
135 static const struct soc_enum palm27x_enum[] = {
136 SOC_ENUM_SINGLE_EXT(2, jack_function),
137 SOC_ENUM_SINGLE_EXT(2, spk_function),
140 static const struct snd_kcontrol_new palm27x_controls[] = {
141 SOC_ENUM_EXT("Jack Function", palm27x_enum[0], palm27x_get_jack,
143 SOC_ENUM_EXT("Speaker Function", palm27x_enum[1], palm27x_get_spk,
147 static int palm27x_ac97_init(struct snd_soc_codec *codec)
151 snd_soc_dapm_nc_pin(codec, "OUT3");
152 snd_soc_dapm_nc_pin(codec, "MONOOUT");
154 /* add palm27x specific controls */
155 for (i = 0; i < ARRAY_SIZE(palm27x_controls); i++) {
156 err = snd_ctl_add(codec->card,
157 snd_soc_cnew(&palm27x_controls[i],
163 /* add palm27x specific widgets */
164 snd_soc_dapm_new_controls(codec, palm27x_dapm_widgets,
165 ARRAY_SIZE(palm27x_dapm_widgets));
167 /* set up palm27x specific audio path audio_map */
168 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
170 snd_soc_dapm_sync(codec);
174 static struct snd_soc_dai_link palm27x_dai[] = {
177 .stream_name = "AC97 HiFi",
178 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
179 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_HIFI],
180 .init = palm27x_ac97_init,
185 .stream_name = "AC97 Aux",
186 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
187 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX],
192 static struct snd_soc_card palm27x_asoc = {
193 .name = "Palm/PXA27x",
194 .platform = &pxa2xx_soc_platform,
195 .dai_link = palm27x_dai,
196 .num_links = ARRAY_SIZE(palm27x_dai),
199 static struct snd_soc_device palm27x_snd_devdata = {
200 .card = &palm27x_asoc,
201 .codec_dev = &soc_codec_dev_wm9712,
204 static struct platform_device *palm27x_snd_device;
206 static int __init palm27x_asoc_init(void)
210 if (!(machine_is_palmtx() || machine_is_palmt5() ||
211 machine_is_palmld()))
214 ret = gpio_request(palm27x_ep_gpio, "Headphone Jack");
217 ret = gpio_direction_input(palm27x_ep_gpio);
221 if (request_irq(gpio_to_irq(palm27x_ep_gpio), palm27x_interrupt,
222 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
223 "Headphone jack", NULL))
226 palm27x_snd_device = platform_device_alloc("soc-audio", -1);
227 if (!palm27x_snd_device) {
232 platform_set_drvdata(palm27x_snd_device, &palm27x_snd_devdata);
233 palm27x_snd_devdata.dev = &palm27x_snd_device->dev;
234 ret = platform_device_add(palm27x_snd_device);
242 platform_device_put(palm27x_snd_device);
244 free_irq(gpio_to_irq(palm27x_ep_gpio), NULL);
246 gpio_free(palm27x_ep_gpio);
251 static void __exit palm27x_asoc_exit(void)
253 free_irq(gpio_to_irq(palm27x_ep_gpio), NULL);
254 gpio_free(palm27x_ep_gpio);
255 platform_device_unregister(palm27x_snd_device);
258 void __init palm27x_asoc_set_pdata(struct palm27x_asoc_info *data)
260 palm27x_ep_gpio = data->jack_gpio;
263 module_init(palm27x_asoc_init);
264 module_exit(palm27x_asoc_exit);
266 /* Module information */
267 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
268 MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
269 MODULE_LICENSE("GPL");