Message ID | 20231106104018.29179-1-wenchao.chen@unisoc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mmc: sdhci-sprd: Fix the clock switch | expand |
On Mon, 6 Nov 2023 at 11:40, Wenchao Chen <wenchao.chen@unisoc.com> wrote: > > Some SOCs have a "1x_enable" clock that needs to be turned on and off > in probe, remove and runtime pm. Well, first of all, what is a "1x_enable" clock and why do we need it? Moreover, the clock needs to be described as a part of the DT bindings for the sdhci-sprd mmc controller. That said, it looks like the binding for the sdhci-sprd controller needs to be converted to the yaml format first, can you please have a look at that too? > > Fixes: fb8bd90f83c4 ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller") > Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com> Kind regards Uffe > --- > drivers/mmc/host/sdhci-sprd.c | 29 +++++++++++++++++++++++++---- > 1 file changed, 25 insertions(+), 4 deletions(-) > > diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c > index 6b84ba27e6ab..3367f924dc5b 100644 > --- a/drivers/mmc/host/sdhci-sprd.c > +++ b/drivers/mmc/host/sdhci-sprd.c > @@ -83,6 +83,7 @@ struct sdhci_sprd_host { > u32 version; > struct clk *clk_sdio; > struct clk *clk_enable; > + struct clk *clk_1x_enable; > struct clk *clk_2x_enable; > struct pinctrl *pinctrl; > struct pinctrl_state *pins_uhs; > @@ -784,6 +785,10 @@ static int sdhci_sprd_probe(struct platform_device *pdev) > } > sprd_host->clk_enable = clk; > > + clk = devm_clk_get(&pdev->dev, "1x_enable"); > + if (!IS_ERR(clk)) > + sprd_host->clk_1x_enable = clk; > + > clk = devm_clk_get(&pdev->dev, "2x_enable"); > if (!IS_ERR(clk)) > sprd_host->clk_2x_enable = clk; > @@ -793,12 +798,16 @@ static int sdhci_sprd_probe(struct platform_device *pdev) > goto pltfm_free; > > ret = clk_prepare_enable(sprd_host->clk_enable); > + if (ret) > + goto clk_sdio_disable; > + > + ret = clk_prepare_enable(sprd_host->clk_1x_enable); > if (ret) > goto clk_disable; > > ret = clk_prepare_enable(sprd_host->clk_2x_enable); > if (ret) > - goto clk_disable2; > + goto clk_1x_disable; > > sdhci_sprd_init_config(host); > host->version = sdhci_readw(host, SDHCI_HOST_VERSION); > @@ -858,10 +867,13 @@ static int sdhci_sprd_probe(struct platform_device *pdev) > > clk_disable_unprepare(sprd_host->clk_2x_enable); > > -clk_disable2: > - clk_disable_unprepare(sprd_host->clk_enable); > +clk_1x_disable: > + clk_disable_unprepare(sprd_host->clk_1x_enable); > > clk_disable: > + clk_disable_unprepare(sprd_host->clk_enable); > + > +clk_sdio_disable: > clk_disable_unprepare(sprd_host->clk_sdio); > > pltfm_free: > @@ -878,6 +890,7 @@ static void sdhci_sprd_remove(struct platform_device *pdev) > > clk_disable_unprepare(sprd_host->clk_sdio); > clk_disable_unprepare(sprd_host->clk_enable); > + clk_disable_unprepare(sprd_host->clk_1x_enable); > clk_disable_unprepare(sprd_host->clk_2x_enable); > > sdhci_pltfm_free(pdev); > @@ -900,6 +913,7 @@ static int sdhci_sprd_runtime_suspend(struct device *dev) > > clk_disable_unprepare(sprd_host->clk_sdio); > clk_disable_unprepare(sprd_host->clk_enable); > + clk_disable_unprepare(sprd_host->clk_1x_enable); > clk_disable_unprepare(sprd_host->clk_2x_enable); > > return 0; > @@ -915,10 +929,14 @@ static int sdhci_sprd_runtime_resume(struct device *dev) > if (ret) > return ret; > > - ret = clk_prepare_enable(sprd_host->clk_enable); > + ret = clk_prepare_enable(sprd_host->clk_1x_enable); > if (ret) > goto clk_2x_disable; > > + ret = clk_prepare_enable(sprd_host->clk_enable); > + if (ret) > + goto clk_1x_disable; > + > ret = clk_prepare_enable(sprd_host->clk_sdio); > if (ret) > goto clk_disable; > @@ -931,6 +949,9 @@ static int sdhci_sprd_runtime_resume(struct device *dev) > clk_disable: > clk_disable_unprepare(sprd_host->clk_enable); > > +clk_1x_disable: > + clk_disable_unprepare(sprd_host->clk_1x_enable); > + > clk_2x_disable: > clk_disable_unprepare(sprd_host->clk_2x_enable); > > -- > 2.17.1 >
diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c index 6b84ba27e6ab..3367f924dc5b 100644 --- a/drivers/mmc/host/sdhci-sprd.c +++ b/drivers/mmc/host/sdhci-sprd.c @@ -83,6 +83,7 @@ struct sdhci_sprd_host { u32 version; struct clk *clk_sdio; struct clk *clk_enable; + struct clk *clk_1x_enable; struct clk *clk_2x_enable; struct pinctrl *pinctrl; struct pinctrl_state *pins_uhs; @@ -784,6 +785,10 @@ static int sdhci_sprd_probe(struct platform_device *pdev) } sprd_host->clk_enable = clk; + clk = devm_clk_get(&pdev->dev, "1x_enable"); + if (!IS_ERR(clk)) + sprd_host->clk_1x_enable = clk; + clk = devm_clk_get(&pdev->dev, "2x_enable"); if (!IS_ERR(clk)) sprd_host->clk_2x_enable = clk; @@ -793,12 +798,16 @@ static int sdhci_sprd_probe(struct platform_device *pdev) goto pltfm_free; ret = clk_prepare_enable(sprd_host->clk_enable); + if (ret) + goto clk_sdio_disable; + + ret = clk_prepare_enable(sprd_host->clk_1x_enable); if (ret) goto clk_disable; ret = clk_prepare_enable(sprd_host->clk_2x_enable); if (ret) - goto clk_disable2; + goto clk_1x_disable; sdhci_sprd_init_config(host); host->version = sdhci_readw(host, SDHCI_HOST_VERSION); @@ -858,10 +867,13 @@ static int sdhci_sprd_probe(struct platform_device *pdev) clk_disable_unprepare(sprd_host->clk_2x_enable); -clk_disable2: - clk_disable_unprepare(sprd_host->clk_enable); +clk_1x_disable: + clk_disable_unprepare(sprd_host->clk_1x_enable); clk_disable: + clk_disable_unprepare(sprd_host->clk_enable); + +clk_sdio_disable: clk_disable_unprepare(sprd_host->clk_sdio); pltfm_free: @@ -878,6 +890,7 @@ static void sdhci_sprd_remove(struct platform_device *pdev) clk_disable_unprepare(sprd_host->clk_sdio); clk_disable_unprepare(sprd_host->clk_enable); + clk_disable_unprepare(sprd_host->clk_1x_enable); clk_disable_unprepare(sprd_host->clk_2x_enable); sdhci_pltfm_free(pdev); @@ -900,6 +913,7 @@ static int sdhci_sprd_runtime_suspend(struct device *dev) clk_disable_unprepare(sprd_host->clk_sdio); clk_disable_unprepare(sprd_host->clk_enable); + clk_disable_unprepare(sprd_host->clk_1x_enable); clk_disable_unprepare(sprd_host->clk_2x_enable); return 0; @@ -915,10 +929,14 @@ static int sdhci_sprd_runtime_resume(struct device *dev) if (ret) return ret; - ret = clk_prepare_enable(sprd_host->clk_enable); + ret = clk_prepare_enable(sprd_host->clk_1x_enable); if (ret) goto clk_2x_disable; + ret = clk_prepare_enable(sprd_host->clk_enable); + if (ret) + goto clk_1x_disable; + ret = clk_prepare_enable(sprd_host->clk_sdio); if (ret) goto clk_disable; @@ -931,6 +949,9 @@ static int sdhci_sprd_runtime_resume(struct device *dev) clk_disable: clk_disable_unprepare(sprd_host->clk_enable); +clk_1x_disable: + clk_disable_unprepare(sprd_host->clk_1x_enable); + clk_2x_disable: clk_disable_unprepare(sprd_host->clk_2x_enable);
Some SOCs have a "1x_enable" clock that needs to be turned on and off in probe, remove and runtime pm. Fixes: fb8bd90f83c4 ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller") Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com> --- drivers/mmc/host/sdhci-sprd.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)