2021-07-16 08:01:51

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH V2 5/5] i3c: master: svc: add runtime pm support

Hi Clark,


> @@ -1431,7 +1502,7 @@ static int svc_i3c_master_probe(struct platform_device *pdev)
> GFP_KERNEL);
> if (!master->ibi.slots) {
> ret = -ENOMEM;
> - goto err_disable_sclk;
> + goto rpm_disable;
> }
>
> platform_set_drvdata(pdev, master);
> @@ -1442,18 +1513,17 @@ static int svc_i3c_master_probe(struct platform_device *pdev)
> ret = i3c_master_register(&master->base, &pdev->dev,
> &svc_i3c_master_ops, false);
> if (ret)
> - goto err_disable_sclk;
> + goto rpm_disable;
>
> - return 0;
> -
> -err_disable_sclk:
> - clk_disable_unprepare(master->sclk);
> + pm_runtime_mark_last_busy(&pdev->dev);
> + pm_runtime_put_autosuspend(&pdev->dev);
>
> -err_disable_fclk:
> - clk_disable_unprepare(master->fclk);
> + return 0;
>
> -err_disable_pclk:
> - clk_disable_unprepare(master->pclk);

It's not clear to me why you drop the disable_*clk labels to move them
back in place? I would rather prefer to keep a clean error path.

> +rpm_disable:
> + pm_runtime_dont_use_autosuspend(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
> + pm_runtime_disable(&pdev->dev);
>
> return ret;
> }
> @@ -1467,13 +1537,57 @@ static int svc_i3c_master_remove(struct platform_device *pdev)
> if (ret)
> return ret;
>
> + pm_runtime_dont_use_autosuspend(&pdev->dev);
> + pm_runtime_disable(&pdev->dev);
> +
> + return 0;
> +}
> +
> +static int __maybe_unused svc_i3c_runtime_suspend(struct device *dev)
> +{
> + struct svc_i3c_master *master = dev_get_drvdata(dev);
> +
> clk_disable_unprepare(master->pclk);
> clk_disable_unprepare(master->fclk);
> clk_disable_unprepare(master->sclk);
> + pinctrl_pm_select_sleep_state(dev);
>
> return 0;
> }
>
> +static int __maybe_unused svc_i3c_runtime_resume(struct device *dev)
> +{
> + struct svc_i3c_master *master = dev_get_drvdata(dev);
> + int ret = 0;
> +
> + pinctrl_pm_select_default_state(dev);
> + ret = clk_prepare_enable(master->pclk);
> + if (ret)
> + return ret;
> +
> + ret = clk_prepare_enable(master->fclk);
> + if (ret) {
> + clk_disable_unprepare(master->pclk);
> + return ret;
> + }
> +
> + ret = clk_prepare_enable(master->sclk);
> + if (ret) {
> + clk_disable_unprepare(master->pclk);
> + clk_disable_unprepare(master->fclk);
> + return ret;
> + }
> +
> + return ret;
> +}
> +
> +static const struct dev_pm_ops svc_i3c_pm_ops = {
> + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
> + pm_runtime_force_resume)
> + SET_RUNTIME_PM_OPS(svc_i3c_runtime_suspend,
> + svc_i3c_runtime_resume, NULL)
> +};
> +
> static const struct of_device_id svc_i3c_master_of_match_tbl[] = {
> { .compatible = "silvaco,i3c-master" },
> { /* sentinel */ },
> @@ -1485,6 +1599,7 @@ static struct platform_driver svc_i3c_master = {
> .driver = {
> .name = "silvaco-i3c-master",
> .of_match_table = svc_i3c_master_of_match_tbl,
> + .pm = &svc_i3c_pm_ops,
> },
> };
> module_platform_driver(svc_i3c_master);

Thanks,
Miquèl


2021-07-16 08:44:09

by Clark Wang

[permalink] [raw]
Subject: RE: [PATCH V2 5/5] i3c: master: svc: add runtime pm support


> -----Original Message-----
> From: Miquel Raynal <[email protected]>
> Sent: Friday, July 16, 2021 16:00
> To: Clark Wang <[email protected]>
> Cc: [email protected]; [email protected]; linux-
> [email protected]; [email protected]
> Subject: Re: [PATCH V2 5/5] i3c: master: svc: add runtime pm support
>
> Hi Clark,
>
>
> > @@ -1431,7 +1502,7 @@ static int svc_i3c_master_probe(struct
> platform_device *pdev)
> > GFP_KERNEL);
> > if (!master->ibi.slots) {
> > ret = -ENOMEM;
> > - goto err_disable_sclk;
> > + goto rpm_disable;
> > }
> >
> > platform_set_drvdata(pdev, master);
> > @@ -1442,18 +1513,17 @@ static int svc_i3c_master_probe(struct
> platform_device *pdev)
> > ret = i3c_master_register(&master->base, &pdev->dev,
> > &svc_i3c_master_ops, false);
> > if (ret)
> > - goto err_disable_sclk;
> > + goto rpm_disable;
> >
> > - return 0;
> > -
> > -err_disable_sclk:
> > - clk_disable_unprepare(master->sclk);
> > + pm_runtime_mark_last_busy(&pdev->dev);
> > + pm_runtime_put_autosuspend(&pdev->dev);
> >
> > -err_disable_fclk:
> > - clk_disable_unprepare(master->fclk);
> > + return 0;
> >
> > -err_disable_pclk:
> > - clk_disable_unprepare(master->pclk);
>
> It's not clear to me why you drop the disable_*clk labels to move them back
> in place? I would rather prefer to keep a clean error path.

