* [PATCH] ASoC: rockchip: rockchip_sai: Fix hclk and runtime PM handling in probe
@ 2026-11-30 22:56 Arina Kharlamova via B4 Relay
2026-12-01 12:56 ` Nicolas Frattaroli
0 siblings, 1 reply; 2+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-11-30 22:56 UTC (permalink / raw)
To: Nicolas Frattaroli, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai, Heiko Stuebner, Pei Xiao, Sugar Zhang
Cc: linux-rockchip, linux-sound, linux-arm-kernel, Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
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 <arina.kharlamova@mbzuai.ac.ae>
---
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 <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ASoC: rockchip: rockchip_sai: Fix hclk and runtime PM handling in probe
2026-11-30 22:56 [PATCH] ASoC: rockchip: rockchip_sai: Fix hclk and runtime PM handling in probe Arina Kharlamova via B4 Relay
@ 2026-12-01 12:56 ` Nicolas Frattaroli
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Frattaroli @ 2026-12-01 12:56 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Heiko Stuebner, Pei Xiao, Sugar Zhang, arina.kharlamova
Cc: linux-rockchip, linux-sound, linux-arm-kernel, Arina Kharlamova,
bui duc phuc
+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 <arina.kharlamova@mbzuai.ac.ae>
>
> 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 <arina.kharlamova@mbzuai.ac.ae>
> ---
> 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 <arina.kharlamova@mbzuai.ac.ae>
>
>
>
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 12:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 22:56 [PATCH] ASoC: rockchip: rockchip_sai: Fix hclk and runtime PM handling in probe Arina Kharlamova via B4 Relay
2026-12-01 12:56 ` Nicolas Frattaroli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox