Commit | Line | Data |
---|---|---|
28796eaf IM |
1 | /* |
2 | * e740-wm9705.c -- SoC audio for e740 | |
3 | * | |
4 | * Copyright 2007 (c) Ian Molton <spyro@f2s.com> | |
5 | * | |
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. | |
9 | * | |
10 | */ | |
11 | ||
12 | #include <linux/module.h> | |
13 | #include <linux/moduleparam.h> | |
14 | #include <linux/gpio.h> | |
15 | ||
16 | #include <sound/core.h> | |
17 | #include <sound/pcm.h> | |
18 | #include <sound/soc.h> | |
19 | #include <sound/soc-dapm.h> | |
20 | ||
21 | #include <mach/pxa-regs.h> | |
22 | #include <mach/hardware.h> | |
23 | #include <mach/audio.h> | |
24 | #include <mach/eseries-gpio.h> | |
25 | ||
26 | #include <asm/mach-types.h> | |
27 | ||
28 | #include "../codecs/wm9705.h" | |
29 | #include "pxa2xx-pcm.h" | |
30 | #include "pxa2xx-ac97.h" | |
31 | ||
32 | ||
33 | #define E740_AUDIO_OUT 1 | |
34 | #define E740_AUDIO_IN 2 | |
35 | ||
36 | static int e740_audio_power; | |
37 | ||
38 | static void e740_sync_audio_power(int status) | |
39 | { | |
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); | |
43 | } | |
44 | ||
45 | static int e740_mic_amp_event(struct snd_soc_dapm_widget *w, | |
46 | struct snd_kcontrol *kcontrol, int event) | |
47 | { | |
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; | |
52 | ||
53 | e740_sync_audio_power(e740_audio_power); | |
54 | ||
55 | return 0; | |
56 | } | |
57 | ||
58 | static int e740_output_amp_event(struct snd_soc_dapm_widget *w, | |
59 | struct snd_kcontrol *kcontrol, int event) | |
60 | { | |
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; | |
65 | ||
66 | e740_sync_audio_power(e740_audio_power); | |
67 | ||
68 | return 0; | |
69 | } | |
70 | ||
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), | |
81 | }; | |
82 | ||
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"}, | |
87 | ||
88 | {"Speaker", NULL, "Output Amp"}, | |
89 | {"Headphone Jack", NULL, "Output Amp"}, | |
90 | ||
91 | {"MIC1", NULL, "Mic Amp"}, | |
92 | {"Mic Amp", NULL, "Mic (Internal)"}, | |
93 | }; | |
94 | ||
95 | static int e740_ac97_init(struct snd_soc_codec *codec) | |
96 | { | |
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"); | |
106 | ||
107 | snd_soc_dapm_new_controls(codec, e740_dapm_widgets, | |
108 | ARRAY_SIZE(e740_dapm_widgets)); | |
109 | ||
110 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | |
111 | ||
112 | snd_soc_dapm_sync(codec); | |
113 | ||
114 | return 0; | |
115 | } | |
116 | ||
117 | static struct snd_soc_dai_link e740_dai[] = { | |
118 | { | |
119 | .name = "AC97", | |
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, | |
124 | }, | |
125 | { | |
126 | .name = "AC97 Aux", | |
127 | .stream_name = "AC97 Aux", | |
128 | .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX], | |
129 | .codec_dai = &wm9705_dai[WM9705_DAI_AC97_AUX], | |
130 | }, | |
131 | }; | |
132 | ||
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), | |
138 | }; | |
139 | ||
140 | static struct snd_soc_device e740_snd_devdata = { | |
141 | .card = &e740, | |
142 | .codec_dev = &soc_codec_dev_wm9705, | |
143 | }; | |
144 | ||
145 | static struct platform_device *e740_snd_device; | |
146 | ||
147 | static int __init e740_init(void) | |
148 | { | |
149 | int ret; | |
150 | ||
151 | if (!machine_is_e740()) | |
152 | return -ENODEV; | |
153 | ||
154 | ret = gpio_request(GPIO_E740_MIC_ON, "Mic amp"); | |
155 | if (ret) | |
156 | return ret; | |
157 | ||
158 | ret = gpio_request(GPIO_E740_AMP_ON, "Output amp"); | |
159 | if (ret) | |
160 | goto free_mic_amp_gpio; | |
161 | ||
162 | ret = gpio_request(GPIO_E740_WM9705_nAVDD2, "Audio power"); | |
163 | if (ret) | |
164 | goto free_op_amp_gpio; | |
165 | ||
166 | /* Disable audio */ | |
167 | ret = gpio_direction_output(GPIO_E740_MIC_ON, 0); | |
168 | if (ret) | |
169 | goto free_apwr_gpio; | |
170 | ret = gpio_direction_output(GPIO_E740_AMP_ON, 0); | |
171 | if (ret) | |
172 | goto free_apwr_gpio; | |
173 | ret = gpio_direction_output(GPIO_E740_WM9705_nAVDD2, 1); | |
174 | if (ret) | |
175 | goto free_apwr_gpio; | |
176 | ||
177 | e740_snd_device = platform_device_alloc("soc-audio", -1); | |
178 | if (!e740_snd_device) { | |
179 | ret = -ENOMEM; | |
180 | goto free_apwr_gpio; | |
181 | } | |
182 | ||
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); | |
186 | ||
187 | if (!ret) | |
188 | return 0; | |
189 | ||
190 | /* Fail gracefully */ | |
191 | platform_device_put(e740_snd_device); | |
192 | free_apwr_gpio: | |
193 | gpio_free(GPIO_E740_WM9705_nAVDD2); | |
194 | free_op_amp_gpio: | |
195 | gpio_free(GPIO_E740_AMP_ON); | |
196 | free_mic_amp_gpio: | |
197 | gpio_free(GPIO_E740_MIC_ON); | |
198 | ||
199 | return ret; | |
200 | } | |
201 | ||
202 | static void __exit e740_exit(void) | |
203 | { | |
204 | platform_device_unregister(e740_snd_device); | |
205 | } | |
206 | ||
207 | module_init(e740_init); | |
208 | module_exit(e740_exit); | |
209 | ||
210 | /* Module information */ | |
211 | MODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); | |
212 | MODULE_DESCRIPTION("ALSA SoC driver for e740"); | |
213 | MODULE_LICENSE("GPL v2"); |