]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
ASoC: adau17x1: Workaround for noise bug in ADC
authorRicard Wanderlof <ricard.wanderlof@axis.com>
Thu, 7 Sep 2017 13:31:38 +0000 (15:31 +0200)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Thu, 16 Nov 2017 13:23:33 +0000 (11:23 -0200)
BugLink: http://bugs.launchpad.net/bugs/1731971
commit 1e6f4fc06f6411adf98bbbe7fcd79442cd2b2a75 upstream.

The ADC in the ADAU1361 (and possibly other Analog Devices codecs)
exhibits a cyclic variation in the noise floor (in our test setup between
-87 and -93 dB), a new value being attained within this range whenever a
new capture stream is started. The cycle repeats after about 10 or 11
restarts.

The workaround recommended by the manufacturer is to toggle the ADOSR bit
in the Converter Control 0 register each time a new capture stream is
started.

I have verified that the patch fixes this problem on the ADAU1361, and
according to the manufacturer toggling the bit in question in this manner
will at least have no detrimental effect on other chips served by this
driver.

Signed-off-by: Ricard Wanderlof <ricardw@axis.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
sound/soc/codecs/adau17x1.c
sound/soc/codecs/adau17x1.h

index 2c1bd27638648796dd89e117613578655429232d..6758f789b712cd32af6940ef501619a5af6b8502 100644 (file)
@@ -90,6 +90,27 @@ static int adau17x1_pll_event(struct snd_soc_dapm_widget *w,
        return 0;
 }
 
+static int adau17x1_adc_fixup(struct snd_soc_dapm_widget *w,
+       struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
+       struct adau *adau = snd_soc_codec_get_drvdata(codec);
+
+       /*
+        * If we are capturing, toggle the ADOSR bit in Converter Control 0 to
+        * avoid losing SNR (workaround from ADI). This must be done after
+        * the ADC(s) have been enabled. According to the data sheet, it is
+        * normally illegal to set this bit when the sampling rate is 96 kHz,
+        * but according to ADI it is acceptable for this workaround.
+        */
+       regmap_update_bits(adau->regmap, ADAU17X1_CONVERTER0,
+               ADAU17X1_CONVERTER0_ADOSR, ADAU17X1_CONVERTER0_ADOSR);
+       regmap_update_bits(adau->regmap, ADAU17X1_CONVERTER0,
+               ADAU17X1_CONVERTER0_ADOSR, 0);
+
+       return 0;
+}
+
 static const char * const adau17x1_mono_stereo_text[] = {
        "Stereo",
        "Mono Left Channel (L+R)",
@@ -121,7 +142,8 @@ static const struct snd_soc_dapm_widget adau17x1_dapm_widgets[] = {
        SND_SOC_DAPM_MUX("Right DAC Mode Mux", SND_SOC_NOPM, 0, 0,
                &adau17x1_dac_mode_mux),
 
-       SND_SOC_DAPM_ADC("Left Decimator", NULL, ADAU17X1_ADC_CONTROL, 0, 0),
+       SND_SOC_DAPM_ADC_E("Left Decimator", NULL, ADAU17X1_ADC_CONTROL, 0, 0,
+                          adau17x1_adc_fixup, SND_SOC_DAPM_POST_PMU),
        SND_SOC_DAPM_ADC("Right Decimator", NULL, ADAU17X1_ADC_CONTROL, 1, 0),
        SND_SOC_DAPM_DAC("Left DAC", NULL, ADAU17X1_DAC_CONTROL0, 0, 0),
        SND_SOC_DAPM_DAC("Right DAC", NULL, ADAU17X1_DAC_CONTROL0, 1, 0),
index bf04b7efee4084cf77fa934eadf6ab7a3506b1ad..db350035fad7c5e477b4106bcfba9d1090b543c0 100644 (file)
@@ -129,5 +129,7 @@ bool adau17x1_has_dsp(struct adau *adau);
 
 #define ADAU17X1_CONVERTER0_CONVSR_MASK                0x7
 
+#define ADAU17X1_CONVERTER0_ADOSR              BIT(3)
+
 
 #endif