Merge tag 'powerpc-5.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux/fpc-iii.git] / sound / soc / pxa / mioa701_wm9713.c
blob763db7bbd9bb30592a09b5c37c682cc4e2abcb7a
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Handles the Mitac mioa701 SoC system
5 * Copyright (C) 2008 Robert Jarzmik
7 * This is a little schema of the sound interconnections :
9 * Sagem X200 Wolfson WM9713
10 * +--------+ +-------------------+ Rear Speaker
11 * | | | | /-+
12 * | +--->----->---+MONOIN SPKL+--->----+-+ |
13 * | GSM | | | | | |
14 * | +--->----->---+PCBEEP SPKR+--->----+-+ |
15 * | CHIP | | | \-+
16 * | +---<-----<---+MONO |
17 * | | | | Front Speaker
18 * +--------+ | | /-+
19 * | HPL+--->----+-+ |
20 * | | | | |
21 * | OUT3+--->----+-+ |
22 * | | \-+
23 * | |
24 * | | Front Micro
25 * | | +
26 * | MIC1+-----<--+o+
27 * | | +
28 * +-------------------+ ---
31 #include <linux/module.h>
32 #include <linux/moduleparam.h>
33 #include <linux/platform_device.h>
35 #include <asm/mach-types.h>
36 #include <mach/audio.h>
38 #include <sound/core.h>
39 #include <sound/pcm.h>
40 #include <sound/soc.h>
41 #include <sound/initval.h>
42 #include <sound/ac97_codec.h>
44 #include "../codecs/wm9713.h"
46 #define AC97_GPIO_PULL 0x58
48 /* Use GPIO8 for rear speaker amplifier */
49 static int rear_amp_power(struct snd_soc_component *component, int power)
51 unsigned short reg;
53 if (power) {
54 reg = snd_soc_component_read(component, AC97_GPIO_CFG);
55 snd_soc_component_write(component, AC97_GPIO_CFG, reg | 0x0100);
56 reg = snd_soc_component_read(component, AC97_GPIO_PULL);
57 snd_soc_component_write(component, AC97_GPIO_PULL, reg | (1<<15));
58 } else {
59 reg = snd_soc_component_read(component, AC97_GPIO_CFG);
60 snd_soc_component_write(component, AC97_GPIO_CFG, reg & ~0x0100);
61 reg = snd_soc_component_read(component, AC97_GPIO_PULL);
62 snd_soc_component_write(component, AC97_GPIO_PULL, reg & ~(1<<15));
65 return 0;
68 static int rear_amp_event(struct snd_soc_dapm_widget *widget,
69 struct snd_kcontrol *kctl, int event)
71 struct snd_soc_card *card = widget->dapm->card;
72 struct snd_soc_pcm_runtime *rtd;
73 struct snd_soc_component *component;
75 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
76 component = asoc_rtd_to_codec(rtd, 0)->component;
77 return rear_amp_power(component, SND_SOC_DAPM_EVENT_ON(event));
80 /* mioa701 machine dapm widgets */
81 static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = {
82 SND_SOC_DAPM_SPK("Front Speaker", NULL),
83 SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event),
84 SND_SOC_DAPM_MIC("Headset", NULL),
85 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
86 SND_SOC_DAPM_LINE("GSM Line In", NULL),
87 SND_SOC_DAPM_MIC("Headset Mic", NULL),
88 SND_SOC_DAPM_MIC("Front Mic", NULL),
91 static const struct snd_soc_dapm_route audio_map[] = {
92 /* Call Mic */
93 {"Mic Bias", NULL, "Front Mic"},
94 {"MIC1", NULL, "Mic Bias"},
96 /* Headset Mic */
97 {"LINEL", NULL, "Headset Mic"},
98 {"LINER", NULL, "Headset Mic"},
100 /* GSM Module */
101 {"MONOIN", NULL, "GSM Line Out"},
102 {"PCBEEP", NULL, "GSM Line Out"},
103 {"GSM Line In", NULL, "MONO"},
105 /* headphone connected to HPL, HPR */
106 {"Headset", NULL, "HPL"},
107 {"Headset", NULL, "HPR"},
109 /* front speaker connected to HPL, OUT3 */
110 {"Front Speaker", NULL, "HPL"},
111 {"Front Speaker", NULL, "OUT3"},
113 /* rear speaker connected to SPKL, SPKR */
114 {"Rear Speaker", NULL, "SPKL"},
115 {"Rear Speaker", NULL, "SPKR"},
118 static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
120 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
122 /* Prepare GPIO8 for rear speaker amplifier */
123 snd_soc_component_update_bits(component, AC97_GPIO_CFG, 0x100, 0x100);
125 /* Prepare MIC input */
126 snd_soc_component_update_bits(component, AC97_3D_CONTROL, 0xc000, 0xc000);
128 return 0;
131 static struct snd_soc_ops mioa701_ops;
133 SND_SOC_DAILINK_DEFS(ac97,
134 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
135 DAILINK_COMP_ARRAY(COMP_CODEC("wm9713-codec", "wm9713-hifi")),
136 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
138 SND_SOC_DAILINK_DEFS(ac97_aux,
139 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
140 DAILINK_COMP_ARRAY(COMP_CODEC("wm9713-codec", "wm9713-aux")),
141 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
143 static struct snd_soc_dai_link mioa701_dai[] = {
145 .name = "AC97",
146 .stream_name = "AC97 HiFi",
147 .init = mioa701_wm9713_init,
148 .ops = &mioa701_ops,
149 SND_SOC_DAILINK_REG(ac97),
152 .name = "AC97 Aux",
153 .stream_name = "AC97 Aux",
154 .ops = &mioa701_ops,
155 SND_SOC_DAILINK_REG(ac97_aux),
159 static struct snd_soc_card mioa701 = {
160 .name = "MioA701",
161 .owner = THIS_MODULE,
162 .dai_link = mioa701_dai,
163 .num_links = ARRAY_SIZE(mioa701_dai),
165 .dapm_widgets = mioa701_dapm_widgets,
166 .num_dapm_widgets = ARRAY_SIZE(mioa701_dapm_widgets),
167 .dapm_routes = audio_map,
168 .num_dapm_routes = ARRAY_SIZE(audio_map),
171 static int mioa701_wm9713_probe(struct platform_device *pdev)
173 int rc;
175 if (!machine_is_mioa701())
176 return -ENODEV;
178 mioa701.dev = &pdev->dev;
179 rc = devm_snd_soc_register_card(&pdev->dev, &mioa701);
180 if (!rc)
181 dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will "
182 "lead to overheating and possible destruction of your device."
183 " Do not use without a good knowledge of mio's board design!\n");
184 return rc;
187 static struct platform_driver mioa701_wm9713_driver = {
188 .probe = mioa701_wm9713_probe,
189 .driver = {
190 .name = "mioa701-wm9713",
191 .pm = &snd_soc_pm_ops,
195 module_platform_driver(mioa701_wm9713_driver);
197 /* Module information */
198 MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)");
199 MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
200 MODULE_LICENSE("GPL");
201 MODULE_ALIAS("platform:mioa701-wm9713");