Re: [PATCH 4/7] ASoC: rockchip: add Serial Audio Interface (SAI) driver

From: Krzysztof Kozlowski
Date: Thu Mar 06 2025 - 02:38:16 EST


On 05/03/2025 22:24, Nicolas Frattaroli wrote:
...

> +
> +static int rockchip_sai_runtime_resume(struct device *dev)
> +{
> + struct rk_sai_dev *sai = dev_get_drvdata(dev);
> + unsigned long flags;
> + int ret;
> +
> + dev_dbg(dev, "Runtime resuming device!\n");

Drop probe entry/exit messages. Core already gives you tracing for this.

> +
> + ret = clk_prepare_enable(sai->hclk);
> + if (ret)
> + goto err_hclk;
> +
> + ret = clk_prepare_enable(sai->mclk);
> + if (ret)
> + goto err_mclk;
> +
> + regcache_cache_only(sai->regmap, false);
> + regcache_mark_dirty(sai->regmap);
> + ret = regcache_sync(sai->regmap);
> + if (ret)
> + goto err_regmap;
> +
> + if (sai->quirks & QUIRK_ALWAYS_ON && sai->is_master_mode) {
> + spin_lock_irqsave(&sai->xfer_lock, flags);
> + regmap_update_bits(sai->regmap, SAI_XFER,
> + SAI_XFER_CLK_MASK |
> + SAI_XFER_FSS_MASK,
> + SAI_XFER_CLK_EN |
> + SAI_XFER_FSS_EN);
> + spin_unlock_irqrestore(&sai->xfer_lock, flags);
> + }
> +

...

> +
> + ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to register PCM: %d\n", ret);
> + goto err_runtime_suspend;
> + }
> +
> + ret = devm_snd_soc_register_component(&pdev->dev,
> + &rockchip_sai_component,
> + dai, 1);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to register component: %d\n", ret);
> + goto err_runtime_suspend;
> + }
> +
> + pm_runtime_use_autosuspend(&pdev->dev);
> + pm_runtime_put(&pdev->dev);
> +
> + /*
> + * runtime_resume already enabled our hclk again, so we need to also
> + * get rid of the manual enable we did earlier to balance the counts.
> + */

Your way of handling this is extra confusing. You rely on some other
methods to poke the enable/disable count. It is rather expected that
each function handles this fully, so it disables what it have enabled.
You must not rely on PM runtime to do something with clocks which you
now unwind.

> + clk_disable_unprepare(sai->hclk);
> +
> + return 0;
> +
> +err_runtime_suspend:
> + /* If we're !CONFIG_PM, we get -ENOSYS and disable manually */
> + if (pm_runtime_put(&pdev->dev))
> + rockchip_sai_runtime_suspend(&pdev->dev);
> +err_disable_hclk:
> + clk_disable_unprepare(sai->hclk);
> +
> + return ret;
> +}
> +

_device_id tables are supposed to be around probe, not beginning of the
file.

> +static void rockchip_sai_remove(struct platform_device *pdev)
> +{
> +#ifndef CONFIG_PM
> + rockchip_sai_runtime_suspend(&pdev->dev);> +#endif
> +}
> +
> +static const struct dev_pm_ops rockchip_sai_pm_ops = {
> + SET_RUNTIME_PM_OPS(rockchip_sai_runtime_suspend, rockchip_sai_runtime_resume, NULL)
> + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
> +};
> +
> +static struct platform_driver rockchip_sai_driver = {
> + .probe = rockchip_sai_probe,
> + .remove = rockchip_sai_remove,
> + .driver = {
> + .name = DRV_NAME,
> + .of_match_table = of_match_ptr(rockchip_sai_match),

Drop of_match_ptr, you have warning here.

> + .pm = &rockchip_sai_pm_ops,
> + },
> +};
> +module_platform_driver(rockchip_sai_driver);
> +
> +MODULE_DESCRIPTION("Rockchip SAI ASoC Interface");
> +MODULE_AUTHOR("Sugar Zhang <sugar.zhang@xxxxxxxxxxxxxx>");
> +MODULE_AUTHOR("Nicolas Frattaroli <nicolas.frattaroli@xxxxxxxxxxxxx>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:" DRV_NAME);

You should not need MODULE_ALIAS() in normal cases. If you need it,
usually it means your device ID table is wrong (e.g. misses either
entries or MODULE_DEVICE_TABLE()). MODULE_ALIAS() is not a substitute
for incomplete ID table.


> +MODULE_DEVICE_TABLE(of, rockchip_sai_match);


Best regards,
Krzysztof