ASoC: tpa6130a2: Error handling for broken chip
authorPeter Ujfalusi <peter.ujfalusi@nokia.com>
Thu, 21 Oct 2010 12:03:03 +0000 (15:03 +0300)
committerLiam Girdwood <lrg@slimlogic.co.uk>
Thu, 21 Oct 2010 21:06:53 +0000 (22:06 +0100)
Correct/Implement handling of broken chip.
Fail the i2c_prope if the communication with the chip
fails.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@nokia.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
sound/soc/codecs/tpa6130a2.c

index 99b70e5978a2ee122e6799df5f27e20711a93976..329acc1a207457942a560e86d7f990a2fc44ffd8 100644 (file)
@@ -98,16 +98,21 @@ static u8 tpa6130a2_read(int reg)
        return data->regs[reg];
 }
 
-static void tpa6130a2_initialize(void)
+static int tpa6130a2_initialize(void)
 {
        struct tpa6130a2_data *data;
-       int i;
+       int i, ret = 0;
 
        BUG_ON(tpa6130a2_client == NULL);
        data = i2c_get_clientdata(tpa6130a2_client);
 
-       for (i = 1; i < TPA6130A2_REG_VERSION; i++)
-               tpa6130a2_i2c_write(i, data->regs[i]);
+       for (i = 1; i < TPA6130A2_REG_VERSION; i++) {
+               ret = tpa6130a2_i2c_write(i, data->regs[i]);
+               if (ret < 0)
+                       break;
+       }
+
+       return ret;
 }
 
 static int tpa6130a2_power(int power)
@@ -133,7 +138,16 @@ static int tpa6130a2_power(int power)
                }
 
                data->power_state = 1;
-               tpa6130a2_initialize();
+               ret = tpa6130a2_initialize();
+               if (ret < 0) {
+                       dev_err(&tpa6130a2_client->dev,
+                               "Failed to initialize chip\n");
+                       if (data->power_gpio >= 0)
+                               gpio_set_value(data->power_gpio, 0);
+                       regulator_disable(data->supply);
+                       data->power_state = 0;
+                       goto exit;
+               }
 
                /* Clear SWS */
                val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
@@ -375,7 +389,9 @@ int tpa6130a2_add_controls(struct snd_soc_codec *codec)
 {
        struct  tpa6130a2_data *data;
 
-       BUG_ON(tpa6130a2_client == NULL);
+       if (tpa6130a2_client == NULL)
+               return -ENODEV;
+
        data = i2c_get_clientdata(tpa6130a2_client);
 
        snd_soc_dapm_new_controls(codec, tpa6130a2_dapm_widgets,