diff mbox series

gpio: Simplify using devm_clk_get_enabled()

Message ID 20240820083323.62485-1-rongqianfeng@vivo.com (mailing list archive)
State New, archived
Headers show
Series gpio: Simplify using devm_clk_get_enabled() | expand

Commit Message

Rong Qianfeng Aug. 20, 2024, 8:33 a.m. UTC
devm_clk_get_enabled() will call devm_clk_get() + clk_prepare_enable()
and the clock will automatically be disabled, unprepared and freed when
the device is unbound from the bus. So simplify .probe() and .remove()
accordingly.

Signed-off-by: Rong Qianfeng <rongqianfeng@vivo.com>
---
 drivers/gpio/gpio-davinci.c  | 13 ++-----------
 drivers/gpio/gpio-stp-xway.c | 10 ++--------
 drivers/gpio/gpio-zynq.c     | 10 +---------
 3 files changed, 5 insertions(+), 28 deletions(-)

Comments

Bartosz Golaszewski Aug. 20, 2024, 8:36 a.m. UTC | #1
On Tue, Aug 20, 2024 at 10:33 AM Rong Qianfeng <rongqianfeng@vivo.com> wrote:
>
> devm_clk_get_enabled() will call devm_clk_get() + clk_prepare_enable()
> and the clock will automatically be disabled, unprepared and freed when
> the device is unbound from the bus. So simplify .probe() and .remove()
> accordingly.
>
> Signed-off-by: Rong Qianfeng <rongqianfeng@vivo.com>
> ---
>  drivers/gpio/gpio-davinci.c  | 13 ++-----------
>  drivers/gpio/gpio-stp-xway.c | 10 ++--------
>  drivers/gpio/gpio-zynq.c     | 10 +---------
>  3 files changed, 5 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c

I already sent a patch like that for davinci, please drop that part.
Please split the other two into their separate per-driver patches.

Bart
Rong Qianfeng Aug. 20, 2024, 9:01 a.m. UTC | #2
在 2024/8/20 16:36, Bartosz Golaszewski 写道:
> On Tue, Aug 20, 2024 at 10:33 AM Rong Qianfeng <rongqianfeng@vivo.com> wrote:
>> devm_clk_get_enabled() will call devm_clk_get() + clk_prepare_enable()
>> and the clock will automatically be disabled, unprepared and freed when
>> the device is unbound from the bus. So simplify .probe() and .remove()
>> accordingly.
>>
>> Signed-off-by: Rong Qianfeng <rongqianfeng@vivo.com>
>> ---
>>   drivers/gpio/gpio-davinci.c  | 13 ++-----------
>>   drivers/gpio/gpio-stp-xway.c | 10 ++--------
>>   drivers/gpio/gpio-zynq.c     | 10 +---------
>>   3 files changed, 5 insertions(+), 28 deletions(-)
>>
>> diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
> I already sent a patch like that for davinci, please drop that part.
> Please split the other two into their separate per-driver patches.
Ok.

Best regards,
Qianfeng
>
> Bart
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 1d0175d6350b..945832d54ac3
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -482,7 +482,6 @@  static int davinci_gpio_irq_setup(struct platform_device *pdev)
 {
 	unsigned	gpio, bank;
 	int		irq;
-	int		ret;
 	struct clk	*clk;
 	u32		binten = 0;
 	unsigned	ngpio;
@@ -504,21 +503,16 @@  static int davinci_gpio_irq_setup(struct platform_device *pdev)
 
 	ngpio = pdata->ngpio;
 
-	clk = devm_clk_get(dev, "gpio");
+	clk = devm_clk_get_enabled(dev, "gpio");
 	if (IS_ERR(clk)) {
 		dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk));
 		return PTR_ERR(clk);
 	}
 
-	ret = clk_prepare_enable(clk);
-	if (ret)
-		return ret;
-
 	if (!pdata->gpio_unbanked) {
 		irq = devm_irq_alloc_descs(dev, -1, 0, ngpio, 0);
 		if (irq < 0) {
 			dev_err(dev, "Couldn't allocate IRQ numbers\n");
-			clk_disable_unprepare(clk);
 			return irq;
 		}
 
@@ -527,7 +521,6 @@  static int davinci_gpio_irq_setup(struct platform_device *pdev)
 							chips);
 		if (!irq_domain) {
 			dev_err(dev, "Couldn't register an IRQ domain\n");
-			clk_disable_unprepare(clk);
 			return -ENODEV;
 		}
 	}
@@ -596,10 +589,8 @@  static int davinci_gpio_irq_setup(struct platform_device *pdev)
 				       sizeof(struct
 					      davinci_gpio_irq_data),
 					      GFP_KERNEL);
-		if (!irqdata) {
-			clk_disable_unprepare(clk);
+		if (!irqdata)
 			return -ENOMEM;
-		}
 
 		irqdata->regs = g;
 		irqdata->bank_num = bank;
diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c
index 053d616f2e02..5a6406d1f03a
--- a/drivers/gpio/gpio-stp-xway.c
+++ b/drivers/gpio/gpio-stp-xway.c
@@ -296,23 +296,17 @@  static int xway_stp_probe(struct platform_device *pdev)
 	if (!of_property_read_bool(pdev->dev.of_node, "lantiq,rising"))
 		chip->edge = XWAY_STP_FALLING;
 
-	clk = devm_clk_get(&pdev->dev, NULL);
+	clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "Failed to get clock\n");
 		return PTR_ERR(clk);
 	}
 
-	ret = clk_prepare_enable(clk);
-	if (ret)
-		return ret;
-
 	xway_stp_hw_init(chip);
 
 	ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip);
-	if (ret) {
-		clk_disable_unprepare(clk);
+	if (ret)
 		return ret;
-	}
 
 	dev_info(&pdev->dev, "Init done\n");
 
diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c
index 466e23031afc..1a42336dfc1d
--- a/drivers/gpio/gpio-zynq.c
+++ b/drivers/gpio/gpio-zynq.c
@@ -940,16 +940,10 @@  static int zynq_gpio_probe(struct platform_device *pdev)
 	chip->ngpio = gpio->p_data->ngpio;
 
 	/* Retrieve GPIO clock */
-	gpio->clk = devm_clk_get(&pdev->dev, NULL);
+	gpio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(gpio->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(gpio->clk), "input clock not found.\n");
 
-	ret = clk_prepare_enable(gpio->clk);
-	if (ret) {
-		dev_err(&pdev->dev, "Unable to enable clock.\n");
-		return ret;
-	}
-
 	spin_lock_init(&gpio->dirlock);
 
 	pm_runtime_set_active(&pdev->dev);
@@ -999,7 +993,6 @@  static int zynq_gpio_probe(struct platform_device *pdev)
 	pm_runtime_put(&pdev->dev);
 err_pm_dis:
 	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(gpio->clk);
 
 	return ret;
 }
@@ -1019,7 +1012,6 @@  static void zynq_gpio_remove(struct platform_device *pdev)
 	if (ret < 0)
 		dev_warn(&pdev->dev, "pm_runtime_get_sync() Failed\n");
 	gpiochip_remove(&gpio->chip);
-	clk_disable_unprepare(gpio->clk);
 	device_set_wakeup_capable(&pdev->dev, 0);
 	pm_runtime_disable(&pdev->dev);
 }