ASoC: rt5663: Delay and retry reading rt5663 ID register
authorOder Chiou <oder_chiou@realtek.com>
Thu, 9 Nov 2017 11:28:10 +0000 (19:28 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 9 Nov 2017 11:35:54 +0000 (11:35 +0000)
In the probe, the codec may not be ready for I2C reading or there are some
glitches on the i2c line. So if the i2c reading value is incorrect, it will
read again after delay. This issue is similar the patch
https://patchwork.kernel.org/patch/9681421/. In current project, these 2
devices were connected to the same i2c line, and they met the same problem.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/rt5663.c

index 767f219f6c42056a3f5e2293944a8591e3c40a98..eb3065a992ab5b642c6eab96d2b6113467fb9c85 100644 (file)
@@ -3428,7 +3428,16 @@ static int rt5663_i2c_probe(struct i2c_client *i2c,
                        ret);
                return ret;
        }
-       regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
+
+       ret = regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
+       if (ret || (val != RT5663_DEVICE_ID_2 && val != RT5663_DEVICE_ID_1)) {
+               dev_err(&i2c->dev,
+                       "Device with ID register %#x is not rt5663, retry one time.\n",
+                       val);
+               msleep(100);
+               regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
+       }
+
        switch (val) {
        case RT5663_DEVICE_ID_2:
                rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_v2_regmap);