2 * spitz.c -- SoC audio for Sharp SL-Cxx00 models Spitz, Borzoi and Akita
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
7 * Authors: Liam Girdwood <lrg@slimlogic.co.uk>
8 * Richard Purdie <richard@openedhand.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/timer.h>
20 #include <linux/interrupt.h>
21 #include <linux/platform_device.h>
22 #include <linux/gpio.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/soc.h>
27 #include <asm/mach-types.h>
28 #include <mach/spitz.h>
29 #include "../codecs/wm8750.h"
30 #include "pxa2xx-i2s.h"
35 #define SPITZ_HEADSET 3
36 #define SPITZ_HP_OFF 4
37 #define SPITZ_SPK_ON 0
38 #define SPITZ_SPK_OFF 1
40 /* audio clock in Hz - rounded from 12.235MHz */
41 #define SPITZ_AUDIO_CLOCK 12288000
43 static int spitz_jack_func
;
44 static int spitz_spk_func
;
45 static int spitz_mic_gpio
;
47 static void spitz_ext_control(struct snd_soc_codec
*codec
)
49 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
51 if (spitz_spk_func
== SPITZ_SPK_ON
)
52 snd_soc_dapm_enable_pin(dapm
, "Ext Spk");
54 snd_soc_dapm_disable_pin(dapm
, "Ext Spk");
56 /* set up jack connection */
57 switch (spitz_jack_func
) {
59 /* enable and unmute hp jack, disable mic bias */
60 snd_soc_dapm_disable_pin(dapm
, "Headset Jack");
61 snd_soc_dapm_disable_pin(dapm
, "Mic Jack");
62 snd_soc_dapm_disable_pin(dapm
, "Line Jack");
63 snd_soc_dapm_enable_pin(dapm
, "Headphone Jack");
64 gpio_set_value(SPITZ_GPIO_MUTE_L
, 1);
65 gpio_set_value(SPITZ_GPIO_MUTE_R
, 1);
68 /* enable mic jack and bias, mute hp */
69 snd_soc_dapm_disable_pin(dapm
, "Headphone Jack");
70 snd_soc_dapm_disable_pin(dapm
, "Headset Jack");
71 snd_soc_dapm_disable_pin(dapm
, "Line Jack");
72 snd_soc_dapm_enable_pin(dapm
, "Mic Jack");
73 gpio_set_value(SPITZ_GPIO_MUTE_L
, 0);
74 gpio_set_value(SPITZ_GPIO_MUTE_R
, 0);
77 /* enable line jack, disable mic bias and mute hp */
78 snd_soc_dapm_disable_pin(dapm
, "Headphone Jack");
79 snd_soc_dapm_disable_pin(dapm
, "Headset Jack");
80 snd_soc_dapm_disable_pin(dapm
, "Mic Jack");
81 snd_soc_dapm_enable_pin(dapm
, "Line Jack");
82 gpio_set_value(SPITZ_GPIO_MUTE_L
, 0);
83 gpio_set_value(SPITZ_GPIO_MUTE_R
, 0);
86 /* enable and unmute headset jack enable mic bias, mute L hp */
87 snd_soc_dapm_disable_pin(dapm
, "Headphone Jack");
88 snd_soc_dapm_enable_pin(dapm
, "Mic Jack");
89 snd_soc_dapm_disable_pin(dapm
, "Line Jack");
90 snd_soc_dapm_enable_pin(dapm
, "Headset Jack");
91 gpio_set_value(SPITZ_GPIO_MUTE_L
, 0);
92 gpio_set_value(SPITZ_GPIO_MUTE_R
, 1);
96 /* jack removed, everything off */
97 snd_soc_dapm_disable_pin(dapm
, "Headphone Jack");
98 snd_soc_dapm_disable_pin(dapm
, "Headset Jack");
99 snd_soc_dapm_disable_pin(dapm
, "Mic Jack");
100 snd_soc_dapm_disable_pin(dapm
, "Line Jack");
101 gpio_set_value(SPITZ_GPIO_MUTE_L
, 0);
102 gpio_set_value(SPITZ_GPIO_MUTE_R
, 0);
105 snd_soc_dapm_sync(dapm
);
108 static int spitz_startup(struct snd_pcm_substream
*substream
)
110 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
111 struct snd_soc_codec
*codec
= rtd
->codec
;
113 mutex_lock(&codec
->mutex
);
115 /* check the jack status at stream startup */
116 spitz_ext_control(codec
);
118 mutex_unlock(&codec
->mutex
);
123 static int spitz_hw_params(struct snd_pcm_substream
*substream
,
124 struct snd_pcm_hw_params
*params
)
126 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
127 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
128 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
129 unsigned int clk
= 0;
132 switch (params_rate(params
)) {
146 /* set the codec system clock for DAC and ADC */
147 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8750_SYSCLK
, clk
,
152 /* set the I2S system clock as input (unused) */
153 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA2XX_I2S_SYSCLK
, 0,
161 static struct snd_soc_ops spitz_ops
= {
162 .startup
= spitz_startup
,
163 .hw_params
= spitz_hw_params
,
166 static int spitz_get_jack(struct snd_kcontrol
*kcontrol
,
167 struct snd_ctl_elem_value
*ucontrol
)
169 ucontrol
->value
.integer
.value
[0] = spitz_jack_func
;
173 static int spitz_set_jack(struct snd_kcontrol
*kcontrol
,
174 struct snd_ctl_elem_value
*ucontrol
)
176 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
178 if (spitz_jack_func
== ucontrol
->value
.integer
.value
[0])
181 spitz_jack_func
= ucontrol
->value
.integer
.value
[0];
182 spitz_ext_control(codec
);
186 static int spitz_get_spk(struct snd_kcontrol
*kcontrol
,
187 struct snd_ctl_elem_value
*ucontrol
)
189 ucontrol
->value
.integer
.value
[0] = spitz_spk_func
;
193 static int spitz_set_spk(struct snd_kcontrol
*kcontrol
,
194 struct snd_ctl_elem_value
*ucontrol
)
196 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
198 if (spitz_spk_func
== ucontrol
->value
.integer
.value
[0])
201 spitz_spk_func
= ucontrol
->value
.integer
.value
[0];
202 spitz_ext_control(codec
);
206 static int spitz_mic_bias(struct snd_soc_dapm_widget
*w
,
207 struct snd_kcontrol
*k
, int event
)
209 gpio_set_value_cansleep(spitz_mic_gpio
, SND_SOC_DAPM_EVENT_ON(event
));
213 /* spitz machine dapm widgets */
214 static const struct snd_soc_dapm_widget wm8750_dapm_widgets
[] = {
215 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
216 SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias
),
217 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
218 SND_SOC_DAPM_LINE("Line Jack", NULL
),
220 /* headset is a mic and mono headphone */
221 SND_SOC_DAPM_HP("Headset Jack", NULL
),
224 /* Spitz machine audio_map */
225 static const struct snd_soc_dapm_route spitz_audio_map
[] = {
227 /* headphone connected to LOUT1, ROUT1 */
228 {"Headphone Jack", NULL
, "LOUT1"},
229 {"Headphone Jack", NULL
, "ROUT1"},
231 /* headset connected to ROUT1 and LINPUT1 with bias (def below) */
232 {"Headset Jack", NULL
, "ROUT1"},
234 /* ext speaker connected to LOUT2, ROUT2 */
235 {"Ext Spk", NULL
, "ROUT2"},
236 {"Ext Spk", NULL
, "LOUT2"},
238 /* mic is connected to input 1 - with bias */
239 {"LINPUT1", NULL
, "Mic Bias"},
240 {"Mic Bias", NULL
, "Mic Jack"},
242 /* line is connected to input 1 - no bias */
243 {"LINPUT1", NULL
, "Line Jack"},
246 static const char *jack_function
[] = {"Headphone", "Mic", "Line", "Headset",
248 static const char *spk_function
[] = {"On", "Off"};
249 static const struct soc_enum spitz_enum
[] = {
250 SOC_ENUM_SINGLE_EXT(5, jack_function
),
251 SOC_ENUM_SINGLE_EXT(2, spk_function
),
254 static const struct snd_kcontrol_new wm8750_spitz_controls
[] = {
255 SOC_ENUM_EXT("Jack Function", spitz_enum
[0], spitz_get_jack
,
257 SOC_ENUM_EXT("Speaker Function", spitz_enum
[1], spitz_get_spk
,
262 * Logic for a wm8750 as connected on a Sharp SL-Cxx00 Device
264 static int spitz_wm8750_init(struct snd_soc_pcm_runtime
*rtd
)
266 struct snd_soc_codec
*codec
= rtd
->codec
;
267 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
270 snd_soc_dapm_nc_pin(dapm
, "RINPUT1");
271 snd_soc_dapm_nc_pin(dapm
, "LINPUT2");
272 snd_soc_dapm_nc_pin(dapm
, "RINPUT2");
273 snd_soc_dapm_nc_pin(dapm
, "LINPUT3");
274 snd_soc_dapm_nc_pin(dapm
, "RINPUT3");
275 snd_soc_dapm_nc_pin(dapm
, "OUT3");
276 snd_soc_dapm_nc_pin(dapm
, "MONO1");
281 /* spitz digital audio interface glue - connects codec <--> CPU */
282 static struct snd_soc_dai_link spitz_dai
= {
284 .stream_name
= "WM8750",
285 .cpu_dai_name
= "pxa2xx-i2s",
286 .codec_dai_name
= "wm8750-hifi",
287 .platform_name
= "pxa-pcm-audio",
288 .codec_name
= "wm8750.0-001b",
289 .init
= spitz_wm8750_init
,
290 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
291 SND_SOC_DAIFMT_CBS_CFS
,
295 /* spitz audio machine driver */
296 static struct snd_soc_card snd_soc_spitz
= {
298 .owner
= THIS_MODULE
,
299 .dai_link
= &spitz_dai
,
302 .controls
= wm8750_spitz_controls
,
303 .num_controls
= ARRAY_SIZE(wm8750_spitz_controls
),
304 .dapm_widgets
= wm8750_dapm_widgets
,
305 .num_dapm_widgets
= ARRAY_SIZE(wm8750_dapm_widgets
),
306 .dapm_routes
= spitz_audio_map
,
307 .num_dapm_routes
= ARRAY_SIZE(spitz_audio_map
),
310 static struct platform_device
*spitz_snd_device
;
312 static int __init
spitz_init(void)
316 if (!(machine_is_spitz() || machine_is_borzoi() || machine_is_akita()))
319 if (machine_is_borzoi() || machine_is_spitz())
320 spitz_mic_gpio
= SPITZ_GPIO_MIC_BIAS
;
322 spitz_mic_gpio
= AKITA_GPIO_MIC_BIAS
;
324 ret
= gpio_request(spitz_mic_gpio
, "MIC GPIO");
328 ret
= gpio_direction_output(spitz_mic_gpio
, 0);
332 spitz_snd_device
= platform_device_alloc("soc-audio", -1);
333 if (!spitz_snd_device
) {
338 platform_set_drvdata(spitz_snd_device
, &snd_soc_spitz
);
340 ret
= platform_device_add(spitz_snd_device
);
347 platform_device_put(spitz_snd_device
);
349 gpio_free(spitz_mic_gpio
);
354 static void __exit
spitz_exit(void)
356 platform_device_unregister(spitz_snd_device
);
357 gpio_free(spitz_mic_gpio
);
360 module_init(spitz_init
);
361 module_exit(spitz_exit
);
363 MODULE_AUTHOR("Richard Purdie");
364 MODULE_DESCRIPTION("ALSA SoC Spitz");
365 MODULE_LICENSE("GPL");