Skip to content

Commit 911a0f0

Browse files
Peter UjfalusiLiam Girdwood
authored andcommitted
ASoC: tlv320dac33: Error handling for broken chip
Correct/Implement handling of broken chip. Fail the soc_prope if the communication with the chip fails (can not read chip ID). Signed-off-by: Peter Ujfalusi <[email protected]> Acked-by: Mark Brown <[email protected]> Signed-off-by: Liam Girdwood <[email protected]>
1 parent 84eae18 commit 911a0f0

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

sound/soc/codecs/tlv320dac33.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
200200
u8 *value)
201201
{
202202
struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
203-
int val;
203+
int val, ret = 0;
204204

205205
*value = reg & 0xff;
206206

@@ -210,6 +210,7 @@ static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
210210
if (val < 0) {
211211
dev_err(codec->dev, "Read failed (%d)\n", val);
212212
value[0] = dac33_read_reg_cache(codec, reg);
213+
ret = val;
213214
} else {
214215
value[0] = val;
215216
dac33_write_reg_cache(codec, reg, val);
@@ -218,7 +219,7 @@ static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
218219
value[0] = dac33_read_reg_cache(codec, reg);
219220
}
220221

221-
return 0;
222+
return ret;
222223
}
223224

224225
static int dac33_write(struct snd_soc_codec *codec, unsigned int reg,
@@ -329,13 +330,18 @@ static void dac33_init_chip(struct snd_soc_codec *codec)
329330
dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL));
330331
}
331332

332-
static inline void dac33_read_id(struct snd_soc_codec *codec)
333+
static inline int dac33_read_id(struct snd_soc_codec *codec)
333334
{
335+
int i, ret = 0;
334336
u8 reg;
335337

336-
dac33_read(codec, DAC33_DEVICE_ID_MSB, &reg);
337-
dac33_read(codec, DAC33_DEVICE_ID_LSB, &reg);
338-
dac33_read(codec, DAC33_DEVICE_REV_ID, &reg);
338+
for (i = 0; i < 3; i++) {
339+
ret = dac33_read(codec, DAC33_DEVICE_ID_MSB + i, &reg);
340+
if (ret < 0)
341+
break;
342+
}
343+
344+
return ret;
339345
}
340346

341347
static inline void dac33_soft_power(struct snd_soc_codec *codec, int power)
@@ -1414,9 +1420,15 @@ static int dac33_soc_probe(struct snd_soc_codec *codec)
14141420
dev_err(codec->dev, "Failed to power up codec: %d\n", ret);
14151421
goto err_power;
14161422
}
1417-
dac33_read_id(codec);
1423+
ret = dac33_read_id(codec);
14181424
dac33_hard_power(codec, 0);
14191425

1426+
if (ret < 0) {
1427+
dev_err(codec->dev, "Failed to read chip ID: %d\n", ret);
1428+
ret = -ENODEV;
1429+
goto err_power;
1430+
}
1431+
14201432
/* Check if the IRQ number is valid and request it */
14211433
if (dac33->irq >= 0) {
14221434
ret = request_irq(dac33->irq, dac33_interrupt_handler,

0 commit comments

Comments
 (0)