Merge tag 'selinux-pr-20201214' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / sound / soc / pxa / mioa701_wm9713.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Handles the Mitac mioa701 SoC system
4  *
5  * Copyright (C) 2008 Robert Jarzmik
6  *
7  * This is a little schema of the sound interconnections :
8  *
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  *                           +-------------------+        ---
29  */
30
31 #include <linux/module.h>
32 #include <linux/moduleparam.h>
33 #include <linux/platform_device.h>
34
35 #include <asm/mach-types.h>
36 #include <mach/audio.h>
37
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>
43
44 #include "../codecs/wm9713.h"
45
46 #define AC97_GPIO_PULL          0x58
47
48 /* Use GPIO8 for rear speaker amplifier */
49 static int rear_amp_power(struct snd_soc_component *component, int power)
50 {
51         unsigned short reg;
52
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));
63         }
64
65         return 0;
66 }
67
68 static int rear_amp_event(struct snd_soc_dapm_widget *widget,
69                           struct snd_kcontrol *kctl, int event)
70 {
71         struct snd_soc_card *card = widget->dapm->card;
72         struct snd_soc_pcm_runtime *rtd;
73         struct snd_soc_component *component;
74
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));
78 }
79
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),
89 };
90
91 static const struct snd_soc_dapm_route audio_map[] = {
92         /* Call Mic */
93         {"Mic Bias", NULL, "Front Mic"},
94         {"MIC1", NULL, "Mic Bias"},
95
96         /* Headset Mic */
97         {"LINEL", NULL, "Headset Mic"},
98         {"LINER", NULL, "Headset Mic"},
99
100         /* GSM Module */
101         {"MONOIN", NULL, "GSM Line Out"},
102         {"PCBEEP", NULL, "GSM Line Out"},
103         {"GSM Line In", NULL, "MONO"},
104
105         /* headphone connected to HPL, HPR */
106         {"Headset", NULL, "HPL"},
107         {"Headset", NULL, "HPR"},
108
109         /* front speaker connected to HPL, OUT3 */
110         {"Front Speaker", NULL, "HPL"},
111         {"Front Speaker", NULL, "OUT3"},
112
113         /* rear speaker connected to SPKL, SPKR */
114         {"Rear Speaker", NULL, "SPKL"},
115         {"Rear Speaker", NULL, "SPKR"},
116 };
117
118 static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
119 {
120         struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
121
122         /* Prepare GPIO8 for rear speaker amplifier */
123         snd_soc_component_update_bits(component, AC97_GPIO_CFG, 0x100, 0x100);
124
125         /* Prepare MIC input */
126         snd_soc_component_update_bits(component, AC97_3D_CONTROL, 0xc000, 0xc000);
127
128         return 0;
129 }
130
131 static struct snd_soc_ops mioa701_ops;
132
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")));
137
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")));
142
143 static struct snd_soc_dai_link mioa701_dai[] = {
144         {
145                 .name = "AC97",
146                 .stream_name = "AC97 HiFi",
147                 .init = mioa701_wm9713_init,
148                 .ops = &mioa701_ops,
149                 SND_SOC_DAILINK_REG(ac97),
150         },
151         {
152                 .name = "AC97 Aux",
153                 .stream_name = "AC97 Aux",
154                 .ops = &mioa701_ops,
155                 SND_SOC_DAILINK_REG(ac97_aux),
156         },
157 };
158
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),
164
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),
169 };
170
171 static int mioa701_wm9713_probe(struct platform_device *pdev)
172 {
173         int rc;
174
175         if (!machine_is_mioa701())
176                 return -ENODEV;
177
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;
185 }
186
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,
192         },
193 };
194
195 module_platform_driver(mioa701_wm9713_driver);
196
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");