blob: e94ffe01a4a5e91ac2059de58c3e68a825737bcc [file] [log] [blame]
Graeme Gregory74930bb2007-05-14 11:03:52 +02001/*
2 * neo1973_wm8753.c -- SoC audio for Neo1973
3 *
4 * Copyright 2007 Wolfson Microelectronics PLC.
5 * Author: Graeme Gregory
6 * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
Graeme Gregory74930bb2007-05-14 11:03:52 +020013 */
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/timer.h>
18#include <linux/interrupt.h>
19#include <linux/platform_device.h>
20#include <linux/i2c.h>
Graeme Gregory74930bb2007-05-14 11:03:52 +020021#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
Mike Montoura2e31a52008-06-11 13:47:14 +010025#include <sound/tlv.h>
Graeme Gregory74930bb2007-05-14 11:03:52 +020026
Mark Brownfb2aa072008-10-08 13:02:20 +010027#include <asm/mach-types.h>
Graeme Gregory74930bb2007-05-14 11:03:52 +020028#include <asm/hardware/scoop.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/regs-clock.h>
30#include <mach/regs-gpio.h>
31#include <mach/hardware.h>
Graeme Gregory8ba02ac2008-04-30 20:24:54 +020032#include <linux/io.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010033#include <mach/spi-gpio.h>
Harald Welteaa9673c2007-12-19 15:37:49 +010034
Ben Dooks8150bc82009-03-04 00:49:26 +000035#include <plat/regs-iis.h>
Harald Welteaa9673c2007-12-19 15:37:49 +010036
Graeme Gregory74930bb2007-05-14 11:03:52 +020037#include "../codecs/wm8753.h"
38#include "lm4857.h"
Jassi Brard3ff5a32009-11-17 16:53:31 +090039#include "s3c-dma.h"
Graeme Gregory74930bb2007-05-14 11:03:52 +020040#include "s3c24xx-i2s.h"
41
42/* define the scenarios */
43#define NEO_AUDIO_OFF 0
44#define NEO_GSM_CALL_AUDIO_HANDSET 1
45#define NEO_GSM_CALL_AUDIO_HEADSET 2
46#define NEO_GSM_CALL_AUDIO_BLUETOOTH 3
47#define NEO_STEREO_TO_SPEAKERS 4
48#define NEO_STEREO_TO_HEADPHONES 5
49#define NEO_CAPTURE_HANDSET 6
50#define NEO_CAPTURE_HEADSET 7
51#define NEO_CAPTURE_BLUETOOTH 8
52
Mark Brown87506542008-11-18 20:50:34 +000053static struct snd_soc_card neo1973;
Graeme Gregory74930bb2007-05-14 11:03:52 +020054static struct i2c_client *i2c;
55
56static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
57 struct snd_pcm_hw_params *params)
58{
59 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000060 struct snd_soc_dai *codec_dai = rtd->codec_dai;
61 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Graeme Gregory74930bb2007-05-14 11:03:52 +020062 unsigned int pll_out = 0, bclk = 0;
63 int ret = 0;
64 unsigned long iis_clkrate;
65
Mark Brownee7d4762009-03-06 18:04:34 +000066 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +020067
Graeme Gregory74930bb2007-05-14 11:03:52 +020068 iis_clkrate = s3c24xx_i2s_get_clockrate();
69
70 switch (params_rate(params)) {
71 case 8000:
72 case 16000:
73 pll_out = 12288000;
74 break;
75 case 48000:
76 bclk = WM8753_BCLK_DIV_4;
77 pll_out = 12288000;
78 break;
79 case 96000:
80 bclk = WM8753_BCLK_DIV_2;
81 pll_out = 12288000;
82 break;
83 case 11025:
84 bclk = WM8753_BCLK_DIV_16;
85 pll_out = 11289600;
86 break;
87 case 22050:
88 bclk = WM8753_BCLK_DIV_8;
89 pll_out = 11289600;
90 break;
91 case 44100:
92 bclk = WM8753_BCLK_DIV_4;
93 pll_out = 11289600;
94 break;
95 case 88200:
96 bclk = WM8753_BCLK_DIV_2;
97 pll_out = 11289600;
98 break;
99 }
100
101 /* set codec DAI configuration */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100102 ret = snd_soc_dai_set_fmt(codec_dai,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200103 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
104 SND_SOC_DAIFMT_CBM_CFM);
105 if (ret < 0)
106 return ret;
107
108 /* set cpu DAI configuration */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100109 ret = snd_soc_dai_set_fmt(cpu_dai,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200110 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
111 SND_SOC_DAIFMT_CBM_CFM);
112 if (ret < 0)
113 return ret;
114
115 /* set the codec system clock for DAC and ADC */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100116 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200117 SND_SOC_CLOCK_IN);
118 if (ret < 0)
119 return ret;
120
121 /* set MCLK division for sample rate */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100122 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200123 S3C2410_IISMOD_32FS);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200124 if (ret < 0)
125 return ret;
126
127 /* set codec BCLK division for sample rate */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100128 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200129 if (ret < 0)
130 return ret;
131
132 /* set prescaler division for sample rate */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100133 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200134 S3C24XX_PRESCALE(4, 4));
Graeme Gregory74930bb2007-05-14 11:03:52 +0200135 if (ret < 0)
136 return ret;
137
138 /* codec PLL input is PCLK/4 */
Mark Brown85488032009-09-05 18:52:16 +0100139 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200140 iis_clkrate / 4, pll_out);
141 if (ret < 0)
142 return ret;
143
144 return 0;
145}
146
147static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
148{
149 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000150 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200151
Mark Brownee7d4762009-03-06 18:04:34 +0000152 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200153
Graeme Gregory74930bb2007-05-14 11:03:52 +0200154 /* disable the PLL */
Takashi Iwai140318a2009-10-01 08:40:32 +0200155 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200156}
157
158/*
159 * Neo1973 WM8753 HiFi DAI opserations.
160 */
161static struct snd_soc_ops neo1973_hifi_ops = {
162 .hw_params = neo1973_hifi_hw_params,
163 .hw_free = neo1973_hifi_hw_free,
164};
165
166static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
167 struct snd_pcm_hw_params *params)
168{
169 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000170 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200171 unsigned int pcmdiv = 0;
172 int ret = 0;
173 unsigned long iis_clkrate;
174
Mark Brownee7d4762009-03-06 18:04:34 +0000175 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200176
Graeme Gregory74930bb2007-05-14 11:03:52 +0200177 iis_clkrate = s3c24xx_i2s_get_clockrate();
178
179 if (params_rate(params) != 8000)
180 return -EINVAL;
181 if (params_channels(params) != 1)
182 return -EINVAL;
183
184 pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */
185
186 /* todo: gg check mode (DSP_B) against CSR datasheet */
187 /* set codec DAI configuration */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100188 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B |
Graeme Gregory74930bb2007-05-14 11:03:52 +0200189 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
190 if (ret < 0)
191 return ret;
192
193 /* set the codec system clock for DAC and ADC */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100194 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK, 12288000,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200195 SND_SOC_CLOCK_IN);
196 if (ret < 0)
197 return ret;
198
199 /* set codec PCM division for sample rate */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100200 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200201 if (ret < 0)
202 return ret;
203
Andrea Gelminifa2eb002010-10-16 15:19:20 +0200204 /* configure and enable PLL for 12.288MHz output */
Takashi Iwai140318a2009-10-01 08:40:32 +0200205 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200206 iis_clkrate / 4, 12288000);
207 if (ret < 0)
208 return ret;
209
210 return 0;
211}
212
213static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
214{
215 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000216 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200217
Mark Brownee7d4762009-03-06 18:04:34 +0000218 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200219
Graeme Gregory74930bb2007-05-14 11:03:52 +0200220 /* disable the PLL */
Takashi Iwai140318a2009-10-01 08:40:32 +0200221 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200222}
223
224static struct snd_soc_ops neo1973_voice_ops = {
225 .hw_params = neo1973_voice_hw_params,
226 .hw_free = neo1973_voice_hw_free,
227};
228
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200229static int neo1973_scenario;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200230
231static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol)
233{
234 ucontrol->value.integer.value[0] = neo1973_scenario;
235 return 0;
236}
237
238static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
239{
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200240 struct snd_soc_dapm_context *dapm = &codec->dapm;
241
Mark Brownee7d4762009-03-06 18:04:34 +0000242 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200243
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200244 switch (neo1973_scenario) {
Graeme Gregory74930bb2007-05-14 11:03:52 +0200245 case NEO_AUDIO_OFF:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200246 snd_soc_dapm_disable_pin(dapm, "Audio Out");
247 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
248 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
249 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
250 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200251 break;
252 case NEO_GSM_CALL_AUDIO_HANDSET:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200253 snd_soc_dapm_enable_pin(dapm, "Audio Out");
254 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
255 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
256 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
257 snd_soc_dapm_enable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200258 break;
259 case NEO_GSM_CALL_AUDIO_HEADSET:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200260 snd_soc_dapm_enable_pin(dapm, "Audio Out");
261 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
262 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
263 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
264 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200265 break;
266 case NEO_GSM_CALL_AUDIO_BLUETOOTH:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200267 snd_soc_dapm_disable_pin(dapm, "Audio Out");
268 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
269 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
270 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
271 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200272 break;
273 case NEO_STEREO_TO_SPEAKERS:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200274 snd_soc_dapm_enable_pin(dapm, "Audio Out");
275 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
276 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
277 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
278 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200279 break;
280 case NEO_STEREO_TO_HEADPHONES:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200281 snd_soc_dapm_enable_pin(dapm, "Audio Out");
282 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
283 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
284 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
285 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200286 break;
287 case NEO_CAPTURE_HANDSET:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200288 snd_soc_dapm_disable_pin(dapm, "Audio Out");
289 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
290 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
291 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
292 snd_soc_dapm_enable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200293 break;
294 case NEO_CAPTURE_HEADSET:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200295 snd_soc_dapm_disable_pin(dapm, "Audio Out");
296 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
297 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
298 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
299 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200300 break;
301 case NEO_CAPTURE_BLUETOOTH:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200302 snd_soc_dapm_disable_pin(dapm, "Audio Out");
303 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
304 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
305 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
306 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200307 break;
308 default:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200309 snd_soc_dapm_disable_pin(dapm, "Audio Out");
310 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
311 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
312 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
313 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200314 }
315
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200316 snd_soc_dapm_sync(dapm);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200317
318 return 0;
319}
320
321static int neo1973_set_scenario(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_value *ucontrol)
323{
324 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
325
Mark Brownee7d4762009-03-06 18:04:34 +0000326 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200327
Graeme Gregory74930bb2007-05-14 11:03:52 +0200328 if (neo1973_scenario == ucontrol->value.integer.value[0])
329 return 0;
330
331 neo1973_scenario = ucontrol->value.integer.value[0];
332 set_scenario_endpoints(codec, neo1973_scenario);
333 return 1;
334}
335
336static u8 lm4857_regs[4] = {0x00, 0x40, 0x80, 0xC0};
337
338static void lm4857_write_regs(void)
339{
Mark Brownee7d4762009-03-06 18:04:34 +0000340 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200341
Graeme Gregory74930bb2007-05-14 11:03:52 +0200342 if (i2c_master_send(i2c, lm4857_regs, 4) != 4)
343 printk(KERN_ERR "lm4857: i2c write failed\n");
344}
345
346static int lm4857_get_reg(struct snd_kcontrol *kcontrol,
347 struct snd_ctl_elem_value *ucontrol)
348{
Mark Brown236e6722009-06-10 13:55:34 +0100349 struct soc_mixer_control *mc =
350 (struct soc_mixer_control *)kcontrol->private_value;
351 int reg = mc->reg;
352 int shift = mc->shift;
353 int mask = mc->max;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200354
Mark Brownee7d4762009-03-06 18:04:34 +0000355 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200356
Graeme Gregory74930bb2007-05-14 11:03:52 +0200357 ucontrol->value.integer.value[0] = (lm4857_regs[reg] >> shift) & mask;
358 return 0;
359}
360
361static int lm4857_set_reg(struct snd_kcontrol *kcontrol,
362 struct snd_ctl_elem_value *ucontrol)
363{
Mark Brown236e6722009-06-10 13:55:34 +0100364 struct soc_mixer_control *mc =
365 (struct soc_mixer_control *)kcontrol->private_value;
366 int reg = mc->reg;
367 int shift = mc->shift;
368 int mask = mc->max;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200369
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200370 if (((lm4857_regs[reg] >> shift) & mask) ==
Graeme Gregory74930bb2007-05-14 11:03:52 +0200371 ucontrol->value.integer.value[0])
372 return 0;
373
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200374 lm4857_regs[reg] &= ~(mask << shift);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200375 lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift;
376 lm4857_write_regs();
377 return 1;
378}
379
380static int lm4857_get_mode(struct snd_kcontrol *kcontrol,
381 struct snd_ctl_elem_value *ucontrol)
382{
383 u8 value = lm4857_regs[LM4857_CTRL] & 0x0F;
384
Mark Brownee7d4762009-03-06 18:04:34 +0000385 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200386
Graeme Gregory74930bb2007-05-14 11:03:52 +0200387 if (value)
388 value -= 5;
389
390 ucontrol->value.integer.value[0] = value;
391 return 0;
392}
393
394static int lm4857_set_mode(struct snd_kcontrol *kcontrol,
395 struct snd_ctl_elem_value *ucontrol)
396{
397 u8 value = ucontrol->value.integer.value[0];
398
Mark Brownee7d4762009-03-06 18:04:34 +0000399 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200400
Graeme Gregory74930bb2007-05-14 11:03:52 +0200401 if (value)
402 value += 5;
403
404 if ((lm4857_regs[LM4857_CTRL] & 0x0F) == value)
405 return 0;
406
407 lm4857_regs[LM4857_CTRL] &= 0xF0;
408 lm4857_regs[LM4857_CTRL] |= value;
409 lm4857_write_regs();
410 return 1;
411}
412
413static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
414 SND_SOC_DAPM_LINE("Audio Out", NULL),
415 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
416 SND_SOC_DAPM_LINE("GSM Line In", NULL),
417 SND_SOC_DAPM_MIC("Headset Mic", NULL),
418 SND_SOC_DAPM_MIC("Call Mic", NULL),
419};
420
421
Mark Brown8f3112d2008-05-13 14:58:03 +0200422static const struct snd_soc_dapm_route dapm_routes[] = {
Graeme Gregory74930bb2007-05-14 11:03:52 +0200423
424 /* Connections to the lm4857 amp */
425 {"Audio Out", NULL, "LOUT1"},
426 {"Audio Out", NULL, "ROUT1"},
427
428 /* Connections to the GSM Module */
429 {"GSM Line Out", NULL, "MONO1"},
430 {"GSM Line Out", NULL, "MONO2"},
431 {"RXP", NULL, "GSM Line In"},
432 {"RXN", NULL, "GSM Line In"},
433
434 /* Connections to Headset */
435 {"MIC1", NULL, "Mic Bias"},
436 {"Mic Bias", NULL, "Headset Mic"},
437
438 /* Call Mic */
439 {"MIC2", NULL, "Mic Bias"},
440 {"MIC2N", NULL, "Mic Bias"},
441 {"Mic Bias", NULL, "Call Mic"},
442
443 /* Connect the ALC pins */
444 {"ACIN", NULL, "ACOP"},
Graeme Gregory74930bb2007-05-14 11:03:52 +0200445};
446
447static const char *lm4857_mode[] = {
448 "Off",
449 "Call Speaker",
450 "Stereo Speakers",
451 "Stereo Speakers + Headphones",
452 "Headphones"
453};
454
455static const struct soc_enum lm4857_mode_enum[] = {
456 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lm4857_mode), lm4857_mode),
457};
458
459static const char *neo_scenarios[] = {
460 "Off",
461 "GSM Handset",
462 "GSM Headset",
463 "GSM Bluetooth",
464 "Speakers",
465 "Headphones",
466 "Capture Handset",
467 "Capture Headset",
468 "Capture Bluetooth"
469};
470
471static const struct soc_enum neo_scenario_enum[] = {
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200472 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios), neo_scenarios),
Graeme Gregory74930bb2007-05-14 11:03:52 +0200473};
474
Mike Montoura2e31a52008-06-11 13:47:14 +0100475static const DECLARE_TLV_DB_SCALE(stereo_tlv, -4050, 150, 0);
476static const DECLARE_TLV_DB_SCALE(mono_tlv, -3450, 150, 0);
477
Graeme Gregory74930bb2007-05-14 11:03:52 +0200478static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
Mike Montoura2e31a52008-06-11 13:47:14 +0100479 SOC_SINGLE_EXT_TLV("Amp Left Playback Volume", LM4857_LVOL, 0, 31, 0,
480 lm4857_get_reg, lm4857_set_reg, stereo_tlv),
481 SOC_SINGLE_EXT_TLV("Amp Right Playback Volume", LM4857_RVOL, 0, 31, 0,
482 lm4857_get_reg, lm4857_set_reg, stereo_tlv),
483 SOC_SINGLE_EXT_TLV("Amp Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
484 lm4857_get_reg, lm4857_set_reg, mono_tlv),
Graeme Gregory74930bb2007-05-14 11:03:52 +0200485 SOC_ENUM_EXT("Amp Mode", lm4857_mode_enum[0],
486 lm4857_get_mode, lm4857_set_mode),
487 SOC_ENUM_EXT("Neo Mode", neo_scenario_enum[0],
488 neo1973_get_scenario, neo1973_set_scenario),
489 SOC_SINGLE_EXT("Amp Spk 3D Playback Switch", LM4857_LVOL, 5, 1, 0,
490 lm4857_get_reg, lm4857_set_reg),
491 SOC_SINGLE_EXT("Amp HP 3d Playback Switch", LM4857_RVOL, 5, 1, 0,
492 lm4857_get_reg, lm4857_set_reg),
493 SOC_SINGLE_EXT("Amp Fast Wakeup Playback Switch", LM4857_CTRL, 5, 1, 0,
494 lm4857_get_reg, lm4857_set_reg),
495 SOC_SINGLE_EXT("Amp Earpiece 6dB Playback Switch", LM4857_CTRL, 4, 1, 0,
496 lm4857_get_reg, lm4857_set_reg),
497};
498
499/*
500 * This is an example machine initialisation for a wm8753 connected to a
501 * neo1973 II. It is missing logic to detect hp/mic insertions and logic
502 * to re-route the audio in such an event.
503 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000504static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd)
Graeme Gregory74930bb2007-05-14 11:03:52 +0200505{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000506 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200507 struct snd_soc_dapm_context *dapm = &codec->dapm;
Philipp Zabeleb5f6d752009-03-12 11:07:54 +0100508 int err;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200509
Mark Brownee7d4762009-03-06 18:04:34 +0000510 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200511
Graeme Gregory74930bb2007-05-14 11:03:52 +0200512 /* set up NC codec pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200513 snd_soc_dapm_nc_pin(dapm, "LOUT2");
514 snd_soc_dapm_nc_pin(dapm, "ROUT2");
515 snd_soc_dapm_nc_pin(dapm, "OUT3");
516 snd_soc_dapm_nc_pin(dapm, "OUT4");
517 snd_soc_dapm_nc_pin(dapm, "LINE1");
518 snd_soc_dapm_nc_pin(dapm, "LINE2");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200519
Graeme Gregory74930bb2007-05-14 11:03:52 +0200520 /* Add neo1973 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200521 snd_soc_dapm_new_controls(dapm, wm8753_dapm_widgets,
Mark Brown8f3112d2008-05-13 14:58:03 +0200522 ARRAY_SIZE(wm8753_dapm_widgets));
Graeme Gregory74930bb2007-05-14 11:03:52 +0200523
Jonas Bonne8089942008-10-01 18:17:12 +0100524 /* set endpoints to default mode */
525 set_scenario_endpoints(codec, NEO_AUDIO_OFF);
526
Graeme Gregory74930bb2007-05-14 11:03:52 +0200527 /* add neo1973 specific controls */
Philipp Zabeleb5f6d752009-03-12 11:07:54 +0100528 err = snd_soc_add_controls(codec, wm8753_neo1973_controls,
529 ARRAY_SIZE(8753_neo1973_controls));
530 if (err < 0)
531 return err;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200532
Mark Brown8f3112d2008-05-13 14:58:03 +0200533 /* set up neo1973 specific audio routes */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200534 err = snd_soc_dapm_add_routes(dapm, dapm_routes,
Mark Brown8f3112d2008-05-13 14:58:03 +0200535 ARRAY_SIZE(dapm_routes));
Graeme Gregory74930bb2007-05-14 11:03:52 +0200536
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200537 snd_soc_dapm_sync(dapm);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200538 return 0;
539}
540
541/*
542 * BT Codec DAI
543 */
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100544static struct snd_soc_dai bt_dai = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000545 .name = "bluetooth-dai",
Graeme Gregory74930bb2007-05-14 11:03:52 +0200546 .playback = {
547 .channels_min = 1,
548 .channels_max = 1,
549 .rates = SNDRV_PCM_RATE_8000,
550 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
551 .capture = {
552 .channels_min = 1,
553 .channels_max = 1,
554 .rates = SNDRV_PCM_RATE_8000,
555 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
556};
557
558static struct snd_soc_dai_link neo1973_dai[] = {
559{ /* Hifi Playback - for similatious use with voice below */
560 .name = "WM8753",
561 .stream_name = "WM8753 HiFi",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000562 .platform_name = "s3c24xx-pcm-audio",
563 .cpu_dai_name = "s3c24xx-i2s",
564 .codec_dai_name = "wm8753-hifi",
565 .codec_name = "wm8753-codec.0-0x1a",
Graeme Gregory74930bb2007-05-14 11:03:52 +0200566 .init = neo1973_wm8753_init,
567 .ops = &neo1973_hifi_ops,
568},
569{ /* Voice via BT */
570 .name = "Bluetooth",
571 .stream_name = "Voice",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000572 .platform_name = "s3c24xx-pcm-audio",
573 .cpu_dai_name = "bluetooth-dai",
574 .codec_dai_name = "wm8753-voice",
575 .codec_name = "wm8753-codec.0-0x1a",
Graeme Gregory74930bb2007-05-14 11:03:52 +0200576 .ops = &neo1973_voice_ops,
577},
578};
579
Mark Brown87506542008-11-18 20:50:34 +0000580static struct snd_soc_card neo1973 = {
Graeme Gregory74930bb2007-05-14 11:03:52 +0200581 .name = "neo1973",
582 .dai_link = neo1973_dai,
583 .num_links = ARRAY_SIZE(neo1973_dai),
584};
585
Jean Delvareb6471302008-09-01 17:46:57 +0200586static int lm4857_i2c_probe(struct i2c_client *client,
587 const struct i2c_device_id *id)
Graeme Gregory74930bb2007-05-14 11:03:52 +0200588{
Mark Brownee7d4762009-03-06 18:04:34 +0000589 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200590
Jonas Bonnf9d1ab32008-10-01 21:47:19 +0200591 i2c = client;
592
Graeme Gregory74930bb2007-05-14 11:03:52 +0200593 lm4857_write_regs();
Graeme Gregory74930bb2007-05-14 11:03:52 +0200594 return 0;
595}
596
Jean Delvareb6471302008-09-01 17:46:57 +0200597static int lm4857_i2c_remove(struct i2c_client *client)
Graeme Gregory74930bb2007-05-14 11:03:52 +0200598{
Mark Brownee7d4762009-03-06 18:04:34 +0000599 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200600
Jonas Bonnf9d1ab32008-10-01 21:47:19 +0200601 i2c = NULL;
602
Jean Delvareb6471302008-09-01 17:46:57 +0200603 return 0;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200604}
605
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200606static u8 lm4857_state;
607
608static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
609{
Mark Brownee7d4762009-03-06 18:04:34 +0000610 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200611
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200612 dev_dbg(&dev->dev, "lm4857_suspend\n");
613 lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf;
614 if (lm4857_state) {
615 lm4857_regs[LM4857_CTRL] &= 0xf0;
616 lm4857_write_regs();
617 }
618 return 0;
619}
620
621static int lm4857_resume(struct i2c_client *dev)
622{
Mark Brownee7d4762009-03-06 18:04:34 +0000623 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200624
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200625 if (lm4857_state) {
626 lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f);
627 lm4857_write_regs();
628 }
629 return 0;
630}
631
632static void lm4857_shutdown(struct i2c_client *dev)
633{
Mark Brownee7d4762009-03-06 18:04:34 +0000634 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200635
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200636 dev_dbg(&dev->dev, "lm4857_shutdown\n");
637 lm4857_regs[LM4857_CTRL] &= 0xf0;
638 lm4857_write_regs();
639}
640
Jean Delvareb6471302008-09-01 17:46:57 +0200641static const struct i2c_device_id lm4857_i2c_id[] = {
Mark Browndf20cf92008-09-24 11:57:27 +0100642 { "neo1973_lm4857", 0 },
Jean Delvareb6471302008-09-01 17:46:57 +0200643 { }
644};
645
Graeme Gregory74930bb2007-05-14 11:03:52 +0200646static struct i2c_driver lm4857_i2c_driver = {
647 .driver = {
648 .name = "LM4857 I2C Amp",
649 .owner = THIS_MODULE,
650 },
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200651 .suspend = lm4857_suspend,
652 .resume = lm4857_resume,
653 .shutdown = lm4857_shutdown,
Jean Delvareb6471302008-09-01 17:46:57 +0200654 .probe = lm4857_i2c_probe,
655 .remove = lm4857_i2c_remove,
656 .id_table = lm4857_i2c_id,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200657};
658
659static struct platform_device *neo1973_snd_device;
660
661static int __init neo1973_init(void)
662{
663 int ret;
664
Mark Brownee7d4762009-03-06 18:04:34 +0000665 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200666
Mark Brownfb2aa072008-10-08 13:02:20 +0100667 if (!machine_is_neo1973_gta01()) {
668 printk(KERN_INFO
669 "Only GTA01 hardware supported by ASoC driver\n");
670 return -ENODEV;
671 }
672
Graeme Gregory74930bb2007-05-14 11:03:52 +0200673 neo1973_snd_device = platform_device_alloc("soc-audio", -1);
674 if (!neo1973_snd_device)
675 return -ENOMEM;
676
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000677 platform_set_drvdata(neo1973_snd_device, &neo1973);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200678 ret = platform_device_add(neo1973_snd_device);
679
Jean Delvared2802892008-09-01 17:44:05 +0200680 if (ret) {
Graeme Gregory74930bb2007-05-14 11:03:52 +0200681 platform_device_put(neo1973_snd_device);
Jean Delvared2802892008-09-01 17:44:05 +0200682 return ret;
683 }
Graeme Gregory74930bb2007-05-14 11:03:52 +0200684
Jonas Bonnf9d1ab32008-10-01 21:47:19 +0200685 ret = i2c_add_driver(&lm4857_i2c_driver);
686
Jean Delvareb6471302008-09-01 17:46:57 +0200687 if (ret != 0)
Jean Delvared2802892008-09-01 17:44:05 +0200688 platform_device_unregister(neo1973_snd_device);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200689
690 return ret;
691}
692
693static void __exit neo1973_exit(void)
694{
Mark Brownee7d4762009-03-06 18:04:34 +0000695 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200696
Tim Niemeyer6b9a9b32008-04-22 17:10:23 +0200697 i2c_del_driver(&lm4857_i2c_driver);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200698 platform_device_unregister(neo1973_snd_device);
699}
700
701module_init(neo1973_init);
702module_exit(neo1973_exit);
703
704/* Module information */
Graeme Gregory443590e2008-04-30 20:25:23 +0200705MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200706MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973");
707MODULE_LICENSE("GPL");