Re: [PATCH] spi: rockchip: Avoid redundant clock disable in pm operation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jon,

On Sat, Aug 24, 2024 at 8:55 PM Jon Lin <jon.lin@xxxxxxxxxxxxxx> wrote:
> --- a/drivers/spi/spi-rockchip.c
> +++ b/drivers/spi/spi-rockchip.c
> +#ifdef CONFIG_PM_SLEEP
> +static int rockchip_spi_suspend(struct device *dev)
>  {
> +       int ret;
>         struct spi_controller *ctlr = dev_get_drvdata(dev);
> -       struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
>
> -       clk_disable_unprepare(rs->spiclk);
> -       clk_disable_unprepare(rs->apb_pclk);
> +       ret = spi_controller_suspend(ctlr);
> +       if (ret < 0)
> +               return ret;
> +
> +       /* Avoid redundant clock disable */
> +       if (!pm_runtime_status_suspended(dev))
> +               rockchip_spi_runtime_suspend(dev);

rockchip_spi_runtime_suspend() returns an error code. I understand
that it doesn't actually fail in practice, but you should probably
check it anyway.

> +
> +       pinctrl_pm_select_sleep_state(dev);
>
>         return 0;
>  }
>
> -static int rockchip_spi_runtime_resume(struct device *dev)
> +static int rockchip_spi_resume(struct device *dev)
>  {
>         int ret;
>         struct spi_controller *ctlr = dev_get_drvdata(dev);
> -       struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
>
> -       ret = clk_prepare_enable(rs->apb_pclk);
> -       if (ret < 0)
> -               return ret;
> +       pinctrl_pm_select_default_state(dev);
>
> -       ret = clk_prepare_enable(rs->spiclk);
> +       if (!pm_runtime_status_suspended(dev)) {
> +               ret = rockchip_spi_runtime_resume(dev);
> +               if (ret < 0)
> +                       return ret;
> +       }
> +
> +       ret = spi_controller_resume(ctlr);
>         if (ret < 0)
> -               clk_disable_unprepare(rs->apb_pclk);
> +               rockchip_spi_runtime_suspend(dev);

I don't think this is valid error handling. AFAIK, failing the
resume() function doesn't actually "disable" the device in any way
(it's just informative at best), so we probably shouldn't disable
clocks here. Otherwise, you might leave the clock disabled while the
runtime PM framework thinks it's enabled.

Brian

>
>         return 0;
>  }
> --
> 2.34.1
>





[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux