From c05d9a8c7f55a901d9e8ec2a5f0730137bbfea4a Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Thu, 25 Jun 2015 09:35:11 +0100 Subject: ASoC: arizona: Implement stability check for EQ coefficients Specifying unstable coefficients for the EQ can have a severe impact on the audio. This patchs adds a stability check on the coefficients written to the EQ, for this it is necessary to merge the mode control and the coefficients as some coefficients may only be unstable with a certain mode setting so it is ideal if these are always updated in sync. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- sound/soc/codecs/arizona.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'sound/soc/codecs/arizona.c') diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c index 802e05e..3996786 100644 --- a/sound/soc/codecs/arizona.c +++ b/sound/soc/codecs/arizona.c @@ -2313,6 +2313,65 @@ const struct snd_kcontrol_new arizona_adsp2_rate_controls[] = { }; EXPORT_SYMBOL_GPL(arizona_adsp2_rate_controls); +static bool arizona_eq_filter_unstable(bool mode, __be16 _a, __be16 _b) +{ + s16 a = be16_to_cpu(_a); + s16 b = be16_to_cpu(_b); + + if (!mode) { + return abs(a) >= 4096; + } else { + if (abs(b) >= 4096) + return true; + + return (abs((a << 16) / (4096 - b)) >= 4096 << 4); + } +} + +int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); + struct arizona *arizona = dev_get_drvdata(codec->dev->parent); + struct soc_bytes *params = (void *)kcontrol->private_value; + unsigned int val; + __be16 *data; + int len; + int ret; + + len = params->num_regs * regmap_get_val_bytes(arizona->regmap); + + data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); + if (!data) + return -ENOMEM; + + data[0] &= cpu_to_be16(ARIZONA_EQ1_B1_MODE); + + if (arizona_eq_filter_unstable(!!data[0], data[1], data[2]) || + arizona_eq_filter_unstable(true, data[4], data[5]) || + arizona_eq_filter_unstable(true, data[8], data[9]) || + arizona_eq_filter_unstable(true, data[12], data[13]) || + arizona_eq_filter_unstable(false, data[16], data[17])) { + dev_err(arizona->dev, "Rejecting unstable EQ coefficients\n"); + ret = -EINVAL; + goto out; + } + + ret = regmap_read(arizona->regmap, params->base, &val); + if (ret != 0) + goto out; + + val &= ~ARIZONA_EQ1_B1_MODE; + data[0] |= cpu_to_be16(val); + + ret = regmap_raw_write(arizona->regmap, params->base, data, len); + +out: + kfree(data); + return ret; +} +EXPORT_SYMBOL_GPL(arizona_eq_coeff_put); + MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support"); MODULE_AUTHOR("Mark Brown "); MODULE_LICENSE("GPL"); -- cgit v1.1 From 5f8e671a49e1d608fcf52c8944ea7818cd4c99a9 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Thu, 25 Jun 2015 09:35:12 +0100 Subject: ASoC: arizona: Implement stability check for LHPF coefficients Specifying unstable coefficients for the low/high pass filters can have a severe impact on the audio. This patchs adds a stability check on the coefficients written to the low/high pass filter block to prevent this. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- sound/soc/codecs/arizona.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'sound/soc/codecs/arizona.c') diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c index 3996786..a88202d 100644 --- a/sound/soc/codecs/arizona.c +++ b/sound/soc/codecs/arizona.c @@ -2372,6 +2372,23 @@ out: } EXPORT_SYMBOL_GPL(arizona_eq_coeff_put); +int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); + struct arizona *arizona = dev_get_drvdata(codec->dev->parent); + __be16 *data = (__be16 *)ucontrol->value.bytes.data; + s16 val = be16_to_cpu(*data); + + if (abs(val) >= 4096) { + dev_err(arizona->dev, "Rejecting unstable LHPF coefficients\n"); + return -EINVAL; + } + + return snd_soc_bytes_put(kcontrol, ucontrol); +} +EXPORT_SYMBOL_GPL(arizona_lhpf_coeff_put); + MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support"); MODULE_AUTHOR("Mark Brown "); MODULE_LICENSE("GPL"); -- cgit v1.1 From 5ed68f0a28f96c5127246d1743dd57b58a090f07 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Thu, 9 Jul 2015 11:28:46 +0100 Subject: ASoC: arizona: Use the more idiomatic params_width Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- sound/soc/codecs/arizona.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/soc/codecs/arizona.c') diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c index a88202d..c246fbd 100644 --- a/sound/soc/codecs/arizona.c +++ b/sound/soc/codecs/arizona.c @@ -1504,7 +1504,7 @@ static int arizona_hw_params(struct snd_pcm_substream *substream, else rates = &arizona_48k_bclk_rates[0]; - wl = snd_pcm_format_width(params_format(params)); + wl = params_width(params); if (tdm_slots) { arizona_aif_dbg(dai, "Configuring for %d %d bit TDM slots\n", -- cgit v1.1