blob: 8291d2a5f1525957b6c4e021c8657d4590ce649e [file] [log] [blame]
Jassi Brar5033f432010-11-22 15:37:25 +09001/* sound/soc/samsung/smartq_wm8987.c
Maurus Cuelenaerece93a372010-07-03 02:46:12 +02002 *
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
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020016#include <linux/gpio.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040017#include <linux/module.h>
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020018
Jarkko Nikula1c8f2c42010-11-21 19:48:44 +020019#include <sound/soc.h>
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020020#include <sound/jack.h>
21
Sachin Kamatabffae62014-01-22 17:30:38 +053022#include <mach/gpio-samsung.h>
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020023#include <asm/mach-types.h>
24
Jassi Brarb9493d62010-11-22 15:37:02 +090025#include "i2s.h"
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020026#include "../codecs/wm8750.h"
27
28/*
29 * WM8987 is register compatible with WM8750, so using that as base driver.
30 */
31
32static struct snd_soc_card snd_soc_smartq;
33
34static 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;
Axel Lin74bd21e2010-11-25 13:43:49 +080038 struct snd_soc_dai *codec_dai = rtd->codec_dai;
39 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020040 unsigned int clk = 0;
41 int ret;
42
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020043 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
Jassi Brarb9493d62010-11-22 15:37:02 +090059 /* 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);
62 if (ret < 0)
63 return ret;
64
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);
68 if (ret < 0)
69 return ret;
70
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020071 /* 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);
74 if (ret < 0)
75 return ret;
76
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020077 return 0;
78}
79
80/*
81 * SmartQ WM8987 HiFi DAI operations.
82 */
83static struct snd_soc_ops smartq_hifi_ops = {
84 .hw_params = smartq_hifi_hw_params,
85};
86
87static struct snd_soc_jack smartq_jack;
88
89static 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,
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020094 },
95};
96
97static 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
106static 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
112static 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
121static 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
127static 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
Axel Lin74bd21e2010-11-25 13:43:49 +0800138static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd)
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200139{
Axel Lin74bd21e2010-11-25 13:43:49 +0800140 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200141 struct snd_soc_dapm_context *dapm = &codec->dapm;
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200142 int err = 0;
143
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200144 /* set endpoints to not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200145 snd_soc_dapm_nc_pin(dapm, "LINPUT1");
146 snd_soc_dapm_nc_pin(dapm, "RINPUT1");
147 snd_soc_dapm_nc_pin(dapm, "OUT3");
148 snd_soc_dapm_nc_pin(dapm, "ROUT1");
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200149
150 /* set endpoints to default off mode */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200151 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200152
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200153 /* Headphone jack detection */
Axel Lin74bd21e2010-11-25 13:43:49 +0800154 err = snd_soc_jack_new(codec, "Headphone Jack",
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200155 SND_JACK_HEADPHONE, &smartq_jack);
156 if (err)
157 return err;
158
159 err = snd_soc_jack_add_pins(&smartq_jack, ARRAY_SIZE(smartq_jack_pins),
160 smartq_jack_pins);
161 if (err)
162 return err;
163
164 err = snd_soc_jack_add_gpios(&smartq_jack,
165 ARRAY_SIZE(smartq_jack_gpios),
166 smartq_jack_gpios);
167
168 return err;
169}
170
Takashi Iwai16088cb2014-06-03 12:31:46 +0200171static int smartq_wm8987_card_remove(struct snd_soc_card *card)
Stephen Warrene1d4d3c2014-05-30 12:42:57 -0600172{
173 snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios),
174 smartq_jack_gpios);
175
176 return 0;
177}
178
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200179static struct snd_soc_dai_link smartq_dai[] = {
180 {
181 .name = "wm8987",
182 .stream_name = "SmartQ Hi-Fi",
Jassi Brarb9493d62010-11-22 15:37:02 +0900183 .cpu_dai_name = "samsung-i2s.0",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000184 .codec_dai_name = "wm8750-hifi",
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530185 .platform_name = "samsung-i2s.0",
Mark Browndc5de622011-08-03 18:22:28 +0900186 .codec_name = "wm8750.0-0x1a",
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200187 .init = smartq_wm8987_init,
Lars-Peter Clausen10756c22015-01-01 17:16:26 +0100188 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
189 SND_SOC_DAIFMT_CBS_CFS,
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200190 .ops = &smartq_hifi_ops,
191 },
192};
193
194static struct snd_soc_card snd_soc_smartq = {
195 .name = "SmartQ",
Axel Lin095d79d2011-12-22 10:53:15 +0800196 .owner = THIS_MODULE,
Stephen Warrene1d4d3c2014-05-30 12:42:57 -0600197 .remove = smartq_wm8987_card_remove,
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200198 .dai_link = smartq_dai,
199 .num_links = ARRAY_SIZE(smartq_dai),
Mark Brown257fe592011-10-08 13:30:55 +0100200
201 .dapm_widgets = wm8987_dapm_widgets,
202 .num_dapm_widgets = ARRAY_SIZE(wm8987_dapm_widgets),
203 .dapm_routes = audio_map,
204 .num_dapm_routes = ARRAY_SIZE(audio_map),
205 .controls = wm8987_smartq_controls,
206 .num_controls = ARRAY_SIZE(wm8987_smartq_controls),
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200207};
208
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200209static struct platform_device *smartq_snd_device;
210
211static int __init smartq_init(void)
212{
213 int ret;
214
215 if (!machine_is_smartq7() && !machine_is_smartq5()) {
216 pr_info("Only SmartQ is supported by this ASoC driver\n");
217 return -ENODEV;
218 }
219
220 smartq_snd_device = platform_device_alloc("soc-audio", -1);
221 if (!smartq_snd_device)
222 return -ENOMEM;
223
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000224 platform_set_drvdata(smartq_snd_device, &snd_soc_smartq);
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200225
226 ret = platform_device_add(smartq_snd_device);
227 if (ret) {
228 platform_device_put(smartq_snd_device);
229 return ret;
230 }
231
232 /* Initialise GPIOs used by amplifiers */
233 ret = gpio_request(S3C64XX_GPK(12), "amplifiers shutdown");
234 if (ret) {
235 dev_err(&smartq_snd_device->dev, "Failed to register GPK12\n");
236 goto err_unregister_device;
237 }
238
239 /* Disable amplifiers */
240 ret = gpio_direction_output(S3C64XX_GPK(12), 1);
241 if (ret) {
242 dev_err(&smartq_snd_device->dev, "Failed to configure GPK12\n");
243 goto err_free_gpio_amp_shut;
244 }
245
246 return 0;
247
248err_free_gpio_amp_shut:
249 gpio_free(S3C64XX_GPK(12));
250err_unregister_device:
251 platform_device_unregister(smartq_snd_device);
252
253 return ret;
254}
255
256static void __exit smartq_exit(void)
257{
Axel Lin3790f202010-11-26 14:53:38 +0800258 gpio_free(S3C64XX_GPK(12));
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200259
260 platform_device_unregister(smartq_snd_device);
261}
262
263module_init(smartq_init);
264module_exit(smartq_exit);
265
266/* Module information */
267MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>");
268MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987");
269MODULE_LICENSE("GPL");