[alsa-devel] [PATCH 2/2] ASoC: adau17x1: Do not reload dsp-fw if samplerate has not changed

Robert Rosengren robert.rosengren at axis.com
Tue Apr 3 10:05:35 CEST 2018


From: Danny Smith <dannys at axis.com>

Reloading fw causes an audiable popping sound, we can avoid this
by not reloading if the samplerate is the same as before.

Signed-off-by: Danny Smith <dannys at axis.com>
---
 sound/soc/codecs/adau17x1.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/sound/soc/codecs/adau17x1.c b/sound/soc/codecs/adau17x1.c
index 5636b9522462..3c28b7191ecd 100644
--- a/sound/soc/codecs/adau17x1.c
+++ b/sound/soc/codecs/adau17x1.c
@@ -840,25 +840,34 @@ int adau17x1_setup_firmware(struct adau *adau, unsigned int rate)
 	int ret;
 	int dspsr, dsp_run;
 
-	ret = regmap_read(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, &dspsr);
-	if (ret)
-		return ret;
+	/* Check if sample rate is the same as before. If it is there is no
+	 * point in performing the below steps as the call to
+	 * sigmadsp_setup(...) will return directly when it finds the sample
+	 * rate to be the same as before. By checking this we can prevent an
+	 * audiable popping noise which occours when toggling DSP_RUN.
+	 */
+	if (adau->sigmadsp->current_samplerate != rate) {
+		ret = regmap_read(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE,
+			&dspsr);
+		if (ret)
+			return ret;
 
-	ret = regmap_read(adau->regmap, ADAU17X1_DSP_RUN, &dsp_run);
-	if (ret)
-		return ret;
+		ret = regmap_read(adau->regmap, ADAU17X1_DSP_RUN, &dsp_run);
+		if (ret)
+			return ret;
 
-	regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 1);
-	regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, 0xf);
-	regmap_write(adau->regmap, ADAU17X1_DSP_RUN, 0);
+		regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 1);
+		regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, 0xf);
+		regmap_write(adau->regmap, ADAU17X1_DSP_RUN, 0);
 
-	ret = sigmadsp_setup(adau->sigmadsp, rate);
-	if (ret) {
-		regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 0);
-		return ret;
+		ret = sigmadsp_setup(adau->sigmadsp, rate);
+		if (ret) {
+			regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 0);
+			return ret;
+		}
+		regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, dspsr);
+		regmap_write(adau->regmap, ADAU17X1_DSP_RUN, dsp_run);
 	}
-	regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, dspsr);
-	regmap_write(adau->regmap, ADAU17X1_DSP_RUN, dsp_run);
 
 	return 0;
 }
-- 
2.11.0



More information about the Alsa-devel mailing list