diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2010-07-02 20:46:12 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-07-04 05:04:12 -0400 |
commit | ce93a3702832121d517ad348817929f22fcce47c (patch) | |
tree | 6fe6b606d66fd09f6d2344e99712334978c6e977 | |
parent | 0d9c15e45b362fced933c686c0127e73547bb209 (diff) |
ASoC: Add SmartQ sound driver
This adds sound support for the SmartQ board.
The hardware consists of a S3C6410 coupled with a WM8987 over I²S. The WM8750
driver is used for driving the WM8987, as they are register compatible.
Signed-off-by: Maurus Cuelenaere <mcuelenaere@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r-- | sound/soc/s3c24xx/Kconfig | 6 | ||||
-rw-r--r-- | sound/soc/s3c24xx/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/s3c24xx/smartq_wm8987.c | 296 |
3 files changed, 304 insertions, 0 deletions
diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig index 292d817c9a94..213963ac3c28 100644 --- a/sound/soc/s3c24xx/Kconfig +++ b/sound/soc/s3c24xx/Kconfig | |||
@@ -125,3 +125,9 @@ config SND_SOC_SMDK_WM9713 | |||
125 | select SND_S3C_SOC_AC97 | 125 | select SND_S3C_SOC_AC97 |
126 | help | 126 | help |
127 | Sat Y if you want to add support for SoC audio on the SMDK. | 127 | Sat Y if you want to add support for SoC audio on the SMDK. |
128 | |||
129 | config SND_S3C64XX_SOC_SMARTQ | ||
130 | tristate "SoC I2S Audio support for SmartQ board" | ||
131 | depends on SND_S3C24XX_SOC && MACH_SMARTQ | ||
132 | select SND_S3C64XX_SOC_I2S | ||
133 | select SND_SOC_WM8750 | ||
diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile index 81d8dc503f87..50172c385d90 100644 --- a/sound/soc/s3c24xx/Makefile +++ b/sound/soc/s3c24xx/Makefile | |||
@@ -29,6 +29,7 @@ snd-soc-s3c24xx-simtec-hermes-objs := s3c24xx_simtec_hermes.o | |||
29 | snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o | 29 | snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o |
30 | snd-soc-smdk64xx-wm8580-objs := smdk64xx_wm8580.o | 30 | snd-soc-smdk64xx-wm8580-objs := smdk64xx_wm8580.o |
31 | snd-soc-smdk-wm9713-objs := smdk_wm9713.o | 31 | snd-soc-smdk-wm9713-objs := smdk_wm9713.o |
32 | snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o | ||
32 | 33 | ||
33 | obj-$(CONFIG_SND_S3C24XX_SOC_JIVE_WM8750) += snd-soc-jive-wm8750.o | 34 | obj-$(CONFIG_SND_S3C24XX_SOC_JIVE_WM8750) += snd-soc-jive-wm8750.o |
34 | obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o | 35 | obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o |
@@ -41,3 +42,4 @@ obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_HERMES) += snd-soc-s3c24xx-simtec-hermes.o | |||
41 | obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o | 42 | obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o |
42 | obj-$(CONFIG_SND_S3C64XX_SOC_WM8580) += snd-soc-smdk64xx-wm8580.o | 43 | obj-$(CONFIG_SND_S3C64XX_SOC_WM8580) += snd-soc-smdk64xx-wm8580.o |
43 | obj-$(CONFIG_SND_SOC_SMDK_WM9713) += snd-soc-smdk-wm9713.o | 44 | obj-$(CONFIG_SND_SOC_SMDK_WM9713) += snd-soc-smdk-wm9713.o |
45 | obj-$(CONFIG_SND_S3C64XX_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o | ||
diff --git a/sound/soc/s3c24xx/smartq_wm8987.c b/sound/soc/s3c24xx/smartq_wm8987.c new file mode 100644 index 000000000000..c90ef965aaf8 --- /dev/null +++ b/sound/soc/s3c24xx/smartq_wm8987.c | |||
@@ -0,0 +1,296 @@ | |||
1 | /* sound/soc/s3c24xx/smartq_wm8987.c | ||
2 | * | ||
3 | * Copyright 2010 Maurus Cuelenaere <mcuelenaere@gmail.com> | ||
4 | * | ||
5 | * Based on smdk6410_wm8987.c | ||
6 | * Copyright 2007 Wolfson Microelectronics PLC. - linux@wolfsonmicro.com | ||
7 | * Graeme Gregory - graeme.gregory@wolfsonmicro.com | ||
8 | * | ||
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. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/gpio.h> | ||
19 | |||
20 | #include <sound/pcm.h> | ||
21 | #include <sound/pcm_params.h> | ||
22 | #include <sound/soc-dapm.h> | ||
23 | #include <sound/jack.h> | ||
24 | |||
25 | #include <asm/mach-types.h> | ||
26 | |||
27 | #include "s3c-dma.h" | ||
28 | #include "s3c64xx-i2s.h" | ||
29 | |||
30 | #include "../codecs/wm8750.h" | ||
31 | |||
32 | /* | ||
33 | * WM8987 is register compatible with WM8750, so using that as base driver. | ||
34 | */ | ||
35 | |||
36 | static struct snd_soc_card snd_soc_smartq; | ||
37 | |||
38 | static int smartq_hifi_hw_params(struct snd_pcm_substream *substream, | ||
39 | struct snd_pcm_hw_params *params) | ||
40 | { | ||
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; | ||
45 | unsigned int clk = 0; | ||
46 | int ret; | ||
47 | |||
48 | s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params), | ||
49 | s3c_i2sv2_get_clock(cpu_dai)); | ||
50 | |||
51 | switch (params_rate(params)) { | ||
52 | case 8000: | ||
53 | case 16000: | ||
54 | case 32000: | ||
55 | case 48000: | ||
56 | case 96000: | ||
57 | clk = 12288000; | ||
58 | break; | ||
59 | case 11025: | ||
60 | case 22050: | ||
61 | case 44100: | ||
62 | case 88200: | ||
63 | clk = 11289600; | ||
64 | break; | ||
65 | } | ||
66 | |||
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); | ||
71 | if (ret < 0) | ||
72 | return ret; | ||
73 | |||
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); | ||
78 | if (ret < 0) | ||
79 | return ret; | ||
80 | |||
81 | /* set the codec system clock for DAC and ADC */ | ||
82 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk, | ||
83 | SND_SOC_CLOCK_IN); | ||
84 | if (ret < 0) | ||
85 | return ret; | ||
86 | |||
87 | /* set MCLK division for sample rate */ | ||
88 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, div.fs_div); | ||
89 | if (ret < 0) | ||
90 | return ret; | ||
91 | |||
92 | /* set prescaler division for sample rate */ | ||
93 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_PRESCALER, | ||
94 | div.clk_div - 1); | ||
95 | if (ret < 0) | ||
96 | return ret; | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | * SmartQ WM8987 HiFi DAI operations. | ||
103 | */ | ||
104 | static struct snd_soc_ops smartq_hifi_ops = { | ||
105 | .hw_params = smartq_hifi_hw_params, | ||
106 | }; | ||
107 | |||
108 | static struct snd_soc_jack smartq_jack; | ||
109 | |||
110 | static struct snd_soc_jack_pin smartq_jack_pins[] = { | ||
111 | /* Disable speaker when headphone is plugged in */ | ||
112 | { | ||
113 | .pin = "Internal Speaker", | ||
114 | .mask = SND_JACK_HEADPHONE, | ||
115 | .invert = true, | ||
116 | }, | ||
117 | }; | ||
118 | |||
119 | static struct snd_soc_jack_gpio smartq_jack_gpios[] = { | ||
120 | { | ||
121 | .gpio = S3C64XX_GPL(12), | ||
122 | .name = "headphone detect", | ||
123 | .report = SND_JACK_HEADPHONE, | ||
124 | .debounce_time = 200, | ||
125 | }, | ||
126 | }; | ||
127 | |||
128 | static const struct snd_kcontrol_new wm8987_smartq_controls[] = { | ||
129 | SOC_DAPM_PIN_SWITCH("Internal Speaker"), | ||
130 | SOC_DAPM_PIN_SWITCH("Headphone Jack"), | ||
131 | SOC_DAPM_PIN_SWITCH("Internal Mic"), | ||
132 | }; | ||
133 | |||
134 | static int smartq_speaker_event(struct snd_soc_dapm_widget *w, | ||
135 | struct snd_kcontrol *k, | ||
136 | int event) | ||
137 | { | ||
138 | gpio_set_value(S3C64XX_GPK(12), SND_SOC_DAPM_EVENT_OFF(event)); | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static const struct snd_soc_dapm_widget wm8987_dapm_widgets[] = { | ||
144 | SND_SOC_DAPM_SPK("Internal Speaker", smartq_speaker_event), | ||
145 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
146 | SND_SOC_DAPM_MIC("Internal Mic", NULL), | ||
147 | }; | ||
148 | |||
149 | static const struct snd_soc_dapm_route audio_map[] = { | ||
150 | {"Headphone Jack", NULL, "LOUT2"}, | ||
151 | {"Headphone Jack", NULL, "ROUT2"}, | ||
152 | |||
153 | {"Internal Speaker", NULL, "LOUT2"}, | ||
154 | {"Internal Speaker", NULL, "ROUT2"}, | ||
155 | |||
156 | {"Mic Bias", NULL, "Internal Mic"}, | ||
157 | {"LINPUT2", NULL, "Mic Bias"}, | ||
158 | }; | ||
159 | |||
160 | static int smartq_wm8987_init(struct snd_soc_codec *codec) | ||
161 | { | ||
162 | int err = 0; | ||
163 | |||
164 | /* Add SmartQ specific widgets */ | ||
165 | snd_soc_dapm_new_controls(codec, wm8987_dapm_widgets, | ||
166 | ARRAY_SIZE(wm8987_dapm_widgets)); | ||
167 | |||
168 | /* add SmartQ specific controls */ | ||
169 | err = snd_soc_add_controls(codec, wm8987_smartq_controls, | ||
170 | ARRAY_SIZE(wm8987_smartq_controls)); | ||
171 | |||
172 | if (err < 0) | ||
173 | return err; | ||
174 | |||
175 | /* setup SmartQ specific audio path */ | ||
176 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
177 | |||
178 | /* set endpoints to not connected */ | ||
179 | snd_soc_dapm_nc_pin(codec, "LINPUT1"); | ||
180 | snd_soc_dapm_nc_pin(codec, "RINPUT1"); | ||
181 | snd_soc_dapm_nc_pin(codec, "OUT3"); | ||
182 | snd_soc_dapm_nc_pin(codec, "ROUT1"); | ||
183 | |||
184 | /* set endpoints to default off mode */ | ||
185 | snd_soc_dapm_enable_pin(codec, "Internal Speaker"); | ||
186 | snd_soc_dapm_enable_pin(codec, "Internal Mic"); | ||
187 | snd_soc_dapm_disable_pin(codec, "Headphone Jack"); | ||
188 | |||
189 | err = snd_soc_dapm_sync(codec); | ||
190 | if (err) | ||
191 | return err; | ||
192 | |||
193 | /* Headphone jack detection */ | ||
194 | err = snd_soc_jack_new(&snd_soc_smartq, "Headphone Jack", | ||
195 | SND_JACK_HEADPHONE, &smartq_jack); | ||
196 | if (err) | ||
197 | return err; | ||
198 | |||
199 | err = snd_soc_jack_add_pins(&smartq_jack, ARRAY_SIZE(smartq_jack_pins), | ||
200 | smartq_jack_pins); | ||
201 | if (err) | ||
202 | return err; | ||
203 | |||
204 | err = snd_soc_jack_add_gpios(&smartq_jack, | ||
205 | ARRAY_SIZE(smartq_jack_gpios), | ||
206 | smartq_jack_gpios); | ||
207 | |||
208 | return err; | ||
209 | } | ||
210 | |||
211 | static struct snd_soc_dai_link smartq_dai[] = { | ||
212 | { | ||
213 | .name = "wm8987", | ||
214 | .stream_name = "SmartQ Hi-Fi", | ||
215 | .cpu_dai = &s3c64xx_i2s_dai[0], | ||
216 | .codec_dai = &wm8750_dai, | ||
217 | .init = smartq_wm8987_init, | ||
218 | .ops = &smartq_hifi_ops, | ||
219 | }, | ||
220 | }; | ||
221 | |||
222 | static struct snd_soc_card snd_soc_smartq = { | ||
223 | .name = "SmartQ", | ||
224 | .platform = &s3c24xx_soc_platform, | ||
225 | .dai_link = smartq_dai, | ||
226 | .num_links = ARRAY_SIZE(smartq_dai), | ||
227 | }; | ||
228 | |||
229 | static struct snd_soc_device smartq_snd_devdata = { | ||
230 | .card = &snd_soc_smartq, | ||
231 | .codec_dev = &soc_codec_dev_wm8750, | ||
232 | }; | ||
233 | |||
234 | static struct platform_device *smartq_snd_device; | ||
235 | |||
236 | static int __init smartq_init(void) | ||
237 | { | ||
238 | int ret; | ||
239 | |||
240 | if (!machine_is_smartq7() && !machine_is_smartq5()) { | ||
241 | pr_info("Only SmartQ is supported by this ASoC driver\n"); | ||
242 | return -ENODEV; | ||
243 | } | ||
244 | |||
245 | smartq_snd_device = platform_device_alloc("soc-audio", -1); | ||
246 | if (!smartq_snd_device) | ||
247 | return -ENOMEM; | ||
248 | |||
249 | platform_set_drvdata(smartq_snd_device, &smartq_snd_devdata); | ||
250 | smartq_snd_devdata.dev = &smartq_snd_device->dev; | ||
251 | |||
252 | ret = platform_device_add(smartq_snd_device); | ||
253 | if (ret) { | ||
254 | platform_device_put(smartq_snd_device); | ||
255 | return ret; | ||
256 | } | ||
257 | |||
258 | /* Initialise GPIOs used by amplifiers */ | ||
259 | ret = gpio_request(S3C64XX_GPK(12), "amplifiers shutdown"); | ||
260 | if (ret) { | ||
261 | dev_err(&smartq_snd_device->dev, "Failed to register GPK12\n"); | ||
262 | goto err_unregister_device; | ||
263 | } | ||
264 | |||
265 | /* Disable amplifiers */ | ||
266 | ret = gpio_direction_output(S3C64XX_GPK(12), 1); | ||
267 | if (ret) { | ||
268 | dev_err(&smartq_snd_device->dev, "Failed to configure GPK12\n"); | ||
269 | goto err_free_gpio_amp_shut; | ||
270 | } | ||
271 | |||
272 | return 0; | ||
273 | |||
274 | err_free_gpio_amp_shut: | ||
275 | gpio_free(S3C64XX_GPK(12)); | ||
276 | err_unregister_device: | ||
277 | platform_device_unregister(smartq_snd_device); | ||
278 | |||
279 | return ret; | ||
280 | } | ||
281 | |||
282 | static void __exit smartq_exit(void) | ||
283 | { | ||
284 | snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios), | ||
285 | smartq_jack_gpios); | ||
286 | |||
287 | platform_device_unregister(smartq_snd_device); | ||
288 | } | ||
289 | |||
290 | module_init(smartq_init); | ||
291 | module_exit(smartq_exit); | ||
292 | |||
293 | /* Module information */ | ||
294 | MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>"); | ||
295 | MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987"); | ||
296 | MODULE_LICENSE("GPL"); | ||