rtlwifi: Fix the usage of the wrong variable in usb.c
[linux/fpc-iii.git] / sound / soc / pxa / e740_wm9705.c
blob35ed7eb8cff2e6793147cd52c2acec6a9d86e6b6
1 /*
2 * e740-wm9705.c -- SoC audio for e740
4 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 ONLY.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/gpio.h>
16 #include <sound/core.h>
17 #include <sound/pcm.h>
18 #include <sound/soc.h>
20 #include <mach/audio.h>
21 #include <mach/eseries-gpio.h>
23 #include <asm/mach-types.h>
25 #include "../codecs/wm9705.h"
26 #include "pxa2xx-ac97.h"
29 #define E740_AUDIO_OUT 1
30 #define E740_AUDIO_IN 2
32 static int e740_audio_power;
34 static void e740_sync_audio_power(int status)
36 gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
37 gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
38 gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
41 static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
42 struct snd_kcontrol *kcontrol, int event)
44 if (event & SND_SOC_DAPM_PRE_PMU)
45 e740_audio_power |= E740_AUDIO_IN;
46 else if (event & SND_SOC_DAPM_POST_PMD)
47 e740_audio_power &= ~E740_AUDIO_IN;
49 e740_sync_audio_power(e740_audio_power);
51 return 0;
54 static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
55 struct snd_kcontrol *kcontrol, int event)
57 if (event & SND_SOC_DAPM_PRE_PMU)
58 e740_audio_power |= E740_AUDIO_OUT;
59 else if (event & SND_SOC_DAPM_POST_PMD)
60 e740_audio_power &= ~E740_AUDIO_OUT;
62 e740_sync_audio_power(e740_audio_power);
64 return 0;
67 static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
68 SND_SOC_DAPM_HP("Headphone Jack", NULL),
69 SND_SOC_DAPM_SPK("Speaker", NULL),
70 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
71 SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
72 e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
73 SND_SOC_DAPM_POST_PMD),
74 SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
75 e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
76 SND_SOC_DAPM_POST_PMD),
79 static const struct snd_soc_dapm_route audio_map[] = {
80 {"Output Amp", NULL, "LOUT"},
81 {"Output Amp", NULL, "ROUT"},
82 {"Output Amp", NULL, "MONOOUT"},
84 {"Speaker", NULL, "Output Amp"},
85 {"Headphone Jack", NULL, "Output Amp"},
87 {"MIC1", NULL, "Mic Amp"},
88 {"Mic Amp", NULL, "Mic (Internal)"},
91 static int e740_ac97_init(struct snd_soc_pcm_runtime *rtd)
93 struct snd_soc_codec *codec = rtd->codec;
94 struct snd_soc_dapm_context *dapm = &codec->dapm;
96 snd_soc_dapm_nc_pin(dapm, "HPOUTL");
97 snd_soc_dapm_nc_pin(dapm, "HPOUTR");
98 snd_soc_dapm_nc_pin(dapm, "PHONE");
99 snd_soc_dapm_nc_pin(dapm, "LINEINL");
100 snd_soc_dapm_nc_pin(dapm, "LINEINR");
101 snd_soc_dapm_nc_pin(dapm, "CDINL");
102 snd_soc_dapm_nc_pin(dapm, "CDINR");
103 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
104 snd_soc_dapm_nc_pin(dapm, "MIC2");
106 snd_soc_dapm_new_controls(dapm, e740_dapm_widgets,
107 ARRAY_SIZE(e740_dapm_widgets));
109 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
111 return 0;
114 static struct snd_soc_dai_link e740_dai[] = {
116 .name = "AC97",
117 .stream_name = "AC97 HiFi",
118 .cpu_dai_name = "pxa2xx-ac97",
119 .codec_dai_name = "wm9705-hifi",
120 .platform_name = "pxa-pcm-audio",
121 .codec_name = "wm9705-codec",
122 .init = e740_ac97_init,
125 .name = "AC97 Aux",
126 .stream_name = "AC97 Aux",
127 .cpu_dai_name = "pxa2xx-ac97-aux",
128 .codec_dai_name = "wm9705-aux",
129 .platform_name = "pxa-pcm-audio",
130 .codec_name = "wm9705-codec",
134 static struct snd_soc_card e740 = {
135 .name = "Toshiba e740",
136 .dai_link = e740_dai,
137 .num_links = ARRAY_SIZE(e740_dai),
140 static struct platform_device *e740_snd_device;
142 static int __init e740_init(void)
144 int ret;
146 if (!machine_is_e740())
147 return -ENODEV;
149 ret = gpio_request(GPIO_E740_MIC_ON, "Mic amp");
150 if (ret)
151 return ret;
153 ret = gpio_request(GPIO_E740_AMP_ON, "Output amp");
154 if (ret)
155 goto free_mic_amp_gpio;
157 ret = gpio_request(GPIO_E740_WM9705_nAVDD2, "Audio power");
158 if (ret)
159 goto free_op_amp_gpio;
161 /* Disable audio */
162 ret = gpio_direction_output(GPIO_E740_MIC_ON, 0);
163 if (ret)
164 goto free_apwr_gpio;
165 ret = gpio_direction_output(GPIO_E740_AMP_ON, 0);
166 if (ret)
167 goto free_apwr_gpio;
168 ret = gpio_direction_output(GPIO_E740_WM9705_nAVDD2, 1);
169 if (ret)
170 goto free_apwr_gpio;
172 e740_snd_device = platform_device_alloc("soc-audio", -1);
173 if (!e740_snd_device) {
174 ret = -ENOMEM;
175 goto free_apwr_gpio;
178 platform_set_drvdata(e740_snd_device, &e740);
179 ret = platform_device_add(e740_snd_device);
181 if (!ret)
182 return 0;
184 /* Fail gracefully */
185 platform_device_put(e740_snd_device);
186 free_apwr_gpio:
187 gpio_free(GPIO_E740_WM9705_nAVDD2);
188 free_op_amp_gpio:
189 gpio_free(GPIO_E740_AMP_ON);
190 free_mic_amp_gpio:
191 gpio_free(GPIO_E740_MIC_ON);
193 return ret;
196 static void __exit e740_exit(void)
198 platform_device_unregister(e740_snd_device);
199 gpio_free(GPIO_E740_WM9705_nAVDD2);
200 gpio_free(GPIO_E740_AMP_ON);
201 gpio_free(GPIO_E740_MIC_ON);
204 module_init(e740_init);
205 module_exit(e740_exit);
207 /* Module information */
208 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
209 MODULE_DESCRIPTION("ALSA SoC driver for e740");
210 MODULE_LICENSE("GPL v2");