[PATCH 1/4] wdt: Add CONFIG_DESIGNWARE_WATCHDOG to Kconfig

Currently this is set from headers. No board has this set by default, so we don't need to modify any configs. --- drivers/watchdog/Kconfig | 7 +++++++ include/configs/socfpga_common.h | 1 - include/configs/socfpga_soc64_common.h | 1 - 3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 8c16d69d33..b717eebe3c 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -176,6 +176,13 @@ config WDT_TANGIER Intel Tangier SoC. If you're using a board with Intel Tangier SoC, say Y here.
+config DESIGNWARE_WATCHDOG + bool "Synopsys Designware watchdog timer support" + select HW_WATCHDOG if !WDT + help + Enable support for the Synopsys Designware watchdog timer, which can + be found on Altera socfpgas, and on Kendryte CPUs. + config SPL_WDT bool "Enable driver model for watchdog timer drivers in SPL" depends on SPL_DM diff --git a/include/configs/socfpga_common.h b/include/configs/socfpga_common.h index 05bfef75c0..5329b19af2 100644 --- a/include/configs/socfpga_common.h +++ b/include/configs/socfpga_common.h @@ -105,7 +105,6 @@ * L4 Watchdog */ #ifdef CONFIG_HW_WATCHDOG -#define CONFIG_DESIGNWARE_WATCHDOG #define CONFIG_DW_WDT_BASE SOCFPGA_L4WD0_ADDRESS #define CONFIG_DW_WDT_CLOCK_KHZ 25000 #endif diff --git a/include/configs/socfpga_soc64_common.h b/include/configs/socfpga_soc64_common.h index 4afadafd35..159e60ec6e 100644 --- a/include/configs/socfpga_soc64_common.h +++ b/include/configs/socfpga_soc64_common.h @@ -152,7 +152,6 @@ unsigned int cm_get_qspi_controller_clk_hz(void); */ #ifdef CONFIG_SPL_BUILD #define CONFIG_HW_WATCHDOG -#define CONFIG_DESIGNWARE_WATCHDOG #define CONFIG_DW_WDT_BASE SOCFPGA_L4WD0_ADDRESS #ifdef CONFIG_TARGET_SOCFPGA_STRATIX10 #ifndef __ASSEMBLY__

