Skip to contentSkip to conversation

mmc: sdhci-of-dwcmshc: Use helper function devm_clk_get_enabled()

PATCH Superseded Yi Yang 2 participants 4 messages Aug 21, 2023 – Aug 24, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yi Yang

author
#0 lore raw

PATCH v2 1/1 mmc: sdhci-of-dwcmshc: Use helper function devm_clk_get_enabled()

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.

---
v2: Remove clk_disable_unprepare in dwcmshc_remove()

---
 drivers/mmc/host/sdhci-of-dwcmshc.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/mmc/host/sdhci-of-dwcmshc.c +8 -12
index 31c1892f4ecd..08b566984733 100644
@@ -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);
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 29 lines · Yi Yang

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.

---
v2: Remove clk_disable_unprepare in dwcmshc_remove()

---
 drivers/mmc/host/sdhci-of-dwcmshc.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/mmc/host/sdhci-of-dwcmshc.c +2 -2
index 31c1892f4ecd..08b566984733 100644
@@ -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;

drivers/mmc/host/sdhci-of-dwcmshc.c static int dwcmshc_probe(struct platform_device *pdev) · line 506

Quoted 10 lines
drivers/mmc/host/sdhci-of-dwcmshc.c +2 -6
 		}
-		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)) {

"!" does not belong, should be "if (IS_ERR(priv->bus_clk))" instead

Quoted 25 lines
drivers/mmc/host/sdhci-of-dwcmshc.c +4 -4
+			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);
maintainer
#2 lore raw
Quoted 35 lines · Adrian Hunter
Quoted 34 lines · Yi Yang

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.

---
v2: Remove clk_disable_unprepare in dwcmshc_remove()

---
 drivers/mmc/host/sdhci-of-dwcmshc.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/mmc/host/sdhci-of-dwcmshc.c +2 -5
index 31c1892f4ecd..08b566984733 100644
@@ -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;
 
Quoted 7 lines

drivers/mmc/host/sdhci-of-dwcmshc.c static int dwcmshc_probe(struct platform_device *pdev) · line 506

Quoted 5 lines
drivers/mmc/host/sdhci-of-dwcmshc.c +2 -3
-		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)) {

"!" does not belong, should be "if (IS_ERR(priv->bus_clk))" instead

Although previously it seemed like the clock was optional. At least the error was not considered fatal.

Quoted 27 lines
Quoted 26 lines
drivers/mmc/host/sdhci-of-dwcmshc.c +4 -4
+			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);
author
#3 lore raw
Quoted 36 lines · Adrian Hunter
Quoted 35 lines · Adrian Hunter
Quoted 34 lines · Yi Yang

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.

---
v2: Remove clk_disable_unprepare in dwcmshc_remove()

---
  drivers/mmc/host/sdhci-of-dwcmshc.c | 20 ++++++++------------
  1 file changed, 8 insertions(+), 12 deletions(-)
drivers/mmc/host/sdhci-of-dwcmshc.c +2 -5
index 31c1892f4ecd..08b566984733 100644
@@ -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;
 
Quoted 8 lines
Quoted 7 lines

drivers/mmc/host/sdhci-of-dwcmshc.c static int dwcmshc_probe(struct platform_device *pdev) · line 506

Quoted 5 lines
drivers/mmc/host/sdhci-of-dwcmshc.c +2 -3
-		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)) {

"!" does not belong, should be "if (IS_ERR(priv->bus_clk))" instead

I'm sorry for this low-level mistake.

Quoted 3 lines

Although previously it seemed like the clock was optional. At least the error was not considered fatal.

Yes,this not a fatal mistake.

Quoted 31 lines
Quoted 19 lines
Quoted 19 lines
drivers/mmc/host/sdhci-of-dwcmshc.c +4 -2
+			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)
 
Quoted 8 lines

drivers/mmc/host/sdhci-of-dwcmshc.c static void dwcmshc_remove(struct platform_device *pdev) · line 586

Quoted 7 lines
drivers/mmc/host/sdhci-of-dwcmshc.c +0 -2
  	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);

.

Signature · 1 line
Yi