diff mbox series

[10/10,SRU,M] ASoC: cs35l41: Detect CSPL errors when sending CSPL commands

Message ID 20231122063541.11346-11-chris.chiu@canonical.com
State New
Headers show
Series Fix system suspend problem for Cirrus CS35L41 HDA codec on HP ZBook Fury 16 G9 | expand

Commit Message

Chris Chiu Nov. 22, 2023, 6:35 a.m. UTC
From: Stefan Binding <sbinding@opensource.cirrus.com>

BugLink: https://bugs.launchpad.net/bugs/2042060

The existing code checks for the correct state transition after sending
a command. However, it is possible for the message box to return -1,
which indicates an error, if an error has occurred in the firmware.
We can detect if the error has occurred, and return a different error.
In addition, there is no recovering from a CSPL error, so the retry
mechanism is not needed in this case, and we can return immediately.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20231026150558.2105827-9-sbinding@opensource.cirrus.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 76c121821a3128eb9d0183a525cf334beb9ccc47)
Signed-off-by: Chris Chiu <chris.chiu@canonical.com>
---
 include/sound/cs35l41.h        | 2 ++
 sound/soc/codecs/cs35l41-lib.c | 5 +++++
 2 files changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/include/sound/cs35l41.h b/include/sound/cs35l41.h
index 29fed4e9f33f..b98cef60a277 100644
--- a/include/sound/cs35l41.h
+++ b/include/sound/cs35l41.h
@@ -817,6 +817,8 @@  struct cs35l41_otp_map_element_t {
 };
 
 enum cs35l41_cspl_mbox_status {
+	CSPL_MBOX_STS_ERROR = U32_MAX,
+	CSPL_MBOX_STS_ERROR2 = 0x00ffffff, // firmware not always sign-extending 24-bit value
 	CSPL_MBOX_STS_RUNNING = 0,
 	CSPL_MBOX_STS_PAUSED = 1,
 	CSPL_MBOX_STS_RDY_FOR_REINIT = 2,
diff --git a/sound/soc/codecs/cs35l41-lib.c b/sound/soc/codecs/cs35l41-lib.c
index 60c34ab37395..5dcdc672e5f1 100644
--- a/sound/soc/codecs/cs35l41-lib.c
+++ b/sound/soc/codecs/cs35l41-lib.c
@@ -1460,6 +1460,11 @@  int cs35l41_set_cspl_mbox_cmd(struct device *dev, struct regmap *regmap,
 			continue;
 		}
 
+		if (sts == CSPL_MBOX_STS_ERROR || sts == CSPL_MBOX_STS_ERROR2) {
+			dev_err(dev, "CSPL Error Detected\n");
+			return -EINVAL;
+		}
+
 		if (!cs35l41_check_cspl_mbox_sts(cmd, sts))
 			dev_dbg(dev, "[%u] cmd %u returned invalid sts %u", i, cmd, sts);
 		else