1 // SPDX-License-Identifier: GPL-2.0-only
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
12 * | +--->----->---+MONOIN SPKL+--->----+-+ |
14 * | +--->----->---+PCBEEP SPKR+--->----+-+ |
16 * | +---<-----<---+MONO |
17 * | | | | Front Speaker
21 * | OUT3+--->----+-+ |
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
)
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));
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));
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
[] = {
93 {"Mic Bias", NULL
, "Front Mic"},
94 {"MIC1", NULL
, "Mic Bias"},
97 {"LINEL", NULL
, "Headset Mic"},
98 {"LINER", NULL
, "Headset Mic"},
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);
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
[] = {
146 .stream_name
= "AC97 HiFi",
147 .init
= mioa701_wm9713_init
,
149 SND_SOC_DAILINK_REG(ac97
),
153 .stream_name
= "AC97 Aux",
155 SND_SOC_DAILINK_REG(ac97_aux
),
159 static struct snd_soc_card 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
)
175 if (!machine_is_mioa701())
178 mioa701
.dev
= &pdev
->dev
;
179 rc
= devm_snd_soc_register_card(&pdev
->dev
, &mioa701
);
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");
187 static struct platform_driver mioa701_wm9713_driver
= {
188 .probe
= mioa701_wm9713_probe
,
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");