* [PATCH 0/4] Simplify code with helper function devm_clk_get*()
@ 2024-09-03 8:06 Zhang Zekun
2024-09-03 8:06 ` [PATCH 1/4] gpio: cadence: Use helper function devm_clk_get_enabled() Zhang Zekun
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Zhang Zekun @ 2024-09-03 8:06 UTC (permalink / raw)
To: linus.walleij, brgl, vz, linux-gpio; +Cc: zhangzekun11
Use helper function devm_clk_get_enabled() and
devm_clk_get_optional_enabled() to simplify code.
Zhang Zekun (4):
gpio: cadence: Use helper function devm_clk_get_enabled()
gpio: lpc18xx: Use helper function devm_clk_get_enabled()
gpio: mb86s7x: Use helper function devm_clk_get_enabled()
gpio: xilinx: Use helper function devm_clk_get_enabled()
drivers/gpio/gpio-cadence.c | 23 ++++++-----------------
drivers/gpio/gpio-lpc18xx.c | 23 ++++++-----------------
drivers/gpio/gpio-mb86s7x.c | 21 +++++++--------------
drivers/gpio/gpio-xilinx.c | 11 +----------
4 files changed, 20 insertions(+), 58 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/4] gpio: cadence: Use helper function devm_clk_get_enabled()
2024-09-03 8:06 [PATCH 0/4] Simplify code with helper function devm_clk_get*() Zhang Zekun
@ 2024-09-03 8:06 ` Zhang Zekun
2024-09-03 8:06 ` [PATCH 2/4] gpio: lpc18xx: " Zhang Zekun
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Zhang Zekun @ 2024-09-03 8:06 UTC (permalink / raw)
To: linus.walleij, brgl, vz, linux-gpio; +Cc: zhangzekun11
devm_clk_get() and clk_prepare_enable() can be replaced by helper
function devm_clk_get_enabled(). Let's use devm_clk_get_enabled() to
simplify code and avoid calling clk_disable_unprepare().
Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
---
drivers/gpio/gpio-cadence.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/gpio/gpio-cadence.c b/drivers/gpio/gpio-cadence.c
index 6a439cf78459..1b8ffd0ddab6 100644
--- a/drivers/gpio/gpio-cadence.c
+++ b/drivers/gpio/gpio-cadence.c
@@ -31,7 +31,6 @@
struct cdns_gpio_chip {
struct gpio_chip gc;
- struct clk *pclk;
void __iomem *regs;
u32 bypass_orig;
};
@@ -155,6 +154,7 @@ static int cdns_gpio_probe(struct platform_device *pdev)
int ret, irq;
u32 dir_prev;
u32 num_gpios = 32;
+ struct clk *clk;
cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL);
if (!cgpio)
@@ -203,21 +203,14 @@ static int cdns_gpio_probe(struct platform_device *pdev)
cgpio->gc.request = cdns_gpio_request;
cgpio->gc.free = cdns_gpio_free;
- cgpio->pclk = devm_clk_get(&pdev->dev, NULL);
- if (IS_ERR(cgpio->pclk)) {
- ret = PTR_ERR(cgpio->pclk);
+ clk = devm_clk_get_enabled(&pdev->dev, NULL);
+ if (IS_ERR(clk)) {
+ ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"Failed to retrieve peripheral clock, %d\n", ret);
goto err_revert_dir;
}
- ret = clk_prepare_enable(cgpio->pclk);
- if (ret) {
- dev_err(&pdev->dev,
- "Failed to enable the peripheral clock, %d\n", ret);
- goto err_revert_dir;
- }
-
/*
* Optional irq_chip support
*/
@@ -234,7 +227,7 @@ static int cdns_gpio_probe(struct platform_device *pdev)
GFP_KERNEL);
if (!girq->parents) {
ret = -ENOMEM;
- goto err_disable_clk;
+ goto err_revert_dir;
}
girq->parents[0] = irq;
girq->default_type = IRQ_TYPE_NONE;
@@ -244,7 +237,7 @@ static int cdns_gpio_probe(struct platform_device *pdev)
ret = devm_gpiochip_add_data(&pdev->dev, &cgpio->gc, cgpio);
if (ret < 0) {
dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
- goto err_disable_clk;
+ goto err_revert_dir;
}
cgpio->bypass_orig = ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE);
@@ -259,9 +252,6 @@ static int cdns_gpio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, cgpio);
return 0;
-err_disable_clk:
- clk_disable_unprepare(cgpio->pclk);
-
err_revert_dir:
iowrite32(dir_prev, cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
@@ -273,7 +263,6 @@ static void cdns_gpio_remove(struct platform_device *pdev)
struct cdns_gpio_chip *cgpio = platform_get_drvdata(pdev);
iowrite32(cgpio->bypass_orig, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
- clk_disable_unprepare(cgpio->pclk);
}
static const struct of_device_id cdns_of_ids[] = {
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/4] gpio: lpc18xx: Use helper function devm_clk_get_enabled()
2024-09-03 8:06 [PATCH 0/4] Simplify code with helper function devm_clk_get*() Zhang Zekun
2024-09-03 8:06 ` [PATCH 1/4] gpio: cadence: Use helper function devm_clk_get_enabled() Zhang Zekun
@ 2024-09-03 8:06 ` Zhang Zekun
2024-09-03 8:06 ` [PATCH 3/4] gpio: mb86s7x: " Zhang Zekun
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Zhang Zekun @ 2024-09-03 8:06 UTC (permalink / raw)
To: linus.walleij, brgl, vz, linux-gpio; +Cc: zhangzekun11
devm_clk_get() and clk_prepare_enable() can be replaced by helper
function devm_clk_get_enabled(). Let's use devm_clk_get_enabled() to
simplify code and avoid calling clk_disable_unprepare().
Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
---
drivers/gpio/gpio-lpc18xx.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/gpio/gpio-lpc18xx.c b/drivers/gpio/gpio-lpc18xx.c
index 5c6bb57a8c99..e7c0ef6e54fa 100644
--- a/drivers/gpio/gpio-lpc18xx.c
+++ b/drivers/gpio/gpio-lpc18xx.c
@@ -47,7 +47,6 @@ struct lpc18xx_gpio_pin_ic {
struct lpc18xx_gpio_chip {
struct gpio_chip gpio;
void __iomem *base;
- struct clk *clk;
struct lpc18xx_gpio_pin_ic *pin_ic;
spinlock_t lock;
};
@@ -328,6 +327,7 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct lpc18xx_gpio_chip *gc;
int index, ret;
+ struct clk *clk;
gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
if (!gc)
@@ -352,16 +352,10 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev)
if (IS_ERR(gc->base))
return PTR_ERR(gc->base);
- gc->clk = devm_clk_get(dev, NULL);
- if (IS_ERR(gc->clk)) {
+ clk = devm_clk_get_enabled(dev, NULL);
+ if (IS_ERR(clk)) {
dev_err(dev, "input clock not found\n");
- return PTR_ERR(gc->clk);
- }
-
- ret = clk_prepare_enable(gc->clk);
- if (ret) {
- dev_err(dev, "unable to enable clock\n");
- return ret;
+ return PTR_ERR(clk);
}
spin_lock_init(&gc->lock);
@@ -369,11 +363,8 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev)
gc->gpio.parent = dev;
ret = devm_gpiochip_add_data(dev, &gc->gpio, gc);
- if (ret) {
- dev_err(dev, "failed to add gpio chip\n");
- clk_disable_unprepare(gc->clk);
- return ret;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to add gpio chip\n");
/* On error GPIO pin interrupt controller just won't be registered */
lpc18xx_gpio_pin_ic_probe(gc);
@@ -387,8 +378,6 @@ static void lpc18xx_gpio_remove(struct platform_device *pdev)
if (gc->pin_ic)
irq_domain_remove(gc->pin_ic->domain);
-
- clk_disable_unprepare(gc->clk);
}
static const struct of_device_id lpc18xx_gpio_match[] = {
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] gpio: mb86s7x: Use helper function devm_clk_get_enabled()
2024-09-03 8:06 [PATCH 0/4] Simplify code with helper function devm_clk_get*() Zhang Zekun
2024-09-03 8:06 ` [PATCH 1/4] gpio: cadence: Use helper function devm_clk_get_enabled() Zhang Zekun
2024-09-03 8:06 ` [PATCH 2/4] gpio: lpc18xx: " Zhang Zekun
@ 2024-09-03 8:06 ` Zhang Zekun
2024-09-03 8:06 ` [PATCH 4/4] gpio: xilinx: " Zhang Zekun
2024-09-04 8:01 ` [PATCH 0/4] Simplify code with helper function devm_clk_get*() Bartosz Golaszewski
4 siblings, 0 replies; 8+ messages in thread
From: Zhang Zekun @ 2024-09-03 8:06 UTC (permalink / raw)
To: linus.walleij, brgl, vz, linux-gpio; +Cc: zhangzekun11
devm_clk_get() and clk_prepare_enable() can be replaced by helper
function devm_clk_get_enabled(). Let's use devm_clk_get_enabled() to
simplify code and avoid calling clk_disable_unprepare().
Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
---
drivers/gpio/gpio-mb86s7x.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/gpio/gpio-mb86s7x.c b/drivers/gpio/gpio-mb86s7x.c
index 7fb298b4571b..ccbb63c21d6f 100644
--- a/drivers/gpio/gpio-mb86s7x.c
+++ b/drivers/gpio/gpio-mb86s7x.c
@@ -35,7 +35,6 @@
struct mb86s70_gpio_chip {
struct gpio_chip gc;
void __iomem *base;
- struct clk *clk;
spinlock_t lock;
};
@@ -157,6 +156,7 @@ static int mb86s70_gpio_to_irq(struct gpio_chip *gc, unsigned int offset)
static int mb86s70_gpio_probe(struct platform_device *pdev)
{
struct mb86s70_gpio_chip *gchip;
+ struct clk *clk;
int ret;
gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL);
@@ -169,13 +169,9 @@ static int mb86s70_gpio_probe(struct platform_device *pdev)
if (IS_ERR(gchip->base))
return PTR_ERR(gchip->base);
- gchip->clk = devm_clk_get_optional(&pdev->dev, NULL);
- if (IS_ERR(gchip->clk))
- return PTR_ERR(gchip->clk);
-
- ret = clk_prepare_enable(gchip->clk);
- if (ret)
- return ret;
+ clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
+ if (IS_ERR(clk))
+ return PTR_ERR(clk);
spin_lock_init(&gchip->lock);
@@ -193,11 +189,9 @@ static int mb86s70_gpio_probe(struct platform_device *pdev)
gchip->gc.base = -1;
ret = gpiochip_add_data(&gchip->gc, gchip);
- if (ret) {
- dev_err(&pdev->dev, "couldn't register gpio driver\n");
- clk_disable_unprepare(gchip->clk);
- return ret;
- }
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "couldn't register gpio driver\n");
acpi_gpiochip_request_interrupts(&gchip->gc);
@@ -210,7 +204,6 @@ static void mb86s70_gpio_remove(struct platform_device *pdev)
acpi_gpiochip_free_interrupts(&gchip->gc);
gpiochip_remove(&gchip->gc);
- clk_disable_unprepare(gchip->clk);
}
static const struct of_device_id mb86s70_gpio_dt_ids[] = {
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/4] gpio: xilinx: Use helper function devm_clk_get_enabled()
2024-09-03 8:06 [PATCH 0/4] Simplify code with helper function devm_clk_get*() Zhang Zekun
` (2 preceding siblings ...)
2024-09-03 8:06 ` [PATCH 3/4] gpio: mb86s7x: " Zhang Zekun
@ 2024-09-03 8:06 ` Zhang Zekun
2024-09-04 8:01 ` [PATCH 0/4] Simplify code with helper function devm_clk_get*() Bartosz Golaszewski
4 siblings, 0 replies; 8+ messages in thread
From: Zhang Zekun @ 2024-09-03 8:06 UTC (permalink / raw)
To: linus.walleij, brgl, vz, linux-gpio; +Cc: zhangzekun11
devm_clk_get() and clk_prepare_enable() can be replaced by helper
function devm_clk_get_enabled(). Let's use devm_clk_get_enabled() to
simplify code and avoid calling clk_disable_unprepare().
Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
---
drivers/gpio/gpio-xilinx.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 7348df385198..afcf432a1573 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -333,12 +333,9 @@ static int __maybe_unused xgpio_suspend(struct device *dev)
*/
static void 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);
}
/**
@@ -644,15 +641,10 @@ 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");
- 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);
@@ -699,7 +691,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;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/4] Simplify code with helper function devm_clk_get*()
2024-09-03 8:06 [PATCH 0/4] Simplify code with helper function devm_clk_get*() Zhang Zekun
` (3 preceding siblings ...)
2024-09-03 8:06 ` [PATCH 4/4] gpio: xilinx: " Zhang Zekun
@ 2024-09-04 8:01 ` Bartosz Golaszewski
2024-09-04 8:44 ` zhangzekun (A)
4 siblings, 1 reply; 8+ messages in thread
From: Bartosz Golaszewski @ 2024-09-04 8:01 UTC (permalink / raw)
To: linus.walleij, brgl, vz, linux-gpio, Zhang Zekun; +Cc: Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
On Tue, 03 Sep 2024 16:06:23 +0800, Zhang Zekun wrote:
> Use helper function devm_clk_get_enabled() and
> devm_clk_get_optional_enabled() to simplify code.
>
> Zhang Zekun (4):
> gpio: cadence: Use helper function devm_clk_get_enabled()
> gpio: lpc18xx: Use helper function devm_clk_get_enabled()
> gpio: mb86s7x: Use helper function devm_clk_get_enabled()
> gpio: xilinx: Use helper function devm_clk_get_enabled()
>
> [...]
Applied, thanks!
[1/4] gpio: cadence: Use helper function devm_clk_get_enabled()
commit: 7cea93092a28d3338e242b08f8ee5099c82c1cb6
[2/4] gpio: lpc18xx: Use helper function devm_clk_get_enabled()
commit: c9e5cb9916fcf73ac8d2e0a1e35a9327bf0e347e
[3/4] gpio: mb86s7x: Use helper function devm_clk_get_enabled()
commit: 1c927fb131fffea28a7ebe00220071d400a11d53
[4/4] gpio: xilinx: Use helper function devm_clk_get_enabled()
commit: f8d5200bd59b9688f5f59ec8b1e06e8200dc4fda
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/4] Simplify code with helper function devm_clk_get*()
2024-09-04 8:01 ` [PATCH 0/4] Simplify code with helper function devm_clk_get*() Bartosz Golaszewski
@ 2024-09-04 8:44 ` zhangzekun (A)
2024-09-04 9:05 ` Bartosz Golaszewski
0 siblings, 1 reply; 8+ messages in thread
From: zhangzekun (A) @ 2024-09-04 8:44 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: Bartosz Golaszewski, vz, linux-gpio, linus.walleij
Hi, Bartosz,
After receiving your ack email, I find out some mistakes in the
commit message. In commit messages of patch [3/4] and patch [4/4],
devm_clk_get_enabled() should be replaced by
devm_clk_get_optional_enabled(). Sorry for making these mistakes. I
think I should send v2 to fix them.
Best Regards,
Zekun
在 2024/9/4 16:01, Bartosz Golaszewski 写道:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
>
> On Tue, 03 Sep 2024 16:06:23 +0800, Zhang Zekun wrote:
>> Use helper function devm_clk_get_enabled() and
>> devm_clk_get_optional_enabled() to simplify code.
>>
>> Zhang Zekun (4):
>> gpio: cadence: Use helper function devm_clk_get_enabled()
>> gpio: lpc18xx: Use helper function devm_clk_get_enabled()
>> gpio: mb86s7x: Use helper function devm_clk_get_enabled()
>> gpio: xilinx: Use helper function devm_clk_get_enabled()
>>
>> [...]
>
> Applied, thanks!
>
> [1/4] gpio: cadence: Use helper function devm_clk_get_enabled()
> commit: 7cea93092a28d3338e242b08f8ee5099c82c1cb6
> [2/4] gpio: lpc18xx: Use helper function devm_clk_get_enabled()
> commit: c9e5cb9916fcf73ac8d2e0a1e35a9327bf0e347e
> [3/4] gpio: mb86s7x: Use helper function devm_clk_get_enabled()
> commit: 1c927fb131fffea28a7ebe00220071d400a11d53
> [4/4] gpio: xilinx: Use helper function devm_clk_get_enabled()
> commit: f8d5200bd59b9688f5f59ec8b1e06e8200dc4fda
>
> Best regards,
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/4] Simplify code with helper function devm_clk_get*()
2024-09-04 8:44 ` zhangzekun (A)
@ 2024-09-04 9:05 ` Bartosz Golaszewski
0 siblings, 0 replies; 8+ messages in thread
From: Bartosz Golaszewski @ 2024-09-04 9:05 UTC (permalink / raw)
To: zhangzekun (A); +Cc: Bartosz Golaszewski, vz, linux-gpio, linus.walleij
On Wed, Sep 4, 2024 at 10:44 AM zhangzekun (A) <zhangzekun11@huawei.com> wrote:
>
> Hi, Bartosz,
>
> After receiving your ack email, I find out some mistakes in the
> commit message. In commit messages of patch [3/4] and patch [4/4],
> devm_clk_get_enabled() should be replaced by
> devm_clk_get_optional_enabled(). Sorry for making these mistakes. I
> think I should send v2 to fix them.
>
Ok, I'll back them out.
Bart
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-09-04 9:05 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-03 8:06 [PATCH 0/4] Simplify code with helper function devm_clk_get*() Zhang Zekun
2024-09-03 8:06 ` [PATCH 1/4] gpio: cadence: Use helper function devm_clk_get_enabled() Zhang Zekun
2024-09-03 8:06 ` [PATCH 2/4] gpio: lpc18xx: " Zhang Zekun
2024-09-03 8:06 ` [PATCH 3/4] gpio: mb86s7x: " Zhang Zekun
2024-09-03 8:06 ` [PATCH 4/4] gpio: xilinx: " Zhang Zekun
2024-09-04 8:01 ` [PATCH 0/4] Simplify code with helper function devm_clk_get*() Bartosz Golaszewski
2024-09-04 8:44 ` zhangzekun (A)
2024-09-04 9:05 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).