From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.70.43.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795983810; b=tysFYSEF0QyILqPtgzJS00YB8Y+oGnzdrn6GyVcOHpAiRY6xfW33ZgGotmgKmGvujVWy AdH2SZtVWDytuW+pnWvsWsAstZBsqfcTxaDZ6kNUDt663ReAuxE+b9JYeSVpYvwrlbM6x VEnY3vQFIFWSxwbrxFeI2Yqxh1OTbNX7WdbG4TiTAKV2ezQt5kVfD47cqbfjn20fmzCIR NNf3AC1azQNKAEleIbex2BC0v7GGY2NCocWACO3jdx9sx9CD7gw1v1VngV76mX31dIhxO upeB8DBIfgp65UmOQi9UG4fxa4cgUw8PCn7Sl7zqG8u7h4gtQSk6kp/MgOyWyqq7cDg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795983810; h=DMARC-Filter:X-Pm-Submission-Id:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=UC1GmNjSynwcZ+uW0gLGFq80trKvWEjchDqTofxccoY=; b=y11u2GL3mhDTYFH9z8mfzbIrw6ZADMD2YxPoVXLzqXxHfDQLUfcZuPEwzsh/pRuRuJAG HTARV5fIXG/HPQAtbL7quHniwaqea/jrjMp+1njgaXV9Y8Up/bzTkq/RieH8vHQi3N2p7 ymY/bEq4zli8/BIKtw28AOZxEgsz45WMEBfuhBnWv6Gg1GEaP+HXFo9guunK7bwVw+NcB Kb1ucHgCitVSv/cXDq6L5YKhztQlYHD1nrTUuxZKv69OIB60FK+tDGUhOHiV4hFRi4MOV qpq2ESAEknlbFCrje+QjrQyq5D8gSSmuTIs2gNSar6sBb9RrGdM2bxoKQKQ3/+Ge8DQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=phorex.org; spf=pass smtp.mailfrom=phorex.org; arc=none smtp.remote-ip=185.70.43.170 Received: from mail-43170.protonmail.ch (mail-43170.protonmail.ch [185.70.43.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9A22606A32D; Sun, 29 Nov 2026 20:23:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D9A22606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=phorex.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=phorex.org X-Pm-Submission-Id: 4jcz9y6dg5z2Scd2 From: Luke Macken To: srini@kernel.org, vkoul@kernel.org, yung-chuan.liao@linux.intel.com Cc: pierre-louis.bossart@linux.dev, okerixx@gmail.com, gopi.kanala@oss.qualcomm.com, linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Luke Macken Subject: [PATCH] soundwire: qcom: wait for the link to stop before gating the clock Date: Sun, 29 Nov 2026 13:22:58 -0700 Message-ID: <20261129202258.2613829-1-luke@phorex.org> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On a Lenovo ThinkPad T14s Gen 7 (v3.1.0 controller, two WSA884x amplifiers), the speakers are intermittently silent when playback starts after the bus has been in clock stop. The kernel logs "SWR bus clsh detected" and "Parity error detected". This is with commit 6c067677192f ("soundwire: qcom: disable the interrupt before gating the clock") applied. swrm_runtime_suspend() gates hclk right after sdw_bus_clk_stop() returns, without checking that the frame generator has stopped. On this laptop, hclk is the clock output of the LPASS WSA macro. Disabling it clears the macro's SoundWire clock enable, so the bus clock can be taken away while the frame generator is still running. In a trace, the frame generator was still enabled when sdw_bus_clk_stop() returned in 13 of 40 runtime suspends. Qualcomm's downstream driver sleeps 100 us after ClockStopNow. On controller versions above v1.5.1, it then polls the link status until the frame generator is disabled or a retry limit is reached. Only then is the clock released [1]. Do the same; on timeout (about 50 ms) warn and gate the clock anyway. A single read was enough in all 40 traced runtime suspends, so the usual cost is the sleep and one register read. A 2.5 s tone was started every 15 s, each time after a confirmed runtime suspend of the controller. Without this change, 34 of 120 starts were silent. With it, none of 120 were silent and neither message was logged. Link: https://git.codelinaro.org/clo/la/platform/vendor/opensource/audio-kernel/-/blob/5adf8aa04e8f4d987a398c8be3e3d3cfd2feb9f9/soc/swr-mstr-ctrl.c#L2886-2895 # [1] Fixes: 74e79da9fd46 ("soundwire: qcom: add runtime pm support") Assisted-by: LLM Signed-off-by: Luke Macken --- Based on soundwire/fixes. There is no Cc: stable because I have seen this fail only on this laptop, whose devicetree is new in v7.4. Gen 7 tests and trace: v7.4-rc4 + 6c067677192f, soundwire/next, the Qualcomm and sound branches queued for 7.5, the pending patch [2] and series [3], and this laptop's out-of-tree patches (none touches drivers/soundwire or sound/). [2] changes the same function; the two patches do not conflict. In the same test, none of 240 starts were silent with only this patch's sleep, and none of 120 with only its poll. Limitations: - A ThinkPad T14s Gen 6 (v2.0.0 controller) does not fail, and I do not know why. It ran Fedora's 7.3.5 kernel, which does not have 6c067677192f. With that kernel unmodified, sdw_bus_clk_stop() also returned with the frame generator still enabled in 8 of 99 traced runtime suspends. Yet none of 120 starts, all after a clock stop, were silent. With soundwire-qcom.ko rebuilt with this change, none of 120 were silent either; 39 of those were confirmed to follow a clock stop. - Not tested: controllers other than v2.0.0 and v3.1.0 (up to v1.5.1 only the sleep is added); the multi-master mode in soundwire/next, where the dependent controller's runtime suspend returns before the new code; the "link failed to disconnect" path, which never ran. [2] https://lore.kernel.org/r/20261128-sdw-qcom-irq-v1-1-d053ac530faa@oss.qualcomm.com [3] https://lore.kernel.org/r/20261125103825.936939-1-srinivas.kandagatla@oss.qualcomm.com An AI coding assistant (Claude Code) traced the driver, found the downstream handling, wrote the patch and this text, and ran the tests. I have reviewed all of it. drivers/soundwire/qcom.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index 147e55b7a6..588bd6acf4 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -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: 6c067677192f054bbfa815caf04f536bb8dcdee2 -- 2.43.0