ASoC: Avoid wraparound in wm_hubs DC servo correction
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 29 Mar 2010 14:24:40 +0000 (15:24 +0100)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 5 Apr 2010 15:17:39 +0000 (16:17 +0100)
If the correction wraps around then a substantial offset would be
introduced.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
sound/soc/codecs/wm_hubs.c

index 486bdd21a98ab9115f6ee6e37133491079d0ca4d..3729a12b151ff4dbd2c3ad2a94016243eae9025b 100644 (file)
@@ -113,13 +113,15 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
                /* HPOUT1L */
                reg = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_1) &
                        WM8993_DCS_INTEG_CHAN_0_MASK;;
-               reg += hubs->dcs_codes;
+               if (reg + hubs->dcs_codes > 0 && reg + hubs->dcs_codes < 0xff)
+                       reg += hubs->dcs_codes;
                dcs_cfg = reg << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
 
                /* HPOUT1R */
                reg = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_2) &
                        WM8993_DCS_INTEG_CHAN_1_MASK;
-               reg += hubs->dcs_codes;
+               if (reg + hubs->dcs_codes > 0 && reg + hubs->dcs_codes < 0xff)
+                       reg += hubs->dcs_codes;
                dcs_cfg |= reg;
 
                /* Do it */