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 <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
27 #include <asm/mach-types.h>
28 #include <asm/hardware/scoop.h>
29 #include <mach/pxa-regs.h>
30 #include <mach/hardware.h>
31 #include <mach/akita.h>
32 #include <mach/spitz.h>
33 #include "../codecs/wm8750.h"
34 #include "pxa2xx-pcm.h"
35 #include "pxa2xx-i2s.h"
40 #define SPITZ_HEADSET 3
41 #define SPITZ_HP_OFF 4
42 #define SPITZ_SPK_ON 0
43 #define SPITZ_SPK_OFF 1
45 /* audio clock in Hz - rounded from 12.235MHz */
46 #define SPITZ_AUDIO_CLOCK 12288000
48 static int spitz_jack_func;
49 static int spitz_spk_func;
51 static void spitz_ext_control(struct snd_soc_codec *codec)
53 if (spitz_spk_func == SPITZ_SPK_ON)
54 snd_soc_dapm_enable_pin(codec, "Ext Spk");
56 snd_soc_dapm_disable_pin(codec, "Ext Spk");
58 /* set up jack connection */
59 switch (spitz_jack_func) {
61 /* enable and unmute hp jack, disable mic bias */
62 snd_soc_dapm_disable_pin(codec, "Headset Jack");
63 snd_soc_dapm_disable_pin(codec, "Mic Jack");
64 snd_soc_dapm_disable_pin(codec, "Line Jack");
65 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
66 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
67 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
70 /* enable mic jack and bias, mute hp */
71 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
72 snd_soc_dapm_disable_pin(codec, "Headset Jack");
73 snd_soc_dapm_disable_pin(codec, "Line Jack");
74 snd_soc_dapm_enable_pin(codec, "Mic Jack");
75 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
76 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
79 /* enable line jack, disable mic bias and mute hp */
80 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
81 snd_soc_dapm_disable_pin(codec, "Headset Jack");
82 snd_soc_dapm_disable_pin(codec, "Mic Jack");
83 snd_soc_dapm_enable_pin(codec, "Line Jack");
84 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
85 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
88 /* enable and unmute headset jack enable mic bias, mute L hp */
89 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
90 snd_soc_dapm_enable_pin(codec, "Mic Jack");
91 snd_soc_dapm_disable_pin(codec, "Line Jack");
92 snd_soc_dapm_enable_pin(codec, "Headset Jack");
93 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
94 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
98 /* jack removed, everything off */
99 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
100 snd_soc_dapm_disable_pin(codec, "Headset Jack");
101 snd_soc_dapm_disable_pin(codec, "Mic Jack");
102 snd_soc_dapm_disable_pin(codec, "Line Jack");
103 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
104 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
107 snd_soc_dapm_sync(codec);
110 static int spitz_startup(struct snd_pcm_substream *substream)
112 struct snd_soc_pcm_runtime *rtd = substream->private_data;
113 struct snd_soc_codec *codec = rtd->socdev->codec;
115 /* check the jack status at stream startup */
116 spitz_ext_control(codec);
120 static int spitz_hw_params(struct snd_pcm_substream *substream,
121 struct snd_pcm_hw_params *params)
123 struct snd_soc_pcm_runtime *rtd = substream->private_data;
124 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
125 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
126 unsigned int clk = 0;
129 switch (params_rate(params)) {
143 /* set codec DAI configuration */
144 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
145 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
149 /* set cpu DAI configuration */
150 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
151 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
155 /* set the codec system clock for DAC and ADC */
156 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
161 /* set the I2S system clock as input (unused) */
162 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
170 static struct snd_soc_ops spitz_ops = {
171 .startup = spitz_startup,
172 .hw_params = spitz_hw_params,
175 static int spitz_get_jack(struct snd_kcontrol *kcontrol,
176 struct snd_ctl_elem_value *ucontrol)
178 ucontrol->value.integer.value[0] = spitz_jack_func;
182 static int spitz_set_jack(struct snd_kcontrol *kcontrol,
183 struct snd_ctl_elem_value *ucontrol)
185 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
187 if (spitz_jack_func == ucontrol->value.integer.value[0])
190 spitz_jack_func = ucontrol->value.integer.value[0];
191 spitz_ext_control(codec);
195 static int spitz_get_spk(struct snd_kcontrol *kcontrol,
196 struct snd_ctl_elem_value *ucontrol)
198 ucontrol->value.integer.value[0] = spitz_spk_func;
202 static int spitz_set_spk(struct snd_kcontrol *kcontrol,
203 struct snd_ctl_elem_value *ucontrol)
205 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
207 if (spitz_spk_func == ucontrol->value.integer.value[0])
210 spitz_spk_func = ucontrol->value.integer.value[0];
211 spitz_ext_control(codec);
215 static int spitz_mic_bias(struct snd_soc_dapm_widget *w,
216 struct snd_kcontrol *k, int event)
218 if (machine_is_borzoi() || machine_is_spitz()) {
219 if (SND_SOC_DAPM_EVENT_ON(event))
220 set_scoop_gpio(&spitzscoop2_device.dev,
221 SPITZ_SCP2_MIC_BIAS);
223 reset_scoop_gpio(&spitzscoop2_device.dev,
224 SPITZ_SCP2_MIC_BIAS);
227 if (machine_is_akita()) {
228 if (SND_SOC_DAPM_EVENT_ON(event))
229 akita_set_ioexp(&akitaioexp_device.dev,
230 AKITA_IOEXP_MIC_BIAS);
232 akita_reset_ioexp(&akitaioexp_device.dev,
233 AKITA_IOEXP_MIC_BIAS);
238 /* spitz machine dapm widgets */
239 static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
240 SND_SOC_DAPM_HP("Headphone Jack", NULL),
241 SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
242 SND_SOC_DAPM_SPK("Ext Spk", NULL),
243 SND_SOC_DAPM_LINE("Line Jack", NULL),
245 /* headset is a mic and mono headphone */
246 SND_SOC_DAPM_HP("Headset Jack", NULL),
249 /* Spitz machine audio_map */
250 static const struct snd_soc_dapm_route audio_map[] = {
252 /* headphone connected to LOUT1, ROUT1 */
253 {"Headphone Jack", NULL, "LOUT1"},
254 {"Headphone Jack", NULL, "ROUT1"},
256 /* headset connected to ROUT1 and LINPUT1 with bias (def below) */
257 {"Headset Jack", NULL, "ROUT1"},
259 /* ext speaker connected to LOUT2, ROUT2 */
260 {"Ext Spk", NULL , "ROUT2"},
261 {"Ext Spk", NULL , "LOUT2"},
263 /* mic is connected to input 1 - with bias */
264 {"LINPUT1", NULL, "Mic Bias"},
265 {"Mic Bias", NULL, "Mic Jack"},
267 /* line is connected to input 1 - no bias */
268 {"LINPUT1", NULL, "Line Jack"},
271 static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",
273 static const char *spk_function[] = {"On", "Off"};
274 static const struct soc_enum spitz_enum[] = {
275 SOC_ENUM_SINGLE_EXT(5, jack_function),
276 SOC_ENUM_SINGLE_EXT(2, spk_function),
279 static const struct snd_kcontrol_new wm8750_spitz_controls[] = {
280 SOC_ENUM_EXT("Jack Function", spitz_enum[0], spitz_get_jack,
282 SOC_ENUM_EXT("Speaker Function", spitz_enum[1], spitz_get_spk,
287 * Logic for a wm8750 as connected on a Sharp SL-Cxx00 Device
289 static int spitz_wm8750_init(struct snd_soc_codec *codec)
294 snd_soc_dapm_nc_pin(codec, "RINPUT1");
295 snd_soc_dapm_nc_pin(codec, "LINPUT2");
296 snd_soc_dapm_nc_pin(codec, "RINPUT2");
297 snd_soc_dapm_nc_pin(codec, "LINPUT3");
298 snd_soc_dapm_nc_pin(codec, "RINPUT3");
299 snd_soc_dapm_nc_pin(codec, "OUT3");
300 snd_soc_dapm_nc_pin(codec, "MONO1");
302 /* Add spitz specific controls */
303 for (i = 0; i < ARRAY_SIZE(wm8750_spitz_controls); i++) {
304 err = snd_ctl_add(codec->card,
305 snd_soc_cnew(&wm8750_spitz_controls[i], codec, NULL));
310 /* Add spitz specific widgets */
311 snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
312 ARRAY_SIZE(wm8750_dapm_widgets));
314 /* Set up spitz specific audio paths */
315 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
317 snd_soc_dapm_sync(codec);
321 /* spitz digital audio interface glue - connects codec <--> CPU */
322 static struct snd_soc_dai_link spitz_dai = {
324 .stream_name = "WM8750",
325 .cpu_dai = &pxa_i2s_dai,
326 .codec_dai = &wm8750_dai,
327 .init = spitz_wm8750_init,
331 /* spitz audio machine driver */
332 static struct snd_soc_machine snd_soc_machine_spitz = {
334 .dai_link = &spitz_dai,
338 /* spitz audio private data */
339 static struct wm8750_setup_data spitz_wm8750_setup = {
344 /* spitz audio subsystem */
345 static struct snd_soc_device spitz_snd_devdata = {
346 .machine = &snd_soc_machine_spitz,
347 .platform = &pxa2xx_soc_platform,
348 .codec_dev = &soc_codec_dev_wm8750,
349 .codec_data = &spitz_wm8750_setup,
352 static struct platform_device *spitz_snd_device;
354 static int __init spitz_init(void)
358 if (!(machine_is_spitz() || machine_is_borzoi() || machine_is_akita()))
361 spitz_snd_device = platform_device_alloc("soc-audio", -1);
362 if (!spitz_snd_device)
365 platform_set_drvdata(spitz_snd_device, &spitz_snd_devdata);
366 spitz_snd_devdata.dev = &spitz_snd_device->dev;
367 ret = platform_device_add(spitz_snd_device);
370 platform_device_put(spitz_snd_device);
375 static void __exit spitz_exit(void)
377 platform_device_unregister(spitz_snd_device);
380 module_init(spitz_init);
381 module_exit(spitz_exit);
383 MODULE_AUTHOR("Richard Purdie");
384 MODULE_DESCRIPTION("ALSA SoC Spitz");
385 MODULE_LICENSE("GPL");