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 v3 8/8] ALSA: hda/cs35l41: Ensure SPI devices are always reset during system suspend
Date: Thu, 3 Dec 2026 14:13:10 +0000 [thread overview]
Message-ID: <20261203141359.150688-9-sbinding@opensource.cirrus.com> (raw)
In-Reply-To: <20261203141359.150688-1-sbinding@opensource.cirrus.com>
After the software reset was removed from the normal system resume for
SPI devices due to boot issues, there remains a path where one of the
amps could suspend and resume without reset. This could cause
unexpected issues.
To solve this, add a software reset for SPI devices in the suspend
callback. Whilst, in theory, the boot issue could re-occur due to the
software reset, it can only occur if reset GPIO does not get used,
such as if the suspend gets aborted before the amp which owns the
shared reset suspends. The separation between the suspend and resume
calls should also help to minimise the chance of failure.
The CS35L41 may need to be woken from hibernation before reset.
I2C devices do not need to reset on suspend, since they are safe to
reset in the system resume call.
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 138 +++++++++++++++++++--
sound/hda/codecs/side-codecs/cs35l41_hda.h | 7 ++
2 files changed, 138 insertions(+), 7 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index e6ab53d5ba3a..507beea057c0 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -947,7 +947,99 @@ static int cs35l41_verify_id(struct cs35l41_hda *cs35l41, unsigned int *regid, u
return 0;
}
-static int cs35l41_ready_for_reset(struct cs35l41_hda *cs35l41)
+#if IS_ENABLED(CONFIG_SPI)
+
+static int cs35l41_spi_issue_bus_locked_reset(struct cs35l41_hda *cs35l41, struct spi_device *spi)
+{
+ struct cs35l41_spi_payload *buf = cs35l41->spi_payload_buf;
+ struct spi_transfer t = {
+ .tx_buf = cs35l41->spi_payload_buf,
+ .len = sizeof(*cs35l41->spi_payload_buf),
+ };
+ struct spi_message m;
+ int ret;
+
+ buf->addr = cpu_to_be32(CS35L41_SFT_RESET);
+ buf->value = cpu_to_be32(CS35L41_SOFTWARE_RESET);
+ spi_message_init_with_transfers(&m, &t, 1);
+ ret = spi_sync_locked(spi, &m);
+ if (ret)
+ dev_err(cs35l41->dev, "spi_sync failed: %d\n", ret);
+
+ return ret;
+}
+
+static int cs35l41_spi_system_reset(struct cs35l41_hda *cs35l41)
+{
+ struct spi_device *spi = to_spi_device(cs35l41->dev);
+ int ret;
+
+ /*
+ * There must not be any other SPI bus activity while the amp is
+ * soft-resetting.
+ */
+ ret = spi_bus_lock(spi->controller);
+ if (ret) {
+ dev_err(cs35l41->dev, "spi_bus_lock failed: %d\n", ret);
+ return ret;
+ }
+
+ dev_info(cs35l41->dev, "Issuing SPI software reset\n");
+
+ /* Force quiet interval before issuing reset */
+ fsleep(10000);
+
+ ret = cs35l41_spi_issue_bus_locked_reset(cs35l41, spi);
+
+ /* Force quiet interval after issuing reset */
+ fsleep(10000);
+
+ spi_bus_unlock(spi->controller);
+
+ return ret;
+}
+
+static int cs35l41_spi_suspend_reset(struct cs35l41_hda *cs35l41)
+{
+ int ret = 0;
+
+ if (cs35l41->control_bus != SPI)
+ return 0;
+
+ if (cs35l41->cs_dsp.running) {
+ /*
+ * If the DSP was running, after _force_suspend() we will be in hibernation.
+ * We need to exit hibernation, or the reset write could be ignored.
+ */
+ regcache_cache_only(cs35l41->regmap, false);
+ ret = cs35l41_exit_hibernate(cs35l41->dev, cs35l41->regmap);
+ regcache_cache_only(cs35l41->regmap, true);
+ if (ret)
+ return ret;
+ }
+
+ ret = cs35l41_spi_system_reset(cs35l41);
+ if (ret) {
+ /* revert hibernation if reset failed */
+ if (cs35l41->cs_dsp.running) {
+ regcache_cache_only(cs35l41->regmap, false);
+ cs35l41_enter_hibernate(cs35l41->dev, cs35l41->regmap,
+ cs35l41->hw_cfg.bst_type);
+ regcache_cache_only(cs35l41->regmap, true);
+ }
+ dev_err(cs35l41->dev, "SPI System Reset Failed: %d\n", ret);
+ }
+
+ return ret;
+}
+#else
+static int cs35l41_spi_suspend_reset(struct cs35l41_hda *cs35l41)
+{
+ return 0;
+}
+#endif /* IS_ENABLED(CONFIG_SPI) */
+
+static void cs35l41_ready_for_reset(struct cs35l41_hda *cs35l41)
{
guard(mutex)(&cs35l41->fw_mutex);
if (cs35l41->cs_dsp.running) {
@@ -955,8 +1047,6 @@ static int cs35l41_ready_for_reset(struct cs35l41_hda *cs35l41)
cs35l41->cs_dsp.booted = false;
}
regcache_mark_dirty(cs35l41->regmap);
-
- return 0;
}
static void cs35l41_set_suspending(struct cs35l41_hda *cs35l41, bool suspending)
@@ -1048,15 +1138,32 @@ static int cs35l41_system_suspend(struct device *dev)
return ret;
}
+ /*
+ * Ensure SPI Devices have been reset in case of abort.
+ * All I2C devices will be reset on resume anyway, but SPI devices would only get reset on
+ * resume by the shared reset GPIO.
+ */
+ ret = cs35l41_spi_suspend_reset(cs35l41);
+ if (ret) {
+ /* clean up force_suspend */
+ int tmp = pm_runtime_force_resume(cs35l41->dev);
+
+ if (tmp)
+ dev_err(cs35l41->dev, "Resume failed after SPI reset failure: %d\n", tmp);
+
+ if (cs35l41->irq)
+ enable_irq(cs35l41->irq);
+
+ return ret;
+ }
+
/* Shutdown DSP before system suspend */
- ret = cs35l41_ready_for_reset(cs35l41);
- if (ret)
- dev_err(dev, "System Suspend Failed, not ready for Reset: %d\n", ret);
+ cs35l41_ready_for_reset(cs35l41);
dev_dbg(cs35l41->dev, "System Suspended\n");
cs35l41_set_suspending(cs35l41, false);
- return ret;
+ return 0;
}
static int cs35l41_system_suspend_late(struct device *dev)
@@ -2055,6 +2162,17 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
return 0;
}
+static int cs35l41_init_config_for_spi(struct cs35l41_hda *cs35l41, struct spi_device *spi)
+{
+ cs35l41->spi_payload_buf = devm_kzalloc_obj(&spi->dev,
+ *cs35l41->spi_payload_buf,
+ GFP_KERNEL | GFP_DMA);
+ if (!cs35l41->spi_payload_buf)
+ return -ENOMEM;
+
+ return 0;
+}
+
int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int irq,
struct regmap *regmap, enum control_bus control_bus)
{
@@ -2072,6 +2190,12 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
if (!cs35l41)
return -ENOMEM;
+ if (control_bus == SPI) {
+ ret = cs35l41_init_config_for_spi(cs35l41, to_spi_device(dev));
+ if (ret)
+ return ret;
+ }
+
cs35l41->dev = dev;
cs35l41->irq = irq;
cs35l41->regmap = regmap;
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.h b/sound/hda/codecs/side-codecs/cs35l41_hda.h
index b374836e8537..9329fb6834af 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.h
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.h
@@ -39,6 +39,12 @@ struct cs35l41_amp_efi_data {
struct cs35l41_amp_cal_data data[];
} __packed;
+struct cs35l41_spi_payload {
+ __be32 addr;
+ __be16 pad;
+ __be32 value;
+} __packed;
+
enum cs35l41_hda_spk_pos {
CS35L41_LEFT,
CS35L41_RIGHT,
@@ -79,6 +85,7 @@ struct cs35l41_hda {
struct snd_kcontrol *fw_load_ctl;
struct snd_kcontrol *mute_override_ctl;
struct notifier_block pm_notifier;
+ struct cs35l41_spi_payload *spi_payload_buf;
bool suspending;
struct regmap_irq_chip_data *irq_data;
--
2.43.0
prev parent reply other threads:[~2026-12-03 14:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:13 [PATCH v3 0/8] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
2026-12-03 14:13 ` [PATCH v3 1/8] ALSA: hda: cs35l41: Remove redundant lock_system_sleep() calls Stefan Binding
2026-12-03 14:13 ` [PATCH v3 2/8] ASoC: cs35l41: Prevent software reset when using SPI Stefan Binding
2026-12-03 14:55 ` sashiko-bot
2026-12-03 14:13 ` [PATCH v3 3/8] ALSA: hda: cs35l41: Unset irq if not used or configured Stefan Binding
2026-12-03 14:13 ` [PATCH v3 4/8] ALSA: hda/cs35l41: Split System Suspend/Resume callbacks Stefan Binding
2026-12-03 14:13 ` [PATCH v3 5/8] ALSA: hda/cs35l41: Remove support for alternative firmware types Stefan Binding
2026-12-03 14:13 ` [PATCH v3 6/8] ALSA: hda/cs35l41: Store filenames of successfully loaded firmware and tunings Stefan Binding
2026-12-03 14:13 ` [PATCH v3 7/8] ALSA: hda/cs35l41: rework how firmware requests are queued and flushed to prevent races Stefan Binding
2026-12-03 14:13 ` Stefan Binding [this message]
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=20261203141359.150688-9-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox