* [PATCH -next 1/3] watchdog: at91sam9_wdt: Use the devm_clk_get_enabled() helper function
@ 2023-08-24 13:55 Jinjie Ruan
2023-08-24 13:55 ` [PATCH -next 2/3] watchdog: ath79_wdt: " Jinjie Ruan
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Jinjie Ruan @ 2023-08-24 13:55 UTC (permalink / raw)
To: linux-watchdog, linux-arm-kernel, wim, linux, nicolas.ferre,
alexandre.belloni, claudiu.beznea, xt.hu
Cc: ruanjinjie
The devm_clk_get_enabled() helper:
- calls devm_clk_get()
- calls clk_prepare_enable() and registers what is needed in order to
call clk_disable_unprepare() when needed, as a managed resource.
This simplifies the code.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/watchdog/at91sam9_wdt.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index fed7be246442..b111b28acb94 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -348,25 +348,21 @@ static int __init at91wdt_probe(struct platform_device *pdev)
if (IS_ERR(wdt->base))
return PTR_ERR(wdt->base);
- wdt->sclk = devm_clk_get(&pdev->dev, NULL);
- if (IS_ERR(wdt->sclk))
- return PTR_ERR(wdt->sclk);
-
- err = clk_prepare_enable(wdt->sclk);
- if (err) {
+ wdt->sclk = devm_clk_get_enabled(&pdev->dev, NULL);
+ if (IS_ERR(wdt->sclk)) {
dev_err(&pdev->dev, "Could not enable slow clock\n");
- return err;
+ return PTR_ERR(wdt->sclk);
}
if (pdev->dev.of_node) {
err = of_at91wdt_init(pdev->dev.of_node, wdt);
if (err)
- goto err_clk;
+ return err;
}
err = at91_wdt_init(pdev, wdt);
if (err)
- goto err_clk;
+ return err;
platform_set_drvdata(pdev, wdt);
@@ -374,11 +370,6 @@ static int __init at91wdt_probe(struct platform_device *pdev)
wdt->wdd.timeout, wdt->nowayout);
return 0;
-
-err_clk:
- clk_disable_unprepare(wdt->sclk);
-
- return err;
}
static int __exit at91wdt_remove(struct platform_device *pdev)
@@ -388,7 +379,6 @@ static int __exit at91wdt_remove(struct platform_device *pdev)
pr_warn("I quit now, hardware will probably reboot!\n");
del_timer(&wdt->timer);
- clk_disable_unprepare(wdt->sclk);
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH -next 2/3] watchdog: ath79_wdt: Use the devm_clk_get_enabled() helper function
2023-08-24 13:55 [PATCH -next 1/3] watchdog: at91sam9_wdt: Use the devm_clk_get_enabled() helper function Jinjie Ruan
@ 2023-08-24 13:55 ` Jinjie Ruan
2023-08-24 15:47 ` Guenter Roeck
2023-08-24 13:55 ` [PATCH -next 3/3] watchdog: sunplus: " Jinjie Ruan
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Jinjie Ruan @ 2023-08-24 13:55 UTC (permalink / raw)
To: linux-watchdog, linux-arm-kernel, wim, linux, nicolas.ferre,
alexandre.belloni, claudiu.beznea, xt.hu
Cc: ruanjinjie
The devm_clk_get_enabled() helper:
- calls devm_clk_get()
- calls clk_prepare_enable() and registers what is needed in order to
call clk_disable_unprepare() when needed, as a managed resource.
This simplifies the code.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/watchdog/ath79_wdt.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/drivers/watchdog/ath79_wdt.c b/drivers/watchdog/ath79_wdt.c
index b7b705060438..e5cc30622b12 100644
--- a/drivers/watchdog/ath79_wdt.c
+++ b/drivers/watchdog/ath79_wdt.c
@@ -257,19 +257,13 @@ static int ath79_wdt_probe(struct platform_device *pdev)
if (IS_ERR(wdt_base))
return PTR_ERR(wdt_base);
- wdt_clk = devm_clk_get(&pdev->dev, "wdt");
+ wdt_clk = devm_clk_get_enabled(&pdev->dev, "wdt");
if (IS_ERR(wdt_clk))
return PTR_ERR(wdt_clk);
- err = clk_prepare_enable(wdt_clk);
- if (err)
- return err;
-
wdt_freq = clk_get_rate(wdt_clk);
- if (!wdt_freq) {
- err = -EINVAL;
- goto err_clk_disable;
- }
+ if (!wdt_freq)
+ return -EINVAL;
max_timeout = (0xfffffffful / wdt_freq);
if (timeout < 1 || timeout > max_timeout) {
@@ -286,20 +280,15 @@ static int ath79_wdt_probe(struct platform_device *pdev)
if (err) {
dev_err(&pdev->dev,
"unable to register misc device, err=%d\n", err);
- goto err_clk_disable;
+ return err;
}
return 0;
-
-err_clk_disable:
- clk_disable_unprepare(wdt_clk);
- return err;
}
static void ath79_wdt_remove(struct platform_device *pdev)
{
misc_deregister(&ath79_wdt_miscdev);
- clk_disable_unprepare(wdt_clk);
}
static void ath79_wdt_shutdown(struct platform_device *pdev)
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH -next 3/3] watchdog: sunplus: Use the devm_clk_get_enabled() helper function
2023-08-24 13:55 [PATCH -next 1/3] watchdog: at91sam9_wdt: Use the devm_clk_get_enabled() helper function Jinjie Ruan
2023-08-24 13:55 ` [PATCH -next 2/3] watchdog: ath79_wdt: " Jinjie Ruan
@ 2023-08-24 13:55 ` Jinjie Ruan
2023-08-24 15:47 ` Guenter Roeck
2023-08-24 15:46 ` [PATCH -next 1/3] watchdog: at91sam9_wdt: " Guenter Roeck
2023-08-25 4:15 ` claudiu beznea
3 siblings, 1 reply; 7+ messages in thread
From: Jinjie Ruan @ 2023-08-24 13:55 UTC (permalink / raw)
To: linux-watchdog, linux-arm-kernel, wim, linux, nicolas.ferre,
alexandre.belloni, claudiu.beznea, xt.hu
Cc: ruanjinjie
watchdog: ath79_wdt: Use the devm_clk_get_enabled() helper function
The devm_clk_get_enabled() helper:
- calls devm_clk_get()
- calls clk_prepare_enable() and registers what is needed in order to
call clk_disable_unprepare() when needed, as a managed resource.
This simplifies the code and avoids the need of a dedicated function used
with devm_add_action_or_reset().
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/watchdog/sunplus_wdt.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/drivers/watchdog/sunplus_wdt.c b/drivers/watchdog/sunplus_wdt.c
index e2d8c532bcb1..9d3ca848e8b6 100644
--- a/drivers/watchdog/sunplus_wdt.c
+++ b/drivers/watchdog/sunplus_wdt.c
@@ -136,11 +136,6 @@ static const struct watchdog_ops sp_wdt_ops = {
.restart = sp_wdt_restart,
};
-static void sp_clk_disable_unprepare(void *data)
-{
- clk_disable_unprepare(data);
-}
-
static void sp_reset_control_assert(void *data)
{
reset_control_assert(data);
@@ -156,17 +151,9 @@ static int sp_wdt_probe(struct platform_device *pdev)
if (!priv)
return -ENOMEM;
- priv->clk = devm_clk_get(dev, NULL);
+ priv->clk = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(priv->clk))
- return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to get clock\n");
-
- ret = clk_prepare_enable(priv->clk);
- if (ret)
- return dev_err_probe(dev, ret, "Failed to enable clock\n");
-
- ret = devm_add_action_or_reset(dev, sp_clk_disable_unprepare, priv->clk);
- if (ret)
- return ret;
+ return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to enable clock\n");
/* The timer and watchdog shared the STC reset */
priv->rstc = devm_reset_control_get_shared(dev, NULL);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH -next 1/3] watchdog: at91sam9_wdt: Use the devm_clk_get_enabled() helper function
2023-08-24 13:55 [PATCH -next 1/3] watchdog: at91sam9_wdt: Use the devm_clk_get_enabled() helper function Jinjie Ruan
2023-08-24 13:55 ` [PATCH -next 2/3] watchdog: ath79_wdt: " Jinjie Ruan
2023-08-24 13:55 ` [PATCH -next 3/3] watchdog: sunplus: " Jinjie Ruan
@ 2023-08-24 15:46 ` Guenter Roeck
2023-08-25 4:15 ` claudiu beznea
3 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2023-08-24 15:46 UTC (permalink / raw)
To: Jinjie Ruan
Cc: linux-watchdog, linux-arm-kernel, wim, nicolas.ferre,
alexandre.belloni, claudiu.beznea, xt.hu
On Thu, Aug 24, 2023 at 09:55:12PM +0800, Jinjie Ruan wrote:
> The devm_clk_get_enabled() helper:
> - calls devm_clk_get()
> - calls clk_prepare_enable() and registers what is needed in order to
> call clk_disable_unprepare() when needed, as a managed resource.
>
> This simplifies the code.
>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/watchdog/at91sam9_wdt.c | 20 +++++---------------
> 1 file changed, 5 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
> index fed7be246442..b111b28acb94 100644
> --- a/drivers/watchdog/at91sam9_wdt.c
> +++ b/drivers/watchdog/at91sam9_wdt.c
> @@ -348,25 +348,21 @@ static int __init at91wdt_probe(struct platform_device *pdev)
> if (IS_ERR(wdt->base))
> return PTR_ERR(wdt->base);
>
> - wdt->sclk = devm_clk_get(&pdev->dev, NULL);
> - if (IS_ERR(wdt->sclk))
> - return PTR_ERR(wdt->sclk);
> -
> - err = clk_prepare_enable(wdt->sclk);
> - if (err) {
> + wdt->sclk = devm_clk_get_enabled(&pdev->dev, NULL);
> + if (IS_ERR(wdt->sclk)) {
> dev_err(&pdev->dev, "Could not enable slow clock\n");
> - return err;
> + return PTR_ERR(wdt->sclk);
> }
>
> if (pdev->dev.of_node) {
> err = of_at91wdt_init(pdev->dev.of_node, wdt);
> if (err)
> - goto err_clk;
> + return err;
> }
>
> err = at91_wdt_init(pdev, wdt);
> if (err)
> - goto err_clk;
> + return err;
>
> platform_set_drvdata(pdev, wdt);
>
> @@ -374,11 +370,6 @@ static int __init at91wdt_probe(struct platform_device *pdev)
> wdt->wdd.timeout, wdt->nowayout);
>
> return 0;
> -
> -err_clk:
> - clk_disable_unprepare(wdt->sclk);
> -
> - return err;
> }
>
> static int __exit at91wdt_remove(struct platform_device *pdev)
> @@ -388,7 +379,6 @@ static int __exit at91wdt_remove(struct platform_device *pdev)
>
> pr_warn("I quit now, hardware will probably reboot!\n");
> del_timer(&wdt->timer);
> - clk_disable_unprepare(wdt->sclk);
>
> return 0;
> }
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH -next 2/3] watchdog: ath79_wdt: Use the devm_clk_get_enabled() helper function
2023-08-24 13:55 ` [PATCH -next 2/3] watchdog: ath79_wdt: " Jinjie Ruan
@ 2023-08-24 15:47 ` Guenter Roeck
0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2023-08-24 15:47 UTC (permalink / raw)
To: Jinjie Ruan
Cc: linux-watchdog, linux-arm-kernel, wim, nicolas.ferre,
alexandre.belloni, claudiu.beznea, xt.hu
On Thu, Aug 24, 2023 at 09:55:13PM +0800, Jinjie Ruan wrote:
> The devm_clk_get_enabled() helper:
> - calls devm_clk_get()
> - calls clk_prepare_enable() and registers what is needed in order to
> call clk_disable_unprepare() when needed, as a managed resource.
>
> This simplifies the code.
>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/watchdog/ath79_wdt.c | 19 ++++---------------
> 1 file changed, 4 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/watchdog/ath79_wdt.c b/drivers/watchdog/ath79_wdt.c
> index b7b705060438..e5cc30622b12 100644
> --- a/drivers/watchdog/ath79_wdt.c
> +++ b/drivers/watchdog/ath79_wdt.c
> @@ -257,19 +257,13 @@ static int ath79_wdt_probe(struct platform_device *pdev)
> if (IS_ERR(wdt_base))
> return PTR_ERR(wdt_base);
>
> - wdt_clk = devm_clk_get(&pdev->dev, "wdt");
> + wdt_clk = devm_clk_get_enabled(&pdev->dev, "wdt");
> if (IS_ERR(wdt_clk))
> return PTR_ERR(wdt_clk);
>
> - err = clk_prepare_enable(wdt_clk);
> - if (err)
> - return err;
> -
> wdt_freq = clk_get_rate(wdt_clk);
> - if (!wdt_freq) {
> - err = -EINVAL;
> - goto err_clk_disable;
> - }
> + if (!wdt_freq)
> + return -EINVAL;
>
> max_timeout = (0xfffffffful / wdt_freq);
> if (timeout < 1 || timeout > max_timeout) {
> @@ -286,20 +280,15 @@ static int ath79_wdt_probe(struct platform_device *pdev)
> if (err) {
> dev_err(&pdev->dev,
> "unable to register misc device, err=%d\n", err);
> - goto err_clk_disable;
> + return err;
> }
>
> return 0;
> -
> -err_clk_disable:
> - clk_disable_unprepare(wdt_clk);
> - return err;
> }
>
> static void ath79_wdt_remove(struct platform_device *pdev)
> {
> misc_deregister(&ath79_wdt_miscdev);
> - clk_disable_unprepare(wdt_clk);
> }
>
> static void ath79_wdt_shutdown(struct platform_device *pdev)
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH -next 3/3] watchdog: sunplus: Use the devm_clk_get_enabled() helper function
2023-08-24 13:55 ` [PATCH -next 3/3] watchdog: sunplus: " Jinjie Ruan
@ 2023-08-24 15:47 ` Guenter Roeck
0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2023-08-24 15:47 UTC (permalink / raw)
To: Jinjie Ruan
Cc: linux-watchdog, linux-arm-kernel, wim, nicolas.ferre,
alexandre.belloni, claudiu.beznea, xt.hu
On Thu, Aug 24, 2023 at 09:55:14PM +0800, Jinjie Ruan wrote:
> watchdog: ath79_wdt: Use the devm_clk_get_enabled() helper function
>
> The devm_clk_get_enabled() helper:
> - calls devm_clk_get()
> - calls clk_prepare_enable() and registers what is needed in order to
> call clk_disable_unprepare() when needed, as a managed resource.
>
> This simplifies the code and avoids the need of a dedicated function used
> with devm_add_action_or_reset().
>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/watchdog/sunplus_wdt.c | 17 ++---------------
> 1 file changed, 2 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/watchdog/sunplus_wdt.c b/drivers/watchdog/sunplus_wdt.c
> index e2d8c532bcb1..9d3ca848e8b6 100644
> --- a/drivers/watchdog/sunplus_wdt.c
> +++ b/drivers/watchdog/sunplus_wdt.c
> @@ -136,11 +136,6 @@ static const struct watchdog_ops sp_wdt_ops = {
> .restart = sp_wdt_restart,
> };
>
> -static void sp_clk_disable_unprepare(void *data)
> -{
> - clk_disable_unprepare(data);
> -}
> -
> static void sp_reset_control_assert(void *data)
> {
> reset_control_assert(data);
> @@ -156,17 +151,9 @@ static int sp_wdt_probe(struct platform_device *pdev)
> if (!priv)
> return -ENOMEM;
>
> - priv->clk = devm_clk_get(dev, NULL);
> + priv->clk = devm_clk_get_enabled(dev, NULL);
> if (IS_ERR(priv->clk))
> - return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to get clock\n");
> -
> - ret = clk_prepare_enable(priv->clk);
> - if (ret)
> - return dev_err_probe(dev, ret, "Failed to enable clock\n");
> -
> - ret = devm_add_action_or_reset(dev, sp_clk_disable_unprepare, priv->clk);
> - if (ret)
> - return ret;
> + return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to enable clock\n");
>
> /* The timer and watchdog shared the STC reset */
> priv->rstc = devm_reset_control_get_shared(dev, NULL);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH -next 1/3] watchdog: at91sam9_wdt: Use the devm_clk_get_enabled() helper function
2023-08-24 13:55 [PATCH -next 1/3] watchdog: at91sam9_wdt: Use the devm_clk_get_enabled() helper function Jinjie Ruan
` (2 preceding siblings ...)
2023-08-24 15:46 ` [PATCH -next 1/3] watchdog: at91sam9_wdt: " Guenter Roeck
@ 2023-08-25 4:15 ` claudiu beznea
3 siblings, 0 replies; 7+ messages in thread
From: claudiu beznea @ 2023-08-25 4:15 UTC (permalink / raw)
To: Jinjie Ruan, linux-watchdog, linux-arm-kernel, wim, linux,
nicolas.ferre, alexandre.belloni, xt.hu
On 8/24/23 16:55, Jinjie Ruan wrote:
> The devm_clk_get_enabled() helper:
> - calls devm_clk_get()
> - calls clk_prepare_enable() and registers what is needed in order to
> call clk_disable_unprepare() when needed, as a managed resource.
>
> This simplifies the code.
>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Claudiu Beznea <claudiu.beznea@tuxon.dev>
> ---
> drivers/watchdog/at91sam9_wdt.c | 20 +++++---------------
> 1 file changed, 5 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
> index fed7be246442..b111b28acb94 100644
> --- a/drivers/watchdog/at91sam9_wdt.c
> +++ b/drivers/watchdog/at91sam9_wdt.c
> @@ -348,25 +348,21 @@ static int __init at91wdt_probe(struct platform_device *pdev)
> if (IS_ERR(wdt->base))
> return PTR_ERR(wdt->base);
>
> - wdt->sclk = devm_clk_get(&pdev->dev, NULL);
> - if (IS_ERR(wdt->sclk))
> - return PTR_ERR(wdt->sclk);
> -
> - err = clk_prepare_enable(wdt->sclk);
> - if (err) {
> + wdt->sclk = devm_clk_get_enabled(&pdev->dev, NULL);
> + if (IS_ERR(wdt->sclk)) {
> dev_err(&pdev->dev, "Could not enable slow clock\n");
> - return err;
> + return PTR_ERR(wdt->sclk);
> }
>
> if (pdev->dev.of_node) {
> err = of_at91wdt_init(pdev->dev.of_node, wdt);
> if (err)
> - goto err_clk;
> + return err;
> }
>
> err = at91_wdt_init(pdev, wdt);
> if (err)
> - goto err_clk;
> + return err;
>
> platform_set_drvdata(pdev, wdt);
>
> @@ -374,11 +370,6 @@ static int __init at91wdt_probe(struct platform_device *pdev)
> wdt->wdd.timeout, wdt->nowayout);
>
> return 0;
> -
> -err_clk:
> - clk_disable_unprepare(wdt->sclk);
> -
> - return err;
> }
>
> static int __exit at91wdt_remove(struct platform_device *pdev)
> @@ -388,7 +379,6 @@ static int __exit at91wdt_remove(struct platform_device *pdev)
>
> pr_warn("I quit now, hardware will probably reboot!\n");
> del_timer(&wdt->timer);
> - clk_disable_unprepare(wdt->sclk);
>
> return 0;
> }
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-08-25 4:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-24 13:55 [PATCH -next 1/3] watchdog: at91sam9_wdt: Use the devm_clk_get_enabled() helper function Jinjie Ruan
2023-08-24 13:55 ` [PATCH -next 2/3] watchdog: ath79_wdt: " Jinjie Ruan
2023-08-24 15:47 ` Guenter Roeck
2023-08-24 13:55 ` [PATCH -next 3/3] watchdog: sunplus: " Jinjie Ruan
2023-08-24 15:47 ` Guenter Roeck
2023-08-24 15:46 ` [PATCH -next 1/3] watchdog: at91sam9_wdt: " Guenter Roeck
2023-08-25 4:15 ` claudiu beznea
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).