blob: dc65650a6fa15af240a43de9dab1dbe5e929f228 [file] [log] [blame]
Ian Molton28796ea2009-01-17 15:11:06 +00001/*
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>
Ian Molton28796ea2009-01-17 15:11:06 +000019
Ian Molton28796ea2009-01-17 15:11:06 +000020#include <mach/audio.h>
21#include <mach/eseries-gpio.h>
22
23#include <asm/mach-types.h>
24
25#include "../codecs/wm9705.h"
Ian Molton28796ea2009-01-17 15:11:06 +000026#include "pxa2xx-ac97.h"
27
28
29#define E740_AUDIO_OUT 1
30#define E740_AUDIO_IN 2
31
32static int e740_audio_power;
33
34static void e740_sync_audio_power(int status)
35{
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);
39}
40
41static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
42 struct snd_kcontrol *kcontrol, int event)
43{
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;
48
49 e740_sync_audio_power(e740_audio_power);
50
51 return 0;
52}
53
54static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
55 struct snd_kcontrol *kcontrol, int event)
56{
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;
61
62 e740_sync_audio_power(e740_audio_power);
63
64 return 0;
65}
66
67static 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),
77};
78
79static const struct snd_soc_dapm_route audio_map[] = {
80 {"Output Amp", NULL, "LOUT"},
81 {"Output Amp", NULL, "ROUT"},
82 {"Output Amp", NULL, "MONOOUT"},
83
84 {"Speaker", NULL, "Output Amp"},
85 {"Headphone Jack", NULL, "Output Amp"},
86
87 {"MIC1", NULL, "Mic Amp"},
88 {"Mic Amp", NULL, "Mic (Internal)"},
89};
90
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000091static int e740_ac97_init(struct snd_soc_pcm_runtime *rtd)
Ian Molton28796ea2009-01-17 15:11:06 +000092{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000093 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020094 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095
Liam Girdwoodce6120c2010-11-05 15:53:46 +020096 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");
Ian Molton28796ea2009-01-17 15:11:06 +0000105
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200106 snd_soc_dapm_new_controls(dapm, e740_dapm_widgets,
Ian Molton28796ea2009-01-17 15:11:06 +0000107 ARRAY_SIZE(e740_dapm_widgets));
108
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200109 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Ian Molton28796ea2009-01-17 15:11:06 +0000110
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200111 snd_soc_dapm_sync(dapm);
Ian Molton28796ea2009-01-17 15:11:06 +0000112
113 return 0;
114}
115
116static struct snd_soc_dai_link e740_dai[] = {
117 {
118 .name = "AC97",
119 .stream_name = "AC97 HiFi",
Dmitry Eremin-Solenikov4bfc4e22011-02-23 02:29:11 +0300120 .cpu_dai_name = "pxa2xx-ac97",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000121 .codec_dai_name = "wm9705-hifi",
122 .platform_name = "pxa-pcm-audio",
123 .codec_name = "wm9705-codec",
Ian Molton28796ea2009-01-17 15:11:06 +0000124 .init = e740_ac97_init,
125 },
126 {
127 .name = "AC97 Aux",
128 .stream_name = "AC97 Aux",
Dmitry Eremin-Solenikov4bfc4e22011-02-23 02:29:11 +0300129 .cpu_dai_name = "pxa2xx-ac97-aux",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000130 .codec_dai_name = "wm9705-aux",
131 .platform_name = "pxa-pcm-audio",
132 .codec_name = "wm9705-codec",
Ian Molton28796ea2009-01-17 15:11:06 +0000133 },
134};
135
136static struct snd_soc_card e740 = {
137 .name = "Toshiba e740",
Ian Molton28796ea2009-01-17 15:11:06 +0000138 .dai_link = e740_dai,
139 .num_links = ARRAY_SIZE(e740_dai),
140};
141
Ian Molton28796ea2009-01-17 15:11:06 +0000142static struct platform_device *e740_snd_device;
143
144static int __init e740_init(void)
145{
146 int ret;
147
148 if (!machine_is_e740())
149 return -ENODEV;
150
151 ret = gpio_request(GPIO_E740_MIC_ON, "Mic amp");
152 if (ret)
153 return ret;
154
155 ret = gpio_request(GPIO_E740_AMP_ON, "Output amp");
156 if (ret)
157 goto free_mic_amp_gpio;
158
159 ret = gpio_request(GPIO_E740_WM9705_nAVDD2, "Audio power");
160 if (ret)
161 goto free_op_amp_gpio;
162
163 /* Disable audio */
164 ret = gpio_direction_output(GPIO_E740_MIC_ON, 0);
165 if (ret)
166 goto free_apwr_gpio;
167 ret = gpio_direction_output(GPIO_E740_AMP_ON, 0);
168 if (ret)
169 goto free_apwr_gpio;
170 ret = gpio_direction_output(GPIO_E740_WM9705_nAVDD2, 1);
171 if (ret)
172 goto free_apwr_gpio;
173
174 e740_snd_device = platform_device_alloc("soc-audio", -1);
175 if (!e740_snd_device) {
176 ret = -ENOMEM;
177 goto free_apwr_gpio;
178 }
179
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000180 platform_set_drvdata(e740_snd_device, &e740);
Ian Molton28796ea2009-01-17 15:11:06 +0000181 ret = platform_device_add(e740_snd_device);
182
183 if (!ret)
184 return 0;
185
186/* Fail gracefully */
187 platform_device_put(e740_snd_device);
188free_apwr_gpio:
189 gpio_free(GPIO_E740_WM9705_nAVDD2);
190free_op_amp_gpio:
191 gpio_free(GPIO_E740_AMP_ON);
192free_mic_amp_gpio:
193 gpio_free(GPIO_E740_MIC_ON);
194
195 return ret;
196}
197
198static void __exit e740_exit(void)
199{
200 platform_device_unregister(e740_snd_device);
Axel Linb67696b2010-08-19 14:40:25 +0800201 gpio_free(GPIO_E740_WM9705_nAVDD2);
202 gpio_free(GPIO_E740_AMP_ON);
203 gpio_free(GPIO_E740_MIC_ON);
Ian Molton28796ea2009-01-17 15:11:06 +0000204}
205
206module_init(e740_init);
207module_exit(e740_exit);
208
209/* Module information */
210MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
211MODULE_DESCRIPTION("ALSA SoC driver for e740");
212MODULE_LICENSE("GPL v2");