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