[PATCH] ASoC: rockchip: rockchip_sai: Fix hclk and runtime PM handling in probe

Bui Duc Phuc phucduc.bui at gmail.com
Wed Dec 2 00:19:15 PST 2026


Hi Nicolas,

>
> 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.

Thank you for personally sending me the board. I really appreciate
your generosity. Having real hardware to test this driver on means
a lot to an independent developer like me. It's still in transit, so I don't
have it yet and can't test Arina's patch on it.

> > From: Arina Kharlamova <arina.kharlamova at 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.

As for the review: The analysis is correct, and I checked that the clock
enables counts balance on all paths, with and without CONFIG_PM.

FWIW, it addresses the same two issues as the patches I first posted in
June, which haven't been reviewed yet:

Fix unbalanced clock reference count:
https://lore.kernel.org/all/20260722115250.62588-1-phucduc.bui@gmail.com/ (v2)

Runtime PM status fix:
https://lore.kernel.org/all/20260722115250.62588-2-phucduc.bui@gmail.com/

Arina's version does both in a single bisectable change with Fixes:
tags, so I'm fine with taking it instead of mine.

> >
> > 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 at mbzuai.ac.ae>

Reviewed-by: bui duc phuc <phucduc.bui at gmail.com>

> 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.

Agreed. Enabling runtime PM right after getting the clocks and using
pm_runtime_resume_and_get()/pm_runtime_put_sync() around the register
accesses removes the manual accounting and the manual hclk handling.
For !CONFIG_PM, the device is powered up by hand and a devm action
powers it down, which also replaces .remove. It also moves the IRQ
request after the device setup, since the IRQ is IRQF_SHARED and the
ISR reads registers.

Roughly:
-----------------------------------------------------------------------
static void rockchip_sai_runtime_suspend_action(void *data)
{
        if (!pm_runtime_status_suspended(dev))
                rockchip_sai_runtime_suspend(dev);
}

rockchip_sai_probe()
{
        /* resets, regmap, irq = platform_get_irq_optional() */
        /* mclk, hclk = devm_clk_get(): no manual enable */

        devm_add_action(dev, rockchip_sai_runtime_suspend_action, dev);

        devm_pm_runtime_enable(dev);
        if(!pm_runtime_enabled(dev)) /* !CONFIG_PM */
                rockchip_sai_runtime_resume(dev);

        pm_runtime_resume_and_get(dev);

        /* on error above: pm_runtime_put_noidle() and return */
        regmap_read(SAI_VERSION);
        rockchip_sai_init_dai();
        rockchip_sai_parse_paths();
        if (irq > 0)
                devm_request_irq(..., IRQF_SHARED, ...);

        pm_runtime_put_sync(dev);

        devm_snd_dmaengine_pcm_register();
        return devm_snd_soc_register_component();
}

/* .remove is dropped: the devm action powers the device down if it is
 * still on, which is always the case with !CONFIG_PM */
-----------------------------------------------------------------------------

As this is untested and changes more behaviour than Arina's patch,
I'd suggest taking hers as the fix for stable. Once the board arrives,
I'll test her patch first and then send this as a proper patch on top.

Best regards,
Phuc



More information about the linux-arm-kernel mailing list