Skip to contentSkip to conversation

ASoC: adau1761: Reset codec at probe and shutdown

PATCH In review Niklas Carlsson 2 participants 2 messages Aug 5, 2022 – Aug 8, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: adau1761: Reset codec at probe and shutdown

From: Niklas Carlsson <[email protected]>

ADAU1X61 doesn't have a reset pin, which leads to the codec retaining the register values after the device has been rebooted without a power cycle. This causes the driver to be out of sync with the codec.

Simulating a hardware reset ensures that the codec is in a defined state.

---
 sound/soc/codecs/adau1761-i2c.c |  6 +++++
 sound/soc/codecs/adau1761-spi.c |  6 +++++
 sound/soc/codecs/adau1761.c     | 43 +++++++++++++++++++++++++++++++++
 sound/soc/codecs/adau1761.h     |  1 +
 4 files changed, 56 insertions(+)
sound/soc/codecs/adau1761-i2c.c +6 -0
index 0683caf86aea..23bffbd74469 100644
@@ -36,6 +36,11 @@ static int adau1761_i2c_remove(struct i2c_client *client)
 	return 0;
 }
 
+static void adau1761_i2c_shutdown(struct i2c_client *client)
+{
+	adau1761_shutdown(&client->dev);
+}
+
 static const struct i2c_device_id adau1761_i2c_ids[] = {
 	{ "adau1361", ADAU1361 },
 	{ "adau1461", ADAU1761 },
@@ -63,6 +68,7 @@ static struct i2c_driver adau1761_i2c_driver = {
 	},
 	.probe_new = adau1761_i2c_probe,
 	.remove = adau1761_i2c_remove,
+	.shutdown = adau1761_i2c_shutdown,
 	.id_table = adau1761_i2c_ids,
 };
 module_i2c_driver(adau1761_i2c_driver);
sound/soc/codecs/adau1761-spi.c +6 -0
index 7c9242c2ff94..5bbbc3d3b5be 100644
@@ -50,6 +50,11 @@ static void adau1761_spi_remove(struct spi_device *spi)
 	adau17x1_remove(&spi->dev);
 }
 
+static void adau1761_spi_shutdown(struct spi_device *spi)
+{
+	adau1761_shutdown(&spi->dev);
+}
+
 static const struct spi_device_id adau1761_spi_id[] = {
 	{ "adau1361", ADAU1361 },
 	{ "adau1461", ADAU1761 },
@@ -77,6 +82,7 @@ static struct spi_driver adau1761_spi_driver = {
 	},
 	.probe = adau1761_spi_probe,
 	.remove = adau1761_spi_remove,
+	.shutdown = adau1761_spi_shutdown,
 	.id_table = adau1761_spi_id,
 };
 module_spi_driver(adau1761_spi_driver);
sound/soc/codecs/adau1761.c +43 -0

61 lines not on this page · raw message

sound/soc/codecs/adau1761.h +1 -0
index 7beabf448ad1..98d698ebde27 100644
@@ -16,6 +16,7 @@ struct device;
 
 int adau1761_probe(struct device *dev, struct regmap *regmap,
 	enum adau17x1_type type, void (*switch_mode)(struct device *dev));
+void adau1761_shutdown(struct device *dev);
 
 extern const struct regmap_config adau1761_regmap_config;
 
Signature · 1 line
2.30.2
maintainer
#1 lore raw

sound/soc/codecs/adau1761.c static struct snd_soc_dai_driver adau1761_dai_driver = { · line 987

Quoted 3 lines · Niklas Carlsson
sound/soc/codecs/adau1761.c +3 -0
+	 * Steps for performing the reset:
+	 *   1) Make sure that the cache is marked as dirty by writing all
+	 *      default values directly to the cache.

Why? If there's some need to mark the cache as dirty there's a function that directly does that. Note especially that a cache sync will explicitly not write any default values to the hardware if it knows about them.

sound/soc/codecs/adau1761.c static struct snd_soc_dai_driver adau1761_dai_driver = { · line 993

Quoted 5 lines
sound/soc/codecs/adau1761.c +5 -0
+	 *   2) Enable the core clock which is needed for writing all registers
+	 *      except CLOCK_CONTROL.
+	 *
+	 *   3) Use regcache_sync() for synchronizing the dirty cache back to
+	 *      the hardware.

We then need to disable clock control at the end (which the code does but the comment doesn't). It might be better to just have comments next to the individual steps here.

I'd expect something more like

enable clock
for each register except CLOCK_CONTROL write the default disable clock

here, no faffing with the cache. You could use two bulk writes to do the writes of registers below and above CLOCK_CONTROL if that's the goal in doing a cache sync.