* [PATCH v3 1/8] ALSA: hda: cs35l41: Remove redundant lock_system_sleep() calls
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 ` Stefan Binding
2026-12-03 14:13 ` [PATCH v3 2/8] ASoC: cs35l41: Prevent software reset when using SPI Stefan Binding
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Stefan Binding @ 2026-12-03 14:13 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, patches, Stefan Binding
These calls are there to prevent sleep when adding or removing device
links in the bind/unbind calls. However, since these calls occur in
probe and remove calls, where sleep is blocked, this is unnecessary.
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index 919630c11018..f6910916ad47 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -1443,7 +1443,6 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
struct hda_component_parent *parent = master_data;
struct hda_component *comp;
- unsigned int sleep_flags;
int ret = 0;
comp = hda_component_from_index(parent, cs35l41->index);
@@ -1492,10 +1491,8 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
mutex_unlock(&cs35l41->fw_mutex);
- sleep_flags = lock_system_sleep();
if (!device_link_add(&cs35l41->codec->core.dev, cs35l41->dev, DL_FLAG_STATELESS))
dev_warn(dev, "Unable to create device link\n");
- unlock_system_sleep(sleep_flags);
dev_info(cs35l41->dev,
"CS35L41 Bound - SSID: %s, BST: %d, VSPK: %d, CH: %c, FW EN: %d, SPKID: %d\n",
@@ -1512,16 +1509,13 @@ static void cs35l41_hda_unbind(struct device *dev, struct device *master, void *
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
struct hda_component_parent *parent = master_data;
struct hda_component *comp;
- unsigned int sleep_flags;
comp = hda_component_from_index(parent, cs35l41->index);
if (!comp)
return;
if (comp->dev == dev) {
- sleep_flags = lock_system_sleep();
device_link_remove(&cs35l41->codec->core.dev, cs35l41->dev);
- unlock_system_sleep(sleep_flags);
memset(comp, 0, sizeof(*comp));
cs35l41_remove_controls(cs35l41);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 2/8] ASoC: cs35l41: Prevent software reset when using SPI
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 ` 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
` (5 subsequent siblings)
7 siblings, 1 reply; 10+ messages in thread
From: Stefan Binding @ 2026-12-03 14:13 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, patches, Stefan Binding
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 try to 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
Fixes: 9bfbc1af0713 ("ALSA: hda: cs35l41: Add common wait_for_boot api and reset_and_boot api")
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
sound/soc/codecs/cs35l41-lib.c | 50 ++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 14 deletions(-)
diff --git a/sound/soc/codecs/cs35l41-lib.c b/sound/soc/codecs/cs35l41-lib.c
index 9e6bed22fbdb..e11810795ee8 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,36 @@ 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
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v3 2/8] ASoC: cs35l41: Prevent software reset when using SPI
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
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-03 14:55 UTC (permalink / raw)
To: Stefan Binding; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: cs35l41: cs35l41_reset_and_boot() skips SPI reset on
unload/rebind
- [Low] ASoC: cs35l41: dev_err() called with NULL dev in
cs35l41_is_spi_regmap()
- [Low] ASoC: cs35l41: Fixes tag cites refactor instead of introducing
commits
--
commit 1cc179574843ec0efb1395f06726b215379a855a
Author: Stefan Binding <sbinding@opensource.cirrus.com>
> ASoC: cs35l41: Prevent software reset when using SPI
>
> 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 try to 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
> Fixes: 9bfbc1af0713 ("ALSA: hda: cs35l41: Add common wait_for_boot api and reset_and_boot api")
>
> Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
[Severity: Low]
Should the Fixes tag cite the commits that originally introduced the
software reset on SPI rather than the refactor 9bfbc1af0713 ("ALSA:
hda: cs35l41: Add common wait_for_boot api and reset_and_boot api")?
Commit 2ee06ff5d7cf ("ALSA: hda: cs35l41: Force a software reset after
hardware reset") added the HDA software reset and commit a04a1a820f37
("ASoC: cs35l41: Use common wait_for_boot and reset_and_boot apis")
brought it to ASoC. Citing only the refactor hides older stable trees:
Fixes: 2ee06ff5d7cf ("ALSA: hda: cs35l41: Force a software reset after hardware reset")
Fixes: a04a1a820f37 ("ASoC: cs35l41: Use common wait_for_boot and reset_and_boot apis")
> diff --git a/sound/soc/codecs/cs35l41-lib.c b/sound/soc/codecs/cs35l41-lib.c
> index 9e6bed22fbdb5..e11810795ee86 100644
> --- a/sound/soc/codecs/cs35l41-lib.c
> +++ b/sound/soc/codecs/cs35l41-lib.c
[ ... ]
> @@ -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);
> +}
[Severity: Low]
Is passing dev to dev_err() inside the if (!dev) branch intentional?
__dev_printk() guards against NULL and logs "(NULL device *)", so this
won't crash, but it drops device context. Since cs35l41_reset_and_boot()
already receives struct device *dev, this helper could check that dev
directly and drop the regmap_get_device() lookup and error path.
[ ... ]
> @@ -1627,27 +1640,36 @@ 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 {
[Severity: Medium]
As reported by Mark Brown on v2 [1], what happens on driver unload/reload
or unbind/rebind for an SPI amplifier without an owned reset GPIO?
cs35l41_probe() gets reset_gpio with devm_gpiod_get_optional() (clearing
it on -EBUSY for shared resets), and HDA secondary shared-reset amps also
probe with reset_gpio set to NULL. Neither remove path issues an SPI
software reset, so re-probing now skips CS35L41_SFT_RESET altogether.
That leaves hardware in its prior state while devm_regmap_init_spi()
seeds a fresh REGCACHE_MAPLE cache with defaults, causing cache
divergence on regmap_update_bits() and -ETIMEDOUT in HDA
cs35l41_wait_boot_done() if CS35L41_OTP_BOOT_DONE was already cleared.
Commit "ALSA: hda/cs35l41: Ensure SPI devices are always reset during
system suspend" only handles HDA suspend aborts in
cs35l41_system_suspend(), leaving unload/reload and unbind/rebind
unaddressed.
[1] https://lore.kernel.org/r/179574575897.838304.8691157769089102804.b4-review@b4
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203141359.150688-1-sbinding@opensource.cirrus.com?part=2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 3/8] ALSA: hda: cs35l41: Unset irq if not used or configured
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:13 ` Stefan Binding
2026-12-03 14:13 ` [PATCH v3 4/8] ALSA: hda/cs35l41: Split System Suspend/Resume callbacks Stefan Binding
` (4 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Stefan Binding @ 2026-12-03 14:13 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, patches, Stefan Binding
If the irq is not allocated, or does not exist in ACPI, clear the saved
irq value. This prevents the driver from being able to access an
unconfigured or unused irq later.
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index f6910916ad47..2e2bf231d3fc 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -1633,6 +1633,8 @@ static void cs35l41_configure_interrupt(struct cs35l41_hda *cs35l41, int irq_pol
IRQF_ONESHOT | IRQF_SHARED | irq_pol,
0, &cs35l41_regmap_irq_chip, &cs35l41->irq_data);
if (ret) {
+ /* unset irq if unable to be used */
+ cs35l41->irq = 0;
dev_dbg(cs35l41->dev, "Unable to add IRQ Chip: %d.", ret);
goto err;
}
@@ -1712,6 +1714,9 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41)
if (using_irq)
cs35l41_configure_interrupt(cs35l41, irq_pol);
+ else
+ /* Unset irq if not used */
+ cs35l41->irq = 0;
return cs35l41_hda_channel_map(cs35l41);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 4/8] ALSA: hda/cs35l41: Split System Suspend/Resume callbacks
2026-12-03 14:13 [PATCH v3 0/8] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
` (2 preceding siblings ...)
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 ` Stefan Binding
2026-12-03 14:13 ` [PATCH v3 5/8] ALSA: hda/cs35l41: Remove support for alternative firmware types Stefan Binding
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Stefan Binding @ 2026-12-03 14:13 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, patches, Stefan Binding
Currently, the CS35L41 driver does most of its system suspend and
resume functions inside single suspend and resume callbacks.
Ensure IRQs are correctly disabled and enabled at the right times
during the System Suspend and Resume process, to ensure we don't get
spurious interrupts which cause issues.
Additionally, move the GPIO reset into the .resume_early() callback to
ensure both amps are reset first, before the .resume() callback is
called for each amp, in the case where there is a shared reset.
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 101 ++++++++++++++++++---
1 file changed, 88 insertions(+), 13 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index 2e2bf231d3fc..b30f000dab71 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -942,18 +942,27 @@ static int cs35l41_system_suspend(struct device *dev)
dev_dbg(cs35l41->dev, "System Suspend\n");
- if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) {
- dev_err_once(cs35l41->dev, "System Suspend not supported\n");
+ if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH)
return 0; /* don't block the whole system suspend */
- }
scoped_guard(mutex, &cs35l41->fw_mutex) {
if (cs35l41->playback_started)
cs35l41_hda_pause_done(dev);
}
+ /*
+ * The interrupt line is normally shared, but after we start suspending
+ * we can't check if our device is the source of an interrupt, and can't
+ * clear it. Prevent this race by temporarily disabling the parent irq
+ * until we reach _noirq.
+ */
+ if (cs35l41->irq)
+ disable_irq(cs35l41->irq);
+
ret = pm_runtime_force_suspend(dev);
if (ret) {
+ if (cs35l41->irq)
+ enable_irq(cs35l41->irq);
dev_err(dev, "System Suspend Failed, unable to runtime suspend: %d\n", ret);
return ret;
}
@@ -963,46 +972,110 @@ static int cs35l41_system_suspend(struct device *dev)
if (ret)
dev_err(dev, "System Suspend Failed, not ready for Reset: %d\n", ret);
+ dev_dbg(cs35l41->dev, "System Suspended\n");
+
+ return ret;
+}
+
+static int cs35l41_system_suspend_late(struct device *dev)
+{
+ struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
+
+ if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH)
+ return 0; /* don't block the whole system suspend */
+
+ /*
+ * RESET is usually shared by all amps so it must not be asserted until
+ * all driver instances have done their suspend() stage.
+ */
if (cs35l41->reset_gpio) {
dev_info(cs35l41->dev, "Asserting Reset\n");
gpiod_set_value_cansleep(cs35l41->reset_gpio, 0);
usleep_range(2000, 2100);
}
- dev_dbg(cs35l41->dev, "System Suspended\n");
-
- return ret;
+ return 0;
}
-static int cs35l41_system_resume(struct device *dev)
+static int cs35l41_system_suspend_noirq(struct device *dev)
{
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
- int ret;
- dev_dbg(cs35l41->dev, "System Resume\n");
+ if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH)
+ return 0; /* don't block the whole system suspend */
+
+ /* Handlers are now disabled so the parent IRQ can safely be re-enabled. */
+ if (cs35l41->irq)
+ enable_irq(cs35l41->irq);
+
+ return 0;
+}
+
+static int cs35l41_system_resume_noirq(struct device *dev)
+{
+ struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) {
dev_err_once(cs35l41->dev, "System Resume not supported\n");
return 0; /* don't block the whole system resume */
}
+ /*
+ * WAKE interrupts unmask if the CS35L41 resets, which can cause
+ * spurious interrupts, and the interrupt line is normally shared.
+ * We can't check if our device is the source of an interrupt, and can't
+ * clear it, until it has fully resumed. Prevent this race by temporarily
+ * disabling the parent irq until we complete resume().
+ */
+ if (cs35l41->irq)
+ disable_irq(cs35l41->irq);
+
+ return 0;
+}
+
+static int cs35l41_system_resume_early(struct device *dev)
+{
+ struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
+
+ if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH)
+ return 0; /* don't block the whole system resume */
+
if (cs35l41->reset_gpio) {
+ dev_info(cs35l41->dev, "Deasserting Reset\n");
gpiod_set_value_cansleep(cs35l41->reset_gpio, 0);
usleep_range(2000, 2100);
gpiod_set_value_cansleep(cs35l41->reset_gpio, 1);
+ usleep_range(2000, 2100);
}
- usleep_range(2000, 2100);
+ return 0;
+}
+
+static int cs35l41_system_resume(struct device *dev)
+{
+ struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
+ int ret;
+
+ dev_dbg(cs35l41->dev, "System Resume\n");
+
+ if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH)
+ return 0; /* don't block the whole system resume */
regcache_cache_only(cs35l41->regmap, false);
ret = cs35l41_reset_and_boot(cs35l41->dev, cs35l41->regmap);
- if (ret)
- return ret;
regcache_cache_only(cs35l41->regmap, true);
+ if (ret) {
+ dev_err(cs35l41->dev, "System Resume Failed: Boot Failed: %d\n", ret);
+ if (cs35l41->irq)
+ enable_irq(cs35l41->irq);
+ return ret;
+ }
ret = pm_runtime_force_resume(dev);
+ if (cs35l41->irq)
+ enable_irq(cs35l41->irq);
if (ret) {
dev_err(dev, "System Resume Failed: Unable to runtime resume: %d\n", ret);
return ret;
@@ -1015,7 +1088,7 @@ static int cs35l41_system_resume(struct device *dev)
schedule_work(&cs35l41->fw_load_work);
}
- return ret;
+ return 0;
}
static int cs35l41_runtime_idle(struct device *dev)
@@ -2083,6 +2156,8 @@ const struct dev_pm_ops cs35l41_hda_pm_ops = {
cs35l41_runtime_idle)
.prepare = cs35l41_system_suspend_prep,
SYSTEM_SLEEP_PM_OPS(cs35l41_system_suspend, cs35l41_system_resume)
+ LATE_SYSTEM_SLEEP_PM_OPS(cs35l41_system_suspend_late, cs35l41_system_resume_early)
+ NOIRQ_SYSTEM_SLEEP_PM_OPS(cs35l41_system_suspend_noirq, cs35l41_system_resume_noirq)
};
EXPORT_SYMBOL_NS_GPL(cs35l41_hda_pm_ops, "SND_HDA_SCODEC_CS35L41");
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 5/8] ALSA: hda/cs35l41: Remove support for alternative firmware types
2026-12-03 14:13 [PATCH v3 0/8] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
` (3 preceding siblings ...)
2026-12-03 14:13 ` [PATCH v3 4/8] ALSA: hda/cs35l41: Split System Suspend/Resume callbacks Stefan Binding
@ 2026-12-03 14:13 ` Stefan Binding
2026-12-03 14:13 ` [PATCH v3 6/8] ALSA: hda/cs35l41: Store filenames of successfully loaded firmware and tunings Stefan Binding
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Stefan Binding @ 2026-12-03 14:13 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, patches, Stefan Binding
Originally the driver has support for loading alternative firmware
types. However, whilst it could load alternative types, only speaker
protection was ever actually supported in the driver.
Remove this support to ensure that the firmware type is fixed.
This is preparing the driver to make proper use of firmware caching in
later commits.
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 86 ++--------------------
sound/hda/codecs/side-codecs/cs35l41_hda.h | 2 -
2 files changed, 8 insertions(+), 80 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index b30f000dab71..2c6efd07df80 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -37,6 +37,7 @@
#define CS35L41_DSM_GET_MUTE 5
#define CS35L41_NOTIFY_EVENT 0x91
#define CS35L41_TUNING_SIG 0x109A4A35
+#define CS35L41_HDA_FW_ID "spk-prot"
enum cs35l41_tuning_param_types {
TUNING_PARAM_GAIN,
@@ -73,21 +74,6 @@ static const struct cirrus_amp_cal_controls cs35l41_calibration_controls = {
.checksum = CAL_CHECKSUM_DSP_CTL_NAME,
};
-enum cs35l41_hda_fw_id {
- CS35L41_HDA_FW_SPK_PROT,
- CS35L41_HDA_FW_SPK_CALI,
- CS35L41_HDA_FW_SPK_DIAG,
- CS35L41_HDA_FW_MISC,
- CS35L41_HDA_NUM_FW
-};
-
-static const char * const cs35l41_hda_fw_ids[CS35L41_HDA_NUM_FW] = {
- [CS35L41_HDA_FW_SPK_PROT] = "spk-prot",
- [CS35L41_HDA_FW_SPK_CALI] = "spk-cali",
- [CS35L41_HDA_FW_SPK_DIAG] = "spk-diag",
- [CS35L41_HDA_FW_MISC] = "misc",
-};
-
static bool firmware_autostart = 1;
module_param(firmware_autostart, bool, 0444);
MODULE_PARM_DESC(firmware_autostart, "Allow automatic firmware download on boot"
@@ -173,24 +159,19 @@ static int cs35l41_request_firmware_file(struct cs35l41_hda *cs35l41,
*firmware = NULL;
if (spkid > -1 && ssid && amp_name)
*filename = kasprintf(GFP_KERNEL, "cirrus/%s-%s-%s-%s-spkid%d-%s.%s", CS35L41_PART,
- dsp_name, cs35l41_hda_fw_ids[cs35l41->firmware_type],
- ssid, spkid, amp_name, filetype);
+ dsp_name, CS35L41_HDA_FW_ID, ssid, spkid, amp_name, filetype);
else if (spkid > -1 && ssid)
*filename = kasprintf(GFP_KERNEL, "cirrus/%s-%s-%s-%s-spkid%d.%s", CS35L41_PART,
- dsp_name, cs35l41_hda_fw_ids[cs35l41->firmware_type],
- ssid, spkid, filetype);
+ dsp_name, CS35L41_HDA_FW_ID, ssid, spkid, filetype);
else if (ssid && amp_name)
*filename = kasprintf(GFP_KERNEL, "cirrus/%s-%s-%s-%s-%s.%s", CS35L41_PART,
- dsp_name, cs35l41_hda_fw_ids[cs35l41->firmware_type],
- ssid, amp_name, filetype);
+ dsp_name, CS35L41_HDA_FW_ID, ssid, amp_name, filetype);
else if (ssid)
*filename = kasprintf(GFP_KERNEL, "cirrus/%s-%s-%s-%s.%s", CS35L41_PART,
- dsp_name, cs35l41_hda_fw_ids[cs35l41->firmware_type],
- ssid, filetype);
+ dsp_name, CS35L41_HDA_FW_ID, ssid, filetype);
else
*filename = kasprintf(GFP_KERNEL, "cirrus/%s-%s-%s.%s", CS35L41_PART,
- dsp_name, cs35l41_hda_fw_ids[cs35l41->firmware_type],
- filetype);
+ dsp_name, CS35L41_HDA_FW_ID, filetype);
if (*filename == NULL)
return -ENOMEM;
@@ -589,7 +570,7 @@ static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41)
}
ret = cs_dsp_power_up(dsp, wmfw_firmware, wmfw_filename, coeff_firmware, coeff_filename,
- cs35l41_hda_fw_ids[cs35l41->firmware_type]);
+ CS35L41_HDA_FW_ID);
if (ret) {
cs35l41_set_default_tuning_params(cs35l41);
return ret;
@@ -1248,7 +1229,7 @@ static int cs35l41_smart_amp(struct cs35l41_hda *cs35l41)
}
dev_info(cs35l41->dev, "Firmware Loaded - Type: %s, Gain: %d\n",
- cs35l41_hda_fw_ids[cs35l41->firmware_type], cs35l41->tuning_gain);
+ CS35L41_HDA_FW_ID, cs35l41->tuning_gain);
return 0;
@@ -1330,38 +1311,6 @@ static int cs35l41_fw_load_ctl_put(struct snd_kcontrol *kcontrol,
return 1;
}
-static int cs35l41_fw_type_ctl_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
-{
- struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol);
-
- ucontrol->value.enumerated.item[0] = cs35l41->firmware_type;
-
- return 0;
-}
-
-static int cs35l41_fw_type_ctl_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
-{
- struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol);
-
- if (ucontrol->value.enumerated.item[0] < CS35L41_HDA_NUM_FW) {
- if (cs35l41->firmware_type != ucontrol->value.enumerated.item[0]) {
- cs35l41->firmware_type = ucontrol->value.enumerated.item[0];
- return 1;
- } else {
- return 0;
- }
- }
-
- return -EINVAL;
-}
-
-static int cs35l41_fw_type_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
- return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(cs35l41_hda_fw_ids), cs35l41_hda_fw_ids);
-}
-
static void cs35l41_remove_controls(struct cs35l41_hda *cs35l41)
{
if (!cs35l41->codec)
@@ -1372,9 +1321,6 @@ static void cs35l41_remove_controls(struct cs35l41_hda *cs35l41)
snd_ctl_remove(cs35l41->codec->card, cs35l41->fw_load_ctl);
cs35l41->fw_load_ctl = NULL;
-
- snd_ctl_remove(cs35l41->codec->card, cs35l41->fw_type_ctl);
- cs35l41->fw_type_ctl = NULL;
}
static int cs35l41_add_control(struct cs35l41_hda *cs35l41,
@@ -1401,16 +1347,8 @@ static int cs35l41_add_control(struct cs35l41_hda *cs35l41,
static int cs35l41_create_controls(struct cs35l41_hda *cs35l41)
{
- char fw_type_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
char fw_load_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
char mute_override_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
- struct snd_kcontrol_new fw_type_ctl = {
- .name = fw_type_ctl_name,
- .iface = SNDRV_CTL_ELEM_IFACE_CARD,
- .info = cs35l41_fw_type_ctl_info,
- .get = cs35l41_fw_type_ctl_get,
- .put = cs35l41_fw_type_ctl_put,
- };
struct snd_kcontrol_new fw_load_ctl = {
.name = fw_load_ctl_name,
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
@@ -1427,17 +1365,11 @@ static int cs35l41_create_controls(struct cs35l41_hda *cs35l41)
};
int ret;
- scnprintf(fw_type_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s DSP1 Firmware Type",
- cs35l41->amp_name);
scnprintf(fw_load_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s DSP1 Firmware Load",
cs35l41->amp_name);
scnprintf(mute_override_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s Forced Mute Status",
cs35l41->amp_name);
- ret = cs35l41_add_control(cs35l41, &fw_type_ctl, &cs35l41->fw_type_ctl);
- if (ret)
- goto err;
-
ret = cs35l41_add_control(cs35l41, &fw_load_ctl, &cs35l41->fw_load_ctl);
if (ret)
goto err;
@@ -1537,8 +1469,6 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
strscpy(comp->name, dev_name(dev), sizeof(comp->name));
- cs35l41->firmware_type = CS35L41_HDA_FW_SPK_PROT;
-
if (firmware_autostart) {
dev_dbg(cs35l41->dev, "Firmware Autostart.\n");
cs35l41->request_fw_load = true;
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.h b/sound/hda/codecs/side-codecs/cs35l41_hda.h
index 56ec07c0bb74..6fea4b2ad0ac 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.h
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.h
@@ -73,11 +73,9 @@ struct cs35l41_hda {
unsigned volatile long irq_errors;
const char *amp_name;
const char *acpi_subsystem_id;
- int firmware_type;
int speaker_id;
struct mutex fw_mutex;
struct work_struct fw_load_work;
- struct snd_kcontrol *fw_type_ctl;
struct snd_kcontrol *fw_load_ctl;
struct snd_kcontrol *mute_override_ctl;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 6/8] ALSA: hda/cs35l41: Store filenames of successfully loaded firmware and tunings
2026-12-03 14:13 [PATCH v3 0/8] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
` (4 preceding siblings ...)
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 ` 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 ` [PATCH v3 8/8] ALSA: hda/cs35l41: Ensure SPI devices are always reset during system suspend Stefan Binding
7 siblings, 0 replies; 10+ messages in thread
From: Stefan Binding @ 2026-12-03 14:13 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, patches, Stefan Binding
When the CS35L41 HDA driver loads firmware, it typically loops through
possible filenames, requesting each and stopping when it finds a valid
file.
Since firmware is sometimes reloaded - such as during system resume,
it loops through the possible filenames each time. However, since the
filename will never change, we can store the filename when we
successfully load the firmware for the first time, and reuse it later.
This ensures that the only firmware files requested by the driver in
system resume are the same as the ones cached during suspend, since
only successfully requested firmware files are cached. This prevents
unnecessary file access during resume - if a cached firmware is
requested, the cached file is used, eliminating any potential blocking
calls to the filesystem.
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 47 +++++++++++++++++-----
sound/hda/codecs/side-codecs/cs35l41_hda.h | 3 ++
2 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index 2c6efd07df80..51ac11270c88 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -142,6 +142,7 @@ static int cs35l41_request_tuning_param_file(struct cs35l41_hda *cs35l41, char *
dev_dbg(cs35l41->dev, "Failed to request '%s'\n", *filename);
kfree(*filename);
*filename = NULL;
+ cs35l41->skip_tuning_params = true;
}
return ret;
@@ -308,6 +309,7 @@ static int cs35l41_fallback_firmware_file(struct cs35l41_hda *cs35l41,
if (ret) {
release_firmware(*wmfw_firmware);
kfree(*wmfw_filename);
+ *wmfw_filename = NULL;
goto err;
}
return 0;
@@ -325,6 +327,25 @@ static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
{
int ret;
+ if (*wmfw_filename) {
+ ret = firmware_request_nowarn(wmfw_firmware, *wmfw_filename, cs35l41->dev);
+ if (ret != 0) {
+ dev_err(cs35l41->dev, "Failed to request known file '%s'\n",
+ *wmfw_filename);
+ return ret;
+ }
+ if (*coeff_filename) {
+ ret = firmware_request_nowarn(coeff_firmware, *coeff_filename,
+ cs35l41->dev);
+ if (ret != 0) {
+ dev_err(cs35l41->dev, "Failed to request known file '%s'\n",
+ *coeff_filename);
+ return ret;
+ }
+ }
+ return 0;
+ }
+
if (cs35l41->speaker_id > -1) {
ret = cs35l41_request_firmware_files_spkid(cs35l41, wmfw_firmware, wmfw_filename,
coeff_firmware, coeff_filename);
@@ -374,6 +395,7 @@ static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
coeff_err:
release_firmware(*wmfw_firmware);
kfree(*wmfw_filename);
+ *wmfw_filename = NULL;
fallback:
return cs35l41_fallback_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
coeff_firmware, coeff_filename);
@@ -514,6 +536,9 @@ static int cs35l41_load_tuning_params(struct cs35l41_hda *cs35l41, char *tuning_
char *tuning_param_filename __free(kfree) = NULL;
int ret;
+ if (cs35l41->skip_tuning_params)
+ return 0;
+
ret = cs35l41_request_tuning_param_file(cs35l41, tuning_filename, &tuning_param_file,
&tuning_param_filename, cs35l41->acpi_subsystem_id);
if (ret) {
@@ -538,8 +563,6 @@ static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41)
const struct firmware *coeff_firmware __free(firmware) = NULL;
const struct firmware *wmfw_firmware __free(firmware) = NULL;
struct cs_dsp *dsp = &cs35l41->cs_dsp;
- char *coeff_filename __free(kfree) = NULL;
- char *wmfw_filename __free(kfree) = NULL;
int ret;
if (!cs35l41->halo_initialized) {
@@ -554,23 +577,23 @@ static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41)
cs35l41_set_default_tuning_params(cs35l41);
- ret = cs35l41_request_firmware_files(cs35l41, &wmfw_firmware, &wmfw_filename,
- &coeff_firmware, &coeff_filename);
+ ret = cs35l41_request_firmware_files(cs35l41, &wmfw_firmware, &cs35l41->wmfw_filename,
+ &coeff_firmware, &cs35l41->coeff_filename);
if (ret < 0)
return ret;
- dev_dbg(cs35l41->dev, "Loading WMFW Firmware: %s\n", wmfw_filename);
- if (coeff_filename) {
- dev_dbg(cs35l41->dev, "Loading Coefficient File: %s\n", coeff_filename);
- ret = cs35l41_load_tuning_params(cs35l41, coeff_filename);
+ dev_dbg(cs35l41->dev, "Loading WMFW Firmware: %s\n", cs35l41->wmfw_filename);
+ if (cs35l41->coeff_filename) {
+ dev_dbg(cs35l41->dev, "Loading Coefficient File: %s\n", cs35l41->coeff_filename);
+ ret = cs35l41_load_tuning_params(cs35l41, cs35l41->coeff_filename);
if (ret)
dev_warn(cs35l41->dev, "Unable to load Tuning Parameters: %d\n", ret);
} else {
dev_warn(cs35l41->dev, "No Coefficient File available.\n");
}
- ret = cs_dsp_power_up(dsp, wmfw_firmware, wmfw_filename, coeff_firmware, coeff_filename,
- CS35L41_HDA_FW_ID);
+ ret = cs_dsp_power_up(dsp, wmfw_firmware, cs35l41->wmfw_filename, coeff_firmware,
+ cs35l41->coeff_filename, CS35L41_HDA_FW_ID);
if (ret) {
cs35l41_set_default_tuning_params(cs35l41);
return ret;
@@ -600,6 +623,10 @@ static void cs35l41_remove_dsp(struct cs35l41_hda *cs35l41)
cs35l41_shutdown_dsp(cs35l41);
cs_dsp_remove(dsp);
cs35l41->halo_initialized = false;
+ kfree(cs35l41->wmfw_filename);
+ kfree(cs35l41->coeff_filename);
+ cs35l41->wmfw_filename = NULL;
+ cs35l41->coeff_filename = NULL;
}
/* Protection release cycle to get the speaker out of Safe-Mode */
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.h b/sound/hda/codecs/side-codecs/cs35l41_hda.h
index 6fea4b2ad0ac..64ee70c31a43 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.h
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.h
@@ -93,7 +93,10 @@ struct cs35l41_hda {
unsigned int tuning_gain;
struct cirrus_amp_cal_data cal_data;
bool cal_data_valid;
+ bool skip_tuning_params;
+ char *coeff_filename;
+ char *wmfw_filename;
};
enum halo_state {
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 7/8] ALSA: hda/cs35l41: rework how firmware requests are queued and flushed to prevent races
2026-12-03 14:13 [PATCH v3 0/8] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
` (5 preceding siblings ...)
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 ` Stefan Binding
2026-12-03 14:13 ` [PATCH v3 8/8] ALSA: hda/cs35l41: Ensure SPI devices are always reset during system suspend Stefan Binding
7 siblings, 0 replies; 10+ messages in thread
From: Stefan Binding @ 2026-12-03 14:13 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, patches, Stefan Binding
Currently, in a small number of scenarios, the firmware on CS35L41 can
be reloaded:
- Using an ALSA control
- System Resume
- After Playback (after System Resume - if reload has not occurred)
In all these cases, the reload is done inside a work item and
scheduled on the default workqueue.
This should instead be queued on the system_freezable_wq, which ensures
that the work item is handled correctly during system suspend, where it
is not allowed to start whilst the workqueue is frozen.
There are 3 main scenarios where we need to ensure firmware load work
is flushed:
- Before System Suspend
- Before first playback after System Resume
- Error Paths
Register the driver for PM Notifications so that it can correctly flush
before suspending. Ensure any firmware work is either cancelled (if
pending) or flushed in the PM_*_PREPARE notification callbacks.
This ensures that the work item completes before any workqueues are
frozen. If the firmware load work item is still running when the
workqueue is frozen, then it would ordinarily be flushed, but may hang
on waiting for filesystem access in a call to request_firmware(), if
filesystem access requires work in a freezable workqueue itself.
Additionally, ensure that we flush the work before we start playback
after system resume. This ensures firmware is loaded before we restart
any playback after system suspend.
We also need to re-queue the firmware load in the PM_POST_* notifiers,
if the suspend was aborted before we finished suspending, but after
the PM_*_PREPARE notifier cancelled a pending firmware load.
Fixes: 88672826e2a4 ("ALSA: hda: cs35l41: Support System Suspend")
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 144 +++++++++++++++++----
sound/hda/codecs/side-codecs/cs35l41_hda.h | 2 +
2 files changed, 122 insertions(+), 24 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index 51ac11270c88..e6ab53d5ba3a 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -12,6 +12,7 @@
#include <sound/hda_codec.h>
#include <sound/soc.h>
#include <linux/pm_runtime.h>
+#include <linux/suspend.h>
#include <linux/spi/spi.h>
#include <linux/vmalloc.h>
#include "hda_local.h"
@@ -603,13 +604,52 @@ static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41)
return 0;
}
+static void cs35l41_fw_load_request_unlocked(struct cs35l41_hda *cs35l41)
+{
+ /* firmware request is pending */
+ if (cs35l41->fw_request_ongoing)
+ return;
+
+ /* no need to request firmware load if DSP running state matches request */
+ if (cs35l41->cs_dsp.running == cs35l41->request_fw_load)
+ return;
+
+ /* block firmware load request if suspending */
+ if (cs35l41->suspending)
+ return;
+
+ cs35l41->fw_request_ongoing = queue_work(system_freezable_wq, &cs35l41->fw_load_work);
+}
+
+static void cs35l41_fw_load_request(struct cs35l41_hda *cs35l41)
+{
+ guard(mutex)(&cs35l41->fw_mutex);
+
+ cs35l41_fw_load_request_unlocked(cs35l41);
+}
+
+static void cs35l41_fw_load_cancel_sync(struct cs35l41_hda *cs35l41)
+{
+ cancel_work_sync(&cs35l41->fw_load_work);
+
+ guard(mutex)(&cs35l41->fw_mutex);
+ cs35l41->fw_request_ongoing = false;
+}
+
static void cs35l41_shutdown_dsp(struct cs35l41_hda *cs35l41)
{
struct cs_dsp *dsp = &cs35l41->cs_dsp;
+ if (!cs35l41->halo_initialized)
+ return;
+
cs35l41_set_default_tuning_params(cs35l41);
- cs_dsp_stop(dsp);
+
+ if (cs35l41->cs_dsp.running)
+ cs_dsp_stop(dsp);
+
cs_dsp_power_down(dsp);
+
dev_dbg(cs35l41->dev, "Unloaded Firmware\n");
}
@@ -617,7 +657,7 @@ static void cs35l41_remove_dsp(struct cs35l41_hda *cs35l41)
{
struct cs_dsp *dsp = &cs35l41->cs_dsp;
- cancel_work_sync(&cs35l41->fw_load_work);
+ cs35l41_fw_load_cancel_sync(cs35l41);
guard(mutex)(&cs35l41->fw_mutex);
cs35l41_shutdown_dsp(cs35l41);
@@ -811,6 +851,7 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
pm_runtime_get_sync(dev);
break;
case HDA_GEN_PCM_ACT_PREPARE:
+ flush_work(&cs35l41->fw_load_work);
scoped_guard(mutex, &cs35l41->fw_mutex) {
cs35l41_hda_play_start(dev);
}
@@ -821,14 +862,7 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
}
break;
case HDA_GEN_PCM_ACT_CLOSE:
- scoped_guard(mutex, &cs35l41->fw_mutex) {
- if (!cs35l41->cs_dsp.running && cs35l41->request_fw_load &&
- !cs35l41->fw_request_ongoing) {
- dev_info(dev, "Requesting Firmware Load after HDA_GEN_PCM_ACT_CLOSE\n");
- cs35l41->fw_request_ongoing = true;
- schedule_work(&cs35l41->fw_load_work);
- }
- }
+ cs35l41_fw_load_request(cs35l41);
/*
* Playback must be finished for all amps before we start runtime suspend.
@@ -925,6 +959,45 @@ static int cs35l41_ready_for_reset(struct cs35l41_hda *cs35l41)
return 0;
}
+static void cs35l41_set_suspending(struct cs35l41_hda *cs35l41, bool suspending)
+{
+ guard(mutex)(&cs35l41->fw_mutex);
+
+ cs35l41->suspending = suspending;
+}
+
+static int cs35l41_hda_pm_notifier(struct notifier_block *nb, unsigned long action, void *data)
+{
+ struct cs35l41_hda *cs35l41 = container_of(nb, struct cs35l41_hda, pm_notifier);
+
+ dev_dbg(cs35l41->dev, "PM notifier action: %lu\n", action);
+
+ switch (action) {
+ case PM_HIBERNATION_PREPARE:
+ case PM_SUSPEND_PREPARE:
+ case PM_RESTORE_PREPARE:
+ cs35l41_set_suspending(cs35l41, true);
+ cs35l41_fw_load_cancel_sync(cs35l41);
+ break;
+ case PM_POST_HIBERNATION:
+ case PM_POST_SUSPEND:
+ case PM_POST_RESTORE:
+ /*
+ * If suspending is still set, we are in the recovery path - reload firmware
+ * after failed suspend
+ */
+ if (cs35l41->suspending) {
+ cs35l41_set_suspending(cs35l41, false);
+ cs35l41_fw_load_request(cs35l41);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return NOTIFY_DONE;
+}
+
static int cs35l41_system_suspend_prep(struct device *dev)
{
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
@@ -981,6 +1054,7 @@ static int cs35l41_system_suspend(struct device *dev)
dev_err(dev, "System Suspend Failed, not ready for Reset: %d\n", ret);
dev_dbg(cs35l41->dev, "System Suspended\n");
+ cs35l41_set_suspending(cs35l41, false);
return ret;
}
@@ -1089,12 +1163,7 @@ static int cs35l41_system_resume(struct device *dev)
return ret;
}
- guard(mutex)(&cs35l41->fw_mutex);
-
- if (cs35l41->request_fw_load && !cs35l41->fw_request_ongoing) {
- cs35l41->fw_request_ongoing = true;
- schedule_work(&cs35l41->fw_load_work);
- }
+ cs35l41_fw_load_request(cs35l41);
return 0;
}
@@ -1331,9 +1400,11 @@ static int cs35l41_fw_load_ctl_put(struct snd_kcontrol *kcontrol,
return -EBUSY;
}
- cs35l41->fw_request_ongoing = true;
+ guard(mutex)(&cs35l41->fw_mutex);
+
cs35l41->request_fw_load = ucontrol->value.integer.value[0];
- schedule_work(&cs35l41->fw_load_work);
+
+ cs35l41_fw_load_request_unlocked(cs35l41);
return 1;
}
@@ -1475,7 +1546,7 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
struct hda_component_parent *parent = master_data;
struct hda_component *comp;
- int ret = 0;
+ int ret;
comp = hda_component_from_index(parent, cs35l41->index);
if (!comp)
@@ -1505,8 +1576,6 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
dev_dbg(cs35l41->dev, "Firmware Autostart is disabled.\n");
}
- ret = cs35l41_create_controls(cs35l41);
-
comp->playback_hook = cs35l41_hda_playback_hook;
comp->pre_playback_hook = cs35l41_hda_pre_playback_hook;
comp->post_playback_hook = cs35l41_hda_post_playback_hook;
@@ -1521,9 +1590,18 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
mutex_unlock(&cs35l41->fw_mutex);
+ /* Create the necessary controls, do not create them under fw_mutex */
+ ret = cs35l41_create_controls(cs35l41);
+ if (ret) {
+ dev_err(cs35l41->dev, "Failed to create controls: %d\n", ret);
+ goto err;
+ }
+
if (!device_link_add(&cs35l41->codec->core.dev, cs35l41->dev, DL_FLAG_STATELESS))
dev_warn(dev, "Unable to create device link\n");
+ register_pm_notifier(&cs35l41->pm_notifier);
+
dev_info(cs35l41->dev,
"CS35L41 Bound - SSID: %s, BST: %d, VSPK: %d, CH: %c, FW EN: %d, SPKID: %d\n",
cs35l41->acpi_subsystem_id, cs35l41->hw_cfg.bst_type,
@@ -1531,6 +1609,16 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
channel_name[cs35l41->hw_cfg.spk_pos],
cs35l41->cs_dsp.running, cs35l41->speaker_id);
+ return 0;
+err:
+ memset(comp, 0, sizeof(*comp));
+ cs35l41_fw_load_cancel_sync(cs35l41);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ cs35l41->request_fw_load = false;
+ cs35l41_shutdown_dsp(cs35l41);
+ }
+ cs35l41->codec = NULL;
+
return ret;
}
@@ -1545,11 +1633,18 @@ static void cs35l41_hda_unbind(struct device *dev, struct device *master, void *
return;
if (comp->dev == dev) {
+ guard(pm_runtime_active_auto)(dev);
+
device_link_remove(&cs35l41->codec->core.dev, cs35l41->dev);
memset(comp, 0, sizeof(*comp));
-
cs35l41_remove_controls(cs35l41);
- cancel_work_sync(&cs35l41->fw_load_work);
+ unregister_pm_notifier(&cs35l41->pm_notifier);
+ cs35l41_fw_load_cancel_sync(cs35l41);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ cs35l41->request_fw_load = false;
+ cs35l41_shutdown_dsp(cs35l41);
+ }
+
cs35l41->codec = NULL;
}
}
@@ -1981,6 +2076,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
cs35l41->irq = irq;
cs35l41->regmap = regmap;
cs35l41->control_bus = control_bus;
+ cs35l41->pm_notifier.notifier_call = cs35l41_hda_pm_notifier;
dev_set_drvdata(dev, cs35l41);
ret = cs35l41_hda_read_acpi(cs35l41, device_name, id);
@@ -2087,7 +2183,7 @@ void cs35l41_hda_remove(struct device *dev)
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
component_del(cs35l41->dev, &cs35l41_hda_comp_ops);
- cancel_work_sync(&cs35l41->fw_load_work);
+ cs35l41_fw_load_cancel_sync(cs35l41);
pm_runtime_get_sync(cs35l41->dev);
pm_runtime_dont_use_autosuspend(cs35l41->dev);
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.h b/sound/hda/codecs/side-codecs/cs35l41_hda.h
index 64ee70c31a43..b374836e8537 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.h
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.h
@@ -78,6 +78,8 @@ struct cs35l41_hda {
struct work_struct fw_load_work;
struct snd_kcontrol *fw_load_ctl;
struct snd_kcontrol *mute_override_ctl;
+ struct notifier_block pm_notifier;
+ bool suspending;
struct regmap_irq_chip_data *irq_data;
bool firmware_running;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 8/8] ALSA: hda/cs35l41: Ensure SPI devices are always reset during system suspend
2026-12-03 14:13 [PATCH v3 0/8] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
` (6 preceding siblings ...)
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
7 siblings, 0 replies; 10+ messages in thread
From: Stefan Binding @ 2026-12-03 14:13 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, patches, Stefan Binding
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
^ permalink raw reply related [flat|nested] 10+ messages in thread