Hi Miquel,

Yes it is. This change is indeed not very clear.
I have restored the error path.
And I found that it is not necessary to enable runtime pm so early.

Please check V3.

Thanks.

Best Regards,
Clark Wang

>
> > +rpm_disable:
> > + pm_runtime_dont_use_autosuspend(&pdev->dev);
> > + pm_runtime_put_sync(&pdev->dev);
> > + pm_runtime_disable(&pdev->dev);
> >
> > return ret;
> > }
> > @@ -1467,13 +1537,57 @@ static int svc_i3c_master_remove(struct
> platform_device *pdev)
> > if (ret)
> > return ret;
> >
> > + pm_runtime_dont_use_autosuspend(&pdev->dev);
> > + pm_runtime_disable(&pdev->dev);
> > +
> > + return 0;
> > +}
> > +
> > +static int __maybe_unused svc_i3c_runtime_suspend(struct device *dev)
> > +{
> > + struct svc_i3c_master *master = dev_get_drvdata(dev);
> > +
> > clk_disable_unprepare(master->pclk);
> > clk_disable_unprepare(master->fclk);
> > clk_disable_unprepare(master->sclk);
> > + pinctrl_pm_select_sleep_state(dev);
> >
> > return 0;
> > }
> >
> > +static int __maybe_unused svc_i3c_runtime_resume(struct device *dev)
> > +{
> > + struct svc_i3c_master *master = dev_get_drvdata(dev);
> > + int ret = 0;
> > +
> > + pinctrl_pm_select_default_state(dev);
> > + ret = clk_prepare_enable(master->pclk);
> > + if (ret)
> > + return ret;
> > +
> > + ret = clk_prepare_enable(master->fclk);
> > + if (ret) {
> > + clk_disable_unprepare(master->pclk);
> > + return ret;
> > + }
> > +
> > + ret = clk_prepare_enable(master->sclk);
> > + if (ret) {
> > + clk_disable_unprepare(master->pclk);
> > + clk_disable_unprepare(master->fclk);
> > + return ret;
> > + }
> > +
> > + return ret;
> > +}
> > +
> > +static const struct dev_pm_ops svc_i3c_pm_ops = {
> > + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
> > + pm_runtime_force_resume)
> > + SET_RUNTIME_PM_OPS(svc_i3c_runtime_suspend,
> > + svc_i3c_runtime_resume, NULL)
> > +};
> > +
> > static const struct of_device_id svc_i3c_master_of_match_tbl[] = {
> > { .compatible = "silvaco,i3c-master" },
> > { /* sentinel */ },
> > @@ -1485,6 +1599,7 @@ static struct platform_driver svc_i3c_master = {
> > .driver = {
> > .name = "silvaco-i3c-master",
> > .of_match_table = svc_i3c_master_of_match_tbl,
> > + .pm = &svc_i3c_pm_ops,
> > },
> > };
> > module_platform_driver(svc_i3c_master);
>
> Thanks,
> Miquèl


Attachments:
smime.p7s (9.36 kB)