blob: 47052fe3f5f4fce7498f9d04a351ae991f4558df [file] [log] [blame]
Robert Jarzmik8f0dc652009-02-07 14:01:58 +01001/*
2 * Handles the Mitac mioa701 SoC system
3 *
4 * Copyright (C) 2008 Robert Jarzmik
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation in version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * This is a little schema of the sound interconnections :
20 *
21 * Sagem X200 Wolfson WM9713
22 * +--------+ +-------------------+ Rear Speaker
23 * | | | | /-+
24 * | +--->----->---+MONOIN SPKL+--->----+-+ |
25 * | GSM | | | | | |
26 * | +--->----->---+PCBEEP SPKR+--->----+-+ |
27 * | CHIP | | | \-+
28 * | +---<-----<---+MONO |
29 * | | | | Front Speaker
30 * +--------+ | | /-+
31 * | HPL+--->----+-+ |
32 * | | | | |
33 * | OUT3+--->----+-+ |
34 * | | \-+
35 * | |
36 * | | Front Micro
37 * | | +
38 * | MIC1+-----<--+o+
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>
Robert Jarzmik8f0dc652009-02-07 14:01:58 +010053#include <sound/initval.h>
54#include <sound/ac97_codec.h>
55
Robert Jarzmik8f0dc652009-02-07 14:01:58 +010056#include "../codecs/wm9713.h"
57
Robert Jarzmik8f0dc652009-02-07 14:01:58 +010058#define AC97_GPIO_PULL 0x58
59
60/* Use GPIO8 for rear speaker amplifier */
Kuninori Morimoto6aa89ef2018-01-29 04:46:53 +000061static int rear_amp_power(struct snd_soc_component *component, int power)
Robert Jarzmik8f0dc652009-02-07 14:01:58 +010062{
63 unsigned short reg;
64
65 if (power) {
Kuninori Morimoto6aa89ef2018-01-29 04:46:53 +000066 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));
Robert Jarzmik8f0dc652009-02-07 14:01:58 +010070 } else {
Kuninori Morimoto6aa89ef2018-01-29 04:46:53 +000071 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));
Robert Jarzmik8f0dc652009-02-07 14:01:58 +010075 }
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{
Mengdong Lin50159202015-11-18 02:34:01 -050083 struct snd_soc_card *card = widget->dapm->card;
84 struct snd_soc_pcm_runtime *rtd;
Kuninori Morimoto6aa89ef2018-01-29 04:46:53 +000085 struct snd_soc_component *component;
Robert Jarzmik8f0dc652009-02-07 14:01:58 +010086
Mengdong Lin50159202015-11-18 02:34:01 -050087 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
Kuninori Morimoto6aa89ef2018-01-29 04:46:53 +000088 component = rtd->codec_dai->component;
89 return rear_amp_power(component, SND_SOC_DAPM_EVENT_ON(event));
Robert Jarzmik8f0dc652009-02-07 14:01:58 +010090}
91
92/* mioa701 machine dapm widgets */
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 /* Call Mic */
105 {"Mic Bias", NULL, "Front Mic"},
106 {"MIC1", NULL, "Mic Bias"},
107
108 /* Headset Mic */
109 {"LINEL", NULL, "Headset Mic"},
110 {"LINER", NULL, "Headset Mic"},
111
112 /* GSM Module */
113 {"MONOIN", NULL, "GSM Line Out"},
114 {"PCBEEP", NULL, "GSM Line Out"},
115 {"GSM Line In", NULL, "MONO"},
116
117 /* headphone connected to HPL, HPR */
118 {"Headset", NULL, "HPL"},
119 {"Headset", NULL, "HPR"},
120
121 /* front speaker connected to HPL, OUT3 */
122 {"Front Speaker", NULL, "HPL"},
123 {"Front Speaker", NULL, "OUT3"},
124
125 /* rear speaker connected to SPKL, SPKR */
126 {"Rear Speaker", NULL, "SPKL"},
127 {"Rear Speaker", NULL, "SPKR"},
128};
129
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000130static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100131{
Kuninori Morimoto6aa89ef2018-01-29 04:46:53 +0000132 struct snd_soc_component *component = rtd->codec_dai->component;
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100133
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100134 /* Prepare GPIO8 for rear speaker amplifier */
Kuninori Morimoto6aa89ef2018-01-29 04:46:53 +0000135 snd_soc_component_update_bits(component, AC97_GPIO_CFG, 0x100, 0x100);
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100136
137 /* Prepare MIC input */
Kuninori Morimoto6aa89ef2018-01-29 04:46:53 +0000138 snd_soc_component_update_bits(component, AC97_3D_CONTROL, 0xc000, 0xc000);
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100139
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100140 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",
Dmitry Eremin-Solenikov4bfc4e22011-02-23 02:29:11 +0300149 .cpu_dai_name = "pxa2xx-ac97",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000150 .codec_dai_name = "wm9713-hifi",
151 .codec_name = "wm9713-codec",
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100152 .init = mioa701_wm9713_init,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000153 .platform_name = "pxa-pcm-audio",
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100154 .ops = &mioa701_ops,
155 },
156 {
157 .name = "AC97 Aux",
158 .stream_name = "AC97 Aux",
Dmitry Eremin-Solenikov4bfc4e22011-02-23 02:29:11 +0300159 .cpu_dai_name = "pxa2xx-ac97-aux",
Codrut Grosu7be5c5f2017-02-25 22:25:23 +0200160 .codec_dai_name = "wm9713-aux",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000161 .codec_name = "wm9713-codec",
162 .platform_name = "pxa-pcm-audio",
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100163 .ops = &mioa701_ops,
164 },
165};
166
167static struct snd_soc_card mioa701 = {
168 .name = "MioA701",
Axel Lin561c6a12011-12-22 09:44:43 +0800169 .owner = THIS_MODULE,
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100170 .dai_link = mioa701_dai,
171 .num_links = ARRAY_SIZE(mioa701_dai),
Lars-Peter Clausenf6b2a042014-03-01 15:48:18 +0100172
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),
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100177};
178
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500179static int mioa701_wm9713_probe(struct platform_device *pdev)
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100180{
Robert Jarzmik890255e2012-06-30 19:25:08 +0200181 int rc;
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100182
183 if (!machine_is_mioa701())
184 return -ENODEV;
185
Robert Jarzmik890255e2012-06-30 19:25:08 +0200186 mioa701.dev = &pdev->dev;
Axel Lin2fd70762015-09-01 10:32:59 +0800187 rc = devm_snd_soc_register_card(&pdev->dev, &mioa701);
Robert Jarzmik890255e2012-06-30 19:25:08 +0200188 if (!rc)
Colin Ian King28ab49b2016-11-12 16:30:25 +0000189 dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will "
Robert Jarzmik890255e2012-06-30 19:25:08 +0200190 "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;
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100193}
194
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100195static struct platform_driver mioa701_wm9713_driver = {
196 .probe = mioa701_wm9713_probe,
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100197 .driver = {
198 .name = "mioa701-wm9713",
Dmitry Eremin-Solenikov7db16982013-10-17 14:01:37 +0400199 .pm = &snd_soc_pm_ops,
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100200 },
201};
202
Axel Lin2f702a12011-11-25 10:13:37 +0800203module_platform_driver(mioa701_wm9713_driver);
Robert Jarzmik8f0dc652009-02-07 14:01:58 +0100204
205/* Module information */
206MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)");
207MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
208MODULE_LICENSE("GPL");
Andrea Adamie5b7d712016-05-06 17:27:34 +0200209MODULE_ALIAS("platform:mioa701-wm9713");