This header is needed outside of the arm architecture by the designware wdt driver. --- arch/arm/cpu/armv7/cache_v7.c | 2 +- arch/arm/mach-davinci/spl.c | 2 +- arch/arm/mach-omap2/clocks-common.c | 2 +- arch/arm/mach-omap2/emif-common.c | 2 +- arch/arm/mach-omap2/omap4/emif.c | 2 +- arch/arm/mach-omap2/omap5/dra7xx_iodelay.c | 2 +- arch/arm/mach-omap2/omap5/emif.c | 2 +- arch/arm/mach-omap2/omap5/hwinit.c | 2 +- arch/arm/mach-socfpga/spl_a10.c | 2 +- arch/arm/mach-socfpga/spl_agilex.c | 2 +- arch/arm/mach-socfpga/spl_gen5.c | 2 +- arch/arm/mach-socfpga/spl_s10.c | 2 +- drivers/watchdog/designware_wdt.c | 4 ++-- arch/arm/include/asm/utils.h => include/log2.h | 4 ++-- 14 files changed, 16 insertions(+), 16 deletions(-) rename arch/arm/include/asm/utils.h => include/log2.h (93%)
diff --git a/arch/arm/cpu/armv7/cache_v7.c b/arch/arm/cpu/armv7/cache_v7.c index 99eb7db342..049a27cc92 100644 --- a/arch/arm/cpu/armv7/cache_v7.c +++ b/arch/arm/cpu/armv7/cache_v7.c @@ -8,7 +8,7 @@ #include <linux/types.h> #include <common.h> #include <asm/armv7.h> -#include <asm/utils.h> +#include <log2.h>
#define ARMV7_DCACHE_INVAL_RANGE 1 #define ARMV7_DCACHE_CLEAN_INVAL_RANGE 2 diff --git a/arch/arm/mach-davinci/spl.c b/arch/arm/mach-davinci/spl.c index be3daa9bc0..821324074c 100644 --- a/arch/arm/mach-davinci/spl.c +++ b/arch/arm/mach-davinci/spl.c @@ -7,7 +7,7 @@ #include <config.h> #include <spl.h> #include <asm/u-boot.h> -#include <asm/utils.h> +#include <log2.h> #include <nand.h> #include <asm/arch/dm365_lowlevel.h> #include <ns16550.h> diff --git a/arch/arm/mach-omap2/clocks-common.c b/arch/arm/mach-omap2/clocks-common.c index 5932d694d3..7b91a39cdb 100644 --- a/arch/arm/mach-omap2/clocks-common.c +++ b/arch/arm/mach-omap2/clocks-common.c @@ -18,7 +18,7 @@ #include <asm/gpio.h> #include <asm/arch/clock.h> #include <asm/arch/sys_proto.h> -#include <asm/utils.h> +#include <log2.h> #include <asm/omap_gpio.h> #include <asm/emif.h>
diff --git a/arch/arm/mach-omap2/emif-common.c b/arch/arm/mach-omap2/emif-common.c index 290f9dcdb0..758c2b3d11 100644 --- a/arch/arm/mach-omap2/emif-common.c +++ b/arch/arm/mach-omap2/emif-common.c @@ -14,7 +14,7 @@ #include <asm/arch/sys_proto.h> #include <asm/omap_common.h> #include <asm/omap_sec_common.h> -#include <asm/utils.h> +#include <log2.h> #include <linux/compiler.h> #include <asm/ti-common/ti-edma3.h>
diff --git a/arch/arm/mach-omap2/omap4/emif.c b/arch/arm/mach-omap2/omap4/emif.c index 35a51645be..d2b530535e 100644 --- a/arch/arm/mach-omap2/omap4/emif.c +++ b/arch/arm/mach-omap2/omap4/emif.c @@ -11,7 +11,7 @@ #include <common.h> #include <asm/emif.h> #include <asm/arch/sys_proto.h> -#include <asm/utils.h> +#include <log2.h>
#ifndef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS u32 *const T_num = (u32 *)OMAP_SRAM_SCRATCH_EMIF_T_NUM; diff --git a/arch/arm/mach-omap2/omap5/dra7xx_iodelay.c b/arch/arm/mach-omap2/omap5/dra7xx_iodelay.c index 9eda57c450..e541e729ef 100644 --- a/arch/arm/mach-omap2/omap5/dra7xx_iodelay.c +++ b/arch/arm/mach-omap2/omap5/dra7xx_iodelay.c @@ -7,7 +7,7 @@ */
#include <common.h> -#include <asm/utils.h> +#include <log2.h> #include <asm/arch/dra7xx_iodelay.h> #include <asm/arch/omap.h> #include <asm/arch/sys_proto.h> diff --git a/arch/arm/mach-omap2/omap5/emif.c b/arch/arm/mach-omap2/omap5/emif.c index f3661a0e74..a5c74261c0 100644 --- a/arch/arm/mach-omap2/omap5/emif.c +++ b/arch/arm/mach-omap2/omap5/emif.c @@ -11,7 +11,7 @@ #include <common.h> #include <asm/emif.h> #include <asm/arch/sys_proto.h> -#include <asm/utils.h> +#include <log2.h>
#ifndef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS #define print_timing_reg(reg) debug(#reg" - 0x%08x\n", (reg)) diff --git a/arch/arm/mach-omap2/omap5/hwinit.c b/arch/arm/mach-omap2/omap5/hwinit.c index 56458ce495..ebd3b4903f 100644 --- a/arch/arm/mach-omap2/omap5/hwinit.c +++ b/arch/arm/mach-omap2/omap5/hwinit.c @@ -18,7 +18,7 @@ #include <asm/arch/sys_proto.h> #include <asm/arch/clock.h> #include <linux/sizes.h> -#include <asm/utils.h> +#include <log2.h> #include <asm/arch/gpio.h> #include <asm/emif.h> #include <asm/omap_common.h> diff --git a/arch/arm/mach-socfpga/spl_a10.c b/arch/arm/mach-socfpga/spl_a10.c index 7c38c50981..a2b19e0f47 100644 --- a/arch/arm/mach-socfpga/spl_a10.c +++ b/arch/arm/mach-socfpga/spl_a10.c @@ -8,7 +8,7 @@ #include <asm/io.h> #include <asm/pl310.h> #include <asm/u-boot.h> -#include <asm/utils.h> +#include <log2.h> #include <image.h> #include <asm/arch/reset_manager.h> #include <spl.h> diff --git a/arch/arm/mach-socfpga/spl_agilex.c b/arch/arm/mach-socfpga/spl_agilex.c index c745d64114..4e46d2bf5c 100644 --- a/arch/arm/mach-socfpga/spl_agilex.c +++ b/arch/arm/mach-socfpga/spl_agilex.c @@ -6,7 +6,7 @@
#include <asm/io.h> #include <asm/u-boot.h> -#include <asm/utils.h> +#include <log2.h> #include <common.h> #include <image.h> #include <spl.h> diff --git a/arch/arm/mach-socfpga/spl_gen5.c b/arch/arm/mach-socfpga/spl_gen5.c index e19f55aa9b..48de2aceee 100644 --- a/arch/arm/mach-socfpga/spl_gen5.c +++ b/arch/arm/mach-socfpga/spl_gen5.c @@ -6,7 +6,7 @@ #include <common.h> #include <asm/io.h> #include <asm/u-boot.h> -#include <asm/utils.h> +#include <log2.h> #include <image.h> #include <asm/arch/reset_manager.h> #include <spl.h> diff --git a/arch/arm/mach-socfpga/spl_s10.c b/arch/arm/mach-socfpga/spl_s10.c index 8d96918cb4..44063b332a 100644 --- a/arch/arm/mach-socfpga/spl_s10.c +++ b/arch/arm/mach-socfpga/spl_s10.c @@ -6,7 +6,7 @@
#include <asm/io.h> #include <asm/u-boot.h> -#include <asm/utils.h> +#include <log2.h> #include <common.h> #include <debug_uart.h> #include <image.h> diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c index c668567c66..3b97db1256 100644 --- a/drivers/watchdog/designware_wdt.c +++ b/drivers/watchdog/designware_wdt.c @@ -4,9 +4,9 @@ */
#include <common.h> -#include <watchdog.h> #include <asm/io.h> -#include <asm/utils.h> +#include <log2.h> +#include <watchdog.h>
#define DW_WDT_CR 0x00 #define DW_WDT_TORR 0x04 diff --git a/arch/arm/include/asm/utils.h b/include/log2.h similarity index 93% rename from arch/arm/include/asm/utils.h rename to include/log2.h index eee60c50e9..4f89d3dd76 100644 --- a/arch/arm/include/asm/utils.h +++ b/include/log2.h @@ -4,8 +4,8 @@ * Texas Instruments, <www.ti.com> * Aneesh V aneesh@ti.com */ -#ifndef _UTILS_H_ -#define _UTILS_H_ +#ifndef _LOG2_H_ +#define _LOG2_H_
static inline s32 log_2_n_round_up(u32 n) {

On 2/2/20 12:12 PM, Sean Anderson wrote:
This header is needed outside of the arm architecture by the designware wdt driver.
arch/arm/cpu/armv7/cache_v7.c | 2 +- arch/arm/mach-davinci/spl.c | 2 +- arch/arm/mach-omap2/clocks-common.c | 2 +- arch/arm/mach-omap2/emif-common.c | 2 +- arch/arm/mach-omap2/omap4/emif.c | 2 +- arch/arm/mach-omap2/omap5/dra7xx_iodelay.c | 2 +- arch/arm/mach-omap2/omap5/emif.c | 2 +- arch/arm/mach-omap2/omap5/hwinit.c | 2 +- arch/arm/mach-socfpga/spl_a10.c | 2 +- arch/arm/mach-socfpga/spl_agilex.c | 2 +- arch/arm/mach-socfpga/spl_gen5.c | 2 +- arch/arm/mach-socfpga/spl_s10.c | 2 +- drivers/watchdog/designware_wdt.c | 4 ++-- arch/arm/include/asm/utils.h => include/log2.h | 4 ++-- 14 files changed, 16 insertions(+), 16 deletions(-) rename arch/arm/include/asm/utils.h => include/log2.h (93%)
Signed-off-by: Sean Anderson seanga2@gmail.com

On Sun, 2 Feb 2020 at 10:12, Sean Anderson seanga2@gmail.com wrote:
This header is needed outside of the arm architecture by the designware wdt driver.
arch/arm/cpu/armv7/cache_v7.c | 2 +- arch/arm/mach-davinci/spl.c | 2 +- arch/arm/mach-omap2/clocks-common.c | 2 +- arch/arm/mach-omap2/emif-common.c | 2 +- arch/arm/mach-omap2/omap4/emif.c | 2 +- arch/arm/mach-omap2/omap5/dra7xx_iodelay.c | 2 +- arch/arm/mach-omap2/omap5/emif.c | 2 +- arch/arm/mach-omap2/omap5/hwinit.c | 2 +- arch/arm/mach-socfpga/spl_a10.c | 2 +- arch/arm/mach-socfpga/spl_agilex.c | 2 +- arch/arm/mach-socfpga/spl_gen5.c | 2 +- arch/arm/mach-socfpga/spl_s10.c | 2 +- drivers/watchdog/designware_wdt.c | 4 ++-- arch/arm/include/asm/utils.h => include/log2.h | 4 ++-- 14 files changed, 16 insertions(+), 16 deletions(-) rename arch/arm/include/asm/utils.h => include/log2.h (93%)
Reviewed-by: Simon Glass sjg@chromium.org

On 2/3/20 1:04 AM, Simon Glass wrote:
On Sun, 2 Feb 2020 at 10:12, Sean Anderson seanga2@gmail.com wrote:
This header is needed outside of the arm architecture by the designware wdt driver.
arch/arm/cpu/armv7/cache_v7.c | 2 +- arch/arm/mach-davinci/spl.c | 2 +- arch/arm/mach-omap2/clocks-common.c | 2 +- arch/arm/mach-omap2/emif-common.c | 2 +- arch/arm/mach-omap2/omap4/emif.c | 2 +- arch/arm/mach-omap2/omap5/dra7xx_iodelay.c | 2 +- arch/arm/mach-omap2/omap5/emif.c | 2 +- arch/arm/mach-omap2/omap5/hwinit.c | 2 +- arch/arm/mach-socfpga/spl_a10.c | 2 +- arch/arm/mach-socfpga/spl_agilex.c | 2 +- arch/arm/mach-socfpga/spl_gen5.c | 2 +- arch/arm/mach-socfpga/spl_s10.c | 2 +- drivers/watchdog/designware_wdt.c | 4 ++-- arch/arm/include/asm/utils.h => include/log2.h | 4 ++-- 14 files changed, 16 insertions(+), 16 deletions(-) rename arch/arm/include/asm/utils.h => include/log2.h (93%)
Reviewed-by: Simon Glass sjg@chromium.org
How could this be reviewed if it's missing basic things, like a SoB line ?

Hi Marek,
On Mon, 3 Feb 2020 at 01:28, Marek Vasut marex@denx.de wrote:
On 2/3/20 1:04 AM, Simon Glass wrote:
On Sun, 2 Feb 2020 at 10:12, Sean Anderson seanga2@gmail.com wrote:
This header is needed outside of the arm architecture by the designware wdt driver.
arch/arm/cpu/armv7/cache_v7.c | 2 +- arch/arm/mach-davinci/spl.c | 2 +- arch/arm/mach-omap2/clocks-common.c | 2 +- arch/arm/mach-omap2/emif-common.c | 2 +- arch/arm/mach-omap2/omap4/emif.c | 2 +- arch/arm/mach-omap2/omap5/dra7xx_iodelay.c | 2 +- arch/arm/mach-omap2/omap5/emif.c | 2 +- arch/arm/mach-omap2/omap5/hwinit.c | 2 +- arch/arm/mach-socfpga/spl_a10.c | 2 +- arch/arm/mach-socfpga/spl_agilex.c | 2 +- arch/arm/mach-socfpga/spl_gen5.c | 2 +- arch/arm/mach-socfpga/spl_s10.c | 2 +- drivers/watchdog/designware_wdt.c | 4 ++-- arch/arm/include/asm/utils.h => include/log2.h | 4 ++-- 14 files changed, 16 insertions(+), 16 deletions(-) rename arch/arm/include/asm/utils.h => include/log2.h (93%)
Reviewed-by: Simon Glass sjg@chromium.org
How could this be reviewed if it's missing basic things, like a SoB line ?
I saw you requested that on another patch. Apart from that it looks OK to me.
People should use patman :-)
Regards, Simon

