blob: 9b9c15ffb7d275cdc7e32103f3af32a8e1537ed5 [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 +000041struct fll_config {
42 int src;
43 int in;
44 int out;
45};
46
47#define WM8994_NUM_DRC 3
48#define WM8994_NUM_EQ 3
49
50static int wm8994_drc_base[] = {
51 WM8994_AIF1_DRC1_1,
52 WM8994_AIF1_DRC2_1,
53 WM8994_AIF2_DRC_1,
54};
55
56static int wm8994_retune_mobile_base[] = {
57 WM8994_AIF1_DAC1_EQ_GAINS_1,
58 WM8994_AIF1_DAC2_EQ_GAINS_1,
59 WM8994_AIF2_EQ_GAINS_1,
60};
61
Mark Brown88766982010-03-29 20:57:12 +010062struct wm8994_micdet {
63 struct snd_soc_jack *jack;
64 int det;
65 int shrt;
66};
67
Mark Brown9e6e96a2010-01-29 17:47:12 +000068/* codec private data */
69struct wm8994_priv {
70 struct wm_hubs_data hubs;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000071 enum snd_soc_control_type control_type;
72 void *control_data;
73 struct snd_soc_codec *codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +000074 int sysclk[2];
75 int sysclk_rate[2];
76 int mclk[2];
77 int aifclk[2];
78 struct fll_config fll[2], fll_suspend[2];
79
80 int dac_rates[2];
81 int lrclk_shared[2];
82
Mark Brownd6addcc2010-11-26 15:21:08 +000083 int mbc_ena[3];
84
Mark Brown9e6e96a2010-01-29 17:47:12 +000085 /* Platform dependant DRC configuration */
86 const char **drc_texts;
87 int drc_cfg[WM8994_NUM_DRC];
88 struct soc_enum drc_enum;
89
90 /* Platform dependant ReTune mobile configuration */
91 int num_retune_mobile_texts;
92 const char **retune_mobile_texts;
93 int retune_mobile_cfg[WM8994_NUM_EQ];
94 struct soc_enum retune_mobile_enum;
95
Mark Brown131d8102010-11-30 17:03:39 +000096 /* Platform dependant MBC configuration */
97 int mbc_cfg;
98 const char **mbc_texts;
99 struct soc_enum mbc_enum;
100
Mark Brown88766982010-03-29 20:57:12 +0100101 struct wm8994_micdet micdet[2];
102
Mark Brown821edd22010-11-26 15:21:09 +0000103 wm8958_micdet_cb jack_cb;
104 void *jack_cb_data;
105 bool jack_is_mic;
106 bool jack_is_video;
Mark Brown9b7c5252011-02-17 20:05:44 -0800107 int micdet_irq;
Mark Brown821edd22010-11-26 15:21:09 +0000108
Mark Brownb6b05692010-08-13 12:58:20 +0100109 int revision;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000110 struct wm8994_pdata *pdata;
Dimitris Papastamos173efa02011-02-11 16:32:11 +0000111
112 unsigned int aif1clk_enable:1;
113 unsigned int aif2clk_enable:1;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000114};
115
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +0000116static int wm8994_readable(struct snd_soc_codec *codec, unsigned int reg)
Mark Brown9e6e96a2010-01-29 17:47:12 +0000117{
Mark Browne88ff1e2010-07-09 00:12:08 +0900118 switch (reg) {
119 case WM8994_GPIO_1:
120 case WM8994_GPIO_2:
121 case WM8994_GPIO_3:
122 case WM8994_GPIO_4:
123 case WM8994_GPIO_5:
124 case WM8994_GPIO_6:
125 case WM8994_GPIO_7:
126 case WM8994_GPIO_8:
127 case WM8994_GPIO_9:
128 case WM8994_GPIO_10:
129 case WM8994_GPIO_11:
130 case WM8994_INTERRUPT_STATUS_1:
131 case WM8994_INTERRUPT_STATUS_2:
132 case WM8994_INTERRUPT_RAW_STATUS_2:
133 return 1;
134 default:
135 break;
136 }
137
Mark Brown7b306da2010-11-16 20:11:40 +0000138 if (reg >= WM8994_CACHE_SIZE)
Mark Brown9e6e96a2010-01-29 17:47:12 +0000139 return 0;
Mark Brown7b306da2010-11-16 20:11:40 +0000140 return wm8994_access_masks[reg].readable != 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000141}
142
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +0000143static int wm8994_volatile(struct snd_soc_codec *codec, unsigned int reg)
Mark Brown9e6e96a2010-01-29 17:47:12 +0000144{
Mark Brownca9aef52010-11-26 17:23:41 +0000145 if (reg >= WM8994_CACHE_SIZE)
Mark Brown9e6e96a2010-01-29 17:47:12 +0000146 return 1;
147
148 switch (reg) {
149 case WM8994_SOFTWARE_RESET:
150 case WM8994_CHIP_REVISION:
151 case WM8994_DC_SERVO_1:
152 case WM8994_DC_SERVO_READBACK:
153 case WM8994_RATE_STATUS:
154 case WM8994_LDO_1:
155 case WM8994_LDO_2:
Mark Brownd6addcc2010-11-26 15:21:08 +0000156 case WM8958_DSP2_EXECCONTROL:
Mark Brown821edd22010-11-26 15:21:09 +0000157 case WM8958_MIC_DETECT_3:
Mark Brown9e6e96a2010-01-29 17:47:12 +0000158 return 1;
159 default:
160 return 0;
161 }
162}
163
164static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg,
165 unsigned int value)
166{
Mark Brownca9aef52010-11-26 17:23:41 +0000167 int ret;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000168
169 BUG_ON(reg > WM8994_MAX_REGISTER);
170
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +0000171 if (!wm8994_volatile(codec, reg)) {
Mark Brownca9aef52010-11-26 17:23:41 +0000172 ret = snd_soc_cache_write(codec, reg, value);
173 if (ret != 0)
174 dev_err(codec->dev, "Cache write to %x failed: %d\n",
175 reg, ret);
176 }
Mark Brown9e6e96a2010-01-29 17:47:12 +0000177
178 return wm8994_reg_write(codec->control_data, reg, value);
179}
180
181static unsigned int wm8994_read(struct snd_soc_codec *codec,
182 unsigned int reg)
183{
Mark Brownca9aef52010-11-26 17:23:41 +0000184 unsigned int val;
185 int ret;
Mark Brown9e6e96a2010-01-29 17:47:12 +0000186
187 BUG_ON(reg > WM8994_MAX_REGISTER);
188
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +0000189 if (!wm8994_volatile(codec, reg) && wm8994_readable(codec, reg) &&
Mark Brownca9aef52010-11-26 17:23:41 +0000190 reg < codec->driver->reg_cache_size) {
191 ret = snd_soc_cache_read(codec, reg, &val);
192 if (ret >= 0)
193 return val;
194 else
195 dev_err(codec->dev, "Cache read from %x failed: %d\n",
196 reg, ret);
197 }
198
199 return wm8994_reg_read(codec->control_data, reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000200}
201
202static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
203{
Mark Brownb2c812e2010-04-14 15:35:19 +0900204 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000205 int rate;
206 int reg1 = 0;
207 int offset;
208
209 if (aif)
210 offset = 4;
211 else
212 offset = 0;
213
214 switch (wm8994->sysclk[aif]) {
215 case WM8994_SYSCLK_MCLK1:
216 rate = wm8994->mclk[0];
217 break;
218
219 case WM8994_SYSCLK_MCLK2:
220 reg1 |= 0x8;
221 rate = wm8994->mclk[1];
222 break;
223
224 case WM8994_SYSCLK_FLL1:
225 reg1 |= 0x10;
226 rate = wm8994->fll[0].out;
227 break;
228
229 case WM8994_SYSCLK_FLL2:
230 reg1 |= 0x18;
231 rate = wm8994->fll[1].out;
232 break;
233
234 default:
235 return -EINVAL;
236 }
237
238 if (rate >= 13500000) {
239 rate /= 2;
240 reg1 |= WM8994_AIF1CLK_DIV;
241
242 dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
243 aif + 1, rate);
244 }
Mark Brown5e5e2be2010-04-25 12:20:30 +0100245
246 if (rate && rate < 3000000)
247 dev_warn(codec->dev, "AIF%dCLK is %dHz, should be >=3MHz for optimal performance\n",
248 aif + 1, rate);
249
Mark Brown9e6e96a2010-01-29 17:47:12 +0000250 wm8994->aifclk[aif] = rate;
251
252 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset,
253 WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
254 reg1);
255
256 return 0;
257}
258
259static int configure_clock(struct snd_soc_codec *codec)
260{
Mark Brownb2c812e2010-04-14 15:35:19 +0900261 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000262 int old, new;
263
264 /* Bring up the AIF clocks first */
265 configure_aif_clock(codec, 0);
266 configure_aif_clock(codec, 1);
267
268 /* Then switch CLK_SYS over to the higher of them; a change
269 * can only happen as a result of a clocking change which can
270 * only be made outside of DAPM so we can safely redo the
271 * clocking.
272 */
273
274 /* If they're equal it doesn't matter which is used */
275 if (wm8994->aifclk[0] == wm8994->aifclk[1])
276 return 0;
277
278 if (wm8994->aifclk[0] < wm8994->aifclk[1])
279 new = WM8994_SYSCLK_SRC;
280 else
281 new = 0;
282
283 old = snd_soc_read(codec, WM8994_CLOCKING_1) & WM8994_SYSCLK_SRC;
284
285 /* If there's no change then we're done. */
286 if (old == new)
287 return 0;
288
289 snd_soc_update_bits(codec, WM8994_CLOCKING_1, WM8994_SYSCLK_SRC, new);
290
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200291 snd_soc_dapm_sync(&codec->dapm);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000292
293 return 0;
294}
295
296static int check_clk_sys(struct snd_soc_dapm_widget *source,
297 struct snd_soc_dapm_widget *sink)
298{
299 int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1);
300 const char *clk;
301
302 /* Check what we're currently using for CLK_SYS */
303 if (reg & WM8994_SYSCLK_SRC)
304 clk = "AIF2CLK";
305 else
306 clk = "AIF1CLK";
307
308 return strcmp(source->name, clk) == 0;
309}
310
311static const char *sidetone_hpf_text[] = {
312 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
313};
314
315static const struct soc_enum sidetone_hpf =
316 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
317
Uk Kim146fd572010-12-07 13:58:40 +0000318static const char *adc_hpf_text[] = {
319 "HiFi", "Voice 1", "Voice 2", "Voice 3"
320};
321
322static const struct soc_enum aif1adc1_hpf =
323 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text);
324
325static const struct soc_enum aif1adc2_hpf =
326 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text);
327
328static const struct soc_enum aif2adc_hpf =
329 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text);
330
Mark Brown9e6e96a2010-01-29 17:47:12 +0000331static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
332static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
333static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
334static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
335static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
336
337#define WM8994_DRC_SWITCH(xname, reg, shift) \
338{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
339 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
340 .put = wm8994_put_drc_sw, \
341 .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
342
343static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
345{
346 struct soc_mixer_control *mc =
347 (struct soc_mixer_control *)kcontrol->private_value;
348 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
349 int mask, ret;
350
351 /* Can't enable both ADC and DAC paths simultaneously */
352 if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
353 mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
354 WM8994_AIF1ADC1R_DRC_ENA_MASK;
355 else
356 mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
357
358 ret = snd_soc_read(codec, mc->reg);
359 if (ret < 0)
360 return ret;
361 if (ret & mask)
362 return -EINVAL;
363
364 return snd_soc_put_volsw(kcontrol, ucontrol);
365}
366
Mark Brown9e6e96a2010-01-29 17:47:12 +0000367static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
368{
Mark Brownb2c812e2010-04-14 15:35:19 +0900369 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000370 struct wm8994_pdata *pdata = wm8994->pdata;
371 int base = wm8994_drc_base[drc];
372 int cfg = wm8994->drc_cfg[drc];
373 int save, i;
374
375 /* Save any enables; the configuration should clear them. */
376 save = snd_soc_read(codec, base);
377 save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
378 WM8994_AIF1ADC1R_DRC_ENA;
379
380 for (i = 0; i < WM8994_DRC_REGS; i++)
381 snd_soc_update_bits(codec, base + i, 0xffff,
382 pdata->drc_cfgs[cfg].regs[i]);
383
384 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
385 WM8994_AIF1ADC1L_DRC_ENA |
386 WM8994_AIF1ADC1R_DRC_ENA, save);
387}
388
389/* Icky as hell but saves code duplication */
390static int wm8994_get_drc(const char *name)
391{
392 if (strcmp(name, "AIF1DRC1 Mode") == 0)
393 return 0;
394 if (strcmp(name, "AIF1DRC2 Mode") == 0)
395 return 1;
396 if (strcmp(name, "AIF2DRC Mode") == 0)
397 return 2;
398 return -EINVAL;
399}
400
401static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
402 struct snd_ctl_elem_value *ucontrol)
403{
404 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000405 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000406 struct wm8994_pdata *pdata = wm8994->pdata;
407 int drc = wm8994_get_drc(kcontrol->id.name);
408 int value = ucontrol->value.integer.value[0];
409
410 if (drc < 0)
411 return drc;
412
413 if (value >= pdata->num_drc_cfgs)
414 return -EINVAL;
415
416 wm8994->drc_cfg[drc] = value;
417
418 wm8994_set_drc(codec, drc);
419
420 return 0;
421}
422
423static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
424 struct snd_ctl_elem_value *ucontrol)
425{
426 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900427 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000428 int drc = wm8994_get_drc(kcontrol->id.name);
429
430 ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
431
432 return 0;
433}
434
435static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
436{
Mark Brownb2c812e2010-04-14 15:35:19 +0900437 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000438 struct wm8994_pdata *pdata = wm8994->pdata;
439 int base = wm8994_retune_mobile_base[block];
440 int iface, best, best_val, save, i, cfg;
441
442 if (!pdata || !wm8994->num_retune_mobile_texts)
443 return;
444
445 switch (block) {
446 case 0:
447 case 1:
448 iface = 0;
449 break;
450 case 2:
451 iface = 1;
452 break;
453 default:
454 return;
455 }
456
457 /* Find the version of the currently selected configuration
458 * with the nearest sample rate. */
459 cfg = wm8994->retune_mobile_cfg[block];
460 best = 0;
461 best_val = INT_MAX;
462 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
463 if (strcmp(pdata->retune_mobile_cfgs[i].name,
464 wm8994->retune_mobile_texts[cfg]) == 0 &&
465 abs(pdata->retune_mobile_cfgs[i].rate
466 - wm8994->dac_rates[iface]) < best_val) {
467 best = i;
468 best_val = abs(pdata->retune_mobile_cfgs[i].rate
469 - wm8994->dac_rates[iface]);
470 }
471 }
472
473 dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
474 block,
475 pdata->retune_mobile_cfgs[best].name,
476 pdata->retune_mobile_cfgs[best].rate,
477 wm8994->dac_rates[iface]);
478
479 /* The EQ will be disabled while reconfiguring it, remember the
480 * current configuration.
481 */
482 save = snd_soc_read(codec, base);
483 save &= WM8994_AIF1DAC1_EQ_ENA;
484
485 for (i = 0; i < WM8994_EQ_REGS; i++)
486 snd_soc_update_bits(codec, base + i, 0xffff,
487 pdata->retune_mobile_cfgs[best].regs[i]);
488
489 snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
490}
491
492/* Icky as hell but saves code duplication */
493static int wm8994_get_retune_mobile_block(const char *name)
494{
495 if (strcmp(name, "AIF1.1 EQ Mode") == 0)
496 return 0;
497 if (strcmp(name, "AIF1.2 EQ Mode") == 0)
498 return 1;
499 if (strcmp(name, "AIF2 EQ Mode") == 0)
500 return 2;
501 return -EINVAL;
502}
503
504static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
505 struct snd_ctl_elem_value *ucontrol)
506{
507 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000508 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000509 struct wm8994_pdata *pdata = wm8994->pdata;
510 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
511 int value = ucontrol->value.integer.value[0];
512
513 if (block < 0)
514 return block;
515
516 if (value >= pdata->num_retune_mobile_cfgs)
517 return -EINVAL;
518
519 wm8994->retune_mobile_cfg[block] = value;
520
521 wm8994_set_retune_mobile(codec, block);
522
523 return 0;
524}
525
526static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
527 struct snd_ctl_elem_value *ucontrol)
528{
529 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brown4a8d9292011-02-16 14:57:17 -0800530 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000531 int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
532
533 ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
534
535 return 0;
536}
537
Mark Brown96b101e2010-11-18 15:49:38 +0000538static const char *aif_chan_src_text[] = {
Mark Brownf5548852010-08-31 19:39:48 +0100539 "Left", "Right"
540};
541
Mark Brown96b101e2010-11-18 15:49:38 +0000542static const struct soc_enum aif1adcl_src =
543 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
544
545static const struct soc_enum aif1adcr_src =
546 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
547
548static const struct soc_enum aif2adcl_src =
549 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
550
551static const struct soc_enum aif2adcr_src =
552 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
553
Mark Brownf5548852010-08-31 19:39:48 +0100554static const struct soc_enum aif1dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000555 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100556
557static const struct soc_enum aif1dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000558 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100559
560static const struct soc_enum aif2dacl_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000561 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100562
563static const struct soc_enum aif2dacr_src =
Mark Brown96b101e2010-11-18 15:49:38 +0000564 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
Mark Brownf5548852010-08-31 19:39:48 +0100565
Mark Brown154b26a2010-12-09 12:07:44 +0000566static const char *osr_text[] = {
567 "Low Power", "High Performance",
568};
569
570static const struct soc_enum dac_osr =
571 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
572
573static const struct soc_enum adc_osr =
574 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
575
Mark Brownd6addcc2010-11-26 15:21:08 +0000576static void wm8958_mbc_apply(struct snd_soc_codec *codec, int mbc, int start)
577{
578 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown131d8102010-11-30 17:03:39 +0000579 struct wm8994_pdata *pdata = wm8994->pdata;
Mark Brownd6addcc2010-11-26 15:21:08 +0000580 int pwr_reg = snd_soc_read(codec, WM8994_POWER_MANAGEMENT_5);
Mark Brown131d8102010-11-30 17:03:39 +0000581 int ena, reg, aif, i;
Mark Brownd6addcc2010-11-26 15:21:08 +0000582
583 switch (mbc) {
584 case 0:
585 pwr_reg &= (WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA);
586 aif = 0;
587 break;
588 case 1:
589 pwr_reg &= (WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
590 aif = 0;
591 break;
592 case 2:
593 pwr_reg &= (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA);
594 aif = 1;
595 break;
596 default:
597 BUG();
598 return;
599 }
600
601 /* We can only enable the MBC if the AIF is enabled and we
602 * want it to be enabled. */
603 ena = pwr_reg && wm8994->mbc_ena[mbc];
604
605 reg = snd_soc_read(codec, WM8958_DSP2_PROGRAM);
606
607 dev_dbg(codec->dev, "MBC %d startup: %d, power: %x, DSP: %x\n",
608 mbc, start, pwr_reg, reg);
609
610 if (start && ena) {
611 /* If the DSP is already running then noop */
612 if (reg & WM8958_DSP2_ENA)
613 return;
614
615 /* Switch the clock over to the appropriate AIF */
616 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
617 WM8958_DSP2CLK_SRC | WM8958_DSP2CLK_ENA,
618 aif << WM8958_DSP2CLK_SRC_SHIFT |
619 WM8958_DSP2CLK_ENA);
620
621 snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM,
622 WM8958_DSP2_ENA, WM8958_DSP2_ENA);
623
Mark Brown131d8102010-11-30 17:03:39 +0000624 /* If we've got user supplied MBC settings use them */
625 if (pdata && pdata->num_mbc_cfgs) {
626 struct wm8958_mbc_cfg *cfg
627 = &pdata->mbc_cfgs[wm8994->mbc_cfg];
628
629 for (i = 0; i < ARRAY_SIZE(cfg->coeff_regs); i++)
630 snd_soc_write(codec, i + WM8958_MBC_BAND_1_K_1,
631 cfg->coeff_regs[i]);
632
633 for (i = 0; i < ARRAY_SIZE(cfg->cutoff_regs); i++)
634 snd_soc_write(codec,
635 i + WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_1,
636 cfg->cutoff_regs[i]);
637 }
Mark Brownd6addcc2010-11-26 15:21:08 +0000638
639 /* Run the DSP */
640 snd_soc_write(codec, WM8958_DSP2_EXECCONTROL,
641 WM8958_DSP2_RUNR);
642
643 /* And we're off! */
644 snd_soc_update_bits(codec, WM8958_DSP2_CONFIG,
645 WM8958_MBC_ENA | WM8958_MBC_SEL_MASK,
646 mbc << WM8958_MBC_SEL_SHIFT |
647 WM8958_MBC_ENA);
648 } else {
649 /* If the DSP is already stopped then noop */
650 if (!(reg & WM8958_DSP2_ENA))
651 return;
652
653 snd_soc_update_bits(codec, WM8958_DSP2_CONFIG,
654 WM8958_MBC_ENA, 0);
655 snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM,
656 WM8958_DSP2_ENA, 0);
657 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
658 WM8958_DSP2CLK_ENA, 0);
659 }
660}
661
662static int wm8958_aif_ev(struct snd_soc_dapm_widget *w,
663 struct snd_kcontrol *kcontrol, int event)
664{
665 struct snd_soc_codec *codec = w->codec;
666 int mbc;
667
668 switch (w->shift) {
669 case 13:
670 case 12:
671 mbc = 2;
672 break;
673 case 11:
674 case 10:
675 mbc = 1;
676 break;
677 case 9:
678 case 8:
679 mbc = 0;
680 break;
681 default:
682 BUG();
683 return -EINVAL;
684 }
685
686 switch (event) {
687 case SND_SOC_DAPM_POST_PMU:
688 wm8958_mbc_apply(codec, mbc, 1);
689 break;
690 case SND_SOC_DAPM_POST_PMD:
691 wm8958_mbc_apply(codec, mbc, 0);
692 break;
693 }
694
695 return 0;
696}
697
Mark Brown131d8102010-11-30 17:03:39 +0000698static int wm8958_put_mbc_enum(struct snd_kcontrol *kcontrol,
699 struct snd_ctl_elem_value *ucontrol)
700{
701 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
702 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
703 struct wm8994_pdata *pdata = wm8994->pdata;
704 int value = ucontrol->value.integer.value[0];
705 int reg;
706
707 /* Don't allow on the fly reconfiguration */
708 reg = snd_soc_read(codec, WM8994_CLOCKING_1);
709 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
710 return -EBUSY;
711
712 if (value >= pdata->num_mbc_cfgs)
713 return -EINVAL;
714
715 wm8994->mbc_cfg = value;
716
717 return 0;
718}
719
720static int wm8958_get_mbc_enum(struct snd_kcontrol *kcontrol,
721 struct snd_ctl_elem_value *ucontrol)
722{
723 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
724 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
725
726 ucontrol->value.enumerated.item[0] = wm8994->mbc_cfg;
727
728 return 0;
729}
730
Mark Brownd6addcc2010-11-26 15:21:08 +0000731static int wm8958_mbc_info(struct snd_kcontrol *kcontrol,
732 struct snd_ctl_elem_info *uinfo)
733{
734 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
735 uinfo->count = 1;
736 uinfo->value.integer.min = 0;
737 uinfo->value.integer.max = 1;
738 return 0;
739}
740
741static int wm8958_mbc_get(struct snd_kcontrol *kcontrol,
742 struct snd_ctl_elem_value *ucontrol)
743{
744 int mbc = kcontrol->private_value;
745 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
746 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
747
748 ucontrol->value.integer.value[0] = wm8994->mbc_ena[mbc];
749
750 return 0;
751}
752
753static int wm8958_mbc_put(struct snd_kcontrol *kcontrol,
754 struct snd_ctl_elem_value *ucontrol)
755{
756 int mbc = kcontrol->private_value;
757 int i;
758 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
759 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
760
761 if (ucontrol->value.integer.value[0] > 1)
762 return -EINVAL;
763
764 for (i = 0; i < ARRAY_SIZE(wm8994->mbc_ena); i++) {
765 if (mbc != i && wm8994->mbc_ena[i]) {
766 dev_dbg(codec->dev, "MBC %d active already\n", mbc);
767 return -EBUSY;
768 }
769 }
770
771 wm8994->mbc_ena[mbc] = ucontrol->value.integer.value[0];
772
773 wm8958_mbc_apply(codec, mbc, wm8994->mbc_ena[mbc]);
774
775 return 0;
776}
777
778#define WM8958_MBC_SWITCH(xname, xval) {\
779 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
780 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
781 .info = wm8958_mbc_info, \
782 .get = wm8958_mbc_get, .put = wm8958_mbc_put, \
783 .private_value = xval }
784
Mark Brown9e6e96a2010-01-29 17:47:12 +0000785static const struct snd_kcontrol_new wm8994_snd_controls[] = {
786SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
787 WM8994_AIF1_ADC1_RIGHT_VOLUME,
788 1, 119, 0, digital_tlv),
789SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
790 WM8994_AIF1_ADC2_RIGHT_VOLUME,
791 1, 119, 0, digital_tlv),
792SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
793 WM8994_AIF2_ADC_RIGHT_VOLUME,
794 1, 119, 0, digital_tlv),
795
Mark Brown96b101e2010-11-18 15:49:38 +0000796SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
797SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000798SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
799SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
Mark Brown96b101e2010-11-18 15:49:38 +0000800
Mark Brownf5548852010-08-31 19:39:48 +0100801SOC_ENUM("AIF1DACL Source", aif1dacl_src),
802SOC_ENUM("AIF1DACR Source", aif1dacr_src),
Mark Brown49db7e72010-12-08 13:49:43 +0000803SOC_ENUM("AIF2DACL Source", aif2dacl_src),
804SOC_ENUM("AIF2DACR Source", aif2dacr_src),
Mark Brownf5548852010-08-31 19:39:48 +0100805
Mark Brown9e6e96a2010-01-29 17:47:12 +0000806SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
807 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
808SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
809 WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
810SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
811 WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
812
813SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
814SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
815
816SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
817SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
818SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
819
820WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
821WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
822WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
823
824WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
825WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
826WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
827
828WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
829WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
830WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
831
832SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
833 5, 12, 0, st_tlv),
834SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
835 0, 12, 0, st_tlv),
836SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
837 5, 12, 0, st_tlv),
838SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
839 0, 12, 0, st_tlv),
840SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
841SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
842
Uk Kim146fd572010-12-07 13:58:40 +0000843SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
844SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
845
846SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
847SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
848
849SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
850SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
851
Mark Brown154b26a2010-12-09 12:07:44 +0000852SOC_ENUM("ADC OSR", adc_osr),
853SOC_ENUM("DAC OSR", dac_osr),
854
Mark Brown9e6e96a2010-01-29 17:47:12 +0000855SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
856 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
857SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
858 WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
859
860SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
861 WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
862SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
863 WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
864
865SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
866 6, 1, 1, wm_hubs_spkmix_tlv),
867SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
868 2, 1, 1, wm_hubs_spkmix_tlv),
869
870SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
871 6, 1, 1, wm_hubs_spkmix_tlv),
872SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
873 2, 1, 1, wm_hubs_spkmix_tlv),
874
875SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
876 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000877SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000878 8, 1, 0),
879SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
880 10, 15, 0, wm8994_3d_tlv),
881SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
882 8, 1, 0),
Mark Brown458350b2010-12-20 14:35:09 +0000883SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000884 10, 15, 0, wm8994_3d_tlv),
Mark Brown458350b2010-12-20 14:35:09 +0000885SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
Mark Brown9e6e96a2010-01-29 17:47:12 +0000886 8, 1, 0),
887};
888
889static const struct snd_kcontrol_new wm8994_eq_controls[] = {
890SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
891 eq_tlv),
892SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
893 eq_tlv),
894SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
895 eq_tlv),
896SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
897 eq_tlv),
898SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
899 eq_tlv),
900
901SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
902 eq_tlv),
903SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
904 eq_tlv),
905SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
906 eq_tlv),
907SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
908 eq_tlv),
909SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
910 eq_tlv),
911
912SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
913 eq_tlv),
914SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
915 eq_tlv),
916SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
917 eq_tlv),
918SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
919 eq_tlv),
920SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
921 eq_tlv),
922};
923
Mark Brownc4431df2010-11-26 15:21:07 +0000924static const struct snd_kcontrol_new wm8958_snd_controls[] = {
925SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
Mark Brownd6addcc2010-11-26 15:21:08 +0000926WM8958_MBC_SWITCH("AIF1DAC1 MBC Switch", 0),
927WM8958_MBC_SWITCH("AIF1DAC2 MBC Switch", 1),
928WM8958_MBC_SWITCH("AIF2DAC MBC Switch", 2),
Mark Brownc4431df2010-11-26 15:21:07 +0000929};
930
Mark Brown9e6e96a2010-01-29 17:47:12 +0000931static int clk_sys_event(struct snd_soc_dapm_widget *w,
932 struct snd_kcontrol *kcontrol, int event)
933{
934 struct snd_soc_codec *codec = w->codec;
935
936 switch (event) {
937 case SND_SOC_DAPM_PRE_PMU:
938 return configure_clock(codec);
939
940 case SND_SOC_DAPM_POST_PMD:
941 configure_clock(codec);
942 break;
943 }
944
945 return 0;
946}
947
948static void wm8994_update_class_w(struct snd_soc_codec *codec)
949{
Mark Brownfec6dd82010-10-27 13:48:36 -0700950 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000951 int enable = 1;
952 int source = 0; /* GCC flow analysis can't track enable */
953 int reg, reg_r;
954
955 /* Only support direct DAC->headphone paths */
956 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
957 if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
Mark Brownee839a22010-04-20 13:57:08 +0900958 dev_vdbg(codec->dev, "HPL connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000959 enable = 0;
960 }
961
962 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
963 if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
Mark Brownee839a22010-04-20 13:57:08 +0900964 dev_vdbg(codec->dev, "HPR connected to output mixer\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000965 enable = 0;
966 }
967
968 /* We also need the same setting for L/R and only one path */
969 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
970 switch (reg) {
971 case WM8994_AIF2DACL_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900972 dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000973 source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
974 break;
975 case WM8994_AIF1DAC2L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900976 dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000977 source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
978 break;
979 case WM8994_AIF1DAC1L_TO_DAC1L:
Mark Brownee839a22010-04-20 13:57:08 +0900980 dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000981 source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
982 break;
983 default:
Mark Brownee839a22010-04-20 13:57:08 +0900984 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
Mark Brown9e6e96a2010-01-29 17:47:12 +0000985 enable = 0;
986 break;
987 }
988
989 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
990 if (reg_r != reg) {
Mark Brownee839a22010-04-20 13:57:08 +0900991 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
Mark Brown9e6e96a2010-01-29 17:47:12 +0000992 enable = 0;
993 }
994
995 if (enable) {
996 dev_dbg(codec->dev, "Class W enabled\n");
997 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
998 WM8994_CP_DYN_PWR |
999 WM8994_CP_DYN_SRC_SEL_MASK,
1000 source | WM8994_CP_DYN_PWR);
Mark Brownfec6dd82010-10-27 13:48:36 -07001001 wm8994->hubs.class_w = true;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001002
1003 } else {
1004 dev_dbg(codec->dev, "Class W disabled\n");
1005 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
1006 WM8994_CP_DYN_PWR, 0);
Mark Brownfec6dd82010-10-27 13:48:36 -07001007 wm8994->hubs.class_w = false;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001008 }
1009}
1010
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001011static int late_enable_ev(struct snd_soc_dapm_widget *w,
1012 struct snd_kcontrol *kcontrol, int event)
1013{
1014 struct snd_soc_codec *codec = w->codec;
1015 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1016
1017 switch (event) {
1018 case SND_SOC_DAPM_PRE_PMU:
1019 if (wm8994->aif1clk_enable)
1020 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1021 WM8994_AIF1CLK_ENA_MASK,
1022 WM8994_AIF1CLK_ENA);
1023 if (wm8994->aif2clk_enable)
1024 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1025 WM8994_AIF2CLK_ENA_MASK,
1026 WM8994_AIF2CLK_ENA);
1027 break;
1028 }
1029
1030 return 0;
1031}
1032
1033static int late_disable_ev(struct snd_soc_dapm_widget *w,
1034 struct snd_kcontrol *kcontrol, int event)
1035{
1036 struct snd_soc_codec *codec = w->codec;
1037 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1038
1039 switch (event) {
1040 case SND_SOC_DAPM_POST_PMD:
1041 if (wm8994->aif1clk_enable) {
1042 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1043 WM8994_AIF1CLK_ENA_MASK, 0);
1044 wm8994->aif1clk_enable = 0;
1045 }
1046 if (wm8994->aif2clk_enable) {
1047 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1048 WM8994_AIF2CLK_ENA_MASK, 0);
1049 wm8994->aif2clk_enable = 0;
1050 }
1051 break;
1052 }
1053
1054 return 0;
1055}
1056
1057static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1058 struct snd_kcontrol *kcontrol, int event)
1059{
1060 struct snd_soc_codec *codec = w->codec;
1061 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1062
1063 switch (event) {
1064 case SND_SOC_DAPM_PRE_PMU:
1065 wm8994->aif1clk_enable = 1;
1066 break;
1067 }
1068
1069 return 0;
1070}
1071
1072static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1073 struct snd_kcontrol *kcontrol, int event)
1074{
1075 struct snd_soc_codec *codec = w->codec;
1076 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1077
1078 switch (event) {
1079 case SND_SOC_DAPM_PRE_PMU:
1080 wm8994->aif2clk_enable = 1;
1081 break;
1082 }
1083
1084 return 0;
1085}
1086
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001087static int dac_ev(struct snd_soc_dapm_widget *w,
1088 struct snd_kcontrol *kcontrol, int event)
1089{
1090 struct snd_soc_codec *codec = w->codec;
1091 unsigned int mask = 1 << w->shift;
1092
1093 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
1094 mask, mask);
1095 return 0;
1096}
1097
Mark Brown9e6e96a2010-01-29 17:47:12 +00001098static const char *hp_mux_text[] = {
1099 "Mixer",
1100 "DAC",
1101};
1102
1103#define WM8994_HP_ENUM(xname, xenum) \
1104{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1105 .info = snd_soc_info_enum_double, \
1106 .get = snd_soc_dapm_get_enum_double, \
1107 .put = wm8994_put_hp_enum, \
1108 .private_value = (unsigned long)&xenum }
1109
1110static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
1111 struct snd_ctl_elem_value *ucontrol)
1112{
1113 struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol);
1114 struct snd_soc_codec *codec = w->codec;
1115 int ret;
1116
1117 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1118
1119 wm8994_update_class_w(codec);
1120
1121 return ret;
1122}
1123
1124static const struct soc_enum hpl_enum =
1125 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
1126
1127static const struct snd_kcontrol_new hpl_mux =
1128 WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
1129
1130static const struct soc_enum hpr_enum =
1131 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
1132
1133static const struct snd_kcontrol_new hpr_mux =
1134 WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
1135
1136static const char *adc_mux_text[] = {
1137 "ADC",
1138 "DMIC",
1139};
1140
1141static const struct soc_enum adc_enum =
1142 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
1143
1144static const struct snd_kcontrol_new adcl_mux =
1145 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
1146
1147static const struct snd_kcontrol_new adcr_mux =
1148 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
1149
1150static const struct snd_kcontrol_new left_speaker_mixer[] = {
1151SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
1152SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
1153SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
1154SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
1155SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
1156};
1157
1158static const struct snd_kcontrol_new right_speaker_mixer[] = {
1159SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
1160SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
1161SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
1162SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
1163SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1164};
1165
1166/* Debugging; dump chip status after DAPM transitions */
1167static int post_ev(struct snd_soc_dapm_widget *w,
1168 struct snd_kcontrol *kcontrol, int event)
1169{
1170 struct snd_soc_codec *codec = w->codec;
1171 dev_dbg(codec->dev, "SRC status: %x\n",
1172 snd_soc_read(codec,
1173 WM8994_RATE_STATUS));
1174 return 0;
1175}
1176
1177static const struct snd_kcontrol_new aif1adc1l_mix[] = {
1178SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1179 1, 1, 0),
1180SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
1181 0, 1, 0),
1182};
1183
1184static const struct snd_kcontrol_new aif1adc1r_mix[] = {
1185SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1186 1, 1, 0),
1187SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
1188 0, 1, 0),
1189};
1190
Mark Browna3257ba2010-07-19 14:02:34 +01001191static const struct snd_kcontrol_new aif1adc2l_mix[] = {
1192SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1193 1, 1, 0),
1194SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
1195 0, 1, 0),
1196};
1197
1198static const struct snd_kcontrol_new aif1adc2r_mix[] = {
1199SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1200 1, 1, 0),
1201SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
1202 0, 1, 0),
1203};
1204
Mark Brown9e6e96a2010-01-29 17:47:12 +00001205static const struct snd_kcontrol_new aif2dac2l_mix[] = {
1206SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1207 5, 1, 0),
1208SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1209 4, 1, 0),
1210SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1211 2, 1, 0),
1212SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1213 1, 1, 0),
1214SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
1215 0, 1, 0),
1216};
1217
1218static const struct snd_kcontrol_new aif2dac2r_mix[] = {
1219SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1220 5, 1, 0),
1221SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1222 4, 1, 0),
1223SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1224 2, 1, 0),
1225SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1226 1, 1, 0),
1227SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
1228 0, 1, 0),
1229};
1230
1231#define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
1232{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1233 .info = snd_soc_info_volsw, \
1234 .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
1235 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
1236
1237static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1238 struct snd_ctl_elem_value *ucontrol)
1239{
1240 struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol);
1241 struct snd_soc_codec *codec = w->codec;
1242 int ret;
1243
1244 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1245
1246 wm8994_update_class_w(codec);
1247
1248 return ret;
1249}
1250
1251static const struct snd_kcontrol_new dac1l_mix[] = {
1252WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1253 5, 1, 0),
1254WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1255 4, 1, 0),
1256WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1257 2, 1, 0),
1258WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1259 1, 1, 0),
1260WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
1261 0, 1, 0),
1262};
1263
1264static const struct snd_kcontrol_new dac1r_mix[] = {
1265WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1266 5, 1, 0),
1267WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1268 4, 1, 0),
1269WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1270 2, 1, 0),
1271WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1272 1, 1, 0),
1273WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
1274 0, 1, 0),
1275};
1276
1277static const char *sidetone_text[] = {
1278 "ADC/DMIC1", "DMIC2",
1279};
1280
1281static const struct soc_enum sidetone1_enum =
1282 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
1283
1284static const struct snd_kcontrol_new sidetone1_mux =
1285 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1286
1287static const struct soc_enum sidetone2_enum =
1288 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
1289
1290static const struct snd_kcontrol_new sidetone2_mux =
1291 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
1292
1293static const char *aif1dac_text[] = {
1294 "AIF1DACDAT", "AIF3DACDAT",
1295};
1296
1297static const struct soc_enum aif1dac_enum =
1298 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
1299
1300static const struct snd_kcontrol_new aif1dac_mux =
1301 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
1302
1303static const char *aif2dac_text[] = {
1304 "AIF2DACDAT", "AIF3DACDAT",
1305};
1306
1307static const struct soc_enum aif2dac_enum =
1308 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
1309
1310static const struct snd_kcontrol_new aif2dac_mux =
1311 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
1312
1313static const char *aif2adc_text[] = {
1314 "AIF2ADCDAT", "AIF3DACDAT",
1315};
1316
1317static const struct soc_enum aif2adc_enum =
1318 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
1319
1320static const struct snd_kcontrol_new aif2adc_mux =
1321 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
1322
1323static const char *aif3adc_text[] = {
Mark Brownc4431df2010-11-26 15:21:07 +00001324 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
Mark Brown9e6e96a2010-01-29 17:47:12 +00001325};
1326
Mark Brownc4431df2010-11-26 15:21:07 +00001327static const struct soc_enum wm8994_aif3adc_enum =
Mark Brown9e6e96a2010-01-29 17:47:12 +00001328 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
1329
Mark Brownc4431df2010-11-26 15:21:07 +00001330static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1331 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1332
1333static const struct soc_enum wm8958_aif3adc_enum =
1334 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1335
1336static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1337 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1338
1339static const char *mono_pcm_out_text[] = {
1340 "None", "AIF2ADCL", "AIF2ADCR",
1341};
1342
1343static const struct soc_enum mono_pcm_out_enum =
1344 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1345
1346static const struct snd_kcontrol_new mono_pcm_out_mux =
1347 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1348
1349static const char *aif2dac_src_text[] = {
1350 "AIF2", "AIF3",
1351};
1352
1353/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1354static const struct soc_enum aif2dacl_src_enum =
1355 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1356
1357static const struct snd_kcontrol_new aif2dacl_src_mux =
1358 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1359
1360static const struct soc_enum aif2dacr_src_enum =
1361 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1362
1363static const struct snd_kcontrol_new aif2dacr_src_mux =
1364 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001365
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001366static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
1367SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_ev,
1368 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1369SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_ev,
1370 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1371
1372SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1373 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1374SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1375 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1376SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1377 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1378SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
1379 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1380
1381SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
1382};
1383
1384static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
1385SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0),
1386SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0)
1387};
1388
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00001389static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
1390SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
1391 dac_ev, SND_SOC_DAPM_PRE_PMU),
1392SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
1393 dac_ev, SND_SOC_DAPM_PRE_PMU),
1394SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
1395 dac_ev, SND_SOC_DAPM_PRE_PMU),
1396SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
1397 dac_ev, SND_SOC_DAPM_PRE_PMU),
1398};
1399
1400static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
1401SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
1402SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
1403SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
1404SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
1405};
1406
Mark Brown9e6e96a2010-01-29 17:47:12 +00001407static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
1408SND_SOC_DAPM_INPUT("DMIC1DAT"),
1409SND_SOC_DAPM_INPUT("DMIC2DAT"),
Mark Brown66b47fd2010-07-08 11:25:43 +09001410SND_SOC_DAPM_INPUT("Clock"),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001411
1412SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
1413 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1414
1415SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0),
1416SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0),
1417SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0),
1418
Mark Brown7f94de42011-02-03 16:27:34 +00001419SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001420 0, WM8994_POWER_MANAGEMENT_4, 9, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001421SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001422 0, WM8994_POWER_MANAGEMENT_4, 8, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001423SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
1424 WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001425 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001426SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1427 WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001428 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001429
Mark Brown7f94de42011-02-03 16:27:34 +00001430SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001431 0, WM8994_POWER_MANAGEMENT_4, 11, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001432SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001433 0, WM8994_POWER_MANAGEMENT_4, 10, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001434SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
1435 WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001436 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brownd6addcc2010-11-26 15:21:08 +00001437SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1438 WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
Mark Brownb2822a82010-11-30 16:59:29 +00001439 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001440
1441SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
1442 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
1443SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
1444 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
1445
Mark Browna3257ba2010-07-19 14:02:34 +01001446SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
1447 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
1448SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
1449 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
1450
Mark Brown9e6e96a2010-01-29 17:47:12 +00001451SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
1452 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
1453SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
1454 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
1455
1456SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
1457SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
1458
1459SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
1460 dac1l_mix, ARRAY_SIZE(dac1l_mix)),
1461SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
1462 dac1r_mix, ARRAY_SIZE(dac1r_mix)),
1463
1464SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
1465 WM8994_POWER_MANAGEMENT_4, 13, 0),
1466SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
1467 WM8994_POWER_MANAGEMENT_4, 12, 0),
Mark Brownd6addcc2010-11-26 15:21:08 +00001468SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
1469 WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
1470 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1471SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1472 WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
1473 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001474
1475SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1476SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
Mark Brown7f94de42011-02-03 16:27:34 +00001477SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001478SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
1479
1480SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
1481SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
1482SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
Mark Brown9e6e96a2010-01-29 17:47:12 +00001483
1484SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
1485SND_SOC_DAPM_AIF_IN("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
1486
1487SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
1488
1489SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
1490SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
1491SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
1492SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
1493
1494/* Power is done with the muxes since the ADC power also controls the
1495 * downsampling chain, the chip will automatically manage the analogue
1496 * specific portions.
1497 */
1498SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
1499SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
1500
1501SND_SOC_DAPM_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
1502SND_SOC_DAPM_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
1503
Mark Brown9e6e96a2010-01-29 17:47:12 +00001504SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
1505SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
1506
1507SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1508 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1509SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1510 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1511
1512SND_SOC_DAPM_POST("Debug log", post_ev),
1513};
1514
Mark Brownc4431df2010-11-26 15:21:07 +00001515static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1516SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1517};
Mark Brown9e6e96a2010-01-29 17:47:12 +00001518
Mark Brownc4431df2010-11-26 15:21:07 +00001519static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1520SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1521SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1522SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1523SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1524};
1525
1526static const struct snd_soc_dapm_route intercon[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001527 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
1528 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
1529
1530 { "DSP1CLK", NULL, "CLK_SYS" },
1531 { "DSP2CLK", NULL, "CLK_SYS" },
1532 { "DSPINTCLK", NULL, "CLK_SYS" },
1533
1534 { "AIF1ADC1L", NULL, "AIF1CLK" },
1535 { "AIF1ADC1L", NULL, "DSP1CLK" },
1536 { "AIF1ADC1R", NULL, "AIF1CLK" },
1537 { "AIF1ADC1R", NULL, "DSP1CLK" },
1538 { "AIF1ADC1R", NULL, "DSPINTCLK" },
1539
1540 { "AIF1DAC1L", NULL, "AIF1CLK" },
1541 { "AIF1DAC1L", NULL, "DSP1CLK" },
1542 { "AIF1DAC1R", NULL, "AIF1CLK" },
1543 { "AIF1DAC1R", NULL, "DSP1CLK" },
1544 { "AIF1DAC1R", NULL, "DSPINTCLK" },
1545
1546 { "AIF1ADC2L", NULL, "AIF1CLK" },
1547 { "AIF1ADC2L", NULL, "DSP1CLK" },
1548 { "AIF1ADC2R", NULL, "AIF1CLK" },
1549 { "AIF1ADC2R", NULL, "DSP1CLK" },
1550 { "AIF1ADC2R", NULL, "DSPINTCLK" },
1551
1552 { "AIF1DAC2L", NULL, "AIF1CLK" },
1553 { "AIF1DAC2L", NULL, "DSP1CLK" },
1554 { "AIF1DAC2R", NULL, "AIF1CLK" },
1555 { "AIF1DAC2R", NULL, "DSP1CLK" },
1556 { "AIF1DAC2R", NULL, "DSPINTCLK" },
1557
1558 { "AIF2ADCL", NULL, "AIF2CLK" },
1559 { "AIF2ADCL", NULL, "DSP2CLK" },
1560 { "AIF2ADCR", NULL, "AIF2CLK" },
1561 { "AIF2ADCR", NULL, "DSP2CLK" },
1562 { "AIF2ADCR", NULL, "DSPINTCLK" },
1563
1564 { "AIF2DACL", NULL, "AIF2CLK" },
1565 { "AIF2DACL", NULL, "DSP2CLK" },
1566 { "AIF2DACR", NULL, "AIF2CLK" },
1567 { "AIF2DACR", NULL, "DSP2CLK" },
1568 { "AIF2DACR", NULL, "DSPINTCLK" },
1569
1570 { "DMIC1L", NULL, "DMIC1DAT" },
1571 { "DMIC1L", NULL, "CLK_SYS" },
1572 { "DMIC1R", NULL, "DMIC1DAT" },
1573 { "DMIC1R", NULL, "CLK_SYS" },
1574 { "DMIC2L", NULL, "DMIC2DAT" },
1575 { "DMIC2L", NULL, "CLK_SYS" },
1576 { "DMIC2R", NULL, "DMIC2DAT" },
1577 { "DMIC2R", NULL, "CLK_SYS" },
1578
1579 { "ADCL", NULL, "AIF1CLK" },
1580 { "ADCL", NULL, "DSP1CLK" },
1581 { "ADCL", NULL, "DSPINTCLK" },
1582
1583 { "ADCR", NULL, "AIF1CLK" },
1584 { "ADCR", NULL, "DSP1CLK" },
1585 { "ADCR", NULL, "DSPINTCLK" },
1586
1587 { "ADCL Mux", "ADC", "ADCL" },
1588 { "ADCL Mux", "DMIC", "DMIC1L" },
1589 { "ADCR Mux", "ADC", "ADCR" },
1590 { "ADCR Mux", "DMIC", "DMIC1R" },
1591
1592 { "DAC1L", NULL, "AIF1CLK" },
1593 { "DAC1L", NULL, "DSP1CLK" },
1594 { "DAC1L", NULL, "DSPINTCLK" },
1595
1596 { "DAC1R", NULL, "AIF1CLK" },
1597 { "DAC1R", NULL, "DSP1CLK" },
1598 { "DAC1R", NULL, "DSPINTCLK" },
1599
1600 { "DAC2L", NULL, "AIF2CLK" },
1601 { "DAC2L", NULL, "DSP2CLK" },
1602 { "DAC2L", NULL, "DSPINTCLK" },
1603
1604 { "DAC2R", NULL, "AIF2DACR" },
1605 { "DAC2R", NULL, "AIF2CLK" },
1606 { "DAC2R", NULL, "DSP2CLK" },
1607 { "DAC2R", NULL, "DSPINTCLK" },
1608
1609 { "TOCLK", NULL, "CLK_SYS" },
1610
1611 /* AIF1 outputs */
1612 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
1613 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1614 { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1615
1616 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
1617 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1618 { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1619
Mark Browna3257ba2010-07-19 14:02:34 +01001620 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
1621 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1622 { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1623
1624 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
1625 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1626 { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1627
Mark Brown9e6e96a2010-01-29 17:47:12 +00001628 /* Pin level routing for AIF3 */
1629 { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
1630 { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
1631 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
1632 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
1633
Mark Brown9e6e96a2010-01-29 17:47:12 +00001634 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
1635 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1636 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
1637 { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
1638 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1639 { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1640 { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
1641
1642 /* DAC1 inputs */
Mark Brown9e6e96a2010-01-29 17:47:12 +00001643 { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
1644 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1645 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1646 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1647 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1648
Mark Brown9e6e96a2010-01-29 17:47:12 +00001649 { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
1650 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1651 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1652 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1653 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1654
1655 /* DAC2/AIF2 outputs */
1656 { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001657 { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
1658 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1659 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1660 { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1661 { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1662
1663 { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
Mark Brown9e6e96a2010-01-29 17:47:12 +00001664 { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
1665 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1666 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1667 { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1668 { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1669
Mark Brown7f94de42011-02-03 16:27:34 +00001670 { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
1671 { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
1672 { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
1673 { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
1674
Mark Brown9e6e96a2010-01-29 17:47:12 +00001675 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1676
1677 /* AIF3 output */
1678 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
1679 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
1680 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
1681 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
1682 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
1683 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
1684 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
1685 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
1686
1687 /* Sidetone */
1688 { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
1689 { "Left Sidetone", "DMIC2", "DMIC2L" },
1690 { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
1691 { "Right Sidetone", "DMIC2", "DMIC2R" },
1692
1693 /* Output stages */
1694 { "Left Output Mixer", "DAC Switch", "DAC1L" },
1695 { "Right Output Mixer", "DAC Switch", "DAC1R" },
1696
1697 { "SPKL", "DAC1 Switch", "DAC1L" },
1698 { "SPKL", "DAC2 Switch", "DAC2L" },
1699
1700 { "SPKR", "DAC1 Switch", "DAC1R" },
1701 { "SPKR", "DAC2 Switch", "DAC2R" },
1702
1703 { "Left Headphone Mux", "DAC", "DAC1L" },
1704 { "Right Headphone Mux", "DAC", "DAC1R" },
1705};
1706
Dimitris Papastamos173efa02011-02-11 16:32:11 +00001707static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
1708 { "DAC1L", NULL, "Late DAC1L Enable PGA" },
1709 { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
1710 { "DAC1R", NULL, "Late DAC1R Enable PGA" },
1711 { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
1712 { "DAC2L", NULL, "Late DAC2L Enable PGA" },
1713 { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
1714 { "DAC2R", NULL, "Late DAC2R Enable PGA" },
1715 { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
1716};
1717
1718static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
1719 { "DAC1L", NULL, "DAC1L Mixer" },
1720 { "DAC1R", NULL, "DAC1R Mixer" },
1721 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
1722 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
1723};
1724
Mark Brown6ed8f142011-02-03 16:27:35 +00001725static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
1726 { "AIF1DACDAT", NULL, "AIF2DACDAT" },
1727 { "AIF2DACDAT", NULL, "AIF1DACDAT" },
1728 { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
1729 { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
1730};
1731
Mark Brownc4431df2010-11-26 15:21:07 +00001732static const struct snd_soc_dapm_route wm8994_intercon[] = {
1733 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1734 { "AIF2DACR", NULL, "AIF2DAC Mux" },
1735};
1736
1737static const struct snd_soc_dapm_route wm8958_intercon[] = {
1738 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1739 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1740
1741 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1742 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1743 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1744 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1745
1746 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1747 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1748
1749 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1750};
1751
Mark Brown9e6e96a2010-01-29 17:47:12 +00001752/* The size in bits of the FLL divide multiplied by 10
1753 * to allow rounding later */
1754#define FIXED_FLL_SIZE ((1 << 16) * 10)
1755
1756struct fll_div {
1757 u16 outdiv;
1758 u16 n;
1759 u16 k;
1760 u16 clk_ref_div;
1761 u16 fll_fratio;
1762};
1763
1764static int wm8994_get_fll_config(struct fll_div *fll,
1765 int freq_in, int freq_out)
1766{
1767 u64 Kpart;
1768 unsigned int K, Ndiv, Nmod;
1769
1770 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
1771
1772 /* Scale the input frequency down to <= 13.5MHz */
1773 fll->clk_ref_div = 0;
1774 while (freq_in > 13500000) {
1775 fll->clk_ref_div++;
1776 freq_in /= 2;
1777
1778 if (fll->clk_ref_div > 3)
1779 return -EINVAL;
1780 }
1781 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1782
1783 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1784 fll->outdiv = 3;
1785 while (freq_out * (fll->outdiv + 1) < 90000000) {
1786 fll->outdiv++;
1787 if (fll->outdiv > 63)
1788 return -EINVAL;
1789 }
1790 freq_out *= fll->outdiv + 1;
1791 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1792
1793 if (freq_in > 1000000) {
1794 fll->fll_fratio = 0;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001795 } else if (freq_in > 256000) {
1796 fll->fll_fratio = 1;
1797 freq_in *= 2;
1798 } else if (freq_in > 128000) {
1799 fll->fll_fratio = 2;
1800 freq_in *= 4;
1801 } else if (freq_in > 64000) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00001802 fll->fll_fratio = 3;
1803 freq_in *= 8;
Mark Brown7d48a6a2010-04-20 13:36:11 +09001804 } else {
1805 fll->fll_fratio = 4;
1806 freq_in *= 16;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001807 }
1808 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1809
1810 /* Now, calculate N.K */
1811 Ndiv = freq_out / freq_in;
1812
1813 fll->n = Ndiv;
1814 Nmod = freq_out % freq_in;
1815 pr_debug("Nmod=%d\n", Nmod);
1816
1817 /* Calculate fractional part - scale up so we can round. */
1818 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
1819
1820 do_div(Kpart, freq_in);
1821
1822 K = Kpart & 0xFFFFFFFF;
1823
1824 if ((K % 10) >= 5)
1825 K += 5;
1826
1827 /* Move down to proper range now rounding is done */
1828 fll->k = K / 10;
1829
1830 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1831
1832 return 0;
1833}
1834
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001835static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
Mark Brown9e6e96a2010-01-29 17:47:12 +00001836 unsigned int freq_in, unsigned int freq_out)
1837{
Mark Brownb2c812e2010-04-14 15:35:19 +09001838 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00001839 int reg_offset, ret;
1840 struct fll_div fll;
1841 u16 reg, aif1, aif2;
1842
1843 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
1844 & WM8994_AIF1CLK_ENA;
1845
1846 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
1847 & WM8994_AIF2CLK_ENA;
1848
1849 switch (id) {
1850 case WM8994_FLL1:
1851 reg_offset = 0;
1852 id = 0;
1853 break;
1854 case WM8994_FLL2:
1855 reg_offset = 0x20;
1856 id = 1;
1857 break;
1858 default:
1859 return -EINVAL;
1860 }
1861
Mark Brown136ff2a2010-04-20 12:56:18 +09001862 switch (src) {
Mark Brown7add84a2010-04-22 02:29:01 +09001863 case 0:
1864 /* Allow no source specification when stopping */
1865 if (freq_out)
1866 return -EINVAL;
Mark Brown4514e892010-12-03 16:02:10 +00001867 src = wm8994->fll[id].src;
Mark Brown7add84a2010-04-22 02:29:01 +09001868 break;
Mark Brown136ff2a2010-04-20 12:56:18 +09001869 case WM8994_FLL_SRC_MCLK1:
1870 case WM8994_FLL_SRC_MCLK2:
1871 case WM8994_FLL_SRC_LRCLK:
1872 case WM8994_FLL_SRC_BCLK:
1873 break;
1874 default:
1875 return -EINVAL;
1876 }
1877
Mark Brown9e6e96a2010-01-29 17:47:12 +00001878 /* Are we changing anything? */
1879 if (wm8994->fll[id].src == src &&
1880 wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
1881 return 0;
1882
1883 /* If we're stopping the FLL redo the old config - no
1884 * registers will actually be written but we avoid GCC flow
1885 * analysis bugs spewing warnings.
1886 */
1887 if (freq_out)
1888 ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
1889 else
1890 ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
1891 wm8994->fll[id].out);
1892 if (ret < 0)
1893 return ret;
1894
1895 /* Gate the AIF clocks while we reclock */
1896 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1897 WM8994_AIF1CLK_ENA, 0);
1898 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1899 WM8994_AIF2CLK_ENA, 0);
1900
1901 /* We always need to disable the FLL while reconfiguring */
1902 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1903 WM8994_FLL1_ENA, 0);
1904
1905 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
1906 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
1907 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
1908 WM8994_FLL1_OUTDIV_MASK |
1909 WM8994_FLL1_FRATIO_MASK, reg);
1910
1911 snd_soc_write(codec, WM8994_FLL1_CONTROL_3 + reg_offset, fll.k);
1912
1913 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
1914 WM8994_FLL1_N_MASK,
1915 fll.n << WM8994_FLL1_N_SHIFT);
1916
1917 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
Mark Brown136ff2a2010-04-20 12:56:18 +09001918 WM8994_FLL1_REFCLK_DIV_MASK |
1919 WM8994_FLL1_REFCLK_SRC_MASK,
1920 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
1921 (src - 1));
Mark Brown9e6e96a2010-01-29 17:47:12 +00001922
1923 /* Enable (with fractional mode if required) */
1924 if (freq_out) {
1925 if (fll.k)
1926 reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
1927 else
1928 reg = WM8994_FLL1_ENA;
1929 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
1930 WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
1931 reg);
1932 }
1933
1934 wm8994->fll[id].in = freq_in;
1935 wm8994->fll[id].out = freq_out;
Mark Brown136ff2a2010-04-20 12:56:18 +09001936 wm8994->fll[id].src = src;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001937
1938 /* Enable any gated AIF clocks */
1939 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
1940 WM8994_AIF1CLK_ENA, aif1);
1941 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
1942 WM8994_AIF2CLK_ENA, aif2);
1943
1944 configure_clock(codec);
1945
1946 return 0;
1947}
1948
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001949
Mark Brown66b47fd2010-07-08 11:25:43 +09001950static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
1951
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001952static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
1953 unsigned int freq_in, unsigned int freq_out)
1954{
1955 return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
1956}
1957
Mark Brown9e6e96a2010-01-29 17:47:12 +00001958static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
1959 int clk_id, unsigned int freq, int dir)
1960{
1961 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09001962 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown66b47fd2010-07-08 11:25:43 +09001963 int i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00001964
1965 switch (dai->id) {
1966 case 1:
1967 case 2:
1968 break;
1969
1970 default:
1971 /* AIF3 shares clocking with AIF1/2 */
1972 return -EINVAL;
1973 }
1974
1975 switch (clk_id) {
1976 case WM8994_SYSCLK_MCLK1:
1977 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
1978 wm8994->mclk[0] = freq;
1979 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
1980 dai->id, freq);
1981 break;
1982
1983 case WM8994_SYSCLK_MCLK2:
1984 /* TODO: Set GPIO AF */
1985 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
1986 wm8994->mclk[1] = freq;
1987 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
1988 dai->id, freq);
1989 break;
1990
1991 case WM8994_SYSCLK_FLL1:
1992 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
1993 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
1994 break;
1995
1996 case WM8994_SYSCLK_FLL2:
1997 wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
1998 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
1999 break;
2000
Mark Brown66b47fd2010-07-08 11:25:43 +09002001 case WM8994_SYSCLK_OPCLK:
2002 /* Special case - a division (times 10) is given and
2003 * no effect on main clocking.
2004 */
2005 if (freq) {
2006 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
2007 if (opclk_divs[i] == freq)
2008 break;
2009 if (i == ARRAY_SIZE(opclk_divs))
2010 return -EINVAL;
2011 snd_soc_update_bits(codec, WM8994_CLOCKING_2,
2012 WM8994_OPCLK_DIV_MASK, i);
2013 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2014 WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
2015 } else {
2016 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
2017 WM8994_OPCLK_ENA, 0);
2018 }
2019
Mark Brown9e6e96a2010-01-29 17:47:12 +00002020 default:
2021 return -EINVAL;
2022 }
2023
2024 configure_clock(codec);
2025
2026 return 0;
2027}
2028
2029static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2030 enum snd_soc_bias_level level)
2031{
Mark Brown3a423152010-11-26 15:21:06 +00002032 struct wm8994 *control = codec->control_data;
Mark Brownb6b05692010-08-13 12:58:20 +01002033 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2034
Mark Brown9e6e96a2010-01-29 17:47:12 +00002035 switch (level) {
2036 case SND_SOC_BIAS_ON:
2037 break;
2038
2039 case SND_SOC_BIAS_PREPARE:
2040 /* VMID=2x40k */
2041 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
2042 WM8994_VMID_SEL_MASK, 0x2);
2043 break;
2044
2045 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002046 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown39fb51a2010-11-26 17:23:43 +00002047 pm_runtime_get_sync(codec->dev);
2048
Mark Brown8bc3c2c2010-11-30 14:56:18 +00002049 switch (control->type) {
2050 case WM8994:
2051 if (wm8994->revision < 4) {
2052 /* Tweak DC servo and DSP
2053 * configuration for improved
2054 * performance. */
2055 snd_soc_write(codec, 0x102, 0x3);
2056 snd_soc_write(codec, 0x56, 0x3);
2057 snd_soc_write(codec, 0x817, 0);
2058 snd_soc_write(codec, 0x102, 0);
2059 }
2060 break;
2061
2062 case WM8958:
2063 if (wm8994->revision == 0) {
2064 /* Optimise performance for rev A */
2065 snd_soc_write(codec, 0x102, 0x3);
2066 snd_soc_write(codec, 0xcb, 0x81);
2067 snd_soc_write(codec, 0x817, 0);
2068 snd_soc_write(codec, 0x102, 0);
2069
2070 snd_soc_update_bits(codec,
2071 WM8958_CHARGE_PUMP_2,
2072 WM8958_CP_DISCH,
2073 WM8958_CP_DISCH);
2074 }
2075 break;
Mark Brownb6b05692010-08-13 12:58:20 +01002076 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002077
2078 /* Discharge LINEOUT1 & 2 */
2079 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2080 WM8994_LINEOUT1_DISCH |
2081 WM8994_LINEOUT2_DISCH,
2082 WM8994_LINEOUT1_DISCH |
2083 WM8994_LINEOUT2_DISCH);
2084
2085 /* Startup bias, VMID ramp & buffer */
2086 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2087 WM8994_STARTUP_BIAS_ENA |
2088 WM8994_VMID_BUF_ENA |
2089 WM8994_VMID_RAMP_MASK,
2090 WM8994_STARTUP_BIAS_ENA |
2091 WM8994_VMID_BUF_ENA |
2092 (0x11 << WM8994_VMID_RAMP_SHIFT));
2093
2094 /* Main bias enable, VMID=2x40k */
2095 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
2096 WM8994_BIAS_ENA |
2097 WM8994_VMID_SEL_MASK,
2098 WM8994_BIAS_ENA | 0x2);
2099
2100 msleep(20);
2101 }
2102
2103 /* VMID=2x500k */
2104 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
2105 WM8994_VMID_SEL_MASK, 0x4);
2106
2107 break;
2108
2109 case SND_SOC_BIAS_OFF:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002110 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
Mark Brownd522ffb2010-03-30 14:29:14 +01002111 /* Switch over to startup biases */
2112 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2113 WM8994_BIAS_SRC |
2114 WM8994_STARTUP_BIAS_ENA |
2115 WM8994_VMID_BUF_ENA |
2116 WM8994_VMID_RAMP_MASK,
2117 WM8994_BIAS_SRC |
2118 WM8994_STARTUP_BIAS_ENA |
2119 WM8994_VMID_BUF_ENA |
2120 (1 << WM8994_VMID_RAMP_SHIFT));
Mark Brown9e6e96a2010-01-29 17:47:12 +00002121
Mark Brownd522ffb2010-03-30 14:29:14 +01002122 /* Disable main biases */
2123 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
2124 WM8994_BIAS_ENA |
2125 WM8994_VMID_SEL_MASK, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002126
Mark Brownd522ffb2010-03-30 14:29:14 +01002127 /* Discharge line */
2128 snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
2129 WM8994_LINEOUT1_DISCH |
2130 WM8994_LINEOUT2_DISCH,
2131 WM8994_LINEOUT1_DISCH |
2132 WM8994_LINEOUT2_DISCH);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002133
Mark Brownd522ffb2010-03-30 14:29:14 +01002134 msleep(5);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002135
Mark Brownd522ffb2010-03-30 14:29:14 +01002136 /* Switch off startup biases */
2137 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
2138 WM8994_BIAS_SRC |
2139 WM8994_STARTUP_BIAS_ENA |
2140 WM8994_VMID_BUF_ENA |
2141 WM8994_VMID_RAMP_MASK, 0);
Mark Brown39fb51a2010-11-26 17:23:43 +00002142
2143 pm_runtime_put(codec->dev);
Mark Brownd522ffb2010-03-30 14:29:14 +01002144 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002145 break;
2146 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002147 codec->dapm.bias_level = level;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002148 return 0;
2149}
2150
2151static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2152{
2153 struct snd_soc_codec *codec = dai->codec;
Mark Brownc4431df2010-11-26 15:21:07 +00002154 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002155 int ms_reg;
2156 int aif1_reg;
2157 int ms = 0;
2158 int aif1 = 0;
2159
2160 switch (dai->id) {
2161 case 1:
2162 ms_reg = WM8994_AIF1_MASTER_SLAVE;
2163 aif1_reg = WM8994_AIF1_CONTROL_1;
2164 break;
2165 case 2:
2166 ms_reg = WM8994_AIF2_MASTER_SLAVE;
2167 aif1_reg = WM8994_AIF2_CONTROL_1;
2168 break;
2169 default:
2170 return -EINVAL;
2171 }
2172
2173 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2174 case SND_SOC_DAIFMT_CBS_CFS:
2175 break;
2176 case SND_SOC_DAIFMT_CBM_CFM:
2177 ms = WM8994_AIF1_MSTR;
2178 break;
2179 default:
2180 return -EINVAL;
2181 }
2182
2183 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2184 case SND_SOC_DAIFMT_DSP_B:
2185 aif1 |= WM8994_AIF1_LRCLK_INV;
2186 case SND_SOC_DAIFMT_DSP_A:
2187 aif1 |= 0x18;
2188 break;
2189 case SND_SOC_DAIFMT_I2S:
2190 aif1 |= 0x10;
2191 break;
2192 case SND_SOC_DAIFMT_RIGHT_J:
2193 break;
2194 case SND_SOC_DAIFMT_LEFT_J:
2195 aif1 |= 0x8;
2196 break;
2197 default:
2198 return -EINVAL;
2199 }
2200
2201 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2202 case SND_SOC_DAIFMT_DSP_A:
2203 case SND_SOC_DAIFMT_DSP_B:
2204 /* frame inversion not valid for DSP modes */
2205 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2206 case SND_SOC_DAIFMT_NB_NF:
2207 break;
2208 case SND_SOC_DAIFMT_IB_NF:
2209 aif1 |= WM8994_AIF1_BCLK_INV;
2210 break;
2211 default:
2212 return -EINVAL;
2213 }
2214 break;
2215
2216 case SND_SOC_DAIFMT_I2S:
2217 case SND_SOC_DAIFMT_RIGHT_J:
2218 case SND_SOC_DAIFMT_LEFT_J:
2219 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2220 case SND_SOC_DAIFMT_NB_NF:
2221 break;
2222 case SND_SOC_DAIFMT_IB_IF:
2223 aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
2224 break;
2225 case SND_SOC_DAIFMT_IB_NF:
2226 aif1 |= WM8994_AIF1_BCLK_INV;
2227 break;
2228 case SND_SOC_DAIFMT_NB_IF:
2229 aif1 |= WM8994_AIF1_LRCLK_INV;
2230 break;
2231 default:
2232 return -EINVAL;
2233 }
2234 break;
2235 default:
2236 return -EINVAL;
2237 }
2238
Mark Brownc4431df2010-11-26 15:21:07 +00002239 /* The AIF2 format configuration needs to be mirrored to AIF3
2240 * on WM8958 if it's in use so just do it all the time. */
2241 if (control->type == WM8958 && dai->id == 2)
2242 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2243 WM8994_AIF1_LRCLK_INV |
2244 WM8958_AIF3_FMT_MASK, aif1);
2245
Mark Brown9e6e96a2010-01-29 17:47:12 +00002246 snd_soc_update_bits(codec, aif1_reg,
2247 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
2248 WM8994_AIF1_FMT_MASK,
2249 aif1);
2250 snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
2251 ms);
2252
2253 return 0;
2254}
2255
2256static struct {
2257 int val, rate;
2258} srs[] = {
2259 { 0, 8000 },
2260 { 1, 11025 },
2261 { 2, 12000 },
2262 { 3, 16000 },
2263 { 4, 22050 },
2264 { 5, 24000 },
2265 { 6, 32000 },
2266 { 7, 44100 },
2267 { 8, 48000 },
2268 { 9, 88200 },
2269 { 10, 96000 },
2270};
2271
2272static int fs_ratios[] = {
2273 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
2274};
2275
2276static int bclk_divs[] = {
2277 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
2278 640, 880, 960, 1280, 1760, 1920
2279};
2280
2281static int wm8994_hw_params(struct snd_pcm_substream *substream,
2282 struct snd_pcm_hw_params *params,
2283 struct snd_soc_dai *dai)
2284{
2285 struct snd_soc_codec *codec = dai->codec;
Mark Brownc4431df2010-11-26 15:21:07 +00002286 struct wm8994 *control = codec->control_data;
Mark Brownb2c812e2010-04-14 15:35:19 +09002287 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002288 int aif1_reg;
Mark Brownb1e43d92010-12-07 17:14:56 +00002289 int aif2_reg;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002290 int bclk_reg;
2291 int lrclk_reg;
2292 int rate_reg;
2293 int aif1 = 0;
Mark Brownb1e43d92010-12-07 17:14:56 +00002294 int aif2 = 0;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002295 int bclk = 0;
2296 int lrclk = 0;
2297 int rate_val = 0;
2298 int id = dai->id - 1;
2299
2300 int i, cur_val, best_val, bclk_rate, best;
2301
2302 switch (dai->id) {
2303 case 1:
2304 aif1_reg = WM8994_AIF1_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002305 aif2_reg = WM8994_AIF1_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002306 bclk_reg = WM8994_AIF1_BCLK;
2307 rate_reg = WM8994_AIF1_RATE;
2308 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002309 wm8994->lrclk_shared[0]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002310 lrclk_reg = WM8994_AIF1DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002311 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002312 lrclk_reg = WM8994_AIF1ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002313 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
2314 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002315 break;
2316 case 2:
2317 aif1_reg = WM8994_AIF2_CONTROL_1;
Mark Brownb1e43d92010-12-07 17:14:56 +00002318 aif2_reg = WM8994_AIF2_CONTROL_2;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002319 bclk_reg = WM8994_AIF2_BCLK;
2320 rate_reg = WM8994_AIF2_RATE;
2321 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
Mark Brown7d83d212010-08-23 10:54:43 +01002322 wm8994->lrclk_shared[1]) {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002323 lrclk_reg = WM8994_AIF2DAC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002324 } else {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002325 lrclk_reg = WM8994_AIF2ADC_LRCLK;
Mark Brown7d83d212010-08-23 10:54:43 +01002326 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
2327 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002328 break;
Mark Brownc4431df2010-11-26 15:21:07 +00002329 case 3:
2330 switch (control->type) {
2331 case WM8958:
2332 aif1_reg = WM8958_AIF3_CONTROL_1;
2333 break;
2334 default:
2335 return 0;
2336 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002337 default:
2338 return -EINVAL;
2339 }
2340
2341 bclk_rate = params_rate(params) * 2;
2342 switch (params_format(params)) {
2343 case SNDRV_PCM_FORMAT_S16_LE:
2344 bclk_rate *= 16;
2345 break;
2346 case SNDRV_PCM_FORMAT_S20_3LE:
2347 bclk_rate *= 20;
2348 aif1 |= 0x20;
2349 break;
2350 case SNDRV_PCM_FORMAT_S24_LE:
2351 bclk_rate *= 24;
2352 aif1 |= 0x40;
2353 break;
2354 case SNDRV_PCM_FORMAT_S32_LE:
2355 bclk_rate *= 32;
2356 aif1 |= 0x60;
2357 break;
2358 default:
2359 return -EINVAL;
2360 }
2361
2362 /* Try to find an appropriate sample rate; look for an exact match. */
2363 for (i = 0; i < ARRAY_SIZE(srs); i++)
2364 if (srs[i].rate == params_rate(params))
2365 break;
2366 if (i == ARRAY_SIZE(srs))
2367 return -EINVAL;
2368 rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
2369
2370 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
2371 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
2372 dai->id, wm8994->aifclk[id], bclk_rate);
2373
Mark Brownb1e43d92010-12-07 17:14:56 +00002374 if (params_channels(params) == 1 &&
2375 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2376 aif2 |= WM8994_AIF1_MONO;
2377
Mark Brown9e6e96a2010-01-29 17:47:12 +00002378 if (wm8994->aifclk[id] == 0) {
2379 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
2380 return -EINVAL;
2381 }
2382
2383 /* AIFCLK/fs ratio; look for a close match in either direction */
2384 best = 0;
2385 best_val = abs((fs_ratios[0] * params_rate(params))
2386 - wm8994->aifclk[id]);
2387 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
2388 cur_val = abs((fs_ratios[i] * params_rate(params))
2389 - wm8994->aifclk[id]);
2390 if (cur_val >= best_val)
2391 continue;
2392 best = i;
2393 best_val = cur_val;
2394 }
2395 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
2396 dai->id, fs_ratios[best]);
2397 rate_val |= best;
2398
2399 /* We may not get quite the right frequency if using
2400 * approximate clocks so look for the closest match that is
2401 * higher than the target (we need to ensure that there enough
2402 * BCLKs to clock out the samples).
2403 */
2404 best = 0;
2405 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002406 cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002407 if (cur_val < 0) /* BCLK table is sorted */
2408 break;
2409 best = i;
2410 }
Joonyoung Shim07cd8ad2010-02-02 18:53:19 +09002411 bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
Mark Brown9e6e96a2010-01-29 17:47:12 +00002412 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
2413 bclk_divs[best], bclk_rate);
2414 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
2415
2416 lrclk = bclk_rate / params_rate(params);
2417 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
2418 lrclk, bclk_rate / lrclk);
2419
2420 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
Mark Brownb1e43d92010-12-07 17:14:56 +00002421 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002422 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
2423 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
2424 lrclk);
2425 snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
2426 WM8994_AIF1CLK_RATE_MASK, rate_val);
2427
2428 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2429 switch (dai->id) {
2430 case 1:
2431 wm8994->dac_rates[0] = params_rate(params);
2432 wm8994_set_retune_mobile(codec, 0);
2433 wm8994_set_retune_mobile(codec, 1);
2434 break;
2435 case 2:
2436 wm8994->dac_rates[1] = params_rate(params);
2437 wm8994_set_retune_mobile(codec, 2);
2438 break;
2439 }
2440 }
2441
2442 return 0;
2443}
2444
Mark Brownc4431df2010-11-26 15:21:07 +00002445static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2446 struct snd_pcm_hw_params *params,
2447 struct snd_soc_dai *dai)
2448{
2449 struct snd_soc_codec *codec = dai->codec;
2450 struct wm8994 *control = codec->control_data;
2451 int aif1_reg;
2452 int aif1 = 0;
2453
2454 switch (dai->id) {
2455 case 3:
2456 switch (control->type) {
2457 case WM8958:
2458 aif1_reg = WM8958_AIF3_CONTROL_1;
2459 break;
2460 default:
2461 return 0;
2462 }
2463 default:
2464 return 0;
2465 }
2466
2467 switch (params_format(params)) {
2468 case SNDRV_PCM_FORMAT_S16_LE:
2469 break;
2470 case SNDRV_PCM_FORMAT_S20_3LE:
2471 aif1 |= 0x20;
2472 break;
2473 case SNDRV_PCM_FORMAT_S24_LE:
2474 aif1 |= 0x40;
2475 break;
2476 case SNDRV_PCM_FORMAT_S32_LE:
2477 aif1 |= 0x60;
2478 break;
2479 default:
2480 return -EINVAL;
2481 }
2482
2483 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2484}
2485
Mark Brown9e6e96a2010-01-29 17:47:12 +00002486static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2487{
2488 struct snd_soc_codec *codec = codec_dai->codec;
2489 int mute_reg;
2490 int reg;
2491
2492 switch (codec_dai->id) {
2493 case 1:
2494 mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
2495 break;
2496 case 2:
2497 mute_reg = WM8994_AIF2_DAC_FILTERS_1;
2498 break;
2499 default:
2500 return -EINVAL;
2501 }
2502
2503 if (mute)
2504 reg = WM8994_AIF1DAC1_MUTE;
2505 else
2506 reg = 0;
2507
2508 snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
2509
2510 return 0;
2511}
2512
Mark Brown778a76e2010-03-22 22:05:10 +00002513static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2514{
2515 struct snd_soc_codec *codec = codec_dai->codec;
2516 int reg, val, mask;
2517
2518 switch (codec_dai->id) {
2519 case 1:
2520 reg = WM8994_AIF1_MASTER_SLAVE;
2521 mask = WM8994_AIF1_TRI;
2522 break;
2523 case 2:
2524 reg = WM8994_AIF2_MASTER_SLAVE;
2525 mask = WM8994_AIF2_TRI;
2526 break;
2527 case 3:
2528 reg = WM8994_POWER_MANAGEMENT_6;
2529 mask = WM8994_AIF3_TRI;
2530 break;
2531 default:
2532 return -EINVAL;
2533 }
2534
2535 if (tristate)
2536 val = mask;
2537 else
2538 val = 0;
2539
Qiao Zhou78b3fb42011-01-19 19:10:47 +08002540 return snd_soc_update_bits(codec, reg, mask, val);
Mark Brown778a76e2010-03-22 22:05:10 +00002541}
2542
Mark Brown9e6e96a2010-01-29 17:47:12 +00002543#define WM8994_RATES SNDRV_PCM_RATE_8000_96000
2544
2545#define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Ian Lartey3079aed2010-08-31 23:56:34 +01002546 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002547
2548static struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
2549 .set_sysclk = wm8994_set_dai_sysclk,
2550 .set_fmt = wm8994_set_dai_fmt,
2551 .hw_params = wm8994_hw_params,
2552 .digital_mute = wm8994_aif_mute,
2553 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002554 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002555};
2556
2557static struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
2558 .set_sysclk = wm8994_set_dai_sysclk,
2559 .set_fmt = wm8994_set_dai_fmt,
2560 .hw_params = wm8994_hw_params,
2561 .digital_mute = wm8994_aif_mute,
2562 .set_pll = wm8994_set_fll,
Mark Brown778a76e2010-03-22 22:05:10 +00002563 .set_tristate = wm8994_set_tristate,
2564};
2565
2566static struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
Mark Brownc4431df2010-11-26 15:21:07 +00002567 .hw_params = wm8994_aif3_hw_params,
Mark Brown778a76e2010-03-22 22:05:10 +00002568 .set_tristate = wm8994_set_tristate,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002569};
2570
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002571static struct snd_soc_dai_driver wm8994_dai[] = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002572 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002573 .name = "wm8994-aif1",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002574 .id = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002575 .playback = {
2576 .stream_name = "AIF1 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002577 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002578 .channels_max = 2,
2579 .rates = WM8994_RATES,
2580 .formats = WM8994_FORMATS,
2581 },
2582 .capture = {
2583 .stream_name = "AIF1 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002584 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002585 .channels_max = 2,
2586 .rates = WM8994_RATES,
2587 .formats = WM8994_FORMATS,
2588 },
2589 .ops = &wm8994_aif1_dai_ops,
2590 },
2591 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002592 .name = "wm8994-aif2",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002593 .id = 2,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002594 .playback = {
2595 .stream_name = "AIF2 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002596 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002597 .channels_max = 2,
2598 .rates = WM8994_RATES,
2599 .formats = WM8994_FORMATS,
2600 },
2601 .capture = {
2602 .stream_name = "AIF2 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002603 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002604 .channels_max = 2,
2605 .rates = WM8994_RATES,
2606 .formats = WM8994_FORMATS,
2607 },
2608 .ops = &wm8994_aif2_dai_ops,
2609 },
2610 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002611 .name = "wm8994-aif3",
Mark Brown8c7f78b2010-10-12 15:56:09 +01002612 .id = 3,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002613 .playback = {
2614 .stream_name = "AIF3 Playback",
Mark Brownb1e43d92010-12-07 17:14:56 +00002615 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002616 .channels_max = 2,
2617 .rates = WM8994_RATES,
2618 .formats = WM8994_FORMATS,
2619 },
Dan Carpentera8462bd2010-03-24 14:58:34 +03002620 .capture = {
Mark Brown9e6e96a2010-01-29 17:47:12 +00002621 .stream_name = "AIF3 Capture",
Mark Brownb1e43d92010-12-07 17:14:56 +00002622 .channels_min = 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002623 .channels_max = 2,
2624 .rates = WM8994_RATES,
2625 .formats = WM8994_FORMATS,
2626 },
Mark Brown778a76e2010-03-22 22:05:10 +00002627 .ops = &wm8994_aif3_dai_ops,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002628 }
2629};
Mark Brown9e6e96a2010-01-29 17:47:12 +00002630
2631#ifdef CONFIG_PM
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002632static int wm8994_suspend(struct snd_soc_codec *codec, pm_message_t state)
Mark Brown9e6e96a2010-01-29 17:47:12 +00002633{
Mark Brownb2c812e2010-04-14 15:35:19 +09002634 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002635 int i, ret;
2636
2637 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
2638 memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
2639 sizeof(struct fll_config));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002640 ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002641 if (ret < 0)
2642 dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
2643 i + 1, ret);
2644 }
2645
2646 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
2647
2648 return 0;
2649}
2650
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002651static int wm8994_resume(struct snd_soc_codec *codec)
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 Brown9e6e96a2010-01-29 17:47:12 +00002654 int i, ret;
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00002655 unsigned int val, mask;
2656
2657 if (wm8994->revision < 4) {
2658 /* force a HW read */
2659 val = wm8994_reg_read(codec->control_data,
2660 WM8994_POWER_MANAGEMENT_5);
2661
2662 /* modify the cache only */
2663 codec->cache_only = 1;
2664 mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
2665 WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
2666 val &= mask;
2667 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
2668 mask, val);
2669 codec->cache_only = 0;
2670 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002671
2672 /* Restore the registers */
Mark Brownca9aef52010-11-26 17:23:41 +00002673 ret = snd_soc_cache_sync(codec);
2674 if (ret != 0)
2675 dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
Mark Brown9e6e96a2010-01-29 17:47:12 +00002676
2677 wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2678
2679 for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
Mark Brown6a2f1ee2010-05-10 18:36:37 +01002680 if (!wm8994->fll_suspend[i].out)
2681 continue;
2682
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002683 ret = _wm8994_set_fll(codec, i + 1,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002684 wm8994->fll_suspend[i].src,
2685 wm8994->fll_suspend[i].in,
2686 wm8994->fll_suspend[i].out);
2687 if (ret < 0)
2688 dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
2689 i + 1, ret);
2690 }
2691
2692 return 0;
2693}
2694#else
2695#define wm8994_suspend NULL
2696#define wm8994_resume NULL
2697#endif
2698
2699static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
2700{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002701 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002702 struct wm8994_pdata *pdata = wm8994->pdata;
2703 struct snd_kcontrol_new controls[] = {
2704 SOC_ENUM_EXT("AIF1.1 EQ Mode",
2705 wm8994->retune_mobile_enum,
2706 wm8994_get_retune_mobile_enum,
2707 wm8994_put_retune_mobile_enum),
2708 SOC_ENUM_EXT("AIF1.2 EQ Mode",
2709 wm8994->retune_mobile_enum,
2710 wm8994_get_retune_mobile_enum,
2711 wm8994_put_retune_mobile_enum),
2712 SOC_ENUM_EXT("AIF2 EQ Mode",
2713 wm8994->retune_mobile_enum,
2714 wm8994_get_retune_mobile_enum,
2715 wm8994_put_retune_mobile_enum),
2716 };
2717 int ret, i, j;
2718 const char **t;
2719
2720 /* We need an array of texts for the enum API but the number
2721 * of texts is likely to be less than the number of
2722 * configurations due to the sample rate dependency of the
2723 * configurations. */
2724 wm8994->num_retune_mobile_texts = 0;
2725 wm8994->retune_mobile_texts = NULL;
2726 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
2727 for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
2728 if (strcmp(pdata->retune_mobile_cfgs[i].name,
2729 wm8994->retune_mobile_texts[j]) == 0)
2730 break;
2731 }
2732
2733 if (j != wm8994->num_retune_mobile_texts)
2734 continue;
2735
2736 /* Expand the array... */
2737 t = krealloc(wm8994->retune_mobile_texts,
2738 sizeof(char *) *
2739 (wm8994->num_retune_mobile_texts + 1),
2740 GFP_KERNEL);
2741 if (t == NULL)
2742 continue;
2743
2744 /* ...store the new entry... */
2745 t[wm8994->num_retune_mobile_texts] =
2746 pdata->retune_mobile_cfgs[i].name;
2747
2748 /* ...and remember the new version. */
2749 wm8994->num_retune_mobile_texts++;
2750 wm8994->retune_mobile_texts = t;
2751 }
2752
2753 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
2754 wm8994->num_retune_mobile_texts);
2755
2756 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
2757 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
2758
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002759 ret = snd_soc_add_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002760 ARRAY_SIZE(controls));
2761 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002762 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002763 "Failed to add ReTune Mobile controls: %d\n", ret);
2764}
2765
2766static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
2767{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002768 struct snd_soc_codec *codec = wm8994->codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00002769 struct wm8994_pdata *pdata = wm8994->pdata;
2770 int ret, i;
2771
2772 if (!pdata)
2773 return;
2774
2775 wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
2776 pdata->lineout2_diff,
2777 pdata->lineout1fb,
2778 pdata->lineout2fb,
2779 pdata->jd_scthr,
2780 pdata->jd_thr,
2781 pdata->micbias1_lvl,
2782 pdata->micbias2_lvl);
2783
2784 dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
2785
2786 if (pdata->num_drc_cfgs) {
2787 struct snd_kcontrol_new controls[] = {
2788 SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
2789 wm8994_get_drc_enum, wm8994_put_drc_enum),
2790 SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
2791 wm8994_get_drc_enum, wm8994_put_drc_enum),
2792 SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
2793 wm8994_get_drc_enum, wm8994_put_drc_enum),
2794 };
2795
2796 /* We need an array of texts for the enum API */
2797 wm8994->drc_texts = kmalloc(sizeof(char *)
2798 * pdata->num_drc_cfgs, GFP_KERNEL);
2799 if (!wm8994->drc_texts) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002800 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002801 "Failed to allocate %d DRC config texts\n",
2802 pdata->num_drc_cfgs);
2803 return;
2804 }
2805
2806 for (i = 0; i < pdata->num_drc_cfgs; i++)
2807 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
2808
2809 wm8994->drc_enum.max = pdata->num_drc_cfgs;
2810 wm8994->drc_enum.texts = wm8994->drc_texts;
2811
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002812 ret = snd_soc_add_controls(wm8994->codec, controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002813 ARRAY_SIZE(controls));
2814 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002815 dev_err(wm8994->codec->dev,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002816 "Failed to add DRC mode controls: %d\n", ret);
2817
2818 for (i = 0; i < WM8994_NUM_DRC; i++)
2819 wm8994_set_drc(codec, i);
2820 }
2821
2822 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
2823 pdata->num_retune_mobile_cfgs);
2824
Mark Brown131d8102010-11-30 17:03:39 +00002825 if (pdata->num_mbc_cfgs) {
2826 struct snd_kcontrol_new control[] = {
2827 SOC_ENUM_EXT("MBC Mode", wm8994->mbc_enum,
2828 wm8958_get_mbc_enum, wm8958_put_mbc_enum),
2829 };
2830
2831 /* We need an array of texts for the enum API */
2832 wm8994->mbc_texts = kmalloc(sizeof(char *)
2833 * pdata->num_mbc_cfgs, GFP_KERNEL);
2834 if (!wm8994->mbc_texts) {
2835 dev_err(wm8994->codec->dev,
2836 "Failed to allocate %d MBC config texts\n",
2837 pdata->num_mbc_cfgs);
2838 return;
2839 }
2840
2841 for (i = 0; i < pdata->num_mbc_cfgs; i++)
2842 wm8994->mbc_texts[i] = pdata->mbc_cfgs[i].name;
2843
2844 wm8994->mbc_enum.max = pdata->num_mbc_cfgs;
2845 wm8994->mbc_enum.texts = wm8994->mbc_texts;
2846
2847 ret = snd_soc_add_controls(wm8994->codec, control, 1);
2848 if (ret != 0)
2849 dev_err(wm8994->codec->dev,
2850 "Failed to add MBC mode controls: %d\n", ret);
2851 }
2852
Mark Brown9e6e96a2010-01-29 17:47:12 +00002853 if (pdata->num_retune_mobile_cfgs)
2854 wm8994_handle_retune_mobile_pdata(wm8994);
2855 else
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002856 snd_soc_add_controls(wm8994->codec, wm8994_eq_controls,
Mark Brown9e6e96a2010-01-29 17:47:12 +00002857 ARRAY_SIZE(wm8994_eq_controls));
Mark Brown48e028e2011-02-21 17:11:59 -08002858
2859 for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
2860 if (pdata->micbias[i]) {
2861 snd_soc_write(codec, WM8958_MICBIAS1 + i,
2862 pdata->micbias[i] & 0xffff);
2863 }
2864 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00002865}
2866
Mark Brown88766982010-03-29 20:57:12 +01002867/**
2868 * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
2869 *
2870 * @codec: WM8994 codec
2871 * @jack: jack to report detection events on
2872 * @micbias: microphone bias to detect on
2873 * @det: value to report for presence detection
2874 * @shrt: value to report for short detection
2875 *
2876 * Enable microphone detection via IRQ on the WM8994. If GPIOs are
2877 * being used to bring out signals to the processor then only platform
Mark Brown5ab230a2010-09-06 14:59:34 +01002878 * data configuration is needed for WM8994 and processor GPIOs should
Mark Brown88766982010-03-29 20:57:12 +01002879 * be configured using snd_soc_jack_add_gpios() instead.
2880 *
2881 * Configuration of detection levels is available via the micbias1_lvl
2882 * and micbias2_lvl platform data members.
2883 */
2884int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
2885 int micbias, int det, int shrt)
2886{
Mark Brownb2c812e2010-04-14 15:35:19 +09002887 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown88766982010-03-29 20:57:12 +01002888 struct wm8994_micdet *micdet;
Mark Brown3a423152010-11-26 15:21:06 +00002889 struct wm8994 *control = codec->control_data;
Mark Brown88766982010-03-29 20:57:12 +01002890 int reg;
2891
Mark Brown3a423152010-11-26 15:21:06 +00002892 if (control->type != WM8994)
2893 return -EINVAL;
2894
Mark Brown88766982010-03-29 20:57:12 +01002895 switch (micbias) {
2896 case 1:
2897 micdet = &wm8994->micdet[0];
2898 break;
2899 case 2:
2900 micdet = &wm8994->micdet[1];
2901 break;
2902 default:
2903 return -EINVAL;
2904 }
2905
2906 dev_dbg(codec->dev, "Configuring microphone detection on %d: %x %x\n",
2907 micbias, det, shrt);
2908
2909 /* Store the configuration */
2910 micdet->jack = jack;
2911 micdet->det = det;
2912 micdet->shrt = shrt;
2913
2914 /* If either of the jacks is set up then enable detection */
2915 if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
2916 reg = WM8994_MICD_ENA;
2917 else
2918 reg = 0;
2919
2920 snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
2921
2922 return 0;
2923}
2924EXPORT_SYMBOL_GPL(wm8994_mic_detect);
2925
2926static irqreturn_t wm8994_mic_irq(int irq, void *data)
2927{
2928 struct wm8994_priv *priv = data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002929 struct snd_soc_codec *codec = priv->codec;
Mark Brown88766982010-03-29 20:57:12 +01002930 int reg;
2931 int report;
2932
Mark Brown7116f452010-12-29 13:05:21 +00002933#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00002934 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00002935#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00002936
Mark Brown88766982010-03-29 20:57:12 +01002937 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
2938 if (reg < 0) {
2939 dev_err(codec->dev, "Failed to read microphone status: %d\n",
2940 reg);
2941 return IRQ_HANDLED;
2942 }
2943
2944 dev_dbg(codec->dev, "Microphone status: %x\n", reg);
2945
2946 report = 0;
2947 if (reg & WM8994_MIC1_DET_STS)
2948 report |= priv->micdet[0].det;
2949 if (reg & WM8994_MIC1_SHRT_STS)
2950 report |= priv->micdet[0].shrt;
2951 snd_soc_jack_report(priv->micdet[0].jack, report,
2952 priv->micdet[0].det | priv->micdet[0].shrt);
2953
2954 report = 0;
2955 if (reg & WM8994_MIC2_DET_STS)
2956 report |= priv->micdet[1].det;
2957 if (reg & WM8994_MIC2_SHRT_STS)
2958 report |= priv->micdet[1].shrt;
2959 snd_soc_jack_report(priv->micdet[1].jack, report,
2960 priv->micdet[1].det | priv->micdet[1].shrt);
2961
2962 return IRQ_HANDLED;
2963}
2964
Mark Brown821edd22010-11-26 15:21:09 +00002965/* Default microphone detection handler for WM8958 - the user can
2966 * override this if they wish.
2967 */
2968static void wm8958_default_micdet(u16 status, void *data)
2969{
2970 struct snd_soc_codec *codec = data;
2971 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2972 int report = 0;
2973
2974 /* If nothing present then clear our statuses */
2975 if (!(status & WM8958_MICD_STS)) {
2976 wm8994->jack_is_video = false;
2977 wm8994->jack_is_mic = false;
2978 goto done;
2979 }
2980
2981 /* Assume anything over 475 ohms is a microphone and remember
2982 * that we've seen one (since buttons override it) */
2983 if (status & 0x600)
2984 wm8994->jack_is_mic = true;
2985 if (wm8994->jack_is_mic)
2986 report |= SND_JACK_MICROPHONE;
2987
2988 /* Video has an impedence of approximately 75 ohms; assume
2989 * this isn't used as a button and remember it since buttons
2990 * override it. */
2991 if (status & 0x40)
2992 wm8994->jack_is_video = true;
2993 if (wm8994->jack_is_video)
2994 report |= SND_JACK_VIDEOOUT;
2995
2996 /* Everything else is buttons; just assign slots */
2997 if (status & 0x4)
2998 report |= SND_JACK_BTN_0;
2999 if (status & 0x8)
3000 report |= SND_JACK_BTN_1;
3001 if (status & 0x10)
3002 report |= SND_JACK_BTN_2;
3003 if (status & 0x20)
3004 report |= SND_JACK_BTN_3;
3005 if (status & 0x80)
3006 report |= SND_JACK_BTN_4;
3007 if (status & 0x100)
3008 report |= SND_JACK_BTN_5;
3009
3010done:
Mark Brown406e56c2011-02-21 20:41:25 -08003011 snd_soc_jack_report(wm8994->micdet[0].jack, report,
Mark Brown821edd22010-11-26 15:21:09 +00003012 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 |
3013 SND_JACK_BTN_3 | SND_JACK_BTN_4 | SND_JACK_BTN_5 |
Mark Brown406e56c2011-02-21 20:41:25 -08003014 SND_JACK_MICROPHONE | SND_JACK_VIDEOOUT);
Mark Brown821edd22010-11-26 15:21:09 +00003015}
3016
3017/**
3018 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
3019 *
3020 * @codec: WM8958 codec
3021 * @jack: jack to report detection events on
3022 *
3023 * Enable microphone detection functionality for the WM8958. By
3024 * default simple detection which supports the detection of up to 6
3025 * buttons plus video and microphone functionality is supported.
3026 *
3027 * The WM8958 has an advanced jack detection facility which is able to
3028 * support complex accessory detection, especially when used in
3029 * conjunction with external circuitry. In order to provide maximum
3030 * flexiblity a callback is provided which allows a completely custom
3031 * detection algorithm.
3032 */
3033int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3034 wm8958_micdet_cb cb, void *cb_data)
3035{
3036 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3037 struct wm8994 *control = codec->control_data;
3038
3039 if (control->type != WM8958)
3040 return -EINVAL;
3041
3042 if (jack) {
3043 if (!cb) {
3044 dev_dbg(codec->dev, "Using default micdet callback\n");
3045 cb = wm8958_default_micdet;
3046 cb_data = codec;
3047 }
3048
3049 wm8994->micdet[0].jack = jack;
3050 wm8994->jack_cb = cb;
3051 wm8994->jack_cb_data = cb_data;
3052
3053 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3054 WM8958_MICD_ENA, WM8958_MICD_ENA);
3055 } else {
3056 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3057 WM8958_MICD_ENA, 0);
3058 }
3059
3060 return 0;
3061}
3062EXPORT_SYMBOL_GPL(wm8958_mic_detect);
3063
3064static irqreturn_t wm8958_mic_irq(int irq, void *data)
3065{
3066 struct wm8994_priv *wm8994 = data;
3067 struct snd_soc_codec *codec = wm8994->codec;
3068 int reg;
3069
3070 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
3071 if (reg < 0) {
3072 dev_err(codec->dev, "Failed to read mic detect status: %d\n",
3073 reg);
3074 return IRQ_NONE;
3075 }
3076
3077 if (!(reg & WM8958_MICD_VALID)) {
3078 dev_dbg(codec->dev, "Mic detect data not valid\n");
3079 goto out;
3080 }
3081
Mark Brown7116f452010-12-29 13:05:21 +00003082#ifndef CONFIG_SND_SOC_WM8994_MODULE
Mark Brown2bbb5d62010-12-05 12:50:12 +00003083 trace_snd_soc_jack_irq(dev_name(codec->dev));
Mark Brown7116f452010-12-29 13:05:21 +00003084#endif
Mark Brown2bbb5d62010-12-05 12:50:12 +00003085
Mark Brown821edd22010-11-26 15:21:09 +00003086 if (wm8994->jack_cb)
3087 wm8994->jack_cb(reg, wm8994->jack_cb_data);
3088 else
3089 dev_warn(codec->dev, "Accessory detection with no callback\n");
3090
3091out:
3092 return IRQ_HANDLED;
3093}
3094
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003095static int wm8994_codec_probe(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003096{
Mark Brown3a423152010-11-26 15:21:06 +00003097 struct wm8994 *control;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003098 struct wm8994_priv *wm8994;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003099 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brownec62dbd2010-08-15 14:56:40 +01003100 int ret, i;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003101
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003102 codec->control_data = dev_get_drvdata(codec->dev->parent);
Mark Brown3a423152010-11-26 15:21:06 +00003103 control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003104
3105 wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003106 if (wm8994 == NULL)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003107 return -ENOMEM;
Mark Brownb2c812e2010-04-14 15:35:19 +09003108 snd_soc_codec_set_drvdata(codec, wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003109
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003110 wm8994->pdata = dev_get_platdata(codec->dev->parent);
3111 wm8994->codec = codec;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003112
Mark Brown9b7c5252011-02-17 20:05:44 -08003113 if (wm8994->pdata && wm8994->pdata->micdet_irq)
3114 wm8994->micdet_irq = wm8994->pdata->micdet_irq;
3115 else if (wm8994->pdata && wm8994->pdata->irq_base)
3116 wm8994->micdet_irq = wm8994->pdata->irq_base +
3117 WM8994_IRQ_MIC1_DET;
3118
Mark Brown39fb51a2010-11-26 17:23:43 +00003119 pm_runtime_enable(codec->dev);
3120 pm_runtime_resume(codec->dev);
3121
Mark Brownca9aef52010-11-26 17:23:41 +00003122 /* Read our current status back from the chip - we don't want to
3123 * reset as this may interfere with the GPIO or LDO operation. */
3124 for (i = 0; i < WM8994_CACHE_SIZE; i++) {
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +00003125 if (!wm8994_readable(codec, i) || wm8994_volatile(codec, i))
Mark Brownca9aef52010-11-26 17:23:41 +00003126 continue;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003127
Mark Brownca9aef52010-11-26 17:23:41 +00003128 ret = wm8994_reg_read(codec->control_data, i);
3129 if (ret <= 0)
3130 continue;
3131
3132 ret = snd_soc_cache_write(codec, i, ret);
3133 if (ret != 0) {
3134 dev_err(codec->dev,
3135 "Failed to initialise cache for 0x%x: %d\n",
3136 i, ret);
3137 goto err;
3138 }
3139 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003140
3141 /* Set revision-specific configuration */
Mark Brownb6b05692010-08-13 12:58:20 +01003142 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
Mark Brown3a423152010-11-26 15:21:06 +00003143 switch (control->type) {
3144 case WM8994:
3145 switch (wm8994->revision) {
3146 case 2:
3147 case 3:
3148 wm8994->hubs.dcs_codes = -5;
3149 wm8994->hubs.hp_startup_mode = 1;
3150 wm8994->hubs.dcs_readback_mode = 1;
3151 break;
3152 default:
3153 wm8994->hubs.dcs_readback_mode = 1;
3154 break;
3155 }
3156
3157 case WM8958:
Mark Brown8437f702010-03-29 17:09:45 +01003158 wm8994->hubs.dcs_readback_mode = 1;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003159 break;
Mark Brown3a423152010-11-26 15:21:06 +00003160
Mark Brown9e6e96a2010-01-29 17:47:12 +00003161 default:
3162 break;
3163 }
Mark Brown9e6e96a2010-01-29 17:47:12 +00003164
Mark Brown3a423152010-11-26 15:21:06 +00003165 switch (control->type) {
3166 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003167 if (wm8994->micdet_irq) {
3168 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3169 wm8994_mic_irq,
3170 IRQF_TRIGGER_RISING,
3171 "Mic1 detect",
3172 wm8994);
3173 if (ret != 0)
3174 dev_warn(codec->dev,
3175 "Failed to request Mic1 detect IRQ: %d\n",
3176 ret);
3177 }
Mark Brown88766982010-03-29 20:57:12 +01003178
Mark Brown3a423152010-11-26 15:21:06 +00003179 ret = wm8994_request_irq(codec->control_data,
3180 WM8994_IRQ_MIC1_SHRT,
3181 wm8994_mic_irq, "Mic 1 short",
3182 wm8994);
3183 if (ret != 0)
3184 dev_warn(codec->dev,
3185 "Failed to request Mic1 short IRQ: %d\n",
3186 ret);
Mark Brown88766982010-03-29 20:57:12 +01003187
Mark Brown3a423152010-11-26 15:21:06 +00003188 ret = wm8994_request_irq(codec->control_data,
3189 WM8994_IRQ_MIC2_DET,
3190 wm8994_mic_irq, "Mic 2 detect",
3191 wm8994);
3192 if (ret != 0)
3193 dev_warn(codec->dev,
3194 "Failed to request Mic2 detect IRQ: %d\n",
3195 ret);
Mark Brown88766982010-03-29 20:57:12 +01003196
Mark Brown3a423152010-11-26 15:21:06 +00003197 ret = wm8994_request_irq(codec->control_data,
3198 WM8994_IRQ_MIC2_SHRT,
3199 wm8994_mic_irq, "Mic 2 short",
3200 wm8994);
3201 if (ret != 0)
3202 dev_warn(codec->dev,
3203 "Failed to request Mic2 short IRQ: %d\n",
3204 ret);
3205 break;
Mark Brown821edd22010-11-26 15:21:09 +00003206
3207 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003208 if (wm8994->micdet_irq) {
3209 ret = request_threaded_irq(wm8994->micdet_irq, NULL,
3210 wm8958_mic_irq,
3211 IRQF_TRIGGER_RISING,
3212 "Mic detect",
3213 wm8994);
3214 if (ret != 0)
3215 dev_warn(codec->dev,
3216 "Failed to request Mic detect IRQ: %d\n",
3217 ret);
3218 }
Mark Brown3a423152010-11-26 15:21:06 +00003219 }
Mark Brown88766982010-03-29 20:57:12 +01003220
Mark Brown9e6e96a2010-01-29 17:47:12 +00003221 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3222 * configured on init - if a system wants to do this dynamically
3223 * at runtime we can deal with that then.
3224 */
3225 ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_1);
3226 if (ret < 0) {
3227 dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003228 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003229 }
3230 if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
3231 wm8994->lrclk_shared[0] = 1;
3232 wm8994_dai[0].symmetric_rates = 1;
3233 } else {
3234 wm8994->lrclk_shared[0] = 0;
3235 }
3236
3237 ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_6);
3238 if (ret < 0) {
3239 dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
Mark Brown88766982010-03-29 20:57:12 +01003240 goto err_irq;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003241 }
3242 if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
3243 wm8994->lrclk_shared[1] = 1;
3244 wm8994_dai[1].symmetric_rates = 1;
3245 } else {
3246 wm8994->lrclk_shared[1] = 0;
3247 }
3248
Mark Brown9e6e96a2010-01-29 17:47:12 +00003249 wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
3250
Mark Brown9e6e96a2010-01-29 17:47:12 +00003251 /* Latch volume updates (right only; we always do left then right). */
3252 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3253 WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
3254 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3255 WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
3256 snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3257 WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
3258 snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3259 WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
3260 snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3261 WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
3262 snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3263 WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
3264 snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3265 WM8994_DAC1_VU, WM8994_DAC1_VU);
3266 snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3267 WM8994_DAC2_VU, WM8994_DAC2_VU);
3268
3269 /* Set the low bit of the 3D stereo depth so TLV matches */
3270 snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
3271 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
3272 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
3273 snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
3274 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
3275 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
3276 snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
3277 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
3278 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
3279
Mark Brownd1ce6b22010-07-20 10:13:14 +01003280 /* Unconditionally enable AIF1 ADC TDM mode; it only affects
3281 * behaviour on idle TDM clock cycles. */
3282 snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
3283 WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
3284
Mark Brown9e6e96a2010-01-29 17:47:12 +00003285 wm8994_update_class_w(codec);
3286
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003287 wm8994_handle_pdata(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003288
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003289 wm_hubs_add_analogue_controls(codec);
3290 snd_soc_add_controls(codec, wm8994_snd_controls,
3291 ARRAY_SIZE(wm8994_snd_controls));
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003292 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003293 ARRAY_SIZE(wm8994_dapm_widgets));
Mark Brownc4431df2010-11-26 15:21:07 +00003294
3295 switch (control->type) {
3296 case WM8994:
3297 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3298 ARRAY_SIZE(wm8994_specific_dapm_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003299 if (wm8994->revision < 4) {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003300 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3301 ARRAY_SIZE(wm8994_lateclk_revd_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003302 snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3303 ARRAY_SIZE(wm8994_dac_revd_widgets));
3304 } else {
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003305 snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3306 ARRAY_SIZE(wm8994_lateclk_widgets));
Dimitris Papastamosc52fd022011-02-11 16:32:12 +00003307 snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3308 ARRAY_SIZE(wm8994_dac_widgets));
3309 }
Mark Brownc4431df2010-11-26 15:21:07 +00003310 break;
3311 case WM8958:
3312 snd_soc_add_controls(codec, wm8958_snd_controls,
3313 ARRAY_SIZE(wm8958_snd_controls));
3314 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3315 ARRAY_SIZE(wm8958_dapm_widgets));
3316 break;
3317 }
3318
3319
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003320 wm_hubs_add_analogue_routes(codec, 0, 0);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003321 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown9e6e96a2010-01-29 17:47:12 +00003322
Mark Brownc4431df2010-11-26 15:21:07 +00003323 switch (control->type) {
3324 case WM8994:
3325 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
3326 ARRAY_SIZE(wm8994_intercon));
Mark Brown6ed8f142011-02-03 16:27:35 +00003327
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003328 if (wm8994->revision < 4) {
Mark Brown6ed8f142011-02-03 16:27:35 +00003329 snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
3330 ARRAY_SIZE(wm8994_revd_intercon));
Dimitris Papastamos173efa02011-02-11 16:32:11 +00003331 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
3332 ARRAY_SIZE(wm8994_lateclk_revd_intercon));
3333 } else {
3334 snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
3335 ARRAY_SIZE(wm8994_lateclk_intercon));
3336 }
Mark Brownc4431df2010-11-26 15:21:07 +00003337 break;
3338 case WM8958:
3339 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3340 ARRAY_SIZE(wm8958_intercon));
3341 break;
3342 }
3343
Mark Brown9e6e96a2010-01-29 17:47:12 +00003344 return 0;
3345
Mark Brown88766982010-03-29 20:57:12 +01003346err_irq:
3347 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994);
3348 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994);
3349 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994);
Mark Brown9b7c5252011-02-17 20:05:44 -08003350 if (wm8994->micdet_irq)
3351 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003352err:
3353 kfree(wm8994);
3354 return ret;
3355}
3356
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003357static int wm8994_codec_remove(struct snd_soc_codec *codec)
Mark Brown9e6e96a2010-01-29 17:47:12 +00003358{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003359 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
Mark Brown3a423152010-11-26 15:21:06 +00003360 struct wm8994 *control = codec->control_data;
Mark Brown9e6e96a2010-01-29 17:47:12 +00003361
3362 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003363
Mark Brown39fb51a2010-11-26 17:23:43 +00003364 pm_runtime_disable(codec->dev);
3365
Mark Brown3a423152010-11-26 15:21:06 +00003366 switch (control->type) {
3367 case WM8994:
Mark Brown9b7c5252011-02-17 20:05:44 -08003368 if (wm8994->micdet_irq)
3369 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown3a423152010-11-26 15:21:06 +00003370 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET,
3371 wm8994);
3372 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT,
3373 wm8994);
3374 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET,
3375 wm8994);
3376 break;
Mark Brown821edd22010-11-26 15:21:09 +00003377
3378 case WM8958:
Mark Brown9b7c5252011-02-17 20:05:44 -08003379 if (wm8994->micdet_irq)
3380 free_irq(wm8994->micdet_irq, wm8994);
Mark Brown821edd22010-11-26 15:21:09 +00003381 break;
Mark Brown3a423152010-11-26 15:21:06 +00003382 }
Axel Lin24fb2b12010-11-23 15:58:39 +08003383 kfree(wm8994->retune_mobile_texts);
3384 kfree(wm8994->drc_texts);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003385 kfree(wm8994);
Mark Brown9e6e96a2010-01-29 17:47:12 +00003386
3387 return 0;
3388}
3389
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003390static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
3391 .probe = wm8994_codec_probe,
3392 .remove = wm8994_codec_remove,
3393 .suspend = wm8994_suspend,
3394 .resume = wm8994_resume,
Mark Brownca9aef52010-11-26 17:23:41 +00003395 .read = wm8994_read,
3396 .write = wm8994_write,
Mark Browneba19fd2010-11-19 16:09:15 +00003397 .readable_register = wm8994_readable,
3398 .volatile_register = wm8994_volatile,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003399 .set_bias_level = wm8994_set_bias_level,
Mark Brownca9aef52010-11-26 17:23:41 +00003400
3401 .reg_cache_size = WM8994_CACHE_SIZE,
3402 .reg_cache_default = wm8994_reg_defaults,
3403 .reg_word_size = 2,
Mark Brown2e19b0c2010-11-26 17:23:42 +00003404 .compress_type = SND_SOC_RBTREE_COMPRESSION,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003405};
3406
3407static int __devinit wm8994_probe(struct platform_device *pdev)
3408{
3409 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
3410 wm8994_dai, ARRAY_SIZE(wm8994_dai));
3411}
3412
3413static int __devexit wm8994_remove(struct platform_device *pdev)
3414{
3415 snd_soc_unregister_codec(&pdev->dev);
3416 return 0;
3417}
3418
Mark Brown9e6e96a2010-01-29 17:47:12 +00003419static struct platform_driver wm8994_codec_driver = {
3420 .driver = {
3421 .name = "wm8994-codec",
3422 .owner = THIS_MODULE,
3423 },
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003424 .probe = wm8994_probe,
3425 .remove = __devexit_p(wm8994_remove),
Mark Brown9e6e96a2010-01-29 17:47:12 +00003426};
3427
3428static __init int wm8994_init(void)
3429{
3430 return platform_driver_register(&wm8994_codec_driver);
3431}
3432module_init(wm8994_init);
3433
3434static __exit void wm8994_exit(void)
3435{
3436 platform_driver_unregister(&wm8994_codec_driver);
3437}
3438module_exit(wm8994_exit);
3439
3440
3441MODULE_DESCRIPTION("ASoC WM8994 driver");
3442MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
3443MODULE_LICENSE("GPL");
3444MODULE_ALIAS("platform:wm8994-codec");