]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - sound/soc/pxa/tosa.c
Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-jammy-kernel.git] / sound / soc / pxa / tosa.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
1b49cb98
LG
2/*
3 * tosa.c -- SoC audio for Tosa
4 *
5 * Copyright 2005 Wolfson Microelectronics PLC.
6 * Copyright 2005 Openedhand Ltd.
7 *
d331124d 8 * Authors: Liam Girdwood <lrg@slimlogic.co.uk>
1b49cb98
LG
9 * Richard Purdie <richard@openedhand.com>
10 *
1b49cb98
LG
11 * GPIO's
12 * 1 - Jack Insertion
13 * 5 - Hookswitch (headset answer/hang up switch)
1b49cb98
LG
14 */
15
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/device.h>
4440cbd6 19#include <linux/gpio.h>
1b49cb98 20
1b49cb98
LG
21#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/soc.h>
1b49cb98
LG
24
25#include <asm/mach-types.h>
a09e64fb 26#include <mach/tosa.h>
a09e64fb 27#include <mach/audio.h>
1b49cb98 28
1b49cb98
LG
29#define TOSA_HP 0
30#define TOSA_MIC_INT 1
31#define TOSA_HEADSET 2
32#define TOSA_HP_OFF 3
33#define TOSA_SPK_ON 0
34#define TOSA_SPK_OFF 1
35
36static int tosa_jack_func;
37static int tosa_spk_func;
38
079942ab 39static void tosa_ext_control(struct snd_soc_dapm_context *dapm)
1b49cb98 40{
ce6120cc 41
26e24ddc
CK
42 snd_soc_dapm_mutex_lock(dapm);
43
1b49cb98
LG
44 /* set up jack connection */
45 switch (tosa_jack_func) {
46 case TOSA_HP:
26e24ddc
CK
47 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic (Internal)");
48 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
49 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
1b49cb98
LG
50 break;
51 case TOSA_MIC_INT:
26e24ddc
CK
52 snd_soc_dapm_enable_pin_unlocked(dapm, "Mic (Internal)");
53 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
54 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
1b49cb98
LG
55 break;
56 case TOSA_HEADSET:
26e24ddc
CK
57 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic (Internal)");
58 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
59 snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Jack");
1b49cb98
LG
60 break;
61 }
62
63 if (tosa_spk_func == TOSA_SPK_ON)
26e24ddc 64 snd_soc_dapm_enable_pin_unlocked(dapm, "Speaker");
a5302181 65 else
26e24ddc
CK
66 snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker");
67
68 snd_soc_dapm_sync_unlocked(dapm);
1b49cb98 69
26e24ddc 70 snd_soc_dapm_mutex_unlock(dapm);
1b49cb98
LG
71}
72
73static int tosa_startup(struct snd_pcm_substream *substream)
74{
75 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1b49cb98
LG
76
77 /* check the jack status at stream startup */
079942ab 78 tosa_ext_control(&rtd->card->dapm);
71a29560 79
1b49cb98
LG
80 return 0;
81}
82
943b7311 83static const struct snd_soc_ops tosa_ops = {
1b49cb98
LG
84 .startup = tosa_startup,
85};
86
87static int tosa_get_jack(struct snd_kcontrol *kcontrol,
88 struct snd_ctl_elem_value *ucontrol)
89{
419396d5 90 ucontrol->value.enumerated.item[0] = tosa_jack_func;
1b49cb98
LG
91 return 0;
92}
93
94static int tosa_set_jack(struct snd_kcontrol *kcontrol,
95 struct snd_ctl_elem_value *ucontrol)
96{
079942ab 97 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
1b49cb98 98
419396d5 99 if (tosa_jack_func == ucontrol->value.enumerated.item[0])
1b49cb98
LG
100 return 0;
101
419396d5 102 tosa_jack_func = ucontrol->value.enumerated.item[0];
079942ab 103 tosa_ext_control(&card->dapm);
1b49cb98
LG
104 return 1;
105}
106
107static int tosa_get_spk(struct snd_kcontrol *kcontrol,
108 struct snd_ctl_elem_value *ucontrol)
109{
419396d5 110 ucontrol->value.enumerated.item[0] = tosa_spk_func;
1b49cb98
LG
111 return 0;
112}
113
114static int tosa_set_spk(struct snd_kcontrol *kcontrol,
115 struct snd_ctl_elem_value *ucontrol)
116{
079942ab 117 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
1b49cb98 118
419396d5 119 if (tosa_spk_func == ucontrol->value.enumerated.item[0])
1b49cb98
LG
120 return 0;
121
419396d5 122 tosa_spk_func = ucontrol->value.enumerated.item[0];
079942ab 123 tosa_ext_control(&card->dapm);
1b49cb98
LG
124 return 1;
125}
126
127/* tosa dapm event handlers */
338c7ed0
JN
128static int tosa_hp_event(struct snd_soc_dapm_widget *w,
129 struct snd_kcontrol *k, int event)
1b49cb98 130{
ca87cfad 131 gpio_set_value(TOSA_GPIO_L_MUTE, SND_SOC_DAPM_EVENT_ON(event) ? 1 : 0);
1b49cb98
LG
132 return 0;
133}
134
135/* tosa machine dapm widgets */
136static const struct snd_soc_dapm_widget tosa_dapm_widgets[] = {
137SND_SOC_DAPM_HP("Headphone Jack", tosa_hp_event),
138SND_SOC_DAPM_HP("Headset Jack", NULL),
139SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
140SND_SOC_DAPM_SPK("Speaker", NULL),
141};
142
143/* tosa audio map */
76d39d0a 144static const struct snd_soc_dapm_route audio_map[] = {
1b49cb98
LG
145
146 /* headphone connected to HPOUTL, HPOUTR */
147 {"Headphone Jack", NULL, "HPOUTL"},
148 {"Headphone Jack", NULL, "HPOUTR"},
149
150 /* ext speaker connected to LOUT2, ROUT2 */
151 {"Speaker", NULL, "LOUT2"},
152 {"Speaker", NULL, "ROUT2"},
153
154 /* internal mic is connected to mic1, mic2 differential - with bias */
155 {"MIC1", NULL, "Mic Bias"},
156 {"MIC2", NULL, "Mic Bias"},
157 {"Mic Bias", NULL, "Mic (Internal)"},
158
159 /* headset is connected to HPOUTR, and LINEINR with bias */
160 {"Headset Jack", NULL, "HPOUTR"},
161 {"LINEINR", NULL, "Mic Bias"},
162 {"Mic Bias", NULL, "Headset Jack"},
1b49cb98
LG
163};
164
92be5810
LPC
165static const char * const jack_function[] = {"Headphone", "Mic", "Line",
166 "Headset", "Off"};
167static const char * const spk_function[] = {"On", "Off"};
1b49cb98
LG
168static const struct soc_enum tosa_enum[] = {
169 SOC_ENUM_SINGLE_EXT(5, jack_function),
170 SOC_ENUM_SINGLE_EXT(2, spk_function),
171};
172
173static const struct snd_kcontrol_new tosa_controls[] = {
174 SOC_ENUM_EXT("Jack Function", tosa_enum[0], tosa_get_jack,
175 tosa_set_jack),
176 SOC_ENUM_EXT("Speaker Function", tosa_enum[1], tosa_get_spk,
177 tosa_set_spk),
178};
179
1b49cb98
LG
180static struct snd_soc_dai_link tosa_dai[] = {
181{
182 .name = "AC97",
183 .stream_name = "AC97 HiFi",
4bfc4e25 184 .cpu_dai_name = "pxa2xx-ac97",
f0fba2ad
LG
185 .codec_dai_name = "wm9712-hifi",
186 .platform_name = "pxa-pcm-audio",
187 .codec_name = "wm9712-codec",
cb4c048b 188 .ops = &tosa_ops,
1b49cb98
LG
189},
190{
191 .name = "AC97 Aux",
192 .stream_name = "AC97 Aux",
4bfc4e25 193 .cpu_dai_name = "pxa2xx-ac97-aux",
f0fba2ad
LG
194 .codec_dai_name = "wm9712-aux",
195 .platform_name = "pxa-pcm-audio",
196 .codec_name = "wm9712-codec",
cb4c048b 197 .ops = &tosa_ops,
1b49cb98
LG
198},
199};
200
87506549 201static struct snd_soc_card tosa = {
1b49cb98 202 .name = "Tosa",
561c6a17 203 .owner = THIS_MODULE,
1b49cb98
LG
204 .dai_link = tosa_dai,
205 .num_links = ARRAY_SIZE(tosa_dai),
079942ab
LPC
206
207 .controls = tosa_controls,
208 .num_controls = ARRAY_SIZE(tosa_controls),
209 .dapm_widgets = tosa_dapm_widgets,
210 .num_dapm_widgets = ARRAY_SIZE(tosa_dapm_widgets),
211 .dapm_routes = audio_map,
212 .num_dapm_routes = ARRAY_SIZE(audio_map),
c02e723f 213 .fully_routed = true,
1b49cb98
LG
214};
215
570f6fe1 216static int tosa_probe(struct platform_device *pdev)
1b49cb98 217{
f285b8c8 218 struct snd_soc_card *card = &tosa;
1b49cb98
LG
219 int ret;
220
f285b8c8
AL
221 ret = gpio_request_one(TOSA_GPIO_L_MUTE, GPIOF_OUT_INIT_LOW,
222 "Headphone Jack");
223 if (ret)
224 return ret;
4440cbd6 225
f285b8c8 226 card->dev = &pdev->dev;
4440cbd6 227
2fd7076a 228 ret = devm_snd_soc_register_card(&pdev->dev, card);
f285b8c8
AL
229 if (ret) {
230 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
231 ret);
232 gpio_free(TOSA_GPIO_L_MUTE);
233 }
1b49cb98
LG
234 return ret;
235}
236
570f6fe1 237static int tosa_remove(struct platform_device *pdev)
1b49cb98 238{
f285b8c8 239 gpio_free(TOSA_GPIO_L_MUTE);
f285b8c8 240 return 0;
1b49cb98
LG
241}
242
f285b8c8
AL
243static struct platform_driver tosa_driver = {
244 .driver = {
245 .name = "tosa-audio",
7db1698f 246 .pm = &snd_soc_pm_ops,
f285b8c8
AL
247 },
248 .probe = tosa_probe,
570f6fe1 249 .remove = tosa_remove,
f285b8c8
AL
250};
251
252module_platform_driver(tosa_driver);
1b49cb98
LG
253
254/* Module information */
255MODULE_AUTHOR("Richard Purdie");
256MODULE_DESCRIPTION("ALSA SoC Tosa");
257MODULE_LICENSE("GPL");
f285b8c8 258MODULE_ALIAS("platform:tosa-audio");