[PATCH v1 2/7] ASoC: cs35l41: Prevent software reset when using SPI
From: Stefan Binding
Date: Fri Nov 20 2026 - 11:12:36 EST
If there is any SPI Bus activity during a software reset, even if the
chip select is not set for that Amp, the amp may not boot.
This affects both CS35L41 ASoC and HDA drivers. For HDA this also
affects system resume.
Whilst the driver needs the amp to be reset when coming out of system
suspend, the driver will always toggle the reset GPIO off and on to
ensure this occurs. If a reset GPIO is not defined for the amplifier,
the amplifier will not probe - unless the amp is using a shared reset.
In the case of a shared reset, the GPIO will control resets for both
amps anyway.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=221161
Signed-off-by: Stefan Binding <sbinding@xxxxxxxxxxxxxxxxxxxxx>
---
sound/soc/codecs/cs35l41-lib.c | 51 ++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 15 deletions(-)
diff --git a/sound/soc/codecs/cs35l41-lib.c b/sound/soc/codecs/cs35l41-lib.c
index 9e6bed22fbdb..0ea6e9c87da1 100644
--- a/sound/soc/codecs/cs35l41-lib.c
+++ b/sound/soc/codecs/cs35l41-lib.c
@@ -13,6 +13,7 @@
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/firmware/cirrus/wmfw.h>
+#include <linux/spi/spi.h>
#include <sound/cs35l41.h>
@@ -1588,6 +1589,18 @@ int cs35l41_exit_hibernate(struct device *dev, struct regmap *regmap)
}
EXPORT_SYMBOL_GPL(cs35l41_exit_hibernate);
+static bool cs35l41_is_spi_regmap(struct regmap *regmap)
+{
+ struct device *dev = regmap_get_device(regmap);
+
+ if (!dev) {
+ dev_err(dev, "Failed to get device from regmap\n");
+ return false;
+ }
+
+ return (IS_ENABLED(CONFIG_SPI) && dev->bus == &spi_bus_type);
+}
+
int cs35l41_wait_boot_done(struct device *dev, struct regmap *regmap)
{
ktime_t timeout;
@@ -1627,27 +1640,35 @@ int cs35l41_reset_and_boot(struct device *dev, struct regmap *regmap)
{
int ret;
- ret = regmap_write(regmap, CS35L41_SFT_RESET, CS35L41_SOFTWARE_RESET);
- if (ret) {
- dev_warn(dev, "Failed to write software reset: %d\n", ret);
-
+ if (cs35l41_is_spi_regmap(regmap)) {
/*
- * If the write failed, it is likely because the chip is still booting after a
- * reset. Wait for boot, then retry the software reset. If the initial write failed
- * for another reason, then either waiting for boot, or the second write will fail,
- * So we can return the error then.
+ * If there is any SPI Bus activity during a software reset, even if the
+ * chip select is not set for that Amp, the amp may not boot.
*/
- ret = cs35l41_wait_boot_done(dev, regmap);
- if (ret)
- return ret;
-
+ dev_dbg(dev, "Preventing Software Reset on SPI\n");
+ } else {
ret = regmap_write(regmap, CS35L41_SFT_RESET, CS35L41_SOFTWARE_RESET);
if (ret) {
- dev_err(dev, "Failed to write software reset on retry: %d\n", ret);
- return ret;
+ dev_warn(dev, "Failed to write software reset: %d\n", ret);
+
+ /*
+ * If the write failed, it is likely because the chip is still booting after
+ * a reset. Wait for boot, then retry the software reset. If the initial
+ * write failed for another reason, then either waiting for boot, or the
+ * second write will fail, so we can return the error then.
+ */
+ ret = cs35l41_wait_boot_done(dev, regmap);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(regmap, CS35L41_SFT_RESET, CS35L41_SOFTWARE_RESET);
+ if (ret) {
+ dev_err(dev, "Failed to write software reset on retry: %d\n", ret);
+ return ret;
+ }
}
+ usleep_range(2000, 2100);
}
- usleep_range(2000, 2100);
return cs35l41_wait_boot_done(dev, regmap);
}
--
2.43.0