1 /* sound/soc/s3c24xx/smartq_wm8987.c
3 * Copyright 2010 Maurus Cuelenaere <mcuelenaere@gmail.com>
5 * Based on smdk6410_wm8987.c
6 * Copyright 2007 Wolfson Microelectronics PLC. - linux@wolfsonmicro.com
7 * Graeme Gregory - graeme.gregory@wolfsonmicro.com
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/gpio.h>
20 #include <sound/pcm.h>
21 #include <sound/pcm_params.h>
22 #include <sound/soc-dapm.h>
23 #include <sound/jack.h>
25 #include <asm/mach-types.h>
28 #include "s3c64xx-i2s.h"
30 #include "../codecs/wm8750.h"
33 * WM8987 is register compatible with WM8750, so using that as base driver.
36 static struct snd_soc_card snd_soc_smartq;
38 static int smartq_hifi_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
42 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
44 struct s3c_i2sv2_rate_calc div;
48 s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
49 s3c_i2sv2_get_clock(cpu_dai));
51 switch (params_rate(params)) {
67 /* set codec DAI configuration */
68 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
69 SND_SOC_DAIFMT_NB_NF |
70 SND_SOC_DAIFMT_CBS_CFS);
74 /* set cpu DAI configuration */
75 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
76 SND_SOC_DAIFMT_NB_NF |
77 SND_SOC_DAIFMT_CBS_CFS);
81 /* set the codec system clock for DAC and ADC */
82 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
87 /* set MCLK division for sample rate */
88 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, div.fs_div);
92 /* set prescaler division for sample rate */
93 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_PRESCALER,
102 * SmartQ WM8987 HiFi DAI operations.
104 static struct snd_soc_ops smartq_hifi_ops = {
105 .hw_params = smartq_hifi_hw_params,
108 static struct snd_soc_jack smartq_jack;
110 static struct snd_soc_jack_pin smartq_jack_pins[] = {
111 /* Disable speaker when headphone is plugged in */
113 .pin = "Internal Speaker",
114 .mask = SND_JACK_HEADPHONE,
118 static struct snd_soc_jack_gpio smartq_jack_gpios[] = {
120 .gpio = S3C64XX_GPL(12),
121 .name = "headphone detect",
122 .report = SND_JACK_HEADPHONE,
123 .debounce_time = 200,
127 static const struct snd_kcontrol_new wm8987_smartq_controls[] = {
128 SOC_DAPM_PIN_SWITCH("Internal Speaker"),
129 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
130 SOC_DAPM_PIN_SWITCH("Internal Mic"),
133 static int smartq_speaker_event(struct snd_soc_dapm_widget *w,
134 struct snd_kcontrol *k,
137 gpio_set_value(S3C64XX_GPK(12), SND_SOC_DAPM_EVENT_OFF(event));
142 static const struct snd_soc_dapm_widget wm8987_dapm_widgets[] = {
143 SND_SOC_DAPM_SPK("Internal Speaker", smartq_speaker_event),
144 SND_SOC_DAPM_HP("Headphone Jack", NULL),
145 SND_SOC_DAPM_MIC("Internal Mic", NULL),
148 static const struct snd_soc_dapm_route audio_map[] = {
149 {"Headphone Jack", NULL, "LOUT2"},
150 {"Headphone Jack", NULL, "ROUT2"},
152 {"Internal Speaker", NULL, "LOUT2"},
153 {"Internal Speaker", NULL, "ROUT2"},
155 {"Mic Bias", NULL, "Internal Mic"},
156 {"LINPUT2", NULL, "Mic Bias"},
159 static int smartq_wm8987_init(struct snd_soc_codec *codec)
163 /* Add SmartQ specific widgets */
164 snd_soc_dapm_new_controls(codec, wm8987_dapm_widgets,
165 ARRAY_SIZE(wm8987_dapm_widgets));
167 /* add SmartQ specific controls */
168 err = snd_soc_add_controls(codec, wm8987_smartq_controls,
169 ARRAY_SIZE(wm8987_smartq_controls));
174 /* setup SmartQ specific audio path */
175 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
177 /* set endpoints to not connected */
178 snd_soc_dapm_nc_pin(codec, "LINPUT1");
179 snd_soc_dapm_nc_pin(codec, "RINPUT1");
180 snd_soc_dapm_nc_pin(codec, "OUT3");
181 snd_soc_dapm_nc_pin(codec, "ROUT1");
183 /* set endpoints to default off mode */
184 snd_soc_dapm_enable_pin(codec, "Internal Speaker");
185 snd_soc_dapm_enable_pin(codec, "Internal Mic");
186 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
188 err = snd_soc_dapm_sync(codec);
192 /* Headphone jack detection */
193 err = snd_soc_jack_new(&snd_soc_smartq, "Headphone Jack",
194 SND_JACK_HEADPHONE, &smartq_jack);
198 err = snd_soc_jack_add_pins(&smartq_jack, ARRAY_SIZE(smartq_jack_pins),
203 err = snd_soc_jack_add_gpios(&smartq_jack,
204 ARRAY_SIZE(smartq_jack_gpios),
210 static struct snd_soc_dai_link smartq_dai[] = {
213 .stream_name = "SmartQ Hi-Fi",
214 .cpu_dai_name = "s3c64xx-i2s.0",
215 .codec_dai_name = "wm8750-hifi",
216 .platform_name = "s3c24xx-pcm-audio",
217 .codec_name = "wm8750-codec.0-0x1a",
218 .init = smartq_wm8987_init,
219 .ops = &smartq_hifi_ops,
223 static struct snd_soc_card snd_soc_smartq = {
225 .dai_link = smartq_dai,
226 .num_links = ARRAY_SIZE(smartq_dai),
229 static struct platform_device *smartq_snd_device;
231 static int __init smartq_init(void)
235 if (!machine_is_smartq7() && !machine_is_smartq5()) {
236 pr_info("Only SmartQ is supported by this ASoC driver\n");
240 smartq_snd_device = platform_device_alloc("soc-audio", -1);
241 if (!smartq_snd_device)
244 platform_set_drvdata(smartq_snd_device, &snd_soc_smartq);
246 ret = platform_device_add(smartq_snd_device);
248 platform_device_put(smartq_snd_device);
252 /* Initialise GPIOs used by amplifiers */
253 ret = gpio_request(S3C64XX_GPK(12), "amplifiers shutdown");
255 dev_err(&smartq_snd_device->dev, "Failed to register GPK12\n");
256 goto err_unregister_device;
259 /* Disable amplifiers */
260 ret = gpio_direction_output(S3C64XX_GPK(12), 1);
262 dev_err(&smartq_snd_device->dev, "Failed to configure GPK12\n");
263 goto err_free_gpio_amp_shut;
268 err_free_gpio_amp_shut:
269 gpio_free(S3C64XX_GPK(12));
270 err_unregister_device:
271 platform_device_unregister(smartq_snd_device);
276 static void __exit smartq_exit(void)
278 snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios),
281 platform_device_unregister(smartq_snd_device);
284 module_init(smartq_init);
285 module_exit(smartq_exit);
287 /* Module information */
288 MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>");
289 MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987");
290 MODULE_LICENSE("GPL");