ASoC: Replace remaining uses of snd_soc_cnew with snd_soc_add_controls.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / soc / pxa / tosa.c
blobfc781374b1bfa234cba453ed85459747e6d58be0
1 /*
2 * tosa.c -- SoC audio for Tosa
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.
15 * GPIO's
16 * 1 - Jack Insertion
17 * 5 - Hookswitch (headset answer/hang up switch)
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/device.h>
24 #include <linux/gpio.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
31 #include <asm/mach-types.h>
32 #include <mach/tosa.h>
33 #include <mach/pxa-regs.h>
34 #include <mach/hardware.h>
35 #include <mach/audio.h>
37 #include "../codecs/wm9712.h"
38 #include "pxa2xx-pcm.h"
39 #include "pxa2xx-ac97.h"
41 static struct snd_soc_card tosa;
43 #define TOSA_HP 0
44 #define TOSA_MIC_INT 1
45 #define TOSA_HEADSET 2
46 #define TOSA_HP_OFF 3
47 #define TOSA_SPK_ON 0
48 #define TOSA_SPK_OFF 1
50 static int tosa_jack_func;
51 static int tosa_spk_func;
53 static void tosa_ext_control(struct snd_soc_codec *codec)
55 /* set up jack connection */
56 switch (tosa_jack_func) {
57 case TOSA_HP:
58 snd_soc_dapm_disable_pin(codec, "Mic (Internal)");
59 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
60 snd_soc_dapm_disable_pin(codec, "Headset Jack");
61 break;
62 case TOSA_MIC_INT:
63 snd_soc_dapm_enable_pin(codec, "Mic (Internal)");
64 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
65 snd_soc_dapm_disable_pin(codec, "Headset Jack");
66 break;
67 case TOSA_HEADSET:
68 snd_soc_dapm_disable_pin(codec, "Mic (Internal)");
69 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
70 snd_soc_dapm_enable_pin(codec, "Headset Jack");
71 break;
74 if (tosa_spk_func == TOSA_SPK_ON)
75 snd_soc_dapm_enable_pin(codec, "Speaker");
76 else
77 snd_soc_dapm_disable_pin(codec, "Speaker");
79 snd_soc_dapm_sync(codec);
82 static int tosa_startup(struct snd_pcm_substream *substream)
84 struct snd_soc_pcm_runtime *rtd = substream->private_data;
85 struct snd_soc_codec *codec = rtd->socdev->card->codec;
87 /* check the jack status at stream startup */
88 tosa_ext_control(codec);
89 return 0;
92 static struct snd_soc_ops tosa_ops = {
93 .startup = tosa_startup,
96 static int tosa_get_jack(struct snd_kcontrol *kcontrol,
97 struct snd_ctl_elem_value *ucontrol)
99 ucontrol->value.integer.value[0] = tosa_jack_func;
100 return 0;
103 static int tosa_set_jack(struct snd_kcontrol *kcontrol,
104 struct snd_ctl_elem_value *ucontrol)
106 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
108 if (tosa_jack_func == ucontrol->value.integer.value[0])
109 return 0;
111 tosa_jack_func = ucontrol->value.integer.value[0];
112 tosa_ext_control(codec);
113 return 1;
116 static int tosa_get_spk(struct snd_kcontrol *kcontrol,
117 struct snd_ctl_elem_value *ucontrol)
119 ucontrol->value.integer.value[0] = tosa_spk_func;
120 return 0;
123 static int tosa_set_spk(struct snd_kcontrol *kcontrol,
124 struct snd_ctl_elem_value *ucontrol)
126 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
128 if (tosa_spk_func == ucontrol->value.integer.value[0])
129 return 0;
131 tosa_spk_func = ucontrol->value.integer.value[0];
132 tosa_ext_control(codec);
133 return 1;
136 /* tosa dapm event handlers */
137 static int tosa_hp_event(struct snd_soc_dapm_widget *w,
138 struct snd_kcontrol *k, int event)
140 gpio_set_value(TOSA_GPIO_L_MUTE, SND_SOC_DAPM_EVENT_ON(event) ? 1 :0);
141 return 0;
144 /* tosa machine dapm widgets */
145 static const struct snd_soc_dapm_widget tosa_dapm_widgets[] = {
146 SND_SOC_DAPM_HP("Headphone Jack", tosa_hp_event),
147 SND_SOC_DAPM_HP("Headset Jack", NULL),
148 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
149 SND_SOC_DAPM_SPK("Speaker", NULL),
152 /* tosa audio map */
153 static const struct snd_soc_dapm_route audio_map[] = {
155 /* headphone connected to HPOUTL, HPOUTR */
156 {"Headphone Jack", NULL, "HPOUTL"},
157 {"Headphone Jack", NULL, "HPOUTR"},
159 /* ext speaker connected to LOUT2, ROUT2 */
160 {"Speaker", NULL, "LOUT2"},
161 {"Speaker", NULL, "ROUT2"},
163 /* internal mic is connected to mic1, mic2 differential - with bias */
164 {"MIC1", NULL, "Mic Bias"},
165 {"MIC2", NULL, "Mic Bias"},
166 {"Mic Bias", NULL, "Mic (Internal)"},
168 /* headset is connected to HPOUTR, and LINEINR with bias */
169 {"Headset Jack", NULL, "HPOUTR"},
170 {"LINEINR", NULL, "Mic Bias"},
171 {"Mic Bias", NULL, "Headset Jack"},
174 static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",
175 "Off"};
176 static const char *spk_function[] = {"On", "Off"};
177 static const struct soc_enum tosa_enum[] = {
178 SOC_ENUM_SINGLE_EXT(5, jack_function),
179 SOC_ENUM_SINGLE_EXT(2, spk_function),
182 static const struct snd_kcontrol_new tosa_controls[] = {
183 SOC_ENUM_EXT("Jack Function", tosa_enum[0], tosa_get_jack,
184 tosa_set_jack),
185 SOC_ENUM_EXT("Speaker Function", tosa_enum[1], tosa_get_spk,
186 tosa_set_spk),
189 static int tosa_ac97_init(struct snd_soc_codec *codec)
191 int err;
193 snd_soc_dapm_nc_pin(codec, "OUT3");
194 snd_soc_dapm_nc_pin(codec, "MONOOUT");
196 /* add tosa specific controls */
197 err = snd_soc_add_controls(codec, tosa_controls,
198 ARRAY_SIZE(tosa_controls));
199 if (err < 0)
200 return err;
202 /* add tosa specific widgets */
203 snd_soc_dapm_new_controls(codec, tosa_dapm_widgets,
204 ARRAY_SIZE(tosa_dapm_widgets));
206 /* set up tosa specific audio path audio_map */
207 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
209 snd_soc_dapm_sync(codec);
210 return 0;
213 static struct snd_soc_dai_link tosa_dai[] = {
215 .name = "AC97",
216 .stream_name = "AC97 HiFi",
217 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
218 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_HIFI],
219 .init = tosa_ac97_init,
220 .ops = &tosa_ops,
223 .name = "AC97 Aux",
224 .stream_name = "AC97 Aux",
225 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
226 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX],
227 .ops = &tosa_ops,
231 static int tosa_probe(struct platform_device *dev)
233 int ret;
235 ret = gpio_request(TOSA_GPIO_L_MUTE, "Headphone Jack");
236 if (ret)
237 return ret;
238 ret = gpio_direction_output(TOSA_GPIO_L_MUTE, 0);
239 if (ret)
240 gpio_free(TOSA_GPIO_L_MUTE);
242 return ret;
245 static int tosa_remove(struct platform_device *dev)
247 gpio_free(TOSA_GPIO_L_MUTE);
248 return 0;
251 static struct snd_soc_card tosa = {
252 .name = "Tosa",
253 .platform = &pxa2xx_soc_platform,
254 .dai_link = tosa_dai,
255 .num_links = ARRAY_SIZE(tosa_dai),
256 .probe = tosa_probe,
257 .remove = tosa_remove,
260 static struct snd_soc_device tosa_snd_devdata = {
261 .card = &tosa,
262 .codec_dev = &soc_codec_dev_wm9712,
265 static struct platform_device *tosa_snd_device;
267 static int __init tosa_init(void)
269 int ret;
271 if (!machine_is_tosa())
272 return -ENODEV;
274 tosa_snd_device = platform_device_alloc("soc-audio", -1);
275 if (!tosa_snd_device) {
276 ret = -ENOMEM;
277 goto err_alloc;
280 platform_set_drvdata(tosa_snd_device, &tosa_snd_devdata);
281 tosa_snd_devdata.dev = &tosa_snd_device->dev;
282 ret = platform_device_add(tosa_snd_device);
284 if (!ret)
285 return 0;
287 platform_device_put(tosa_snd_device);
289 err_alloc:
290 return ret;
293 static void __exit tosa_exit(void)
295 platform_device_unregister(tosa_snd_device);
298 module_init(tosa_init);
299 module_exit(tosa_exit);
301 /* Module information */
302 MODULE_AUTHOR("Richard Purdie");
303 MODULE_DESCRIPTION("ALSA SoC Tosa");
304 MODULE_LICENSE("GPL");