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/audio.h>
22 #include <mach/eseries-gpio.h>
24 #include <asm/mach-types.h>
26 #include "../codecs/wm9705.h"
27 #include "pxa2xx-pcm.h"
28 #include "pxa2xx-ac97.h"
31 #define E740_AUDIO_OUT 1
32 #define E740_AUDIO_IN 2
34 static int e740_audio_power
;
36 static void e740_sync_audio_power(int status
)
38 gpio_set_value(GPIO_E740_WM9705_nAVDD2
, !status
);
39 gpio_set_value(GPIO_E740_AMP_ON
, (status
& E740_AUDIO_OUT
) ? 1 : 0);
40 gpio_set_value(GPIO_E740_MIC_ON
, (status
& E740_AUDIO_IN
) ? 1 : 0);
43 static int e740_mic_amp_event(struct snd_soc_dapm_widget
*w
,
44 struct snd_kcontrol
*kcontrol
, int event
)
46 if (event
& SND_SOC_DAPM_PRE_PMU
)
47 e740_audio_power
|= E740_AUDIO_IN
;
48 else if (event
& SND_SOC_DAPM_POST_PMD
)
49 e740_audio_power
&= ~E740_AUDIO_IN
;
51 e740_sync_audio_power(e740_audio_power
);
56 static int e740_output_amp_event(struct snd_soc_dapm_widget
*w
,
57 struct snd_kcontrol
*kcontrol
, int event
)
59 if (event
& SND_SOC_DAPM_PRE_PMU
)
60 e740_audio_power
|= E740_AUDIO_OUT
;
61 else if (event
& SND_SOC_DAPM_POST_PMD
)
62 e740_audio_power
&= ~E740_AUDIO_OUT
;
64 e740_sync_audio_power(e740_audio_power
);
69 static const struct snd_soc_dapm_widget e740_dapm_widgets
[] = {
70 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
71 SND_SOC_DAPM_SPK("Speaker", NULL
),
72 SND_SOC_DAPM_MIC("Mic (Internal)", NULL
),
73 SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM
, 0, 0, NULL
, 0,
74 e740_output_amp_event
, SND_SOC_DAPM_PRE_PMU
|
75 SND_SOC_DAPM_POST_PMD
),
76 SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM
, 0, 0, NULL
, 0,
77 e740_mic_amp_event
, SND_SOC_DAPM_PRE_PMU
|
78 SND_SOC_DAPM_POST_PMD
),
81 static const struct snd_soc_dapm_route audio_map
[] = {
82 {"Output Amp", NULL
, "LOUT"},
83 {"Output Amp", NULL
, "ROUT"},
84 {"Output Amp", NULL
, "MONOOUT"},
86 {"Speaker", NULL
, "Output Amp"},
87 {"Headphone Jack", NULL
, "Output Amp"},
89 {"MIC1", NULL
, "Mic Amp"},
90 {"Mic Amp", NULL
, "Mic (Internal)"},
93 static int e740_ac97_init(struct snd_soc_codec
*codec
)
95 snd_soc_dapm_nc_pin(codec
, "HPOUTL");
96 snd_soc_dapm_nc_pin(codec
, "HPOUTR");
97 snd_soc_dapm_nc_pin(codec
, "PHONE");
98 snd_soc_dapm_nc_pin(codec
, "LINEINL");
99 snd_soc_dapm_nc_pin(codec
, "LINEINR");
100 snd_soc_dapm_nc_pin(codec
, "CDINL");
101 snd_soc_dapm_nc_pin(codec
, "CDINR");
102 snd_soc_dapm_nc_pin(codec
, "PCBEEP");
103 snd_soc_dapm_nc_pin(codec
, "MIC2");
105 snd_soc_dapm_new_controls(codec
, e740_dapm_widgets
,
106 ARRAY_SIZE(e740_dapm_widgets
));
108 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
110 snd_soc_dapm_sync(codec
);
115 static struct snd_soc_dai_link e740_dai
[] = {
118 .stream_name
= "AC97 HiFi",
119 .cpu_dai
= &pxa_ac97_dai
[PXA2XX_DAI_AC97_HIFI
],
120 .codec_dai
= &wm9705_dai
[WM9705_DAI_AC97_HIFI
],
121 .init
= e740_ac97_init
,
125 .stream_name
= "AC97 Aux",
126 .cpu_dai
= &pxa_ac97_dai
[PXA2XX_DAI_AC97_AUX
],
127 .codec_dai
= &wm9705_dai
[WM9705_DAI_AC97_AUX
],
131 static struct snd_soc_card e740
= {
132 .name
= "Toshiba e740",
133 .platform
= &pxa2xx_soc_platform
,
134 .dai_link
= e740_dai
,
135 .num_links
= ARRAY_SIZE(e740_dai
),
138 static struct snd_soc_device e740_snd_devdata
= {
140 .codec_dev
= &soc_codec_dev_wm9705
,
143 static struct platform_device
*e740_snd_device
;
145 static int __init
e740_init(void)
149 if (!machine_is_e740())
152 ret
= gpio_request(GPIO_E740_MIC_ON
, "Mic amp");
156 ret
= gpio_request(GPIO_E740_AMP_ON
, "Output amp");
158 goto free_mic_amp_gpio
;
160 ret
= gpio_request(GPIO_E740_WM9705_nAVDD2
, "Audio power");
162 goto free_op_amp_gpio
;
165 ret
= gpio_direction_output(GPIO_E740_MIC_ON
, 0);
168 ret
= gpio_direction_output(GPIO_E740_AMP_ON
, 0);
171 ret
= gpio_direction_output(GPIO_E740_WM9705_nAVDD2
, 1);
175 e740_snd_device
= platform_device_alloc("soc-audio", -1);
176 if (!e740_snd_device
) {
181 platform_set_drvdata(e740_snd_device
, &e740_snd_devdata
);
182 e740_snd_devdata
.dev
= &e740_snd_device
->dev
;
183 ret
= platform_device_add(e740_snd_device
);
188 /* Fail gracefully */
189 platform_device_put(e740_snd_device
);
191 gpio_free(GPIO_E740_WM9705_nAVDD2
);
193 gpio_free(GPIO_E740_AMP_ON
);
195 gpio_free(GPIO_E740_MIC_ON
);
200 static void __exit
e740_exit(void)
202 platform_device_unregister(e740_snd_device
);
205 module_init(e740_init
);
206 module_exit(e740_exit
);
208 /* Module information */
209 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
210 MODULE_DESCRIPTION("ALSA SoC driver for e740");
211 MODULE_LICENSE("GPL v2");