diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-11-30 12:03:39 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-12-01 06:47:29 -0500 |
commit | 131d81061eba5ffd436b5d132530ac5205b16892 (patch) | |
tree | 16e0df193581d982c541fd531347e07fb360059b | |
parent | b2822a8c22d13bc8c441e1c0492baa40ae974b51 (diff) |
ASoC: Allow user-specified WM8958 multiband compressor configurations
The paramters of the WM8958 multiband compressor can be tuned by the
user for their system using a graphical configuration tool on the host.
Allow the user to specify a set of such paramters in platform data and
select between them at runtime.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
-rw-r--r-- | include/linux/mfd/wm8994/pdata.h | 17 | ||||
-rw-r--r-- | include/linux/mfd/wm8994/registers.h | 68 | ||||
-rw-r--r-- | sound/soc/codecs/wm8994.c | 84 |
3 files changed, 167 insertions, 2 deletions
diff --git a/include/linux/mfd/wm8994/pdata.h b/include/linux/mfd/wm8994/pdata.h index 5c51f367c061..882b51aefbc0 100644 --- a/include/linux/mfd/wm8994/pdata.h +++ b/include/linux/mfd/wm8994/pdata.h | |||
@@ -30,6 +30,8 @@ struct wm8994_ldo_pdata { | |||
30 | 30 | ||
31 | #define WM8994_DRC_REGS 5 | 31 | #define WM8994_DRC_REGS 5 |
32 | #define WM8994_EQ_REGS 19 | 32 | #define WM8994_EQ_REGS 19 |
33 | #define WM8958_MBC_CUTOFF_REGS 20 | ||
34 | #define WM8958_MBC_COEFF_REGS 48 | ||
33 | 35 | ||
34 | /** | 36 | /** |
35 | * DRC configurations are specified with a label and a set of register | 37 | * DRC configurations are specified with a label and a set of register |
@@ -59,6 +61,18 @@ struct wm8994_retune_mobile_cfg { | |||
59 | u16 regs[WM8994_EQ_REGS]; | 61 | u16 regs[WM8994_EQ_REGS]; |
60 | }; | 62 | }; |
61 | 63 | ||
64 | /** | ||
65 | * Multiband compressor configurations are specified with a label and | ||
66 | * two sets of values to write. Configurations are expected to be | ||
67 | * generated using the multiband compressor configuration panel in | ||
68 | * WISCE - see http://www.wolfsonmicro.com/wisce/ | ||
69 | */ | ||
70 | struct wm8958_mbc_cfg { | ||
71 | const char *name; | ||
72 | u16 cutoff_regs[WM8958_MBC_CUTOFF_REGS]; | ||
73 | u16 coeff_regs[WM8958_MBC_COEFF_REGS]; | ||
74 | }; | ||
75 | |||
62 | struct wm8994_pdata { | 76 | struct wm8994_pdata { |
63 | int gpio_base; | 77 | int gpio_base; |
64 | 78 | ||
@@ -78,6 +92,9 @@ struct wm8994_pdata { | |||
78 | int num_retune_mobile_cfgs; | 92 | int num_retune_mobile_cfgs; |
79 | struct wm8994_retune_mobile_cfg *retune_mobile_cfgs; | 93 | struct wm8994_retune_mobile_cfg *retune_mobile_cfgs; |
80 | 94 | ||
95 | int num_mbc_cfgs; | ||
96 | struct wm8958_mbc_cfg *mbc_cfgs; | ||
97 | |||
81 | /* LINEOUT can be differential or single ended */ | 98 | /* LINEOUT can be differential or single ended */ |
82 | unsigned int lineout1_diff:1; | 99 | unsigned int lineout1_diff:1; |
83 | unsigned int lineout2_diff:1; | 100 | unsigned int lineout2_diff:1; |
diff --git a/include/linux/mfd/wm8994/registers.h b/include/linux/mfd/wm8994/registers.h index a610c8746436..ccf3a774fe36 100644 --- a/include/linux/mfd/wm8994/registers.h +++ b/include/linux/mfd/wm8994/registers.h | |||
@@ -258,6 +258,74 @@ | |||
258 | #define WM8958_DSP2_VERMAJMIN 0xA04 | 258 | #define WM8958_DSP2_VERMAJMIN 0xA04 |
259 | #define WM8958_DSP2_VERBUILD 0xA05 | 259 | #define WM8958_DSP2_VERBUILD 0xA05 |
260 | #define WM8958_DSP2_EXECCONTROL 0xA0D | 260 | #define WM8958_DSP2_EXECCONTROL 0xA0D |
261 | #define WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_1 0x2200 | ||
262 | #define WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_2 0x2201 | ||
263 | #define WM8958_MBC_BAND_2_LOWER_CUTOFF_C2_1 0x2202 | ||
264 | #define WM8958_MBC_BAND_2_LOWER_CUTOFF_C2_2 0x2203 | ||
265 | #define WM8958_MBC_BAND_2_LOWER_CUTOFF_C3_1 0x2204 | ||
266 | #define WM8958_MBC_BAND_2_LOWER_CUTOFF_C3_2 0x2205 | ||
267 | #define WM8958_MBC_BAND_2_UPPER_CUTOFF_C2_1 0x2206 | ||
268 | #define WM8958_MBC_BAND_2_UPPER_CUTOFF_C2_2 0x2207 | ||
269 | #define WM8958_MBC_BAND_2_UPPER_CUTOFF_C3_1 0x2208 | ||
270 | #define WM8958_MBC_BAND_2_UPPER_CUTOFF_C3_2 0x2209 | ||
271 | #define WM8958_MBC_BAND_2_UPPER_CUTOFF_C1_1 0x220A | ||
272 | #define WM8958_MBC_BAND_2_UPPER_CUTOFF_C1_2 0x220B | ||
273 | #define WM8958_MBC_BAND_1_UPPER_CUTOFF_C1_1 0x220C | ||
274 | #define WM8958_MBC_BAND_1_UPPER_CUTOFF_C1_2 0x220D | ||
275 | #define WM8958_MBC_BAND_1_UPPER_CUTOFF_C2_1 0x220E | ||
276 | #define WM8958_MBC_BAND_1_UPPER_CUTOFF_C2_2 0x220F | ||
277 | #define WM8958_MBC_BAND_1_UPPER_CUTOFF_C3_1 0x2210 | ||
278 | #define WM8958_MBC_BAND_1_UPPER_CUTOFF_C3_2 0x2211 | ||
279 | #define WM8958_MBC_BAND_1_LOWER_CUTOFF_1 0x2212 | ||
280 | #define WM8958_MBC_BAND_1_LOWER_CUTOFF_2 0x2213 | ||
281 | #define WM8958_MBC_BAND_1_K_1 0x2400 | ||
282 | #define WM8958_MBC_BAND_1_K_2 0x2401 | ||
283 | #define WM8958_MBC_BAND_1_N1_1 0x2402 | ||
284 | #define WM8958_MBC_BAND_1_N1_2 0x2403 | ||
285 | #define WM8958_MBC_BAND_1_N2_1 0x2404 | ||
286 | #define WM8958_MBC_BAND_1_N2_2 0x2405 | ||
287 | #define WM8958_MBC_BAND_1_N3_1 0x2406 | ||
288 | #define WM8958_MBC_BAND_1_N3_2 0x2407 | ||
289 | #define WM8958_MBC_BAND_1_N4_1 0x2408 | ||
290 | #define WM8958_MBC_BAND_1_N4_2 0x2409 | ||
291 | #define WM8958_MBC_BAND_1_N5_1 0x240A | ||
292 | #define WM8958_MBC_BAND_1_N5_2 0x240B | ||
293 | #define WM8958_MBC_BAND_1_X1_1 0x240C | ||
294 | #define WM8958_MBC_BAND_1_X1_2 0x240D | ||
295 | #define WM8958_MBC_BAND_1_X2_1 0x240E | ||
296 | #define WM8958_MBC_BAND_1_X2_2 0x240F | ||
297 | #define WM8958_MBC_BAND_1_X3_1 0x2410 | ||
298 | #define WM8958_MBC_BAND_1_X3_2 0x2411 | ||
299 | #define WM8958_MBC_BAND_1_ATTACK_1 0x2412 | ||
300 | #define WM8958_MBC_BAND_1_ATTACK_2 0x2413 | ||
301 | #define WM8958_MBC_BAND_1_DECAY_1 0x2414 | ||
302 | #define WM8958_MBC_BAND_1_DECAY_2 0x2415 | ||
303 | #define WM8958_MBC_BAND_2_K_1 0x2416 | ||
304 | #define WM8958_MBC_BAND_2_K_2 0x2417 | ||
305 | #define WM8958_MBC_BAND_2_N1_1 0x2418 | ||
306 | #define WM8958_MBC_BAND_2_N1_2 0x2419 | ||
307 | #define WM8958_MBC_BAND_2_N2_1 0x241A | ||
308 | #define WM8958_MBC_BAND_2_N2_2 0x241B | ||
309 | #define WM8958_MBC_BAND_2_N3_1 0x241C | ||
310 | #define WM8958_MBC_BAND_2_N3_2 0x241D | ||
311 | #define WM8958_MBC_BAND_2_N4_1 0x241E | ||
312 | #define WM8958_MBC_BAND_2_N4_2 0x241F | ||
313 | #define WM8958_MBC_BAND_2_N5_1 0x2420 | ||
314 | #define WM8958_MBC_BAND_2_N5_2 0x2421 | ||
315 | #define WM8958_MBC_BAND_2_X1_1 0x2422 | ||
316 | #define WM8958_MBC_BAND_2_X1_2 0x2423 | ||
317 | #define WM8958_MBC_BAND_2_X2_1 0x2424 | ||
318 | #define WM8958_MBC_BAND_2_X2_2 0x2425 | ||
319 | #define WM8958_MBC_BAND_2_X3_1 0x2426 | ||
320 | #define WM8958_MBC_BAND_2_X3_2 0x2427 | ||
321 | #define WM8958_MBC_BAND_2_ATTACK_1 0x2428 | ||
322 | #define WM8958_MBC_BAND_2_ATTACK_2 0x2429 | ||
323 | #define WM8958_MBC_BAND_2_DECAY_1 0x242A | ||
324 | #define WM8958_MBC_BAND_2_DECAY_2 0x242B | ||
325 | #define WM8958_MBC_B2_PG2_1 0x242C | ||
326 | #define WM8958_MBC_B2_PG2_2 0x242D | ||
327 | #define WM8958_MBC_B1_PG2_1 0x242E | ||
328 | #define WM8958_MBC_B1_PG2_2 0x242F | ||
261 | #define WM8994_WRITE_SEQUENCER_0 0x3000 | 329 | #define WM8994_WRITE_SEQUENCER_0 0x3000 |
262 | #define WM8994_WRITE_SEQUENCER_1 0x3001 | 330 | #define WM8994_WRITE_SEQUENCER_1 0x3001 |
263 | #define WM8994_WRITE_SEQUENCER_2 0x3002 | 331 | #define WM8994_WRITE_SEQUENCER_2 0x3002 |
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c index 51f5cf16b425..59d361145b15 100644 --- a/sound/soc/codecs/wm8994.c +++ b/sound/soc/codecs/wm8994.c | |||
@@ -92,6 +92,11 @@ struct wm8994_priv { | |||
92 | int retune_mobile_cfg[WM8994_NUM_EQ]; | 92 | int retune_mobile_cfg[WM8994_NUM_EQ]; |
93 | struct soc_enum retune_mobile_enum; | 93 | struct soc_enum retune_mobile_enum; |
94 | 94 | ||
95 | /* Platform dependant MBC configuration */ | ||
96 | int mbc_cfg; | ||
97 | const char **mbc_texts; | ||
98 | struct soc_enum mbc_enum; | ||
99 | |||
95 | struct wm8994_micdet micdet[2]; | 100 | struct wm8994_micdet micdet[2]; |
96 | 101 | ||
97 | wm8958_micdet_cb jack_cb; | 102 | wm8958_micdet_cb jack_cb; |
@@ -543,8 +548,9 @@ static const struct soc_enum aif2dacr_src = | |||
543 | static void wm8958_mbc_apply(struct snd_soc_codec *codec, int mbc, int start) | 548 | static void wm8958_mbc_apply(struct snd_soc_codec *codec, int mbc, int start) |
544 | { | 549 | { |
545 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); | 550 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
551 | struct wm8994_pdata *pdata = wm8994->pdata; | ||
546 | int pwr_reg = snd_soc_read(codec, WM8994_POWER_MANAGEMENT_5); | 552 | int pwr_reg = snd_soc_read(codec, WM8994_POWER_MANAGEMENT_5); |
547 | int ena, reg, aif; | 553 | int ena, reg, aif, i; |
548 | 554 | ||
549 | switch (mbc) { | 555 | switch (mbc) { |
550 | case 0: | 556 | case 0: |
@@ -587,7 +593,20 @@ static void wm8958_mbc_apply(struct snd_soc_codec *codec, int mbc, int start) | |||
587 | snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM, | 593 | snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM, |
588 | WM8958_DSP2_ENA, WM8958_DSP2_ENA); | 594 | WM8958_DSP2_ENA, WM8958_DSP2_ENA); |
589 | 595 | ||
590 | /* TODO: Apply any user specified MBC settings */ | 596 | /* If we've got user supplied MBC settings use them */ |
597 | if (pdata && pdata->num_mbc_cfgs) { | ||
598 | struct wm8958_mbc_cfg *cfg | ||
599 | = &pdata->mbc_cfgs[wm8994->mbc_cfg]; | ||
600 | |||
601 | for (i = 0; i < ARRAY_SIZE(cfg->coeff_regs); i++) | ||
602 | snd_soc_write(codec, i + WM8958_MBC_BAND_1_K_1, | ||
603 | cfg->coeff_regs[i]); | ||
604 | |||
605 | for (i = 0; i < ARRAY_SIZE(cfg->cutoff_regs); i++) | ||
606 | snd_soc_write(codec, | ||
607 | i + WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_1, | ||
608 | cfg->cutoff_regs[i]); | ||
609 | } | ||
591 | 610 | ||
592 | /* Run the DSP */ | 611 | /* Run the DSP */ |
593 | snd_soc_write(codec, WM8958_DSP2_EXECCONTROL, | 612 | snd_soc_write(codec, WM8958_DSP2_EXECCONTROL, |
@@ -648,6 +667,39 @@ static int wm8958_aif_ev(struct snd_soc_dapm_widget *w, | |||
648 | return 0; | 667 | return 0; |
649 | } | 668 | } |
650 | 669 | ||
670 | static int wm8958_put_mbc_enum(struct snd_kcontrol *kcontrol, | ||
671 | struct snd_ctl_elem_value *ucontrol) | ||
672 | { | ||
673 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
674 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); | ||
675 | struct wm8994_pdata *pdata = wm8994->pdata; | ||
676 | int value = ucontrol->value.integer.value[0]; | ||
677 | int reg; | ||
678 | |||
679 | /* Don't allow on the fly reconfiguration */ | ||
680 | reg = snd_soc_read(codec, WM8994_CLOCKING_1); | ||
681 | if (reg < 0 || reg & WM8958_DSP2CLK_ENA) | ||
682 | return -EBUSY; | ||
683 | |||
684 | if (value >= pdata->num_mbc_cfgs) | ||
685 | return -EINVAL; | ||
686 | |||
687 | wm8994->mbc_cfg = value; | ||
688 | |||
689 | return 0; | ||
690 | } | ||
691 | |||
692 | static int wm8958_get_mbc_enum(struct snd_kcontrol *kcontrol, | ||
693 | struct snd_ctl_elem_value *ucontrol) | ||
694 | { | ||
695 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
696 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); | ||
697 | |||
698 | ucontrol->value.enumerated.item[0] = wm8994->mbc_cfg; | ||
699 | |||
700 | return 0; | ||
701 | } | ||
702 | |||
651 | static int wm8958_mbc_info(struct snd_kcontrol *kcontrol, | 703 | static int wm8958_mbc_info(struct snd_kcontrol *kcontrol, |
652 | struct snd_ctl_elem_info *uinfo) | 704 | struct snd_ctl_elem_info *uinfo) |
653 | { | 705 | { |
@@ -2539,6 +2591,34 @@ static void wm8994_handle_pdata(struct wm8994_priv *wm8994) | |||
2539 | dev_dbg(codec->dev, "%d ReTune Mobile configurations\n", | 2591 | dev_dbg(codec->dev, "%d ReTune Mobile configurations\n", |
2540 | pdata->num_retune_mobile_cfgs); | 2592 | pdata->num_retune_mobile_cfgs); |
2541 | 2593 | ||
2594 | if (pdata->num_mbc_cfgs) { | ||
2595 | struct snd_kcontrol_new control[] = { | ||
2596 | SOC_ENUM_EXT("MBC Mode", wm8994->mbc_enum, | ||
2597 | wm8958_get_mbc_enum, wm8958_put_mbc_enum), | ||
2598 | }; | ||
2599 | |||
2600 | /* We need an array of texts for the enum API */ | ||
2601 | wm8994->mbc_texts = kmalloc(sizeof(char *) | ||
2602 | * pdata->num_mbc_cfgs, GFP_KERNEL); | ||
2603 | if (!wm8994->mbc_texts) { | ||
2604 | dev_err(wm8994->codec->dev, | ||
2605 | "Failed to allocate %d MBC config texts\n", | ||
2606 | pdata->num_mbc_cfgs); | ||
2607 | return; | ||
2608 | } | ||
2609 | |||
2610 | for (i = 0; i < pdata->num_mbc_cfgs; i++) | ||
2611 | wm8994->mbc_texts[i] = pdata->mbc_cfgs[i].name; | ||
2612 | |||
2613 | wm8994->mbc_enum.max = pdata->num_mbc_cfgs; | ||
2614 | wm8994->mbc_enum.texts = wm8994->mbc_texts; | ||
2615 | |||
2616 | ret = snd_soc_add_controls(wm8994->codec, control, 1); | ||
2617 | if (ret != 0) | ||
2618 | dev_err(wm8994->codec->dev, | ||
2619 | "Failed to add MBC mode controls: %d\n", ret); | ||
2620 | } | ||
2621 | |||
2542 | if (pdata->num_retune_mobile_cfgs) | 2622 | if (pdata->num_retune_mobile_cfgs) |
2543 | wm8994_handle_retune_mobile_pdata(wm8994); | 2623 | wm8994_handle_retune_mobile_pdata(wm8994); |
2544 | else | 2624 | else |