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>
19 #include <sound/soc-dapm.h>
21 #include <mach/pxa-regs.h>
22 #include <mach/hardware.h>
23 #include <mach/audio.h>
24 #include <mach/eseries-gpio.h>
26 #include <asm/mach-types.h>
28 #include "../codecs/wm9705.h"
29 #include "pxa2xx-pcm.h"
30 #include "pxa2xx-ac97.h"
33 #define E740_AUDIO_OUT 1
34 #define E740_AUDIO_IN 2
36 static int e740_audio_power;
38 static void e740_sync_audio_power(int status)
40 gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
41 gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
42 gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
45 static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
46 struct snd_kcontrol *kcontrol, int event)
48 if (event & SND_SOC_DAPM_PRE_PMU)
49 e740_audio_power |= E740_AUDIO_IN;
50 else if (event & SND_SOC_DAPM_POST_PMD)
51 e740_audio_power &= ~E740_AUDIO_IN;
53 e740_sync_audio_power(e740_audio_power);
58 static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
59 struct snd_kcontrol *kcontrol, int event)
61 if (event & SND_SOC_DAPM_PRE_PMU)
62 e740_audio_power |= E740_AUDIO_OUT;
63 else if (event & SND_SOC_DAPM_POST_PMD)
64 e740_audio_power &= ~E740_AUDIO_OUT;
66 e740_sync_audio_power(e740_audio_power);
71 static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
72 SND_SOC_DAPM_HP("Headphone Jack", NULL),
73 SND_SOC_DAPM_SPK("Speaker", NULL),
74 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
75 SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
76 e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
77 SND_SOC_DAPM_POST_PMD),
78 SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
79 e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
80 SND_SOC_DAPM_POST_PMD),
83 static const struct snd_soc_dapm_route audio_map[] = {
84 {"Output Amp", NULL, "LOUT"},
85 {"Output Amp", NULL, "ROUT"},
86 {"Output Amp", NULL, "MONOOUT"},
88 {"Speaker", NULL, "Output Amp"},
89 {"Headphone Jack", NULL, "Output Amp"},
91 {"MIC1", NULL, "Mic Amp"},
92 {"Mic Amp", NULL, "Mic (Internal)"},
95 static int e740_ac97_init(struct snd_soc_codec *codec)
97 snd_soc_dapm_nc_pin(codec, "HPOUTL");
98 snd_soc_dapm_nc_pin(codec, "HPOUTR");
99 snd_soc_dapm_nc_pin(codec, "PHONE");
100 snd_soc_dapm_nc_pin(codec, "LINEINL");
101 snd_soc_dapm_nc_pin(codec, "LINEINR");
102 snd_soc_dapm_nc_pin(codec, "CDINL");
103 snd_soc_dapm_nc_pin(codec, "CDINR");
104 snd_soc_dapm_nc_pin(codec, "PCBEEP");
105 snd_soc_dapm_nc_pin(codec, "MIC2");
107 snd_soc_dapm_new_controls(codec, e740_dapm_widgets,
108 ARRAY_SIZE(e740_dapm_widgets));
110 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
112 snd_soc_dapm_sync(codec);
117 static struct snd_soc_dai_link e740_dai[] = {
120 .stream_name = "AC97 HiFi",
121 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
122 .codec_dai = &wm9705_dai[WM9705_DAI_AC97_HIFI],
123 .init = e740_ac97_init,
127 .stream_name = "AC97 Aux",
128 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
129 .codec_dai = &wm9705_dai[WM9705_DAI_AC97_AUX],
133 static struct snd_soc_card e740 = {
134 .name = "Toshiba e740",
135 .platform = &pxa2xx_soc_platform,
136 .dai_link = e740_dai,
137 .num_links = ARRAY_SIZE(e740_dai),
140 static struct snd_soc_device e740_snd_devdata = {
142 .codec_dev = &soc_codec_dev_wm9705,
145 static struct platform_device *e740_snd_device;
147 static int __init e740_init(void)
151 if (!machine_is_e740())
154 ret = gpio_request(GPIO_E740_MIC_ON, "Mic amp");
158 ret = gpio_request(GPIO_E740_AMP_ON, "Output amp");
160 goto free_mic_amp_gpio;
162 ret = gpio_request(GPIO_E740_WM9705_nAVDD2, "Audio power");
164 goto free_op_amp_gpio;
167 ret = gpio_direction_output(GPIO_E740_MIC_ON, 0);
170 ret = gpio_direction_output(GPIO_E740_AMP_ON, 0);
173 ret = gpio_direction_output(GPIO_E740_WM9705_nAVDD2, 1);
177 e740_snd_device = platform_device_alloc("soc-audio", -1);
178 if (!e740_snd_device) {
183 platform_set_drvdata(e740_snd_device, &e740_snd_devdata);
184 e740_snd_devdata.dev = &e740_snd_device->dev;
185 ret = platform_device_add(e740_snd_device);
190 /* Fail gracefully */
191 platform_device_put(e740_snd_device);
193 gpio_free(GPIO_E740_WM9705_nAVDD2);
195 gpio_free(GPIO_E740_AMP_ON);
197 gpio_free(GPIO_E740_MIC_ON);
202 static void __exit e740_exit(void)
204 platform_device_unregister(e740_snd_device);
207 module_init(e740_init);
208 module_exit(e740_exit);
210 /* Module information */
211 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
212 MODULE_DESCRIPTION("ALSA SoC driver for e740");
213 MODULE_LICENSE("GPL v2");