1 /* sound/soc/samsung/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/gpio.h>
17 #include <linux/module.h>
19 #include <sound/soc.h>
20 #include <sound/jack.h>
22 #include <asm/mach-types.h>
25 #include "../codecs/wm8750.h"
28 * WM8987 is register compatible with WM8750, so using that as base driver.
31 static struct snd_soc_card snd_soc_smartq
;
33 static int smartq_hifi_hw_params(struct snd_pcm_substream
*substream
,
34 struct snd_pcm_hw_params
*params
)
36 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
37 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
38 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
42 switch (params_rate(params
)) {
58 /* set codec DAI configuration */
59 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
60 SND_SOC_DAIFMT_NB_NF
|
61 SND_SOC_DAIFMT_CBS_CFS
);
65 /* set cpu DAI configuration */
66 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
67 SND_SOC_DAIFMT_NB_NF
|
68 SND_SOC_DAIFMT_CBS_CFS
);
72 /* Use PCLK for I2S signal generation */
73 ret
= snd_soc_dai_set_sysclk(cpu_dai
, SAMSUNG_I2S_RCLKSRC_0
,
78 /* Gate the RCLK output on PAD */
79 ret
= snd_soc_dai_set_sysclk(cpu_dai
, SAMSUNG_I2S_CDCLK
,
84 /* set the codec system clock for DAC and ADC */
85 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8750_SYSCLK
, clk
,
94 * SmartQ WM8987 HiFi DAI operations.
96 static struct snd_soc_ops smartq_hifi_ops
= {
97 .hw_params
= smartq_hifi_hw_params
,
100 static struct snd_soc_jack smartq_jack
;
102 static struct snd_soc_jack_pin smartq_jack_pins
[] = {
103 /* Disable speaker when headphone is plugged in */
105 .pin
= "Internal Speaker",
106 .mask
= SND_JACK_HEADPHONE
,
110 static struct snd_soc_jack_gpio smartq_jack_gpios
[] = {
112 .gpio
= S3C64XX_GPL(12),
113 .name
= "headphone detect",
114 .report
= SND_JACK_HEADPHONE
,
115 .debounce_time
= 200,
119 static const struct snd_kcontrol_new wm8987_smartq_controls
[] = {
120 SOC_DAPM_PIN_SWITCH("Internal Speaker"),
121 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
122 SOC_DAPM_PIN_SWITCH("Internal Mic"),
125 static int smartq_speaker_event(struct snd_soc_dapm_widget
*w
,
126 struct snd_kcontrol
*k
,
129 gpio_set_value(S3C64XX_GPK(12), SND_SOC_DAPM_EVENT_OFF(event
));
134 static const struct snd_soc_dapm_widget wm8987_dapm_widgets
[] = {
135 SND_SOC_DAPM_SPK("Internal Speaker", smartq_speaker_event
),
136 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
137 SND_SOC_DAPM_MIC("Internal Mic", NULL
),
140 static const struct snd_soc_dapm_route audio_map
[] = {
141 {"Headphone Jack", NULL
, "LOUT2"},
142 {"Headphone Jack", NULL
, "ROUT2"},
144 {"Internal Speaker", NULL
, "LOUT2"},
145 {"Internal Speaker", NULL
, "ROUT2"},
147 {"Mic Bias", NULL
, "Internal Mic"},
148 {"LINPUT2", NULL
, "Mic Bias"},
151 static int smartq_wm8987_init(struct snd_soc_pcm_runtime
*rtd
)
153 struct snd_soc_codec
*codec
= rtd
->codec
;
154 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
157 /* set endpoints to not connected */
158 snd_soc_dapm_nc_pin(dapm
, "LINPUT1");
159 snd_soc_dapm_nc_pin(dapm
, "RINPUT1");
160 snd_soc_dapm_nc_pin(dapm
, "OUT3");
161 snd_soc_dapm_nc_pin(dapm
, "ROUT1");
163 /* set endpoints to default off mode */
164 snd_soc_dapm_enable_pin(dapm
, "Internal Speaker");
165 snd_soc_dapm_enable_pin(dapm
, "Internal Mic");
166 snd_soc_dapm_disable_pin(dapm
, "Headphone Jack");
168 /* Headphone jack detection */
169 err
= snd_soc_jack_new(codec
, "Headphone Jack",
170 SND_JACK_HEADPHONE
, &smartq_jack
);
174 err
= snd_soc_jack_add_pins(&smartq_jack
, ARRAY_SIZE(smartq_jack_pins
),
179 err
= snd_soc_jack_add_gpios(&smartq_jack
,
180 ARRAY_SIZE(smartq_jack_gpios
),
186 static struct snd_soc_dai_link smartq_dai
[] = {
189 .stream_name
= "SmartQ Hi-Fi",
190 .cpu_dai_name
= "samsung-i2s.0",
191 .codec_dai_name
= "wm8750-hifi",
192 .platform_name
= "samsung-audio",
193 .codec_name
= "wm8750.0-0x1a",
194 .init
= smartq_wm8987_init
,
195 .ops
= &smartq_hifi_ops
,
199 static struct snd_soc_card snd_soc_smartq
= {
201 .dai_link
= smartq_dai
,
202 .num_links
= ARRAY_SIZE(smartq_dai
),
204 .dapm_widgets
= wm8987_dapm_widgets
,
205 .num_dapm_widgets
= ARRAY_SIZE(wm8987_dapm_widgets
),
206 .dapm_routes
= audio_map
,
207 .num_dapm_routes
= ARRAY_SIZE(audio_map
),
208 .controls
= wm8987_smartq_controls
,
209 .num_controls
= ARRAY_SIZE(wm8987_smartq_controls
),
212 static struct platform_device
*smartq_snd_device
;
214 static int __init
smartq_init(void)
218 if (!machine_is_smartq7() && !machine_is_smartq5()) {
219 pr_info("Only SmartQ is supported by this ASoC driver\n");
223 smartq_snd_device
= platform_device_alloc("soc-audio", -1);
224 if (!smartq_snd_device
)
227 platform_set_drvdata(smartq_snd_device
, &snd_soc_smartq
);
229 ret
= platform_device_add(smartq_snd_device
);
231 platform_device_put(smartq_snd_device
);
235 /* Initialise GPIOs used by amplifiers */
236 ret
= gpio_request(S3C64XX_GPK(12), "amplifiers shutdown");
238 dev_err(&smartq_snd_device
->dev
, "Failed to register GPK12\n");
239 goto err_unregister_device
;
242 /* Disable amplifiers */
243 ret
= gpio_direction_output(S3C64XX_GPK(12), 1);
245 dev_err(&smartq_snd_device
->dev
, "Failed to configure GPK12\n");
246 goto err_free_gpio_amp_shut
;
251 err_free_gpio_amp_shut
:
252 gpio_free(S3C64XX_GPK(12));
253 err_unregister_device
:
254 platform_device_unregister(smartq_snd_device
);
259 static void __exit
smartq_exit(void)
261 gpio_free(S3C64XX_GPK(12));
262 snd_soc_jack_free_gpios(&smartq_jack
, ARRAY_SIZE(smartq_jack_gpios
),
265 platform_device_unregister(smartq_snd_device
);
268 module_init(smartq_init
);
269 module_exit(smartq_exit
);
271 /* Module information */
272 MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>");
273 MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987");
274 MODULE_LICENSE("GPL");