Skip to content

Commit 872a64d

Browse files
Peter UjfalusiLiam Girdwood
authored andcommitted
ASoC: tpa6130a2: Error handling for broken chip
Correct/Implement handling of broken chip. Fail the i2c_prope if the communication with the chip fails. Signed-off-by: Peter Ujfalusi <[email protected]> Acked-by: Mark Brown <[email protected]> Signed-off-by: Liam Girdwood <[email protected]>
1 parent cf4bb69 commit 872a64d

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

sound/soc/codecs/tpa6130a2.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,21 @@ static u8 tpa6130a2_read(int reg)
9898
return data->regs[reg];
9999
}
100100

101-
static void tpa6130a2_initialize(void)
101+
static int tpa6130a2_initialize(void)
102102
{
103103
struct tpa6130a2_data *data;
104-
int i;
104+
int i, ret = 0;
105105

106106
BUG_ON(tpa6130a2_client == NULL);
107107
data = i2c_get_clientdata(tpa6130a2_client);
108108

109-
for (i = 1; i < TPA6130A2_REG_VERSION; i++)
110-
tpa6130a2_i2c_write(i, data->regs[i]);
109+
for (i = 1; i < TPA6130A2_REG_VERSION; i++) {
110+
ret = tpa6130a2_i2c_write(i, data->regs[i]);
111+
if (ret < 0)
112+
break;
113+
}
114+
115+
return ret;
111116
}
112117

113118
static int tpa6130a2_power(int power)
@@ -133,7 +138,16 @@ static int tpa6130a2_power(int power)
133138
}
134139

135140
data->power_state = 1;
136-
tpa6130a2_initialize();
141+
ret = tpa6130a2_initialize();
142+
if (ret < 0) {
143+
dev_err(&tpa6130a2_client->dev,
144+
"Failed to initialize chip\n");
145+
if (data->power_gpio >= 0)
146+
gpio_set_value(data->power_gpio, 0);
147+
regulator_disable(data->supply);
148+
data->power_state = 0;
149+
goto exit;
150+
}
137151

138152
/* Clear SWS */
139153
val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
@@ -375,7 +389,9 @@ int tpa6130a2_add_controls(struct snd_soc_codec *codec)
375389
{
376390
struct tpa6130a2_data *data;
377391

378-
BUG_ON(tpa6130a2_client == NULL);
392+
if (tpa6130a2_client == NULL)
393+
return -ENODEV;
394+
379395
data = i2c_get_clientdata(tpa6130a2_client);
380396

381397
snd_soc_dapm_new_controls(codec, tpa6130a2_dapm_widgets,

0 commit comments

Comments
 (0)