2 * neo1973_wm8753.c -- SoC audio for Openmoko Neo1973 and Freerunner devices
4 * Copyright 2007 Openmoko Inc
5 * Author: Graeme Gregory <graeme@openmoko.org>
6 * Copyright 2007 Wolfson Microelectronics PLC.
7 * Author: Graeme Gregory
8 * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
9 * Copyright 2009 Wolfson Microelectronics
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/gpio.h>
21 #include <sound/soc.h>
23 #include <mach/gpio-samsung.h>
24 #include <asm/mach-types.h>
27 #include "../codecs/wm8753.h"
28 #include "s3c24xx-i2s.h"
30 static int neo1973_hifi_hw_params(struct snd_pcm_substream
*substream
,
31 struct snd_pcm_hw_params
*params
)
33 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
34 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
35 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
36 unsigned int pll_out
= 0, bclk
= 0;
38 unsigned long iis_clkrate
;
40 iis_clkrate
= s3c24xx_i2s_get_clockrate();
42 switch (params_rate(params
)) {
48 bclk
= WM8753_BCLK_DIV_4
;
52 bclk
= WM8753_BCLK_DIV_2
;
56 bclk
= WM8753_BCLK_DIV_16
;
60 bclk
= WM8753_BCLK_DIV_8
;
64 bclk
= WM8753_BCLK_DIV_4
;
68 bclk
= WM8753_BCLK_DIV_2
;
73 /* set codec DAI configuration */
74 ret
= snd_soc_dai_set_fmt(codec_dai
,
75 SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
76 SND_SOC_DAIFMT_CBM_CFM
);
80 /* set cpu DAI configuration */
81 ret
= snd_soc_dai_set_fmt(cpu_dai
,
82 SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
83 SND_SOC_DAIFMT_CBM_CFM
);
87 /* set the codec system clock for DAC and ADC */
88 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8753_MCLK
, pll_out
,
93 /* set MCLK division for sample rate */
94 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_MCLK
,
99 /* set codec BCLK division for sample rate */
100 ret
= snd_soc_dai_set_clkdiv(codec_dai
, 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_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_hifi_ops
= {
132 .hw_params
= neo1973_hifi_hw_params
,
133 .hw_free
= neo1973_hifi_hw_free
,
136 static int neo1973_voice_hw_params(struct snd_pcm_substream
*substream
,
137 struct snd_pcm_hw_params
*params
)
139 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
140 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
141 unsigned int pcmdiv
= 0;
143 unsigned long iis_clkrate
;
145 iis_clkrate
= s3c24xx_i2s_get_clockrate();
147 if (params_rate(params
) != 8000)
149 if (params_channels(params
) != 1)
152 pcmdiv
= WM8753_PCM_DIV_6
; /* 2.048 MHz */
154 /* todo: gg check mode (DSP_B) against CSR datasheet */
155 /* set codec DAI configuration */
156 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_DSP_B
|
157 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
161 /* set the codec system clock for DAC and ADC */
162 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8753_PCMCLK
, 12288000,
167 /* set codec PCM division for sample rate */
168 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8753_PCMDIV
, pcmdiv
);
172 /* configure and enable PLL for 12.288MHz output */
173 ret
= snd_soc_dai_set_pll(codec_dai
, WM8753_PLL2
, 0,
174 iis_clkrate
/ 4, 12288000);
181 static int neo1973_voice_hw_free(struct snd_pcm_substream
*substream
)
183 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
184 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
186 /* disable the PLL */
187 return snd_soc_dai_set_pll(codec_dai
, WM8753_PLL2
, 0, 0, 0);
190 static struct snd_soc_ops neo1973_voice_ops
= {
191 .hw_params
= neo1973_voice_hw_params
,
192 .hw_free
= neo1973_voice_hw_free
,
195 static int gta02_speaker_enabled
;
197 static int lm4853_set_spk(struct snd_kcontrol
*kcontrol
,
198 struct snd_ctl_elem_value
*ucontrol
)
200 gta02_speaker_enabled
= ucontrol
->value
.integer
.value
[0];
202 gpio_set_value(S3C2410_GPJ(2), !gta02_speaker_enabled
);
207 static int lm4853_get_spk(struct snd_kcontrol
*kcontrol
,
208 struct snd_ctl_elem_value
*ucontrol
)
210 ucontrol
->value
.integer
.value
[0] = gta02_speaker_enabled
;
214 static int lm4853_event(struct snd_soc_dapm_widget
*w
,
215 struct snd_kcontrol
*k
, int event
)
217 gpio_set_value(S3C2410_GPJ(1), SND_SOC_DAPM_EVENT_OFF(event
));
222 static const struct snd_soc_dapm_widget neo1973_wm8753_dapm_widgets
[] = {
223 SND_SOC_DAPM_LINE("GSM Line Out", NULL
),
224 SND_SOC_DAPM_LINE("GSM Line In", NULL
),
225 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
226 SND_SOC_DAPM_MIC("Handset Mic", NULL
),
227 SND_SOC_DAPM_SPK("Handset Spk", NULL
),
228 SND_SOC_DAPM_SPK("Stereo Out", lm4853_event
),
231 static const struct snd_soc_dapm_route neo1973_wm8753_routes
[] = {
232 /* Connections to the GSM Module */
233 {"GSM Line Out", NULL
, "MONO1"},
234 {"GSM Line Out", NULL
, "MONO2"},
235 {"RXP", NULL
, "GSM Line In"},
236 {"RXN", NULL
, "GSM Line In"},
238 /* Connections to Headset */
239 {"MIC1", NULL
, "Mic Bias"},
240 {"Mic Bias", NULL
, "Headset Mic"},
243 {"MIC2", NULL
, "Mic Bias"},
244 {"MIC2N", NULL
, "Mic Bias"},
245 {"Mic Bias", NULL
, "Handset Mic"},
247 /* Connect the ALC pins */
248 {"ACIN", NULL
, "ACOP"},
250 /* Connections to the amp */
251 {"Stereo Out", NULL
, "LOUT1"},
252 {"Stereo Out", NULL
, "ROUT1"},
255 {"Handset Spk", NULL
, "LOUT2"},
256 {"Handset Spk", NULL
, "ROUT2"},
259 static const struct snd_kcontrol_new neo1973_wm8753_controls
[] = {
260 SOC_DAPM_PIN_SWITCH("GSM Line Out"),
261 SOC_DAPM_PIN_SWITCH("GSM Line In"),
262 SOC_DAPM_PIN_SWITCH("Headset Mic"),
263 SOC_DAPM_PIN_SWITCH("Handset Mic"),
264 SOC_DAPM_PIN_SWITCH("Handset Spk"),
265 SOC_DAPM_PIN_SWITCH("Stereo Out"),
267 SOC_SINGLE_BOOL_EXT("Amp Spk Switch", 0,
272 static int neo1973_wm8753_init(struct snd_soc_pcm_runtime
*rtd
)
274 struct snd_soc_card
*card
= rtd
->card
;
276 /* set endpoints to default off mode */
277 snd_soc_dapm_disable_pin(&card
->dapm
, "GSM Line Out");
278 snd_soc_dapm_disable_pin(&card
->dapm
, "GSM Line In");
279 snd_soc_dapm_disable_pin(&card
->dapm
, "Headset Mic");
280 snd_soc_dapm_disable_pin(&card
->dapm
, "Handset Mic");
281 snd_soc_dapm_disable_pin(&card
->dapm
, "Stereo Out");
282 snd_soc_dapm_disable_pin(&card
->dapm
, "Handset Spk");
284 /* allow audio paths from the GSM modem to run during suspend */
285 snd_soc_dapm_ignore_suspend(&card
->dapm
, "GSM Line Out");
286 snd_soc_dapm_ignore_suspend(&card
->dapm
, "GSM Line In");
287 snd_soc_dapm_ignore_suspend(&card
->dapm
, "Headset Mic");
288 snd_soc_dapm_ignore_suspend(&card
->dapm
, "Handset Mic");
289 snd_soc_dapm_ignore_suspend(&card
->dapm
, "Stereo Out");
290 snd_soc_dapm_ignore_suspend(&card
->dapm
, "Handset Spk");
295 static struct snd_soc_dai_link neo1973_dai
[] = {
296 { /* Hifi Playback - for similatious use with voice below */
298 .stream_name
= "WM8753 HiFi",
299 .platform_name
= "s3c24xx-iis",
300 .cpu_dai_name
= "s3c24xx-iis",
301 .codec_dai_name
= "wm8753-hifi",
302 .codec_name
= "wm8753.0-001a",
303 .init
= neo1973_wm8753_init
,
304 .ops
= &neo1973_hifi_ops
,
308 .stream_name
= "Voice",
309 .cpu_dai_name
= "bt-sco-pcm",
310 .codec_dai_name
= "wm8753-voice",
311 .codec_name
= "wm8753.0-001a",
312 .ops
= &neo1973_voice_ops
,
316 static struct snd_soc_aux_dev neo1973_aux_devs
[] = {
319 .codec_name
= "dfbmcs320.0",
323 static struct snd_soc_codec_conf neo1973_codec_conf
[] = {
325 .dev_name
= "lm4857.0-007c",
326 .name_prefix
= "Amp",
330 static const struct gpio neo1973_gta02_gpios
[] = {
331 { S3C2410_GPJ(2), GPIOF_OUT_INIT_HIGH
, "GTA02_HP_IN" },
332 { S3C2410_GPJ(1), GPIOF_OUT_INIT_HIGH
, "GTA02_AMP_SHUT" },
335 static struct snd_soc_card neo1973
= {
337 .owner
= THIS_MODULE
,
338 .dai_link
= neo1973_dai
,
339 .num_links
= ARRAY_SIZE(neo1973_dai
),
340 .aux_dev
= neo1973_aux_devs
,
341 .num_aux_devs
= ARRAY_SIZE(neo1973_aux_devs
),
342 .codec_conf
= neo1973_codec_conf
,
343 .num_configs
= ARRAY_SIZE(neo1973_codec_conf
),
345 .controls
= neo1973_wm8753_controls
,
346 .num_controls
= ARRAY_SIZE(neo1973_wm8753_controls
),
347 .dapm_widgets
= neo1973_wm8753_dapm_widgets
,
348 .num_dapm_widgets
= ARRAY_SIZE(neo1973_wm8753_dapm_widgets
),
349 .dapm_routes
= neo1973_wm8753_routes
,
350 .num_dapm_routes
= ARRAY_SIZE(neo1973_wm8753_routes
),
351 .fully_routed
= true,
354 static struct platform_device
*neo1973_snd_device
;
356 static int __init
neo1973_init(void)
360 if (!machine_is_neo1973_gta02())
363 if (machine_is_neo1973_gta02()) {
364 neo1973
.name
= "neo1973gta02";
365 neo1973
.num_aux_devs
= 1;
367 ret
= gpio_request_array(neo1973_gta02_gpios
,
368 ARRAY_SIZE(neo1973_gta02_gpios
));
373 neo1973_snd_device
= platform_device_alloc("soc-audio", -1);
374 if (!neo1973_snd_device
) {
379 platform_set_drvdata(neo1973_snd_device
, &neo1973
);
380 ret
= platform_device_add(neo1973_snd_device
);
388 platform_device_put(neo1973_snd_device
);
390 if (machine_is_neo1973_gta02()) {
391 gpio_free_array(neo1973_gta02_gpios
,
392 ARRAY_SIZE(neo1973_gta02_gpios
));
396 module_init(neo1973_init
);
398 static void __exit
neo1973_exit(void)
400 platform_device_unregister(neo1973_snd_device
);
402 if (machine_is_neo1973_gta02()) {
403 gpio_free_array(neo1973_gta02_gpios
,
404 ARRAY_SIZE(neo1973_gta02_gpios
));
407 module_exit(neo1973_exit
);
409 /* Module information */
410 MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org");
411 MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973 and Frerunner");
412 MODULE_LICENSE("GPL");