[PATCH v5 0/6] wdt: Add support for watchdogs on Kendryte K210

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH v5 0/6] wdt: Add support for watchdogs on Kendryte K210

Sean Anderson
This series depends on
https://patchwork.ozlabs.org/project/uboot/list/?series=200642

Changes in v5:
- Rebase on u-boot/master

Changes in v4:
- Fix build error without CONFIG_CLK

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 (6):
  wdt: dw: Switch to using fls for log2
  wdt: dw: Switch to if(CONFIG()) instead of using #if
  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 | 37 ++++++++++++++++++++-----------
 3 files changed, 26 insertions(+), 14 deletions(-)

--
2.29.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v5 1/6] wdt: dw: Switch to using fls for log2

Sean Anderson
log_2_n_round_up is only found in arm. fls performs the same job and is
generic.

Signed-off-by: Sean Anderson <[hidden email]>
Reviewed-by: Simon Glass <[hidden email]>
---

(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(-)

diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c
index 7caa6c550c..c0f43785a9 100644
--- a/drivers/watchdog/designware_wdt.c
+++ b/drivers/watchdog/designware_wdt.c
@@ -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);
--
2.29.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v5 2/6] wdt: dw: Switch to if(CONFIG()) instead of using #if

Sean Anderson
In reply to this post by Sean Anderson
This 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.

Signed-off-by: Sean Anderson <[hidden email]>
Reviewed-by: Heinrich Schuchardt <[hidden email]>
---

(no changes since v1)

 drivers/watchdog/designware_wdt.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c
index c0f43785a9..41866fa01b 100644
--- a/drivers/watchdog/designware_wdt.c
+++ b/drivers/watchdog/designware_wdt.c
@@ -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);
--
2.29.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v5 3/6] wdt: dw: Enable the clock before using it

Sean Anderson
In reply to this post by Sean Anderson
The watchdog won't work if the clock isn't enabled.

Fixes: cf89ef8d10f240554541c20b2e1bdcdd58d1d7e6
Signed-off-by: Sean Anderson <[hidden email]>
Reviewed-by: Simon Glass <[hidden email]>
---

(no changes since v1)

 drivers/watchdog/designware_wdt.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c
index 41866fa01b..e6f5437056 100644
--- a/drivers/watchdog/designware_wdt.c
+++ b/drivers/watchdog/designware_wdt.c
@@ -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;
--
2.29.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v5 4/6] wdt: dw: Free the clock on error

Sean Anderson
In reply to this post by Sean Anderson
The clock subsystem requires that clk_free be called on clocks obtained via
clk_get_*.

Signed-off-by: Sean Anderson <[hidden email]>
Reviewed-by: Simon Glass <[hidden email]>
---

(no changes since v4)

Changes in v4:
- Fix build error without CONFIG_CLK

 drivers/watchdog/designware_wdt.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c
index e6f5437056..b952737fb4 100644
--- a/drivers/watchdog/designware_wdt.c
+++ b/drivers/watchdog/designware_wdt.c
@@ -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,21 @@ 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);
+#endif
+ return ret;
 }
 
 static const struct wdt_ops designware_wdt_ops = {
--
2.29.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v5 5/6] riscv: Add watchdog bindings for the k210

Sean Anderson
In reply to this post by Sean Anderson
This adds the necessary bindings. Most of them are already there.

Signed-off-by: Sean Anderson <[hidden email]>
Acked-by: Rick Chen <[hidden email]>
---

(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(-)

diff --git a/arch/riscv/dts/k210.dtsi b/arch/riscv/dts/k210.dtsi
index 81b04018c6..0b79a29600 100644
--- a/arch/riscv/dts/k210.dtsi
+++ b/arch/riscv/dts/k210.dtsi
@@ -439,7 +439,6 @@
  interrupts = <21>;
  clocks = <&sysclk K210_CLK_WDT0>;
  resets = <&sysrst K210_RST_WDT0>;
- status = "disabled";
  };
 
  wdt1: watchdog@50410000 {
--
2.29.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v5 6/6] riscv: Enable watchdog for the k210

Sean Anderson
In reply to this post by Sean Anderson
This enables the necessary config options.

Signed-off-by: Sean Anderson <[hidden email]>
Reviewed-by: Simon Glass <[hidden email]>
---

(no changes since v1)

 board/sipeed/maix/Kconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/board/sipeed/maix/Kconfig b/board/sipeed/maix/Kconfig
index 4c42dd2087..95fe6d9706 100644
--- a/board/sipeed/maix/Kconfig
+++ b/board/sipeed/maix/Kconfig
@@ -53,4 +53,6 @@ config BOARD_SPECIFIC_OPTIONS
  imply CMD_GPIO
  imply LED
  imply LED_GPIO
+ imply WDT
+ imply DESIGNWARE_WATCHDOG
 endif
--
2.29.2

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v5 0/6] wdt: Add support for watchdogs on Kendryte K210

Sean Anderson
In reply to this post by Sean Anderson

On 12/22/20 6:58 PM, Sean Anderson wrote:

> This series depends on
> https://patchwork.ozlabs.org/project/uboot/list/?series=200642
>
> Changes in v5:
> - Rebase on u-boot/master
>
> Changes in v4:
> - Fix build error without CONFIG_CLK
>
> 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 (6):
>    wdt: dw: Switch to using fls for log2
>    wdt: dw: Switch to if(CONFIG()) instead of using #if
>    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 | 37 ++++++++++++++++++++-----------
>   3 files changed, 26 insertions(+), 14 deletions(-)
>

*bump*

I'd like to get this into 2020.04, since it has had no changes since
September except for a rebase.

--Sean