All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Binding <sbinding@opensource.cirrus.com>
To: Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com,
	Stefan Binding <sbinding@opensource.cirrus.com>
Subject: [PATCH v1 2/7] ASoC: cs35l41: Prevent software reset when using SPI
Date: Fri, 20 Nov 2026 16:10:48 +0000	[thread overview]
Message-ID: <20261120161136.157593-3-sbinding@opensource.cirrus.com> (raw)
In-Reply-To: <20261120161136.157593-1-sbinding@opensource.cirrus.com>

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@opensource.cirrus.com>
---
 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


  parent reply	other threads:[~2026-11-20 16:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 16:10 [PATCH v1 0/7] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
2026-11-20 16:10 ` [PATCH v1 1/7] ALSA: hda: cs35l41: Remove redundant lock_system_sleep() calls Stefan Binding
2026-11-20 16:10 ` Stefan Binding [this message]
2026-11-20 16:22   ` [PATCH v1 2/7] ASoC: cs35l41: Prevent software reset when using SPI sashiko-bot
2026-11-20 16:10 ` [PATCH v1 3/7] ALSA: hda: cs35l41: Unset irq if not used or configured Stefan Binding
2026-11-20 16:10 ` [PATCH v1 4/7] ALSA: hda/cs35l41: Split System Suspend/Resume callbacks Stefan Binding
2026-11-20 16:27   ` sashiko-bot
2026-11-20 16:10 ` [PATCH v1 5/7] ALSA: hda/cs35l41: Remove support for alternative firmware types Stefan Binding
2026-11-20 16:10 ` [PATCH v1 6/7] ALSA: hda/cs35l41: Store filenames of successfully loaded firmware and tunings Stefan Binding
2026-11-20 16:10 ` [PATCH v1 7/7] ALSA: hda/cs35l41: rework how firmware requests are queued and flushed to prevent races Stefan Binding
2026-11-20 16:41   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120161136.157593-3-sbinding@opensource.cirrus.com \
    --to=sbinding@opensource.cirrus.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.