2 * wm8958-dsp2.c -- WM8958 DSP2 support
4 * Copyright 2011 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
18 #include <linux/i2c.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21 #include <sound/soc.h>
22 #include <sound/initval.h>
23 #include <sound/tlv.h>
24 #include <trace/events/asoc.h>
26 #include <linux/mfd/wm8994/core.h>
27 #include <linux/mfd/wm8994/registers.h>
28 #include <linux/mfd/wm8994/pdata.h>
29 #include <linux/mfd/wm8994/gpio.h>
33 #define WM_FW_BLOCK_INFO 0xff
34 #define WM_FW_BLOCK_PM 0x00
35 #define WM_FW_BLOCK_X 0x01
36 #define WM_FW_BLOCK_Y 0x02
37 #define WM_FW_BLOCK_Z 0x03
38 #define WM_FW_BLOCK_I 0x06
39 #define WM_FW_BLOCK_A 0x08
40 #define WM_FW_BLOCK_C 0x0c
42 static int wm8958_dsp2_fw(struct snd_soc_component *component, const char *name,
43 const struct firmware *fw, bool check)
45 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
50 size_t block_len, len;
53 /* Suppress unneeded downloads */
54 if (wm8994->cur_fw == fw)
58 dev_err(component->dev, "%s: firmware too short (%zd bytes)\n",
63 if (memcmp(fw->data, "WMFW", 4) != 0) {
64 memcpy(&data32, fw->data, sizeof(data32));
65 data32 = be32_to_cpu(data32);
66 dev_err(component->dev, "%s: firmware has bad file magic %08x\n",
71 memcpy(&data32, fw->data + 4, sizeof(data32));
72 len = be32_to_cpu(data32);
74 memcpy(&data32, fw->data + 8, sizeof(data32));
75 data32 = be32_to_cpu(data32);
76 if ((data32 >> 24) & 0xff) {
77 dev_err(component->dev, "%s: unsupported firmware version %d\n",
78 name, (data32 >> 24) & 0xff);
81 if ((data32 & 0xffff) != 8958) {
82 dev_err(component->dev, "%s: unsupported target device %d\n",
83 name, data32 & 0xffff);
86 if (((data32 >> 16) & 0xff) != 0xc) {
87 dev_err(component->dev, "%s: unsupported target core %d\n",
88 name, (data32 >> 16) & 0xff);
93 memcpy(&data64, fw->data + 24, sizeof(u64));
94 dev_info(component->dev, "%s timestamp %llx\n",
95 name, be64_to_cpu(data64));
97 snd_soc_component_write(component, 0x102, 0x2);
98 snd_soc_component_write(component, 0x900, 0x2);
101 data = fw->data + len;
102 len = fw->size - len;
105 dev_err(component->dev, "%s short data block of %zd\n",
110 memcpy(&data32, data + 4, sizeof(data32));
111 block_len = be32_to_cpu(data32);
112 if (block_len + 8 > len) {
113 dev_err(component->dev, "%zd byte block longer than file\n",
117 if (block_len == 0) {
118 dev_err(component->dev, "Zero length block\n");
122 memcpy(&data32, data, sizeof(data32));
123 data32 = be32_to_cpu(data32);
125 switch ((data32 >> 24) & 0xff) {
126 case WM_FW_BLOCK_INFO:
127 /* Informational text */
131 str = kzalloc(block_len + 1, GFP_KERNEL);
133 memcpy(str, data + 8, block_len);
134 dev_info(component->dev, "%s: %s\n", name, str);
137 dev_err(component->dev, "Out of memory\n");
147 dev_dbg(component->dev, "%s: %zd bytes of %x@%x\n", name,
148 block_len, (data32 >> 24) & 0xff,
156 wm8994_bulk_write(wm8994->wm8994,
163 dev_warn(component->dev, "%s: unknown block type %d\n",
164 name, (data32 >> 24) & 0xff);
168 /* Round up to the next 32 bit word */
169 block_len += block_len % 4;
171 data += block_len + 8;
172 len -= block_len + 8;
176 dev_dbg(component->dev, "%s: download done\n", name);
179 dev_info(component->dev, "%s: got firmware\n", name);
188 snd_soc_component_write(component, 0x900, 0x0);
189 snd_soc_component_write(component, 0x102, 0x0);
195 static void wm8958_dsp_start_mbc(struct snd_soc_component *component, int path)
197 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
198 struct wm8994 *control = wm8994->wm8994;
201 /* If the DSP is already running then noop */
202 if (snd_soc_component_read32(component, WM8958_DSP2_PROGRAM) & WM8958_DSP2_ENA)
205 /* If we have MBC firmware download it */
207 wm8958_dsp2_fw(component, "MBC", wm8994->mbc, false);
209 snd_soc_component_update_bits(component, WM8958_DSP2_PROGRAM,
210 WM8958_DSP2_ENA, WM8958_DSP2_ENA);
212 /* If we've got user supplied MBC settings use them */
213 if (control->pdata.num_mbc_cfgs) {
214 struct wm8958_mbc_cfg *cfg
215 = &control->pdata.mbc_cfgs[wm8994->mbc_cfg];
217 for (i = 0; i < ARRAY_SIZE(cfg->coeff_regs); i++)
218 snd_soc_component_write(component, i + WM8958_MBC_BAND_1_K_1,
221 for (i = 0; i < ARRAY_SIZE(cfg->cutoff_regs); i++)
222 snd_soc_component_write(component,
223 i + WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_1,
224 cfg->cutoff_regs[i]);
228 snd_soc_component_write(component, WM8958_DSP2_EXECCONTROL,
232 snd_soc_component_update_bits(component, WM8958_DSP2_CONFIG,
235 path << WM8958_MBC_SEL_SHIFT |
239 static void wm8958_dsp_start_vss(struct snd_soc_component *component, int path)
241 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
242 struct wm8994 *control = wm8994->wm8994;
246 wm8958_dsp2_fw(component, "MBC+VSS", wm8994->mbc_vss, false);
248 snd_soc_component_update_bits(component, WM8958_DSP2_PROGRAM,
249 WM8958_DSP2_ENA, WM8958_DSP2_ENA);
251 /* If we've got user supplied settings use them */
252 if (control->pdata.num_mbc_cfgs) {
253 struct wm8958_mbc_cfg *cfg
254 = &control->pdata.mbc_cfgs[wm8994->mbc_cfg];
256 for (i = 0; i < ARRAY_SIZE(cfg->combined_regs); i++)
257 snd_soc_component_write(component, i + 0x2800,
258 cfg->combined_regs[i]);
261 if (control->pdata.num_vss_cfgs) {
262 struct wm8958_vss_cfg *cfg
263 = &control->pdata.vss_cfgs[wm8994->vss_cfg];
265 for (i = 0; i < ARRAY_SIZE(cfg->regs); i++)
266 snd_soc_component_write(component, i + 0x2600, cfg->regs[i]);
269 if (control->pdata.num_vss_hpf_cfgs) {
270 struct wm8958_vss_hpf_cfg *cfg
271 = &control->pdata.vss_hpf_cfgs[wm8994->vss_hpf_cfg];
273 for (i = 0; i < ARRAY_SIZE(cfg->regs); i++)
274 snd_soc_component_write(component, i + 0x2400, cfg->regs[i]);
278 snd_soc_component_write(component, WM8958_DSP2_EXECCONTROL,
281 /* Enable the algorithms we've selected */
283 if (wm8994->mbc_ena[path])
285 if (wm8994->hpf2_ena[path])
287 if (wm8994->hpf1_ena[path])
289 if (wm8994->vss_ena[path])
292 snd_soc_component_write(component, 0x2201, ena);
294 /* Switch the DSP into the data path */
295 snd_soc_component_update_bits(component, WM8958_DSP2_CONFIG,
296 WM8958_MBC_SEL_MASK | WM8958_MBC_ENA,
297 path << WM8958_MBC_SEL_SHIFT | WM8958_MBC_ENA);
300 static void wm8958_dsp_start_enh_eq(struct snd_soc_component *component, int path)
302 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
303 struct wm8994 *control = wm8994->wm8994;
306 wm8958_dsp2_fw(component, "ENH_EQ", wm8994->enh_eq, false);
308 snd_soc_component_update_bits(component, WM8958_DSP2_PROGRAM,
309 WM8958_DSP2_ENA, WM8958_DSP2_ENA);
311 /* If we've got user supplied settings use them */
312 if (control->pdata.num_enh_eq_cfgs) {
313 struct wm8958_enh_eq_cfg *cfg
314 = &control->pdata.enh_eq_cfgs[wm8994->enh_eq_cfg];
316 for (i = 0; i < ARRAY_SIZE(cfg->regs); i++)
317 snd_soc_component_write(component, i + 0x2200,
322 snd_soc_component_write(component, WM8958_DSP2_EXECCONTROL,
325 /* Switch the DSP into the data path */
326 snd_soc_component_update_bits(component, WM8958_DSP2_CONFIG,
327 WM8958_MBC_SEL_MASK | WM8958_MBC_ENA,
328 path << WM8958_MBC_SEL_SHIFT | WM8958_MBC_ENA);
331 static void wm8958_dsp_apply(struct snd_soc_component *component, int path, int start)
333 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
334 int pwr_reg = snd_soc_component_read32(component, WM8994_POWER_MANAGEMENT_5);
339 pwr_reg &= (WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA);
343 pwr_reg &= (WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
347 pwr_reg &= (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA);
351 WARN(1, "Invalid path %d\n", path);
355 /* Do we have both an active AIF and an active algorithm? */
356 ena = wm8994->mbc_ena[path] || wm8994->vss_ena[path] ||
357 wm8994->hpf1_ena[path] || wm8994->hpf2_ena[path] ||
358 wm8994->enh_eq_ena[path];
362 reg = snd_soc_component_read32(component, WM8958_DSP2_PROGRAM);
364 dev_dbg(component->dev, "DSP path %d %d startup: %d, power: %x, DSP: %x\n",
365 path, wm8994->dsp_active, start, pwr_reg, reg);
368 /* If the DSP is already running then noop */
369 if (reg & WM8958_DSP2_ENA)
372 /* If either AIFnCLK is not yet enabled postpone */
373 if (!(snd_soc_component_read32(component, WM8994_AIF1_CLOCKING_1)
374 & WM8994_AIF1CLK_ENA_MASK) &&
375 !(snd_soc_component_read32(component, WM8994_AIF2_CLOCKING_1)
376 & WM8994_AIF2CLK_ENA_MASK))
379 /* Switch the clock over to the appropriate AIF */
380 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
381 WM8958_DSP2CLK_SRC | WM8958_DSP2CLK_ENA,
382 aif << WM8958_DSP2CLK_SRC_SHIFT |
385 if (wm8994->enh_eq_ena[path])
386 wm8958_dsp_start_enh_eq(component, path);
387 else if (wm8994->vss_ena[path] || wm8994->hpf1_ena[path] ||
388 wm8994->hpf2_ena[path])
389 wm8958_dsp_start_vss(component, path);
390 else if (wm8994->mbc_ena[path])
391 wm8958_dsp_start_mbc(component, path);
393 wm8994->dsp_active = path;
395 dev_dbg(component->dev, "DSP running in path %d\n", path);
398 if (!start && wm8994->dsp_active == path) {
399 /* If the DSP is already stopped then noop */
400 if (!(reg & WM8958_DSP2_ENA))
403 snd_soc_component_update_bits(component, WM8958_DSP2_CONFIG,
405 snd_soc_component_write(component, WM8958_DSP2_EXECCONTROL,
407 snd_soc_component_update_bits(component, WM8958_DSP2_PROGRAM,
409 snd_soc_component_update_bits(component, WM8994_CLOCKING_1,
410 WM8958_DSP2CLK_ENA, 0);
412 wm8994->dsp_active = -1;
414 dev_dbg(component->dev, "DSP stopped\n");
418 int wm8958_aif_ev(struct snd_soc_dapm_widget *w,
419 struct snd_kcontrol *kcontrol, int event)
421 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
422 struct wm8994 *control = dev_get_drvdata(component->dev->parent);
425 if (control->type != WM8958)
429 case SND_SOC_DAPM_POST_PMU:
430 case SND_SOC_DAPM_PRE_PMU:
431 for (i = 0; i < 3; i++)
432 wm8958_dsp_apply(component, i, 1);
434 case SND_SOC_DAPM_POST_PMD:
435 case SND_SOC_DAPM_PRE_PMD:
436 for (i = 0; i < 3; i++)
437 wm8958_dsp_apply(component, i, 0);
444 /* Check if DSP2 is in use on another AIF */
445 static int wm8958_dsp2_busy(struct wm8994_priv *wm8994, int aif)
449 for (i = 0; i < ARRAY_SIZE(wm8994->mbc_ena); i++) {
452 if (wm8994->mbc_ena[i] || wm8994->vss_ena[i] ||
453 wm8994->hpf1_ena[i] || wm8994->hpf2_ena[i])
460 static int wm8958_put_mbc_enum(struct snd_kcontrol *kcontrol,
461 struct snd_ctl_elem_value *ucontrol)
463 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
464 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
465 struct wm8994 *control = wm8994->wm8994;
466 int value = ucontrol->value.enumerated.item[0];
469 /* Don't allow on the fly reconfiguration */
470 reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
471 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
474 if (value >= control->pdata.num_mbc_cfgs)
477 wm8994->mbc_cfg = value;
482 static int wm8958_get_mbc_enum(struct snd_kcontrol *kcontrol,
483 struct snd_ctl_elem_value *ucontrol)
485 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
486 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
488 ucontrol->value.enumerated.item[0] = wm8994->mbc_cfg;
493 static int wm8958_mbc_info(struct snd_kcontrol *kcontrol,
494 struct snd_ctl_elem_info *uinfo)
496 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
498 uinfo->value.integer.min = 0;
499 uinfo->value.integer.max = 1;
503 static int wm8958_mbc_get(struct snd_kcontrol *kcontrol,
504 struct snd_ctl_elem_value *ucontrol)
506 int mbc = kcontrol->private_value;
507 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
508 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
510 ucontrol->value.integer.value[0] = wm8994->mbc_ena[mbc];
515 static int wm8958_mbc_put(struct snd_kcontrol *kcontrol,
516 struct snd_ctl_elem_value *ucontrol)
518 int mbc = kcontrol->private_value;
519 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
520 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
522 if (wm8994->mbc_ena[mbc] == ucontrol->value.integer.value[0])
525 if (ucontrol->value.integer.value[0] > 1)
528 if (wm8958_dsp2_busy(wm8994, mbc)) {
529 dev_dbg(component->dev, "DSP2 active on %d already\n", mbc);
533 if (wm8994->enh_eq_ena[mbc])
536 wm8994->mbc_ena[mbc] = ucontrol->value.integer.value[0];
538 wm8958_dsp_apply(component, mbc, wm8994->mbc_ena[mbc]);
543 #define WM8958_MBC_SWITCH(xname, xval) {\
544 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
545 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
546 .info = wm8958_mbc_info, \
547 .get = wm8958_mbc_get, .put = wm8958_mbc_put, \
548 .private_value = xval }
550 static int wm8958_put_vss_enum(struct snd_kcontrol *kcontrol,
551 struct snd_ctl_elem_value *ucontrol)
553 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
554 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
555 struct wm8994 *control = wm8994->wm8994;
556 int value = ucontrol->value.enumerated.item[0];
559 /* Don't allow on the fly reconfiguration */
560 reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
561 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
564 if (value >= control->pdata.num_vss_cfgs)
567 wm8994->vss_cfg = value;
572 static int wm8958_get_vss_enum(struct snd_kcontrol *kcontrol,
573 struct snd_ctl_elem_value *ucontrol)
575 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
576 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
578 ucontrol->value.enumerated.item[0] = wm8994->vss_cfg;
583 static int wm8958_put_vss_hpf_enum(struct snd_kcontrol *kcontrol,
584 struct snd_ctl_elem_value *ucontrol)
586 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
587 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
588 struct wm8994 *control = wm8994->wm8994;
589 int value = ucontrol->value.enumerated.item[0];
592 /* Don't allow on the fly reconfiguration */
593 reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
594 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
597 if (value >= control->pdata.num_vss_hpf_cfgs)
600 wm8994->vss_hpf_cfg = value;
605 static int wm8958_get_vss_hpf_enum(struct snd_kcontrol *kcontrol,
606 struct snd_ctl_elem_value *ucontrol)
608 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
609 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
611 ucontrol->value.enumerated.item[0] = wm8994->vss_hpf_cfg;
616 static int wm8958_vss_info(struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_info *uinfo)
619 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
621 uinfo->value.integer.min = 0;
622 uinfo->value.integer.max = 1;
626 static int wm8958_vss_get(struct snd_kcontrol *kcontrol,
627 struct snd_ctl_elem_value *ucontrol)
629 int vss = kcontrol->private_value;
630 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
631 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
633 ucontrol->value.integer.value[0] = wm8994->vss_ena[vss];
638 static int wm8958_vss_put(struct snd_kcontrol *kcontrol,
639 struct snd_ctl_elem_value *ucontrol)
641 int vss = kcontrol->private_value;
642 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
643 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
645 if (wm8994->vss_ena[vss] == ucontrol->value.integer.value[0])
648 if (ucontrol->value.integer.value[0] > 1)
651 if (!wm8994->mbc_vss)
654 if (wm8958_dsp2_busy(wm8994, vss)) {
655 dev_dbg(component->dev, "DSP2 active on %d already\n", vss);
659 if (wm8994->enh_eq_ena[vss])
662 wm8994->vss_ena[vss] = ucontrol->value.integer.value[0];
664 wm8958_dsp_apply(component, vss, wm8994->vss_ena[vss]);
670 #define WM8958_VSS_SWITCH(xname, xval) {\
671 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
672 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
673 .info = wm8958_vss_info, \
674 .get = wm8958_vss_get, .put = wm8958_vss_put, \
675 .private_value = xval }
677 static int wm8958_hpf_info(struct snd_kcontrol *kcontrol,
678 struct snd_ctl_elem_info *uinfo)
680 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
682 uinfo->value.integer.min = 0;
683 uinfo->value.integer.max = 1;
687 static int wm8958_hpf_get(struct snd_kcontrol *kcontrol,
688 struct snd_ctl_elem_value *ucontrol)
690 int hpf = kcontrol->private_value;
691 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
692 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
695 ucontrol->value.integer.value[0] = wm8994->hpf1_ena[hpf % 3];
697 ucontrol->value.integer.value[0] = wm8994->hpf2_ena[hpf % 3];
702 static int wm8958_hpf_put(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
705 int hpf = kcontrol->private_value;
706 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
707 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
710 if (wm8994->hpf1_ena[hpf % 3] ==
711 ucontrol->value.integer.value[0])
714 if (wm8994->hpf2_ena[hpf % 3] ==
715 ucontrol->value.integer.value[0])
719 if (ucontrol->value.integer.value[0] > 1)
722 if (!wm8994->mbc_vss)
725 if (wm8958_dsp2_busy(wm8994, hpf % 3)) {
726 dev_dbg(component->dev, "DSP2 active on %d already\n", hpf);
730 if (wm8994->enh_eq_ena[hpf % 3])
734 wm8994->hpf1_ena[hpf % 3] = ucontrol->value.integer.value[0];
736 wm8994->hpf2_ena[hpf % 3] = ucontrol->value.integer.value[0];
738 wm8958_dsp_apply(component, hpf % 3, ucontrol->value.integer.value[0]);
743 #define WM8958_HPF_SWITCH(xname, xval) {\
744 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
745 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
746 .info = wm8958_hpf_info, \
747 .get = wm8958_hpf_get, .put = wm8958_hpf_put, \
748 .private_value = xval }
750 static int wm8958_put_enh_eq_enum(struct snd_kcontrol *kcontrol,
751 struct snd_ctl_elem_value *ucontrol)
753 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
754 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
755 struct wm8994 *control = wm8994->wm8994;
756 int value = ucontrol->value.enumerated.item[0];
759 /* Don't allow on the fly reconfiguration */
760 reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
761 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
764 if (value >= control->pdata.num_enh_eq_cfgs)
767 wm8994->enh_eq_cfg = value;
772 static int wm8958_get_enh_eq_enum(struct snd_kcontrol *kcontrol,
773 struct snd_ctl_elem_value *ucontrol)
775 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
776 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
778 ucontrol->value.enumerated.item[0] = wm8994->enh_eq_cfg;
783 static int wm8958_enh_eq_info(struct snd_kcontrol *kcontrol,
784 struct snd_ctl_elem_info *uinfo)
786 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
788 uinfo->value.integer.min = 0;
789 uinfo->value.integer.max = 1;
793 static int wm8958_enh_eq_get(struct snd_kcontrol *kcontrol,
794 struct snd_ctl_elem_value *ucontrol)
796 int eq = kcontrol->private_value;
797 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
798 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
800 ucontrol->value.integer.value[0] = wm8994->enh_eq_ena[eq];
805 static int wm8958_enh_eq_put(struct snd_kcontrol *kcontrol,
806 struct snd_ctl_elem_value *ucontrol)
808 int eq = kcontrol->private_value;
809 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
810 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
812 if (wm8994->enh_eq_ena[eq] == ucontrol->value.integer.value[0])
815 if (ucontrol->value.integer.value[0] > 1)
821 if (wm8958_dsp2_busy(wm8994, eq)) {
822 dev_dbg(component->dev, "DSP2 active on %d already\n", eq);
826 if (wm8994->mbc_ena[eq] || wm8994->vss_ena[eq] ||
827 wm8994->hpf1_ena[eq] || wm8994->hpf2_ena[eq])
830 wm8994->enh_eq_ena[eq] = ucontrol->value.integer.value[0];
832 wm8958_dsp_apply(component, eq, ucontrol->value.integer.value[0]);
837 #define WM8958_ENH_EQ_SWITCH(xname, xval) {\
838 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
839 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
840 .info = wm8958_enh_eq_info, \
841 .get = wm8958_enh_eq_get, .put = wm8958_enh_eq_put, \
842 .private_value = xval }
844 static const struct snd_kcontrol_new wm8958_mbc_snd_controls[] = {
845 WM8958_MBC_SWITCH("AIF1DAC1 MBC Switch", 0),
846 WM8958_MBC_SWITCH("AIF1DAC2 MBC Switch", 1),
847 WM8958_MBC_SWITCH("AIF2DAC MBC Switch", 2),
850 static const struct snd_kcontrol_new wm8958_vss_snd_controls[] = {
851 WM8958_VSS_SWITCH("AIF1DAC1 VSS Switch", 0),
852 WM8958_VSS_SWITCH("AIF1DAC2 VSS Switch", 1),
853 WM8958_VSS_SWITCH("AIF2DAC VSS Switch", 2),
854 WM8958_HPF_SWITCH("AIF1DAC1 HPF1 Switch", 0),
855 WM8958_HPF_SWITCH("AIF1DAC2 HPF1 Switch", 1),
856 WM8958_HPF_SWITCH("AIF2DAC HPF1 Switch", 2),
857 WM8958_HPF_SWITCH("AIF1DAC1 HPF2 Switch", 3),
858 WM8958_HPF_SWITCH("AIF1DAC2 HPF2 Switch", 4),
859 WM8958_HPF_SWITCH("AIF2DAC HPF2 Switch", 5),
862 static const struct snd_kcontrol_new wm8958_enh_eq_snd_controls[] = {
863 WM8958_ENH_EQ_SWITCH("AIF1DAC1 Enhanced EQ Switch", 0),
864 WM8958_ENH_EQ_SWITCH("AIF1DAC2 Enhanced EQ Switch", 1),
865 WM8958_ENH_EQ_SWITCH("AIF2DAC Enhanced EQ Switch", 2),
868 static void wm8958_enh_eq_loaded(const struct firmware *fw, void *context)
870 struct snd_soc_component *component = context;
871 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
873 if (fw && (wm8958_dsp2_fw(component, "ENH_EQ", fw, true) == 0)) {
874 mutex_lock(&wm8994->fw_lock);
876 mutex_unlock(&wm8994->fw_lock);
880 static void wm8958_mbc_vss_loaded(const struct firmware *fw, void *context)
882 struct snd_soc_component *component = context;
883 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
885 if (fw && (wm8958_dsp2_fw(component, "MBC+VSS", fw, true) == 0)) {
886 mutex_lock(&wm8994->fw_lock);
887 wm8994->mbc_vss = fw;
888 mutex_unlock(&wm8994->fw_lock);
892 static void wm8958_mbc_loaded(const struct firmware *fw, void *context)
894 struct snd_soc_component *component = context;
895 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
897 if (fw && (wm8958_dsp2_fw(component, "MBC", fw, true) == 0)) {
898 mutex_lock(&wm8994->fw_lock);
900 mutex_unlock(&wm8994->fw_lock);
904 void wm8958_dsp2_init(struct snd_soc_component *component)
906 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
907 struct wm8994 *control = wm8994->wm8994;
908 struct wm8994_pdata *pdata = &control->pdata;
911 wm8994->dsp_active = -1;
913 snd_soc_add_component_controls(component, wm8958_mbc_snd_controls,
914 ARRAY_SIZE(wm8958_mbc_snd_controls));
915 snd_soc_add_component_controls(component, wm8958_vss_snd_controls,
916 ARRAY_SIZE(wm8958_vss_snd_controls));
917 snd_soc_add_component_controls(component, wm8958_enh_eq_snd_controls,
918 ARRAY_SIZE(wm8958_enh_eq_snd_controls));
921 /* We don't *require* firmware and don't want to delay boot */
922 reject_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
923 "/*(DEBLOBBED)*/", component->dev, GFP_KERNEL,
924 component, wm8958_mbc_loaded);
925 reject_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
926 "/*(DEBLOBBED)*/", component->dev, GFP_KERNEL,
927 component, wm8958_mbc_vss_loaded);
928 reject_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
929 "/*(DEBLOBBED)*/", component->dev, GFP_KERNEL,
930 component, wm8958_enh_eq_loaded);
932 if (pdata->num_mbc_cfgs) {
933 struct snd_kcontrol_new control[] = {
934 SOC_ENUM_EXT("MBC Mode", wm8994->mbc_enum,
935 wm8958_get_mbc_enum, wm8958_put_mbc_enum),
938 /* We need an array of texts for the enum API */
939 wm8994->mbc_texts = kmalloc_array(pdata->num_mbc_cfgs,
942 if (!wm8994->mbc_texts)
945 for (i = 0; i < pdata->num_mbc_cfgs; i++)
946 wm8994->mbc_texts[i] = pdata->mbc_cfgs[i].name;
948 wm8994->mbc_enum.items = pdata->num_mbc_cfgs;
949 wm8994->mbc_enum.texts = wm8994->mbc_texts;
951 ret = snd_soc_add_component_controls(wm8994->hubs.component,
954 dev_err(wm8994->hubs.component->dev,
955 "Failed to add MBC mode controls: %d\n", ret);
958 if (pdata->num_vss_cfgs) {
959 struct snd_kcontrol_new control[] = {
960 SOC_ENUM_EXT("VSS Mode", wm8994->vss_enum,
961 wm8958_get_vss_enum, wm8958_put_vss_enum),
964 /* We need an array of texts for the enum API */
965 wm8994->vss_texts = kmalloc_array(pdata->num_vss_cfgs,
968 if (!wm8994->vss_texts)
971 for (i = 0; i < pdata->num_vss_cfgs; i++)
972 wm8994->vss_texts[i] = pdata->vss_cfgs[i].name;
974 wm8994->vss_enum.items = pdata->num_vss_cfgs;
975 wm8994->vss_enum.texts = wm8994->vss_texts;
977 ret = snd_soc_add_component_controls(wm8994->hubs.component,
980 dev_err(wm8994->hubs.component->dev,
981 "Failed to add VSS mode controls: %d\n", ret);
984 if (pdata->num_vss_hpf_cfgs) {
985 struct snd_kcontrol_new control[] = {
986 SOC_ENUM_EXT("VSS HPF Mode", wm8994->vss_hpf_enum,
987 wm8958_get_vss_hpf_enum,
988 wm8958_put_vss_hpf_enum),
991 /* We need an array of texts for the enum API */
992 wm8994->vss_hpf_texts = kmalloc_array(pdata->num_vss_hpf_cfgs,
995 if (!wm8994->vss_hpf_texts)
998 for (i = 0; i < pdata->num_vss_hpf_cfgs; i++)
999 wm8994->vss_hpf_texts[i] = pdata->vss_hpf_cfgs[i].name;
1001 wm8994->vss_hpf_enum.items = pdata->num_vss_hpf_cfgs;
1002 wm8994->vss_hpf_enum.texts = wm8994->vss_hpf_texts;
1004 ret = snd_soc_add_component_controls(wm8994->hubs.component,
1007 dev_err(wm8994->hubs.component->dev,
1008 "Failed to add VSS HPFmode controls: %d\n",
1012 if (pdata->num_enh_eq_cfgs) {
1013 struct snd_kcontrol_new control[] = {
1014 SOC_ENUM_EXT("Enhanced EQ Mode", wm8994->enh_eq_enum,
1015 wm8958_get_enh_eq_enum,
1016 wm8958_put_enh_eq_enum),
1019 /* We need an array of texts for the enum API */
1020 wm8994->enh_eq_texts = kmalloc_array(pdata->num_enh_eq_cfgs,
1023 if (!wm8994->enh_eq_texts)
1026 for (i = 0; i < pdata->num_enh_eq_cfgs; i++)
1027 wm8994->enh_eq_texts[i] = pdata->enh_eq_cfgs[i].name;
1029 wm8994->enh_eq_enum.items = pdata->num_enh_eq_cfgs;
1030 wm8994->enh_eq_enum.texts = wm8994->enh_eq_texts;
1032 ret = snd_soc_add_component_controls(wm8994->hubs.component,
1035 dev_err(wm8994->hubs.component->dev,
1036 "Failed to add enhanced EQ controls: %d\n",