1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43#include <linux/module.h>
44#include <linux/moduleparam.h>
45#include <linux/platform_device.h>
46
47#include <asm/mach-types.h>
48#include <mach/audio.h>
49
50#include <sound/core.h>
51#include <sound/pcm.h>
52#include <sound/soc.h>
53#include <sound/initval.h>
54#include <sound/ac97_codec.h>
55
56#include "../codecs/wm9713.h"
57
58#define AC97_GPIO_PULL 0x58
59
60
61static int rear_amp_power(struct snd_soc_component *component, int power)
62{
63 unsigned short reg;
64
65 if (power) {
66 reg = snd_soc_component_read32(component, AC97_GPIO_CFG);
67 snd_soc_component_write(component, AC97_GPIO_CFG, reg | 0x0100);
68 reg = snd_soc_component_read32(component, AC97_GPIO_PULL);
69 snd_soc_component_write(component, AC97_GPIO_PULL, reg | (1<<15));
70 } else {
71 reg = snd_soc_component_read32(component, AC97_GPIO_CFG);
72 snd_soc_component_write(component, AC97_GPIO_CFG, reg & ~0x0100);
73 reg = snd_soc_component_read32(component, AC97_GPIO_PULL);
74 snd_soc_component_write(component, AC97_GPIO_PULL, reg & ~(1<<15));
75 }
76
77 return 0;
78}
79
80static int rear_amp_event(struct snd_soc_dapm_widget *widget,
81 struct snd_kcontrol *kctl, int event)
82{
83 struct snd_soc_card *card = widget->dapm->card;
84 struct snd_soc_pcm_runtime *rtd;
85 struct snd_soc_component *component;
86
87 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
88 component = rtd->codec_dai->component;
89 return rear_amp_power(component, SND_SOC_DAPM_EVENT_ON(event));
90}
91
92
93static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = {
94 SND_SOC_DAPM_SPK("Front Speaker", NULL),
95 SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event),
96 SND_SOC_DAPM_MIC("Headset", NULL),
97 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
98 SND_SOC_DAPM_LINE("GSM Line In", NULL),
99 SND_SOC_DAPM_MIC("Headset Mic", NULL),
100 SND_SOC_DAPM_MIC("Front Mic", NULL),
101};
102
103static const struct snd_soc_dapm_route audio_map[] = {
104
105 {"Mic Bias", NULL, "Front Mic"},
106 {"MIC1", NULL, "Mic Bias"},
107
108
109 {"LINEL", NULL, "Headset Mic"},
110 {"LINER", NULL, "Headset Mic"},
111
112
113 {"MONOIN", NULL, "GSM Line Out"},
114 {"PCBEEP", NULL, "GSM Line Out"},
115 {"GSM Line In", NULL, "MONO"},
116
117
118 {"Headset", NULL, "HPL"},
119 {"Headset", NULL, "HPR"},
120
121
122 {"Front Speaker", NULL, "HPL"},
123 {"Front Speaker", NULL, "OUT3"},
124
125
126 {"Rear Speaker", NULL, "SPKL"},
127 {"Rear Speaker", NULL, "SPKR"},
128};
129
130static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
131{
132 struct snd_soc_component *component = rtd->codec_dai->component;
133
134
135 snd_soc_component_update_bits(component, AC97_GPIO_CFG, 0x100, 0x100);
136
137
138 snd_soc_component_update_bits(component, AC97_3D_CONTROL, 0xc000, 0xc000);
139
140 return 0;
141}
142
143static struct snd_soc_ops mioa701_ops;
144
145static struct snd_soc_dai_link mioa701_dai[] = {
146 {
147 .name = "AC97",
148 .stream_name = "AC97 HiFi",
149 .cpu_dai_name = "pxa2xx-ac97",
150 .codec_dai_name = "wm9713-hifi",
151 .codec_name = "wm9713-codec",
152 .init = mioa701_wm9713_init,
153 .platform_name = "pxa-pcm-audio",
154 .ops = &mioa701_ops,
155 },
156 {
157 .name = "AC97 Aux",
158 .stream_name = "AC97 Aux",
159 .cpu_dai_name = "pxa2xx-ac97-aux",
160 .codec_dai_name = "wm9713-aux",
161 .codec_name = "wm9713-codec",
162 .platform_name = "pxa-pcm-audio",
163 .ops = &mioa701_ops,
164 },
165};
166
167static struct snd_soc_card mioa701 = {
168 .name = "MioA701",
169 .owner = THIS_MODULE,
170 .dai_link = mioa701_dai,
171 .num_links = ARRAY_SIZE(mioa701_dai),
172
173 .dapm_widgets = mioa701_dapm_widgets,
174 .num_dapm_widgets = ARRAY_SIZE(mioa701_dapm_widgets),
175 .dapm_routes = audio_map,
176 .num_dapm_routes = ARRAY_SIZE(audio_map),
177};
178
179static int mioa701_wm9713_probe(struct platform_device *pdev)
180{
181 int rc;
182
183 if (!machine_is_mioa701())
184 return -ENODEV;
185
186 mioa701.dev = &pdev->dev;
187 rc = devm_snd_soc_register_card(&pdev->dev, &mioa701);
188 if (!rc)
189 dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will "
190 "lead to overheating and possible destruction of your device."
191 " Do not use without a good knowledge of mio's board design!\n");
192 return rc;
193}
194
195static struct platform_driver mioa701_wm9713_driver = {
196 .probe = mioa701_wm9713_probe,
197 .driver = {
198 .name = "mioa701-wm9713",
199 .pm = &snd_soc_pm_ops,
200 },
201};
202
203module_platform_driver(mioa701_wm9713_driver);
204
205
206MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)");
207MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
208MODULE_LICENSE("GPL");
209MODULE_ALIAS("platform:mioa701-wm9713");
210