2 * neo1973_gta02_wm8753.c -- SoC audio for Openmoko Freerunner(GTA02)
4 * Copyright 2007 Openmoko Inc
5 * Author: Graeme Gregory <graeme@openmoko.org>
6 * Copyright 2007 Wolfson Microelectronics PLC.
7 * Author: Graeme Gregory <linux@wolfsonmicro.com>
8 * Copyright 2009 Wolfson Microelectronics
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.
16 #include <linux/gpio.h>
18 #include <sound/soc.h>
20 #include <asm/mach-types.h>
21 #include <plat/regs-iis.h>
22 #include <mach/gta02.h>
24 #include "../codecs/wm8753.h"
25 #include "s3c24xx-i2s.h"
27 static struct snd_soc_card neo1973_gta02;
29 static int neo1973_gta02_hifi_hw_params(struct snd_pcm_substream *substream,
30 struct snd_pcm_hw_params *params)
32 struct snd_soc_pcm_runtime *rtd = substream->private_data;
33 struct snd_soc_dai *codec_dai = rtd->codec_dai;
34 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
35 unsigned int pll_out = 0, bclk = 0;
37 unsigned long iis_clkrate;
39 iis_clkrate = s3c24xx_i2s_get_clockrate();
41 switch (params_rate(params)) {
47 bclk = WM8753_BCLK_DIV_4;
51 bclk = WM8753_BCLK_DIV_2;
55 bclk = WM8753_BCLK_DIV_16;
59 bclk = WM8753_BCLK_DIV_8;
63 bclk = WM8753_BCLK_DIV_4;
67 bclk = WM8753_BCLK_DIV_2;
72 /* set codec DAI configuration */
73 ret = snd_soc_dai_set_fmt(codec_dai,
74 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
75 SND_SOC_DAIFMT_CBM_CFM);
79 /* set cpu DAI configuration */
80 ret = snd_soc_dai_set_fmt(cpu_dai,
81 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
82 SND_SOC_DAIFMT_CBM_CFM);
86 /* set the codec system clock for DAC and ADC */
87 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out,
92 /* set MCLK division for sample rate */
93 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
98 /* set codec BCLK division for sample rate */
99 ret = snd_soc_dai_set_clkdiv(codec_dai,
100 WM8753_BCLKDIV, bclk);
104 /* set prescaler division for sample rate */
105 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
106 S3C24XX_PRESCALE(4, 4));
110 /* codec PLL input is PCLK/4 */
111 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0,
112 iis_clkrate / 4, pll_out);
119 static int neo1973_gta02_hifi_hw_free(struct snd_pcm_substream *substream)
121 struct snd_soc_pcm_runtime *rtd = substream->private_data;
122 struct snd_soc_dai *codec_dai = rtd->codec_dai;
124 /* disable the PLL */
125 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0);
129 * Neo1973 WM8753 HiFi DAI opserations.
131 static struct snd_soc_ops neo1973_gta02_hifi_ops = {
132 .hw_params = neo1973_gta02_hifi_hw_params,
133 .hw_free = neo1973_gta02_hifi_hw_free,
136 static int neo1973_gta02_voice_hw_params(
137 struct snd_pcm_substream *substream,
138 struct snd_pcm_hw_params *params)
140 struct snd_soc_pcm_runtime *rtd = substream->private_data;
141 struct snd_soc_dai *codec_dai = rtd->codec_dai;
142 unsigned int pcmdiv = 0;
144 unsigned long iis_clkrate;
146 iis_clkrate = s3c24xx_i2s_get_clockrate();
148 if (params_rate(params) != 8000)
150 if (params_channels(params) != 1)
153 pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */
155 /* todo: gg check mode (DSP_B) against CSR datasheet */
156 /* set codec DAI configuration */
157 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B |
158 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
162 /* set the codec system clock for DAC and ADC */
163 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK,
164 12288000, SND_SOC_CLOCK_IN);
168 /* set codec PCM division for sample rate */
169 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_PCMDIV,
174 /* configure and enable PLL for 12.288MHz output */
175 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0,
176 iis_clkrate / 4, 12288000);
183 static int neo1973_gta02_voice_hw_free(struct snd_pcm_substream *substream)
185 struct snd_soc_pcm_runtime *rtd = substream->private_data;
186 struct snd_soc_dai *codec_dai = rtd->codec_dai;
188 /* disable the PLL */
189 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
192 static struct snd_soc_ops neo1973_gta02_voice_ops = {
193 .hw_params = neo1973_gta02_voice_hw_params,
194 .hw_free = neo1973_gta02_voice_hw_free,
197 static int gta02_speaker_enabled;
199 static int lm4853_set_spk(struct snd_kcontrol *kcontrol,
200 struct snd_ctl_elem_value *ucontrol)
202 gta02_speaker_enabled = ucontrol->value.integer.value[0];
204 gpio_set_value(GTA02_GPIO_HP_IN, !gta02_speaker_enabled);
209 static int lm4853_get_spk(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_value *ucontrol)
212 ucontrol->value.integer.value[0] = gta02_speaker_enabled;
216 static int lm4853_event(struct snd_soc_dapm_widget *w,
217 struct snd_kcontrol *k, int event)
219 gpio_set_value(GTA02_GPIO_AMP_SHUT, SND_SOC_DAPM_EVENT_OFF(event));
224 static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
225 SND_SOC_DAPM_SPK("Stereo Out", lm4853_event),
226 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
227 SND_SOC_DAPM_LINE("GSM Line In", NULL),
228 SND_SOC_DAPM_MIC("Headset Mic", NULL),
229 SND_SOC_DAPM_MIC("Handset Mic", NULL),
230 SND_SOC_DAPM_SPK("Handset Spk", NULL),
234 /* example machine audio_mapnections */
235 static const struct snd_soc_dapm_route audio_map[] = {
237 /* Connections to the lm4853 amp */
238 {"Stereo Out", NULL, "LOUT1"},
239 {"Stereo Out", NULL, "ROUT1"},
241 /* Connections to the GSM Module */
242 {"GSM Line Out", NULL, "MONO1"},
243 {"GSM Line Out", NULL, "MONO2"},
244 {"RXP", NULL, "GSM Line In"},
245 {"RXN", NULL, "GSM Line In"},
247 /* Connections to Headset */
248 {"MIC1", NULL, "Mic Bias"},
249 {"Mic Bias", NULL, "Headset Mic"},
252 {"MIC2", NULL, "Mic Bias"},
253 {"MIC2N", NULL, "Mic Bias"},
254 {"Mic Bias", NULL, "Handset Mic"},
257 {"Handset Spk", NULL, "LOUT2"},
258 {"Handset Spk", NULL, "ROUT2"},
260 /* Connect the ALC pins */
261 {"ACIN", NULL, "ACOP"},
264 static const struct snd_kcontrol_new wm8753_neo1973_gta02_controls[] = {
265 SOC_DAPM_PIN_SWITCH("Stereo Out"),
266 SOC_DAPM_PIN_SWITCH("GSM Line Out"),
267 SOC_DAPM_PIN_SWITCH("GSM Line In"),
268 SOC_DAPM_PIN_SWITCH("Headset Mic"),
269 SOC_DAPM_PIN_SWITCH("Handset Mic"),
270 SOC_DAPM_PIN_SWITCH("Handset Spk"),
272 SOC_SINGLE_BOOL_EXT("Amp Spk Switch", 0,
278 * This is an example machine initialisation for a wm8753 connected to a
281 static int neo1973_gta02_wm8753_init(struct snd_soc_pcm_runtime *rtd)
283 struct snd_soc_codec *codec = rtd->codec;
284 struct snd_soc_dapm_context *dapm = &codec->dapm;
287 /* set up NC codec pins */
288 snd_soc_dapm_nc_pin(dapm, "OUT3");
289 snd_soc_dapm_nc_pin(dapm, "OUT4");
290 snd_soc_dapm_nc_pin(dapm, "LINE1");
291 snd_soc_dapm_nc_pin(dapm, "LINE2");
293 /* Add neo1973 gta02 specific widgets */
294 snd_soc_dapm_new_controls(dapm, wm8753_dapm_widgets,
295 ARRAY_SIZE(wm8753_dapm_widgets));
297 /* add neo1973 gta02 specific controls */
298 err = snd_soc_add_controls(codec, wm8753_neo1973_gta02_controls,
299 ARRAY_SIZE(wm8753_neo1973_gta02_controls));
304 /* set up neo1973 gta02 specific audio path audio_map */
305 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
307 /* set endpoints to default off mode */
308 snd_soc_dapm_disable_pin(dapm, "Stereo Out");
309 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
310 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
311 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
312 snd_soc_dapm_disable_pin(dapm, "Handset Mic");
313 snd_soc_dapm_disable_pin(dapm, "Handset Spk");
315 /* allow audio paths from the GSM modem to run during suspend */
316 snd_soc_dapm_ignore_suspend(dapm, "Stereo Out");
317 snd_soc_dapm_ignore_suspend(dapm, "GSM Line Out");
318 snd_soc_dapm_ignore_suspend(dapm, "GSM Line In");
319 snd_soc_dapm_ignore_suspend(dapm, "Headset Mic");
320 snd_soc_dapm_ignore_suspend(dapm, "Handset Mic");
321 snd_soc_dapm_ignore_suspend(dapm, "Handset Spk");
323 snd_soc_dapm_sync(dapm);
331 static struct snd_soc_dai_driver bt_dai = {
332 .name = "bluetooth-dai",
336 .rates = SNDRV_PCM_RATE_8000,
337 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
341 .rates = SNDRV_PCM_RATE_8000,
342 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
345 static struct snd_soc_dai_link neo1973_gta02_dai[] = {
346 { /* Hifi Playback - for similatious use with voice below */
348 .stream_name = "WM8753 HiFi",
349 .cpu_dai_name = "s3c24xx-iis",
350 .codec_dai_name = "wm8753-hifi",
351 .init = neo1973_gta02_wm8753_init,
352 .platform_name = "samsung-audio",
353 .codec_name = "wm8753-codec.0-001a",
354 .ops = &neo1973_gta02_hifi_ops,
358 .stream_name = "Voice",
359 .cpu_dai_name = "bluetooth-dai",
360 .codec_dai_name = "wm8753-voice",
361 .ops = &neo1973_gta02_voice_ops,
362 .codec_name = "wm8753-codec.0-001a",
363 .platform_name = "samsung-audio",
367 static struct snd_soc_card neo1973_gta02 = {
368 .name = "neo1973-gta02",
369 .dai_link = neo1973_gta02_dai,
370 .num_links = ARRAY_SIZE(neo1973_gta02_dai),
373 static const struct gpio neo1973_gta02_gpios[] = {
374 { GTA02_GPIO_HP_IN, GPIOF_OUT_INIT_HIGH, "GTA02_HP_IN" },
375 { GTA02_GPIO_AMP_SHUT, GPIOF_OUT_INIT_HIGH, "GTA02_AMP_SHUT" },
378 static struct platform_device *neo1973_gta02_snd_device;
380 static int __init neo1973_gta02_init(void)
384 if (!machine_is_neo1973_gta02()) {
386 "Only GTA02 is supported by this ASoC driver\n");
390 ret = gpio_request_array(neo1973_gta02_gpios,
391 ARRAY_SIZE(neo1973_gta02_gpios));
395 neo1973_gta02_snd_device = platform_device_alloc("soc-audio", -1);
396 if (!neo1973_gta02_snd_device) {
401 /* register bluetooth DAI here */
402 ret = snd_soc_register_dai(&neo1973_gta02_snd_device->dev, &bt_dai);
406 platform_set_drvdata(neo1973_gta02_snd_device, &neo1973_gta02);
407 ret = platform_device_add(neo1973_gta02_snd_device);
410 goto err_unregister_dai;
415 snd_soc_unregister_dai(&neo1973_gta02_snd_device->dev);
417 platform_device_put(neo1973_gta02_snd_device);
419 gpio_free_array(neo1973_gta02_gpios, ARRAY_SIZE(neo1973_gta02_gpios));
422 module_init(neo1973_gta02_init);
424 static void __exit neo1973_gta02_exit(void)
426 snd_soc_unregister_dai(&neo1973_gta02_snd_device->dev);
427 platform_device_unregister(neo1973_gta02_snd_device);
428 gpio_free_array(neo1973_gta02_gpios, ARRAY_SIZE(neo1973_gta02_gpios));
430 module_exit(neo1973_gta02_exit);
432 /* Module information */
433 MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org");
434 MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973 GTA02");
435 MODULE_LICENSE("GPL");