On 2/3/20 10:11 AM, Simon Glass wrote:
Hi Marek,
On Mon, 3 Feb 2020 at 01:28, Marek Vasut marex@denx.de wrote:
How could this be reviewed if it's missing basic things, like a SoB line ?
I added that in a reply to the original patch; again my apologies for missing it the first time around.
I saw you requested that on another patch. Apart from that it looks OK to me.
People should use patman :-)
I usually add my signed-off-by lines with git rebase --sign, but I forgot to do that this time. Though reasonably the thing which should have reminded me was running checkpatch (which I also forgot to run).
Regards, Simon

Hi Sean,
On Mon, 3 Feb 2020 at 08:27, Sean Anderson seanga2@gmail.com wrote:
On 2/3/20 10:11 AM, Simon Glass wrote:
Hi Marek,
On Mon, 3 Feb 2020 at 01:28, Marek Vasut marex@denx.de wrote:
How could this be reviewed if it's missing basic things, like a SoB line ?
I added that in a reply to the original patch; again my apologies for missing it the first time around.
I saw you requested that on another patch. Apart from that it looks OK to me.
People should use patman :-)
I usually add my signed-off-by lines with git rebase --sign, but I forgot to do that this time. Though reasonably the thing which should have reminded me was running checkpatch (which I also forgot to run).
That's why patman exists, to automate adding sign-off, checkpath, get maintainers, dropping unwanted tags, cover letter, etc.
It's so simple to set up. It really doesn't make much sense to send patches manually, IMO.
Regards, Simon

