Skip to content

Commit a394f88

Browse files
Fabio Estevamchrillomat
authored andcommitted
ASoC: sgtl5000: Fix driver probe after reset
After a 'reboot' command in Linux or after pressing the system's reset button the sgtl5000 driver fails to probe: sgtl5000 0-000a: Device with ID register ffff is not a sgtl5000 sgtl5000 0-000a: ASoC: failed to probe CODEC -19 imx-sgtl5000 sound.12: ASoC: failed to instantiate card -19 imx-sgtl5000 sound.12: snd_soc_register_card failed (-19) sgtl5000 codec does not have a reset line, nor a reset command in software, so after a system reset the codec does not contain the default register values from sgtl5000_reg_defaults[] anymore, as these are only valid after a power-on-reset cycle. Fix this issue by explicitly reading all the reset register values from sgtl5000_reg_defaults[] and writing them back into sgtl5000 to ensure a sane state. Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com> Tested-by: Eric Nelson <eric.nelson@boundarydevices.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent c4a3abc commit a394f88

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

sound/soc/codecs/sgtl5000.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,31 @@ static const struct regmap_config sgtl5000_regmap = {
14641464
.num_reg_defaults = ARRAY_SIZE(sgtl5000_reg_defaults),
14651465
};
14661466

1467+
/*
1468+
* Write all the default values from sgtl5000_reg_defaults[] array into the
1469+
* sgtl5000 registers, to make sure we always start with the sane registers
1470+
* values as stated in the datasheet.
1471+
*
1472+
* Since sgtl5000 does not have a reset line, nor a reset command in software,
1473+
* we follow this approach to guarantee we always start from the default values
1474+
* and avoid problems like, not being able to probe after an audio playback
1475+
* followed by a system reset or a 'reboot' command in Linux
1476+
*/
1477+
static int sgtl5000_fill_defaults(struct sgtl5000_priv *sgtl5000)
1478+
{
1479+
int i, ret, val, index;
1480+
1481+
for (i = 0; i < ARRAY_SIZE(sgtl5000_reg_defaults); i++) {
1482+
val = sgtl5000_reg_defaults[i].def;
1483+
index = sgtl5000_reg_defaults[i].reg;
1484+
ret = regmap_write(sgtl5000->regmap, index, val);
1485+
if (ret)
1486+
return ret;
1487+
}
1488+
1489+
return 0;
1490+
}
1491+
14671492
static int sgtl5000_i2c_probe(struct i2c_client *client,
14681493
const struct i2c_device_id *id)
14691494
{
@@ -1499,6 +1524,11 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
14991524

15001525
i2c_set_clientdata(client, sgtl5000);
15011526

1527+
/* Ensure sgtl5000 will start with sane register values */
1528+
ret = sgtl5000_fill_defaults(sgtl5000);
1529+
if (ret)
1530+
return ret;
1531+
15021532
ret = snd_soc_register_codec(&client->dev,
15031533
&sgtl5000_driver, &sgtl5000_dai, 1);
15041534
return ret;

0 commit comments

Comments
 (0)