Commit | Line | Data |
---|---|---|
5033f43c | 1 | /* sound/soc/samsung/smartq_wm8987.c |
ce93a370 MC |
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 | ||
ce93a370 | 16 | #include <linux/gpio.h> |
da155d5b | 17 | #include <linux/module.h> |
ce93a370 | 18 | |
1c8f2c42 | 19 | #include <sound/soc.h> |
ce93a370 MC |
20 | #include <sound/jack.h> |
21 | ||
abffae64 | 22 | #include <mach/gpio-samsung.h> |
ce93a370 MC |
23 | #include <asm/mach-types.h> |
24 | ||
b9493d6c | 25 | #include "i2s.h" |
ce93a370 MC |
26 | #include "../codecs/wm8750.h" |
27 | ||
28 | /* | |
29 | * WM8987 is register compatible with WM8750, so using that as base driver. | |
30 | */ | |
31 | ||
32 | static struct snd_soc_card snd_soc_smartq; | |
33 | ||
34 | static int smartq_hifi_hw_params(struct snd_pcm_substream *substream, | |
35 | struct snd_pcm_hw_params *params) | |
36 | { | |
37 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
74bd21e9 AL |
38 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
39 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
ce93a370 MC |
40 | unsigned int clk = 0; |
41 | int ret; | |
42 | ||
ce93a370 MC |
43 | switch (params_rate(params)) { |
44 | case 8000: | |
45 | case 16000: | |
46 | case 32000: | |
47 | case 48000: | |
48 | case 96000: | |
49 | clk = 12288000; | |
50 | break; | |
51 | case 11025: | |
52 | case 22050: | |
53 | case 44100: | |
54 | case 88200: | |
55 | clk = 11289600; | |
56 | break; | |
57 | } | |
58 | ||
b9493d6c JB |
59 | /* Use PCLK for I2S signal generation */ |
60 | ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0, | |
61 | 0, SND_SOC_CLOCK_IN); | |
ce93a370 MC |
62 | if (ret < 0) |
63 | return ret; | |
64 | ||
b9493d6c JB |
65 | /* Gate the RCLK output on PAD */ |
66 | ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK, | |
67 | 0, SND_SOC_CLOCK_IN); | |
ce93a370 MC |
68 | if (ret < 0) |
69 | return ret; | |
70 | ||
b9493d6c JB |
71 | /* set the codec system clock for DAC and ADC */ |
72 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk, | |
73 | SND_SOC_CLOCK_IN); | |
ce93a370 MC |
74 | if (ret < 0) |
75 | return ret; | |
76 | ||
77 | return 0; | |
78 | } | |
79 | ||
80 | /* | |
81 | * SmartQ WM8987 HiFi DAI operations. | |
82 | */ | |
83 | static struct snd_soc_ops smartq_hifi_ops = { | |
84 | .hw_params = smartq_hifi_hw_params, | |
85 | }; | |
86 | ||
87 | static struct snd_soc_jack smartq_jack; | |
88 | ||
89 | static struct snd_soc_jack_pin smartq_jack_pins[] = { | |
90 | /* Disable speaker when headphone is plugged in */ | |
91 | { | |
92 | .pin = "Internal Speaker", | |
93 | .mask = SND_JACK_HEADPHONE, | |
ce93a370 MC |
94 | }, |
95 | }; | |
96 | ||
97 | static struct snd_soc_jack_gpio smartq_jack_gpios[] = { | |
98 | { | |
99 | .gpio = S3C64XX_GPL(12), | |
100 | .name = "headphone detect", | |
101 | .report = SND_JACK_HEADPHONE, | |
102 | .debounce_time = 200, | |
103 | }, | |
104 | }; | |
105 | ||
106 | static const struct snd_kcontrol_new wm8987_smartq_controls[] = { | |
107 | SOC_DAPM_PIN_SWITCH("Internal Speaker"), | |
108 | SOC_DAPM_PIN_SWITCH("Headphone Jack"), | |
109 | SOC_DAPM_PIN_SWITCH("Internal Mic"), | |
110 | }; | |
111 | ||
112 | static int smartq_speaker_event(struct snd_soc_dapm_widget *w, | |
113 | struct snd_kcontrol *k, | |
114 | int event) | |
115 | { | |
116 | gpio_set_value(S3C64XX_GPK(12), SND_SOC_DAPM_EVENT_OFF(event)); | |
117 | ||
118 | return 0; | |
119 | } | |
120 | ||
121 | static const struct snd_soc_dapm_widget wm8987_dapm_widgets[] = { | |
122 | SND_SOC_DAPM_SPK("Internal Speaker", smartq_speaker_event), | |
123 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | |
124 | SND_SOC_DAPM_MIC("Internal Mic", NULL), | |
125 | }; | |
126 | ||
127 | static const struct snd_soc_dapm_route audio_map[] = { | |
128 | {"Headphone Jack", NULL, "LOUT2"}, | |
129 | {"Headphone Jack", NULL, "ROUT2"}, | |
130 | ||
131 | {"Internal Speaker", NULL, "LOUT2"}, | |
132 | {"Internal Speaker", NULL, "ROUT2"}, | |
133 | ||
134 | {"Mic Bias", NULL, "Internal Mic"}, | |
135 | {"LINPUT2", NULL, "Mic Bias"}, | |
136 | }; | |
137 | ||
74bd21e9 | 138 | static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd) |
ce93a370 | 139 | { |
d01d7d3d | 140 | struct snd_soc_dapm_context *dapm = &rtd->card->dapm; |
ce93a370 MC |
141 | int err = 0; |
142 | ||
ce93a370 | 143 | /* set endpoints to not connected */ |
ce6120cc LG |
144 | snd_soc_dapm_nc_pin(dapm, "LINPUT1"); |
145 | snd_soc_dapm_nc_pin(dapm, "RINPUT1"); | |
146 | snd_soc_dapm_nc_pin(dapm, "OUT3"); | |
147 | snd_soc_dapm_nc_pin(dapm, "ROUT1"); | |
ce93a370 | 148 | |
ce93a370 | 149 | /* Headphone jack detection */ |
55b2ed2d LPC |
150 | err = snd_soc_card_jack_new(rtd->card, "Headphone Jack", |
151 | SND_JACK_HEADPHONE, &smartq_jack, | |
152 | smartq_jack_pins, | |
153 | ARRAY_SIZE(smartq_jack_pins)); | |
ce93a370 MC |
154 | if (err) |
155 | return err; | |
156 | ||
157 | err = snd_soc_jack_add_gpios(&smartq_jack, | |
158 | ARRAY_SIZE(smartq_jack_gpios), | |
159 | smartq_jack_gpios); | |
160 | ||
161 | return err; | |
162 | } | |
163 | ||
16088cb6 | 164 | static int smartq_wm8987_card_remove(struct snd_soc_card *card) |
e1d4d3c8 SW |
165 | { |
166 | snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios), | |
167 | smartq_jack_gpios); | |
168 | ||
169 | return 0; | |
170 | } | |
171 | ||
ce93a370 MC |
172 | static struct snd_soc_dai_link smartq_dai[] = { |
173 | { | |
174 | .name = "wm8987", | |
175 | .stream_name = "SmartQ Hi-Fi", | |
b9493d6c | 176 | .cpu_dai_name = "samsung-i2s.0", |
f0fba2ad | 177 | .codec_dai_name = "wm8750-hifi", |
a08485d8 | 178 | .platform_name = "samsung-i2s.0", |
dc5de62b | 179 | .codec_name = "wm8750.0-0x1a", |
ce93a370 | 180 | .init = smartq_wm8987_init, |
10756c27 LPC |
181 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
182 | SND_SOC_DAIFMT_CBS_CFS, | |
ce93a370 MC |
183 | .ops = &smartq_hifi_ops, |
184 | }, | |
185 | }; | |
186 | ||
187 | static struct snd_soc_card snd_soc_smartq = { | |
188 | .name = "SmartQ", | |
095d79dc | 189 | .owner = THIS_MODULE, |
e1d4d3c8 | 190 | .remove = smartq_wm8987_card_remove, |
ce93a370 MC |
191 | .dai_link = smartq_dai, |
192 | .num_links = ARRAY_SIZE(smartq_dai), | |
257fe593 MB |
193 | |
194 | .dapm_widgets = wm8987_dapm_widgets, | |
195 | .num_dapm_widgets = ARRAY_SIZE(wm8987_dapm_widgets), | |
196 | .dapm_routes = audio_map, | |
197 | .num_dapm_routes = ARRAY_SIZE(audio_map), | |
198 | .controls = wm8987_smartq_controls, | |
199 | .num_controls = ARRAY_SIZE(wm8987_smartq_controls), | |
ce93a370 MC |
200 | }; |
201 | ||
ce93a370 MC |
202 | static struct platform_device *smartq_snd_device; |
203 | ||
204 | static int __init smartq_init(void) | |
205 | { | |
206 | int ret; | |
207 | ||
208 | if (!machine_is_smartq7() && !machine_is_smartq5()) { | |
209 | pr_info("Only SmartQ is supported by this ASoC driver\n"); | |
210 | return -ENODEV; | |
211 | } | |
212 | ||
213 | smartq_snd_device = platform_device_alloc("soc-audio", -1); | |
214 | if (!smartq_snd_device) | |
215 | return -ENOMEM; | |
216 | ||
f0fba2ad | 217 | platform_set_drvdata(smartq_snd_device, &snd_soc_smartq); |
ce93a370 MC |
218 | |
219 | ret = platform_device_add(smartq_snd_device); | |
220 | if (ret) { | |
221 | platform_device_put(smartq_snd_device); | |
222 | return ret; | |
223 | } | |
224 | ||
225 | /* Initialise GPIOs used by amplifiers */ | |
226 | ret = gpio_request(S3C64XX_GPK(12), "amplifiers shutdown"); | |
227 | if (ret) { | |
228 | dev_err(&smartq_snd_device->dev, "Failed to register GPK12\n"); | |
229 | goto err_unregister_device; | |
230 | } | |
231 | ||
232 | /* Disable amplifiers */ | |
233 | ret = gpio_direction_output(S3C64XX_GPK(12), 1); | |
234 | if (ret) { | |
235 | dev_err(&smartq_snd_device->dev, "Failed to configure GPK12\n"); | |
236 | goto err_free_gpio_amp_shut; | |
237 | } | |
238 | ||
239 | return 0; | |
240 | ||
241 | err_free_gpio_amp_shut: | |
242 | gpio_free(S3C64XX_GPK(12)); | |
243 | err_unregister_device: | |
244 | platform_device_unregister(smartq_snd_device); | |
245 | ||
246 | return ret; | |
247 | } | |
248 | ||
249 | static void __exit smartq_exit(void) | |
250 | { | |
3790f205 | 251 | gpio_free(S3C64XX_GPK(12)); |
ce93a370 MC |
252 | |
253 | platform_device_unregister(smartq_snd_device); | |
254 | } | |
255 | ||
256 | module_init(smartq_init); | |
257 | module_exit(smartq_exit); | |
258 | ||
259 | /* Module information */ | |
260 | MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>"); | |
261 | MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987"); | |
262 | MODULE_LICENSE("GPL"); |