Currently, the designware watchdog driver depends in several places on the values of CONFIG_DW_WDT_ defines. This patch moves these uses to just the functions hw_watchdog_*. --- drivers/watchdog/designware_wdt.c | 65 ++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 23 deletions(-)
diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c index 3b97db1256..61c4046f50 100644 --- a/drivers/watchdog/designware_wdt.c +++ b/drivers/watchdog/designware_wdt.c @@ -17,57 +17,76 @@ #define DW_WDT_CR_RMOD_VAL 0x00 #define DW_WDT_CRR_RESTART_VAL 0x76
+struct designware_wdt_priv { + void __iomem *base; + ulong clock_khz; +}; + /* * Set the watchdog time interval. * Counter is 32 bit. */ -static int designware_wdt_settimeout(unsigned int timeout) +static int designware_wdt_settimeout(struct designware_wdt_priv *priv, + u64 timeout) { signed int i;
/* calculate the timeout range value */ - i = (log_2_n_round_up(timeout * CONFIG_DW_WDT_CLOCK_KHZ)) - 16; + i = log_2_n_round_up(timeout * priv->clock_khz) - 16; if (i > 15) i = 15; if (i < 0) i = 0;
- writel((i | (i << 4)), (CONFIG_DW_WDT_BASE + DW_WDT_TORR)); + writel(i | (i << 4), priv->base + DW_WDT_TORR); return 0; }
-static void designware_wdt_enable(void) +static void designware_wdt_enable(struct designware_wdt_priv *priv) { - writel(((DW_WDT_CR_RMOD_VAL << DW_WDT_CR_RMOD_OFFSET) | - (0x1 << DW_WDT_CR_EN_OFFSET)), - (CONFIG_DW_WDT_BASE + DW_WDT_CR)); + writel((DW_WDT_CR_RMOD_VAL << DW_WDT_CR_RMOD_OFFSET) | + (0x1 << DW_WDT_CR_EN_OFFSET), priv->base + DW_WDT_CR); }
-static unsigned int designware_wdt_is_enabled(void) +static unsigned int designware_wdt_is_enabled(struct designware_wdt_priv *priv) { unsigned long val; - val = readl((CONFIG_DW_WDT_BASE + DW_WDT_CR)); - return val & 0x1; + val = readl(priv->base + DW_WDT_CR); + return val & 1; }
-#if defined(CONFIG_HW_WATCHDOG) +static void designware_wdt_reset(struct designware_wdt_priv *priv) +{ + if (designware_wdt_is_enabled(priv)) + writel(DW_WDT_CRR_RESTART_VAL, priv->base + DW_WDT_CRR); +} + +static void designware_wdt_init(struct designware_wdt_priv *priv, u64 timeout) +{ + /* reset to disable the watchdog */ + designware_wdt_reset(priv); + /* set timer in miliseconds */ + designware_wdt_settimeout(priv, timeout); + designware_wdt_enable(priv); + designware_wdt_reset(priv); +} + +#ifdef CONFIG_HW_WATCHDOG +static struct designware_wdt_priv wdt_priv = { + .base = CONFIG_DW_WDT_BASE, +}; + void hw_watchdog_reset(void) { - if (designware_wdt_is_enabled()) - /* restart the watchdog counter */ - writel(DW_WDT_CRR_RESTART_VAL, - (CONFIG_DW_WDT_BASE + DW_WDT_CRR)); + /* XXX: may contain a function call; must be done at runtime */ + wdt_priv.clock_khz = CONFIG_DW_WDT_CLOCK_KHZ; + designware_wdt_reset(&wdt_priv); }
void hw_watchdog_init(void) { - /* reset to disable the watchdog */ - hw_watchdog_reset(); - /* set timer in miliseconds */ - designware_wdt_settimeout(CONFIG_WATCHDOG_TIMEOUT_MSECS); - /* enable the watchdog */ - designware_wdt_enable(); - /* reset the watchdog */ - hw_watchdog_reset(); + /* XXX: see above */ + wdt_priv.clock_khz = CONFIG_DW_WDT_CLOCK_KHZ; + designware_wdt_init(&wdt_priv, CONFIG_WATCHDOG_TIMEOUT_MSECS); } #endif

