diff mbox series

[-next,10/11] gpio: xilinx: Use helper function devm_clk_get_optional_enabled()

Message ID 20230818093018.1051434-11-lizetao1@huawei.com
State Handled Elsewhere
Headers show
Series gpio: Use devm_clk_get_*() helper function to simplify the drivers. | expand

Commit Message

Li Zetao Aug. 18, 2023, 9:30 a.m. UTC
Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
prepared and enabled clocks"), devm_clk_get_optional() and
clk_prepare_enable() can now be replaced by
devm_clk_get_optional_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: Li Zetao <lizetao1@huawei.com>
---
 drivers/gpio/gpio-xilinx.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

Comments

Andy Shevchenko Aug. 18, 2023, 3:12 p.m. UTC | #1
On Fri, Aug 18, 2023 at 05:30:17PM +0800, Li Zetao wrote:
> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
> prepared and enabled clocks"), devm_clk_get_optional() and
> clk_prepare_enable() can now be replaced by
> devm_clk_get_optional_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.

...

>  	if (IS_ERR(chip->clk))
> -		return dev_err_probe(&pdev->dev, PTR_ERR(chip->clk), "input clock not found.\n");
> +		return dev_err_probe(&pdev->dev, PTR_ERR(chip->clk),
> +				     "input clock not found or failed to prepare clk\n");

Don't alter message in this change.

...

Do you need to set driver data now?
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index a16945e8319e..4e4da07bf8a2 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -334,12 +334,9 @@  static int __maybe_unused xgpio_suspend(struct device *dev)
  */
 static int xgpio_remove(struct platform_device *pdev)
 {
-	struct xgpio_instance *gpio = platform_get_drvdata(pdev);
-
 	pm_runtime_get_sync(&pdev->dev);
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(gpio->clk);
 
 	return 0;
 }
@@ -647,15 +644,11 @@  static int xgpio_probe(struct platform_device *pdev)
 		return PTR_ERR(chip->regs);
 	}
 
-	chip->clk = devm_clk_get_optional(&pdev->dev, NULL);
+	chip->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
 	if (IS_ERR(chip->clk))
-		return dev_err_probe(&pdev->dev, PTR_ERR(chip->clk), "input clock not found.\n");
+		return dev_err_probe(&pdev->dev, PTR_ERR(chip->clk),
+				     "input clock not found or failed to prepare clk\n");
 
-	status = clk_prepare_enable(chip->clk);
-	if (status < 0) {
-		dev_err(&pdev->dev, "Failed to prepare clk\n");
-		return status;
-	}
 	pm_runtime_get_noresume(&pdev->dev);
 	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
@@ -702,7 +695,6 @@  static int xgpio_probe(struct platform_device *pdev)
 err_pm_put:
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_put_noidle(&pdev->dev);
-	clk_disable_unprepare(chip->clk);
 	return status;
 }