Skip to contentSkip to conversation

soundwire: qcom: wait for the link to stop before gating the clock

PATCH In review Luke Macken 2 participants 2 messages Nov 30 – Dec 1

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 soundwire: qcom: wait for the link to stop before gating the clock

swrm_runtime_suspend() gates hclk after sdw_bus_clk_stop() returns without checking that the frame generator has stopped. On the ThinkPad T14s Gen 7 (v3.1.0 controller) hclk comes from the LPASS WSA macro, and gating it turns off the macro's SoundWire clock. A trace shows that the frame generator can still be enabled when sdw_bus_clk_stop() returns.

On this laptop the speakers sometimes stay silent when playback starts after a runtime suspend. A failure may leave one or both of these in the log:

qcom-soundwire 6c80000.soundwire: qcom_swrm_irq_handler: SWR bus clsh detected wsa884x-codec sdw:1:0:0217:0204:00:1: Parity error detected

Qualcomm's downstream driver sleeps 100 us after ClockStopNow, then on newer controllers polls the link status until the frame generator has stopped [1]. Do the same. If the poll times out, warn and gate the clock anyway.

Before this change playback was silent in 34 out of 120 tries, each after a runtime suspend. With it, playback was never silent and neither message appeared.

---
Changes in v2:
- Shorter commit log and notes, no code change.

Tested on v7.4-rc4 with commit 6c067677192f ("soundwire: qcom: disable the interrupt before gating the clock"), the 7.5 queues (soundwire/next, sound, Qualcomm), two pending submissions for this driver and out-of-tree patches for this laptop.

v1: https://lore.kernel.org/r/[email protected]

 drivers/soundwire/qcom.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/soundwire/qcom.c +28 -0
index a4cb628971..8f3dbb9b16 100644
@@ -915,6 +915,30 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id)
 	return ret;
 }
 
+static void swrm_wait_for_frame_gen_disabled(struct qcom_swrm_ctrl *ctrl)
+{
+	int retry = SWRM_LINK_STATUS_RETRY_CNT;
+	u32 comp_sts;
+
+	/*
+	 * Downstream only checks the link status from v1.6 on, where HCLK
+	 * and MCLK are decoupled.
+	 */
+	if (ctrl->version <= SWRM_VERSION_1_5_1)
+		return;
+
+	do {
+		ctrl->reg_read(ctrl, ctrl->reg_layout[SWRM_REG_FRAME_GEN_ENABLED],
+			       &comp_sts);
+		if (!(comp_sts & SWRM_FRM_GEN_ENABLED))
+			return;
+
+		usleep_range(500, 510);
+	} while (retry--);
+
+	dev_warn_ratelimited(ctrl->dev, "link failed to disconnect\n");
+}
+
 static bool swrm_wait_for_frame_gen_enabled(struct qcom_swrm_ctrl *ctrl)
 {
 	int retry = SWRM_LINK_STATUS_RETRY_CNT;
@@ -1886,6 +1910,10 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev)
 			dev_err(dev, "bus clock stop failed %d", ret);
 			return ret;
 		}
+
+		/* Let the link stop before its clock is gated */
+		usleep_range(100, 105);
+		swrm_wait_for_frame_gen_disabled(ctrl);
 	}
 
 	disable_irq(ctrl->irq);

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244

Signature · 1 line
2.43.0
#1 lore raw
Quoted 9 lines · Luke Macken

swrm_runtime_suspend() gates hclk after sdw_bus_clk_stop() returns without checking that the frame generator has stopped. On the ThinkPad T14s Gen 7 (v3.1.0 controller) hclk comes from the LPASS WSA macro, and gating it turns off the macro's SoundWire clock. A trace shows that the frame generator can still be enabled when sdw_bus_clk_stop() returns.

On this laptop the speakers sometimes stay silent when playback starts after a runtime suspend. A failure may leave one or both of these in the log:

[...]

drivers/soundwire/qcom.c static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) · line 928

Quoted 11 lines
drivers/soundwire/qcom.c +11 -0
+static void swrm_wait_for_frame_gen_disabled(struct qcom_swrm_ctrl *ctrl)
+{
+	int retry = SWRM_LINK_STATUS_RETRY_CNT;
+	u32 comp_sts;
+
+	/*
+	 * Downstream only checks the link status from v1.6 on, where HCLK
+	 * and MCLK are decoupled.
+	 */
+	if (ctrl->version <= SWRM_VERSION_1_5_1)
+		return;

note:

if (!(ctrl->version >= VERSION_1_6)

would be more robust if say v1.5.7 comes around

Konrad