[PATCH v1 4/7] ALSA: hda/cs35l41: Split System Suspend/Resume callbacks

From: Stefan Binding

Date: Fri Nov 20 2026 - 11:12:25 EST


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.

Signed-off-by: Stefan Binding <sbinding@xxxxxxxxxxxxxxxxxxxxx>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 91 ++++++++++++++++++----
1 file changed, 78 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..1a192749c7b0 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -942,10 +942,8 @@ 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)
@@ -963,15 +961,75 @@ static int cs35l41_system_suspend(struct device *dev)
if (ret)
dev_err(dev, "System Suspend Failed, not ready for Reset: %d\n", ret);

+
+ /*
+ * 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);
+
+ 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 0;
+}

- return ret;
+static int cs35l41_system_suspend_noirq(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 */
+
+ /* 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(struct device *dev)
@@ -981,28 +1039,32 @@ static int cs35l41_system_resume(struct device *dev)

dev_dbg(cs35l41->dev, "System Resume\n");

- if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) {
- dev_err_once(cs35l41->dev, "System Resume not supported\n");
+ 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);
-
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 +1077,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 +2145,9 @@ 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, NULL)
+ 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