On 2/2/20 12:12 PM, Sean Anderson wrote:
Currently, the designware watchdog driver depends in several places on the values of CONFIG_DW_WDT_ defines. This patch moves these uses to just the functions hw_watchdog_*.
drivers/watchdog/designware_wdt.c | 65 ++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 23 deletions(-)
Signed-off-by: Sean Anderson seanga2@gmail.com

The binding used is the same as Linux's. --- doc/device-tree-bindings/watchdog/dw_wdt.txt | 24 +++++++ drivers/watchdog/designware_wdt.c | 67 ++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 doc/device-tree-bindings/watchdog/dw_wdt.txt
diff --git a/doc/device-tree-bindings/watchdog/dw_wdt.txt b/doc/device-tree-bindings/watchdog/dw_wdt.txt new file mode 100644 index 0000000000..eb0914420c --- /dev/null +++ b/doc/device-tree-bindings/watchdog/dw_wdt.txt @@ -0,0 +1,24 @@ +Synopsys Designware Watchdog Timer + +Required Properties: + +- compatible : Should contain "snps,dw-wdt" +- reg : Base address and size of the watchdog timer registers. +- clocks : phandle + clock-specifier for the clock that drives the + watchdog timer. + +Optional Properties: + +- interrupts : The interrupt used for the watchdog timeout warning. +- resets : phandle pointing to the system reset controller with + line index for the watchdog. + +Example: + + watchdog0: wd@ffd02000 { + compatible = "snps,dw-wdt"; + reg = <0xffd02000 0x1000>; + interrupts = <0 171 4>; + clocks = <&per_base_clk>; + resets = <&rst WDT0_RESET>; + }; diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c index 61c4046f50..1f7f4f0103 100644 --- a/drivers/watchdog/designware_wdt.c +++ b/drivers/watchdog/designware_wdt.c @@ -5,8 +5,10 @@
#include <common.h> #include <asm/io.h> +#include <clk.h> #include <log2.h> #include <watchdog.h> +#include <wdt.h>
#define DW_WDT_CR 0x00 #define DW_WDT_TORR 0x04 @@ -90,3 +92,68 @@ void hw_watchdog_init(void) designware_wdt_init(&wdt_priv, CONFIG_WATCHDOG_TIMEOUT_MSECS); } #endif + +#ifdef CONFIG_WDT +static int dw_wdt_reset(struct udevice *dev) +{ + struct designware_wdt_priv *priv = dev_get_priv(dev); + + designware_wdt_reset(priv); + + return 0; +} + +static int dw_wdt_start(struct udevice *dev, u64 timeout, ulong flags) +{ + struct designware_wdt_priv *priv = dev_get_priv(dev); + + designware_wdt_init(priv, timeout); + + return 0; +} + +static int dw_wdt_probe(struct udevice *dev) +{ + int ret; + ulong rate; + struct clk clk; + struct designware_wdt_priv *priv = dev_get_priv(dev); + + priv->base = dev_read_addr_ptr(dev); + if (!priv->base) + return -ENOENT; + + ret = clk_get_by_index(dev, 0, &clk); + if (ret) + return ret; + + rate = clk_get_rate(&clk); + if (IS_ERR_VALUE(rate)) { + clk_free(&clk); + return rate; + } + priv->clock_khz = rate / 1000; + + return 0; +} + +static const struct wdt_ops dw_wdt_ops = { + .start = dw_wdt_start, + .reset = dw_wdt_reset, +}; + +static const struct udevice_id dw_wdt_ids[] = { + { .compatible = "snps,dw-wdt" }, + { }, +}; + +U_BOOT_DRIVER(designware_wdt) = { + .name = "designware_wdt", + .id = UCLASS_WDT, + .of_match = dw_wdt_ids, + .probe = dw_wdt_probe, + .ops = &dw_wdt_ops, + .priv_auto_alloc_size = sizeof(struct designware_wdt_priv), + .flags = DM_FLAG_PRE_RELOC, +}; +#endif /* WDT */

