From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 A969A606A320 for ; Tue, 1 Dec 2026 12:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=BSm1z0Jq; dkim=fail reason="signature verification failed" (1024-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=CKmK3Z4N DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=27t1ov5Lr6CI4J/V6lWbSqMubMU09d/3ZgTIkG0nPlY=; b=BSm1z0Jq1/7LfHO45zHqmTU84R iMjyVIMhNTehB09884Jnl8V42r+Ty6Gk5EkpDzuouYoeZJxqwrysYD88D6jyWEfhsz0gSaFkiY5ER qsN9fm+wmhPRD1abw3Y2v+IpqtPZdhmKDgsZqstXKxJc13ps0A48jdpYMpHsMVS0ZydeG0LzMqrVl 1yId6C0tg/NbcT0hJ03DiAV9m9kcFV43XCW9KXsrtOeADDm5Y0xpOMehM269CeUYdUmAjfktykJGf LoRxaVO7x1RwQKoabFGEeuInw/lwZvFDyZnmY4JxYZlLFXZ4xrHPtDRTLzS0qHe3zpW4y4Zg/MKJc u6UYD3mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYNQ0-00000007r5X-383p; Tue, 01 Dec 2026 12:57:12 +0000 Received: from sender6-pp-g122.zoho.com ([165.173.180.122]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYNPw-00000007r3x-0McO; Tue, 01 Dec 2026 12:57:09 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1796129812; cv=none; d=zohomail.com; s=zohoarc; b=ivj6+7vh7sE4SV6skUPG0Ftuq4Tz2DNhZVKuoVJNElmcNyY1GIIXdHdcIMyhoBl/LsaI0RH7d1m2j2yFfkNVtzBhDC7jyrLPFP7ki0sKHnLzBZOR+GxrYpgleGYL1QkSqTPB0wZYel41fTEt9jSn66lUXf9Pwje7mhFMb+pTAEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796129812; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=27t1ov5Lr6CI4J/V6lWbSqMubMU09d/3ZgTIkG0nPlY=; b=CmSjDHhNAtPF4BWZYh2tpzrfoE8IdZZQS8lQ6Nylsly/4d6qzvj9G1LbbuGzfxG+HRmh9JX+e09Y/Op51CdkCpY0OKY9IMVJZ+wqSMNCbF5lEpwNI0BggrKEo7zoQzlBJVURV2zr5qo3ubih4CMWZPNFtnYl90QlL8rFQWdnZh8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=CKmK3Z4NlmvLHVZSkU4pc57WTZkUN83xqpE25UMIiLzaDc+oWTMhTRGx0FB0cINVvM0cMW1+zUoHALSXtbuqC5wkCCG7HfEu1EXWQ6f0Rre168ynMXArALigVnb3CJZQ73x4pEWOOWtfTBKPJOHR0mD6tEHR3y2Pbe+fgGrCl34=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=27t1ov5Lr6CI4J/V6lWbSqMubMU09d/3ZgTIkG0nPlY=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1796129809875919.1614621249507; Tue, 1 Dec 2026 04:56:49 -0800 (PST) From: Nicolas Frattaroli To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Heiko Stuebner , Pei Xiao , Sugar Zhang , arina.kharlamova@mbzuai.ac.ae Cc: linux-rockchip@lists.infradead.org, linux-sound@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Arina Kharlamova , bui duc phuc Subject: Re: [PATCH] ASoC: rockchip: rockchip_sai: Fix hclk and runtime PM handling in probe Date: Tue, 01 Dec 2026 13:56:44 +0100 Message-ID: In-Reply-To: <20261201-s2p-d08-v1-1-e6905d3dc4e7@mbzuai.ac.ae> References: <20261201-s2p-d08-v1-1-e6905d3dc4e7@mbzuai.ac.ae> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_045708_178043_015C3560 X-CRM114-Status: GOOD ( 33.79 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 +Cc Bui Duc Phuc On Monday, 30 November 2026 23:56:00 Central European Standard Time Arina Kharlamova via B4 Relay wrote: > From: Arina Kharlamova > > Probe powers the device up by calling rockchip_sai_runtime_resume() > directly, but runtime PM is not told about it and the status stays > suspended. The pm_runtime_put() at the end of probe then does nothing, > so the mclk and hclk enables taken by that call are never dropped: both > clocks stay on while the device is idle, and mclk stays on after unbind. > > hclk is also got with devm_clk_get_enabled(), although probe drops its > own enable with clk_disable_unprepare() once the device is registered, > so devres disables it a second time at unbind. With CONFIG_PM the two > bugs cancel out for hclk; without it hclk is disabled once too often. > > Get hclk with devm_clk_get() and enable it by hand, as before the > conversion, and disable it on the probe error paths. Resume the device > first, mark it active and only then enable runtime PM. Use > pm_runtime_put_sync() on the error path, so the device is suspended > before devres disables runtime PM. > > The two fixes go together: either one alone leaves hclk unbalanced. > > Fixes: cc78d1eaabad ("ASoC: rockchip: add Serial Audio Interface (SAI) driver") > Fixes: 03b778d19948 ("ASOC: rockchip: Use helper function devm_clk_get_enabled()") > Signed-off-by: Arina Kharlamova > --- > Two fixes for the clock handling in rockchip_sai_probe(). > > 1. hclk is got with devm_clk_get_enabled(), but probe also drops the > enable by hand once the device is registered, so devres disables the > clock a second time at unbind. Get it with devm_clk_get() and enable > it by hand, as before the conversion. > > 2. Probe powers the device up by calling the runtime resume callback > directly without marking it active, so the pm_runtime_put() at the > end of probe does nothing and mclk and hclk are never released. > Resume first, mark the device active, then enable runtime PM. > > Found by checks derived from the spec2patch kernel API specifications, > with the help of an AI coding assistant (Claude); I reviewed the > analysis and the fix. > --- > sound/soc/rockchip/rockchip_sai.c | 34 +++++++++++++++++++++++++--------- > 1 file changed, 25 insertions(+), 9 deletions(-) > > diff --git a/sound/soc/rockchip/rockchip_sai.c b/sound/soc/rockchip/rockchip_sai.c > index b625d69f76c8..866b68cc706c 100644 > --- a/sound/soc/rockchip/rockchip_sai.c > +++ b/sound/soc/rockchip/rockchip_sai.c > @@ -1459,20 +1459,30 @@ static int rockchip_sai_probe(struct platform_device *pdev) > return dev_err_probe(&pdev->dev, PTR_ERR(sai->mclk), > "Failed to get mclk\n"); > > - sai->hclk = devm_clk_get_enabled(&pdev->dev, "hclk"); > + sai->hclk = devm_clk_get(&pdev->dev, "hclk"); > if (IS_ERR(sai->hclk)) > return dev_err_probe(&pdev->dev, PTR_ERR(sai->hclk), > "Failed to get hclk\n"); > > + /* > + * hclk is only needed until runtime PM takes over below, so it is > + * enabled by hand and not with devm_clk_get_enabled(). > + */ > + ret = clk_prepare_enable(sai->hclk); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, "Failed to enable hclk\n"); > + > regmap_read(sai->regmap, SAI_VERSION, &sai->version); > > ret = rockchip_sai_init_dai(sai, res, &dai); > - if (ret) > - return dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n"); > + if (ret) { > + dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n"); > + goto err_disable_hclk; > + } > > ret = rockchip_sai_parse_paths(sai, node); > if (ret) > - return ret; > + goto err_disable_hclk; > > /* > * From here on, all register accesses need to be wrapped in > @@ -1480,11 +1490,15 @@ static int rockchip_sai_probe(struct platform_device *pdev) > * > * NB: we don't rely on _resume_and_get in case of !CONFIG_PM > */ > - devm_pm_runtime_enable(&pdev->dev); > - pm_runtime_get_noresume(&pdev->dev); > ret = rockchip_sai_runtime_resume(&pdev->dev); > - if (ret) > - return dev_err_probe(&pdev->dev, ret, "Failed to resume device\n"); > + if (ret) { > + dev_err_probe(&pdev->dev, ret, "Failed to resume device\n"); > + goto err_disable_hclk; > + } > + > + pm_runtime_set_active(&pdev->dev); > + pm_runtime_get_noresume(&pdev->dev); > + devm_pm_runtime_enable(&pdev->dev); > > ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); > if (ret) > @@ -1505,9 +1519,11 @@ static int rockchip_sai_probe(struct platform_device *pdev) > > err_runtime_suspend: > if (IS_ENABLED(CONFIG_PM)) > - pm_runtime_put(&pdev->dev); > + pm_runtime_put_sync(&pdev->dev); > else > rockchip_sai_runtime_suspend(&pdev->dev); > +err_disable_hclk: > + clk_disable_unprepare(sai->hclk); > > return ret; > } > > --- > base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5 > change-id: 20261129-s2p-d08-dd5b1bd68fab > > Best regards, > -- > Arina Kharlamova > > > I'll leave reviewing this one in-depth up to bui duc phuc, who has been sent hardware (by me) that uses this driver and has done work wrt runtime PM handling in this driver already. Entirely possible that instead of this mess there's a much simpler solution here, like setting up and enabling RPM earlier so this manual accounting during probe doesn't need to be done at all. Regards, Nicolas Frattaroli