Merge remote-tracking branches 'asoc/topic/wm8804' and 'asoc/topic/wm9713' into asoc...
[deliverable/linux.git] / sound / soc / samsung / smartq_wm8987.c
CommitLineData
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
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;
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
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
b9493d6c
JB
73 /* 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);
ce93a370
MC
76 if (ret < 0)
77 return ret;
78
b9493d6c
JB
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);
ce93a370
MC
82 if (ret < 0)
83 return ret;
84
b9493d6c
JB
85 /* 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);
ce93a370
MC
88 if (ret < 0)
89 return ret;
90
91 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,
ce93a370
MC
108 },
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
74bd21e9 152static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd)
ce93a370 153{
74bd21e9 154 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 155 struct snd_soc_dapm_context *dapm = &codec->dapm;
ce93a370
MC
156 int err = 0;
157
ce93a370 158 /* set endpoints to not connected */
ce6120cc
LG
159 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");
ce93a370
MC
163
164 /* set endpoints to default off mode */
ce6120cc 165 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
ce93a370 166
ce93a370 167 /* Headphone jack detection */
74bd21e9 168 err = snd_soc_jack_new(codec, "Headphone Jack",
ce93a370
MC
169 SND_JACK_HEADPHONE, &smartq_jack);
170 if (err)
171 return err;
172
173 err = snd_soc_jack_add_pins(&smartq_jack, ARRAY_SIZE(smartq_jack_pins),
174 smartq_jack_pins);
175 if (err)
176 return err;
177
178 err = snd_soc_jack_add_gpios(&smartq_jack,
179 ARRAY_SIZE(smartq_jack_gpios),
180 smartq_jack_gpios);
181
182 return err;
183}
184
185static struct snd_soc_dai_link smartq_dai[] = {
186 {
187 .name = "wm8987",
188 .stream_name = "SmartQ Hi-Fi",
b9493d6c 189 .cpu_dai_name = "samsung-i2s.0",
f0fba2ad 190 .codec_dai_name = "wm8750-hifi",
a08485d8 191 .platform_name = "samsung-i2s.0",
dc5de62b 192 .codec_name = "wm8750.0-0x1a",
ce93a370
MC
193 .init = smartq_wm8987_init,
194 .ops = &smartq_hifi_ops,
195 },
196};
197
198static struct snd_soc_card snd_soc_smartq = {
199 .name = "SmartQ",
095d79dc 200 .owner = THIS_MODULE,
ce93a370
MC
201 .dai_link = smartq_dai,
202 .num_links = ARRAY_SIZE(smartq_dai),
257fe593
MB
203
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),
ce93a370
MC
210};
211
ce93a370
MC
212static struct platform_device *smartq_snd_device;
213
214static int __init smartq_init(void)
215{
216 int ret;
217
218 if (!machine_is_smartq7() && !machine_is_smartq5()) {
219 pr_info("Only SmartQ is supported by this ASoC driver\n");
220 return -ENODEV;
221 }
222
223 smartq_snd_device = platform_device_alloc("soc-audio", -1);
224 if (!smartq_snd_device)
225 return -ENOMEM;
226
f0fba2ad 227 platform_set_drvdata(smartq_snd_device, &snd_soc_smartq);
ce93a370
MC
228
229 ret = platform_device_add(smartq_snd_device);
230 if (ret) {
231 platform_device_put(smartq_snd_device);
232 return ret;
233 }
234
235 /* Initialise GPIOs used by amplifiers */
236 ret = gpio_request(S3C64XX_GPK(12), "amplifiers shutdown");
237 if (ret) {
238 dev_err(&smartq_snd_device->dev, "Failed to register GPK12\n");
239 goto err_unregister_device;
240 }
241
242 /* Disable amplifiers */
243 ret = gpio_direction_output(S3C64XX_GPK(12), 1);
244 if (ret) {
245 dev_err(&smartq_snd_device->dev, "Failed to configure GPK12\n");
246 goto err_free_gpio_amp_shut;
247 }
248
249 return 0;
250
251err_free_gpio_amp_shut:
252 gpio_free(S3C64XX_GPK(12));
253err_unregister_device:
254 platform_device_unregister(smartq_snd_device);
255
256 return ret;
257}
258
259static void __exit smartq_exit(void)
260{
3790f205 261 gpio_free(S3C64XX_GPK(12));
ce93a370
MC
262 snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios),
263 smartq_jack_gpios);
264
265 platform_device_unregister(smartq_snd_device);
266}
267
268module_init(smartq_init);
269module_exit(smartq_exit);
270
271/* Module information */
272MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>");
273MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987");
274MODULE_LICENSE("GPL");
This page took 0.167983 seconds and 5 git commands to generate.