blob: c7a24514beb58c65b349616a52e3733bf3ec6667 [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>
Mike Montoura2e31a52008-06-11 13:47:14 +010024#include <sound/tlv.h>
Graeme Gregory74930bb2007-05-14 11:03:52 +020025
Mark Brownfb2aa072008-10-08 13:02:20 +010026#include <asm/mach-types.h>
Graeme Gregory74930bb2007-05-14 11:03:52 +020027#include <asm/hardware/scoop.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/regs-clock.h>
29#include <mach/regs-gpio.h>
30#include <mach/hardware.h>
Graeme Gregory8ba02ac2008-04-30 20:24:54 +020031#include <linux/io.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010032#include <mach/spi-gpio.h>
Harald Welteaa9673c2007-12-19 15:37:49 +010033
Ben Dooks8150bc82009-03-04 00:49:26 +000034#include <plat/regs-iis.h>
Harald Welteaa9673c2007-12-19 15:37:49 +010035
Graeme Gregory74930bb2007-05-14 11:03:52 +020036#include "../codecs/wm8753.h"
37#include "lm4857.h"
Jassi Brar4b640cf2010-11-22 15:35:57 +090038#include "dma.h"
Graeme Gregory74930bb2007-05-14 11:03:52 +020039#include "s3c24xx-i2s.h"
40
41/* define the scenarios */
42#define NEO_AUDIO_OFF 0
43#define NEO_GSM_CALL_AUDIO_HANDSET 1
44#define NEO_GSM_CALL_AUDIO_HEADSET 2
45#define NEO_GSM_CALL_AUDIO_BLUETOOTH 3
46#define NEO_STEREO_TO_SPEAKERS 4
47#define NEO_STEREO_TO_HEADPHONES 5
48#define NEO_CAPTURE_HANDSET 6
49#define NEO_CAPTURE_HEADSET 7
50#define NEO_CAPTURE_BLUETOOTH 8
51
Mark Brown87506542008-11-18 20:50:34 +000052static struct snd_soc_card neo1973;
Graeme Gregory74930bb2007-05-14 11:03:52 +020053static struct i2c_client *i2c;
54
55static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
56 struct snd_pcm_hw_params *params)
57{
58 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000059 struct snd_soc_dai *codec_dai = rtd->codec_dai;
60 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Graeme Gregory74930bb2007-05-14 11:03:52 +020061 unsigned int pll_out = 0, bclk = 0;
62 int ret = 0;
63 unsigned long iis_clkrate;
64
Mark Brownee7d4762009-03-06 18:04:34 +000065 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +020066
Graeme Gregory74930bb2007-05-14 11:03:52 +020067 iis_clkrate = s3c24xx_i2s_get_clockrate();
68
69 switch (params_rate(params)) {
70 case 8000:
71 case 16000:
72 pll_out = 12288000;
73 break;
74 case 48000:
75 bclk = WM8753_BCLK_DIV_4;
76 pll_out = 12288000;
77 break;
78 case 96000:
79 bclk = WM8753_BCLK_DIV_2;
80 pll_out = 12288000;
81 break;
82 case 11025:
83 bclk = WM8753_BCLK_DIV_16;
84 pll_out = 11289600;
85 break;
86 case 22050:
87 bclk = WM8753_BCLK_DIV_8;
88 pll_out = 11289600;
89 break;
90 case 44100:
91 bclk = WM8753_BCLK_DIV_4;
92 pll_out = 11289600;
93 break;
94 case 88200:
95 bclk = WM8753_BCLK_DIV_2;
96 pll_out = 11289600;
97 break;
98 }
99
100 /* set codec DAI configuration */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100101 ret = snd_soc_dai_set_fmt(codec_dai,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200102 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
103 SND_SOC_DAIFMT_CBM_CFM);
104 if (ret < 0)
105 return ret;
106
107 /* set cpu DAI configuration */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100108 ret = snd_soc_dai_set_fmt(cpu_dai,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200109 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
110 SND_SOC_DAIFMT_CBM_CFM);
111 if (ret < 0)
112 return ret;
113
114 /* set the codec system clock for DAC and ADC */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100115 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200116 SND_SOC_CLOCK_IN);
117 if (ret < 0)
118 return ret;
119
120 /* set MCLK division for sample rate */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100121 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200122 S3C2410_IISMOD_32FS);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200123 if (ret < 0)
124 return ret;
125
126 /* set codec BCLK division for sample rate */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100127 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200128 if (ret < 0)
129 return ret;
130
131 /* set prescaler division for sample rate */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100132 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200133 S3C24XX_PRESCALE(4, 4));
Graeme Gregory74930bb2007-05-14 11:03:52 +0200134 if (ret < 0)
135 return ret;
136
137 /* codec PLL input is PCLK/4 */
Mark Brown85488032009-09-05 18:52:16 +0100138 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200139 iis_clkrate / 4, pll_out);
140 if (ret < 0)
141 return ret;
142
143 return 0;
144}
145
146static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
147{
148 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000149 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200150
Mark Brownee7d4762009-03-06 18:04:34 +0000151 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200152
Graeme Gregory74930bb2007-05-14 11:03:52 +0200153 /* disable the PLL */
Takashi Iwai140318a2009-10-01 08:40:32 +0200154 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200155}
156
157/*
158 * Neo1973 WM8753 HiFi DAI opserations.
159 */
160static struct snd_soc_ops neo1973_hifi_ops = {
161 .hw_params = neo1973_hifi_hw_params,
162 .hw_free = neo1973_hifi_hw_free,
163};
164
165static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
166 struct snd_pcm_hw_params *params)
167{
168 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000169 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200170 unsigned int pcmdiv = 0;
171 int ret = 0;
172 unsigned long iis_clkrate;
173
Mark Brownee7d4762009-03-06 18:04:34 +0000174 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200175
Graeme Gregory74930bb2007-05-14 11:03:52 +0200176 iis_clkrate = s3c24xx_i2s_get_clockrate();
177
178 if (params_rate(params) != 8000)
179 return -EINVAL;
180 if (params_channels(params) != 1)
181 return -EINVAL;
182
183 pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */
184
185 /* todo: gg check mode (DSP_B) against CSR datasheet */
186 /* set codec DAI configuration */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100187 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B |
Graeme Gregory74930bb2007-05-14 11:03:52 +0200188 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
189 if (ret < 0)
190 return ret;
191
192 /* set the codec system clock for DAC and ADC */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100193 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK, 12288000,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200194 SND_SOC_CLOCK_IN);
195 if (ret < 0)
196 return ret;
197
198 /* set codec PCM division for sample rate */
Liam Girdwood64105cf2008-07-08 13:19:18 +0100199 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200200 if (ret < 0)
201 return ret;
202
Andrea Gelminifa2eb002010-10-16 15:19:20 +0200203 /* configure and enable PLL for 12.288MHz output */
Takashi Iwai140318a2009-10-01 08:40:32 +0200204 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200205 iis_clkrate / 4, 12288000);
206 if (ret < 0)
207 return ret;
208
209 return 0;
210}
211
212static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
213{
214 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000215 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200216
Mark Brownee7d4762009-03-06 18:04:34 +0000217 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200218
Graeme Gregory74930bb2007-05-14 11:03:52 +0200219 /* disable the PLL */
Takashi Iwai140318a2009-10-01 08:40:32 +0200220 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200221}
222
223static struct snd_soc_ops neo1973_voice_ops = {
224 .hw_params = neo1973_voice_hw_params,
225 .hw_free = neo1973_voice_hw_free,
226};
227
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200228static int neo1973_scenario;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200229
230static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
231 struct snd_ctl_elem_value *ucontrol)
232{
233 ucontrol->value.integer.value[0] = neo1973_scenario;
234 return 0;
235}
236
237static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
238{
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200239 struct snd_soc_dapm_context *dapm = &codec->dapm;
240
Mark Brownee7d4762009-03-06 18:04:34 +0000241 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200242
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200243 switch (neo1973_scenario) {
Graeme Gregory74930bb2007-05-14 11:03:52 +0200244 case NEO_AUDIO_OFF:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200245 snd_soc_dapm_disable_pin(dapm, "Audio Out");
246 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
247 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
248 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
249 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200250 break;
251 case NEO_GSM_CALL_AUDIO_HANDSET:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200252 snd_soc_dapm_enable_pin(dapm, "Audio Out");
253 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
254 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
255 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
256 snd_soc_dapm_enable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200257 break;
258 case NEO_GSM_CALL_AUDIO_HEADSET:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200259 snd_soc_dapm_enable_pin(dapm, "Audio Out");
260 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
261 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
262 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
263 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200264 break;
265 case NEO_GSM_CALL_AUDIO_BLUETOOTH:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200266 snd_soc_dapm_disable_pin(dapm, "Audio Out");
267 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
268 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
269 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
270 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200271 break;
272 case NEO_STEREO_TO_SPEAKERS:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200273 snd_soc_dapm_enable_pin(dapm, "Audio Out");
274 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
275 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
276 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
277 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200278 break;
279 case NEO_STEREO_TO_HEADPHONES:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200280 snd_soc_dapm_enable_pin(dapm, "Audio Out");
281 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
282 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
283 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
284 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200285 break;
286 case NEO_CAPTURE_HANDSET:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200287 snd_soc_dapm_disable_pin(dapm, "Audio Out");
288 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
289 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
290 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
291 snd_soc_dapm_enable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200292 break;
293 case NEO_CAPTURE_HEADSET:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200294 snd_soc_dapm_disable_pin(dapm, "Audio Out");
295 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
296 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
297 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
298 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200299 break;
300 case NEO_CAPTURE_BLUETOOTH:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200301 snd_soc_dapm_disable_pin(dapm, "Audio Out");
302 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
303 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
304 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
305 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200306 break;
307 default:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200308 snd_soc_dapm_disable_pin(dapm, "Audio Out");
309 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
310 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
311 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
312 snd_soc_dapm_disable_pin(dapm, "Call Mic");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200313 }
314
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200315 snd_soc_dapm_sync(dapm);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200316
317 return 0;
318}
319
320static int neo1973_set_scenario(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_value *ucontrol)
322{
323 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
324
Mark Brownee7d4762009-03-06 18:04:34 +0000325 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200326
Graeme Gregory74930bb2007-05-14 11:03:52 +0200327 if (neo1973_scenario == ucontrol->value.integer.value[0])
328 return 0;
329
330 neo1973_scenario = ucontrol->value.integer.value[0];
331 set_scenario_endpoints(codec, neo1973_scenario);
332 return 1;
333}
334
335static u8 lm4857_regs[4] = {0x00, 0x40, 0x80, 0xC0};
336
337static void lm4857_write_regs(void)
338{
Mark Brownee7d4762009-03-06 18:04:34 +0000339 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200340
Graeme Gregory74930bb2007-05-14 11:03:52 +0200341 if (i2c_master_send(i2c, lm4857_regs, 4) != 4)
342 printk(KERN_ERR "lm4857: i2c write failed\n");
343}
344
345static int lm4857_get_reg(struct snd_kcontrol *kcontrol,
346 struct snd_ctl_elem_value *ucontrol)
347{
Mark Brown236e6722009-06-10 13:55:34 +0100348 struct soc_mixer_control *mc =
349 (struct soc_mixer_control *)kcontrol->private_value;
350 int reg = mc->reg;
351 int shift = mc->shift;
352 int mask = mc->max;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200353
Mark Brownee7d4762009-03-06 18:04:34 +0000354 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200355
Graeme Gregory74930bb2007-05-14 11:03:52 +0200356 ucontrol->value.integer.value[0] = (lm4857_regs[reg] >> shift) & mask;
357 return 0;
358}
359
360static int lm4857_set_reg(struct snd_kcontrol *kcontrol,
361 struct snd_ctl_elem_value *ucontrol)
362{
Mark Brown236e6722009-06-10 13:55:34 +0100363 struct soc_mixer_control *mc =
364 (struct soc_mixer_control *)kcontrol->private_value;
365 int reg = mc->reg;
366 int shift = mc->shift;
367 int mask = mc->max;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200368
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200369 if (((lm4857_regs[reg] >> shift) & mask) ==
Graeme Gregory74930bb2007-05-14 11:03:52 +0200370 ucontrol->value.integer.value[0])
371 return 0;
372
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200373 lm4857_regs[reg] &= ~(mask << shift);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200374 lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift;
375 lm4857_write_regs();
376 return 1;
377}
378
379static int lm4857_get_mode(struct snd_kcontrol *kcontrol,
380 struct snd_ctl_elem_value *ucontrol)
381{
382 u8 value = lm4857_regs[LM4857_CTRL] & 0x0F;
383
Mark Brownee7d4762009-03-06 18:04:34 +0000384 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200385
Graeme Gregory74930bb2007-05-14 11:03:52 +0200386 if (value)
387 value -= 5;
388
389 ucontrol->value.integer.value[0] = value;
390 return 0;
391}
392
393static int lm4857_set_mode(struct snd_kcontrol *kcontrol,
394 struct snd_ctl_elem_value *ucontrol)
395{
396 u8 value = ucontrol->value.integer.value[0];
397
Mark Brownee7d4762009-03-06 18:04:34 +0000398 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200399
Graeme Gregory74930bb2007-05-14 11:03:52 +0200400 if (value)
401 value += 5;
402
403 if ((lm4857_regs[LM4857_CTRL] & 0x0F) == value)
404 return 0;
405
406 lm4857_regs[LM4857_CTRL] &= 0xF0;
407 lm4857_regs[LM4857_CTRL] |= value;
408 lm4857_write_regs();
409 return 1;
410}
411
412static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
413 SND_SOC_DAPM_LINE("Audio Out", NULL),
414 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
415 SND_SOC_DAPM_LINE("GSM Line In", NULL),
416 SND_SOC_DAPM_MIC("Headset Mic", NULL),
417 SND_SOC_DAPM_MIC("Call Mic", NULL),
418};
419
420
Mark Brown8f3112d2008-05-13 14:58:03 +0200421static const struct snd_soc_dapm_route dapm_routes[] = {
Graeme Gregory74930bb2007-05-14 11:03:52 +0200422
423 /* Connections to the lm4857 amp */
424 {"Audio Out", NULL, "LOUT1"},
425 {"Audio Out", NULL, "ROUT1"},
426
427 /* Connections to the GSM Module */
428 {"GSM Line Out", NULL, "MONO1"},
429 {"GSM Line Out", NULL, "MONO2"},
430 {"RXP", NULL, "GSM Line In"},
431 {"RXN", NULL, "GSM Line In"},
432
433 /* Connections to Headset */
434 {"MIC1", NULL, "Mic Bias"},
435 {"Mic Bias", NULL, "Headset Mic"},
436
437 /* Call Mic */
438 {"MIC2", NULL, "Mic Bias"},
439 {"MIC2N", NULL, "Mic Bias"},
440 {"Mic Bias", NULL, "Call Mic"},
441
442 /* Connect the ALC pins */
443 {"ACIN", NULL, "ACOP"},
Graeme Gregory74930bb2007-05-14 11:03:52 +0200444};
445
446static const char *lm4857_mode[] = {
447 "Off",
448 "Call Speaker",
449 "Stereo Speakers",
450 "Stereo Speakers + Headphones",
451 "Headphones"
452};
453
454static const struct soc_enum lm4857_mode_enum[] = {
455 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lm4857_mode), lm4857_mode),
456};
457
458static const char *neo_scenarios[] = {
459 "Off",
460 "GSM Handset",
461 "GSM Headset",
462 "GSM Bluetooth",
463 "Speakers",
464 "Headphones",
465 "Capture Handset",
466 "Capture Headset",
467 "Capture Bluetooth"
468};
469
470static const struct soc_enum neo_scenario_enum[] = {
Graeme Gregory8ba02ac2008-04-30 20:24:54 +0200471 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios), neo_scenarios),
Graeme Gregory74930bb2007-05-14 11:03:52 +0200472};
473
Mike Montoura2e31a52008-06-11 13:47:14 +0100474static const DECLARE_TLV_DB_SCALE(stereo_tlv, -4050, 150, 0);
475static const DECLARE_TLV_DB_SCALE(mono_tlv, -3450, 150, 0);
476
Graeme Gregory74930bb2007-05-14 11:03:52 +0200477static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
Mike Montoura2e31a52008-06-11 13:47:14 +0100478 SOC_SINGLE_EXT_TLV("Amp Left Playback Volume", LM4857_LVOL, 0, 31, 0,
479 lm4857_get_reg, lm4857_set_reg, stereo_tlv),
480 SOC_SINGLE_EXT_TLV("Amp Right Playback Volume", LM4857_RVOL, 0, 31, 0,
481 lm4857_get_reg, lm4857_set_reg, stereo_tlv),
482 SOC_SINGLE_EXT_TLV("Amp Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
483 lm4857_get_reg, lm4857_set_reg, mono_tlv),
Graeme Gregory74930bb2007-05-14 11:03:52 +0200484 SOC_ENUM_EXT("Amp Mode", lm4857_mode_enum[0],
485 lm4857_get_mode, lm4857_set_mode),
486 SOC_ENUM_EXT("Neo Mode", neo_scenario_enum[0],
487 neo1973_get_scenario, neo1973_set_scenario),
488 SOC_SINGLE_EXT("Amp Spk 3D Playback Switch", LM4857_LVOL, 5, 1, 0,
489 lm4857_get_reg, lm4857_set_reg),
490 SOC_SINGLE_EXT("Amp HP 3d Playback Switch", LM4857_RVOL, 5, 1, 0,
491 lm4857_get_reg, lm4857_set_reg),
492 SOC_SINGLE_EXT("Amp Fast Wakeup Playback Switch", LM4857_CTRL, 5, 1, 0,
493 lm4857_get_reg, lm4857_set_reg),
494 SOC_SINGLE_EXT("Amp Earpiece 6dB Playback Switch", LM4857_CTRL, 4, 1, 0,
495 lm4857_get_reg, lm4857_set_reg),
496};
497
498/*
499 * This is an example machine initialisation for a wm8753 connected to a
500 * neo1973 II. It is missing logic to detect hp/mic insertions and logic
501 * to re-route the audio in such an event.
502 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000503static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd)
Graeme Gregory74930bb2007-05-14 11:03:52 +0200504{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000505 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200506 struct snd_soc_dapm_context *dapm = &codec->dapm;
Philipp Zabeleb5f6d752009-03-12 11:07:54 +0100507 int err;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200508
Mark Brownee7d4762009-03-06 18:04:34 +0000509 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200510
Graeme Gregory74930bb2007-05-14 11:03:52 +0200511 /* set up NC codec pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200512 snd_soc_dapm_nc_pin(dapm, "LOUT2");
513 snd_soc_dapm_nc_pin(dapm, "ROUT2");
514 snd_soc_dapm_nc_pin(dapm, "OUT3");
515 snd_soc_dapm_nc_pin(dapm, "OUT4");
516 snd_soc_dapm_nc_pin(dapm, "LINE1");
517 snd_soc_dapm_nc_pin(dapm, "LINE2");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200518
Graeme Gregory74930bb2007-05-14 11:03:52 +0200519 /* Add neo1973 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200520 snd_soc_dapm_new_controls(dapm, wm8753_dapm_widgets,
Mark Brown8f3112d2008-05-13 14:58:03 +0200521 ARRAY_SIZE(wm8753_dapm_widgets));
Graeme Gregory74930bb2007-05-14 11:03:52 +0200522
Jonas Bonne8089942008-10-01 18:17:12 +0100523 /* set endpoints to default mode */
524 set_scenario_endpoints(codec, NEO_AUDIO_OFF);
525
Graeme Gregory74930bb2007-05-14 11:03:52 +0200526 /* add neo1973 specific controls */
Philipp Zabeleb5f6d752009-03-12 11:07:54 +0100527 err = snd_soc_add_controls(codec, wm8753_neo1973_controls,
528 ARRAY_SIZE(8753_neo1973_controls));
529 if (err < 0)
530 return err;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200531
Mark Brown8f3112d2008-05-13 14:58:03 +0200532 /* set up neo1973 specific audio routes */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200533 err = snd_soc_dapm_add_routes(dapm, dapm_routes,
Mark Brown8f3112d2008-05-13 14:58:03 +0200534 ARRAY_SIZE(dapm_routes));
Graeme Gregory74930bb2007-05-14 11:03:52 +0200535
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200536 snd_soc_dapm_sync(dapm);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200537 return 0;
538}
539
540/*
541 * BT Codec DAI
542 */
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100543static struct snd_soc_dai bt_dai = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000544 .name = "bluetooth-dai",
Graeme Gregory74930bb2007-05-14 11:03:52 +0200545 .playback = {
546 .channels_min = 1,
547 .channels_max = 1,
548 .rates = SNDRV_PCM_RATE_8000,
549 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
550 .capture = {
551 .channels_min = 1,
552 .channels_max = 1,
553 .rates = SNDRV_PCM_RATE_8000,
554 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
555};
556
557static struct snd_soc_dai_link neo1973_dai[] = {
558{ /* Hifi Playback - for similatious use with voice below */
559 .name = "WM8753",
560 .stream_name = "WM8753 HiFi",
Jassi Brar58bb4072010-11-22 15:35:50 +0900561 .platform_name = "samsung-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000562 .cpu_dai_name = "s3c24xx-i2s",
563 .codec_dai_name = "wm8753-hifi",
564 .codec_name = "wm8753-codec.0-0x1a",
Graeme Gregory74930bb2007-05-14 11:03:52 +0200565 .init = neo1973_wm8753_init,
566 .ops = &neo1973_hifi_ops,
567},
568{ /* Voice via BT */
569 .name = "Bluetooth",
570 .stream_name = "Voice",
Jassi Brar58bb4072010-11-22 15:35:50 +0900571 .platform_name = "samsung-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000572 .cpu_dai_name = "bluetooth-dai",
573 .codec_dai_name = "wm8753-voice",
574 .codec_name = "wm8753-codec.0-0x1a",
Graeme Gregory74930bb2007-05-14 11:03:52 +0200575 .ops = &neo1973_voice_ops,
576},
577};
578
Mark Brown87506542008-11-18 20:50:34 +0000579static struct snd_soc_card neo1973 = {
Graeme Gregory74930bb2007-05-14 11:03:52 +0200580 .name = "neo1973",
581 .dai_link = neo1973_dai,
582 .num_links = ARRAY_SIZE(neo1973_dai),
583};
584
Jean Delvareb6471302008-09-01 17:46:57 +0200585static int lm4857_i2c_probe(struct i2c_client *client,
586 const struct i2c_device_id *id)
Graeme Gregory74930bb2007-05-14 11:03:52 +0200587{
Mark Brownee7d4762009-03-06 18:04:34 +0000588 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200589
Jonas Bonnf9d1ab32008-10-01 21:47:19 +0200590 i2c = client;
591
Graeme Gregory74930bb2007-05-14 11:03:52 +0200592 lm4857_write_regs();
Graeme Gregory74930bb2007-05-14 11:03:52 +0200593 return 0;
594}
595
Jean Delvareb6471302008-09-01 17:46:57 +0200596static int lm4857_i2c_remove(struct i2c_client *client)
Graeme Gregory74930bb2007-05-14 11:03:52 +0200597{
Mark Brownee7d4762009-03-06 18:04:34 +0000598 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200599
Jonas Bonnf9d1ab32008-10-01 21:47:19 +0200600 i2c = NULL;
601
Jean Delvareb6471302008-09-01 17:46:57 +0200602 return 0;
Graeme Gregory74930bb2007-05-14 11:03:52 +0200603}
604
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200605static u8 lm4857_state;
606
607static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
608{
Mark Brownee7d4762009-03-06 18:04:34 +0000609 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200610
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200611 dev_dbg(&dev->dev, "lm4857_suspend\n");
612 lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf;
613 if (lm4857_state) {
614 lm4857_regs[LM4857_CTRL] &= 0xf0;
615 lm4857_write_regs();
616 }
617 return 0;
618}
619
620static int lm4857_resume(struct i2c_client *dev)
621{
Mark Brownee7d4762009-03-06 18:04:34 +0000622 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200623
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200624 if (lm4857_state) {
625 lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f);
626 lm4857_write_regs();
627 }
628 return 0;
629}
630
631static void lm4857_shutdown(struct i2c_client *dev)
632{
Mark Brownee7d4762009-03-06 18:04:34 +0000633 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200634
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200635 dev_dbg(&dev->dev, "lm4857_shutdown\n");
636 lm4857_regs[LM4857_CTRL] &= 0xf0;
637 lm4857_write_regs();
638}
639
Jean Delvareb6471302008-09-01 17:46:57 +0200640static const struct i2c_device_id lm4857_i2c_id[] = {
Mark Browndf20cf92008-09-24 11:57:27 +0100641 { "neo1973_lm4857", 0 },
Jean Delvareb6471302008-09-01 17:46:57 +0200642 { }
643};
644
Graeme Gregory74930bb2007-05-14 11:03:52 +0200645static struct i2c_driver lm4857_i2c_driver = {
646 .driver = {
647 .name = "LM4857 I2C Amp",
648 .owner = THIS_MODULE,
649 },
Graeme Gregoryfd403dc2008-04-30 20:26:45 +0200650 .suspend = lm4857_suspend,
651 .resume = lm4857_resume,
652 .shutdown = lm4857_shutdown,
Jean Delvareb6471302008-09-01 17:46:57 +0200653 .probe = lm4857_i2c_probe,
654 .remove = lm4857_i2c_remove,
655 .id_table = lm4857_i2c_id,
Graeme Gregory74930bb2007-05-14 11:03:52 +0200656};
657
658static struct platform_device *neo1973_snd_device;
659
660static int __init neo1973_init(void)
661{
662 int ret;
663
Mark Brownee7d4762009-03-06 18:04:34 +0000664 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200665
Mark Brownfb2aa072008-10-08 13:02:20 +0100666 if (!machine_is_neo1973_gta01()) {
667 printk(KERN_INFO
668 "Only GTA01 hardware supported by ASoC driver\n");
669 return -ENODEV;
670 }
671
Graeme Gregory74930bb2007-05-14 11:03:52 +0200672 neo1973_snd_device = platform_device_alloc("soc-audio", -1);
673 if (!neo1973_snd_device)
674 return -ENOMEM;
675
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000676 platform_set_drvdata(neo1973_snd_device, &neo1973);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200677 ret = platform_device_add(neo1973_snd_device);
678
Jean Delvared2802892008-09-01 17:44:05 +0200679 if (ret) {
Graeme Gregory74930bb2007-05-14 11:03:52 +0200680 platform_device_put(neo1973_snd_device);
Jean Delvared2802892008-09-01 17:44:05 +0200681 return ret;
682 }
Graeme Gregory74930bb2007-05-14 11:03:52 +0200683
Jonas Bonnf9d1ab32008-10-01 21:47:19 +0200684 ret = i2c_add_driver(&lm4857_i2c_driver);
685
Jean Delvareb6471302008-09-01 17:46:57 +0200686 if (ret != 0)
Jean Delvared2802892008-09-01 17:44:05 +0200687 platform_device_unregister(neo1973_snd_device);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200688
689 return ret;
690}
691
692static void __exit neo1973_exit(void)
693{
Mark Brownee7d4762009-03-06 18:04:34 +0000694 pr_debug("Entered %s\n", __func__);
Tim Niemeyer1894c592008-05-05 14:16:12 +0200695
Tim Niemeyer6b9a9b32008-04-22 17:10:23 +0200696 i2c_del_driver(&lm4857_i2c_driver);
Graeme Gregory74930bb2007-05-14 11:03:52 +0200697 platform_device_unregister(neo1973_snd_device);
698}
699
700module_init(neo1973_init);
701module_exit(neo1973_exit);
702
703/* Module information */
Graeme Gregory443590e2008-04-30 20:25:23 +0200704MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org");
Graeme Gregory74930bb2007-05-14 11:03:52 +0200705MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973");
706MODULE_LICENSE("GPL");