Re: [alsa-devel] [PATCH v5 2/2] ASoC: da7210: Add support for ALC andNoise suppression

From: Girdwood, Liam
Date: Wed Oct 19 2011 - 03:58:01 EST


On 18 October 2011 14:43, Ashish Chavan <ashish.chavan@xxxxxxxxxxxxxxx> wrote:
> This patch adds controls to set following ALC parameters,
> Â- Max gain, Min gain, Noise gain, Attack rate, Release rate and delay
>
> It also adds a switch to enable/disable noise suppression.
>
> As per DA7210 data sheet, ALC and noise suppression can be enabled
> only if certain conditions are met. This condition checks are handled
> by simply using "_EXT" version of controls to capture change events.
>
> Signed-off-by: Ashish Chavan <ashish.chavan@xxxxxxxxxxxxxxx>
> Signed-off-by: David Dajun Chen <dchen@xxxxxxxxxxx>
> ---
> Changes since v1:
> - Reading from register instead of cache
> - Made debug message more specific about error
> - Changed "Gain" to "Volume" in names of ALC controls
> ---
> Âsound/soc/codecs/da7210.c | Â109 +++++++++++++++++++++++++++++++++++++++++++++
> Â1 files changed, 109 insertions(+), 0 deletions(-)
>
> diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c
> index a31be70..edcfc36 100644
> --- a/sound/soc/codecs/da7210.c
> +++ b/sound/soc/codecs/da7210.c
> @@ -26,11 +26,15 @@
> Â#include <sound/tlv.h>
>
> Â/* DA7210 register space */
> +#define DA7210_CONTROL Â Â Â Â Â Â Â Â 0x01
> Â#define DA7210_STATUS Â Â Â Â Â Â Â Â Â0x02
> Â#define DA7210_STARTUP1 Â Â Â Â Â Â Â Â Â Â Â Â0x03
> Â#define DA7210_MIC_L Â Â Â Â Â Â Â Â Â 0x07
> Â#define DA7210_MIC_R Â Â Â Â Â Â Â Â Â 0x08
> +#define DA7210_AUX1_L Â Â Â Â Â Â Â Â Â0x09
> +#define DA7210_AUX1_R Â Â Â Â Â Â Â Â Â0x0A
> Â#define DA7210_AUX2 Â Â Â Â Â Â Â Â Â Â0x0B
> +#define DA7210_IN_GAIN Â Â Â Â Â Â Â Â 0x0C
> Â#define DA7210_INMIX_L Â Â Â Â Â Â Â Â 0x0D
> Â#define DA7210_INMIX_R Â Â Â Â Â Â Â Â 0x0E
> Â#define DA7210_ADC_HPF Â Â Â Â Â Â Â Â 0x0F
> @@ -59,6 +63,12 @@
> Â#define DA7210_PLL_DIV2 Â Â Â Â Â Â Â Â Â Â Â Â0x2A
> Â#define DA7210_PLL_DIV3 Â Â Â Â Â Â Â Â Â Â Â Â0x2B
> Â#define DA7210_PLL Â Â Â Â Â Â Â Â Â Â 0x2C
> +#define DA7210_ALC_MAX Â Â Â Â Â Â Â Â 0x83
> +#define DA7210_ALC_MIN Â Â Â Â Â Â Â Â 0x84
> +#define DA7210_ALC_NOIS Â Â Â Â Â Â Â Â Â Â Â Â0x85
> +#define DA7210_ALC_ATT Â Â Â Â Â Â Â Â 0x86
> +#define DA7210_ALC_REL Â Â Â Â Â Â Â Â 0x87
> +#define DA7210_ALC_DEL Â Â Â Â Â Â Â Â 0x88
> Â#define DA7210_A_HID_UNLOCK Â Â Â Â Â Â0x8A
> Â#define DA7210_A_TEST_UNLOCK Â Â Â Â Â 0x8B
> Â#define DA7210_A_PLL1 Â Â Â Â Â Â Â Â Â0x90
> @@ -81,6 +91,7 @@
> Â#define DA7210_IN_R_EN Â Â Â Â Â Â Â Â (1 << 7)
>
> Â/* ADC bit fields */
> +#define DA7210_ADC_ALC_EN Â Â Â Â Â Â Â(1 << 0)
> Â#define DA7210_ADC_L_EN Â Â Â Â Â Â Â Â Â Â Â Â(1 << 3)
> Â#define DA7210_ADC_R_EN Â Â Â Â Â Â Â Â Â Â Â Â(1 << 7)
>
> @@ -150,6 +161,29 @@
> Â/* SOFTMUTE bit fields */
> Â#define DA7210_RAMP_EN Â Â Â Â Â Â Â Â (1 << 6)
>
> +/* CONTROL bit fields */
> +#define DA7210_NOISE_SUP_EN Â Â Â Â Â Â(1 << 3)
> +
> +/* IN_GAIN bit fields */
> +#define DA7210_INPGA_L_VOL Â Â Â Â Â Â (0x0F << 0)
> +#define DA7210_INPGA_R_VOL Â Â Â Â Â Â (0xF0 << 0)
> +
> +/* ZERO_CROSS bit fields */
> +#define DA7210_AUX1_L_ZC Â Â Â Â Â Â Â (1 << 0)
> +#define DA7210_AUX1_R_ZC Â Â Â Â Â Â Â (1 << 1)
> +#define DA7210_HP_L_ZC Â Â Â Â Â Â Â Â (1 << 6)
> +#define DA7210_HP_R_ZC Â Â Â Â Â Â Â Â (1 << 7)
> +
> +/* AUX1_L bit fields */
> +#define DA7210_AUX1_L_VOL Â Â Â Â Â Â Â(0x3F << 0)
> +
> +/* AUX1_R bit fields */
> +#define DA7210_AUX1_R_VOL Â Â Â Â Â Â Â(0x3F << 0)
> +
> +/* Minimum INPGA and AUX1 volume to enable noise suppression */
> +#define DA7210_INPGA_MIN_VOL_NS Â Â Â Â Â Â Â Â0x0A Â/* 10.5dB */
> +#define DA7210_AUX1_MIN_VOL_NS Â Â Â Â 0x35 Â/* 6dB */
> +
> Â#define DA7210_VERSION "0.0.1"
>
> Â/*
> @@ -202,6 +236,68 @@ static const char *da7210_hp_mode_txt[] = {
> Âstatic const struct soc_enum da7210_hp_mode_sel =
> Â Â Â ÂSOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
>
> +/* ALC can be enabled only if noise suppression is disabled */
> +static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct snd_ctl_elem_value *ucontrol)
> +{
> + Â Â Â struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
> +
> + Â Â Â if (ucontrol->value.integer.value[0]) {
> + Â Â Â Â Â Â Â /* Check if noise suppression is enabled */
> + Â Â Â Â Â Â Â if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_dbg(codec->dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Disable noise suppression to enable ALC\n");
> + Â Â Â Â Â Â Â Â Â Â Â return -EPERM;

-EINVAL


> + Â Â Â Â Â Â Â }
> + Â Â Â }
> + Â Â Â /* If all conditions are met or we are actually disabling ALC */
> + Â Â Â return snd_soc_put_volsw(kcontrol, ucontrol);
> +}
> +
> +/* Noise suppression can be enabled only if following conditions are met
> + * ÂALC disabled
> + * ÂZC enabled for HP and AUX1 PGA
> + * ÂINPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
> + * ÂAUX1_L_VOL and AUX1_R_VOL >= 6 dB
> + */
> +static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct snd_ctl_elem_value *ucontrol)
> +{
> + Â Â Â struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
> + Â Â Â u8 val;
> +
> + Â Â Â if (ucontrol->value.integer.value[0]) {
> + Â Â Â Â Â Â Â /* Check if ALC is enabled */
> + Â Â Â Â Â Â Â if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
> + Â Â Â Â Â Â Â Â Â Â Â goto err;
> +
> + Â Â Â Â Â Â Â /* Check ZC for HP and AUX1 PGA */
> + Â Â Â Â Â Â Â if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
> + Â Â Â Â Â Â Â Â Â Â Â (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
> + Â Â Â Â Â Â Â Â Â Â Â DA7210_HP_R_ZC)) != 0xc3)