On 2/2/20 12:13 PM, Sean Anderson wrote:
The binding used is the same as Linux's.
doc/device-tree-bindings/watchdog/dw_wdt.txt | 24 +++++++ drivers/watchdog/designware_wdt.c | 67 ++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 doc/device-tree-bindings/watchdog/dw_wdt.txt
Signed-off-by: Sean Anderson seanga2@gmail.com

Hi Sean,
On Sun, 2 Feb 2020 at 10:25, Sean Anderson seanga2@gmail.com wrote:
On 2/2/20 12:13 PM, Sean Anderson wrote:
The binding used is the same as Linux's.
doc/device-tree-bindings/watchdog/dw_wdt.txt | 24 +++++++ drivers/watchdog/designware_wdt.c | 67 ++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 doc/device-tree-bindings/watchdog/dw_wdt.txt
Signed-off-by: Sean Anderson seanga2@gmail.com
Are you adding this to the Makefile somewhere?
Regards, Simon

On 2/2/20 7:04 PM, Simon Glass wrote:
Hi Sean,
On Sun, 2 Feb 2020 at 10:25, Sean Anderson seanga2@gmail.com wrote:
On 2/2/20 12:13 PM, Sean Anderson wrote:
The binding used is the same as Linux's.
doc/device-tree-bindings/watchdog/dw_wdt.txt | 24 +++++++ drivers/watchdog/designware_wdt.c | 67 ++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 doc/device-tree-bindings/watchdog/dw_wdt.txt
Signed-off-by: Sean Anderson seanga2@gmail.com
Are you adding this to the Makefile somewhere?
I'm not sure what you mean. This is optionally used in [1], but I didn't want to add an explicit dependency. However, this appears to be a bit of a duplicate effort in light of [2].
[1] https://patchwork.ozlabs.org/project/uboot/list/?series=156389 [2] https://patchwork.ozlabs.org/patch/1232414/
--Sean

