wdt: Add support for watchdogs on Kendryte K210
Subsystems (2)
v3 cover wdt: Add support for watchdogs on Kendryte K210
This series depends on
https://patchwork.ozlabs.org/project/uboot/patch/20200901195548.542737-1-seanga2 at gmail.com/
Changes in v3:
- Note dependency on "time: Fix get_ticks being non-monotonic"
- Add a few signed-off-bys which were sent for version 1
Changes in v2:
- Fix fls being off-by-one when compared to log_2_n_round_up
- Move watchdog enable to k210.dtsi as it does not depend on anything board-specific.
Sean Anderson (7):
wdt: dw: Switch to using fls for log2
wdt: dw: Switch to if(CONFIG()) instead of using #if
wdt: dw: Fix clock rate being off by 1000
wdt: dw: Enable the clock before using it
wdt: dw: Free the clock on error
riscv: Add watchdog bindings for the k210
riscv: Enable watchdog for the k210
arch/riscv/dts/k210.dtsi | 1 - board/sipeed/maix/Kconfig | 2 ++ drivers/watchdog/designware_wdt.c | 38 +++++++++++++++++++------------ 3 files changed, 26 insertions(+), 15 deletions(-)
Signature · 1 line
2.28.0
PATCH v3 1/7 wdt: dw: Switch to using fls for log2
log_2_n_round_up is only found in arm. fls performs the same job and is generic.
---
(no changes since v2)
Changes in v2:
- Fix fls being off-by-one when compared to log_2_n_round_up
drivers/watchdog/designware_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/designware_wdt.c +1 -2
@@ -9,7 +9,6 @@#include <reset.h> #include <wdt.h> #include <asm/io.h> -#include <asm/utils.h> #include <linux/bitops.h> #define DW_WDT_CR 0x00
@@ -35,7 +34,7 @@ static int designware_wdt_settimeout(void __iomem *base, unsigned int clk_khz,signed int i;/* calculate the timeout range value */ - i =log_2_n_round_up (timeout * clk_khz) -16 ; + i =fls (timeout * clk_khz -1 ) -16 ; i =clamp (i,0 ,15 );writel (i | (i <<4 ), base +DW_WDT_TORR );
Signature · 1 line
2.28.0
PATCH v3 1/7 wdt: dw: Switch to using fls for log2
Quoted 7 lines · Sean Anderson
log_2_n_round_upis only found in arm. fls performs the same job and is generic.Signed-off-by Sean Anderson <[email protected]>---
Quoted 8 lines
(no changes since v2)
Changes in v2:
- Fix fls being off-by-one when compared tolog_2_n_round_updrivers/watchdog/designware_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH v3 2/7 wdt: dw: Switch to if(CONFIG()) instead of using #if
In reply to Sean AndersonThis is preferred over #if because the compiler can check syntax even if the feature is disabled. This cannot be used for CONFIG_CLK because CONFIG_DW_WDT_CLOCK_KHZ is not defined on all platforms.
---
(no changes since v1)
drivers/watchdog/designware_wdt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/watchdog/designware_wdt.c +9 -9
@@ -136,17 +136,17 @@ static int designware_wdt_probe(struct udevice *dev) priv->clk_khz =CONFIG_DW_WDT_CLOCK_KHZ ;#endif -#if CONFIG_IS_ENABLED (DM_RESET ) -struct reset_ctl_bulk resets; +if (CONFIG_IS_ENABLED (DM_RESET )) { +struct reset_ctl_bulk resets; - ret =reset_get_bulk (dev, &resets); -if (ret) -return ret; + ret =reset_get_bulk (dev, &resets); +if (ret) +return ret; - ret =reset_deassert_bulk (&resets); -if (ret) -return ret; -#endif + ret =reset_deassert_bulk (&resets); +if (ret) +return ret; + }/* reset to disable the watchdog */ return designware_wdt_stop (dev);
Signature · 1 line
2.28.0
PATCH v3 3/7 wdt: dw: Fix clock rate being off by 1000
In reply to Sean AndersonThe clock subsystem returns clock rates in Hz. We need to divide by 1000 so the rate is in kHz.
---
(no changes since v1)
drivers/watchdog/designware_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/designware_wdt.c +1 -1
@@ -129,7 +129,7 @@ static int designware_wdt_probe(struct udevice *dev)if (ret)return ret; - priv->clk_khz =clk_get_rate (&clk); + priv->clk_khz =clk_get_rate (&clk) /1000 ;if (!priv->clk_khz)return -EINVAL ;#else
Signature · 1 line
2.28.0
PATCH v3 4/7 wdt: dw: Enable the clock before using it
In reply to Sean AndersonThe watchdog won't work if the clock isn't enabled.
---
(no changes since v1)
drivers/watchdog/designware_wdt.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/watchdog/designware_wdt.c +4 -0
@@ -129,6 +129,10 @@ static int designware_wdt_probe(struct udevice *dev)if (ret)return ret; + ret =clk_enable (&clk); +if (ret) +return ret; + priv->clk_khz =clk_get_rate (&clk) /1000 ;if (!priv->clk_khz)return -EINVAL ;
Signature · 1 line
2.28.0
PATCH v3 5/7 wdt: dw: Free the clock on error
In reply to Sean AndersonThe clock subsystem requires that clk_free be called on clocks obtained via clk_get_*.
---
(no changes since v1)
drivers/watchdog/designware_wdt.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/watchdog/designware_wdt.c +12 -5
@@ -131,11 +131,13 @@ static int designware_wdt_probe(struct udevice *dev) ret =clk_enable (&clk);if (ret) -return ret; + goto err; priv->clk_khz =clk_get_rate (&clk) /1000 ; -if (!priv->clk_khz) -return -EINVAL ; +if (!priv->clk_khz) { + ret = -EINVAL ; + goto err; + }#else priv->clk_khz =CONFIG_DW_WDT_CLOCK_KHZ ;#endif
@@ -145,15 +147,20 @@ static int designware_wdt_probe(struct udevice *dev) ret =reset_get_bulk (dev, &resets);if (ret) -return ret; + goto err; ret =reset_deassert_bulk (&resets);if (ret) -return ret; + goto err; }/* reset to disable the watchdog */ return designware_wdt_stop (dev); + +err: +if (CONFIG_IS_ENABLED (CLK )) +clk_free (&clk); +return ret; }static const struct wdt_ops designware_wdt_ops = {
Signature · 1 line
2.28.0
PATCH v3 5/7 wdt: dw: Free the clock on error
Quoted 41 lines · Sean Anderson
The clock subsystem requires that
clk_freebe called on clocks obtained via clk_get_*.Signed-off-by Sean Anderson <[email protected]>Reviewed-by Simon Glass <[email protected]>---
(no changes since v1)
drivers/watchdog/designware_wdt.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)drivers/watchdog/designware_wdt.c +6
-4@@ -131,11 +131,13 @@ static int designware_wdt_probe(struct udevice *dev) ret =clk_enable (&clk);if (ret) -return ret; + goto err; priv->clk_khz =clk_get_rate (&clk) /1000 ; -if (!priv->clk_khz) -return -EINVAL ; +if (!priv->clk_khz) { + ret = -EINVAL ; + goto err; + }#else priv->clk_khz =CONFIG_DW_WDT_CLOCK_KHZ ;#endif @@ -145,15 +147,20 @@ static int designware_wdt_probe(struct udevice *dev) ret =reset_get_bulk (dev, &resets);if (ret) -return ret; + goto err; ret =reset_deassert_bulk (&resets);
drivers/watchdog/designware_wdt.c static int designware_wdt_probe(struct udevice *dev) · line 161
Quoted 10 lines
drivers/watchdog/designware_wdt.c +4
-1if (ret) -return ret; + goto err; }/* reset to disable the watchdog */ return designware_wdt_stop (dev); + +err: +if (CONFIG_IS_ENABLED (CLK ))
This should be an #if. Found by running CI at
Will be fixed in v4.
--Sean
Quoted 6 lines
drivers/watchdog/designware_wdt.c +2
-0+clk_free (&clk); +return ret; }static const struct wdt_ops designware_wdt_ops = {
PATCH v3 6/7 riscv: Add watchdog bindings for the k210
In reply to Sean AndersonThis adds the necessary bindings. Most of them are already there.
---
(no changes since v2)
Changes in v2:
- Move watchdog enable to k210.dtsi as it does not depend on anything board-specific.
arch/riscv/dts/k210.dtsi | 1 - 1 file changed, 1 deletion(-)
arch/riscv/dts/k210.dtsi +0 -1
@@ -425,7 +425,6 @@ interrupts = <21>; clocks = <&sysclk K210_CLK_WDT0>; resets = <&sysrst K210_RST_WDT0>; - status = "disabled"; }; wdt1: watchdog at 50410000 {
Signature · 1 line
2.28.0
PATCH v3 7/7 riscv: Enable watchdog for the k210
In reply to Sean AndersonThis enables the necessary config options.
---
Changes in v3:
- Note dependency on "time: Fix get_ticks being non-monotonic"
- Add a few signed-off-bys which were sent for version 1
board/sipeed/maix/Kconfig | 2 ++ 1 file changed, 2 insertions(+)
board/sipeed/maix/Kconfig +2 -0
@@ -44,4 +44,6 @@ config BOARD_SPECIFIC_OPTIONS imply RESET_SYSCON imply SYSRESET imply SYSRESET_SYSCON + imply WDT + imply DESIGNWARE_WATCHDOG endif
Signature · 1 line
2.28.0
PATCH v3 7/7 riscv: Enable watchdog for the k210
Quoted 4 lines · Sean Anderson
This enables the necessary config options.
Signed-off-by Sean Anderson <[email protected]>
Quoted 8 lines
---
Changes in v3:
- Note dependency on "time: Fixget_ticksbeing non-monotonic"
- Add a few signed-off-bys which were sent for version 1board/sipeed/maix/Kconfig | 2 ++ 1 file changed, 2 insertions(+)
v3 cover wdt: Add support for watchdogs on Kendryte K210
In reply to Sean AndersonQuoted 2 lines · Sean Anderson
This series depends on
https://patchwork.ozlabs.org/project/uboot/patch/20200901195548.542737-1-seanga2 at gmail.com/
A note for those following along at home: after further investigation, this series depends on [1]. It works with v1 of the above patch (as linked), but if one applies v2 [2], it will panic without [1].
[1] https://patchwork.ozlabs.org/project/uboot/list/?series=200642
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=200645
Quoted 24 lines
Changes in v3:
- Note dependency on "time: Fixget_ticksbeing non-monotonic"
- Add a few signed-off-bys which were sent for version 1Changes in v2:
- Fix fls being off-by-one when compared tolog_2_n_round_up
- Move watchdog enable tok210.dtsias it does not depend on anything board-specific.Sean Anderson (7):
wdt: dw: Switch to using fls for log2
wdt: dw: Switch to if(CONFIG()) instead of using #if
wdt: dw: Fix clock rate being off by 1000
wdt: dw: Enable the clock before using it
wdt: dw: Free the clock on error
riscv: Add watchdog bindings for the k210
riscv: Enable watchdog for the k210arch/riscv/dts/k210.dtsi | 1 - board/sipeed/maix/Kconfig | 2 ++ drivers/watchdog/designware_wdt.c | 38 +++++++++++++++++++------------ 3 files changed, 26 insertions(+), 15 deletions(-)