blob: 94124913bb3edd34d81d80342c2ae2fd29bdf2c1 [file] [log] [blame]
Mark Brown9e6e96a2010-01-29 17:47:12 +00001/*
2 * wm8994.c -- WM8994 ALSA SoC Audio driver
3 *
4 * Copyright 2009 Wolfson Microelectronics plc
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/pm.h>
19#include <linux/i2c.h>
20#include <linux/platform_device.h>
Mark Brown39fb51a2010-11-26 17:23:43 +000021#include <linux/pm_runtime.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000022#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000024#include <sound/core.h>
Mark Brown821edd22010-11-26 15:21:09 +000025#include <sound/jack.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000026#include <sound/pcm.h>
27#include <sound/pcm_params.h>
28#include <sound/soc.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000029#include <sound/initval.h>
30#include <sound/tlv.h>
Mark Brown2bbb5d62010-12-05 12:50:12 +000031#include <trace/events/asoc.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000032
33#include <linux/mfd/wm8994/core.h>
34#include <linux/mfd/wm8994/registers.h>
35#include <linux/mfd/wm8994/pdata.h>
36#include <linux/mfd/wm8994/gpio.h>
37
38#include "wm8994.h"
39#include "wm_hubs.h"
40
Mark Brown9e6e96a2010-01-29 17:47:12 +000041#define WM8994_NUM_DRC 3
42#define WM8994_NUM_EQ 3
43
44static int wm8994_drc_base[] = {
45 WM8994_AIF1_DRC1_1,
46 WM8994_AIF1_DRC2_1,
47 WM8994_AIF2_DRC_1,
48};
49
50static int wm8994_retune_mobile_base[] = {
51 WM8994_AIF1_DAC1_EQ_GAINS_1,
52 WM8994_AIF1_DAC2_EQ_GAINS_1,
53 WM8994_AIF2_EQ_GAINS_1,
54};
55
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +000056static int wm8994_readable(struct snd_soc_codec *codec, unsigned int reg)
Mark Brown9e6e96a2010-01-29 17:47:12 +000057{
Mark Brownaf9af862011-03-16 21:05:06 +000058 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
59 struct wm8994 *control = wm8994->control_data;
60
Mark Browne88ff1e2010-07-09 00:12:08 +090061 switch (reg) {
62 case WM8994_GPIO_1:
63 case WM8994_GPIO_2:
64 case WM8994_GPIO_3:
65 case WM8994_GPIO_4:
66 case WM8994_GPIO_5:
67 case WM8994_GPIO_6:
68 case WM8994_GPIO_7:
69 case WM8994_GPIO_8:
70 case WM8994_GPIO_9:
71 case WM8994_GPIO_10:
72 case WM8994_GPIO_11:
73 case WM8994_INTERRUPT_STATUS_1:
74 case WM8994_INTERRUPT_STATUS_2:
75 case WM8994_INTERRUPT_RAW_STATUS_2:
76 return 1;
Mark Brownaf9af862011-03-16 21:05:06 +000077
78 case WM8958_DSP2_PROGRAM:
79 case WM8958_DSP2_CONFIG:
80 case WM8958_DSP2_EXECCONTROL:
81 if (control->type == WM8958)
82 return 1;
83 else
84 return 0;
85
Mark Browne88ff1e2010-07-09 00:12:08 +090086 default:
87 break;
88 }
89
Mark Brown7b306da2010-11-16 20:11:40 +000090 if (reg >= WM8994_CACHE_SIZE)
Mark Brown9e6e96a2010-01-29 17:47:12 +000091 return 0;
Mark Brown7b306da2010-11-16 20:11:40 +000092 return wm8994_access_masks[reg].readable != 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +000093}
94
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +000095static int wm8994_volatile(struct snd_soc_codec *codec, unsigned int reg)
Mark Brown9e6e96a2010-01-29 17:47:12 +000096{
Mark Brownca9aef52010-11-26 17:23:41 +000097 if (reg >= WM8994_CACHE_SIZE)
Mark Brown9e6e96a2010-01-29 17:47:12 +000098 return 1;
99
100 switch (reg) {
101 case WM8994_SOFTWARE_RESET:
102 case WM8994_CHIP_REVISION:
103 case WM8994_DC_SERVO_1:
104 case WM8994_DC_SERVO_READBACK:
105 case WM8994_RATE_STATUS:
106 case WM8994_LDO_1:
107 case WM8994_LDO_2:
Mark Brownd6addcc2010-11-26 15:21:08 +0000108 case WM8958_DSP2_EXECCONTROL:
Mark Brown821edd22010-11-26 15:21:09 +0000109 case WM8958_MIC_DETECT_3:
Mark Brown79ef0ab2011-08-01 13:02:17 +0900110 case WM8994_DC_SERVO_4E:
Mark Brown9e6e96a2010-01-29 17:47:12 +0000111 return 1;
112 default:
113 return 0;
114 }
115}
116
117static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg,
118 unsigned int value)
119{
Mark Brownca9aef52010-11-26 17:23:41 +0000120 int ret;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000121
122 BUG_ON(reg > WM8994_MAX_REGISTER);
123
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +0000124 if (!wm8994_volatile(codec, reg)) {
Mark Brownca9aef52010-11-26 17:23:41 +0000125 ret = snd_soc_cache_write(codec, reg, value);
126 if (ret != 0)
127 dev_err(codec->dev, "Cache write to %x failed: %d\n",
128 reg, ret);
129 }
Mark Brown9e6e96a2010-01-29 17:47:12 +0000130
131 return wm8994_reg_write(codec->control_data, reg, value);
132}
133
134static unsigned int wm8994_read(struct snd_soc_codec *codec,
135 unsigned int reg)
136{
Mark Brownca9aef52010-11-26 17:23:41 +0000137 unsigned int val;
138 int ret;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000139
140 BUG_ON(reg > WM8994_MAX_REGISTER);
141
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +0000142 if (!wm8994_volatile(codec, reg) && wm8994_readable(codec, reg) &&
Mark Brownca9aef52010-11-26 17:23:41 +0000143 reg < codec->driver->reg_cache_size) {
144 ret = snd_soc_cache_read(codec, reg, &val);
145 if (ret >= 0)
146 return val;
147 else
148 dev_err(codec->dev, "Cache read from %x failed: %d\n",
149 reg, ret);
150 }
151
152 return wm8994_reg_read(codec->control_data, reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000153}
154
155static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
156{
Mark Brownb2c812e2010-04-14 15:35:19 +0900157 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000158 int rate;
159 int reg1 = 0;
160 int offset;
161
162 if (aif)
163 offset = 4;
164 else
165 offset = 0;
166
167 switch (wm8994->sysclk[aif]) {
168 case WM8994_SYSCLK_MCLK1:
169 rate = wm8994->mclk[0];
170 break;
171
172 case WM8994_SYSCLK_MCLK2:
173 reg1 |= 0x8;
174 rate = wm8994->mclk[1];
175 break;
176
177 case WM8994_SYSCLK_FLL1:
178 reg1 |= 0x10;
179 rate = wm8994->fll[0].out;
180 break;
181
182 case WM8994_SYSCLK_FLL2:
183 reg1 |= 0x18;
184 rate = wm8994->fll[1].out;
185 break;
186
187 default:
188 return -EINVAL;
189 }
190
191 if (rate >= 13500000) {
192 rate /= 2;
193 reg1 |= WM8994_AIF1CLK_DIV;
194
195 dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
196 aif + 1, rate);
197 }
Mark Brown5e5e2be2010-04-25 12:20:30 +0100198
Mark Brown9e6e96a2010-01-29 17:47:12 +0000199 wm8994->aifclk[aif] = rate;
200
201 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset,
202 WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
203 reg1);
204
205 return 0;
206}
207
208static int configure_clock(struct snd_soc_codec *codec)
209{
Mark Brownb2c812e2010-04-14 15:35:19 +0900210 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000211 int old, new;
212
213 /* Bring up the AIF clocks first */
214 configure_aif_clock(codec, 0);
215 configure_aif_clock(codec, 1);
216
217 /* Then switch CLK_SYS over to the higher of them; a change
218 * can only happen as a result of a clocking change which can
219 * only be made outside of DAPM so we can safely redo the
220 * clocking.
221 */
222
223 /* If they're equal it doesn't matter which is used */
224 if (wm8994->aifclk[0] == wm8994->aifclk[1])
225 return 0;
226
227 if (wm8994->aifclk[0] < wm8994->aifclk[1])
228 new = WM8994_SYSCLK_SRC;
229 else
230 new = 0;
231
232 old = snd_soc_read(codec, WM8994_CLOCKING_1) & WM8994_SYSCLK_SRC;
233
234 /* If there's no change then we're done. */
235 if (old == new)
236 return 0;
237
238 snd_soc_update_bits(codec, WM8994_CLOCKING_1, WM8994_SYSCLK_SRC, new);
239
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200240 snd_soc_dapm_sync(&codec->dapm);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000241
242 return 0;
243}
244
245static int check_clk_sys(struct snd_soc_dapm_widget *source,
246 struct snd_soc_dapm_widget *sink)
247{
248 int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1);
249 const char *clk;
250
251 /* Check what we're currently using for CLK_SYS */
252 if (reg & WM8994_SYSCLK_SRC)
253 clk = "AIF2CLK";
254 else
255 clk = "AIF1CLK";
256
257 return strcmp(source->name, clk) == 0;
258}
259
260static const char *sidetone_hpf_text[] = {
261 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
262};
263
264static const struct soc_enum sidetone_hpf =
265 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
266
Uk Kim146fd572010-12-07 13:58:40 +0000267static const char *adc_hpf_text[] = {
268 "HiFi", "Voice 1", "Voice 2", "Voice 3"
269};
270
271static const struct soc_enum aif1adc1_hpf =
272 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text);
273
274static const struct soc_enum aif1adc2_hpf =
275 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text);
276
277static const struct soc_enum aif2adc_hpf =
278 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text);
279
Mark Brown9e6e96a2010-01-29 17:47:12 +0000280static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
281static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
282static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
283static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
284static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
Mark Brown1ddc07d2011-08-16 10:08:48 +0900285static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000286
287#define WM8994_DRC_SWITCH(xname, reg, shift) \
288{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
289 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
290 .put = wm8994_put_drc_sw, \
291 .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
292
293static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
294 struct snd_ctl_elem_value *ucontrol)
295{
296 struct soc_mixer_control *mc =
297 (struct soc_mixer_control *)kcontrol->private_value;
298 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
299 int mask, ret;
300
301 /* Can't enable both ADC and DAC paths simultaneously */
302 if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
303 mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
304 WM8994_AIF1ADC1R_DRC_ENA_MASK;
305 else
306 mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
307
308 ret = snd_soc_read(codec, mc->reg);
309 if (ret < 0)
310 return ret;
311 if (ret & mask)
312 return -EINVAL;
313
314 return snd_soc_put_volsw(kcontrol, ucontrol);
315}
316
Mark Brown9e6e96a2010-01-29 17:47:12 +0000317static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
318{
Mark Brownb2c812e2010-04-14 15:35:19 +0900319 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000320 struct wm8994_pdata *pdata = wm8994->pdata;
321 int base = wm8994_drc_base[drc];
322 int cfg = wm8994->drc_cfg[drc];
323 int save, i;
324
325 /* Save any enables; the configuration should clear them. */
326 save = snd_soc_read(codec, base);
327 save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
328 WM8994_AIF1ADC1R_DRC_ENA;
329
330 for (i = 0; i < WM8994_DRC_REGS; i++)
331 snd_soc_update_bits(codec, base + i, 0xffff,
332 pdata->drc_cfgs[cfg].regs[i]);
333
334 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
335 WM8994_AIF1ADC1L_DRC_ENA |
336 WM8994_AIF1ADC1R_DRC_ENA, save);
337}
338
339/* Icky as hell but saves code duplication */
340static int wm8994_get_drc(const char *name)
341{
342 if (strcmp(name, "AIF1DRC1 Mode") == 0)
343 return 0;
344 if (strcmp(name, "AIF1DRC2 Mode") == 0)
345 return 1;
346 if (strcmp(name, "AIF2DRC Mode") == 0)
347 return 2;
348 return -EINVAL;
349}
350
351static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
352 struct snd_ctl_elem_value *ucontrol)
353{
354 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000355 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000356 struct wm8994_pdata *pdata = wm8994->pdata;
357 int drc = wm8994_get_drc(kcontrol->id.name);
358 int value = ucontrol->value.integer.value[0];
359
360 if (drc < 0)
361 return drc;
362
363 if (value >= pdata->num_drc_cfgs)
364 return -EINVAL;
365
366 wm8994->drc_cfg[drc] = value;
367
368 wm8994_set_drc(codec, drc);
369
370 return 0;
371}
372
373static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
375{
376 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900377 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000378 int drc = wm8994_get_drc(kcontrol->id.name);
379
380 ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
381
382 return 0;
383}
384
385static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
386{
Mark Brownb2c812e2010-04-14 15:35:19 +0900387 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000388 struct wm8994_pdata *pdata = wm8994->pdata;
389 int base = wm8994_retune_mobile_base[block];
390 int iface, best, best_val, save, i, cfg;
391
392 if (!pdata || !wm8994->num_retune_mobile_texts)
393 return;
394
395 switch (block) {
396 case 0:
397 case 1:
398 iface = 0;
399 break;
400 case 2:
401 iface = 1;
402 break;
403 default:
404 return;
405 }
406
407 /* Find the version of the currently selected configuration
408 * with the nearest sample rate. */
409 cfg = wm8994->retune_mobile_cfg[block];
410 best = 0;
411 best_val = INT_MAX;
412 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
413 if (strcmp(pdata->retune_mobile_cfgs[i].name,
414 wm8994->retune_mobile_texts[cfg]) == 0 &&
415 abs(pdata->retune_mobile_cfgs[i].rate
416 - wm8994->dac_rates[iface]) < best_val) {
417 best = i;
418 best_val = abs(pdata->retune_mobile_cfgs[i].rate
419 - wm8994->dac_rates[iface]);
420 }
421 }
422
423 dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
424 block,
425 pdata->retune_mobile_cfgs[best].name,
426 pdata->retune_mobile_cfgs[best].rate,
427 wm8994->dac_rates[iface]);
428
429 /* The EQ will be disabled while reconfiguring it, remember the
430 * current configuration.
431 */
432 save = snd_soc_read(codec, base);
433 save &= WM8994_AIF1DAC1_EQ_ENA;
434
435 for (i = 0; i < WM8994_EQ_REGS; i++)
436 snd_soc_update_bits(codec, base + i, 0xffff,
437 pdata->retune_mobile_cfgs[best].regs[i]);
438
439 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
440}
441
442/* Icky as hell but saves code duplication */
443static int wm8994_get_retune_mobile_block(const char *name)
444{
445 if (strcmp(name, "AIF1.1 EQ Mode") == 0)
446 return 0;
447 if (strcmp(name, "AIF1.2 EQ Mode") == 0)
448 return 1;
449 if (strcmp(name, "AIF2 EQ Mode") == 0)
450 return 2;
451 return -EINVAL;
452}
453
454static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
455 struct snd_ctl_elem_value *ucontrol)
456{
457 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000458 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000459 struct wm8994_pdata *pdata = wm8994->pdata;
460 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
461 int value = ucontrol->value.integer.value[0];
462
463 if (block < 0)
464 return block;
465
466 if (value >= pdata->num_retune_mobile_cfgs)
467 return -EINVAL;
468
469 wm8994->retune_mobile_cfg[block] = value;
470
471 wm8994_set_retune_mobile(codec, block);
472
473 return 0;
474}
475
476static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
477 struct snd_ctl_elem_value *ucontrol)
478{
479 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brown4a8d9292011-02-16 14:57:17 -0800480 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000481 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
482
483 ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
484
485 return 0;
486}
487
Mark Brown96b101e2010-11-18 15:49:38 +0000488static const char *aif_chan_src_text[] = {
Mark Brownf5548852010-08-31 19:39:48 +0100489 "Left", "Right"
490};
491
Mark Brown96b101e2010-11-18 15:49:38 +0000492static const struct soc_enum aif1adcl_src =
493 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
494
495static const struct soc_enum aif1adcr_src =
496 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
497
498static const struct soc_enum aif2adcl_src =
499 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
500
501static const struct soc_enum aif2adcr_src =
502 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
503
Mark Brownf5548852010-08-31 19:39:48 +0100504static const struct soc_enum aif1dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000505 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100506
507static const struct soc_enum aif1dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000508 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100509
510static const struct soc_enum aif2dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000511 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100512
513static const struct soc_enum aif2dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000514 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100515
Mark Brown154b26a2010-12-09 12:07:44 +0000516static const char *osr_text[] = {
517 "Low Power", "High Performance",
518};
519
520static const struct soc_enum dac_osr =
521 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
522
523static const struct soc_enum adc_osr =
524 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
525
Mark Brown9e6e96a2010-01-29 17:47:12 +0000526static const struct snd_kcontrol_new wm8994_snd_controls[] = {
527SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
528 WM8994_AIF1_ADC1_RIGHT_VOLUME,
529 1, 119, 0, digital_tlv),
530SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
531 WM8994_AIF1_ADC2_RIGHT_VOLUME,
532 1, 119, 0, digital_tlv),
533SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
534 WM8994_AIF2_ADC_RIGHT_VOLUME,
535 1, 119, 0, digital_tlv),
536
Mark Brown96b101e2010-11-18 15:49:38 +0000537SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
538SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000539SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
540SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
Mark Brown96b101e2010-11-18 15:49:38 +0000541
Mark Brownf5548852010-08-31 19:39:48 +0100542SOC_ENUM("AIF1DACL Source", aif1dacl_src),
543SOC_ENUM("AIF1DACR Source", aif1dacr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000544SOC_ENUM("AIF2DACL Source", aif2dacl_src),
545SOC_ENUM("AIF2DACR Source", aif2dacr_src),
Mark Brownf5548852010-08-31 19:39:48 +0100546
Mark Brown9e6e96a2010-01-29 17:47:12 +0000547SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
548 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
549SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
550 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
551SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
552 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
553
554SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
555SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
556
557SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
558SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
559SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
560
561WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
562WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
563WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
564
565WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
566WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
567WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
568
569WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
570WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
571WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
572
573SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
574 5, 12, 0, st_tlv),
575SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
576 0, 12, 0, st_tlv),
577SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
578 5, 12, 0, st_tlv),
579SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
580 0, 12, 0, st_tlv),
581SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
582SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
583
Uk Kim146fd572010-12-07 13:58:40 +0000584SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
585SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
586
587SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
588SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
589
590SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
591SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
592
Mark Brown154b26a2010-12-09 12:07:44 +0000593SOC_ENUM("ADC OSR", adc_osr),
594SOC_ENUM("DAC OSR", dac_osr),
595
Mark Brown9e6e96a2010-01-29 17:47:12 +0000596SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
597 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
598SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
599 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
600
601SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
602 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
603SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
604 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
605
606SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
607 6, 1, 1, wm_hubs_spkmix_tlv),
608SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
609 2, 1, 1, wm_hubs_spkmix_tlv),
610
611SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
612 6, 1, 1, wm_hubs_spkmix_tlv),
613SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
614 2, 1, 1, wm_hubs_spkmix_tlv),
615
616SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
617 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000618SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000619 8, 1, 0),
620SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
621 10, 15, 0, wm8994_3d_tlv),
622SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
623 8, 1, 0),
Mark Brown458350b2010-12-20 14:35:09 +0000624SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000625 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000626SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000627 8, 1, 0),
628};
629
630static const struct snd_kcontrol_new wm8994_eq_controls[] = {
631SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
632 eq_tlv),
633SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
634 eq_tlv),
635SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
636 eq_tlv),
637SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
638 eq_tlv),
639SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
640 eq_tlv),
641
642SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
643 eq_tlv),
644SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
645 eq_tlv),
646SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
647 eq_tlv),
648SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
649 eq_tlv),
650SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
651 eq_tlv),
652
653SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
654 eq_tlv),
655SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
656 eq_tlv),
657SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
658 eq_tlv),
659SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
660 eq_tlv),
661SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
662 eq_tlv),
663};
664
Mark Brown1ddc07d2011-08-16 10:08:48 +0900665static const char *wm8958_ng_text[] = {
666 "30ms", "125ms", "250ms", "500ms",
667};
668
669static const struct soc_enum wm8958_aif1dac1_ng_hold =
670 SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE,
671 WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text);
672
673static const struct soc_enum wm8958_aif1dac2_ng_hold =
674 SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE,
675 WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text);
676
677static const struct soc_enum wm8958_aif2dac_ng_hold =
678 SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE,
679 WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text);
680
Mark Brownc4431df2010-11-26 15:21:07 +0000681static const struct snd_kcontrol_new wm8958_snd_controls[] = {
682SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
Mark Brown1ddc07d2011-08-16 10:08:48 +0900683
684SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
685 WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
686SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
687SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
688 WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
689 7, 1, ng_tlv),
690
691SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
692 WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
693SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
694SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
695 WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
696 7, 1, ng_tlv),
697
698SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
699 WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
700SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
701SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
702 WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
703 7, 1, ng_tlv),
Mark Brownc4431df2010-11-26 15:21:07 +0000704};
705
Mark Brown9e6e96a2010-01-29 17:47:12 +0000706static int clk_sys_event(struct snd_soc_dapm_widget *w,
707 struct snd_kcontrol *kcontrol, int event)
708{
709 struct snd_soc_codec *codec = w->codec;
710
711 switch (event) {
712 case SND_SOC_DAPM_PRE_PMU:
713 return configure_clock(codec);
714
715 case SND_SOC_DAPM_POST_PMD:
716 configure_clock(codec);
717 break;
718 }
719
720 return 0;
721}
722
Mark Brown4b7ed832011-08-10 17:47:33 +0900723static void vmid_reference(struct snd_soc_codec *codec)
724{
725 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
726
727 wm8994->vmid_refcount++;
728
729 dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
730 wm8994->vmid_refcount);
731
732 if (wm8994->vmid_refcount == 1) {
733 /* Startup bias, VMID ramp & buffer */
734 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
735 WM8994_STARTUP_BIAS_ENA |
736 WM8994_VMID_BUF_ENA |
737 WM8994_VMID_RAMP_MASK,
738 WM8994_STARTUP_BIAS_ENA |
739 WM8994_VMID_BUF_ENA |
740 (0x11 << WM8994_VMID_RAMP_SHIFT));
741
742 /* Main bias enable, VMID=2x40k */
743 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
744 WM8994_BIAS_ENA |
745 WM8994_VMID_SEL_MASK,
746 WM8994_BIAS_ENA | 0x2);
747
748 msleep(20);
749 }
750}
751
752static void vmid_dereference(struct snd_soc_codec *codec)
753{
754 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
755
756 wm8994->vmid_refcount--;
757
758 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
759 wm8994->vmid_refcount);
760
761 if (wm8994->vmid_refcount == 0) {
762 /* Switch over to startup biases */
763 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
764 WM8994_BIAS_SRC |
765 WM8994_STARTUP_BIAS_ENA |
766 WM8994_VMID_BUF_ENA |
767 WM8994_VMID_RAMP_MASK,
768 WM8994_BIAS_SRC |
769 WM8994_STARTUP_BIAS_ENA |
770 WM8994_VMID_BUF_ENA |
771 (1 << WM8994_VMID_RAMP_SHIFT));
772
773 /* Disable main biases */
774 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
775 WM8994_BIAS_ENA |
776 WM8994_VMID_SEL_MASK, 0);
777
778 /* Discharge line */
779 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
780 WM8994_LINEOUT1_DISCH |
781 WM8994_LINEOUT2_DISCH,
782 WM8994_LINEOUT1_DISCH |
783 WM8994_LINEOUT2_DISCH);
784
785 msleep(5);
786
787 /* Switch off startup biases */
788 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
789 WM8994_BIAS_SRC |
790 WM8994_STARTUP_BIAS_ENA |
791 WM8994_VMID_BUF_ENA |
792 WM8994_VMID_RAMP_MASK, 0);
793 }
794}
795
796static int vmid_event(struct snd_soc_dapm_widget *w,
797 struct snd_kcontrol *kcontrol, int event)
798{
799 struct snd_soc_codec *codec = w->codec;
800
801 switch (event) {
802 case SND_SOC_DAPM_PRE_PMU:
803 vmid_reference(codec);
804 break;
805
806 case SND_SOC_DAPM_POST_PMD:
807 vmid_dereference(codec);
808 break;
809 }
810
811 return 0;
812}
813
Mark Brown9e6e96a2010-01-29 17:47:12 +0000814static void wm8994_update_class_w(struct snd_soc_codec *codec)
815{
Mark Brownfec6dd82010-10-27 13:48:36 -0700816 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000817 int enable = 1;
818 int source = 0; /* GCC flow analysis can't track enable */
819 int reg, reg_r;
820
821 /* Only support direct DAC->headphone paths */
822 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
823 if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
Mark Brownee839a22010-04-20 13:57:08 +0900824 dev_vdbg(codec->dev, "HPL connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000825 enable = 0;
826 }
827
828 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
829 if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
Mark Brownee839a22010-04-20 13:57:08 +0900830 dev_vdbg(codec->dev, "HPR connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000831 enable = 0;
832 }
833
834 /* We also need the same setting for L/R and only one path */
835 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
836 switch (reg) {
837 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900838 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000839 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
840 break;
841 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900842 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000843 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
844 break;
845 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900846 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000847 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
848 break;
849 default:
Mark Brownee839a22010-04-20 13:57:08 +0900850 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000851 enable = 0;
852 break;
853 }
854
855 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
856 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +0900857 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000858 enable = 0;
859 }
860
861 if (enable) {
862 dev_dbg(codec->dev, "Class W enabled\n");
863 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
864 WM8994_CP_DYN_PWR |
865 WM8994_CP_DYN_SRC_SEL_MASK,
866 source | WM8994_CP_DYN_PWR);
Mark Brownfec6dd82010-10-27 13:48:36 -0700867 wm8994->hubs.class_w = true;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000868
869 } else {
870 dev_dbg(codec->dev, "Class W disabled\n");
871 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
872 WM8994_CP_DYN_PWR, 0);
Mark Brownfec6dd82010-10-27 13:48:36 -0700873 wm8994->hubs.class_w = false;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000874 }
875}
876
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000877static int late_enable_ev(struct snd_soc_dapm_widget *w,
878 struct snd_kcontrol *kcontrol, int event)
879{
880 struct snd_soc_codec *codec = w->codec;
881 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
882
883 switch (event) {
884 case SND_SOC_DAPM_PRE_PMU:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000885 if (wm8994->aif1clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000886 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
887 WM8994_AIF1CLK_ENA_MASK,
888 WM8994_AIF1CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000889 wm8994->aif1clk_enable = 0;
890 }
891 if (wm8994->aif2clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000892 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
893 WM8994_AIF2CLK_ENA_MASK,
894 WM8994_AIF2CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000895 wm8994->aif2clk_enable = 0;
896 }
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000897 break;
898 }
899
Mark Brownc6b7b572011-03-11 18:13:12 +0000900 /* We may also have postponed startup of DSP, handle that. */
901 wm8958_aif_ev(w, kcontrol, event);
902
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000903 return 0;
904}
905
906static int late_disable_ev(struct snd_soc_dapm_widget *w,
907 struct snd_kcontrol *kcontrol, int event)
908{
909 struct snd_soc_codec *codec = w->codec;
910 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
911
912 switch (event) {
913 case SND_SOC_DAPM_POST_PMD:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000914 if (wm8994->aif1clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000915 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
916 WM8994_AIF1CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000917 wm8994->aif1clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000918 }
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000919 if (wm8994->aif2clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000920 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
921 WM8994_AIF2CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000922 wm8994->aif2clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000923 }
924 break;
925 }
926
927 return 0;
928}
929
930static int aif1clk_ev(struct snd_soc_dapm_widget *w,
931 struct snd_kcontrol *kcontrol, int event)
932{
933 struct snd_soc_codec *codec = w->codec;
934 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
935
936 switch (event) {
937 case SND_SOC_DAPM_PRE_PMU:
938 wm8994->aif1clk_enable = 1;
939 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000940 case SND_SOC_DAPM_POST_PMD:
941 wm8994->aif1clk_disable = 1;
942 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000943 }
944
945 return 0;
946}
947
948static int aif2clk_ev(struct snd_soc_dapm_widget *w,
949 struct snd_kcontrol *kcontrol, int event)
950{
951 struct snd_soc_codec *codec = w->codec;
952 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
953
954 switch (event) {
955 case SND_SOC_DAPM_PRE_PMU:
956 wm8994->aif2clk_enable = 1;
957 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000958 case SND_SOC_DAPM_POST_PMD:
959 wm8994->aif2clk_disable = 1;
960 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000961 }
962
963 return 0;
964}
965
Dimitris Papastamos04d28682011-03-01 11:47:10 +0000966static int adc_mux_ev(struct snd_soc_dapm_widget *w,
967 struct snd_kcontrol *kcontrol, int event)
968{
969 late_enable_ev(w, kcontrol, event);
970 return 0;
971}
972
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +0000973static int micbias_ev(struct snd_soc_dapm_widget *w,
974 struct snd_kcontrol *kcontrol, int event)
975{
976 late_enable_ev(w, kcontrol, event);
977 return 0;
978}
979
Dimitris Papastamosc52fd022011-02-11 16:32:12 +0000980static int dac_ev(struct snd_soc_dapm_widget *w,
981 struct snd_kcontrol *kcontrol, int event)
982{
983 struct snd_soc_codec *codec = w->codec;
984 unsigned int mask = 1 << w->shift;
985
986 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
987 mask, mask);
988 return 0;
989}
990
Mark Brown9e6e96a2010-01-29 17:47:12 +0000991static const char *hp_mux_text[] = {
992 "Mixer",
993 "DAC",
994};
995
996#define WM8994_HP_ENUM(xname, xenum) \
997{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
998 .info = snd_soc_info_enum_double, \
999 .get = snd_soc_dapm_get_enum_double, \
1000 .put = wm8994_put_hp_enum, \
1001 .private_value = (unsigned long)&xenum }
1002
1003static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
1004 struct snd_ctl_elem_value *ucontrol)
1005{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001006 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1007 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001008 struct snd_soc_codec *codec = w->codec;
1009 int ret;
1010
1011 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1012
1013 wm8994_update_class_w(codec);
1014
1015 return ret;
1016}
1017
1018static const struct soc_enum hpl_enum =
1019 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
1020
1021static const struct snd_kcontrol_new hpl_mux =
1022 WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
1023
1024static const struct soc_enum hpr_enum =
1025 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
1026
1027static const struct snd_kcontrol_new hpr_mux =
1028 WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
1029
1030static const char *adc_mux_text[] = {
1031 "ADC",
1032 "DMIC",
1033};
1034
1035static const struct soc_enum adc_enum =
1036 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1037
1038static const struct snd_kcontrol_new adcl_mux =
1039 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1040
1041static const struct snd_kcontrol_new adcr_mux =
1042 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1043
1044static const struct snd_kcontrol_new left_speaker_mixer[] = {
1045SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1046SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1047SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1048SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1049SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1050};
1051
1052static const struct snd_kcontrol_new right_speaker_mixer[] = {
1053SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1054SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1055SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1056SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1057SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1058};
1059
1060/* Debugging; dump chip status after DAPM transitions */
1061static int post_ev(struct snd_soc_dapm_widget *w,
1062 struct snd_kcontrol *kcontrol, int event)
1063{
1064 struct snd_soc_codec *codec = w->codec;
1065 dev_dbg(codec->dev, "SRC status: %x\n",
1066 snd_soc_read(codec,
1067 WM8994_RATE_STATUS));
1068 return 0;
1069}
1070
1071static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1072SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1073 1, 1, 0),
1074SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1075 0, 1, 0),
1076};
1077
1078static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1079SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1080 1, 1, 0),
1081SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1082 0, 1, 0),
1083};
1084
Mark Browna3257ba2010-07-19 14:02:34 +01001085static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1086SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1087 1, 1, 0),
1088SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1089 0, 1, 0),
1090};
1091
1092static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1093SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1094 1, 1, 0),
1095SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1096 0, 1, 0),
1097};
1098
Mark Brown9e6e96a2010-01-29 17:47:12 +00001099static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1100SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1101 5, 1, 0),
1102SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1103 4, 1, 0),
1104SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1105 2, 1, 0),
1106SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1107 1, 1, 0),
1108SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1109 0, 1, 0),
1110};
1111
1112static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1113SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1114 5, 1, 0),
1115SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1116 4, 1, 0),
1117SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1118 2, 1, 0),
1119SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1120 1, 1, 0),
1121SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1122 0, 1, 0),
1123};
1124
1125#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1126{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1127 .info = snd_soc_info_volsw, \
1128 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1129 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1130
1131static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1132 struct snd_ctl_elem_value *ucontrol)
1133{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001134 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1135 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001136 struct snd_soc_codec *codec = w->codec;
1137 int ret;
1138
1139 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1140
1141 wm8994_update_class_w(codec);
1142
1143 return ret;
1144}
1145
1146static const struct snd_kcontrol_new dac1l_mix[] = {
1147WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1148 5, 1, 0),
1149WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1150 4, 1, 0),
1151WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1152 2, 1, 0),
1153WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1154 1, 1, 0),
1155WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1156 0, 1, 0),
1157};
1158
1159static const struct snd_kcontrol_new dac1r_mix[] = {
1160WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1161 5, 1, 0),
1162WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1163 4, 1, 0),
1164WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1165 2, 1, 0),
1166WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1167 1, 1, 0),
1168WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1169 0, 1, 0),
1170};
1171
1172static const char *sidetone_text[] = {
1173 "ADC/DMIC1", "DMIC2",
1174};
1175
1176static const struct soc_enum sidetone1_enum =
1177 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1178
1179static const struct snd_kcontrol_new sidetone1_mux =
1180 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1181
1182static const struct soc_enum sidetone2_enum =
1183 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1184
1185static const struct snd_kcontrol_new sidetone2_mux =
1186 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1187
1188static const char *aif1dac_text[] = {
1189 "AIF1DACDAT", "AIF3DACDAT",
1190};
1191
1192static const struct soc_enum aif1dac_enum =
1193 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1194
1195static const struct snd_kcontrol_new aif1dac_mux =
1196 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1197
1198static const char *aif2dac_text[] = {
1199 "AIF2DACDAT", "AIF3DACDAT",
1200};
1201
1202static const struct soc_enum aif2dac_enum =
1203 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1204
1205static const struct snd_kcontrol_new aif2dac_mux =
1206 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1207
1208static const char *aif2adc_text[] = {
1209 "AIF2ADCDAT", "AIF3DACDAT",
1210};
1211
1212static const struct soc_enum aif2adc_enum =
1213 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1214
1215static const struct snd_kcontrol_new aif2adc_mux =
1216 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1217
1218static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001219 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001220};
1221
Mark Brownc4431df2010-11-26 15:21:07 +00001222static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001223 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1224
Mark Brownc4431df2010-11-26 15:21:07 +00001225static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1226 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1227
1228static const struct soc_enum wm8958_aif3adc_enum =
1229 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1230
1231static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1232 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1233
1234static const char *mono_pcm_out_text[] = {
1235 "None", "AIF2ADCL", "AIF2ADCR",
1236};
1237
1238static const struct soc_enum mono_pcm_out_enum =
1239 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1240
1241static const struct snd_kcontrol_new mono_pcm_out_mux =
1242 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1243
1244static const char *aif2dac_src_text[] = {
1245 "AIF2", "AIF3",
1246};
1247
1248/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1249static const struct soc_enum aif2dacl_src_enum =
1250 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1251
1252static const struct snd_kcontrol_new aif2dacl_src_mux =
1253 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1254
1255static const struct soc_enum aif2dacr_src_enum =
1256 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1257
1258static const struct snd_kcontrol_new aif2dacr_src_mux =
1259 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001260
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001261static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1262SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_ev,
1263 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1264SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_ev,
1265 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1266
1267SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1268 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1269SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1270 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1271SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1272 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1273SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1274 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownb70a51b2011-06-29 00:21:09 -07001275SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1276 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1277
1278SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1279 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1280 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1281SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1282 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1283 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1284SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux,
1285 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1286SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux,
1287 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001288
1289SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1290};
1291
1292static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1293SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0),
Mark Brownb70a51b2011-06-29 00:21:09 -07001294SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0),
1295SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1296SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1297 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1298SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1299 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1300SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
1301SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001302};
1303
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001304static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1305SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1306 dac_ev, SND_SOC_DAPM_PRE_PMU),
1307SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1308 dac_ev, SND_SOC_DAPM_PRE_PMU),
1309SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1310 dac_ev, SND_SOC_DAPM_PRE_PMU),
1311SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1312 dac_ev, SND_SOC_DAPM_PRE_PMU),
1313};
1314
1315static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1316SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
Mark Brown0627bd22011-03-09 19:09:17 +00001317SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001318SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1319SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1320};
1321
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001322static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
1323SND_SOC_DAPM_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1324 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1325SND_SOC_DAPM_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1326 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1327};
1328
1329static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
1330SND_SOC_DAPM_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1331SND_SOC_DAPM_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
1332};
1333
Mark Brown9e6e96a2010-01-29 17:47:12 +00001334static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1335SND_SOC_DAPM_INPUT("DMIC1DAT"),
1336SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001337SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001338
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001339SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1340 SND_SOC_DAPM_PRE_PMU),
Mark Brown4b7ed832011-08-10 17:47:33 +09001341SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1342 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001343
Mark Brown9e6e96a2010-01-29 17:47:12 +00001344SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1345 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1346
1347SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0),
1348SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0),
1349SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0),
1350
Mark Brown7f94de42011-02-03 16:27:34 +00001351SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001352 0, WM8994_POWER_MANAGEMENT_4, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001353SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001354 0, WM8994_POWER_MANAGEMENT_4, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001355SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1356 WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001357 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001358SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1359 WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001360 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001361
Mark Brown7f94de42011-02-03 16:27:34 +00001362SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001363 0, WM8994_POWER_MANAGEMENT_4, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001364SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001365 0, WM8994_POWER_MANAGEMENT_4, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001366SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1367 WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001368 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001369SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1370 WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001371 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001372
1373SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1374 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1375SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1376 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1377
Mark Browna3257ba2010-07-19 14:02:34 +01001378SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1379 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1380SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1381 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1382
Mark Brown9e6e96a2010-01-29 17:47:12 +00001383SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1384 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1385SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1386 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1387
1388SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1389SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1390
1391SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1392 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1393SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1394 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1395
1396SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1397 WM8994_POWER_MANAGEMENT_4, 13, 0),
1398SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1399 WM8994_POWER_MANAGEMENT_4, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001400SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1401 WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
1402 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1403SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1404 WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
1405 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001406
1407SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1408SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001409SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001410SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
1411
1412SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1413SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1414SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001415
1416SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
1417SND_SOC_DAPM_AIF_IN("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
1418
1419SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1420
1421SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1422SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1423SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1424SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1425
1426/* Power is done with the muxes since the ADC power also controls the
1427 * downsampling chain, the chip will automatically manage the analogue
1428 * specific portions.
1429 */
1430SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1431SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1432
Mark Brown9e6e96a2010-01-29 17:47:12 +00001433SND_SOC_DAPM_POST("Debug log", post_ev),
1434};
1435
Mark Brownc4431df2010-11-26 15:21:07 +00001436static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1437SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1438};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001439
Mark Brownc4431df2010-11-26 15:21:07 +00001440static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1441SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1442SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1443SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1444SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1445};
1446
1447static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001448 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1449 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1450
1451 { "DSP1CLK", NULL, "CLK_SYS" },
1452 { "DSP2CLK", NULL, "CLK_SYS" },
1453 { "DSPINTCLK", NULL, "CLK_SYS" },
1454
1455 { "AIF1ADC1L", NULL, "AIF1CLK" },
1456 { "AIF1ADC1L", NULL, "DSP1CLK" },
1457 { "AIF1ADC1R", NULL, "AIF1CLK" },
1458 { "AIF1ADC1R", NULL, "DSP1CLK" },
1459 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1460
1461 { "AIF1DAC1L", NULL, "AIF1CLK" },
1462 { "AIF1DAC1L", NULL, "DSP1CLK" },
1463 { "AIF1DAC1R", NULL, "AIF1CLK" },
1464 { "AIF1DAC1R", NULL, "DSP1CLK" },
1465 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1466
1467 { "AIF1ADC2L", NULL, "AIF1CLK" },
1468 { "AIF1ADC2L", NULL, "DSP1CLK" },
1469 { "AIF1ADC2R", NULL, "AIF1CLK" },
1470 { "AIF1ADC2R", NULL, "DSP1CLK" },
1471 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1472
1473 { "AIF1DAC2L", NULL, "AIF1CLK" },
1474 { "AIF1DAC2L", NULL, "DSP1CLK" },
1475 { "AIF1DAC2R", NULL, "AIF1CLK" },
1476 { "AIF1DAC2R", NULL, "DSP1CLK" },
1477 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1478
1479 { "AIF2ADCL", NULL, "AIF2CLK" },
1480 { "AIF2ADCL", NULL, "DSP2CLK" },
1481 { "AIF2ADCR", NULL, "AIF2CLK" },
1482 { "AIF2ADCR", NULL, "DSP2CLK" },
1483 { "AIF2ADCR", NULL, "DSPINTCLK" },
1484
1485 { "AIF2DACL", NULL, "AIF2CLK" },
1486 { "AIF2DACL", NULL, "DSP2CLK" },
1487 { "AIF2DACR", NULL, "AIF2CLK" },
1488 { "AIF2DACR", NULL, "DSP2CLK" },
1489 { "AIF2DACR", NULL, "DSPINTCLK" },
1490
1491 { "DMIC1L", NULL, "DMIC1DAT" },
1492 { "DMIC1L", NULL, "CLK_SYS" },
1493 { "DMIC1R", NULL, "DMIC1DAT" },
1494 { "DMIC1R", NULL, "CLK_SYS" },
1495 { "DMIC2L", NULL, "DMIC2DAT" },
1496 { "DMIC2L", NULL, "CLK_SYS" },
1497 { "DMIC2R", NULL, "DMIC2DAT" },
1498 { "DMIC2R", NULL, "CLK_SYS" },
1499
1500 { "ADCL", NULL, "AIF1CLK" },
1501 { "ADCL", NULL, "DSP1CLK" },
1502 { "ADCL", NULL, "DSPINTCLK" },
1503
1504 { "ADCR", NULL, "AIF1CLK" },
1505 { "ADCR", NULL, "DSP1CLK" },
1506 { "ADCR", NULL, "DSPINTCLK" },
1507
1508 { "ADCL Mux", "ADC", "ADCL" },
1509 { "ADCL Mux", "DMIC", "DMIC1L" },
1510 { "ADCR Mux", "ADC", "ADCR" },
1511 { "ADCR Mux", "DMIC", "DMIC1R" },
1512
1513 { "DAC1L", NULL, "AIF1CLK" },
1514 { "DAC1L", NULL, "DSP1CLK" },
1515 { "DAC1L", NULL, "DSPINTCLK" },
1516
1517 { "DAC1R", NULL, "AIF1CLK" },
1518 { "DAC1R", NULL, "DSP1CLK" },
1519 { "DAC1R", NULL, "DSPINTCLK" },
1520
1521 { "DAC2L", NULL, "AIF2CLK" },
1522 { "DAC2L", NULL, "DSP2CLK" },
1523 { "DAC2L", NULL, "DSPINTCLK" },
1524
1525 { "DAC2R", NULL, "AIF2DACR" },
1526 { "DAC2R", NULL, "AIF2CLK" },
1527 { "DAC2R", NULL, "DSP2CLK" },
1528 { "DAC2R", NULL, "DSPINTCLK" },
1529
1530 { "TOCLK", NULL, "CLK_SYS" },
1531
1532 /* AIF1 outputs */
1533 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1534 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1535 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1536
1537 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1538 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1539 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1540
Mark Browna3257ba2010-07-19 14:02:34 +01001541 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1542 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1543 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1544
1545 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1546 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1547 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1548
Mark Brown9e6e96a2010-01-29 17:47:12 +00001549 /* Pin level routing for AIF3 */
1550 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1551 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1552 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1553 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1554
Mark Brown9e6e96a2010-01-29 17:47:12 +00001555 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1556 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1557 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1558 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1559 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1560 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1561 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1562
1563 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001564 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1565 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1566 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1567 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1568 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1569
Mark Brown9e6e96a2010-01-29 17:47:12 +00001570 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1571 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1572 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1573 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1574 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1575
1576 /* DAC2/AIF2 outputs */
1577 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001578 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1579 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1580 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1581 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1582 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1583
1584 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001585 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1586 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1587 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1588 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1589 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1590
Mark Brown7f94de42011-02-03 16:27:34 +00001591 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1592 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1593 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1594 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1595
Mark Brown9e6e96a2010-01-29 17:47:12 +00001596 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1597
1598 /* AIF3 output */
1599 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1600 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1601 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1602 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1603 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1604 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1605 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1606 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1607
1608 /* Sidetone */
1609 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1610 { "Left Sidetone", "DMIC2", "DMIC2L" },
1611 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1612 { "Right Sidetone", "DMIC2", "DMIC2R" },
1613
1614 /* Output stages */
1615 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1616 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1617
1618 { "SPKL", "DAC1 Switch", "DAC1L" },
1619 { "SPKL", "DAC2 Switch", "DAC2L" },
1620
1621 { "SPKR", "DAC1 Switch", "DAC1R" },
1622 { "SPKR", "DAC2 Switch", "DAC2R" },
1623
1624 { "Left Headphone Mux", "DAC", "DAC1L" },
1625 { "Right Headphone Mux", "DAC", "DAC1R" },
1626};
1627
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001628static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1629 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1630 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1631 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1632 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1633 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1634 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1635 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1636 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1637};
1638
1639static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1640 { "DAC1L", NULL, "DAC1L Mixer" },
1641 { "DAC1R", NULL, "DAC1R Mixer" },
1642 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1643 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1644};
1645
Mark Brown6ed8f142011-02-03 16:27:35 +00001646static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1647 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1648 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1649 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1650 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001651 { "MICBIAS1", NULL, "CLK_SYS" },
1652 { "MICBIAS1", NULL, "MICBIAS Supply" },
1653 { "MICBIAS2", NULL, "CLK_SYS" },
1654 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001655};
1656
Mark Brownc4431df2010-11-26 15:21:07 +00001657static const struct snd_soc_dapm_route wm8994_intercon[] = {
1658 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1659 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001660 { "MICBIAS1", NULL, "VMID" },
1661 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001662};
1663
1664static const struct snd_soc_dapm_route wm8958_intercon[] = {
1665 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1666 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1667
1668 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1669 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1670 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1671 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1672
1673 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1674 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1675
1676 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1677};
1678
Mark Brown9e6e96a2010-01-29 17:47:12 +00001679/* The size in bits of the FLL divide multiplied by 10
1680 * to allow rounding later */
1681#define FIXED_FLL_SIZE ((1 << 16) * 10)
1682
1683struct fll_div {
1684 u16 outdiv;
1685 u16 n;
1686 u16 k;
1687 u16 clk_ref_div;
1688 u16 fll_fratio;
1689};
1690
1691static int wm8994_get_fll_config(struct fll_div *fll,
1692 int freq_in, int freq_out)
1693{
1694 u64 Kpart;
1695 unsigned int K, Ndiv, Nmod;
1696
1697 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
1698
1699 /* Scale the input frequency down to <= 13.5MHz */
1700 fll->clk_ref_div = 0;
1701 while (freq_in > 13500000) {
1702 fll->clk_ref_div++;
1703 freq_in /= 2;
1704
1705 if (fll->clk_ref_div > 3)
1706 return -EINVAL;
1707 }
1708 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1709
1710 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1711 fll->outdiv = 3;
1712 while (freq_out * (fll->outdiv + 1) < 90000000) {
1713 fll->outdiv++;
1714 if (fll->outdiv > 63)
1715 return -EINVAL;
1716 }
1717 freq_out *= fll->outdiv + 1;
1718 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1719
1720 if (freq_in > 1000000) {
1721 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001722 } else if (freq_in > 256000) {
1723 fll->fll_fratio = 1;
1724 freq_in *= 2;
1725 } else if (freq_in > 128000) {
1726 fll->fll_fratio = 2;
1727 freq_in *= 4;
1728 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001729 fll->fll_fratio = 3;
1730 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001731 } else {
1732 fll->fll_fratio = 4;
1733 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001734 }
1735 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1736
1737 /* Now, calculate N.K */
1738 Ndiv = freq_out / freq_in;
1739
1740 fll->n = Ndiv;
1741 Nmod = freq_out % freq_in;
1742 pr_debug("Nmod=%d\n", Nmod);
1743
1744 /* Calculate fractional part - scale up so we can round. */
1745 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
1746
1747 do_div(Kpart, freq_in);
1748
1749 K = Kpart & 0xFFFFFFFF;
1750
1751 if ((K % 10) >= 5)
1752 K += 5;
1753
1754 /* Move down to proper range now rounding is done */
1755 fll->k = K / 10;
1756
1757 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1758
1759 return 0;
1760}
1761
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001762static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001763 unsigned int freq_in, unsigned int freq_out)
1764{
Mark Brownb2c812e2010-04-14 15:35:19 +09001765 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09001766 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001767 int reg_offset, ret;
1768 struct fll_div fll;
1769 u16 reg, aif1, aif2;
Mark Brownc7ebf932011-07-12 19:47:59 +09001770 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09001771 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001772
1773 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
1774 & WM8994_AIF1CLK_ENA;
1775
1776 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
1777 & WM8994_AIF2CLK_ENA;
1778
1779 switch (id) {
1780 case WM8994_FLL1:
1781 reg_offset = 0;
1782 id = 0;
1783 break;
1784 case WM8994_FLL2:
1785 reg_offset = 0x20;
1786 id = 1;
1787 break;
1788 default:
1789 return -EINVAL;
1790 }
1791
Mark Brown4b7ed832011-08-10 17:47:33 +09001792 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
1793 was_enabled = reg & WM8994_FLL1_ENA;
1794
Mark Brown136ff2a2010-04-20 12:56:18 +09001795 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09001796 case 0:
1797 /* Allow no source specification when stopping */
1798 if (freq_out)
1799 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00001800 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09001801 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09001802 case WM8994_FLL_SRC_MCLK1:
1803 case WM8994_FLL_SRC_MCLK2:
1804 case WM8994_FLL_SRC_LRCLK:
1805 case WM8994_FLL_SRC_BCLK:
1806 break;
1807 default:
1808 return -EINVAL;
1809 }
1810
Mark Brown9e6e96a2010-01-29 17:47:12 +00001811 /* Are we changing anything? */
1812 if (wm8994->fll[id].src == src &&
1813 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
1814 return 0;
1815
1816 /* If we're stopping the FLL redo the old config - no
1817 * registers will actually be written but we avoid GCC flow
1818 * analysis bugs spewing warnings.
1819 */
1820 if (freq_out)
1821 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
1822 else
1823 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
1824 wm8994->fll[id].out);
1825 if (ret < 0)
1826 return ret;
1827
1828 /* Gate the AIF clocks while we reclock */
1829 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1830 WM8994_AIF1CLK_ENA, 0);
1831 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1832 WM8994_AIF2CLK_ENA, 0);
1833
1834 /* We always need to disable the FLL while reconfiguring */
1835 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1836 WM8994_FLL1_ENA, 0);
1837
1838 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
1839 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
1840 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
1841 WM8994_FLL1_OUTDIV_MASK |
1842 WM8994_FLL1_FRATIO_MASK, reg);
1843
1844 snd_soc_write(codec, WM8994_FLL1_CONTROL_3 + reg_offset, fll.k);
1845
1846 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
1847 WM8994_FLL1_N_MASK,
1848 fll.n << WM8994_FLL1_N_SHIFT);
1849
1850 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brown136ff2a2010-04-20 12:56:18 +09001851 WM8994_FLL1_REFCLK_DIV_MASK |
1852 WM8994_FLL1_REFCLK_SRC_MASK,
1853 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
1854 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00001855
Mark Brownf0f50392011-07-16 03:12:18 +09001856 /* Clear any pending completion from a previous failure */
1857 try_wait_for_completion(&wm8994->fll_locked[id]);
1858
Mark Brown9e6e96a2010-01-29 17:47:12 +00001859 /* Enable (with fractional mode if required) */
1860 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09001861 /* Enable VMID if we need it */
1862 if (!was_enabled) {
1863 switch (control->type) {
1864 case WM8994:
1865 vmid_reference(codec);
1866 break;
1867 case WM8958:
1868 if (wm8994->revision < 1)
1869 vmid_reference(codec);
1870 break;
1871 default:
1872 break;
1873 }
1874 }
1875
Mark Brown9e6e96a2010-01-29 17:47:12 +00001876 if (fll.k)
1877 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
1878 else
1879 reg = WM8994_FLL1_ENA;
1880 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1881 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
1882 reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07001883
Mark Brownc7ebf932011-07-12 19:47:59 +09001884 if (wm8994->fll_locked_irq) {
1885 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
1886 msecs_to_jiffies(10));
1887 if (timeout == 0)
1888 dev_warn(codec->dev,
1889 "Timed out waiting for FLL lock\n");
1890 } else {
1891 msleep(5);
1892 }
Mark Brown4b7ed832011-08-10 17:47:33 +09001893 } else {
1894 if (was_enabled) {
1895 switch (control->type) {
1896 case WM8994:
1897 vmid_dereference(codec);
1898 break;
1899 case WM8958:
1900 if (wm8994->revision < 1)
1901 vmid_dereference(codec);
1902 break;
1903 default:
1904 break;
1905 }
1906 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00001907 }
1908
1909 wm8994->fll[id].in = freq_in;
1910 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09001911 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001912
1913 /* Enable any gated AIF clocks */
1914 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1915 WM8994_AIF1CLK_ENA, aif1);
1916 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1917 WM8994_AIF2CLK_ENA, aif2);
1918
1919 configure_clock(codec);
1920
1921 return 0;
1922}
1923
Mark Brownc7ebf932011-07-12 19:47:59 +09001924static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
1925{
1926 struct completion *completion = data;
1927
1928 complete(completion);
1929
1930 return IRQ_HANDLED;
1931}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001932
Mark Brown66b47fd2010-07-08 11:25:43 +09001933static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
1934
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001935static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
1936 unsigned int freq_in, unsigned int freq_out)
1937{
1938 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
1939}
1940
Mark Brown9e6e96a2010-01-29 17:47:12 +00001941static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
1942 int clk_id, unsigned int freq, int dir)
1943{
1944 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09001945 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09001946 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001947
1948 switch (dai->id) {
1949 case 1:
1950 case 2:
1951 break;
1952
1953 default:
1954 /* AIF3 shares clocking with AIF1/2 */
1955 return -EINVAL;
1956 }
1957
1958 switch (clk_id) {
1959 case WM8994_SYSCLK_MCLK1:
1960 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
1961 wm8994->mclk[0] = freq;
1962 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
1963 dai->id, freq);
1964 break;
1965
1966 case WM8994_SYSCLK_MCLK2:
1967 /* TODO: Set GPIO AF */
1968 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
1969 wm8994->mclk[1] = freq;
1970 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
1971 dai->id, freq);
1972 break;
1973
1974 case WM8994_SYSCLK_FLL1:
1975 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
1976 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
1977 break;
1978
1979 case WM8994_SYSCLK_FLL2:
1980 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
1981 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
1982 break;
1983
Mark Brown66b47fd2010-07-08 11:25:43 +09001984 case WM8994_SYSCLK_OPCLK:
1985 /* Special case - a division (times 10) is given and
1986 * no effect on main clocking.
1987 */
1988 if (freq) {
1989 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
1990 if (opclk_divs[i] == freq)
1991 break;
1992 if (i == ARRAY_SIZE(opclk_divs))
1993 return -EINVAL;
1994 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
1995 WM8994_OPCLK_DIV_MASK, i);
1996 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
1997 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
1998 } else {
1999 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2000 WM8994_OPCLK_ENA, 0);
2001 }
2002
Mark Brown9e6e96a2010-01-29 17:47:12 +00002003 default:
2004 return -EINVAL;
2005 }
2006
2007 configure_clock(codec);
2008
2009 return 0;
2010}
2011
2012static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2013 enum snd_soc_bias_level level)
2014{
Mark Brown3a423152010-11-26 15:21:06 +00002015 struct wm8994 *control = codec->control_data;
Mark Brownb6b05692010-08-13 12:58:20 +01002016 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2017
Mark Brown9e6e96a2010-01-29 17:47:12 +00002018 switch (level) {
2019 case SND_SOC_BIAS_ON:
2020 break;
2021
2022 case SND_SOC_BIAS_PREPARE:
Mark Brown9e6e96a2010-01-29 17:47:12 +00002023 break;
2024
2025 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002026 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown39fb51a2010-11-26 17:23:43 +00002027 pm_runtime_get_sync(codec->dev);
2028
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002029 switch (control->type) {
2030 case WM8994:
2031 if (wm8994->revision < 4) {
2032 /* Tweak DC servo and DSP
2033 * configuration for improved
2034 * performance. */
2035 snd_soc_write(codec, 0x102, 0x3);
2036 snd_soc_write(codec, 0x56, 0x3);
2037 snd_soc_write(codec, 0x817, 0);
2038 snd_soc_write(codec, 0x102, 0);
2039 }
2040 break;
2041
2042 case WM8958:
2043 if (wm8994->revision == 0) {
2044 /* Optimise performance for rev A */
2045 snd_soc_write(codec, 0x102, 0x3);
2046 snd_soc_write(codec, 0xcb, 0x81);
2047 snd_soc_write(codec, 0x817, 0);
2048 snd_soc_write(codec, 0x102, 0);
2049
2050 snd_soc_update_bits(codec,
2051 WM8958_CHARGE_PUMP_2,
2052 WM8958_CP_DISCH,
2053 WM8958_CP_DISCH);
2054 }
2055 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002056 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002057
2058 /* Discharge LINEOUT1 & 2 */
2059 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2060 WM8994_LINEOUT1_DISCH |
2061 WM8994_LINEOUT2_DISCH,
2062 WM8994_LINEOUT1_DISCH |
2063 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002064 }
2065
Mark Brown9e6e96a2010-01-29 17:47:12 +00002066
2067 break;
2068
2069 case SND_SOC_BIAS_OFF:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002070 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
Mark Brownfbbf5922011-03-11 18:09:04 +00002071 wm8994->cur_fw = NULL;
2072
Mark Brown39fb51a2010-11-26 17:23:43 +00002073 pm_runtime_put(codec->dev);
Mark Brownd522ffb2010-03-30 14:29:14 +01002074 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002075 break;
2076 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002077 codec->dapm.bias_level = level;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002078 return 0;
2079}
2080
2081static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2082{
2083 struct snd_soc_codec *codec = dai->codec;
Mark Brownc4431df2010-11-26 15:21:07 +00002084 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002085 int ms_reg;
2086 int aif1_reg;
2087 int ms = 0;
2088 int aif1 = 0;
2089
2090 switch (dai->id) {
2091 case 1:
2092 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2093 aif1_reg = WM8994_AIF1_CONTROL_1;
2094 break;
2095 case 2:
2096 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2097 aif1_reg = WM8994_AIF2_CONTROL_1;
2098 break;
2099 default:
2100 return -EINVAL;
2101 }
2102
2103 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2104 case SND_SOC_DAIFMT_CBS_CFS:
2105 break;
2106 case SND_SOC_DAIFMT_CBM_CFM:
2107 ms = WM8994_AIF1_MSTR;
2108 break;
2109 default:
2110 return -EINVAL;
2111 }
2112
2113 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2114 case SND_SOC_DAIFMT_DSP_B:
2115 aif1 |= WM8994_AIF1_LRCLK_INV;
2116 case SND_SOC_DAIFMT_DSP_A:
2117 aif1 |= 0x18;
2118 break;
2119 case SND_SOC_DAIFMT_I2S:
2120 aif1 |= 0x10;
2121 break;
2122 case SND_SOC_DAIFMT_RIGHT_J:
2123 break;
2124 case SND_SOC_DAIFMT_LEFT_J:
2125 aif1 |= 0x8;
2126 break;
2127 default:
2128 return -EINVAL;
2129 }
2130
2131 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2132 case SND_SOC_DAIFMT_DSP_A:
2133 case SND_SOC_DAIFMT_DSP_B:
2134 /* frame inversion not valid for DSP modes */
2135 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2136 case SND_SOC_DAIFMT_NB_NF:
2137 break;
2138 case SND_SOC_DAIFMT_IB_NF:
2139 aif1 |= WM8994_AIF1_BCLK_INV;
2140 break;
2141 default:
2142 return -EINVAL;
2143 }
2144 break;
2145
2146 case SND_SOC_DAIFMT_I2S:
2147 case SND_SOC_DAIFMT_RIGHT_J:
2148 case SND_SOC_DAIFMT_LEFT_J:
2149 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2150 case SND_SOC_DAIFMT_NB_NF:
2151 break;
2152 case SND_SOC_DAIFMT_IB_IF:
2153 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2154 break;
2155 case SND_SOC_DAIFMT_IB_NF:
2156 aif1 |= WM8994_AIF1_BCLK_INV;
2157 break;
2158 case SND_SOC_DAIFMT_NB_IF:
2159 aif1 |= WM8994_AIF1_LRCLK_INV;
2160 break;
2161 default:
2162 return -EINVAL;
2163 }
2164 break;
2165 default:
2166 return -EINVAL;
2167 }
2168
Mark Brownc4431df2010-11-26 15:21:07 +00002169 /* The AIF2 format configuration needs to be mirrored to AIF3
2170 * on WM8958 if it's in use so just do it all the time. */
2171 if (control->type == WM8958 && dai->id == 2)
2172 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2173 WM8994_AIF1_LRCLK_INV |
2174 WM8958_AIF3_FMT_MASK, aif1);
2175
Mark Brown9e6e96a2010-01-29 17:47:12 +00002176 snd_soc_update_bits(codec, aif1_reg,
2177 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2178 WM8994_AIF1_FMT_MASK,
2179 aif1);
2180 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2181 ms);
2182
2183 return 0;
2184}
2185
2186static struct {
2187 int val, rate;
2188} srs[] = {
2189 { 0, 8000 },
2190 { 1, 11025 },
2191 { 2, 12000 },
2192 { 3, 16000 },
2193 { 4, 22050 },
2194 { 5, 24000 },
2195 { 6, 32000 },
2196 { 7, 44100 },
2197 { 8, 48000 },
2198 { 9, 88200 },
2199 { 10, 96000 },
2200};
2201
2202static int fs_ratios[] = {
2203 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2204};
2205
2206static int bclk_divs[] = {
2207 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2208 640, 880, 960, 1280, 1760, 1920
2209};
2210
2211static int wm8994_hw_params(struct snd_pcm_substream *substream,
2212 struct snd_pcm_hw_params *params,
2213 struct snd_soc_dai *dai)
2214{
2215 struct snd_soc_codec *codec = dai->codec;
Mark Brownc4431df2010-11-26 15:21:07 +00002216 struct wm8994 *control = codec->control_data;
Mark Brownb2c812e2010-04-14 15:35:19 +09002217 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002218 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002219 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002220 int bclk_reg;
2221 int lrclk_reg;
2222 int rate_reg;
2223 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002224 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002225 int bclk = 0;
2226 int lrclk = 0;
2227 int rate_val = 0;
2228 int id = dai->id - 1;
2229
2230 int i, cur_val, best_val, bclk_rate, best;
2231
2232 switch (dai->id) {
2233 case 1:
2234 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002235 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002236 bclk_reg = WM8994_AIF1_BCLK;
2237 rate_reg = WM8994_AIF1_RATE;
2238 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002239 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002240 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002241 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002242 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002243 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2244 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002245 break;
2246 case 2:
2247 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002248 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002249 bclk_reg = WM8994_AIF2_BCLK;
2250 rate_reg = WM8994_AIF2_RATE;
2251 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002252 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002253 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002254 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002255 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002256 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2257 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002258 break;
Mark Brownc4431df2010-11-26 15:21:07 +00002259 case 3:
2260 switch (control->type) {
2261 case WM8958:
2262 aif1_reg = WM8958_AIF3_CONTROL_1;
2263 break;
2264 default:
2265 return 0;
2266 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002267 default:
2268 return -EINVAL;
2269 }
2270
2271 bclk_rate = params_rate(params) * 2;
2272 switch (params_format(params)) {
2273 case SNDRV_PCM_FORMAT_S16_LE:
2274 bclk_rate *= 16;
2275 break;
2276 case SNDRV_PCM_FORMAT_S20_3LE:
2277 bclk_rate *= 20;
2278 aif1 |= 0x20;
2279 break;
2280 case SNDRV_PCM_FORMAT_S24_LE:
2281 bclk_rate *= 24;
2282 aif1 |= 0x40;
2283 break;
2284 case SNDRV_PCM_FORMAT_S32_LE:
2285 bclk_rate *= 32;
2286 aif1 |= 0x60;
2287 break;
2288 default:
2289 return -EINVAL;
2290 }
2291
2292 /* Try to find an appropriate sample rate; look for an exact match. */
2293 for (i = 0; i < ARRAY_SIZE(srs); i++)
2294 if (srs[i].rate == params_rate(params))
2295 break;
2296 if (i == ARRAY_SIZE(srs))
2297 return -EINVAL;
2298 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2299
2300 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2301 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2302 dai->id, wm8994->aifclk[id], bclk_rate);
2303
Mark Brownb1e43d92010-12-07 17:14:56 +00002304 if (params_channels(params) == 1 &&
2305 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2306 aif2 |= WM8994_AIF1_MONO;
2307
Mark Brown9e6e96a2010-01-29 17:47:12 +00002308 if (wm8994->aifclk[id] == 0) {
2309 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2310 return -EINVAL;
2311 }
2312
2313 /* AIFCLK/fs ratio; look for a close match in either direction */
2314 best = 0;
2315 best_val = abs((fs_ratios[0] * params_rate(params))
2316 - wm8994->aifclk[id]);
2317 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2318 cur_val = abs((fs_ratios[i] * params_rate(params))
2319 - wm8994->aifclk[id]);
2320 if (cur_val >= best_val)
2321 continue;
2322 best = i;
2323 best_val = cur_val;
2324 }
2325 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2326 dai->id, fs_ratios[best]);
2327 rate_val |= best;
2328
2329 /* We may not get quite the right frequency if using
2330 * approximate clocks so look for the closest match that is
2331 * higher than the target (we need to ensure that there enough
2332 * BCLKs to clock out the samples).
2333 */
2334 best = 0;
2335 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002336 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002337 if (cur_val < 0) /* BCLK table is sorted */
2338 break;
2339 best = i;
2340 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002341 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002342 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2343 bclk_divs[best], bclk_rate);
2344 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2345
2346 lrclk = bclk_rate / params_rate(params);
2347 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2348 lrclk, bclk_rate / lrclk);
2349
2350 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002351 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002352 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2353 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2354 lrclk);
2355 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2356 WM8994_AIF1CLK_RATE_MASK, rate_val);
2357
2358 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2359 switch (dai->id) {
2360 case 1:
2361 wm8994->dac_rates[0] = params_rate(params);
2362 wm8994_set_retune_mobile(codec, 0);
2363 wm8994_set_retune_mobile(codec, 1);
2364 break;
2365 case 2:
2366 wm8994->dac_rates[1] = params_rate(params);
2367 wm8994_set_retune_mobile(codec, 2);
2368 break;
2369 }
2370 }
2371
2372 return 0;
2373}
2374
Mark Brownc4431df2010-11-26 15:21:07 +00002375static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2376 struct snd_pcm_hw_params *params,
2377 struct snd_soc_dai *dai)
2378{
2379 struct snd_soc_codec *codec = dai->codec;
2380 struct wm8994 *control = codec->control_data;
2381 int aif1_reg;
2382 int aif1 = 0;
2383
2384 switch (dai->id) {
2385 case 3:
2386 switch (control->type) {
2387 case WM8958:
2388 aif1_reg = WM8958_AIF3_CONTROL_1;
2389 break;
2390 default:
2391 return 0;
2392 }
2393 default:
2394 return 0;
2395 }
2396
2397 switch (params_format(params)) {
2398 case SNDRV_PCM_FORMAT_S16_LE:
2399 break;
2400 case SNDRV_PCM_FORMAT_S20_3LE:
2401 aif1 |= 0x20;
2402 break;
2403 case SNDRV_PCM_FORMAT_S24_LE:
2404 aif1 |= 0x40;
2405 break;
2406 case SNDRV_PCM_FORMAT_S32_LE:
2407 aif1 |= 0x60;
2408 break;
2409 default:
2410 return -EINVAL;
2411 }
2412
2413 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2414}
2415
Mark Brown7d021732011-07-14 17:11:38 +09002416static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
2417 struct snd_soc_dai *dai)
2418{
2419 struct snd_soc_codec *codec = dai->codec;
2420 int rate_reg = 0;
2421
2422 switch (dai->id) {
2423 case 1:
2424 rate_reg = WM8994_AIF1_RATE;
2425 break;
2426 case 2:
2427 rate_reg = WM8994_AIF1_RATE;
2428 break;
2429 default:
2430 break;
2431 }
2432
2433 /* If the DAI is idle then configure the divider tree for the
2434 * lowest output rate to save a little power if the clock is
2435 * still active (eg, because it is system clock).
2436 */
2437 if (rate_reg && !dai->playback_active && !dai->capture_active)
2438 snd_soc_update_bits(codec, rate_reg,
2439 WM8994_AIF1_SR_MASK |
2440 WM8994_AIF1CLK_RATE_MASK, 0x9);
2441}
2442
Mark Brown9e6e96a2010-01-29 17:47:12 +00002443static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2444{
2445 struct snd_soc_codec *codec = codec_dai->codec;
2446 int mute_reg;
2447 int reg;
2448
2449 switch (codec_dai->id) {
2450 case 1:
2451 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2452 break;
2453 case 2:
2454 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2455 break;
2456 default:
2457 return -EINVAL;
2458 }
2459
2460 if (mute)
2461 reg = WM8994_AIF1DAC1_MUTE;
2462 else
2463 reg = 0;
2464
2465 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2466
2467 return 0;
2468}
2469
Mark Brown778a76e2010-03-22 22:05:10 +00002470static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2471{
2472 struct snd_soc_codec *codec = codec_dai->codec;
2473 int reg, val, mask;
2474
2475 switch (codec_dai->id) {
2476 case 1:
2477 reg = WM8994_AIF1_MASTER_SLAVE;
2478 mask = WM8994_AIF1_TRI;
2479 break;
2480 case 2:
2481 reg = WM8994_AIF2_MASTER_SLAVE;
2482 mask = WM8994_AIF2_TRI;
2483 break;
2484 case 3:
2485 reg = WM8994_POWER_MANAGEMENT_6;
2486 mask = WM8994_AIF3_TRI;
2487 break;
2488 default:
2489 return -EINVAL;
2490 }
2491
2492 if (tristate)
2493 val = mask;
2494 else
2495 val = 0;
2496
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002497 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002498}
2499
Mark Brownd09f3ec2011-08-15 11:01:02 +09002500static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2501{
2502 struct snd_soc_codec *codec = dai->codec;
2503
2504 /* Disable the pulls on the AIF if we're using it to save power. */
2505 snd_soc_update_bits(codec, WM8994_GPIO_3,
2506 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2507 snd_soc_update_bits(codec, WM8994_GPIO_4,
2508 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2509 snd_soc_update_bits(codec, WM8994_GPIO_5,
2510 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2511
2512 return 0;
2513}
2514
Mark Brown9e6e96a2010-01-29 17:47:12 +00002515#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2516
2517#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002518 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002519
2520static struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
2521 .set_sysclk = wm8994_set_dai_sysclk,
2522 .set_fmt = wm8994_set_dai_fmt,
2523 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002524 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002525 .digital_mute = wm8994_aif_mute,
2526 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002527 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002528};
2529
2530static struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
2531 .set_sysclk = wm8994_set_dai_sysclk,
2532 .set_fmt = wm8994_set_dai_fmt,
2533 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002534 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002535 .digital_mute = wm8994_aif_mute,
2536 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002537 .set_tristate = wm8994_set_tristate,
2538};
2539
2540static struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00002541 .hw_params = wm8994_aif3_hw_params,
Mark Brown778a76e2010-03-22 22:05:10 +00002542 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002543};
2544
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002545static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002546 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002547 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002548 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002549 .playback = {
2550 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002551 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002552 .channels_max = 2,
2553 .rates = WM8994_RATES,
2554 .formats = WM8994_FORMATS,
2555 },
2556 .capture = {
2557 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002558 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002559 .channels_max = 2,
2560 .rates = WM8994_RATES,
2561 .formats = WM8994_FORMATS,
2562 },
2563 .ops = &wm8994_aif1_dai_ops,
2564 },
2565 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002566 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002567 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002568 .playback = {
2569 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002570 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002571 .channels_max = 2,
2572 .rates = WM8994_RATES,
2573 .formats = WM8994_FORMATS,
2574 },
2575 .capture = {
2576 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002577 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002578 .channels_max = 2,
2579 .rates = WM8994_RATES,
2580 .formats = WM8994_FORMATS,
2581 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09002582 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002583 .ops = &wm8994_aif2_dai_ops,
2584 },
2585 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002586 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002587 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002588 .playback = {
2589 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002590 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002591 .channels_max = 2,
2592 .rates = WM8994_RATES,
2593 .formats = WM8994_FORMATS,
2594 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03002595 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002596 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002597 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002598 .channels_max = 2,
2599 .rates = WM8994_RATES,
2600 .formats = WM8994_FORMATS,
2601 },
Mark Brown778a76e2010-03-22 22:05:10 +00002602 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002603 }
2604};
Mark Brown9e6e96a2010-01-29 17:47:12 +00002605
2606#ifdef CONFIG_PM
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002607static int wm8994_suspend(struct snd_soc_codec *codec, pm_message_t state)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002608{
Mark Brownb2c812e2010-04-14 15:35:19 +09002609 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownca629922011-05-11 14:34:53 +02002610 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002611 int i, ret;
2612
Mark Brownca629922011-05-11 14:34:53 +02002613 switch (control->type) {
2614 case WM8994:
2615 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
2616 break;
2617 case WM8958:
2618 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2619 WM8958_MICD_ENA, 0);
2620 break;
2621 }
2622
Mark Brown9e6e96a2010-01-29 17:47:12 +00002623 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
2624 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00002625 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002626 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002627 if (ret < 0)
2628 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
2629 i + 1, ret);
2630 }
2631
2632 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
2633
2634 return 0;
2635}
2636
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002637static int wm8994_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002638{
Mark Brownb2c812e2010-04-14 15:35:19 +09002639 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownca629922011-05-11 14:34:53 +02002640 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002641 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002642 unsigned int val, mask;
2643
2644 if (wm8994->revision < 4) {
2645 /* force a HW read */
2646 val = wm8994_reg_read(codec->control_data,
2647 WM8994_POWER_MANAGEMENT_5);
2648
2649 /* modify the cache only */
2650 codec->cache_only = 1;
2651 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
2652 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
2653 val &= mask;
2654 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
2655 mask, val);
2656 codec->cache_only = 0;
2657 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002658
2659 /* Restore the registers */
Mark Brownca9aef52010-11-26 17:23:41 +00002660 ret = snd_soc_cache_sync(codec);
2661 if (ret != 0)
2662 dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002663
2664 wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2665
2666 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01002667 if (!wm8994->fll_suspend[i].out)
2668 continue;
2669
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002670 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002671 wm8994->fll_suspend[i].src,
2672 wm8994->fll_suspend[i].in,
2673 wm8994->fll_suspend[i].out);
2674 if (ret < 0)
2675 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
2676 i + 1, ret);
2677 }
2678
Mark Brownca629922011-05-11 14:34:53 +02002679 switch (control->type) {
2680 case WM8994:
2681 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2682 snd_soc_update_bits(codec, WM8994_MICBIAS,
2683 WM8994_MICD_ENA, WM8994_MICD_ENA);
2684 break;
2685 case WM8958:
2686 if (wm8994->jack_cb)
2687 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2688 WM8958_MICD_ENA, WM8958_MICD_ENA);
2689 break;
2690 }
2691
Mark Brown9e6e96a2010-01-29 17:47:12 +00002692 return 0;
2693}
2694#else
2695#define wm8994_suspend NULL
2696#define wm8994_resume NULL
2697#endif
2698
2699static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
2700{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002701 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002702 struct wm8994_pdata *pdata = wm8994->pdata;
2703 struct snd_kcontrol_new controls[] = {
2704 SOC_ENUM_EXT("AIF1.1 EQ Mode",
2705 wm8994->retune_mobile_enum,
2706 wm8994_get_retune_mobile_enum,
2707 wm8994_put_retune_mobile_enum),
2708 SOC_ENUM_EXT("AIF1.2 EQ Mode",
2709 wm8994->retune_mobile_enum,
2710 wm8994_get_retune_mobile_enum,
2711 wm8994_put_retune_mobile_enum),
2712 SOC_ENUM_EXT("AIF2 EQ Mode",
2713 wm8994->retune_mobile_enum,
2714 wm8994_get_retune_mobile_enum,
2715 wm8994_put_retune_mobile_enum),
2716 };
2717 int ret, i, j;
2718 const char **t;
2719
2720 /* We need an array of texts for the enum API but the number
2721 * of texts is likely to be less than the number of
2722 * configurations due to the sample rate dependency of the
2723 * configurations. */
2724 wm8994->num_retune_mobile_texts = 0;
2725 wm8994->retune_mobile_texts = NULL;
2726 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
2727 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
2728 if (strcmp(pdata->retune_mobile_cfgs[i].name,
2729 wm8994->retune_mobile_texts[j]) == 0)
2730 break;
2731 }
2732
2733 if (j != wm8994->num_retune_mobile_texts)
2734 continue;
2735
2736 /* Expand the array... */
2737 t = krealloc(wm8994->retune_mobile_texts,
2738 sizeof(char *) *
2739 (wm8994->num_retune_mobile_texts + 1),
2740 GFP_KERNEL);
2741 if (t == NULL)
2742 continue;
2743
2744 /* ...store the new entry... */
2745 t[wm8994->num_retune_mobile_texts] =
2746 pdata->retune_mobile_cfgs[i].name;
2747
2748 /* ...and remember the new version. */
2749 wm8994->num_retune_mobile_texts++;
2750 wm8994->retune_mobile_texts = t;
2751 }
2752
2753 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
2754 wm8994->num_retune_mobile_texts);
2755
2756 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
2757 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
2758
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002759 ret = snd_soc_add_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002760 ARRAY_SIZE(controls));
2761 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002762 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002763 "Failed to add ReTune Mobile controls: %d\n", ret);
2764}
2765
2766static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
2767{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002768 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002769 struct wm8994_pdata *pdata = wm8994->pdata;
2770 int ret, i;
2771
2772 if (!pdata)
2773 return;
2774
2775 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
2776 pdata->lineout2_diff,
2777 pdata->lineout1fb,
2778 pdata->lineout2fb,
2779 pdata->jd_scthr,
2780 pdata->jd_thr,
2781 pdata->micbias1_lvl,
2782 pdata->micbias2_lvl);
2783
2784 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
2785
2786 if (pdata->num_drc_cfgs) {
2787 struct snd_kcontrol_new controls[] = {
2788 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
2789 wm8994_get_drc_enum, wm8994_put_drc_enum),
2790 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
2791 wm8994_get_drc_enum, wm8994_put_drc_enum),
2792 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
2793 wm8994_get_drc_enum, wm8994_put_drc_enum),
2794 };
2795
2796 /* We need an array of texts for the enum API */
2797 wm8994->drc_texts = kmalloc(sizeof(char *)
2798 * pdata->num_drc_cfgs, GFP_KERNEL);
2799 if (!wm8994->drc_texts) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002800 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002801 "Failed to allocate %d DRC config texts\n",
2802 pdata->num_drc_cfgs);
2803 return;
2804 }
2805
2806 for (i = 0; i < pdata->num_drc_cfgs; i++)
2807 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
2808
2809 wm8994->drc_enum.max = pdata->num_drc_cfgs;
2810 wm8994->drc_enum.texts = wm8994->drc_texts;
2811
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002812 ret = snd_soc_add_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002813 ARRAY_SIZE(controls));
2814 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002815 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002816 "Failed to add DRC mode controls: %d\n", ret);
2817
2818 for (i = 0; i < WM8994_NUM_DRC; i++)
2819 wm8994_set_drc(codec, i);
2820 }
2821
2822 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
2823 pdata->num_retune_mobile_cfgs);
2824
2825 if (pdata->num_retune_mobile_cfgs)
2826 wm8994_handle_retune_mobile_pdata(wm8994);
2827 else
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002828 snd_soc_add_controls(wm8994->codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002829 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08002830
2831 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
2832 if (pdata->micbias[i]) {
2833 snd_soc_write(codec, WM8958_MICBIAS1 + i,
2834 pdata->micbias[i] & 0xffff);
2835 }
2836 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002837}
2838
Mark Brown88766982010-03-29 20:57:12 +01002839/**
2840 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
2841 *
2842 * @codec: WM8994 codec
2843 * @jack: jack to report detection events on
2844 * @micbias: microphone bias to detect on
2845 * @det: value to report for presence detection
2846 * @shrt: value to report for short detection
2847 *
2848 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
2849 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01002850 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01002851 * be configured using snd_soc_jack_add_gpios() instead.
2852 *
2853 * Configuration of detection levels is available via the micbias1_lvl
2854 * and micbias2_lvl platform data members.
2855 */
2856int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
2857 int micbias, int det, int shrt)
2858{
Mark Brownb2c812e2010-04-14 15:35:19 +09002859 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01002860 struct wm8994_micdet *micdet;
Mark Brown3a423152010-11-26 15:21:06 +00002861 struct wm8994 *control = codec->control_data;
Mark Brown88766982010-03-29 20:57:12 +01002862 int reg;
2863
Mark Brown3a423152010-11-26 15:21:06 +00002864 if (control->type != WM8994)
2865 return -EINVAL;
2866
Mark Brown88766982010-03-29 20:57:12 +01002867 switch (micbias) {
2868 case 1:
2869 micdet = &wm8994->micdet[0];
2870 break;
2871 case 2:
2872 micdet = &wm8994->micdet[1];
2873 break;
2874 default:
2875 return -EINVAL;
2876 }
2877
2878 dev_dbg(codec->dev, "Configuring microphone detection on %d: %x %x\n",
2879 micbias, det, shrt);
2880
2881 /* Store the configuration */
2882 micdet->jack = jack;
2883 micdet->det = det;
2884 micdet->shrt = shrt;
2885
2886 /* If either of the jacks is set up then enable detection */
2887 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2888 reg = WM8994_MICD_ENA;
2889 else
2890 reg = 0;
2891
2892 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
2893
2894 return 0;
2895}
2896EXPORT_SYMBOL_GPL(wm8994_mic_detect);
2897
2898static irqreturn_t wm8994_mic_irq(int irq, void *data)
2899{
2900 struct wm8994_priv *priv = data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002901 struct snd_soc_codec *codec = priv->codec;
Mark Brown88766982010-03-29 20:57:12 +01002902 int reg;
2903 int report;
2904
Mark Brown7116f452010-12-29 13:05:21 +00002905#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00002906 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00002907#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00002908
Mark Brown88766982010-03-29 20:57:12 +01002909 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
2910 if (reg < 0) {
2911 dev_err(codec->dev, "Failed to read microphone status: %d\n",
2912 reg);
2913 return IRQ_HANDLED;
2914 }
2915
2916 dev_dbg(codec->dev, "Microphone status: %x\n", reg);
2917
2918 report = 0;
2919 if (reg & WM8994_MIC1_DET_STS)
2920 report |= priv->micdet[0].det;
2921 if (reg & WM8994_MIC1_SHRT_STS)
2922 report |= priv->micdet[0].shrt;
2923 snd_soc_jack_report(priv->micdet[0].jack, report,
2924 priv->micdet[0].det | priv->micdet[0].shrt);
2925
2926 report = 0;
2927 if (reg & WM8994_MIC2_DET_STS)
2928 report |= priv->micdet[1].det;
2929 if (reg & WM8994_MIC2_SHRT_STS)
2930 report |= priv->micdet[1].shrt;
2931 snd_soc_jack_report(priv->micdet[1].jack, report,
2932 priv->micdet[1].det | priv->micdet[1].shrt);
2933
2934 return IRQ_HANDLED;
2935}
2936
Mark Brown821edd22010-11-26 15:21:09 +00002937/* Default microphone detection handler for WM8958 - the user can
2938 * override this if they wish.
2939 */
2940static void wm8958_default_micdet(u16 status, void *data)
2941{
2942 struct snd_soc_codec *codec = data;
2943 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2944 int report = 0;
2945
2946 /* If nothing present then clear our statuses */
Mark Brown864c4bd2011-02-21 20:51:13 -08002947 if (!(status & WM8958_MICD_STS))
Mark Brown821edd22010-11-26 15:21:09 +00002948 goto done;
Mark Brown821edd22010-11-26 15:21:09 +00002949
Mark Brown864c4bd2011-02-21 20:51:13 -08002950 report = SND_JACK_MICROPHONE;
Mark Brown821edd22010-11-26 15:21:09 +00002951
2952 /* Everything else is buttons; just assign slots */
Mark Brownb35e1602011-07-15 22:28:32 +09002953 if (status & 0x1c)
Mark Brown821edd22010-11-26 15:21:09 +00002954 report |= SND_JACK_BTN_0;
Mark Brown821edd22010-11-26 15:21:09 +00002955
2956done:
Mark Brown406e56c2011-02-21 20:41:25 -08002957 snd_soc_jack_report(wm8994->micdet[0].jack, report,
Mark Brown864c4bd2011-02-21 20:51:13 -08002958 SND_JACK_BTN_0 | SND_JACK_MICROPHONE);
Mark Brown821edd22010-11-26 15:21:09 +00002959}
2960
2961/**
2962 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
2963 *
2964 * @codec: WM8958 codec
2965 * @jack: jack to report detection events on
2966 *
2967 * Enable microphone detection functionality for the WM8958. By
2968 * default simple detection which supports the detection of up to 6
2969 * buttons plus video and microphone functionality is supported.
2970 *
2971 * The WM8958 has an advanced jack detection facility which is able to
2972 * support complex accessory detection, especially when used in
2973 * conjunction with external circuitry. In order to provide maximum
2974 * flexiblity a callback is provided which allows a completely custom
2975 * detection algorithm.
2976 */
2977int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
2978 wm8958_micdet_cb cb, void *cb_data)
2979{
2980 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2981 struct wm8994 *control = codec->control_data;
2982
2983 if (control->type != WM8958)
2984 return -EINVAL;
2985
2986 if (jack) {
2987 if (!cb) {
2988 dev_dbg(codec->dev, "Using default micdet callback\n");
2989 cb = wm8958_default_micdet;
2990 cb_data = codec;
2991 }
2992
2993 wm8994->micdet[0].jack = jack;
2994 wm8994->jack_cb = cb;
2995 wm8994->jack_cb_data = cb_data;
2996
2997 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2998 WM8958_MICD_ENA, WM8958_MICD_ENA);
2999 } else {
3000 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3001 WM8958_MICD_ENA, 0);
3002 }
3003
3004 return 0;
3005}
3006EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3007
3008static irqreturn_t wm8958_mic_irq(int irq, void *data)
3009{
3010 struct wm8994_priv *wm8994 = data;
3011 struct snd_soc_codec *codec = wm8994->codec;
3012 int reg;
3013
3014 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3015 if (reg < 0) {
3016 dev_err(codec->dev, "Failed to read mic detect status: %d\n",
3017 reg);
3018 return IRQ_NONE;
3019 }
3020
3021 if (!(reg & WM8958_MICD_VALID)) {
3022 dev_dbg(codec->dev, "Mic detect data not valid\n");
3023 goto out;
3024 }
3025
Mark Brown7116f452010-12-29 13:05:21 +00003026#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003027 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003028#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003029
Mark Brown821edd22010-11-26 15:21:09 +00003030 if (wm8994->jack_cb)
3031 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3032 else
3033 dev_warn(codec->dev, "Accessory detection with no callback\n");
3034
3035out:
3036 return IRQ_HANDLED;
3037}
3038
Mark Brown3b1af3f2011-07-14 12:38:18 +09003039static irqreturn_t wm8994_fifo_error(int irq, void *data)
3040{
3041 struct snd_soc_codec *codec = data;
3042
3043 dev_err(codec->dev, "FIFO error\n");
3044
3045 return IRQ_HANDLED;
3046}
3047
Mark Brownf0b182b2011-08-16 12:01:27 +09003048static irqreturn_t wm8994_temp_warn(int irq, void *data)
3049{
3050 struct snd_soc_codec *codec = data;
3051
3052 dev_err(codec->dev, "Thermal warning\n");
3053
3054 return IRQ_HANDLED;
3055}
3056
3057static irqreturn_t wm8994_temp_shut(int irq, void *data)
3058{
3059 struct snd_soc_codec *codec = data;
3060
3061 dev_crit(codec->dev, "Thermal shutdown\n");
3062
3063 return IRQ_HANDLED;
3064}
3065
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003066static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003067{
Mark Brown3a423152010-11-26 15:21:06 +00003068 struct wm8994 *control;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003069 struct wm8994_priv *wm8994;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003070 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownec62dbd2010-08-15 14:56:40 +01003071 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003072
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003073 codec->control_data = dev_get_drvdata(codec->dev->parent);
Mark Brown3a423152010-11-26 15:21:06 +00003074 control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003075
3076 wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003077 if (wm8994 == NULL)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003078 return -ENOMEM;
Mark Brownb2c812e2010-04-14 15:35:19 +09003079 snd_soc_codec_set_drvdata(codec, wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003080
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003081 wm8994->pdata = dev_get_platdata(codec->dev->parent);
3082 wm8994->codec = codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003083
Mark Brownc7ebf932011-07-12 19:47:59 +09003084 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3085 init_completion(&wm8994->fll_locked[i]);
3086
Mark Brown9b7c5252011-02-17 20:05:44 -08003087 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3088 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3089 else if (wm8994->pdata && wm8994->pdata->irq_base)
3090 wm8994->micdet_irq = wm8994->pdata->irq_base +
3091 WM8994_IRQ_MIC1_DET;
3092
Mark Brown39fb51a2010-11-26 17:23:43 +00003093 pm_runtime_enable(codec->dev);
3094 pm_runtime_resume(codec->dev);
3095
Mark Brownca9aef52010-11-26 17:23:41 +00003096 /* Read our current status back from the chip - we don't want to
3097 * reset as this may interfere with the GPIO or LDO operation. */
3098 for (i = 0; i < WM8994_CACHE_SIZE; i++) {
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +00003099 if (!wm8994_readable(codec, i) || wm8994_volatile(codec, i))
Mark Brownca9aef52010-11-26 17:23:41 +00003100 continue;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003101
Mark Brownca9aef52010-11-26 17:23:41 +00003102 ret = wm8994_reg_read(codec->control_data, i);
3103 if (ret <= 0)
3104 continue;
3105
3106 ret = snd_soc_cache_write(codec, i, ret);
3107 if (ret != 0) {
3108 dev_err(codec->dev,
3109 "Failed to initialise cache for 0x%x: %d\n",
3110 i, ret);
3111 goto err;
3112 }
3113 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003114
3115 /* Set revision-specific configuration */
Mark Brownb6b05692010-08-13 12:58:20 +01003116 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
Mark Brown3a423152010-11-26 15:21:06 +00003117 switch (control->type) {
3118 case WM8994:
3119 switch (wm8994->revision) {
3120 case 2:
3121 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003122 wm8994->hubs.dcs_codes_l = -5;
3123 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003124 wm8994->hubs.hp_startup_mode = 1;
3125 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003126 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003127 break;
3128 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003129 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003130 break;
3131 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003132 break;
Mark Brown3a423152010-11-26 15:21:06 +00003133
3134 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003135 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003136 break;
Mark Brown3a423152010-11-26 15:21:06 +00003137
Mark Brown9e6e96a2010-01-29 17:47:12 +00003138 default:
3139 break;
3140 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003141
Mark Brown3b1af3f2011-07-14 12:38:18 +09003142 wm8994_request_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR,
3143 wm8994_fifo_error, "FIFO error", codec);
Mark Brownf0b182b2011-08-16 12:01:27 +09003144 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
3145 wm8994_temp_warn, "Thermal warning", codec);
3146 wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
3147 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003148
Mark Brownb30ead52011-07-12 15:47:17 +09003149 ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
3150 wm_hubs_dcs_done, "DC servo done",
3151 &wm8994->hubs);
3152 if (ret == 0)
3153 wm8994->hubs.dcs_done_irq = true;
3154
Mark Brown3a423152010-11-26 15:21:06 +00003155 switch (control->type) {
3156 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003157 if (wm8994->micdet_irq) {
3158 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3159 wm8994_mic_irq,
3160 IRQF_TRIGGER_RISING,
3161 "Mic1 detect",
3162 wm8994);
3163 if (ret != 0)
3164 dev_warn(codec->dev,
3165 "Failed to request Mic1 detect IRQ: %d\n",
3166 ret);
3167 }
Mark Brown88766982010-03-29 20:57:12 +01003168
Mark Brown3a423152010-11-26 15:21:06 +00003169 ret = wm8994_request_irq(codec->control_data,
3170 WM8994_IRQ_MIC1_SHRT,
3171 wm8994_mic_irq, "Mic 1 short",
3172 wm8994);
3173 if (ret != 0)
3174 dev_warn(codec->dev,
3175 "Failed to request Mic1 short IRQ: %d\n",
3176 ret);
Mark Brown88766982010-03-29 20:57:12 +01003177
Mark Brown3a423152010-11-26 15:21:06 +00003178 ret = wm8994_request_irq(codec->control_data,
3179 WM8994_IRQ_MIC2_DET,
3180 wm8994_mic_irq, "Mic 2 detect",
3181 wm8994);
3182 if (ret != 0)
3183 dev_warn(codec->dev,
3184 "Failed to request Mic2 detect IRQ: %d\n",
3185 ret);
Mark Brown88766982010-03-29 20:57:12 +01003186
Mark Brown3a423152010-11-26 15:21:06 +00003187 ret = wm8994_request_irq(codec->control_data,
3188 WM8994_IRQ_MIC2_SHRT,
3189 wm8994_mic_irq, "Mic 2 short",
3190 wm8994);
3191 if (ret != 0)
3192 dev_warn(codec->dev,
3193 "Failed to request Mic2 short IRQ: %d\n",
3194 ret);
3195 break;
Mark Brown821edd22010-11-26 15:21:09 +00003196
3197 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003198 if (wm8994->micdet_irq) {
3199 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3200 wm8958_mic_irq,
3201 IRQF_TRIGGER_RISING,
3202 "Mic detect",
3203 wm8994);
3204 if (ret != 0)
3205 dev_warn(codec->dev,
3206 "Failed to request Mic detect IRQ: %d\n",
3207 ret);
3208 }
Mark Brown3a423152010-11-26 15:21:06 +00003209 }
Mark Brown88766982010-03-29 20:57:12 +01003210
Mark Brownc7ebf932011-07-12 19:47:59 +09003211 wm8994->fll_locked_irq = true;
3212 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
3213 ret = wm8994_request_irq(codec->control_data,
3214 WM8994_IRQ_FLL1_LOCK + i,
3215 wm8994_fll_locked_irq, "FLL lock",
3216 &wm8994->fll_locked[i]);
3217 if (ret != 0)
3218 wm8994->fll_locked_irq = false;
3219 }
3220
Mark Brown9e6e96a2010-01-29 17:47:12 +00003221 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3222 * configured on init - if a system wants to do this dynamically
3223 * at runtime we can deal with that then.
3224 */
3225 ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_1);
3226 if (ret < 0) {
3227 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003228 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003229 }
3230 if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
3231 wm8994->lrclk_shared[0] = 1;
3232 wm8994_dai[0].symmetric_rates = 1;
3233 } else {
3234 wm8994->lrclk_shared[0] = 0;
3235 }
3236
3237 ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_6);
3238 if (ret < 0) {
3239 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003240 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003241 }
3242 if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
3243 wm8994->lrclk_shared[1] = 1;
3244 wm8994_dai[1].symmetric_rates = 1;
3245 } else {
3246 wm8994->lrclk_shared[1] = 0;
3247 }
3248
Mark Brown9e6e96a2010-01-29 17:47:12 +00003249 wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
3250
Mark Brown9e6e96a2010-01-29 17:47:12 +00003251 /* Latch volume updates (right only; we always do left then right). */
Mark Brownbaa81602011-04-06 10:52:42 +09003252 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
3253 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003254 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3255 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003256 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME,
3257 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003258 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3259 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003260 snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME,
3261 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003262 snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3263 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003264 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME,
3265 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003266 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3267 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003268 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME,
3269 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003270 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3271 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003272 snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME,
3273 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003274 snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3275 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003276 snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME,
3277 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003278 snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3279 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003280 snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME,
3281 WM8994_DAC2_VU, WM8994_DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003282 snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3283 WM8994_DAC2_VU, WM8994_DAC2_VU);
3284
3285 /* Set the low bit of the 3D stereo depth so TLV matches */
3286 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3287 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3288 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3289 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3290 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3291 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3292 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3293 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3294 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3295
Mark Brown5b739672011-07-06 00:08:43 -07003296 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
3297 * use this; it only affects behaviour on idle TDM clock
3298 * cycles. */
3299 switch (control->type) {
3300 case WM8994:
3301 case WM8958:
3302 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3303 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3304 break;
3305 default:
3306 break;
3307 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01003308
Mark Brown9e6e96a2010-01-29 17:47:12 +00003309 wm8994_update_class_w(codec);
3310
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003311 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003312
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003313 wm_hubs_add_analogue_controls(codec);
3314 snd_soc_add_controls(codec, wm8994_snd_controls,
3315 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003316 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003317 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00003318
3319 switch (control->type) {
3320 case WM8994:
3321 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3322 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003323 if (wm8994->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003324 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3325 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003326 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3327 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003328 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3329 ARRAY_SIZE(wm8994_dac_revd_widgets));
3330 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003331 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3332 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003333 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3334 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003335 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3336 ARRAY_SIZE(wm8994_dac_widgets));
3337 }
Mark Brownc4431df2010-11-26 15:21:07 +00003338 break;
3339 case WM8958:
3340 snd_soc_add_controls(codec, wm8958_snd_controls,
3341 ARRAY_SIZE(wm8958_snd_controls));
3342 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3343 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brown780e2802011-03-11 18:00:19 +00003344 if (wm8994->revision < 1) {
3345 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3346 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3347 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3348 ARRAY_SIZE(wm8994_adc_revd_widgets));
3349 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3350 ARRAY_SIZE(wm8994_dac_revd_widgets));
3351 } else {
3352 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3353 ARRAY_SIZE(wm8994_lateclk_widgets));
3354 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3355 ARRAY_SIZE(wm8994_adc_widgets));
3356 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3357 ARRAY_SIZE(wm8994_dac_widgets));
3358 }
Mark Brownc4431df2010-11-26 15:21:07 +00003359 break;
3360 }
3361
3362
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003363 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003364 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003365
Mark Brownc4431df2010-11-26 15:21:07 +00003366 switch (control->type) {
3367 case WM8994:
3368 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
3369 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00003370
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003371 if (wm8994->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00003372 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3373 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003374 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3375 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3376 } else {
3377 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3378 ARRAY_SIZE(wm8994_lateclk_intercon));
3379 }
Mark Brownc4431df2010-11-26 15:21:07 +00003380 break;
3381 case WM8958:
Mark Brown780e2802011-03-11 18:00:19 +00003382 if (wm8994->revision < 1) {
3383 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3384 ARRAY_SIZE(wm8994_revd_intercon));
3385 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3386 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3387 } else {
3388 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3389 ARRAY_SIZE(wm8994_lateclk_intercon));
3390 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3391 ARRAY_SIZE(wm8958_intercon));
3392 }
Mark Brownf701a2e2011-03-09 19:31:01 +00003393
3394 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00003395 break;
3396 }
3397
Mark Brown9e6e96a2010-01-29 17:47:12 +00003398 return 0;
3399
Mark Brown88766982010-03-29 20:57:12 +01003400err_irq:
3401 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994);
3402 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994);
3403 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08003404 if (wm8994->micdet_irq)
3405 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09003406 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3407 wm8994_free_irq(codec->control_data, WM8994_IRQ_FLL1_LOCK + i,
3408 &wm8994->fll_locked[i]);
Mark Brownb30ead52011-07-12 15:47:17 +09003409 wm8994_free_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
3410 &wm8994->hubs);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003411 wm8994_free_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, codec);
Mark Brownf0b182b2011-08-16 12:01:27 +09003412 wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, codec);
3413 wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003414err:
3415 kfree(wm8994);
3416 return ret;
3417}
3418
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003419static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003420{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003421 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown3a423152010-11-26 15:21:06 +00003422 struct wm8994 *control = codec->control_data;
Mark Brownc7ebf932011-07-12 19:47:59 +09003423 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003424
3425 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003426
Mark Brown39fb51a2010-11-26 17:23:43 +00003427 pm_runtime_disable(codec->dev);
3428
Mark Brownc7ebf932011-07-12 19:47:59 +09003429 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3430 wm8994_free_irq(codec->control_data, WM8994_IRQ_FLL1_LOCK + i,
3431 &wm8994->fll_locked[i]);
3432
Mark Brownb30ead52011-07-12 15:47:17 +09003433 wm8994_free_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
3434 &wm8994->hubs);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003435 wm8994_free_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, codec);
Mark Brownf0b182b2011-08-16 12:01:27 +09003436 wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, codec);
3437 wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09003438
Mark Brown3a423152010-11-26 15:21:06 +00003439 switch (control->type) {
3440 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003441 if (wm8994->micdet_irq)
3442 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown3a423152010-11-26 15:21:06 +00003443 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET,
3444 wm8994);
3445 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT,
3446 wm8994);
3447 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET,
3448 wm8994);
3449 break;
Mark Brown821edd22010-11-26 15:21:09 +00003450
3451 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003452 if (wm8994->micdet_irq)
3453 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00003454 break;
Mark Brown3a423152010-11-26 15:21:06 +00003455 }
Mark Brownfbbf5922011-03-11 18:09:04 +00003456 if (wm8994->mbc)
3457 release_firmware(wm8994->mbc);
Mark Brown09e10d72011-03-16 22:57:47 +00003458 if (wm8994->mbc_vss)
3459 release_firmware(wm8994->mbc_vss);
Mark Brown31215872011-03-17 20:23:43 +00003460 if (wm8994->enh_eq)
3461 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08003462 kfree(wm8994->retune_mobile_texts);
3463 kfree(wm8994->drc_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003464 kfree(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003465
3466 return 0;
3467}
3468
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003469static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
3470 .probe = wm8994_codec_probe,
3471 .remove = wm8994_codec_remove,
3472 .suspend = wm8994_suspend,
3473 .resume = wm8994_resume,
Mark Brownca9aef52010-11-26 17:23:41 +00003474 .read = wm8994_read,
3475 .write = wm8994_write,
Mark Browneba19fd2010-11-19 16:09:15 +00003476 .readable_register = wm8994_readable,
3477 .volatile_register = wm8994_volatile,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003478 .set_bias_level = wm8994_set_bias_level,
Mark Brownca9aef52010-11-26 17:23:41 +00003479
3480 .reg_cache_size = WM8994_CACHE_SIZE,
3481 .reg_cache_default = wm8994_reg_defaults,
3482 .reg_word_size = 2,
Mark Brown2e19b0c2010-11-26 17:23:42 +00003483 .compress_type = SND_SOC_RBTREE_COMPRESSION,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003484};
3485
3486static int __devinit wm8994_probe(struct platform_device *pdev)
3487{
3488 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
3489 wm8994_dai, ARRAY_SIZE(wm8994_dai));
3490}
3491
3492static int __devexit wm8994_remove(struct platform_device *pdev)
3493{
3494 snd_soc_unregister_codec(&pdev->dev);
3495 return 0;
3496}
3497
Mark Brown9e6e96a2010-01-29 17:47:12 +00003498static struct platform_driver wm8994_codec_driver = {
3499 .driver = {
3500 .name = "wm8994-codec",
3501 .owner = THIS_MODULE,
3502 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003503 .probe = wm8994_probe,
3504 .remove = __devexit_p(wm8994_remove),
Mark Brown9e6e96a2010-01-29 17:47:12 +00003505};
3506
3507static __init int wm8994_init(void)
3508{
3509 return platform_driver_register(&wm8994_codec_driver);
3510}
3511module_init(wm8994_init);
3512
3513static __exit void wm8994_exit(void)
3514{
3515 platform_driver_unregister(&wm8994_codec_driver);
3516}
3517module_exit(wm8994_exit);
3518
3519
3520MODULE_DESCRIPTION("ASoC WM8994 driver");
3521MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
3522MODULE_LICENSE("GPL");
3523MODULE_ALIAS("platform:wm8994-codec");