From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=79.135.106.111 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068524; b=d8K4A61AB0zuFLQIJC5icxy8thjBVFeDSKzWeoE6Lpa/mdeLhxw9BJGmYqmSLqw+o6YS ljurx6lYQ7qi5Ti9Gvy9uHebKS8JO080fuEv3VWf0cOQWaRl1cHEuOKt39M6z2ba4NdYz jNlM7vYe4BpIWKO7Uqds9yW8q/HL/dCrQ7fvbOf0bs/8Lek49fcpmFTxsfEES7Kze7RYm Y6ejlsl92T3wg8u1WASN2K7fjr5zODPMt4RJqd+AozScPpbHOsjrlFDxluQrXmgicU/tI AGPDKp97aARLBWz126Z5g/zXY523vbU1qD2dFgxtDRquX9fQZ8B+TLGBNLqq5wy0bcw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068524; h=DMARC-Filter:X-Pm-Submission-Id:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=JG8Yqqd1S30hhkRA9mGge47Wmgoak7mkfu8uLJLPcFE=; b=bJyev+S4V05+gik9rWSyfyUOa8nm6pDgRFLH+KuvuHUdPqlwl5+zz1If1nRTv03LiW5Y 6RfkFYUbKVDhQ2KwZ+mQPlkIhYK1JAh3n0OxzBmfjkaaRUi7P5ksu7H6ox35DSJeKp1ig te+LYHMJo/VrhtYcZAC/X/02nUAofqPuj7TaDRO/qcJXCZllFizCJQ9HpZ+hO5sWAo25Q sZusMaNz9LKTicNGK6qwxLWupoaVw3vlZn0X4J36rl+hZSQ8mF82P1x1I+MRHJc56JUhx ql52AwdCPOev17Qfox3xLK0oNzxIFk5XYf/KTpVfUo//WllnKE9oMtb5aIRhL7D33lg== 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=79.135.106.111 Received: from mail-106111.protonmail.ch (mail-106111.protonmail.ch [79.135.106.111]) (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 DCCE8606A337 for ; Mon, 30 Nov 2026 19:55:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DCCE8606A337 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: 4jdZW81wlqz1DFF9 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 v2] soundwire: qcom: wait for the link to stop before gating the clock Date: Mon, 30 Nov 2026 12:55:10 -0700 Message-ID: <20261130195511.1713480-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 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. 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 --- 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/20261129202258.2613829-1-luke@phorex.org drivers/soundwire/qcom.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index a4cb628971..8f3dbb9b16 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: fe6ff8d5d675c01793b9f051d16055dd4aa75244 -- 2.43.0