On Wed, 31 Jul 2019 at 18:17, Ulrich Hecht <[email protected]> wrote:
>
> This fixes a clock imbalance that occurs on Renesas systems because the SD
> clock is handled by both runtime PM and the hardware driver. After a
> suspend/resume cycle both enable the same clock, resulting in an enable
> count of 2 even if the clock is only used by one device.
>
> See https://www.spinics.net/lists/linux-mmc/msg44431.html for details.
>
> This patch removes the clock handling from the driver's runtime PM
> callbacks and turns the clock off after probing if the device has a power
> domain attached.
>
> Reported-by: Geert Uytterhoeven <[email protected]>
> Signed-off-by: Ulrich Hecht <[email protected]>
> Tested-by: Niklas Söderlund <[email protected]>
> ---
> drivers/mmc/host/tmio_mmc_core.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/host/tmio_mmc_core.c
> b/drivers/mmc/host/tmio_mmc_core.c
> index 31ffcc3..733ff96 100644
> --- a/drivers/mmc/host/tmio_mmc_core.c
> +++ b/drivers/mmc/host/tmio_mmc_core.c
> @@ -1260,9 +1260,14 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host)
> /* See if we also get DMA */
> tmio_mmc_request_dma(_host, pdata);
>
> - pm_runtime_set_active(&pdev->dev);
> +#ifdef CONFIG_PM
> + /* PM handles the clock; disable it so it won't be enabled twice. */
> + if (_host->clk_disable && pdev->dev.pm_domain)
Hmm.
This seems to work for most cases of yours, but it's fragile, because
how do you know that the pm_domain above is managing the clock? You
don't.
> + _host->clk_disable(_host);
> + pm_runtime_get_sync(&pdev->dev);
> pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
> pm_runtime_use_autosuspend(&pdev->dev);
> +#endif
>
> ret = mmc_add_host(mmc);
> if (ret)
> @@ -1325,7 +1330,8 @@ int tmio_mmc_host_runtime_suspend(struct device *dev)
> if (host->clk_cache)
> host->set_clock(host, 0);
>
> - tmio_mmc_clk_disable(host);
> + if (!dev->pm_domain)
> + tmio_mmc_clk_disable(host);
>
> return 0;
> }
> @@ -1340,7 +1346,9 @@ int tmio_mmc_host_runtime_resume(struct device *dev)
> {
> struct tmio_mmc_host *host = dev_get_drvdata(dev);
>
> - tmio_mmc_clk_enable(host);
> + if (!dev->pm_domain)
> + tmio_mmc_clk_enable(host);
> +
> tmio_mmc_hw_reset(host->mmc);
>
> if (host->clk_cache)
> --
> 2.7.4
>
I am going to think a bit more about this, but at this point, my
gut-feeling is that may need to add some helper functions to let genpd
and/or the pm_clk framework, to share some internal information with
drivers.
Kind regards
Uffe