Re: [U-Boot] [PATCH v2 1/2] arm: at91: wdt: Convert watchdog driver to dm/dt

2018-09-22 Thread Petr Vorel
Hi Prasanthi,

> Convert the Watchdog driver for AT91SAM9x processors to support
> the driver model and device tree.

> Signed-off-by: Prasanthi Chellakumar 
> ---
>  arch/arm/mach-at91/include/mach/at91_wdt.h |  12 +++-
>  drivers/watchdog/Kconfig   |   7 ++
>  drivers/watchdog/Makefile  |   2 +-
>  drivers/watchdog/at91sam9_wdt.c| 106 
> +
>  4 files changed, 96 insertions(+), 31 deletions(-)

Your patch breaks arm926ejs and atmel.
https://travis-ci.org/pevik/u-boot/builds/430694055


Kind regards,
Petr
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 1/2] arm: at91: wdt: Convert watchdog driver to dm/dt

2018-09-14 Thread Prasanthi Chellakumar
Convert the Watchdog driver for AT91SAM9x processors to support
the driver model and device tree.

Signed-off-by: Prasanthi Chellakumar 
---
 arch/arm/mach-at91/include/mach/at91_wdt.h |  12 +++-
 drivers/watchdog/Kconfig   |   7 ++
 drivers/watchdog/Makefile  |   2 +-
 drivers/watchdog/at91sam9_wdt.c| 106 +
 4 files changed, 96 insertions(+), 31 deletions(-)

diff --git a/arch/arm/mach-at91/include/mach/at91_wdt.h 
b/arch/arm/mach-at91/include/mach/at91_wdt.h
index 99b0cc8..df9f131 100644
--- a/arch/arm/mach-at91/include/mach/at91_wdt.h
+++ b/arch/arm/mach-at91/include/mach/at91_wdt.h
@@ -4,7 +4,7 @@
  *
  * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD 
  * Copyright (C) 2007 Andrew Victor
- * Copyright (C) 2007 Atmel Corporation.
+ * Copyright (C) 2018 Microchip Technology Inc.
  *
  * Watchdog Timer (WDT) - System peripherals regsters.
  * Based on AT91SAM9261 datasheet revision D.
@@ -27,15 +27,21 @@ typedef struct at91_wdt {
 
 #endif
 
+/* Watchdog Control Register */
+#define AT91_WDT_CR0x00
 #define AT91_WDT_CR_WDRSTT 1
 #define AT91_WDT_CR_KEY0xa500  /* KEY Password 
*/
 
-#define AT91_WDT_MR_WDV(x) (x & 0xfff)
+/* Watchdog Mode Register*/
+#define AT91_WDT_MR0X04
+#define AT91_WDT_MR_WDV(0xfff << 0)
+#defineAT91_WDT_MR_SET_WDV(x)  ((x) & AT91_WDT_MR_WDV)
 #define AT91_WDT_MR_WDFIEN 0x1000
 #define AT91_WDT_MR_WDRSTEN0x2000
 #define AT91_WDT_MR_WDRPROC0x4000
 #define AT91_WDT_MR_WDDIS  0x8000
-#define AT91_WDT_MR_WDD(x) ((x & 0xfff) << 16)
+#defineAT91_WDT_MR_WDD (0xfff << 16)
+#defineAT91_WDT_MR_SET_WDD(x)  (((x) << 16) & 
AT91_WDT_MR_WDD)
 #define AT91_WDT_MR_WDDBGHLT   0x1000
 #define AT91_WDT_MR_WDIDLEHLT  0x2000
 
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index d545b3e..001a8d0 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -111,4 +111,11 @@ config XILINX_TB_WATCHDOG
   Select this to enable Xilinx Axi watchdog timer, which can be found 
on some
   Xilinx Microblaze Platforms.
 
+config WDT_AT91
+   bool "AT91 watchdog timer support"
+   depends on WDT
+   help
+  Select this to enable Microchip watchdog timer, which can be found on
+  some AT91 devices.
+
 endmenu
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 08406ca..a5c27b0 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -3,7 +3,7 @@
 # (C) Copyright 2008
 # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
 
-obj-$(CONFIG_AT91SAM9_WATCHDOG) += at91sam9_wdt.o
+obj-$(CONFIG_WDT_AT91) += at91sam9_wdt.o
 obj-$(CONFIG_FTWDT010_WATCHDOG) += ftwdt010_wdt.o
 ifneq (,$(filter $(SOC), mx25 mx31 mx35 mx5 mx6 mx7 vf610))
 obj-y += imx_watchdog.o
diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index fca2849..3c34891 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -2,7 +2,7 @@
 /*
  * [origin: Linux kernel drivers/watchdog/at91sam9_wdt.c]
  *
- * Watchdog driver for Atmel AT91SAM9x processors.
+ * Watchdog driver for AT91SAM9x processors.
  *
  * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD 
  * Copyright (C) 2008 Renaud CERRATO r.cerr...@til-technologies.fr
@@ -14,38 +14,47 @@
  * write to this register. Inform Linux to it too
  */
 
-#include 
-#include 
-#include 
 #include 
 #include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
 
 /*
  * AT91SAM9 watchdog runs a 12bit counter @ 256Hz,
  * use this to convert a watchdog
- * value from/to milliseconds.
+ * value from seconds.
  */
-#define ms_to_ticks(t) (((t << 8) / 1000) - 1)
-#define ticks_to_ms(t) (((t + 1) * 1000) >> 8)
+#define WDT_SEC2TICKS(s)   (((s) << 8) - 1)
 
 /* Hardware timeout in seconds */
-#if !defined(CONFIG_AT91_HW_WDT_TIMEOUT)
-#define WDT_HW_TIMEOUT 2
-#else
-#define WDT_HW_TIMEOUT CONFIG_AT91_HW_WDT_TIMEOUT
-#endif
+#define WDT_MAX_TIMEOUT 16
+#define WDT_MIN_TIMEOUT 0
+#define WDT_DEFAULT_TIMEOUT 2
+
+struct at91_wdt_priv {
+   void __iomem *regs;
+   u32 regval;
+   u32 timeout;
+};
 
 /*
  * Set the watchdog time interval in 1/256Hz (write-once)
  * Counter is 12 bit.
  */
-static int at91_wdt_settimeout(unsigned int timeout)
+static int at91_wdt_start(struct udevice *dev, u64 timeout_s, ulong flags)
 {
-   unsigned int reg;
-   at91_wdt_t *wd = (at91_wdt_t *) ATMEL_BASE_WDT;
+   struct at91_wdt_priv *priv = dev_get_priv(dev);
+   u32 timeout = WDT_SEC2TICKS(timeout_s);
+
+   if (timeout_s > WDT_MAX_TIMEOUT || timeout_s < WDT_MIN_TIMEOUT)
+   timeout = priv->timeout;
 
/* Check if disabled */
-