]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - sound/soc/pxa/spitz.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-hirsute-kernel.git] / sound / soc / pxa / spitz.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
7fb290d0
LG
2/*
3 * spitz.c -- SoC audio for Sharp SL-Cxx00 models Spitz, Borzoi and Akita
4 *
5 * Copyright 2005 Wolfson Microelectronics PLC.
6 * Copyright 2005 Openedhand Ltd.
7 *
d331124d 8 * Authors: Liam Girdwood <lrg@slimlogic.co.uk>
7fb290d0 9 * Richard Purdie <richard@openedhand.com>
7fb290d0
LG
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/timer.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
fff14720 17#include <linux/gpio.h>
7fb290d0
LG
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/soc.h>
7fb290d0
LG
21
22#include <asm/mach-types.h>
a09e64fb 23#include <mach/spitz.h>
7fb290d0 24#include "../codecs/wm8750.h"
97952f60 25#include "pxa2xx-i2s.h"
7fb290d0
LG
26
27#define SPITZ_HP 0
28#define SPITZ_MIC 1
29#define SPITZ_LINE 2
30#define SPITZ_HEADSET 3
31#define SPITZ_HP_OFF 4
32#define SPITZ_SPK_ON 0
33#define SPITZ_SPK_OFF 1
34
35 /* audio clock in Hz - rounded from 12.235MHz */
36#define SPITZ_AUDIO_CLOCK 12288000
37
38static int spitz_jack_func;
39static int spitz_spk_func;
04368d05 40static int spitz_mic_gpio;
7fb290d0 41
059ad760 42static void spitz_ext_control(struct snd_soc_dapm_context *dapm)
7fb290d0 43{
1845a725
CK
44 snd_soc_dapm_mutex_lock(dapm);
45
7fb290d0 46 if (spitz_spk_func == SPITZ_SPK_ON)
1845a725 47 snd_soc_dapm_enable_pin_unlocked(dapm, "Ext Spk");
7fb290d0 48 else
1845a725 49 snd_soc_dapm_disable_pin_unlocked(dapm, "Ext Spk");
7fb290d0
LG
50
51 /* set up jack connection */
52 switch (spitz_jack_func) {
53 case SPITZ_HP:
54 /* enable and unmute hp jack, disable mic bias */
1845a725
CK
55 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
56 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
57 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
58 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
fff14720
EM
59 gpio_set_value(SPITZ_GPIO_MUTE_L, 1);
60 gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
7fb290d0
LG
61 break;
62 case SPITZ_MIC:
63 /* enable mic jack and bias, mute hp */
1845a725
CK
64 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
65 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
66 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
67 snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack");
fff14720
EM
68 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
69 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
7fb290d0
LG
70 break;
71 case SPITZ_LINE:
72 /* enable line jack, disable mic bias and mute hp */
1845a725
CK
73 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
74 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
75 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
76 snd_soc_dapm_enable_pin_unlocked(dapm, "Line Jack");
fff14720
EM
77 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
78 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
7fb290d0
LG
79 break;
80 case SPITZ_HEADSET:
81 /* enable and unmute headset jack enable mic bias, mute L hp */
1845a725
CK
82 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
83 snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack");
84 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
85 snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Jack");
fff14720
EM
86 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
87 gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
7fb290d0
LG
88 break;
89 case SPITZ_HP_OFF:
90
91 /* jack removed, everything off */
1845a725
CK
92 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
93 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
94 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
95 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
fff14720
EM
96 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
97 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
7fb290d0
LG
98 break;
99 }
1845a725
CK
100
101 snd_soc_dapm_sync_unlocked(dapm);
102
103 snd_soc_dapm_mutex_unlock(dapm);
7fb290d0
LG
104}
105
106static int spitz_startup(struct snd_pcm_substream *substream)
107{
108 struct snd_soc_pcm_runtime *rtd = substream->private_data;
71a29560 109
7fb290d0 110 /* check the jack status at stream startup */
e14de47a 111 spitz_ext_control(&rtd->card->dapm);
71a29560 112
7fb290d0
LG
113 return 0;
114}
115
97952f60
LG
116static int spitz_hw_params(struct snd_pcm_substream *substream,
117 struct snd_pcm_hw_params *params)
118{
119 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad
LG
120 struct snd_soc_dai *codec_dai = rtd->codec_dai;
121 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
97952f60
LG
122 unsigned int clk = 0;
123 int ret = 0;
124
125 switch (params_rate(params)) {
126 case 8000:
127 case 16000:
128 case 48000:
129 case 96000:
130 clk = 12288000;
131 break;
132 case 11025:
133 case 22050:
134 case 44100:
135 clk = 11289600;
136 break;
137 }
138
97952f60 139 /* set the codec system clock for DAC and ADC */
64105cfd 140 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
97952f60
LG
141 SND_SOC_CLOCK_IN);
142 if (ret < 0)
143 return ret;
144
145 /* set the I2S system clock as input (unused) */
64105cfd 146 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
97952f60
LG
147 SND_SOC_CLOCK_IN);
148 if (ret < 0)
149 return ret;
150
151 return 0;
152}
153
943b7311 154static const struct snd_soc_ops spitz_ops = {
7fb290d0 155 .startup = spitz_startup,
97952f60 156 .hw_params = spitz_hw_params,
7fb290d0
LG
157};
158
159static int spitz_get_jack(struct snd_kcontrol *kcontrol,
160 struct snd_ctl_elem_value *ucontrol)
161{
49a1ba16 162 ucontrol->value.enumerated.item[0] = spitz_jack_func;
7fb290d0
LG
163 return 0;
164}
165
166static int spitz_set_jack(struct snd_kcontrol *kcontrol,
167 struct snd_ctl_elem_value *ucontrol)
168{
0e66821f 169 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
7fb290d0 170
49a1ba16 171 if (spitz_jack_func == ucontrol->value.enumerated.item[0])
7fb290d0
LG
172 return 0;
173
49a1ba16 174 spitz_jack_func = ucontrol->value.enumerated.item[0];
059ad760 175 spitz_ext_control(&card->dapm);
7fb290d0
LG
176 return 1;
177}
178
179static int spitz_get_spk(struct snd_kcontrol *kcontrol,
180 struct snd_ctl_elem_value *ucontrol)
181{
49a1ba16 182 ucontrol->value.enumerated.item[0] = spitz_spk_func;
7fb290d0
LG
183 return 0;
184}
185
186static int spitz_set_spk(struct snd_kcontrol *kcontrol,
187 struct snd_ctl_elem_value *ucontrol)
188{
059ad760 189 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
7fb290d0 190
49a1ba16 191 if (spitz_spk_func == ucontrol->value.enumerated.item[0])
7fb290d0
LG
192 return 0;
193
49a1ba16 194 spitz_spk_func = ucontrol->value.enumerated.item[0];
059ad760 195 spitz_ext_control(&card->dapm);
7fb290d0
LG
196 return 1;
197}
198
338c7ed0
JN
199static int spitz_mic_bias(struct snd_soc_dapm_widget *w,
200 struct snd_kcontrol *k, int event)
7fb290d0 201{
04368d05 202 gpio_set_value_cansleep(spitz_mic_gpio, SND_SOC_DAPM_EVENT_ON(event));
7fb290d0
LG
203 return 0;
204}
205
206/* spitz machine dapm widgets */
207static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
208 SND_SOC_DAPM_HP("Headphone Jack", NULL),
209 SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
210 SND_SOC_DAPM_SPK("Ext Spk", NULL),
211 SND_SOC_DAPM_LINE("Line Jack", NULL),
212
213 /* headset is a mic and mono headphone */
214 SND_SOC_DAPM_HP("Headset Jack", NULL),
215};
216
217/* Spitz machine audio_map */
7c274263 218static const struct snd_soc_dapm_route spitz_audio_map[] = {
7fb290d0
LG
219
220 /* headphone connected to LOUT1, ROUT1 */
221 {"Headphone Jack", NULL, "LOUT1"},
222 {"Headphone Jack", NULL, "ROUT1"},
223
224 /* headset connected to ROUT1 and LINPUT1 with bias (def below) */
225 {"Headset Jack", NULL, "ROUT1"},
226
227 /* ext speaker connected to LOUT2, ROUT2 */
3e22e9d7
CG
228 {"Ext Spk", NULL, "ROUT2"},
229 {"Ext Spk", NULL, "LOUT2"},
7fb290d0
LG
230
231 /* mic is connected to input 1 - with bias */
232 {"LINPUT1", NULL, "Mic Bias"},
233 {"Mic Bias", NULL, "Mic Jack"},
234
235 /* line is connected to input 1 - no bias */
236 {"LINPUT1", NULL, "Line Jack"},
7fb290d0
LG
237};
238
92be5810
LPC
239static const char * const jack_function[] = {"Headphone", "Mic", "Line",
240 "Headset", "Off"};
241static const char * const spk_function[] = {"On", "Off"};
7fb290d0
LG
242static const struct soc_enum spitz_enum[] = {
243 SOC_ENUM_SINGLE_EXT(5, jack_function),
244 SOC_ENUM_SINGLE_EXT(2, spk_function),
245};
246
247static const struct snd_kcontrol_new wm8750_spitz_controls[] = {
248 SOC_ENUM_EXT("Jack Function", spitz_enum[0], spitz_get_jack,
249 spitz_set_jack),
250 SOC_ENUM_EXT("Speaker Function", spitz_enum[1], spitz_get_spk,
251 spitz_set_spk),
252};
253
7fb290d0
LG
254/* spitz digital audio interface glue - connects codec <--> CPU */
255static struct snd_soc_dai_link spitz_dai = {
256 .name = "wm8750",
257 .stream_name = "WM8750",
a3adfa00 258 .cpu_dai_name = "pxa2xx-i2s",
f0fba2ad
LG
259 .codec_dai_name = "wm8750-hifi",
260 .platform_name = "pxa-pcm-audio",
dc5de62b 261 .codec_name = "wm8750.0-001b",
c0e94231
AL
262 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
263 SND_SOC_DAIFMT_CBS_CFS,
97952f60 264 .ops = &spitz_ops,
7fb290d0
LG
265};
266
267/* spitz audio machine driver */
87506549 268static struct snd_soc_card snd_soc_spitz = {
7fb290d0 269 .name = "Spitz",
561c6a17 270 .owner = THIS_MODULE,
7fb290d0
LG
271 .dai_link = &spitz_dai,
272 .num_links = 1,
7c274263
AL
273
274 .controls = wm8750_spitz_controls,
275 .num_controls = ARRAY_SIZE(wm8750_spitz_controls),
276 .dapm_widgets = wm8750_dapm_widgets,
277 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
278 .dapm_routes = spitz_audio_map,
279 .num_dapm_routes = ARRAY_SIZE(spitz_audio_map),
c4b7586c 280 .fully_routed = true,
7fb290d0
LG
281};
282
ecf00151 283static int spitz_probe(struct platform_device *pdev)
7fb290d0 284{
ecf00151 285 struct snd_soc_card *card = &snd_soc_spitz;
7fb290d0
LG
286 int ret;
287
ecf00151 288 if (machine_is_akita())
04368d05 289 spitz_mic_gpio = AKITA_GPIO_MIC_BIAS;
ecf00151
DB
290 else
291 spitz_mic_gpio = SPITZ_GPIO_MIC_BIAS;
04368d05
MV
292
293 ret = gpio_request(spitz_mic_gpio, "MIC GPIO");
294 if (ret)
295 goto err1;
296
297 ret = gpio_direction_output(spitz_mic_gpio, 0);
298 if (ret)
299 goto err2;
300
ecf00151
DB
301 card->dev = &pdev->dev;
302
2fd7076a 303 ret = devm_snd_soc_register_card(&pdev->dev, card);
ecf00151
DB
304 if (ret) {
305 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
306 ret);
04368d05
MV
307 goto err2;
308 }
7fb290d0 309
04368d05 310 return 0;
7fb290d0 311
04368d05
MV
312err2:
313 gpio_free(spitz_mic_gpio);
314err1:
7fb290d0
LG
315 return ret;
316}
317
ecf00151 318static int spitz_remove(struct platform_device *pdev)
7fb290d0 319{
04368d05 320 gpio_free(spitz_mic_gpio);
ecf00151 321 return 0;
7fb290d0
LG
322}
323
ecf00151
DB
324static struct platform_driver spitz_driver = {
325 .driver = {
326 .name = "spitz-audio",
ecf00151
DB
327 .pm = &snd_soc_pm_ops,
328 },
329 .probe = spitz_probe,
330 .remove = spitz_remove,
331};
332
333module_platform_driver(spitz_driver);
7fb290d0
LG
334
335MODULE_AUTHOR("Richard Purdie");
336MODULE_DESCRIPTION("ALSA SoC Spitz");
337MODULE_LICENSE("GPL");
ecf00151 338MODULE_ALIAS("platform:spitz-audio");