On Sun, 2 Feb 2020 at 18:18, Sean Anderson seanga2@gmail.com wrote:
On 2/2/20 7:04 PM, Simon Glass wrote:
Hi Sean,
On Sun, 2 Feb 2020 at 10:25, Sean Anderson seanga2@gmail.com wrote:
On 2/2/20 12:13 PM, Sean Anderson wrote:
The binding used is the same as Linux's.
doc/device-tree-bindings/watchdog/dw_wdt.txt | 24 +++++++ drivers/watchdog/designware_wdt.c | 67 ++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 doc/device-tree-bindings/watchdog/dw_wdt.txt
Signed-off-by: Sean Anderson seanga2@gmail.com
Are you adding this to the Makefile somewhere?
I'm not sure what you mean. This is optionally used in [1], but I didn't want to add an explicit dependency. However, this appears to be a bit of a duplicate effort in light of [2].
OK, thanks.
Reviewed-by: Simon Glass sjg@chromium.org
[1] https://patchwork.ozlabs.org/project/uboot/list/?series=156389 [2] https://patchwork.ozlabs.org/patch/1232414/
--Sean

On 2/2/20 6:10 PM, Sean Anderson wrote:
Currently this is set from headers. No board has this set by default
Please check where socfpga_common.h and socfpga_soc64_common.h are included. This should then make it clear that this statement in not true.
, so we
don't need to modify any configs.
The patch is wrong, see above. Also, it's missing a SoB line.

On 2/2/20 12:15 PM, Marek Vasut wrote:
On 2/2/20 6:10 PM, Sean Anderson wrote:
Currently this is set from headers. No board has this set by default
Please check where socfpga_common.h and socfpga_soc64_common.h are included. This should then make it clear that this statement in not true.
, so we
don't need to modify any configs.
CONFIG_DESIGNWARE_WATCHDOG is only defined if CONFIG_HW_WATCHDOG is defined, and this is never defined in headers (or in the defconfigs).
The patch is wrong, see above. Also, it's missing a SoB line.
Ah, I just noticed that, thanks for pointing that out.

On 2/2/20 6:23 PM, Sean Anderson wrote:
On 2/2/20 12:15 PM, Marek Vasut wrote:
On 2/2/20 6:10 PM, Sean Anderson wrote:
Currently this is set from headers. No board has this set by default
Please check where socfpga_common.h and socfpga_soc64_common.h are included. This should then make it clear that this statement in not true.
, so we
don't need to modify any configs.
CONFIG_DESIGNWARE_WATCHDOG is only defined if CONFIG_HW_WATCHDOG is defined, and this is never defined in headers (or in the defconfigs).
This is what I see in socfpga_soc64_common.h on u-boot/master: 153 #ifdef CONFIG_SPL_BUILD 154 #define CONFIG_HW_WATCHDOG
The patch is wrong, see above. Also, it's missing a SoB line.
Ah, I just noticed that, thanks for pointing that out.
Note that I updated u-boot-socfpga/master and sent a PR just now (thanks for reminding me of that), it contains the DW WDT patches that were posted to the ML some time ago. You want to rebase the series on top of that.

On 2/2/20 12:40 PM, Marek Vasut wrote:
On 2/2/20 6:23 PM, Sean Anderson wrote:
CONFIG_DESIGNWARE_WATCHDOG is only defined if CONFIG_HW_WATCHDOG is defined, and this is never defined in headers (or in the defconfigs).
This is what I see in socfpga_soc64_common.h on u-boot/master: 153 #ifdef CONFIG_SPL_BUILD 154 #define CONFIG_HW_WATCHDOG
Huh, there it is. I guess I expected the usage to be the same as socfpga_common.h. Would it be best to add DESIGNWARE_WATCHDOG to the appropriate Kconfigs, defconfigs, or leave it in the header?
The patch is wrong, see above. Also, it's missing a SoB line.
Ah, I just noticed that, thanks for pointing that out.
Note that I updated u-boot-socfpga/master and sent a PR just now (thanks for reminding me of that), it contains the DW WDT patches that were posted to the ML some time ago. You want to rebase the series on top of that.
Ok, I will do that for v2.
--Sean

