blob: 207bccd156f1a1cdda4e3a9f49a0b697cc13658f [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);
Mark Brown8eeea522011-11-04 15:52:31 +000059 struct wm8994 *control = codec->control_data;
Mark Brownaf9af862011-03-16 21:05:06 +000060
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);
Axel Lin04f45c42011-10-04 20:07:03 +0800211 int change, new;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000212
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
Axel Lin04f45c42011-10-04 20:07:03 +0800232 change = snd_soc_update_bits(codec, WM8994_CLOCKING_1,
233 WM8994_SYSCLK_SRC, new);
234 if (!change)
Mark Brown9e6e96a2010-01-29 17:47:12 +0000235 return 0;
236
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200237 snd_soc_dapm_sync(&codec->dapm);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000238
239 return 0;
240}
241
242static int check_clk_sys(struct snd_soc_dapm_widget *source,
243 struct snd_soc_dapm_widget *sink)
244{
245 int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1);
246 const char *clk;
247
248 /* Check what we're currently using for CLK_SYS */
249 if (reg & WM8994_SYSCLK_SRC)
250 clk = "AIF2CLK";
251 else
252 clk = "AIF1CLK";
253
254 return strcmp(source->name, clk) == 0;
255}
256
257static const char *sidetone_hpf_text[] = {
258 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
259};
260
261static const struct soc_enum sidetone_hpf =
262 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
263
Uk Kim146fd572010-12-07 13:58:40 +0000264static const char *adc_hpf_text[] = {
265 "HiFi", "Voice 1", "Voice 2", "Voice 3"
266};
267
268static const struct soc_enum aif1adc1_hpf =
269 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text);
270
271static const struct soc_enum aif1adc2_hpf =
272 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text);
273
274static const struct soc_enum aif2adc_hpf =
275 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text);
276
Mark Brown9e6e96a2010-01-29 17:47:12 +0000277static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
278static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
279static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
280static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
281static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
Mark Brown1ddc07d2011-08-16 10:08:48 +0900282static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
Mark Brown81204c82011-05-24 17:35:53 +0800283static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv, 0, 900, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000284
285#define WM8994_DRC_SWITCH(xname, reg, shift) \
286{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
287 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
288 .put = wm8994_put_drc_sw, \
289 .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
290
291static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_value *ucontrol)
293{
294 struct soc_mixer_control *mc =
295 (struct soc_mixer_control *)kcontrol->private_value;
296 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
297 int mask, ret;
298
299 /* Can't enable both ADC and DAC paths simultaneously */
300 if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
301 mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
302 WM8994_AIF1ADC1R_DRC_ENA_MASK;
303 else
304 mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
305
306 ret = snd_soc_read(codec, mc->reg);
307 if (ret < 0)
308 return ret;
309 if (ret & mask)
310 return -EINVAL;
311
312 return snd_soc_put_volsw(kcontrol, ucontrol);
313}
314
Mark Brown9e6e96a2010-01-29 17:47:12 +0000315static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
316{
Mark Brownb2c812e2010-04-14 15:35:19 +0900317 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000318 struct wm8994_pdata *pdata = wm8994->pdata;
319 int base = wm8994_drc_base[drc];
320 int cfg = wm8994->drc_cfg[drc];
321 int save, i;
322
323 /* Save any enables; the configuration should clear them. */
324 save = snd_soc_read(codec, base);
325 save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
326 WM8994_AIF1ADC1R_DRC_ENA;
327
328 for (i = 0; i < WM8994_DRC_REGS; i++)
329 snd_soc_update_bits(codec, base + i, 0xffff,
330 pdata->drc_cfgs[cfg].regs[i]);
331
332 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
333 WM8994_AIF1ADC1L_DRC_ENA |
334 WM8994_AIF1ADC1R_DRC_ENA, save);
335}
336
337/* Icky as hell but saves code duplication */
338static int wm8994_get_drc(const char *name)
339{
340 if (strcmp(name, "AIF1DRC1 Mode") == 0)
341 return 0;
342 if (strcmp(name, "AIF1DRC2 Mode") == 0)
343 return 1;
344 if (strcmp(name, "AIF2DRC Mode") == 0)
345 return 2;
346 return -EINVAL;
347}
348
349static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
350 struct snd_ctl_elem_value *ucontrol)
351{
352 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000353 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000354 struct wm8994_pdata *pdata = wm8994->pdata;
355 int drc = wm8994_get_drc(kcontrol->id.name);
356 int value = ucontrol->value.integer.value[0];
357
358 if (drc < 0)
359 return drc;
360
361 if (value >= pdata->num_drc_cfgs)
362 return -EINVAL;
363
364 wm8994->drc_cfg[drc] = value;
365
366 wm8994_set_drc(codec, drc);
367
368 return 0;
369}
370
371static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
372 struct snd_ctl_elem_value *ucontrol)
373{
374 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900375 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000376 int drc = wm8994_get_drc(kcontrol->id.name);
377
378 ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
379
380 return 0;
381}
382
383static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
384{
Mark Brownb2c812e2010-04-14 15:35:19 +0900385 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000386 struct wm8994_pdata *pdata = wm8994->pdata;
387 int base = wm8994_retune_mobile_base[block];
388 int iface, best, best_val, save, i, cfg;
389
390 if (!pdata || !wm8994->num_retune_mobile_texts)
391 return;
392
393 switch (block) {
394 case 0:
395 case 1:
396 iface = 0;
397 break;
398 case 2:
399 iface = 1;
400 break;
401 default:
402 return;
403 }
404
405 /* Find the version of the currently selected configuration
406 * with the nearest sample rate. */
407 cfg = wm8994->retune_mobile_cfg[block];
408 best = 0;
409 best_val = INT_MAX;
410 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
411 if (strcmp(pdata->retune_mobile_cfgs[i].name,
412 wm8994->retune_mobile_texts[cfg]) == 0 &&
413 abs(pdata->retune_mobile_cfgs[i].rate
414 - wm8994->dac_rates[iface]) < best_val) {
415 best = i;
416 best_val = abs(pdata->retune_mobile_cfgs[i].rate
417 - wm8994->dac_rates[iface]);
418 }
419 }
420
421 dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
422 block,
423 pdata->retune_mobile_cfgs[best].name,
424 pdata->retune_mobile_cfgs[best].rate,
425 wm8994->dac_rates[iface]);
426
427 /* The EQ will be disabled while reconfiguring it, remember the
428 * current configuration.
429 */
430 save = snd_soc_read(codec, base);
431 save &= WM8994_AIF1DAC1_EQ_ENA;
432
433 for (i = 0; i < WM8994_EQ_REGS; i++)
434 snd_soc_update_bits(codec, base + i, 0xffff,
435 pdata->retune_mobile_cfgs[best].regs[i]);
436
437 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
438}
439
440/* Icky as hell but saves code duplication */
441static int wm8994_get_retune_mobile_block(const char *name)
442{
443 if (strcmp(name, "AIF1.1 EQ Mode") == 0)
444 return 0;
445 if (strcmp(name, "AIF1.2 EQ Mode") == 0)
446 return 1;
447 if (strcmp(name, "AIF2 EQ Mode") == 0)
448 return 2;
449 return -EINVAL;
450}
451
452static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
453 struct snd_ctl_elem_value *ucontrol)
454{
455 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000456 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000457 struct wm8994_pdata *pdata = wm8994->pdata;
458 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
459 int value = ucontrol->value.integer.value[0];
460
461 if (block < 0)
462 return block;
463
464 if (value >= pdata->num_retune_mobile_cfgs)
465 return -EINVAL;
466
467 wm8994->retune_mobile_cfg[block] = value;
468
469 wm8994_set_retune_mobile(codec, block);
470
471 return 0;
472}
473
474static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
475 struct snd_ctl_elem_value *ucontrol)
476{
477 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brown4a8d9292011-02-16 14:57:17 -0800478 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000479 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
480
481 ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
482
483 return 0;
484}
485
Mark Brown96b101e2010-11-18 15:49:38 +0000486static const char *aif_chan_src_text[] = {
Mark Brownf5548852010-08-31 19:39:48 +0100487 "Left", "Right"
488};
489
Mark Brown96b101e2010-11-18 15:49:38 +0000490static const struct soc_enum aif1adcl_src =
491 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
492
493static const struct soc_enum aif1adcr_src =
494 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
495
496static const struct soc_enum aif2adcl_src =
497 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
498
499static const struct soc_enum aif2adcr_src =
500 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
501
Mark Brownf5548852010-08-31 19:39:48 +0100502static const struct soc_enum aif1dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000503 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100504
505static const struct soc_enum aif1dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000506 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100507
508static const struct soc_enum aif2dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000509 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100510
511static const struct soc_enum aif2dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000512 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100513
Mark Brown154b26a2010-12-09 12:07:44 +0000514static const char *osr_text[] = {
515 "Low Power", "High Performance",
516};
517
518static const struct soc_enum dac_osr =
519 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
520
521static const struct soc_enum adc_osr =
522 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
523
Mark Brown9e6e96a2010-01-29 17:47:12 +0000524static const struct snd_kcontrol_new wm8994_snd_controls[] = {
525SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
526 WM8994_AIF1_ADC1_RIGHT_VOLUME,
527 1, 119, 0, digital_tlv),
528SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
529 WM8994_AIF1_ADC2_RIGHT_VOLUME,
530 1, 119, 0, digital_tlv),
531SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
532 WM8994_AIF2_ADC_RIGHT_VOLUME,
533 1, 119, 0, digital_tlv),
534
Mark Brown96b101e2010-11-18 15:49:38 +0000535SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
536SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000537SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
538SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
Mark Brown96b101e2010-11-18 15:49:38 +0000539
Mark Brownf5548852010-08-31 19:39:48 +0100540SOC_ENUM("AIF1DACL Source", aif1dacl_src),
541SOC_ENUM("AIF1DACR Source", aif1dacr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000542SOC_ENUM("AIF2DACL Source", aif2dacl_src),
543SOC_ENUM("AIF2DACR Source", aif2dacr_src),
Mark Brownf5548852010-08-31 19:39:48 +0100544
Mark Brown9e6e96a2010-01-29 17:47:12 +0000545SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
546 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
547SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
548 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
549SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
550 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
551
552SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
553SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
554
555SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
556SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
557SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
558
559WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
560WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
561WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
562
563WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
564WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
565WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
566
567WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
568WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
569WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
570
571SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
572 5, 12, 0, st_tlv),
573SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
574 0, 12, 0, st_tlv),
575SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
576 5, 12, 0, st_tlv),
577SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
578 0, 12, 0, st_tlv),
579SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
580SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
581
Uk Kim146fd572010-12-07 13:58:40 +0000582SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
583SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
584
585SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
586SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
587
588SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
589SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
590
Mark Brown154b26a2010-12-09 12:07:44 +0000591SOC_ENUM("ADC OSR", adc_osr),
592SOC_ENUM("DAC OSR", dac_osr),
593
Mark Brown9e6e96a2010-01-29 17:47:12 +0000594SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
595 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
596SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
597 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
598
599SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
600 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
601SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
602 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
603
604SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
605 6, 1, 1, wm_hubs_spkmix_tlv),
606SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
607 2, 1, 1, wm_hubs_spkmix_tlv),
608
609SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
610 6, 1, 1, wm_hubs_spkmix_tlv),
611SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
612 2, 1, 1, wm_hubs_spkmix_tlv),
613
614SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
615 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000616SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000617 8, 1, 0),
618SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
619 10, 15, 0, wm8994_3d_tlv),
620SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
621 8, 1, 0),
Mark Brown458350b2010-12-20 14:35:09 +0000622SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000623 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000624SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000625 8, 1, 0),
626};
627
628static const struct snd_kcontrol_new wm8994_eq_controls[] = {
629SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
630 eq_tlv),
631SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
632 eq_tlv),
633SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
634 eq_tlv),
635SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
636 eq_tlv),
637SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
638 eq_tlv),
639
640SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
641 eq_tlv),
642SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
643 eq_tlv),
644SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
645 eq_tlv),
646SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
647 eq_tlv),
648SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
649 eq_tlv),
650
651SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
652 eq_tlv),
653SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
654 eq_tlv),
655SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
656 eq_tlv),
657SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
658 eq_tlv),
659SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
660 eq_tlv),
661};
662
Mark Brown1ddc07d2011-08-16 10:08:48 +0900663static const char *wm8958_ng_text[] = {
664 "30ms", "125ms", "250ms", "500ms",
665};
666
667static const struct soc_enum wm8958_aif1dac1_ng_hold =
668 SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE,
669 WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text);
670
671static const struct soc_enum wm8958_aif1dac2_ng_hold =
672 SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE,
673 WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text);
674
675static const struct soc_enum wm8958_aif2dac_ng_hold =
676 SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE,
677 WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text);
678
Mark Brownc4431df2010-11-26 15:21:07 +0000679static const struct snd_kcontrol_new wm8958_snd_controls[] = {
680SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
Mark Brown1ddc07d2011-08-16 10:08:48 +0900681
682SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
683 WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
684SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
685SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
686 WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
687 7, 1, ng_tlv),
688
689SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
690 WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
691SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
692SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
693 WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
694 7, 1, ng_tlv),
695
696SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
697 WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
698SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
699SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
700 WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
701 7, 1, ng_tlv),
Mark Brownc4431df2010-11-26 15:21:07 +0000702};
703
Mark Brown81204c82011-05-24 17:35:53 +0800704static const struct snd_kcontrol_new wm1811_snd_controls[] = {
705SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
706 mixin_boost_tlv),
707SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
708 mixin_boost_tlv),
709};
710
Mark Brown9e6e96a2010-01-29 17:47:12 +0000711static int clk_sys_event(struct snd_soc_dapm_widget *w,
712 struct snd_kcontrol *kcontrol, int event)
713{
714 struct snd_soc_codec *codec = w->codec;
715
716 switch (event) {
717 case SND_SOC_DAPM_PRE_PMU:
718 return configure_clock(codec);
719
720 case SND_SOC_DAPM_POST_PMD:
721 configure_clock(codec);
722 break;
723 }
724
725 return 0;
726}
727
Mark Brown4b7ed832011-08-10 17:47:33 +0900728static void vmid_reference(struct snd_soc_codec *codec)
729{
730 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
731
732 wm8994->vmid_refcount++;
733
734 dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
735 wm8994->vmid_refcount);
736
737 if (wm8994->vmid_refcount == 1) {
738 /* Startup bias, VMID ramp & buffer */
739 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
740 WM8994_STARTUP_BIAS_ENA |
741 WM8994_VMID_BUF_ENA |
742 WM8994_VMID_RAMP_MASK,
743 WM8994_STARTUP_BIAS_ENA |
744 WM8994_VMID_BUF_ENA |
745 (0x11 << WM8994_VMID_RAMP_SHIFT));
746
747 /* Main bias enable, VMID=2x40k */
748 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
749 WM8994_BIAS_ENA |
750 WM8994_VMID_SEL_MASK,
751 WM8994_BIAS_ENA | 0x2);
752
753 msleep(20);
754 }
755}
756
757static void vmid_dereference(struct snd_soc_codec *codec)
758{
759 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
760
761 wm8994->vmid_refcount--;
762
763 dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
764 wm8994->vmid_refcount);
765
766 if (wm8994->vmid_refcount == 0) {
767 /* Switch over to startup biases */
768 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
769 WM8994_BIAS_SRC |
770 WM8994_STARTUP_BIAS_ENA |
771 WM8994_VMID_BUF_ENA |
772 WM8994_VMID_RAMP_MASK,
773 WM8994_BIAS_SRC |
774 WM8994_STARTUP_BIAS_ENA |
775 WM8994_VMID_BUF_ENA |
776 (1 << WM8994_VMID_RAMP_SHIFT));
777
778 /* Disable main biases */
779 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
780 WM8994_BIAS_ENA |
781 WM8994_VMID_SEL_MASK, 0);
782
783 /* Discharge line */
784 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
785 WM8994_LINEOUT1_DISCH |
786 WM8994_LINEOUT2_DISCH,
787 WM8994_LINEOUT1_DISCH |
788 WM8994_LINEOUT2_DISCH);
789
790 msleep(5);
791
792 /* Switch off startup biases */
793 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
794 WM8994_BIAS_SRC |
795 WM8994_STARTUP_BIAS_ENA |
796 WM8994_VMID_BUF_ENA |
797 WM8994_VMID_RAMP_MASK, 0);
798 }
799}
800
801static int vmid_event(struct snd_soc_dapm_widget *w,
802 struct snd_kcontrol *kcontrol, int event)
803{
804 struct snd_soc_codec *codec = w->codec;
805
806 switch (event) {
807 case SND_SOC_DAPM_PRE_PMU:
808 vmid_reference(codec);
809 break;
810
811 case SND_SOC_DAPM_POST_PMD:
812 vmid_dereference(codec);
813 break;
814 }
815
816 return 0;
817}
818
Mark Brown9e6e96a2010-01-29 17:47:12 +0000819static void wm8994_update_class_w(struct snd_soc_codec *codec)
820{
Mark Brownfec6dd82010-10-27 13:48:36 -0700821 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000822 int enable = 1;
823 int source = 0; /* GCC flow analysis can't track enable */
824 int reg, reg_r;
825
826 /* Only support direct DAC->headphone paths */
827 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
828 if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
Mark Brownee839a22010-04-20 13:57:08 +0900829 dev_vdbg(codec->dev, "HPL connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000830 enable = 0;
831 }
832
833 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
834 if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
Mark Brownee839a22010-04-20 13:57:08 +0900835 dev_vdbg(codec->dev, "HPR connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000836 enable = 0;
837 }
838
839 /* We also need the same setting for L/R and only one path */
840 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
841 switch (reg) {
842 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900843 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000844 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
845 break;
846 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900847 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000848 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
849 break;
850 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900851 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000852 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
853 break;
854 default:
Mark Brownee839a22010-04-20 13:57:08 +0900855 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000856 enable = 0;
857 break;
858 }
859
860 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
861 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +0900862 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000863 enable = 0;
864 }
865
866 if (enable) {
867 dev_dbg(codec->dev, "Class W enabled\n");
868 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
869 WM8994_CP_DYN_PWR |
870 WM8994_CP_DYN_SRC_SEL_MASK,
871 source | WM8994_CP_DYN_PWR);
Mark Brownfec6dd82010-10-27 13:48:36 -0700872 wm8994->hubs.class_w = true;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000873
874 } else {
875 dev_dbg(codec->dev, "Class W disabled\n");
876 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
877 WM8994_CP_DYN_PWR, 0);
Mark Brownfec6dd82010-10-27 13:48:36 -0700878 wm8994->hubs.class_w = false;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000879 }
880}
881
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000882static int late_enable_ev(struct snd_soc_dapm_widget *w,
883 struct snd_kcontrol *kcontrol, int event)
884{
885 struct snd_soc_codec *codec = w->codec;
886 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
887
888 switch (event) {
889 case SND_SOC_DAPM_PRE_PMU:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000890 if (wm8994->aif1clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000891 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
892 WM8994_AIF1CLK_ENA_MASK,
893 WM8994_AIF1CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000894 wm8994->aif1clk_enable = 0;
895 }
896 if (wm8994->aif2clk_enable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000897 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
898 WM8994_AIF2CLK_ENA_MASK,
899 WM8994_AIF2CLK_ENA);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000900 wm8994->aif2clk_enable = 0;
901 }
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000902 break;
903 }
904
Mark Brownc6b7b572011-03-11 18:13:12 +0000905 /* We may also have postponed startup of DSP, handle that. */
906 wm8958_aif_ev(w, kcontrol, event);
907
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000908 return 0;
909}
910
911static int late_disable_ev(struct snd_soc_dapm_widget *w,
912 struct snd_kcontrol *kcontrol, int event)
913{
914 struct snd_soc_codec *codec = w->codec;
915 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
916
917 switch (event) {
918 case SND_SOC_DAPM_POST_PMD:
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000919 if (wm8994->aif1clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000920 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
921 WM8994_AIF1CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000922 wm8994->aif1clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000923 }
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000924 if (wm8994->aif2clk_disable) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000925 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
926 WM8994_AIF2CLK_ENA_MASK, 0);
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000927 wm8994->aif2clk_disable = 0;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000928 }
929 break;
930 }
931
932 return 0;
933}
934
935static int aif1clk_ev(struct snd_soc_dapm_widget *w,
936 struct snd_kcontrol *kcontrol, int event)
937{
938 struct snd_soc_codec *codec = w->codec;
939 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
940
941 switch (event) {
942 case SND_SOC_DAPM_PRE_PMU:
943 wm8994->aif1clk_enable = 1;
944 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000945 case SND_SOC_DAPM_POST_PMD:
946 wm8994->aif1clk_disable = 1;
947 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000948 }
949
950 return 0;
951}
952
953static int aif2clk_ev(struct snd_soc_dapm_widget *w,
954 struct snd_kcontrol *kcontrol, int event)
955{
956 struct snd_soc_codec *codec = w->codec;
957 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
958
959 switch (event) {
960 case SND_SOC_DAPM_PRE_PMU:
961 wm8994->aif2clk_enable = 1;
962 break;
Dimitris Papastamosa3cff812011-02-28 17:24:11 +0000963 case SND_SOC_DAPM_POST_PMD:
964 wm8994->aif2clk_disable = 1;
965 break;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000966 }
967
968 return 0;
969}
970
Dimitris Papastamos04d28682011-03-01 11:47:10 +0000971static int adc_mux_ev(struct snd_soc_dapm_widget *w,
972 struct snd_kcontrol *kcontrol, int event)
973{
974 late_enable_ev(w, kcontrol, event);
975 return 0;
976}
977
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +0000978static int micbias_ev(struct snd_soc_dapm_widget *w,
979 struct snd_kcontrol *kcontrol, int event)
980{
981 late_enable_ev(w, kcontrol, event);
982 return 0;
983}
984
Dimitris Papastamosc52fd022011-02-11 16:32:12 +0000985static int dac_ev(struct snd_soc_dapm_widget *w,
986 struct snd_kcontrol *kcontrol, int event)
987{
988 struct snd_soc_codec *codec = w->codec;
989 unsigned int mask = 1 << w->shift;
990
991 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
992 mask, mask);
993 return 0;
994}
995
Mark Brown9e6e96a2010-01-29 17:47:12 +0000996static const char *hp_mux_text[] = {
997 "Mixer",
998 "DAC",
999};
1000
1001#define WM8994_HP_ENUM(xname, xenum) \
1002{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1003 .info = snd_soc_info_enum_double, \
1004 .get = snd_soc_dapm_get_enum_double, \
1005 .put = wm8994_put_hp_enum, \
1006 .private_value = (unsigned long)&xenum }
1007
1008static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
1009 struct snd_ctl_elem_value *ucontrol)
1010{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001011 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1012 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001013 struct snd_soc_codec *codec = w->codec;
1014 int ret;
1015
1016 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1017
1018 wm8994_update_class_w(codec);
1019
1020 return ret;
1021}
1022
1023static const struct soc_enum hpl_enum =
1024 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
1025
1026static const struct snd_kcontrol_new hpl_mux =
1027 WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
1028
1029static const struct soc_enum hpr_enum =
1030 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
1031
1032static const struct snd_kcontrol_new hpr_mux =
1033 WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
1034
1035static const char *adc_mux_text[] = {
1036 "ADC",
1037 "DMIC",
1038};
1039
1040static const struct soc_enum adc_enum =
1041 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1042
1043static const struct snd_kcontrol_new adcl_mux =
1044 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1045
1046static const struct snd_kcontrol_new adcr_mux =
1047 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1048
1049static const struct snd_kcontrol_new left_speaker_mixer[] = {
1050SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1051SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1052SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1053SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1054SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1055};
1056
1057static const struct snd_kcontrol_new right_speaker_mixer[] = {
1058SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1059SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1060SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1061SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1062SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1063};
1064
1065/* Debugging; dump chip status after DAPM transitions */
1066static int post_ev(struct snd_soc_dapm_widget *w,
1067 struct snd_kcontrol *kcontrol, int event)
1068{
1069 struct snd_soc_codec *codec = w->codec;
1070 dev_dbg(codec->dev, "SRC status: %x\n",
1071 snd_soc_read(codec,
1072 WM8994_RATE_STATUS));
1073 return 0;
1074}
1075
1076static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1077SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1078 1, 1, 0),
1079SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1080 0, 1, 0),
1081};
1082
1083static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1084SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1085 1, 1, 0),
1086SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1087 0, 1, 0),
1088};
1089
Mark Browna3257ba2010-07-19 14:02:34 +01001090static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1091SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1092 1, 1, 0),
1093SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1094 0, 1, 0),
1095};
1096
1097static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1098SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1099 1, 1, 0),
1100SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1101 0, 1, 0),
1102};
1103
Mark Brown9e6e96a2010-01-29 17:47:12 +00001104static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1105SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1106 5, 1, 0),
1107SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1108 4, 1, 0),
1109SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1110 2, 1, 0),
1111SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1112 1, 1, 0),
1113SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1114 0, 1, 0),
1115};
1116
1117static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1118SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1119 5, 1, 0),
1120SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1121 4, 1, 0),
1122SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1123 2, 1, 0),
1124SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1125 1, 1, 0),
1126SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1127 0, 1, 0),
1128};
1129
1130#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1131{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1132 .info = snd_soc_info_volsw, \
1133 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1134 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1135
1136static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1137 struct snd_ctl_elem_value *ucontrol)
1138{
Jarkko Nikula9d035452011-05-13 19:16:52 +03001139 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1140 struct snd_soc_dapm_widget *w = wlist->widgets[0];
Mark Brown9e6e96a2010-01-29 17:47:12 +00001141 struct snd_soc_codec *codec = w->codec;
1142 int ret;
1143
1144 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1145
1146 wm8994_update_class_w(codec);
1147
1148 return ret;
1149}
1150
1151static const struct snd_kcontrol_new dac1l_mix[] = {
1152WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1153 5, 1, 0),
1154WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1155 4, 1, 0),
1156WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1157 2, 1, 0),
1158WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1159 1, 1, 0),
1160WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1161 0, 1, 0),
1162};
1163
1164static const struct snd_kcontrol_new dac1r_mix[] = {
1165WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1166 5, 1, 0),
1167WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1168 4, 1, 0),
1169WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1170 2, 1, 0),
1171WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1172 1, 1, 0),
1173WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1174 0, 1, 0),
1175};
1176
1177static const char *sidetone_text[] = {
1178 "ADC/DMIC1", "DMIC2",
1179};
1180
1181static const struct soc_enum sidetone1_enum =
1182 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1183
1184static const struct snd_kcontrol_new sidetone1_mux =
1185 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1186
1187static const struct soc_enum sidetone2_enum =
1188 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1189
1190static const struct snd_kcontrol_new sidetone2_mux =
1191 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1192
1193static const char *aif1dac_text[] = {
1194 "AIF1DACDAT", "AIF3DACDAT",
1195};
1196
1197static const struct soc_enum aif1dac_enum =
1198 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1199
1200static const struct snd_kcontrol_new aif1dac_mux =
1201 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1202
1203static const char *aif2dac_text[] = {
1204 "AIF2DACDAT", "AIF3DACDAT",
1205};
1206
1207static const struct soc_enum aif2dac_enum =
1208 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1209
1210static const struct snd_kcontrol_new aif2dac_mux =
1211 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1212
1213static const char *aif2adc_text[] = {
1214 "AIF2ADCDAT", "AIF3DACDAT",
1215};
1216
1217static const struct soc_enum aif2adc_enum =
1218 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1219
1220static const struct snd_kcontrol_new aif2adc_mux =
1221 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1222
1223static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001224 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001225};
1226
Mark Brownc4431df2010-11-26 15:21:07 +00001227static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001228 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1229
Mark Brownc4431df2010-11-26 15:21:07 +00001230static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1231 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1232
1233static const struct soc_enum wm8958_aif3adc_enum =
1234 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1235
1236static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1237 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1238
1239static const char *mono_pcm_out_text[] = {
1240 "None", "AIF2ADCL", "AIF2ADCR",
1241};
1242
1243static const struct soc_enum mono_pcm_out_enum =
1244 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1245
1246static const struct snd_kcontrol_new mono_pcm_out_mux =
1247 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1248
1249static const char *aif2dac_src_text[] = {
1250 "AIF2", "AIF3",
1251};
1252
1253/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1254static const struct soc_enum aif2dacl_src_enum =
1255 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1256
1257static const struct snd_kcontrol_new aif2dacl_src_mux =
1258 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1259
1260static const struct soc_enum aif2dacr_src_enum =
1261 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1262
1263static const struct snd_kcontrol_new aif2dacr_src_mux =
1264 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001265
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001266static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1267SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_ev,
1268 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1269SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_ev,
1270 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1271
1272SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1273 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1274SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1275 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1276SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1277 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1278SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1279 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Mark Brownb70a51b2011-06-29 00:21:09 -07001280SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
1281 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1282
1283SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1284 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
1285 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1286SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1287 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1288 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1289SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux,
1290 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1291SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux,
1292 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001293
1294SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1295};
1296
1297static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1298SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0),
Mark Brownb70a51b2011-06-29 00:21:09 -07001299SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0),
1300SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
1301SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1302 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1303SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1304 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1305SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
1306SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001307};
1308
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001309static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1310SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1311 dac_ev, SND_SOC_DAPM_PRE_PMU),
1312SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1313 dac_ev, SND_SOC_DAPM_PRE_PMU),
1314SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1315 dac_ev, SND_SOC_DAPM_PRE_PMU),
1316SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1317 dac_ev, SND_SOC_DAPM_PRE_PMU),
1318};
1319
1320static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1321SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
Mark Brown0627bd22011-03-09 19:09:17 +00001322SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001323SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1324SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1325};
1326
Dimitris Papastamos04d28682011-03-01 11:47:10 +00001327static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
1328SND_SOC_DAPM_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
1329 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1330SND_SOC_DAPM_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
1331 adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
1332};
1333
1334static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
1335SND_SOC_DAPM_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1336SND_SOC_DAPM_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
1337};
1338
Mark Brown9e6e96a2010-01-29 17:47:12 +00001339static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1340SND_SOC_DAPM_INPUT("DMIC1DAT"),
1341SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001342SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001343
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001344SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
1345 SND_SOC_DAPM_PRE_PMU),
Mark Brown4b7ed832011-08-10 17:47:33 +09001346SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
1347 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Dimitris Papastamosb462c6e2011-03-01 12:54:39 +00001348
Mark Brown9e6e96a2010-01-29 17:47:12 +00001349SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1350 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1351
1352SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0),
1353SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0),
1354SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0),
1355
Mark Brown7f94de42011-02-03 16:27:34 +00001356SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001357 0, WM8994_POWER_MANAGEMENT_4, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001358SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001359 0, WM8994_POWER_MANAGEMENT_4, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001360SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1361 WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001362 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001363SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1364 WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001365 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001366
Mark Brown7f94de42011-02-03 16:27:34 +00001367SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001368 0, WM8994_POWER_MANAGEMENT_4, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001369SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001370 0, WM8994_POWER_MANAGEMENT_4, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001371SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1372 WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001373 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001374SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1375 WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001376 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001377
1378SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1379 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1380SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1381 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1382
Mark Browna3257ba2010-07-19 14:02:34 +01001383SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1384 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1385SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1386 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1387
Mark Brown9e6e96a2010-01-29 17:47:12 +00001388SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1389 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1390SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1391 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1392
1393SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1394SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1395
1396SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1397 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1398SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1399 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1400
1401SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1402 WM8994_POWER_MANAGEMENT_4, 13, 0),
1403SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1404 WM8994_POWER_MANAGEMENT_4, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001405SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1406 WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
1407 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1408SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1409 WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
1410 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001411
1412SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1413SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001414SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001415SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
1416
1417SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1418SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1419SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001420
1421SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
Axel Lin35024f42011-10-20 12:13:24 +08001422SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001423
1424SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1425
1426SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1427SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1428SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1429SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1430
1431/* Power is done with the muxes since the ADC power also controls the
1432 * downsampling chain, the chip will automatically manage the analogue
1433 * specific portions.
1434 */
1435SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1436SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1437
Mark Brown9e6e96a2010-01-29 17:47:12 +00001438SND_SOC_DAPM_POST("Debug log", post_ev),
1439};
1440
Mark Brownc4431df2010-11-26 15:21:07 +00001441static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1442SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1443};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001444
Mark Brownc4431df2010-11-26 15:21:07 +00001445static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1446SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1447SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1448SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1449SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1450};
1451
1452static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001453 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1454 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1455
1456 { "DSP1CLK", NULL, "CLK_SYS" },
1457 { "DSP2CLK", NULL, "CLK_SYS" },
1458 { "DSPINTCLK", NULL, "CLK_SYS" },
1459
1460 { "AIF1ADC1L", NULL, "AIF1CLK" },
1461 { "AIF1ADC1L", NULL, "DSP1CLK" },
1462 { "AIF1ADC1R", NULL, "AIF1CLK" },
1463 { "AIF1ADC1R", NULL, "DSP1CLK" },
1464 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1465
1466 { "AIF1DAC1L", NULL, "AIF1CLK" },
1467 { "AIF1DAC1L", NULL, "DSP1CLK" },
1468 { "AIF1DAC1R", NULL, "AIF1CLK" },
1469 { "AIF1DAC1R", NULL, "DSP1CLK" },
1470 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1471
1472 { "AIF1ADC2L", NULL, "AIF1CLK" },
1473 { "AIF1ADC2L", NULL, "DSP1CLK" },
1474 { "AIF1ADC2R", NULL, "AIF1CLK" },
1475 { "AIF1ADC2R", NULL, "DSP1CLK" },
1476 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1477
1478 { "AIF1DAC2L", NULL, "AIF1CLK" },
1479 { "AIF1DAC2L", NULL, "DSP1CLK" },
1480 { "AIF1DAC2R", NULL, "AIF1CLK" },
1481 { "AIF1DAC2R", NULL, "DSP1CLK" },
1482 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1483
1484 { "AIF2ADCL", NULL, "AIF2CLK" },
1485 { "AIF2ADCL", NULL, "DSP2CLK" },
1486 { "AIF2ADCR", NULL, "AIF2CLK" },
1487 { "AIF2ADCR", NULL, "DSP2CLK" },
1488 { "AIF2ADCR", NULL, "DSPINTCLK" },
1489
1490 { "AIF2DACL", NULL, "AIF2CLK" },
1491 { "AIF2DACL", NULL, "DSP2CLK" },
1492 { "AIF2DACR", NULL, "AIF2CLK" },
1493 { "AIF2DACR", NULL, "DSP2CLK" },
1494 { "AIF2DACR", NULL, "DSPINTCLK" },
1495
1496 { "DMIC1L", NULL, "DMIC1DAT" },
1497 { "DMIC1L", NULL, "CLK_SYS" },
1498 { "DMIC1R", NULL, "DMIC1DAT" },
1499 { "DMIC1R", NULL, "CLK_SYS" },
1500 { "DMIC2L", NULL, "DMIC2DAT" },
1501 { "DMIC2L", NULL, "CLK_SYS" },
1502 { "DMIC2R", NULL, "DMIC2DAT" },
1503 { "DMIC2R", NULL, "CLK_SYS" },
1504
1505 { "ADCL", NULL, "AIF1CLK" },
1506 { "ADCL", NULL, "DSP1CLK" },
1507 { "ADCL", NULL, "DSPINTCLK" },
1508
1509 { "ADCR", NULL, "AIF1CLK" },
1510 { "ADCR", NULL, "DSP1CLK" },
1511 { "ADCR", NULL, "DSPINTCLK" },
1512
1513 { "ADCL Mux", "ADC", "ADCL" },
1514 { "ADCL Mux", "DMIC", "DMIC1L" },
1515 { "ADCR Mux", "ADC", "ADCR" },
1516 { "ADCR Mux", "DMIC", "DMIC1R" },
1517
1518 { "DAC1L", NULL, "AIF1CLK" },
1519 { "DAC1L", NULL, "DSP1CLK" },
1520 { "DAC1L", NULL, "DSPINTCLK" },
1521
1522 { "DAC1R", NULL, "AIF1CLK" },
1523 { "DAC1R", NULL, "DSP1CLK" },
1524 { "DAC1R", NULL, "DSPINTCLK" },
1525
1526 { "DAC2L", NULL, "AIF2CLK" },
1527 { "DAC2L", NULL, "DSP2CLK" },
1528 { "DAC2L", NULL, "DSPINTCLK" },
1529
1530 { "DAC2R", NULL, "AIF2DACR" },
1531 { "DAC2R", NULL, "AIF2CLK" },
1532 { "DAC2R", NULL, "DSP2CLK" },
1533 { "DAC2R", NULL, "DSPINTCLK" },
1534
1535 { "TOCLK", NULL, "CLK_SYS" },
1536
1537 /* AIF1 outputs */
1538 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1539 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1540 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1541
1542 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1543 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1544 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1545
Mark Browna3257ba2010-07-19 14:02:34 +01001546 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1547 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1548 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1549
1550 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1551 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1552 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1553
Mark Brown9e6e96a2010-01-29 17:47:12 +00001554 /* Pin level routing for AIF3 */
1555 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1556 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1557 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1558 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1559
Mark Brown9e6e96a2010-01-29 17:47:12 +00001560 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1561 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1562 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1563 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1564 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1565 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1566 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1567
1568 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001569 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1570 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1571 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1572 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1573 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1574
Mark Brown9e6e96a2010-01-29 17:47:12 +00001575 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1576 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1577 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1578 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1579 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1580
1581 /* DAC2/AIF2 outputs */
1582 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001583 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1584 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1585 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1586 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1587 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1588
1589 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001590 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1591 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1592 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1593 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1594 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1595
Mark Brown7f94de42011-02-03 16:27:34 +00001596 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1597 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1598 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1599 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1600
Mark Brown9e6e96a2010-01-29 17:47:12 +00001601 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1602
1603 /* AIF3 output */
1604 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1605 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1606 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1607 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1608 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1609 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1610 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1611 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1612
1613 /* Sidetone */
1614 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1615 { "Left Sidetone", "DMIC2", "DMIC2L" },
1616 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1617 { "Right Sidetone", "DMIC2", "DMIC2R" },
1618
1619 /* Output stages */
1620 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1621 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1622
1623 { "SPKL", "DAC1 Switch", "DAC1L" },
1624 { "SPKL", "DAC2 Switch", "DAC2L" },
1625
1626 { "SPKR", "DAC1 Switch", "DAC1R" },
1627 { "SPKR", "DAC2 Switch", "DAC2R" },
1628
1629 { "Left Headphone Mux", "DAC", "DAC1L" },
1630 { "Right Headphone Mux", "DAC", "DAC1R" },
1631};
1632
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001633static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1634 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1635 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1636 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1637 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1638 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1639 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1640 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1641 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1642};
1643
1644static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1645 { "DAC1L", NULL, "DAC1L Mixer" },
1646 { "DAC1R", NULL, "DAC1R Mixer" },
1647 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1648 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1649};
1650
Mark Brown6ed8f142011-02-03 16:27:35 +00001651static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1652 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1653 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1654 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1655 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
Mark Brownb793eb62011-07-14 18:21:37 +09001656 { "MICBIAS1", NULL, "CLK_SYS" },
1657 { "MICBIAS1", NULL, "MICBIAS Supply" },
1658 { "MICBIAS2", NULL, "CLK_SYS" },
1659 { "MICBIAS2", NULL, "MICBIAS Supply" },
Mark Brown6ed8f142011-02-03 16:27:35 +00001660};
1661
Mark Brownc4431df2010-11-26 15:21:07 +00001662static const struct snd_soc_dapm_route wm8994_intercon[] = {
1663 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1664 { "AIF2DACR", NULL, "AIF2DAC Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001665 { "MICBIAS1", NULL, "VMID" },
1666 { "MICBIAS2", NULL, "VMID" },
Mark Brownc4431df2010-11-26 15:21:07 +00001667};
1668
1669static const struct snd_soc_dapm_route wm8958_intercon[] = {
1670 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1671 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1672
1673 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1674 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1675 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1676 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1677
1678 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1679 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1680
1681 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1682};
1683
Mark Brown9e6e96a2010-01-29 17:47:12 +00001684/* The size in bits of the FLL divide multiplied by 10
1685 * to allow rounding later */
1686#define FIXED_FLL_SIZE ((1 << 16) * 10)
1687
1688struct fll_div {
1689 u16 outdiv;
1690 u16 n;
1691 u16 k;
1692 u16 clk_ref_div;
1693 u16 fll_fratio;
1694};
1695
1696static int wm8994_get_fll_config(struct fll_div *fll,
1697 int freq_in, int freq_out)
1698{
1699 u64 Kpart;
1700 unsigned int K, Ndiv, Nmod;
1701
1702 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
1703
1704 /* Scale the input frequency down to <= 13.5MHz */
1705 fll->clk_ref_div = 0;
1706 while (freq_in > 13500000) {
1707 fll->clk_ref_div++;
1708 freq_in /= 2;
1709
1710 if (fll->clk_ref_div > 3)
1711 return -EINVAL;
1712 }
1713 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1714
1715 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1716 fll->outdiv = 3;
1717 while (freq_out * (fll->outdiv + 1) < 90000000) {
1718 fll->outdiv++;
1719 if (fll->outdiv > 63)
1720 return -EINVAL;
1721 }
1722 freq_out *= fll->outdiv + 1;
1723 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1724
1725 if (freq_in > 1000000) {
1726 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001727 } else if (freq_in > 256000) {
1728 fll->fll_fratio = 1;
1729 freq_in *= 2;
1730 } else if (freq_in > 128000) {
1731 fll->fll_fratio = 2;
1732 freq_in *= 4;
1733 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001734 fll->fll_fratio = 3;
1735 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001736 } else {
1737 fll->fll_fratio = 4;
1738 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001739 }
1740 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1741
1742 /* Now, calculate N.K */
1743 Ndiv = freq_out / freq_in;
1744
1745 fll->n = Ndiv;
1746 Nmod = freq_out % freq_in;
1747 pr_debug("Nmod=%d\n", Nmod);
1748
1749 /* Calculate fractional part - scale up so we can round. */
1750 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
1751
1752 do_div(Kpart, freq_in);
1753
1754 K = Kpart & 0xFFFFFFFF;
1755
1756 if ((K % 10) >= 5)
1757 K += 5;
1758
1759 /* Move down to proper range now rounding is done */
1760 fll->k = K / 10;
1761
1762 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1763
1764 return 0;
1765}
1766
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001767static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001768 unsigned int freq_in, unsigned int freq_out)
1769{
Mark Brownb2c812e2010-04-14 15:35:19 +09001770 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown4b7ed832011-08-10 17:47:33 +09001771 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001772 int reg_offset, ret;
1773 struct fll_div fll;
1774 u16 reg, aif1, aif2;
Mark Brownc7ebf932011-07-12 19:47:59 +09001775 unsigned long timeout;
Mark Brown4b7ed832011-08-10 17:47:33 +09001776 bool was_enabled;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001777
1778 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
1779 & WM8994_AIF1CLK_ENA;
1780
1781 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
1782 & WM8994_AIF2CLK_ENA;
1783
1784 switch (id) {
1785 case WM8994_FLL1:
1786 reg_offset = 0;
1787 id = 0;
1788 break;
1789 case WM8994_FLL2:
1790 reg_offset = 0x20;
1791 id = 1;
1792 break;
1793 default:
1794 return -EINVAL;
1795 }
1796
Mark Brown4b7ed832011-08-10 17:47:33 +09001797 reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
1798 was_enabled = reg & WM8994_FLL1_ENA;
1799
Mark Brown136ff2a2010-04-20 12:56:18 +09001800 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09001801 case 0:
1802 /* Allow no source specification when stopping */
1803 if (freq_out)
1804 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00001805 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09001806 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09001807 case WM8994_FLL_SRC_MCLK1:
1808 case WM8994_FLL_SRC_MCLK2:
1809 case WM8994_FLL_SRC_LRCLK:
1810 case WM8994_FLL_SRC_BCLK:
1811 break;
1812 default:
1813 return -EINVAL;
1814 }
1815
Mark Brown9e6e96a2010-01-29 17:47:12 +00001816 /* Are we changing anything? */
1817 if (wm8994->fll[id].src == src &&
1818 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
1819 return 0;
1820
1821 /* If we're stopping the FLL redo the old config - no
1822 * registers will actually be written but we avoid GCC flow
1823 * analysis bugs spewing warnings.
1824 */
1825 if (freq_out)
1826 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
1827 else
1828 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
1829 wm8994->fll[id].out);
1830 if (ret < 0)
1831 return ret;
1832
1833 /* Gate the AIF clocks while we reclock */
1834 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1835 WM8994_AIF1CLK_ENA, 0);
1836 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1837 WM8994_AIF2CLK_ENA, 0);
1838
1839 /* We always need to disable the FLL while reconfiguring */
1840 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1841 WM8994_FLL1_ENA, 0);
1842
1843 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
1844 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
1845 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
1846 WM8994_FLL1_OUTDIV_MASK |
1847 WM8994_FLL1_FRATIO_MASK, reg);
1848
1849 snd_soc_write(codec, WM8994_FLL1_CONTROL_3 + reg_offset, fll.k);
1850
1851 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
1852 WM8994_FLL1_N_MASK,
1853 fll.n << WM8994_FLL1_N_SHIFT);
1854
1855 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brown136ff2a2010-04-20 12:56:18 +09001856 WM8994_FLL1_REFCLK_DIV_MASK |
1857 WM8994_FLL1_REFCLK_SRC_MASK,
1858 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
1859 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00001860
Mark Brownf0f50392011-07-16 03:12:18 +09001861 /* Clear any pending completion from a previous failure */
1862 try_wait_for_completion(&wm8994->fll_locked[id]);
1863
Mark Brown9e6e96a2010-01-29 17:47:12 +00001864 /* Enable (with fractional mode if required) */
1865 if (freq_out) {
Mark Brown4b7ed832011-08-10 17:47:33 +09001866 /* Enable VMID if we need it */
1867 if (!was_enabled) {
1868 switch (control->type) {
1869 case WM8994:
1870 vmid_reference(codec);
1871 break;
1872 case WM8958:
1873 if (wm8994->revision < 1)
1874 vmid_reference(codec);
1875 break;
1876 default:
1877 break;
1878 }
1879 }
1880
Mark Brown9e6e96a2010-01-29 17:47:12 +00001881 if (fll.k)
1882 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
1883 else
1884 reg = WM8994_FLL1_ENA;
1885 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1886 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
1887 reg);
Mark Brown8e9ddf82011-07-01 17:24:46 -07001888
Mark Brownc7ebf932011-07-12 19:47:59 +09001889 if (wm8994->fll_locked_irq) {
1890 timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
1891 msecs_to_jiffies(10));
1892 if (timeout == 0)
1893 dev_warn(codec->dev,
1894 "Timed out waiting for FLL lock\n");
1895 } else {
1896 msleep(5);
1897 }
Mark Brown4b7ed832011-08-10 17:47:33 +09001898 } else {
1899 if (was_enabled) {
1900 switch (control->type) {
1901 case WM8994:
1902 vmid_dereference(codec);
1903 break;
1904 case WM8958:
1905 if (wm8994->revision < 1)
1906 vmid_dereference(codec);
1907 break;
1908 default:
1909 break;
1910 }
1911 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00001912 }
1913
1914 wm8994->fll[id].in = freq_in;
1915 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09001916 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001917
1918 /* Enable any gated AIF clocks */
1919 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1920 WM8994_AIF1CLK_ENA, aif1);
1921 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1922 WM8994_AIF2CLK_ENA, aif2);
1923
1924 configure_clock(codec);
1925
1926 return 0;
1927}
1928
Mark Brownc7ebf932011-07-12 19:47:59 +09001929static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
1930{
1931 struct completion *completion = data;
1932
1933 complete(completion);
1934
1935 return IRQ_HANDLED;
1936}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001937
Mark Brown66b47fd2010-07-08 11:25:43 +09001938static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
1939
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001940static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
1941 unsigned int freq_in, unsigned int freq_out)
1942{
1943 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
1944}
1945
Mark Brown9e6e96a2010-01-29 17:47:12 +00001946static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
1947 int clk_id, unsigned int freq, int dir)
1948{
1949 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09001950 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09001951 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001952
1953 switch (dai->id) {
1954 case 1:
1955 case 2:
1956 break;
1957
1958 default:
1959 /* AIF3 shares clocking with AIF1/2 */
1960 return -EINVAL;
1961 }
1962
1963 switch (clk_id) {
1964 case WM8994_SYSCLK_MCLK1:
1965 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
1966 wm8994->mclk[0] = freq;
1967 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
1968 dai->id, freq);
1969 break;
1970
1971 case WM8994_SYSCLK_MCLK2:
1972 /* TODO: Set GPIO AF */
1973 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
1974 wm8994->mclk[1] = freq;
1975 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
1976 dai->id, freq);
1977 break;
1978
1979 case WM8994_SYSCLK_FLL1:
1980 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
1981 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
1982 break;
1983
1984 case WM8994_SYSCLK_FLL2:
1985 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
1986 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
1987 break;
1988
Mark Brown66b47fd2010-07-08 11:25:43 +09001989 case WM8994_SYSCLK_OPCLK:
1990 /* Special case - a division (times 10) is given and
1991 * no effect on main clocking.
1992 */
1993 if (freq) {
1994 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
1995 if (opclk_divs[i] == freq)
1996 break;
1997 if (i == ARRAY_SIZE(opclk_divs))
1998 return -EINVAL;
1999 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2000 WM8994_OPCLK_DIV_MASK, i);
2001 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2002 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2003 } else {
2004 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2005 WM8994_OPCLK_ENA, 0);
2006 }
2007
Mark Brown9e6e96a2010-01-29 17:47:12 +00002008 default:
2009 return -EINVAL;
2010 }
2011
2012 configure_clock(codec);
2013
2014 return 0;
2015}
2016
2017static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2018 enum snd_soc_bias_level level)
2019{
Mark Brown3a423152010-11-26 15:21:06 +00002020 struct wm8994 *control = codec->control_data;
Mark Brownb6b05692010-08-13 12:58:20 +01002021 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2022
Mark Brown9e6e96a2010-01-29 17:47:12 +00002023 switch (level) {
2024 case SND_SOC_BIAS_ON:
2025 break;
2026
2027 case SND_SOC_BIAS_PREPARE:
Mark Brown500fa302011-11-29 19:58:19 +00002028 /* MICBIAS into regulating mode */
2029 switch (control->type) {
2030 case WM8958:
2031 case WM1811:
2032 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2033 WM8958_MICB1_MODE, 0);
2034 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2035 WM8958_MICB2_MODE, 0);
2036 break;
2037 default:
2038 break;
2039 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002040 break;
2041
2042 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002043 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown39fb51a2010-11-26 17:23:43 +00002044 pm_runtime_get_sync(codec->dev);
2045
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002046 switch (control->type) {
2047 case WM8994:
2048 if (wm8994->revision < 4) {
2049 /* Tweak DC servo and DSP
2050 * configuration for improved
2051 * performance. */
2052 snd_soc_write(codec, 0x102, 0x3);
2053 snd_soc_write(codec, 0x56, 0x3);
2054 snd_soc_write(codec, 0x817, 0);
2055 snd_soc_write(codec, 0x102, 0);
2056 }
2057 break;
2058
2059 case WM8958:
2060 if (wm8994->revision == 0) {
2061 /* Optimise performance for rev A */
2062 snd_soc_write(codec, 0x102, 0x3);
2063 snd_soc_write(codec, 0xcb, 0x81);
2064 snd_soc_write(codec, 0x817, 0);
2065 snd_soc_write(codec, 0x102, 0);
2066
2067 snd_soc_update_bits(codec,
2068 WM8958_CHARGE_PUMP_2,
2069 WM8958_CP_DISCH,
2070 WM8958_CP_DISCH);
2071 }
2072 break;
Mark Brown81204c82011-05-24 17:35:53 +08002073
2074 case WM1811:
2075 if (wm8994->revision < 2) {
2076 snd_soc_write(codec, 0x102, 0x3);
2077 snd_soc_write(codec, 0x5d, 0x7e);
2078 snd_soc_write(codec, 0x5e, 0x0);
2079 snd_soc_write(codec, 0x102, 0x0);
2080 }
2081 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002082 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002083
2084 /* Discharge LINEOUT1 & 2 */
2085 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2086 WM8994_LINEOUT1_DISCH |
2087 WM8994_LINEOUT2_DISCH,
2088 WM8994_LINEOUT1_DISCH |
2089 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002090 }
2091
Mark Brown500fa302011-11-29 19:58:19 +00002092 /* MICBIAS into bypass mode on newer devices */
2093 switch (control->type) {
2094 case WM8958:
2095 case WM1811:
2096 snd_soc_update_bits(codec, WM8958_MICBIAS1,
2097 WM8958_MICB1_MODE,
2098 WM8958_MICB1_MODE);
2099 snd_soc_update_bits(codec, WM8958_MICBIAS2,
2100 WM8958_MICB2_MODE,
2101 WM8958_MICB2_MODE);
2102 break;
2103 default:
2104 break;
2105 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002106 break;
2107
2108 case SND_SOC_BIAS_OFF:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002109 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
Mark Brownfbbf5922011-03-11 18:09:04 +00002110 wm8994->cur_fw = NULL;
2111
Mark Brown39fb51a2010-11-26 17:23:43 +00002112 pm_runtime_put(codec->dev);
Mark Brownd522ffb2010-03-30 14:29:14 +01002113 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002114 break;
2115 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002116 codec->dapm.bias_level = level;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002117 return 0;
2118}
2119
2120static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2121{
2122 struct snd_soc_codec *codec = dai->codec;
Mark Brownc4431df2010-11-26 15:21:07 +00002123 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002124 int ms_reg;
2125 int aif1_reg;
2126 int ms = 0;
2127 int aif1 = 0;
2128
2129 switch (dai->id) {
2130 case 1:
2131 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2132 aif1_reg = WM8994_AIF1_CONTROL_1;
2133 break;
2134 case 2:
2135 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2136 aif1_reg = WM8994_AIF2_CONTROL_1;
2137 break;
2138 default:
2139 return -EINVAL;
2140 }
2141
2142 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2143 case SND_SOC_DAIFMT_CBS_CFS:
2144 break;
2145 case SND_SOC_DAIFMT_CBM_CFM:
2146 ms = WM8994_AIF1_MSTR;
2147 break;
2148 default:
2149 return -EINVAL;
2150 }
2151
2152 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2153 case SND_SOC_DAIFMT_DSP_B:
2154 aif1 |= WM8994_AIF1_LRCLK_INV;
2155 case SND_SOC_DAIFMT_DSP_A:
2156 aif1 |= 0x18;
2157 break;
2158 case SND_SOC_DAIFMT_I2S:
2159 aif1 |= 0x10;
2160 break;
2161 case SND_SOC_DAIFMT_RIGHT_J:
2162 break;
2163 case SND_SOC_DAIFMT_LEFT_J:
2164 aif1 |= 0x8;
2165 break;
2166 default:
2167 return -EINVAL;
2168 }
2169
2170 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2171 case SND_SOC_DAIFMT_DSP_A:
2172 case SND_SOC_DAIFMT_DSP_B:
2173 /* frame inversion not valid for DSP modes */
2174 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2175 case SND_SOC_DAIFMT_NB_NF:
2176 break;
2177 case SND_SOC_DAIFMT_IB_NF:
2178 aif1 |= WM8994_AIF1_BCLK_INV;
2179 break;
2180 default:
2181 return -EINVAL;
2182 }
2183 break;
2184
2185 case SND_SOC_DAIFMT_I2S:
2186 case SND_SOC_DAIFMT_RIGHT_J:
2187 case SND_SOC_DAIFMT_LEFT_J:
2188 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2189 case SND_SOC_DAIFMT_NB_NF:
2190 break;
2191 case SND_SOC_DAIFMT_IB_IF:
2192 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2193 break;
2194 case SND_SOC_DAIFMT_IB_NF:
2195 aif1 |= WM8994_AIF1_BCLK_INV;
2196 break;
2197 case SND_SOC_DAIFMT_NB_IF:
2198 aif1 |= WM8994_AIF1_LRCLK_INV;
2199 break;
2200 default:
2201 return -EINVAL;
2202 }
2203 break;
2204 default:
2205 return -EINVAL;
2206 }
2207
Mark Brownc4431df2010-11-26 15:21:07 +00002208 /* The AIF2 format configuration needs to be mirrored to AIF3
2209 * on WM8958 if it's in use so just do it all the time. */
Mark Brown81204c82011-05-24 17:35:53 +08002210 switch (control->type) {
2211 case WM1811:
2212 case WM8958:
2213 if (dai->id == 2)
2214 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2215 WM8994_AIF1_LRCLK_INV |
2216 WM8958_AIF3_FMT_MASK, aif1);
2217 break;
2218
2219 default:
2220 break;
2221 }
Mark Brownc4431df2010-11-26 15:21:07 +00002222
Mark Brown9e6e96a2010-01-29 17:47:12 +00002223 snd_soc_update_bits(codec, aif1_reg,
2224 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2225 WM8994_AIF1_FMT_MASK,
2226 aif1);
2227 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2228 ms);
2229
2230 return 0;
2231}
2232
2233static struct {
2234 int val, rate;
2235} srs[] = {
2236 { 0, 8000 },
2237 { 1, 11025 },
2238 { 2, 12000 },
2239 { 3, 16000 },
2240 { 4, 22050 },
2241 { 5, 24000 },
2242 { 6, 32000 },
2243 { 7, 44100 },
2244 { 8, 48000 },
2245 { 9, 88200 },
2246 { 10, 96000 },
2247};
2248
2249static int fs_ratios[] = {
2250 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2251};
2252
2253static int bclk_divs[] = {
2254 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2255 640, 880, 960, 1280, 1760, 1920
2256};
2257
2258static int wm8994_hw_params(struct snd_pcm_substream *substream,
2259 struct snd_pcm_hw_params *params,
2260 struct snd_soc_dai *dai)
2261{
2262 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09002263 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002264 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002265 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002266 int bclk_reg;
2267 int lrclk_reg;
2268 int rate_reg;
2269 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002270 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002271 int bclk = 0;
2272 int lrclk = 0;
2273 int rate_val = 0;
2274 int id = dai->id - 1;
2275
2276 int i, cur_val, best_val, bclk_rate, best;
2277
2278 switch (dai->id) {
2279 case 1:
2280 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002281 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002282 bclk_reg = WM8994_AIF1_BCLK;
2283 rate_reg = WM8994_AIF1_RATE;
2284 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002285 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002286 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002287 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002288 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002289 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2290 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002291 break;
2292 case 2:
2293 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002294 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002295 bclk_reg = WM8994_AIF2_BCLK;
2296 rate_reg = WM8994_AIF2_RATE;
2297 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002298 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002299 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002300 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002301 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002302 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2303 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002304 break;
2305 default:
2306 return -EINVAL;
2307 }
2308
2309 bclk_rate = params_rate(params) * 2;
2310 switch (params_format(params)) {
2311 case SNDRV_PCM_FORMAT_S16_LE:
2312 bclk_rate *= 16;
2313 break;
2314 case SNDRV_PCM_FORMAT_S20_3LE:
2315 bclk_rate *= 20;
2316 aif1 |= 0x20;
2317 break;
2318 case SNDRV_PCM_FORMAT_S24_LE:
2319 bclk_rate *= 24;
2320 aif1 |= 0x40;
2321 break;
2322 case SNDRV_PCM_FORMAT_S32_LE:
2323 bclk_rate *= 32;
2324 aif1 |= 0x60;
2325 break;
2326 default:
2327 return -EINVAL;
2328 }
2329
2330 /* Try to find an appropriate sample rate; look for an exact match. */
2331 for (i = 0; i < ARRAY_SIZE(srs); i++)
2332 if (srs[i].rate == params_rate(params))
2333 break;
2334 if (i == ARRAY_SIZE(srs))
2335 return -EINVAL;
2336 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2337
2338 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2339 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2340 dai->id, wm8994->aifclk[id], bclk_rate);
2341
Mark Brownb1e43d92010-12-07 17:14:56 +00002342 if (params_channels(params) == 1 &&
2343 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2344 aif2 |= WM8994_AIF1_MONO;
2345
Mark Brown9e6e96a2010-01-29 17:47:12 +00002346 if (wm8994->aifclk[id] == 0) {
2347 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2348 return -EINVAL;
2349 }
2350
2351 /* AIFCLK/fs ratio; look for a close match in either direction */
2352 best = 0;
2353 best_val = abs((fs_ratios[0] * params_rate(params))
2354 - wm8994->aifclk[id]);
2355 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2356 cur_val = abs((fs_ratios[i] * params_rate(params))
2357 - wm8994->aifclk[id]);
2358 if (cur_val >= best_val)
2359 continue;
2360 best = i;
2361 best_val = cur_val;
2362 }
2363 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2364 dai->id, fs_ratios[best]);
2365 rate_val |= best;
2366
2367 /* We may not get quite the right frequency if using
2368 * approximate clocks so look for the closest match that is
2369 * higher than the target (we need to ensure that there enough
2370 * BCLKs to clock out the samples).
2371 */
2372 best = 0;
2373 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002374 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002375 if (cur_val < 0) /* BCLK table is sorted */
2376 break;
2377 best = i;
2378 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002379 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002380 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2381 bclk_divs[best], bclk_rate);
2382 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2383
2384 lrclk = bclk_rate / params_rate(params);
Mark Brownfc07ecd2011-11-28 21:16:56 +00002385 if (!lrclk) {
2386 dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
2387 bclk_rate);
2388 return -EINVAL;
2389 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002390 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2391 lrclk, bclk_rate / lrclk);
2392
2393 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002394 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002395 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2396 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2397 lrclk);
2398 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2399 WM8994_AIF1CLK_RATE_MASK, rate_val);
2400
2401 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2402 switch (dai->id) {
2403 case 1:
2404 wm8994->dac_rates[0] = params_rate(params);
2405 wm8994_set_retune_mobile(codec, 0);
2406 wm8994_set_retune_mobile(codec, 1);
2407 break;
2408 case 2:
2409 wm8994->dac_rates[1] = params_rate(params);
2410 wm8994_set_retune_mobile(codec, 2);
2411 break;
2412 }
2413 }
2414
2415 return 0;
2416}
2417
Mark Brownc4431df2010-11-26 15:21:07 +00002418static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2419 struct snd_pcm_hw_params *params,
2420 struct snd_soc_dai *dai)
2421{
2422 struct snd_soc_codec *codec = dai->codec;
2423 struct wm8994 *control = codec->control_data;
2424 int aif1_reg;
2425 int aif1 = 0;
2426
2427 switch (dai->id) {
2428 case 3:
2429 switch (control->type) {
Mark Brown81204c82011-05-24 17:35:53 +08002430 case WM1811:
Mark Brownc4431df2010-11-26 15:21:07 +00002431 case WM8958:
2432 aif1_reg = WM8958_AIF3_CONTROL_1;
2433 break;
2434 default:
2435 return 0;
2436 }
2437 default:
2438 return 0;
2439 }
2440
2441 switch (params_format(params)) {
2442 case SNDRV_PCM_FORMAT_S16_LE:
2443 break;
2444 case SNDRV_PCM_FORMAT_S20_3LE:
2445 aif1 |= 0x20;
2446 break;
2447 case SNDRV_PCM_FORMAT_S24_LE:
2448 aif1 |= 0x40;
2449 break;
2450 case SNDRV_PCM_FORMAT_S32_LE:
2451 aif1 |= 0x60;
2452 break;
2453 default:
2454 return -EINVAL;
2455 }
2456
2457 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2458}
2459
Mark Brown7d021732011-07-14 17:11:38 +09002460static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
2461 struct snd_soc_dai *dai)
2462{
2463 struct snd_soc_codec *codec = dai->codec;
2464 int rate_reg = 0;
2465
2466 switch (dai->id) {
2467 case 1:
2468 rate_reg = WM8994_AIF1_RATE;
2469 break;
2470 case 2:
Axel Linc527e6a2011-10-04 22:07:18 +08002471 rate_reg = WM8994_AIF2_RATE;
Mark Brown7d021732011-07-14 17:11:38 +09002472 break;
2473 default:
2474 break;
2475 }
2476
2477 /* If the DAI is idle then configure the divider tree for the
2478 * lowest output rate to save a little power if the clock is
2479 * still active (eg, because it is system clock).
2480 */
2481 if (rate_reg && !dai->playback_active && !dai->capture_active)
2482 snd_soc_update_bits(codec, rate_reg,
2483 WM8994_AIF1_SR_MASK |
2484 WM8994_AIF1CLK_RATE_MASK, 0x9);
2485}
2486
Mark Brown9e6e96a2010-01-29 17:47:12 +00002487static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2488{
2489 struct snd_soc_codec *codec = codec_dai->codec;
2490 int mute_reg;
2491 int reg;
2492
2493 switch (codec_dai->id) {
2494 case 1:
2495 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2496 break;
2497 case 2:
2498 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2499 break;
2500 default:
2501 return -EINVAL;
2502 }
2503
2504 if (mute)
2505 reg = WM8994_AIF1DAC1_MUTE;
2506 else
2507 reg = 0;
2508
2509 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2510
2511 return 0;
2512}
2513
Mark Brown778a76e2010-03-22 22:05:10 +00002514static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2515{
2516 struct snd_soc_codec *codec = codec_dai->codec;
2517 int reg, val, mask;
2518
2519 switch (codec_dai->id) {
2520 case 1:
2521 reg = WM8994_AIF1_MASTER_SLAVE;
2522 mask = WM8994_AIF1_TRI;
2523 break;
2524 case 2:
2525 reg = WM8994_AIF2_MASTER_SLAVE;
2526 mask = WM8994_AIF2_TRI;
2527 break;
2528 case 3:
2529 reg = WM8994_POWER_MANAGEMENT_6;
2530 mask = WM8994_AIF3_TRI;
2531 break;
2532 default:
2533 return -EINVAL;
2534 }
2535
2536 if (tristate)
2537 val = mask;
2538 else
2539 val = 0;
2540
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002541 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002542}
2543
Mark Brownd09f3ec2011-08-15 11:01:02 +09002544static int wm8994_aif2_probe(struct snd_soc_dai *dai)
2545{
2546 struct snd_soc_codec *codec = dai->codec;
2547
2548 /* Disable the pulls on the AIF if we're using it to save power. */
2549 snd_soc_update_bits(codec, WM8994_GPIO_3,
2550 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2551 snd_soc_update_bits(codec, WM8994_GPIO_4,
2552 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2553 snd_soc_update_bits(codec, WM8994_GPIO_5,
2554 WM8994_GPN_PU | WM8994_GPN_PD, 0);
2555
2556 return 0;
2557}
2558
Mark Brown9e6e96a2010-01-29 17:47:12 +00002559#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2560
2561#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002562 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002563
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002564static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002565 .set_sysclk = wm8994_set_dai_sysclk,
2566 .set_fmt = wm8994_set_dai_fmt,
2567 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002568 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002569 .digital_mute = wm8994_aif_mute,
2570 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002571 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002572};
2573
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002574static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002575 .set_sysclk = wm8994_set_dai_sysclk,
2576 .set_fmt = wm8994_set_dai_fmt,
2577 .hw_params = wm8994_hw_params,
Mark Brown7d021732011-07-14 17:11:38 +09002578 .shutdown = wm8994_aif_shutdown,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002579 .digital_mute = wm8994_aif_mute,
2580 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002581 .set_tristate = wm8994_set_tristate,
2582};
2583
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01002584static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00002585 .hw_params = wm8994_aif3_hw_params,
Mark Brown778a76e2010-03-22 22:05:10 +00002586 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002587};
2588
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002589static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002590 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002591 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002592 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002593 .playback = {
2594 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002595 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002596 .channels_max = 2,
2597 .rates = WM8994_RATES,
2598 .formats = WM8994_FORMATS,
2599 },
2600 .capture = {
2601 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002602 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002603 .channels_max = 2,
2604 .rates = WM8994_RATES,
2605 .formats = WM8994_FORMATS,
2606 },
2607 .ops = &wm8994_aif1_dai_ops,
2608 },
2609 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002610 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002611 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002612 .playback = {
2613 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002614 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002615 .channels_max = 2,
2616 .rates = WM8994_RATES,
2617 .formats = WM8994_FORMATS,
2618 },
2619 .capture = {
2620 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002621 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002622 .channels_max = 2,
2623 .rates = WM8994_RATES,
2624 .formats = WM8994_FORMATS,
2625 },
Mark Brownd09f3ec2011-08-15 11:01:02 +09002626 .probe = wm8994_aif2_probe,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002627 .ops = &wm8994_aif2_dai_ops,
2628 },
2629 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002630 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002631 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002632 .playback = {
2633 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002634 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002635 .channels_max = 2,
2636 .rates = WM8994_RATES,
2637 .formats = WM8994_FORMATS,
2638 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03002639 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002640 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002641 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002642 .channels_max = 2,
2643 .rates = WM8994_RATES,
2644 .formats = WM8994_FORMATS,
2645 },
Mark Brown778a76e2010-03-22 22:05:10 +00002646 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002647 }
2648};
Mark Brown9e6e96a2010-01-29 17:47:12 +00002649
2650#ifdef CONFIG_PM
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002651static int wm8994_suspend(struct snd_soc_codec *codec, pm_message_t state)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002652{
Mark Brownb2c812e2010-04-14 15:35:19 +09002653 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownca629922011-05-11 14:34:53 +02002654 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002655 int i, ret;
2656
Mark Brownca629922011-05-11 14:34:53 +02002657 switch (control->type) {
2658 case WM8994:
2659 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
2660 break;
Mark Brown81204c82011-05-24 17:35:53 +08002661 case WM1811:
Mark Brownca629922011-05-11 14:34:53 +02002662 case WM8958:
2663 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2664 WM8958_MICD_ENA, 0);
2665 break;
2666 }
2667
Mark Brown9e6e96a2010-01-29 17:47:12 +00002668 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
2669 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
Mark Brownf701a2e2011-03-09 19:31:01 +00002670 sizeof(struct wm8994_fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002671 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002672 if (ret < 0)
2673 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
2674 i + 1, ret);
2675 }
2676
2677 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
2678
2679 return 0;
2680}
2681
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002682static int wm8994_resume(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002683{
Mark Brownb2c812e2010-04-14 15:35:19 +09002684 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brownca629922011-05-11 14:34:53 +02002685 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002686 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002687 unsigned int val, mask;
2688
2689 if (wm8994->revision < 4) {
2690 /* force a HW read */
2691 val = wm8994_reg_read(codec->control_data,
2692 WM8994_POWER_MANAGEMENT_5);
2693
2694 /* modify the cache only */
2695 codec->cache_only = 1;
2696 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
2697 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
2698 val &= mask;
2699 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
2700 mask, val);
2701 codec->cache_only = 0;
2702 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002703
2704 /* Restore the registers */
Mark Brownca9aef52010-11-26 17:23:41 +00002705 ret = snd_soc_cache_sync(codec);
2706 if (ret != 0)
2707 dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002708
2709 wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2710
2711 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01002712 if (!wm8994->fll_suspend[i].out)
2713 continue;
2714
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002715 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002716 wm8994->fll_suspend[i].src,
2717 wm8994->fll_suspend[i].in,
2718 wm8994->fll_suspend[i].out);
2719 if (ret < 0)
2720 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
2721 i + 1, ret);
2722 }
2723
Mark Brownca629922011-05-11 14:34:53 +02002724 switch (control->type) {
2725 case WM8994:
2726 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2727 snd_soc_update_bits(codec, WM8994_MICBIAS,
2728 WM8994_MICD_ENA, WM8994_MICD_ENA);
2729 break;
Mark Brown81204c82011-05-24 17:35:53 +08002730 case WM1811:
Mark Brownca629922011-05-11 14:34:53 +02002731 case WM8958:
2732 if (wm8994->jack_cb)
2733 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2734 WM8958_MICD_ENA, WM8958_MICD_ENA);
2735 break;
2736 }
2737
Mark Brown9e6e96a2010-01-29 17:47:12 +00002738 return 0;
2739}
2740#else
2741#define wm8994_suspend NULL
2742#define wm8994_resume NULL
2743#endif
2744
2745static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
2746{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002747 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002748 struct wm8994_pdata *pdata = wm8994->pdata;
2749 struct snd_kcontrol_new controls[] = {
2750 SOC_ENUM_EXT("AIF1.1 EQ Mode",
2751 wm8994->retune_mobile_enum,
2752 wm8994_get_retune_mobile_enum,
2753 wm8994_put_retune_mobile_enum),
2754 SOC_ENUM_EXT("AIF1.2 EQ Mode",
2755 wm8994->retune_mobile_enum,
2756 wm8994_get_retune_mobile_enum,
2757 wm8994_put_retune_mobile_enum),
2758 SOC_ENUM_EXT("AIF2 EQ Mode",
2759 wm8994->retune_mobile_enum,
2760 wm8994_get_retune_mobile_enum,
2761 wm8994_put_retune_mobile_enum),
2762 };
2763 int ret, i, j;
2764 const char **t;
2765
2766 /* We need an array of texts for the enum API but the number
2767 * of texts is likely to be less than the number of
2768 * configurations due to the sample rate dependency of the
2769 * configurations. */
2770 wm8994->num_retune_mobile_texts = 0;
2771 wm8994->retune_mobile_texts = NULL;
2772 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
2773 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
2774 if (strcmp(pdata->retune_mobile_cfgs[i].name,
2775 wm8994->retune_mobile_texts[j]) == 0)
2776 break;
2777 }
2778
2779 if (j != wm8994->num_retune_mobile_texts)
2780 continue;
2781
2782 /* Expand the array... */
2783 t = krealloc(wm8994->retune_mobile_texts,
2784 sizeof(char *) *
2785 (wm8994->num_retune_mobile_texts + 1),
2786 GFP_KERNEL);
2787 if (t == NULL)
2788 continue;
2789
2790 /* ...store the new entry... */
2791 t[wm8994->num_retune_mobile_texts] =
2792 pdata->retune_mobile_cfgs[i].name;
2793
2794 /* ...and remember the new version. */
2795 wm8994->num_retune_mobile_texts++;
2796 wm8994->retune_mobile_texts = t;
2797 }
2798
2799 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
2800 wm8994->num_retune_mobile_texts);
2801
2802 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
2803 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
2804
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002805 ret = snd_soc_add_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002806 ARRAY_SIZE(controls));
2807 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002808 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002809 "Failed to add ReTune Mobile controls: %d\n", ret);
2810}
2811
2812static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
2813{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002814 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002815 struct wm8994_pdata *pdata = wm8994->pdata;
2816 int ret, i;
2817
2818 if (!pdata)
2819 return;
2820
2821 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
2822 pdata->lineout2_diff,
2823 pdata->lineout1fb,
2824 pdata->lineout2fb,
2825 pdata->jd_scthr,
2826 pdata->jd_thr,
2827 pdata->micbias1_lvl,
2828 pdata->micbias2_lvl);
2829
2830 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
2831
2832 if (pdata->num_drc_cfgs) {
2833 struct snd_kcontrol_new controls[] = {
2834 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
2835 wm8994_get_drc_enum, wm8994_put_drc_enum),
2836 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
2837 wm8994_get_drc_enum, wm8994_put_drc_enum),
2838 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
2839 wm8994_get_drc_enum, wm8994_put_drc_enum),
2840 };
2841
2842 /* We need an array of texts for the enum API */
2843 wm8994->drc_texts = kmalloc(sizeof(char *)
2844 * pdata->num_drc_cfgs, GFP_KERNEL);
2845 if (!wm8994->drc_texts) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002846 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002847 "Failed to allocate %d DRC config texts\n",
2848 pdata->num_drc_cfgs);
2849 return;
2850 }
2851
2852 for (i = 0; i < pdata->num_drc_cfgs; i++)
2853 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
2854
2855 wm8994->drc_enum.max = pdata->num_drc_cfgs;
2856 wm8994->drc_enum.texts = wm8994->drc_texts;
2857
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002858 ret = snd_soc_add_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002859 ARRAY_SIZE(controls));
2860 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002861 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002862 "Failed to add DRC mode controls: %d\n", ret);
2863
2864 for (i = 0; i < WM8994_NUM_DRC; i++)
2865 wm8994_set_drc(codec, i);
2866 }
2867
2868 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
2869 pdata->num_retune_mobile_cfgs);
2870
2871 if (pdata->num_retune_mobile_cfgs)
2872 wm8994_handle_retune_mobile_pdata(wm8994);
2873 else
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002874 snd_soc_add_controls(wm8994->codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002875 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08002876
2877 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
2878 if (pdata->micbias[i]) {
2879 snd_soc_write(codec, WM8958_MICBIAS1 + i,
2880 pdata->micbias[i] & 0xffff);
2881 }
2882 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002883}
2884
Mark Brown88766982010-03-29 20:57:12 +01002885/**
2886 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
2887 *
2888 * @codec: WM8994 codec
2889 * @jack: jack to report detection events on
2890 * @micbias: microphone bias to detect on
2891 * @det: value to report for presence detection
2892 * @shrt: value to report for short detection
2893 *
2894 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
2895 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01002896 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01002897 * be configured using snd_soc_jack_add_gpios() instead.
2898 *
2899 * Configuration of detection levels is available via the micbias1_lvl
2900 * and micbias2_lvl platform data members.
2901 */
2902int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
2903 int micbias, int det, int shrt)
2904{
Mark Brownb2c812e2010-04-14 15:35:19 +09002905 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01002906 struct wm8994_micdet *micdet;
Mark Brown3a423152010-11-26 15:21:06 +00002907 struct wm8994 *control = codec->control_data;
Mark Brown88766982010-03-29 20:57:12 +01002908 int reg;
2909
Mark Brown3a423152010-11-26 15:21:06 +00002910 if (control->type != WM8994)
2911 return -EINVAL;
2912
Mark Brown88766982010-03-29 20:57:12 +01002913 switch (micbias) {
2914 case 1:
2915 micdet = &wm8994->micdet[0];
2916 break;
2917 case 2:
2918 micdet = &wm8994->micdet[1];
2919 break;
2920 default:
2921 return -EINVAL;
2922 }
2923
2924 dev_dbg(codec->dev, "Configuring microphone detection on %d: %x %x\n",
2925 micbias, det, shrt);
2926
2927 /* Store the configuration */
2928 micdet->jack = jack;
2929 micdet->det = det;
2930 micdet->shrt = shrt;
2931
2932 /* If either of the jacks is set up then enable detection */
2933 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2934 reg = WM8994_MICD_ENA;
2935 else
2936 reg = 0;
2937
2938 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
2939
2940 return 0;
2941}
2942EXPORT_SYMBOL_GPL(wm8994_mic_detect);
2943
2944static irqreturn_t wm8994_mic_irq(int irq, void *data)
2945{
2946 struct wm8994_priv *priv = data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002947 struct snd_soc_codec *codec = priv->codec;
Mark Brown88766982010-03-29 20:57:12 +01002948 int reg;
2949 int report;
2950
Mark Brown7116f452010-12-29 13:05:21 +00002951#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00002952 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00002953#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00002954
Mark Brown88766982010-03-29 20:57:12 +01002955 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
2956 if (reg < 0) {
2957 dev_err(codec->dev, "Failed to read microphone status: %d\n",
2958 reg);
2959 return IRQ_HANDLED;
2960 }
2961
2962 dev_dbg(codec->dev, "Microphone status: %x\n", reg);
2963
2964 report = 0;
2965 if (reg & WM8994_MIC1_DET_STS)
2966 report |= priv->micdet[0].det;
2967 if (reg & WM8994_MIC1_SHRT_STS)
2968 report |= priv->micdet[0].shrt;
2969 snd_soc_jack_report(priv->micdet[0].jack, report,
2970 priv->micdet[0].det | priv->micdet[0].shrt);
2971
2972 report = 0;
2973 if (reg & WM8994_MIC2_DET_STS)
2974 report |= priv->micdet[1].det;
2975 if (reg & WM8994_MIC2_SHRT_STS)
2976 report |= priv->micdet[1].shrt;
2977 snd_soc_jack_report(priv->micdet[1].jack, report,
2978 priv->micdet[1].det | priv->micdet[1].shrt);
2979
2980 return IRQ_HANDLED;
2981}
2982
Mark Brown821edd22010-11-26 15:21:09 +00002983/* Default microphone detection handler for WM8958 - the user can
2984 * override this if they wish.
2985 */
2986static void wm8958_default_micdet(u16 status, void *data)
2987{
2988 struct snd_soc_codec *codec = data;
2989 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2990 int report = 0;
2991
2992 /* If nothing present then clear our statuses */
Mark Brown864c4bd2011-02-21 20:51:13 -08002993 if (!(status & WM8958_MICD_STS))
Mark Brown821edd22010-11-26 15:21:09 +00002994 goto done;
Mark Brown821edd22010-11-26 15:21:09 +00002995
Mark Brown864c4bd2011-02-21 20:51:13 -08002996 report = SND_JACK_MICROPHONE;
Mark Brown821edd22010-11-26 15:21:09 +00002997
2998 /* Everything else is buttons; just assign slots */
Mark Brownb35e1602011-07-15 22:28:32 +09002999 if (status & 0x1c)
Mark Brown821edd22010-11-26 15:21:09 +00003000 report |= SND_JACK_BTN_0;
Mark Brown821edd22010-11-26 15:21:09 +00003001
3002done:
Mark Brown406e56c2011-02-21 20:41:25 -08003003 snd_soc_jack_report(wm8994->micdet[0].jack, report,
Mark Brown864c4bd2011-02-21 20:51:13 -08003004 SND_JACK_BTN_0 | SND_JACK_MICROPHONE);
Mark Brown821edd22010-11-26 15:21:09 +00003005}
3006
3007/**
3008 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3009 *
3010 * @codec: WM8958 codec
3011 * @jack: jack to report detection events on
3012 *
3013 * Enable microphone detection functionality for the WM8958. By
3014 * default simple detection which supports the detection of up to 6
3015 * buttons plus video and microphone functionality is supported.
3016 *
3017 * The WM8958 has an advanced jack detection facility which is able to
3018 * support complex accessory detection, especially when used in
3019 * conjunction with external circuitry. In order to provide maximum
3020 * flexiblity a callback is provided which allows a completely custom
3021 * detection algorithm.
3022 */
3023int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3024 wm8958_micdet_cb cb, void *cb_data)
3025{
3026 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3027 struct wm8994 *control = codec->control_data;
3028
Mark Brown81204c82011-05-24 17:35:53 +08003029 switch (control->type) {
3030 case WM1811:
3031 case WM8958:
3032 break;
3033 default:
Mark Brown821edd22010-11-26 15:21:09 +00003034 return -EINVAL;
Mark Brown81204c82011-05-24 17:35:53 +08003035 }
Mark Brown821edd22010-11-26 15:21:09 +00003036
3037 if (jack) {
3038 if (!cb) {
3039 dev_dbg(codec->dev, "Using default micdet callback\n");
3040 cb = wm8958_default_micdet;
3041 cb_data = codec;
3042 }
3043
Mark Brown4cdf5e42011-11-29 14:36:17 +00003044 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
3045
Mark Brown821edd22010-11-26 15:21:09 +00003046 wm8994->micdet[0].jack = jack;
3047 wm8994->jack_cb = cb;
3048 wm8994->jack_cb_data = cb_data;
3049
3050 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3051 WM8958_MICD_ENA, WM8958_MICD_ENA);
3052 } else {
3053 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3054 WM8958_MICD_ENA, 0);
Mark Brown4cdf5e42011-11-29 14:36:17 +00003055 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
Mark Brown821edd22010-11-26 15:21:09 +00003056 }
3057
3058 return 0;
3059}
3060EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3061
3062static irqreturn_t wm8958_mic_irq(int irq, void *data)
3063{
3064 struct wm8994_priv *wm8994 = data;
3065 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown19940b32011-08-19 18:05:05 +09003066 int reg, count;
Mark Brown821edd22010-11-26 15:21:09 +00003067
Mark Brown19940b32011-08-19 18:05:05 +09003068 /* We may occasionally read a detection without an impedence
3069 * range being provided - if that happens loop again.
3070 */
3071 count = 10;
3072 do {
3073 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3074 if (reg < 0) {
3075 dev_err(codec->dev,
3076 "Failed to read mic detect status: %d\n",
3077 reg);
3078 return IRQ_NONE;
3079 }
Mark Brown821edd22010-11-26 15:21:09 +00003080
Mark Brown19940b32011-08-19 18:05:05 +09003081 if (!(reg & WM8958_MICD_VALID)) {
3082 dev_dbg(codec->dev, "Mic detect data not valid\n");
3083 goto out;
3084 }
3085
3086 if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
3087 break;
3088
3089 msleep(1);
3090 } while (count--);
3091
3092 if (count == 0)
3093 dev_warn(codec->dev, "No impedence range reported for jack\n");
Mark Brown821edd22010-11-26 15:21:09 +00003094
Mark Brown7116f452010-12-29 13:05:21 +00003095#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003096 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003097#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003098
Mark Brown821edd22010-11-26 15:21:09 +00003099 if (wm8994->jack_cb)
3100 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3101 else
3102 dev_warn(codec->dev, "Accessory detection with no callback\n");
3103
3104out:
3105 return IRQ_HANDLED;
3106}
3107
Mark Brown3b1af3f2011-07-14 12:38:18 +09003108static irqreturn_t wm8994_fifo_error(int irq, void *data)
3109{
3110 struct snd_soc_codec *codec = data;
3111
3112 dev_err(codec->dev, "FIFO error\n");
3113
3114 return IRQ_HANDLED;
3115}
3116
Mark Brownf0b182b2011-08-16 12:01:27 +09003117static irqreturn_t wm8994_temp_warn(int irq, void *data)
3118{
3119 struct snd_soc_codec *codec = data;
3120
3121 dev_err(codec->dev, "Thermal warning\n");
3122
3123 return IRQ_HANDLED;
3124}
3125
3126static irqreturn_t wm8994_temp_shut(int irq, void *data)
3127{
3128 struct snd_soc_codec *codec = data;
3129
3130 dev_crit(codec->dev, "Thermal shutdown\n");
3131
3132 return IRQ_HANDLED;
3133}
3134
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003135static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003136{
Mark Brown3a423152010-11-26 15:21:06 +00003137 struct wm8994 *control;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003138 struct wm8994_priv *wm8994;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003139 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownec62dbd2010-08-15 14:56:40 +01003140 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003141
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003142 codec->control_data = dev_get_drvdata(codec->dev->parent);
Mark Brown3a423152010-11-26 15:21:06 +00003143 control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003144
3145 wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003146 if (wm8994 == NULL)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003147 return -ENOMEM;
Mark Brownb2c812e2010-04-14 15:35:19 +09003148 snd_soc_codec_set_drvdata(codec, wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003149
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003150 wm8994->pdata = dev_get_platdata(codec->dev->parent);
3151 wm8994->codec = codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003152
Mark Brownc7ebf932011-07-12 19:47:59 +09003153 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3154 init_completion(&wm8994->fll_locked[i]);
3155
Mark Brown9b7c5252011-02-17 20:05:44 -08003156 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3157 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3158 else if (wm8994->pdata && wm8994->pdata->irq_base)
3159 wm8994->micdet_irq = wm8994->pdata->irq_base +
3160 WM8994_IRQ_MIC1_DET;
3161
Mark Brown39fb51a2010-11-26 17:23:43 +00003162 pm_runtime_enable(codec->dev);
3163 pm_runtime_resume(codec->dev);
3164
Mark Brownca9aef52010-11-26 17:23:41 +00003165 /* Read our current status back from the chip - we don't want to
3166 * reset as this may interfere with the GPIO or LDO operation. */
3167 for (i = 0; i < WM8994_CACHE_SIZE; i++) {
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +00003168 if (!wm8994_readable(codec, i) || wm8994_volatile(codec, i))
Mark Brownca9aef52010-11-26 17:23:41 +00003169 continue;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003170
Mark Brownca9aef52010-11-26 17:23:41 +00003171 ret = wm8994_reg_read(codec->control_data, i);
3172 if (ret <= 0)
3173 continue;
3174
3175 ret = snd_soc_cache_write(codec, i, ret);
3176 if (ret != 0) {
3177 dev_err(codec->dev,
3178 "Failed to initialise cache for 0x%x: %d\n",
3179 i, ret);
3180 goto err;
3181 }
3182 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003183
3184 /* Set revision-specific configuration */
Mark Brownb6b05692010-08-13 12:58:20 +01003185 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
Mark Brown3a423152010-11-26 15:21:06 +00003186 switch (control->type) {
3187 case WM8994:
3188 switch (wm8994->revision) {
3189 case 2:
3190 case 3:
Mark Brown4537c4e2011-08-01 13:10:16 +09003191 wm8994->hubs.dcs_codes_l = -5;
3192 wm8994->hubs.dcs_codes_r = -5;
Mark Brown3a423152010-11-26 15:21:06 +00003193 wm8994->hubs.hp_startup_mode = 1;
3194 wm8994->hubs.dcs_readback_mode = 1;
Mark Brownf9acf9f2011-06-07 23:23:52 +01003195 wm8994->hubs.series_startup = 1;
Mark Brown3a423152010-11-26 15:21:06 +00003196 break;
3197 default:
Mark Brown79ef0ab2011-08-01 13:02:17 +09003198 wm8994->hubs.dcs_readback_mode = 2;
Mark Brown3a423152010-11-26 15:21:06 +00003199 break;
3200 }
Mark Brown280ec8b2011-08-10 22:19:19 +09003201 break;
Mark Brown3a423152010-11-26 15:21:06 +00003202
3203 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003204 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003205 break;
Mark Brown3a423152010-11-26 15:21:06 +00003206
Mark Brown81204c82011-05-24 17:35:53 +08003207 case WM1811:
3208 wm8994->hubs.dcs_readback_mode = 2;
3209 wm8994->hubs.no_series_update = 1;
3210
3211 switch (wm8994->revision) {
3212 case 0:
3213 case 1:
Mark Brownfc8e6e82011-11-28 18:48:46 +00003214 case 2:
3215 case 3:
Mark Brown6473a142011-10-17 19:38:52 +01003216 wm8994->hubs.dcs_codes_l = -9;
3217 wm8994->hubs.dcs_codes_r = -5;
Mark Brown81204c82011-05-24 17:35:53 +08003218 break;
3219 default:
3220 break;
3221 }
3222
3223 snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
3224 WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
3225 break;
3226
Mark Brown9e6e96a2010-01-29 17:47:12 +00003227 default:
3228 break;
3229 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003230
Mark Brown3b1af3f2011-07-14 12:38:18 +09003231 wm8994_request_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR,
3232 wm8994_fifo_error, "FIFO error", codec);
Mark Brown5a3ad6b2011-11-04 15:53:48 +00003233 wm8994_request_irq(codec->control_data, WM8994_IRQ_TEMP_WARN,
Mark Brownf0b182b2011-08-16 12:01:27 +09003234 wm8994_temp_warn, "Thermal warning", codec);
Mark Brown5a3ad6b2011-11-04 15:53:48 +00003235 wm8994_request_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT,
Mark Brownf0b182b2011-08-16 12:01:27 +09003236 wm8994_temp_shut, "Thermal shutdown", codec);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003237
Mark Brownb30ead52011-07-12 15:47:17 +09003238 ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
3239 wm_hubs_dcs_done, "DC servo done",
3240 &wm8994->hubs);
3241 if (ret == 0)
3242 wm8994->hubs.dcs_done_irq = true;
3243
Mark Brown3a423152010-11-26 15:21:06 +00003244 switch (control->type) {
3245 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003246 if (wm8994->micdet_irq) {
3247 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3248 wm8994_mic_irq,
3249 IRQF_TRIGGER_RISING,
3250 "Mic1 detect",
3251 wm8994);
3252 if (ret != 0)
3253 dev_warn(codec->dev,
3254 "Failed to request Mic1 detect IRQ: %d\n",
3255 ret);
3256 }
Mark Brown88766982010-03-29 20:57:12 +01003257
Mark Brown3a423152010-11-26 15:21:06 +00003258 ret = wm8994_request_irq(codec->control_data,
3259 WM8994_IRQ_MIC1_SHRT,
3260 wm8994_mic_irq, "Mic 1 short",
3261 wm8994);
3262 if (ret != 0)
3263 dev_warn(codec->dev,
3264 "Failed to request Mic1 short IRQ: %d\n",
3265 ret);
Mark Brown88766982010-03-29 20:57:12 +01003266
Mark Brown3a423152010-11-26 15:21:06 +00003267 ret = wm8994_request_irq(codec->control_data,
3268 WM8994_IRQ_MIC2_DET,
3269 wm8994_mic_irq, "Mic 2 detect",
3270 wm8994);
3271 if (ret != 0)
3272 dev_warn(codec->dev,
3273 "Failed to request Mic2 detect IRQ: %d\n",
3274 ret);
Mark Brown88766982010-03-29 20:57:12 +01003275
Mark Brown3a423152010-11-26 15:21:06 +00003276 ret = wm8994_request_irq(codec->control_data,
3277 WM8994_IRQ_MIC2_SHRT,
3278 wm8994_mic_irq, "Mic 2 short",
3279 wm8994);
3280 if (ret != 0)
3281 dev_warn(codec->dev,
3282 "Failed to request Mic2 short IRQ: %d\n",
3283 ret);
3284 break;
Mark Brown821edd22010-11-26 15:21:09 +00003285
3286 case WM8958:
Mark Brown81204c82011-05-24 17:35:53 +08003287 case WM1811:
Mark Brown9b7c5252011-02-17 20:05:44 -08003288 if (wm8994->micdet_irq) {
3289 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3290 wm8958_mic_irq,
3291 IRQF_TRIGGER_RISING,
3292 "Mic detect",
3293 wm8994);
3294 if (ret != 0)
3295 dev_warn(codec->dev,
3296 "Failed to request Mic detect IRQ: %d\n",
3297 ret);
3298 }
Mark Brown3a423152010-11-26 15:21:06 +00003299 }
Mark Brown88766982010-03-29 20:57:12 +01003300
Mark Brownc7ebf932011-07-12 19:47:59 +09003301 wm8994->fll_locked_irq = true;
3302 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
3303 ret = wm8994_request_irq(codec->control_data,
3304 WM8994_IRQ_FLL1_LOCK + i,
3305 wm8994_fll_locked_irq, "FLL lock",
3306 &wm8994->fll_locked[i]);
3307 if (ret != 0)
3308 wm8994->fll_locked_irq = false;
3309 }
3310
Mark Brown9e6e96a2010-01-29 17:47:12 +00003311 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3312 * configured on init - if a system wants to do this dynamically
3313 * at runtime we can deal with that then.
3314 */
3315 ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_1);
3316 if (ret < 0) {
3317 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003318 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003319 }
3320 if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
3321 wm8994->lrclk_shared[0] = 1;
3322 wm8994_dai[0].symmetric_rates = 1;
3323 } else {
3324 wm8994->lrclk_shared[0] = 0;
3325 }
3326
3327 ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_6);
3328 if (ret < 0) {
3329 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003330 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003331 }
3332 if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
3333 wm8994->lrclk_shared[1] = 1;
3334 wm8994_dai[1].symmetric_rates = 1;
3335 } else {
3336 wm8994->lrclk_shared[1] = 0;
3337 }
3338
Mark Brown9e6e96a2010-01-29 17:47:12 +00003339 wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
3340
Mark Brown9e6e96a2010-01-29 17:47:12 +00003341 /* Latch volume updates (right only; we always do left then right). */
Mark Brownbaa81602011-04-06 10:52:42 +09003342 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
3343 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003344 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3345 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003346 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME,
3347 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003348 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3349 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003350 snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME,
3351 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003352 snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3353 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003354 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME,
3355 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003356 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3357 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003358 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME,
3359 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003360 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3361 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003362 snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME,
3363 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003364 snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3365 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003366 snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME,
3367 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003368 snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3369 WM8994_DAC1_VU, WM8994_DAC1_VU);
Mark Brownbaa81602011-04-06 10:52:42 +09003370 snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME,
3371 WM8994_DAC2_VU, WM8994_DAC2_VU);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003372 snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3373 WM8994_DAC2_VU, WM8994_DAC2_VU);
3374
3375 /* Set the low bit of the 3D stereo depth so TLV matches */
3376 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3377 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3378 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3379 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3380 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3381 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3382 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3383 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3384 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3385
Mark Brown5b739672011-07-06 00:08:43 -07003386 /* Unconditionally enable AIF1 ADC TDM mode on chips which can
3387 * use this; it only affects behaviour on idle TDM clock
3388 * cycles. */
3389 switch (control->type) {
3390 case WM8994:
3391 case WM8958:
3392 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3393 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3394 break;
3395 default:
3396 break;
3397 }
Mark Brownd1ce6b22010-07-20 10:13:14 +01003398
Mark Brown500fa302011-11-29 19:58:19 +00003399 /* Put MICBIAS into bypass mode by default on newer devices */
3400 switch (control->type) {
3401 case WM8958:
3402 case WM1811:
3403 snd_soc_update_bits(codec, WM8958_MICBIAS1,
3404 WM8958_MICB1_MODE, WM8958_MICB1_MODE);
3405 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3406 WM8958_MICB2_MODE, WM8958_MICB2_MODE);
3407 break;
3408 default:
3409 break;
3410 }
3411
Mark Brown9e6e96a2010-01-29 17:47:12 +00003412 wm8994_update_class_w(codec);
3413
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003414 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003415
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003416 wm_hubs_add_analogue_controls(codec);
3417 snd_soc_add_controls(codec, wm8994_snd_controls,
3418 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003419 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003420 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00003421
3422 switch (control->type) {
3423 case WM8994:
3424 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3425 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003426 if (wm8994->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003427 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3428 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003429 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3430 ARRAY_SIZE(wm8994_adc_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003431 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3432 ARRAY_SIZE(wm8994_dac_revd_widgets));
3433 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003434 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3435 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamos04d28682011-03-01 11:47:10 +00003436 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3437 ARRAY_SIZE(wm8994_adc_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003438 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3439 ARRAY_SIZE(wm8994_dac_widgets));
3440 }
Mark Brownc4431df2010-11-26 15:21:07 +00003441 break;
3442 case WM8958:
3443 snd_soc_add_controls(codec, wm8958_snd_controls,
3444 ARRAY_SIZE(wm8958_snd_controls));
3445 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3446 ARRAY_SIZE(wm8958_dapm_widgets));
Mark Brown780e2802011-03-11 18:00:19 +00003447 if (wm8994->revision < 1) {
3448 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3449 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3450 snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3451 ARRAY_SIZE(wm8994_adc_revd_widgets));
3452 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3453 ARRAY_SIZE(wm8994_dac_revd_widgets));
3454 } else {
3455 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3456 ARRAY_SIZE(wm8994_lateclk_widgets));
3457 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3458 ARRAY_SIZE(wm8994_adc_widgets));
3459 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3460 ARRAY_SIZE(wm8994_dac_widgets));
3461 }
Mark Brownc4431df2010-11-26 15:21:07 +00003462 break;
Mark Brown81204c82011-05-24 17:35:53 +08003463
3464 case WM1811:
3465 snd_soc_add_controls(codec, wm8958_snd_controls,
3466 ARRAY_SIZE(wm8958_snd_controls));
3467 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3468 ARRAY_SIZE(wm8958_dapm_widgets));
3469 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3470 ARRAY_SIZE(wm8994_lateclk_widgets));
3471 snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3472 ARRAY_SIZE(wm8994_adc_widgets));
3473 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3474 ARRAY_SIZE(wm8994_dac_widgets));
3475 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003476 }
3477
3478
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003479 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003480 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003481
Mark Brownc4431df2010-11-26 15:21:07 +00003482 switch (control->type) {
3483 case WM8994:
3484 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
3485 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00003486
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003487 if (wm8994->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00003488 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3489 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003490 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3491 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3492 } else {
3493 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3494 ARRAY_SIZE(wm8994_lateclk_intercon));
3495 }
Mark Brownc4431df2010-11-26 15:21:07 +00003496 break;
3497 case WM8958:
Mark Brown780e2802011-03-11 18:00:19 +00003498 if (wm8994->revision < 1) {
3499 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3500 ARRAY_SIZE(wm8994_revd_intercon));
3501 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3502 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3503 } else {
3504 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3505 ARRAY_SIZE(wm8994_lateclk_intercon));
3506 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3507 ARRAY_SIZE(wm8958_intercon));
3508 }
Mark Brownf701a2e2011-03-09 19:31:01 +00003509
3510 wm8958_dsp2_init(codec);
Mark Brownc4431df2010-11-26 15:21:07 +00003511 break;
Mark Brown81204c82011-05-24 17:35:53 +08003512 case WM1811:
3513 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3514 ARRAY_SIZE(wm8994_lateclk_intercon));
3515 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3516 ARRAY_SIZE(wm8958_intercon));
3517 break;
Mark Brownc4431df2010-11-26 15:21:07 +00003518 }
3519
Mark Brown9e6e96a2010-01-29 17:47:12 +00003520 return 0;
3521
Mark Brown88766982010-03-29 20:57:12 +01003522err_irq:
3523 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994);
3524 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994);
3525 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08003526 if (wm8994->micdet_irq)
3527 free_irq(wm8994->micdet_irq, wm8994);
Mark Brownc7ebf932011-07-12 19:47:59 +09003528 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3529 wm8994_free_irq(codec->control_data, WM8994_IRQ_FLL1_LOCK + i,
3530 &wm8994->fll_locked[i]);
Mark Brownb30ead52011-07-12 15:47:17 +09003531 wm8994_free_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
3532 &wm8994->hubs);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003533 wm8994_free_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, codec);
Mark Brownf0b182b2011-08-16 12:01:27 +09003534 wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, codec);
3535 wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003536err:
3537 kfree(wm8994);
3538 return ret;
3539}
3540
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003541static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003542{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003543 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown3a423152010-11-26 15:21:06 +00003544 struct wm8994 *control = codec->control_data;
Mark Brownc7ebf932011-07-12 19:47:59 +09003545 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003546
3547 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003548
Mark Brown39fb51a2010-11-26 17:23:43 +00003549 pm_runtime_disable(codec->dev);
3550
Mark Brownc7ebf932011-07-12 19:47:59 +09003551 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3552 wm8994_free_irq(codec->control_data, WM8994_IRQ_FLL1_LOCK + i,
3553 &wm8994->fll_locked[i]);
3554
Mark Brownb30ead52011-07-12 15:47:17 +09003555 wm8994_free_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
3556 &wm8994->hubs);
Mark Brown3b1af3f2011-07-14 12:38:18 +09003557 wm8994_free_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, codec);
Mark Brownf0b182b2011-08-16 12:01:27 +09003558 wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, codec);
3559 wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, codec);
Mark Brownb30ead52011-07-12 15:47:17 +09003560
Mark Brown3a423152010-11-26 15:21:06 +00003561 switch (control->type) {
3562 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003563 if (wm8994->micdet_irq)
3564 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown3a423152010-11-26 15:21:06 +00003565 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET,
3566 wm8994);
3567 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT,
3568 wm8994);
3569 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET,
3570 wm8994);
3571 break;
Mark Brown821edd22010-11-26 15:21:09 +00003572
Mark Brown81204c82011-05-24 17:35:53 +08003573 case WM1811:
Mark Brown821edd22010-11-26 15:21:09 +00003574 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003575 if (wm8994->micdet_irq)
3576 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00003577 break;
Mark Brown3a423152010-11-26 15:21:06 +00003578 }
Mark Brownfbbf5922011-03-11 18:09:04 +00003579 if (wm8994->mbc)
3580 release_firmware(wm8994->mbc);
Mark Brown09e10d72011-03-16 22:57:47 +00003581 if (wm8994->mbc_vss)
3582 release_firmware(wm8994->mbc_vss);
Mark Brown31215872011-03-17 20:23:43 +00003583 if (wm8994->enh_eq)
3584 release_firmware(wm8994->enh_eq);
Axel Lin24fb2b12010-11-23 15:58:39 +08003585 kfree(wm8994->retune_mobile_texts);
3586 kfree(wm8994->drc_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003587 kfree(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003588
3589 return 0;
3590}
3591
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003592static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
3593 .probe = wm8994_codec_probe,
3594 .remove = wm8994_codec_remove,
3595 .suspend = wm8994_suspend,
3596 .resume = wm8994_resume,
Mark Brownca9aef52010-11-26 17:23:41 +00003597 .read = wm8994_read,
3598 .write = wm8994_write,
Mark Browneba19fd2010-11-19 16:09:15 +00003599 .readable_register = wm8994_readable,
3600 .volatile_register = wm8994_volatile,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003601 .set_bias_level = wm8994_set_bias_level,
Mark Brownca9aef52010-11-26 17:23:41 +00003602
3603 .reg_cache_size = WM8994_CACHE_SIZE,
3604 .reg_cache_default = wm8994_reg_defaults,
3605 .reg_word_size = 2,
Mark Brown2e19b0c2010-11-26 17:23:42 +00003606 .compress_type = SND_SOC_RBTREE_COMPRESSION,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003607};
3608
3609static int __devinit wm8994_probe(struct platform_device *pdev)
3610{
3611 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
3612 wm8994_dai, ARRAY_SIZE(wm8994_dai));
3613}
3614
3615static int __devexit wm8994_remove(struct platform_device *pdev)
3616{
3617 snd_soc_unregister_codec(&pdev->dev);
3618 return 0;
3619}
3620
Mark Brown9e6e96a2010-01-29 17:47:12 +00003621static struct platform_driver wm8994_codec_driver = {
3622 .driver = {
3623 .name = "wm8994-codec",
3624 .owner = THIS_MODULE,
3625 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003626 .probe = wm8994_probe,
3627 .remove = __devexit_p(wm8994_remove),
Mark Brown9e6e96a2010-01-29 17:47:12 +00003628};
3629
Mark Brown5bbcc3c2011-11-23 22:52:08 +00003630module_platform_driver(wm8994_codec_driver);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003631
3632MODULE_DESCRIPTION("ASoC WM8994 driver");
3633MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
3634MODULE_LICENSE("GPL");
3635MODULE_ALIAS("platform:wm8994-codec");