* [PATCH V3] mmc: sdhci-of-dwcmshc: Use helper function devm_clk_get_enabled()
@ 2023-08-24 8:46 Yi Yang
2023-08-24 9:13 ` Adrian Hunter
0 siblings, 1 reply; 3+ messages in thread
From: Yi Yang @ 2023-08-24 8:46 UTC (permalink / raw)
To: adrian.hunter, ulf.hansson; +Cc: linux-mmc
Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
prepared and enabled clocks"), devm_clk_get() and clk_prepare_enable()
can now be replaced by devm_clk_get_enabled() when the driver enables
(and possibly prepares) the clocks for the whole lifetime of the device.
Moreover, it is no longer necessary to unprepare and disable the clocks
explicitly.
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
v3: Fix err check logic
v2: Remove clk_disable_unprepare in dwcmshc_remove()
---
drivers/mmc/host/sdhci-of-dwcmshc.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c
index 31c1892f4ecd..7e1cf78d9695 100644
--- a/drivers/mmc/host/sdhci-of-dwcmshc.c
+++ b/drivers/mmc/host/sdhci-of-dwcmshc.c
@@ -495,19 +495,19 @@ static int dwcmshc_probe(struct platform_device *pdev)
priv = sdhci_pltfm_priv(pltfm_host);
if (dev->of_node) {
- pltfm_host->clk = devm_clk_get(dev, "core");
+ pltfm_host->clk = devm_clk_get_enabled(dev, "core");
if (IS_ERR(pltfm_host->clk)) {
err = PTR_ERR(pltfm_host->clk);
- dev_err(dev, "failed to get core clk: %d\n", err);
+ dev_err(dev, "failed to get or enable core clk: %d\n", err);
goto free_pltfm;
}
- err = clk_prepare_enable(pltfm_host->clk);
- if (err)
- goto free_pltfm;
- priv->bus_clk = devm_clk_get(dev, "bus");
- if (!IS_ERR(priv->bus_clk))
- clk_prepare_enable(priv->bus_clk);
+ priv->bus_clk = devm_clk_get_enabled(dev, "bus");
+ if (IS_ERR(priv->bus_clk)) {
+ err = PTR_ERR(priv->bus_clk);
+ dev_err(dev, "failed to get or enable bus clk: %d\n", err);
+ goto free_pltfm;
+ }
}
err = mmc_of_parse(host->mmc);
@@ -564,8 +564,6 @@ static int dwcmshc_probe(struct platform_device *pdev)
err_setup_host:
sdhci_cleanup_host(host);
err_clk:
- clk_disable_unprepare(pltfm_host->clk);
- clk_disable_unprepare(priv->bus_clk);
if (rk_priv)
clk_bulk_disable_unprepare(RK35xx_MAX_CLKS,
rk_priv->rockchip_clks);
@@ -583,8 +581,6 @@ static void dwcmshc_remove(struct platform_device *pdev)
sdhci_remove_host(host, 0);
- clk_disable_unprepare(pltfm_host->clk);
- clk_disable_unprepare(priv->bus_clk);
if (rk_priv)
clk_bulk_disable_unprepare(RK35xx_MAX_CLKS,
rk_priv->rockchip_clks);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V3] mmc: sdhci-of-dwcmshc: Use helper function devm_clk_get_enabled()
2023-08-24 8:46 [PATCH V3] mmc: sdhci-of-dwcmshc: Use helper function devm_clk_get_enabled() Yi Yang
@ 2023-08-24 9:13 ` Adrian Hunter
2023-08-24 9:28 ` yiyang (D)
0 siblings, 1 reply; 3+ messages in thread
From: Adrian Hunter @ 2023-08-24 9:13 UTC (permalink / raw)
To: Yi Yang; +Cc: linux-mmc, ulf.hansson, Liming Sun, David Thompson, Shawn Lin
On 24/08/23 11:46, Yi Yang wrote:
> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
> prepared and enabled clocks"), devm_clk_get() and clk_prepare_enable()
> can now be replaced by devm_clk_get_enabled() when the driver enables
> (and possibly prepares) the clocks for the whole lifetime of the device.
> Moreover, it is no longer necessary to unprepare and disable the clocks
> explicitly.
>
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
> v3: Fix err check logic
> v2: Remove clk_disable_unprepare in dwcmshc_remove()
> ---
> drivers/mmc/host/sdhci-of-dwcmshc.c | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c
> index 31c1892f4ecd..7e1cf78d9695 100644
> --- a/drivers/mmc/host/sdhci-of-dwcmshc.c
> +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c
> @@ -495,19 +495,19 @@ static int dwcmshc_probe(struct platform_device *pdev)
> priv = sdhci_pltfm_priv(pltfm_host);
>
> if (dev->of_node) {
> - pltfm_host->clk = devm_clk_get(dev, "core");
> + pltfm_host->clk = devm_clk_get_enabled(dev, "core");
> if (IS_ERR(pltfm_host->clk)) {
> err = PTR_ERR(pltfm_host->clk);
> - dev_err(dev, "failed to get core clk: %d\n", err);
> + dev_err(dev, "failed to get or enable core clk: %d\n", err);
> goto free_pltfm;
> }
> - err = clk_prepare_enable(pltfm_host->clk);
> - if (err)
> - goto free_pltfm;
>
> - priv->bus_clk = devm_clk_get(dev, "bus");
> - if (!IS_ERR(priv->bus_clk))
> - clk_prepare_enable(priv->bus_clk);
> + priv->bus_clk = devm_clk_get_enabled(dev, "bus");
This should probably be devm_clk_get_enabled_optional()
Maybe someone who knows the hardware can confirm?
> + if (IS_ERR(priv->bus_clk)) {
> + err = PTR_ERR(priv->bus_clk);
> + dev_err(dev, "failed to get or enable bus clk: %d\n", err);
> + goto free_pltfm;
> + }
> }
>
> err = mmc_of_parse(host->mmc);
> @@ -564,8 +564,6 @@ static int dwcmshc_probe(struct platform_device *pdev)
> err_setup_host:
> sdhci_cleanup_host(host);
> err_clk:
> - clk_disable_unprepare(pltfm_host->clk);
> - clk_disable_unprepare(priv->bus_clk);
> if (rk_priv)
> clk_bulk_disable_unprepare(RK35xx_MAX_CLKS,
> rk_priv->rockchip_clks);
> @@ -583,8 +581,6 @@ static void dwcmshc_remove(struct platform_device *pdev)
>
> sdhci_remove_host(host, 0);
>
> - clk_disable_unprepare(pltfm_host->clk);
> - clk_disable_unprepare(priv->bus_clk);
> if (rk_priv)
> clk_bulk_disable_unprepare(RK35xx_MAX_CLKS,
> rk_priv->rockchip_clks);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V3] mmc: sdhci-of-dwcmshc: Use helper function devm_clk_get_enabled()
2023-08-24 9:13 ` Adrian Hunter
@ 2023-08-24 9:28 ` yiyang (D)
0 siblings, 0 replies; 3+ messages in thread
From: yiyang (D) @ 2023-08-24 9:28 UTC (permalink / raw)
To: Adrian Hunter
Cc: linux-mmc, ulf.hansson, Liming Sun, David Thompson, Shawn Lin
On 2023/8/24 17:13, Adrian Hunter wrote:
> On 24/08/23 11:46, Yi Yang wrote:
>> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
>> prepared and enabled clocks"), devm_clk_get() and clk_prepare_enable()
>> can now be replaced by devm_clk_get_enabled() when the driver enables
>> (and possibly prepares) the clocks for the whole lifetime of the device.
>> Moreover, it is no longer necessary to unprepare and disable the clocks
>> explicitly.
>>
>> Signed-off-by: Yi Yang <yiyang13@huawei.com>
>> ---
>> v3: Fix err check logic
>> v2: Remove clk_disable_unprepare in dwcmshc_remove()
>> ---
>> drivers/mmc/host/sdhci-of-dwcmshc.c | 20 ++++++++------------
>> 1 file changed, 8 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c
>> index 31c1892f4ecd..7e1cf78d9695 100644
>> --- a/drivers/mmc/host/sdhci-of-dwcmshc.c
>> +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c
>> @@ -495,19 +495,19 @@ static int dwcmshc_probe(struct platform_device *pdev)
>> priv = sdhci_pltfm_priv(pltfm_host);
>>
>> if (dev->of_node) {
>> - pltfm_host->clk = devm_clk_get(dev, "core");
>> + pltfm_host->clk = devm_clk_get_enabled(dev, "core");
>> if (IS_ERR(pltfm_host->clk)) {
>> err = PTR_ERR(pltfm_host->clk);
>> - dev_err(dev, "failed to get core clk: %d\n", err);
>> + dev_err(dev, "failed to get or enable core clk: %d\n", err);
>> goto free_pltfm;
>> }
>> - err = clk_prepare_enable(pltfm_host->clk);
>> - if (err)
>> - goto free_pltfm;
>>
>> - priv->bus_clk = devm_clk_get(dev, "bus");
>> - if (!IS_ERR(priv->bus_clk))
>> - clk_prepare_enable(priv->bus_clk);
>> + priv->bus_clk = devm_clk_get_enabled(dev, "bus");
>
> This should probably be devm_clk_get_enabled_optional()
> Maybe someone who knows the hardware can confirm?
>
I don't know enough about hardware, Maybe we can wait for someone to
confirm the change.
>> + if (IS_ERR(priv->bus_clk)) {
>> + err = PTR_ERR(priv->bus_clk);
>> + dev_err(dev, "failed to get or enable bus clk: %d\n", err);
>> + goto free_pltfm;
>> + }
>> }
>>
>> err = mmc_of_parse(host->mmc);
>> @@ -564,8 +564,6 @@ static int dwcmshc_probe(struct platform_device *pdev)
>> err_setup_host:
>> sdhci_cleanup_host(host);
>> err_clk:
>> - clk_disable_unprepare(pltfm_host->clk);
>> - clk_disable_unprepare(priv->bus_clk);
>> if (rk_priv)
>> clk_bulk_disable_unprepare(RK35xx_MAX_CLKS,
>> rk_priv->rockchip_clks);
>> @@ -583,8 +581,6 @@ static void dwcmshc_remove(struct platform_device *pdev)
>>
>> sdhci_remove_host(host, 0);
>>
>> - clk_disable_unprepare(pltfm_host->clk);
>> - clk_disable_unprepare(priv->bus_clk);
>> if (rk_priv)
>> clk_bulk_disable_unprepare(RK35xx_MAX_CLKS,
>> rk_priv->rockchip_clks);
>
> .
>
--
Yi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-24 9:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-24 8:46 [PATCH V3] mmc: sdhci-of-dwcmshc: Use helper function devm_clk_get_enabled() Yi Yang
2023-08-24 9:13 ` Adrian Hunter
2023-08-24 9:28 ` yiyang (D)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox