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>
26 #include <sound/soc-dapm.h>
28 #include <asm/mach-types.h>
29 #include <mach/pxa-regs.h>
30 #include <mach/hardware.h>
31 #include <mach/spitz.h>
32 #include "../codecs/wm8750.h"
33 #include "pxa2xx-pcm.h"
34 #include "pxa2xx-i2s.h"
39 #define SPITZ_HEADSET 3
40 #define SPITZ_HP_OFF 4
41 #define SPITZ_SPK_ON 0
42 #define SPITZ_SPK_OFF 1
44 /* audio clock in Hz - rounded from 12.235MHz */
45 #define SPITZ_AUDIO_CLOCK 12288000
47 static int spitz_jack_func;
48 static int spitz_spk_func;
50 static void spitz_ext_control(struct snd_soc_codec *codec)
52 if (spitz_spk_func == SPITZ_SPK_ON)
53 snd_soc_dapm_enable_pin(codec, "Ext Spk");
55 snd_soc_dapm_disable_pin(codec, "Ext Spk");
57 /* set up jack connection */
58 switch (spitz_jack_func) {
60 /* enable and unmute hp jack, disable mic bias */
61 snd_soc_dapm_disable_pin(codec, "Headset Jack");
62 snd_soc_dapm_disable_pin(codec, "Mic Jack");
63 snd_soc_dapm_disable_pin(codec, "Line Jack");
64 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
65 gpio_set_value(SPITZ_GPIO_MUTE_L, 1);
66 gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
69 /* enable mic jack and bias, mute hp */
70 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
71 snd_soc_dapm_disable_pin(codec, "Headset Jack");
72 snd_soc_dapm_disable_pin(codec, "Line Jack");
73 snd_soc_dapm_enable_pin(codec, "Mic Jack");
74 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
75 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
78 /* enable line jack, disable mic bias and mute hp */
79 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
80 snd_soc_dapm_disable_pin(codec, "Headset Jack");
81 snd_soc_dapm_disable_pin(codec, "Mic Jack");
82 snd_soc_dapm_enable_pin(codec, "Line Jack");
83 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
84 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
87 /* enable and unmute headset jack enable mic bias, mute L hp */
88 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
89 snd_soc_dapm_enable_pin(codec, "Mic Jack");
90 snd_soc_dapm_disable_pin(codec, "Line Jack");
91 snd_soc_dapm_enable_pin(codec, "Headset Jack");
92 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
93 gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
97 /* jack removed, everything off */
98 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
99 snd_soc_dapm_disable_pin(codec, "Headset Jack");
100 snd_soc_dapm_disable_pin(codec, "Mic Jack");
101 snd_soc_dapm_disable_pin(codec, "Line Jack");
102 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
103 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
106 snd_soc_dapm_sync(codec);
109 static int spitz_startup(struct snd_pcm_substream *substream)
111 struct snd_soc_pcm_runtime *rtd = substream->private_data;
112 struct snd_soc_codec *codec = rtd->socdev->card->codec;
114 /* check the jack status at stream startup */
115 spitz_ext_control(codec);
119 static int spitz_hw_params(struct snd_pcm_substream *substream,
120 struct snd_pcm_hw_params *params)
122 struct snd_soc_pcm_runtime *rtd = substream->private_data;
123 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
124 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
125 unsigned int clk = 0;
128 switch (params_rate(params)) {
142 /* set codec DAI configuration */
143 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
144 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
148 /* set cpu DAI configuration */
149 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
150 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
154 /* set the codec system clock for DAC and ADC */
155 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
160 /* set the I2S system clock as input (unused) */
161 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
169 static struct snd_soc_ops spitz_ops = {
170 .startup = spitz_startup,
171 .hw_params = spitz_hw_params,
174 static int spitz_get_jack(struct snd_kcontrol *kcontrol,
175 struct snd_ctl_elem_value *ucontrol)
177 ucontrol->value.integer.value[0] = spitz_jack_func;
181 static int spitz_set_jack(struct snd_kcontrol *kcontrol,
182 struct snd_ctl_elem_value *ucontrol)
184 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
186 if (spitz_jack_func == ucontrol->value.integer.value[0])
189 spitz_jack_func = ucontrol->value.integer.value[0];
190 spitz_ext_control(codec);
194 static int spitz_get_spk(struct snd_kcontrol *kcontrol,
195 struct snd_ctl_elem_value *ucontrol)
197 ucontrol->value.integer.value[0] = spitz_spk_func;
201 static int spitz_set_spk(struct snd_kcontrol *kcontrol,
202 struct snd_ctl_elem_value *ucontrol)
204 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
206 if (spitz_spk_func == ucontrol->value.integer.value[0])
209 spitz_spk_func = ucontrol->value.integer.value[0];
210 spitz_ext_control(codec);
214 static int spitz_mic_bias(struct snd_soc_dapm_widget *w,
215 struct snd_kcontrol *k, int event)
217 if (machine_is_borzoi() || machine_is_spitz())
218 gpio_set_value(SPITZ_GPIO_MIC_BIAS,
219 SND_SOC_DAPM_EVENT_ON(event));
221 if (machine_is_akita())
222 gpio_set_value(AKITA_GPIO_MIC_BIAS,
223 SND_SOC_DAPM_EVENT_ON(event));
228 /* spitz machine dapm widgets */
229 static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
230 SND_SOC_DAPM_HP("Headphone Jack", NULL),
231 SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
232 SND_SOC_DAPM_SPK("Ext Spk", NULL),
233 SND_SOC_DAPM_LINE("Line Jack", NULL),
235 /* headset is a mic and mono headphone */
236 SND_SOC_DAPM_HP("Headset Jack", NULL),
239 /* Spitz machine audio_map */
240 static const struct snd_soc_dapm_route audio_map[] = {
242 /* headphone connected to LOUT1, ROUT1 */
243 {"Headphone Jack", NULL, "LOUT1"},
244 {"Headphone Jack", NULL, "ROUT1"},
246 /* headset connected to ROUT1 and LINPUT1 with bias (def below) */
247 {"Headset Jack", NULL, "ROUT1"},
249 /* ext speaker connected to LOUT2, ROUT2 */
250 {"Ext Spk", NULL , "ROUT2"},
251 {"Ext Spk", NULL , "LOUT2"},
253 /* mic is connected to input 1 - with bias */
254 {"LINPUT1", NULL, "Mic Bias"},
255 {"Mic Bias", NULL, "Mic Jack"},
257 /* line is connected to input 1 - no bias */
258 {"LINPUT1", NULL, "Line Jack"},
261 static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",
263 static const char *spk_function[] = {"On", "Off"};
264 static const struct soc_enum spitz_enum[] = {
265 SOC_ENUM_SINGLE_EXT(5, jack_function),
266 SOC_ENUM_SINGLE_EXT(2, spk_function),
269 static const struct snd_kcontrol_new wm8750_spitz_controls[] = {
270 SOC_ENUM_EXT("Jack Function", spitz_enum[0], spitz_get_jack,
272 SOC_ENUM_EXT("Speaker Function", spitz_enum[1], spitz_get_spk,
277 * Logic for a wm8750 as connected on a Sharp SL-Cxx00 Device
279 static int spitz_wm8750_init(struct snd_soc_codec *codec)
284 snd_soc_dapm_nc_pin(codec, "RINPUT1");
285 snd_soc_dapm_nc_pin(codec, "LINPUT2");
286 snd_soc_dapm_nc_pin(codec, "RINPUT2");
287 snd_soc_dapm_nc_pin(codec, "LINPUT3");
288 snd_soc_dapm_nc_pin(codec, "RINPUT3");
289 snd_soc_dapm_nc_pin(codec, "OUT3");
290 snd_soc_dapm_nc_pin(codec, "MONO1");
292 /* Add spitz specific controls */
293 err = snd_soc_add_controls(codec, wm8750_spitz_controls,
294 ARRAY_SIZE(wm8750_spitz_controls));
298 /* Add spitz specific widgets */
299 snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
300 ARRAY_SIZE(wm8750_dapm_widgets));
302 /* Set up spitz specific audio paths */
303 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
305 snd_soc_dapm_sync(codec);
309 /* spitz digital audio interface glue - connects codec <--> CPU */
310 static struct snd_soc_dai_link spitz_dai = {
312 .stream_name = "WM8750",
313 .cpu_dai = &pxa_i2s_dai,
314 .codec_dai = &wm8750_dai,
315 .init = spitz_wm8750_init,
319 /* spitz audio machine driver */
320 static struct snd_soc_card snd_soc_spitz = {
322 .platform = &pxa2xx_soc_platform,
323 .dai_link = &spitz_dai,
327 /* spitz audio private data */
328 static struct wm8750_setup_data spitz_wm8750_setup = {
333 /* spitz audio subsystem */
334 static struct snd_soc_device spitz_snd_devdata = {
335 .card = &snd_soc_spitz,
336 .codec_dev = &soc_codec_dev_wm8750,
337 .codec_data = &spitz_wm8750_setup,
340 static struct platform_device *spitz_snd_device;
342 static int __init spitz_init(void)
346 if (!(machine_is_spitz() || machine_is_borzoi() || machine_is_akita()))
349 spitz_snd_device = platform_device_alloc("soc-audio", -1);
350 if (!spitz_snd_device)
353 platform_set_drvdata(spitz_snd_device, &spitz_snd_devdata);
354 spitz_snd_devdata.dev = &spitz_snd_device->dev;
355 ret = platform_device_add(spitz_snd_device);
358 platform_device_put(spitz_snd_device);
363 static void __exit spitz_exit(void)
365 platform_device_unregister(spitz_snd_device);
368 module_init(spitz_init);
369 module_exit(spitz_exit);
371 MODULE_AUTHOR("Richard Purdie");
372 MODULE_DESCRIPTION("ALSA SoC Spitz");
373 MODULE_LICENSE("GPL");