ASoC: sgtl5000: Fix driver probe after reset
Subsystems (3)
Fabio Estevam
maintainerPATCH v2 1/1 ASoC: sgtl5000: Fix driver probe after reset
From: Fabio Estevam <[email protected]>
sgtl5000 codec does not have a reset line, nor a reset command in software.
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)
As the sgtl5000 codec did not go through a real reset, we cannot rely on the sgtl5000_reg_defaults array, since these are only valid after a clean power-on reset.
To fix this issue, use 'num_reg_defaults_raw' which tells the regcache driver to actually read the codec registers and then fill the cache with these values.
---
Changes since v1:
- Remove sgtl5000_reg_defaults array
- Do not use num_reg_defaults_raw
sound/soc/codecs/sgtl5000.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-)
sound/soc/codecs/sgtl5000.c +1 -29
@@ -34,33 +34,6 @@#define SGTL5000_DAP_REG_OFFSET 0x0100#define SGTL5000_MAX_REG_OFFSET 0x013A -/* default value of sgtl5000 registers */ -static const struct reg_default sgtl5000_reg_defaults[] = { - {SGTL5000_CHIP_CLK_CTRL ,0x0008 }, - {SGTL5000_CHIP_I2S_CTRL ,0x0010 }, - {SGTL5000_CHIP_SSS_CTRL ,0x0008 }, - {SGTL5000_CHIP_DAC_VOL ,0x3c3c }, - {SGTL5000_CHIP_PAD_STRENGTH ,0x015f }, - {SGTL5000_CHIP_ANA_HP_CTRL ,0x1818 }, - {SGTL5000_CHIP_ANA_CTRL ,0x0111 }, - {SGTL5000_CHIP_LINE_OUT_VOL ,0x0404 }, - {SGTL5000_CHIP_ANA_POWER ,0x7060 }, - {SGTL5000_CHIP_PLL_CTRL ,0x5000 }, - {SGTL5000_DAP_BASS_ENHANCE ,0x0040 }, - {SGTL5000_DAP_BASS_ENHANCE_CTRL ,0x051f }, - {SGTL5000_DAP_SURROUND ,0x0040 }, - {SGTL5000_DAP_EQ_BASS_BAND0 ,0x002f }, - {SGTL5000_DAP_EQ_BASS_BAND1 ,0x002f }, - {SGTL5000_DAP_EQ_BASS_BAND2 ,0x002f }, - {SGTL5000_DAP_EQ_BASS_BAND3 ,0x002f }, - {SGTL5000_DAP_EQ_BASS_BAND4 ,0x002f }, - {SGTL5000_DAP_MAIN_CHAN ,0x8000 }, - {SGTL5000_DAP_AVC_CTRL ,0x0510 }, - {SGTL5000_DAP_AVC_THRESHOLD ,0x1473 }, - {SGTL5000_DAP_AVC_ATTACK ,0x0028 }, - {SGTL5000_DAP_AVC_DECAY ,0x0050 }, -}; -/* regulator supplies for sgtl5000, VDDD is an optional external supply */ enum sgtl5000_regulator_supplies {VDDA ,
@@ -1470,8 +1443,7 @@ static const struct regmap_config sgtl5000_regmap = { .readable_reg = sgtl5000_readable, .cache_type = REGCACHE_RBTREE, - .reg_defaults = sgtl5000_reg_defaults, - .num_reg_defaults = ARRAY_SIZE(sgtl5000_reg_defaults), + .num_reg_defaults_raw = SGTL5000_MAX_REG_OFFSET, }; static int sgtl5000_i2c_probe(struct i2c_client *client,
Signature · 1 line
1.7.9.5
Mark Brown
maintainerQuoted 4 lines · Fabio Estevam
As the sgtl5000 codec did not go through a real reset, we cannot rely on the
sgtl5000_reg_defaultsarray, since these are only valid after a clean power-on reset.
Quoted 8 lines
To fix this issue, use '
num_reg_defaults_raw' which tells the regcache driver to actually read the codec registers and then fill the cache with these values.Signed-off-by Fabio Estevam <[email protected]>---
Changes since v1:
- Removesgtl5000_reg_defaultsarray
- Do not usenum_reg_defaults_raw
Changelog update needed here :)
I'm not sure that removing the defaults is the ideal thing here - it means that the driver will be stuck with whatever the last booted OS left the device running which may or may not be sane. Explicitly writing in all the values we want seems safer, that way we know how the device is configured and there's less potential for odd bugs caused by rebooting at the wrong moment.
A message that is not in the archive (sent off-list or not yet received): CAKGA1b=nHcw4bBDgU-9X-0-+b9J58vi_Az-_h+4ptNEvEC4OpA@mail.gmail.com
Mark Brown
maintainerQuoted 3 lines · Matt Sealey
match a reset chip powered on for the first time. What we should actually be doing is dumping these into the chip as the first thing we do at probe, and then they DO become the reasonable defaults.
Yes, this is eactly what I keep saying :/
Quoted 3 lines
The fix is keep using cache/regmaps or whatever, but it definitely would be an absolute requirement to reset the codec manually by putting in all the right register values before using the cache, which
You don't need to disable the cache at any point.