On 2/2/20 6:48 PM, Sean Anderson wrote:
On 2/2/20 12:40 PM, Marek Vasut wrote:
On 2/2/20 6:23 PM, Sean Anderson wrote:
CONFIG_DESIGNWARE_WATCHDOG is only defined if CONFIG_HW_WATCHDOG is defined, and this is never defined in headers (or in the defconfigs).
This is what I see in socfpga_soc64_common.h on u-boot/master: 153 #ifdef CONFIG_SPL_BUILD 154 #define CONFIG_HW_WATCHDOG
Huh, there it is. I guess I expected the usage to be the same as socfpga_common.h. Would it be best to add DESIGNWARE_WATCHDOG to the appropriate Kconfigs, defconfigs, or leave it in the header?
I also had to look around, because I knew it was somewhere and the WDT should've generally been enabled on socfpga (at least the 32bit ones).
Kconfig is indeed the way to go. For bulk enabling config options, it is better to put them as "select" entry in arch/arm/Kconfig or arch/arm/mach-foo/Kconfig for the entire platform, so all the boards pick the option up without any changes to zillion defconfigs.
The patch is wrong, see above. Also, it's missing a SoB line.
Ah, I just noticed that, thanks for pointing that out.
Note that I updated u-boot-socfpga/master and sent a PR just now (thanks for reminding me of that), it contains the DW WDT patches that were posted to the ML some time ago. You want to rebase the series on top of that.
Ok, I will do that for v2.
Thanks.
btw what's the motivation for this series, are you hitting some issues with the WDT on SoCFPGA ?

btw what's the motivation for this series, are you hitting some issues with the WDT on SoCFPGA ?
This watchdog appears on the Kendryte K210 CPU, which I am adding support for. The rest of the board uses devicetree to configure drivers, so I wanted to add support for this watchdog as well.

On 2/2/20 7:02 PM, Sean Anderson wrote:
btw what's the motivation for this series, are you hitting some issues with the WDT on SoCFPGA ?
This watchdog appears on the Kendryte K210 CPU, which I am adding support for. The rest of the board uses devicetree to configure drivers, so I wanted to add support for this watchdog as well.
You should be able to use what's in u-boot-socfpga/master then. Please give it a try.

On 2/3/20 3:13 AM, Marek Vasut wrote:
On 2/2/20 7:02 PM, Sean Anderson wrote:
btw what's the motivation for this series, are you hitting some issues with the WDT on SoCFPGA ?
This watchdog appears on the Kendryte K210 CPU, which I am adding support for. The rest of the board uses devicetree to configure drivers, so I wanted to add support for this watchdog as well.
You should be able to use what's in u-boot-socfpga/master then. Please give it a try.
This patch series works except that I still need "[PATCH 2/4] arm: Move asm/utils.h to log2.h". I will include it with my k210 support series, since it is specific to that board.
--Sean

On 2/19/20 10:37 PM, Sean Anderson wrote:
On 2/3/20 3:13 AM, Marek Vasut wrote:
On 2/2/20 7:02 PM, Sean Anderson wrote:
btw what's the motivation for this series, are you hitting some issues with the WDT on SoCFPGA ?
This watchdog appears on the Kendryte K210 CPU, which I am adding support for. The rest of the board uses devicetree to configure drivers, so I wanted to add support for this watchdog as well.
You should be able to use what's in u-boot-socfpga/master then. Please give it a try.
This patch series works except that I still need "[PATCH 2/4] arm: Move asm/utils.h to log2.h". I will include it with my k210 support series, since it is specific to that board.
Great! Rebase on u-boot/master and repost. Thanks.

On 2/2/20 12:10 PM, Sean Anderson wrote:
Currently this is set from headers. No board has this set by default, so we don't need to modify any configs.
drivers/watchdog/Kconfig | 7 +++++++ include/configs/socfpga_common.h | 1 - include/configs/socfpga_soc64_common.h | 1 - 3 files changed, 7 insertions(+), 2 deletions(-)
Signed-off-by: Sean Anderson seanga2@gmail.com
participants (3)
-
Marek Vasut
-
Sean Anderson
-
Simon Glass