blob: c3b2adafb7b552900b30583dd83dc65d1eefccd6 [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
59 /* set codec DAI configuration */
60 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
61 SND_SOC_DAIFMT_NB_NF |
62 SND_SOC_DAIFMT_CBS_CFS);
63 if (ret < 0)
64 return ret;
65
66 /* set cpu DAI configuration */
67 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
68 SND_SOC_DAIFMT_NB_NF |
69 SND_SOC_DAIFMT_CBS_CFS);
70 if (ret < 0)
71 return ret;
72
Jassi Brarb9493d62010-11-22 15:37:02 +090073 /* Use PCLK for I2S signal generation */
74 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
75 0, SND_SOC_CLOCK_IN);
76 if (ret < 0)
77 return ret;
78
79 /* Gate the RCLK output on PAD */
80 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
81 0, SND_SOC_CLOCK_IN);
82 if (ret < 0)
83 return ret;
84
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020085 /* set the codec system clock for DAC and ADC */
86 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
87 SND_SOC_CLOCK_IN);
88 if (ret < 0)
89 return ret;
90
Maurus Cuelenaerece93a372010-07-03 02:46:12 +020091 return 0;
92}
93
94/*
95 * SmartQ WM8987 HiFi DAI operations.
96 */
97static struct snd_soc_ops smartq_hifi_ops = {
98 .hw_params = smartq_hifi_hw_params,
99};
100
101static struct snd_soc_jack smartq_jack;
102
103static struct snd_soc_jack_pin smartq_jack_pins[] = {
104 /* Disable speaker when headphone is plugged in */
105 {
106 .pin = "Internal Speaker",
107 .mask = SND_JACK_HEADPHONE,
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200108 },
109};
110
111static struct snd_soc_jack_gpio smartq_jack_gpios[] = {
112 {
113 .gpio = S3C64XX_GPL(12),
114 .name = "headphone detect",
115 .report = SND_JACK_HEADPHONE,
116 .debounce_time = 200,
117 },
118};
119
120static const struct snd_kcontrol_new wm8987_smartq_controls[] = {
121 SOC_DAPM_PIN_SWITCH("Internal Speaker"),
122 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
123 SOC_DAPM_PIN_SWITCH("Internal Mic"),
124};
125
126static int smartq_speaker_event(struct snd_soc_dapm_widget *w,
127 struct snd_kcontrol *k,
128 int event)
129{
130 gpio_set_value(S3C64XX_GPK(12), SND_SOC_DAPM_EVENT_OFF(event));
131
132 return 0;
133}
134
135static const struct snd_soc_dapm_widget wm8987_dapm_widgets[] = {
136 SND_SOC_DAPM_SPK("Internal Speaker", smartq_speaker_event),
137 SND_SOC_DAPM_HP("Headphone Jack", NULL),
138 SND_SOC_DAPM_MIC("Internal Mic", NULL),
139};
140
141static const struct snd_soc_dapm_route audio_map[] = {
142 {"Headphone Jack", NULL, "LOUT2"},
143 {"Headphone Jack", NULL, "ROUT2"},
144
145 {"Internal Speaker", NULL, "LOUT2"},
146 {"Internal Speaker", NULL, "ROUT2"},
147
148 {"Mic Bias", NULL, "Internal Mic"},
149 {"LINPUT2", NULL, "Mic Bias"},
150};
151
Axel Lin74bd21e2010-11-25 13:43:49 +0800152static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd)
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200153{
Axel Lin74bd21e2010-11-25 13:43:49 +0800154 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200155 struct snd_soc_dapm_context *dapm = &codec->dapm;
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200156 int err = 0;
157
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200158 /* set endpoints to not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200159 snd_soc_dapm_nc_pin(dapm, "LINPUT1");
160 snd_soc_dapm_nc_pin(dapm, "RINPUT1");
161 snd_soc_dapm_nc_pin(dapm, "OUT3");
162 snd_soc_dapm_nc_pin(dapm, "ROUT1");
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200163
164 /* set endpoints to default off mode */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200165 snd_soc_dapm_enable_pin(dapm, "Internal Speaker");
166 snd_soc_dapm_enable_pin(dapm, "Internal Mic");
167 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200168
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200169 /* Headphone jack detection */
Axel Lin74bd21e2010-11-25 13:43:49 +0800170 err = snd_soc_jack_new(codec, "Headphone Jack",
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200171 SND_JACK_HEADPHONE, &smartq_jack);
172 if (err)
173 return err;
174
175 err = snd_soc_jack_add_pins(&smartq_jack, ARRAY_SIZE(smartq_jack_pins),
176 smartq_jack_pins);
177 if (err)
178 return err;
179
180 err = snd_soc_jack_add_gpios(&smartq_jack,
181 ARRAY_SIZE(smartq_jack_gpios),
182 smartq_jack_gpios);
183
184 return err;
185}
186
187static struct snd_soc_dai_link smartq_dai[] = {
188 {
189 .name = "wm8987",
190 .stream_name = "SmartQ Hi-Fi",
Jassi Brarb9493d62010-11-22 15:37:02 +0900191 .cpu_dai_name = "samsung-i2s.0",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000192 .codec_dai_name = "wm8750-hifi",
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530193 .platform_name = "samsung-i2s.0",
Mark Browndc5de622011-08-03 18:22:28 +0900194 .codec_name = "wm8750.0-0x1a",
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200195 .init = smartq_wm8987_init,
196 .ops = &smartq_hifi_ops,
197 },
198};
199
200static struct snd_soc_card snd_soc_smartq = {
201 .name = "SmartQ",
Axel Lin095d79d2011-12-22 10:53:15 +0800202 .owner = THIS_MODULE,
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200203 .dai_link = smartq_dai,
204 .num_links = ARRAY_SIZE(smartq_dai),
Mark Brown257fe592011-10-08 13:30:55 +0100205
206 .dapm_widgets = wm8987_dapm_widgets,
207 .num_dapm_widgets = ARRAY_SIZE(wm8987_dapm_widgets),
208 .dapm_routes = audio_map,
209 .num_dapm_routes = ARRAY_SIZE(audio_map),
210 .controls = wm8987_smartq_controls,
211 .num_controls = ARRAY_SIZE(wm8987_smartq_controls),
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200212};
213
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200214static struct platform_device *smartq_snd_device;
215
216static int __init smartq_init(void)
217{
218 int ret;
219
220 if (!machine_is_smartq7() && !machine_is_smartq5()) {
221 pr_info("Only SmartQ is supported by this ASoC driver\n");
222 return -ENODEV;
223 }
224
225 smartq_snd_device = platform_device_alloc("soc-audio", -1);
226 if (!smartq_snd_device)
227 return -ENOMEM;
228
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000229 platform_set_drvdata(smartq_snd_device, &snd_soc_smartq);
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200230
231 ret = platform_device_add(smartq_snd_device);
232 if (ret) {
233 platform_device_put(smartq_snd_device);
234 return ret;
235 }
236
237 /* Initialise GPIOs used by amplifiers */
238 ret = gpio_request(S3C64XX_GPK(12), "amplifiers shutdown");
239 if (ret) {
240 dev_err(&smartq_snd_device->dev, "Failed to register GPK12\n");
241 goto err_unregister_device;
242 }
243
244 /* Disable amplifiers */
245 ret = gpio_direction_output(S3C64XX_GPK(12), 1);
246 if (ret) {
247 dev_err(&smartq_snd_device->dev, "Failed to configure GPK12\n");
248 goto err_free_gpio_amp_shut;
249 }
250
251 return 0;
252
253err_free_gpio_amp_shut:
254 gpio_free(S3C64XX_GPK(12));
255err_unregister_device:
256 platform_device_unregister(smartq_snd_device);
257
258 return ret;
259}
260
261static void __exit smartq_exit(void)
262{
Axel Lin3790f202010-11-26 14:53:38 +0800263 gpio_free(S3C64XX_GPK(12));
Maurus Cuelenaerece93a372010-07-03 02:46:12 +0200264 snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios),
265 smartq_jack_gpios);
266
267 platform_device_unregister(smartq_snd_device);
268}
269
270module_init(smartq_init);
271module_exit(smartq_exit);
272
273/* Module information */
274MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>");
275MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987");
276MODULE_LICENSE("GPL");