It may be clearer if you don't use the magic number here and specify
the bits you are checking.

> + Â Â Â Â Â Â Â Â Â Â Â goto err;
> +
> + Â Â Â Â Â Â Â /* Check INPGA_L_VOL and INPGA_R_VOL */
> + Â Â Â Â Â Â Â val = snd_soc_read(codec, DA7210_IN_GAIN);
> + Â Â Â Â Â Â Â if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
> + Â Â Â Â Â Â Â Â Â Â Â (((val & DA7210_INPGA_R_VOL) >> 4) <
> + Â Â Â Â Â Â Â Â Â Â Â DA7210_INPGA_MIN_VOL_NS))
> + Â Â Â Â Â Â Â Â Â Â Â goto err;
> +
> + Â Â Â Â Â Â Â /* Check AUX1_L_VOL and AUX1_R_VOL */
> + Â Â Â Â Â Â Â if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
> + Â Â Â Â Â Â Â Â Â DA7210_AUX1_MIN_VOL_NS) ||
> + Â Â Â Â Â Â Â Â Â ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
> + Â Â Â Â Â Â Â Â Â DA7210_AUX1_MIN_VOL_NS))
> + Â Â Â Â Â Â Â Â Â Â Â goto err;
> + Â Â Â }
> + Â Â Â /* If all conditions are met or we are actually disabling Noise sup */
> + Â Â Â return snd_soc_put_volsw(kcontrol, ucontrol);
> +
> +err:
> + Â Â Â return -EPERM;

-EINVAL

> +}
> +
> Âstatic const struct snd_kcontrol_new da7210_snd_controls[] = {
>
> Â Â Â ÂSOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
> @@ -260,6 +356,19 @@ static const struct snd_kcontrol_new da7210_snd_controls[] = {
> Â Â Â ÂSOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
>
> Â Â Â ÂSOC_ENUM("Headphone Class", da7210_hp_mode_sel),
> +
> + Â Â Â /* ALC controls */
> + Â Â Â SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
> + Â Â Â Â Â Â Â Â Â Â Âsnd_soc_get_volsw, da7210_put_alc_sw),
> + Â Â Â SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
> + Â Â Â SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
> + Â Â Â SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
> + Â Â Â SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
> + Â Â Â SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
> + Â Â Â SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
> +
> + Â Â Â SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
> + Â Â Â Â Â Â Â Â Â Â Â0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
> Â};
>
> Â/* Codec private data */
> --
> 1.7.1
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/