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

2018-10-09 Thread Prasanthi Chellakumar
Convert the Watchdog driver for AT91SAM9x processors to support
the driver model and device tree. Changes "CONFIG_AT91SAM9_WATCHDOG"
to new "CONFIG_WDT_AT91" Kconfig option.

Signed-off-by: Prasanthi Chellakumar 
---
 arch/arm/dts/at91sam9260-smartweb.dts  |   1 +
 arch/arm/dts/at91sam9g20-taurus.dts|   1 +
 arch/arm/mach-at91/include/mach/at91_wdt.h |   6 +-
 arch/arm/mach-at91/spl.c   |   2 +-
 arch/arm/mach-at91/spl_at91.c  |   2 +-
 arch/arm/mach-at91/spl_atmel.c |   2 +-
 common/board_f.c   |   2 +-
 configs/picosam9g45_defconfig  |   4 ++
 configs/smartweb_defconfig |   3 +
 configs/taurus_defconfig   |   3 +
 doc/README.at91|   2 +-
 doc/README.watchdog|   2 +-
 drivers/watchdog/Kconfig   |  10 +++
 drivers/watchdog/Makefile  |   2 +-
 drivers/watchdog/at91sam9_wdt.c| 104 ++---
 include/configs/picosam9g45.h  |   4 --
 include/configs/smartweb.h |   7 --
 include/configs/taurus.h   |   7 --
 scripts/config_whitelist.txt   |   1 -
 19 files changed, 114 insertions(+), 51 deletions(-)

diff --git a/arch/arm/dts/at91sam9260-smartweb.dts 
b/arch/arm/dts/at91sam9260-smartweb.dts
index e59781b..a22de2d 100644
--- a/arch/arm/dts/at91sam9260-smartweb.dts
+++ b/arch/arm/dts/at91sam9260-smartweb.dts
@@ -89,6 +89,7 @@
};
 
watchdog@fd40 {
+   timeout-sec = <15>;
status = "okay";
};
 
diff --git a/arch/arm/dts/at91sam9g20-taurus.dts 
b/arch/arm/dts/at91sam9g20-taurus.dts
index 7931c0a..cee228b 100644
--- a/arch/arm/dts/at91sam9g20-taurus.dts
+++ b/arch/arm/dts/at91sam9g20-taurus.dts
@@ -98,6 +98,7 @@
};
 
watchdog@fd40 {
+   timeout-sec = <15>;
status = "okay";
};
 
diff --git a/arch/arm/mach-at91/include/mach/at91_wdt.h 
b/arch/arm/mach-at91/include/mach/at91_wdt.h
index 99b0cc8..cd22723 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,9 +27,13 @@ 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 
*/
 
+/* Watchdog Mode Register*/
+#define AT91_WDT_MR0X04
 #define AT91_WDT_MR_WDV(x) (x & 0xfff)
 #define AT91_WDT_MR_WDFIEN 0x1000
 #define AT91_WDT_MR_WDRSTEN0x2000
diff --git a/arch/arm/mach-at91/spl.c b/arch/arm/mach-at91/spl.c
index 8bfb2a4..6da6d41 100644
--- a/arch/arm/mach-at91/spl.c
+++ b/arch/arm/mach-at91/spl.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
 void at91_disable_wdt(void)
 {
struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
diff --git a/arch/arm/mach-at91/spl_at91.c b/arch/arm/mach-at91/spl_at91.c
index 8c36804..23ebaa9 100644
--- a/arch/arm/mach-at91/spl_at91.c
+++ b/arch/arm/mach-at91/spl_at91.c
@@ -76,7 +76,7 @@ void __weak spl_board_init(void)
 void board_init_f(ulong dummy)
 {
lowlevel_clock_init();
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
at91_disable_wdt();
 #endif
 
diff --git a/arch/arm/mach-at91/spl_atmel.c b/arch/arm/mach-at91/spl_atmel.c
index 597ff8c..ef745c9 100644
--- a/arch/arm/mach-at91/spl_atmel.c
+++ b/arch/arm/mach-at91/spl_atmel.c
@@ -98,7 +98,7 @@ void board_init_f(ulong dummy)
configure_2nd_sram_as_l2_cache();
 #endif
 
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
/* disable watchdog */
at91_disable_wdt();
 #endif
diff --git a/common/board_f.c b/common/board_f.c
index 213d044..02223db 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -91,7 +91,7 @@ static int init_func_watchdog_init(void)
 {
 # if defined(CONFIG_HW_WATCHDOG) && \
(defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
-   defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
+   defined(CONFIG_SH) || \
defined(CONFIG_DESIGNWARE_WATCHDOG) || \
defined(CONFIG_IMX_WATCHDOG))
hw_watchdog_init();
diff --git a/configs/picosam9g45_defconf

[U-Boot] [PATCH v2 2/2] arm: at91: wdt: Convert watchdog config to Kconfig

2018-09-17 Thread Prasanthi Chellakumar
Convert "CONFIG_AT91SAM9_WATCHDOG" to new "CONFIG_WDT_AT91"
Kconfig option to support driver model and device tree.

Signed-off-by: Prasanthi Chellakumar 
---
 README| 3 ---
 arch/arm/dts/at91sam9260-smartweb.dts | 1 +
 arch/arm/dts/at91sam9g20-taurus.dts   | 1 +
 arch/arm/mach-at91/spl.c  | 2 +-
 arch/arm/mach-at91/spl_at91.c | 2 +-
 arch/arm/mach-at91/spl_atmel.c| 2 +-
 common/board_f.c  | 2 +-
 configs/picosam9g45_defconfig | 2 ++
 configs/smartweb_defconfig| 2 ++
 configs/taurus_defconfig  | 2 ++
 doc/README.at91   | 2 +-
 doc/README.watchdog   | 2 +-
 include/configs/picosam9g45.h | 4 
 include/configs/smartweb.h| 7 ---
 include/configs/taurus.h  | 7 ---
 scripts/config_whitelist.txt  | 2 --
 16 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/README b/README
index 09822a3..07b2be1 100644
--- a/README
+++ b/README
@@ -802,9 +802,6 @@ The following options need to be configured:
SoC, then define this variable and provide board
specific code for the "hw_watchdog_reset" function.
 
-   CONFIG_AT91_HW_WDT_TIMEOUT
-   specify the timeout in seconds. default 2 seconds.
-
 - Real-Time Clock:
 
When CONFIG_CMD_DATE is selected, the type of the RTC
diff --git a/arch/arm/dts/at91sam9260-smartweb.dts 
b/arch/arm/dts/at91sam9260-smartweb.dts
index e59781b..a22de2d 100644
--- a/arch/arm/dts/at91sam9260-smartweb.dts
+++ b/arch/arm/dts/at91sam9260-smartweb.dts
@@ -89,6 +89,7 @@
};
 
watchdog@fd40 {
+   timeout-sec = <15>;
status = "okay";
};
 
diff --git a/arch/arm/dts/at91sam9g20-taurus.dts 
b/arch/arm/dts/at91sam9g20-taurus.dts
index 7931c0a..cee228b 100644
--- a/arch/arm/dts/at91sam9g20-taurus.dts
+++ b/arch/arm/dts/at91sam9g20-taurus.dts
@@ -98,6 +98,7 @@
};
 
watchdog@fd40 {
+   timeout-sec = <15>;
status = "okay";
};
 
diff --git a/arch/arm/mach-at91/spl.c b/arch/arm/mach-at91/spl.c
index 8bfb2a4..6da6d41 100644
--- a/arch/arm/mach-at91/spl.c
+++ b/arch/arm/mach-at91/spl.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
 void at91_disable_wdt(void)
 {
struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
diff --git a/arch/arm/mach-at91/spl_at91.c b/arch/arm/mach-at91/spl_at91.c
index 8c36804..23ebaa9 100644
--- a/arch/arm/mach-at91/spl_at91.c
+++ b/arch/arm/mach-at91/spl_at91.c
@@ -76,7 +76,7 @@ void __weak spl_board_init(void)
 void board_init_f(ulong dummy)
 {
lowlevel_clock_init();
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
at91_disable_wdt();
 #endif
 
diff --git a/arch/arm/mach-at91/spl_atmel.c b/arch/arm/mach-at91/spl_atmel.c
index 597ff8c..ef745c9 100644
--- a/arch/arm/mach-at91/spl_atmel.c
+++ b/arch/arm/mach-at91/spl_atmel.c
@@ -98,7 +98,7 @@ void board_init_f(ulong dummy)
configure_2nd_sram_as_l2_cache();
 #endif
 
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
/* disable watchdog */
at91_disable_wdt();
 #endif
diff --git a/common/board_f.c b/common/board_f.c
index 88d7700..9c0487f 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -89,7 +89,7 @@ static int init_func_watchdog_init(void)
 {
 # if defined(CONFIG_HW_WATCHDOG) && \
(defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
-   defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
+   defined(CONFIG_SH) || \
defined(CONFIG_DESIGNWARE_WATCHDOG) || \
defined(CONFIG_IMX_WATCHDOG))
hw_watchdog_init();
diff --git a/configs/picosam9g45_defconfig b/configs/picosam9g45_defconfig
index 0b6234f..28bb6df 100644
--- a/configs/picosam9g45_defconfig
+++ b/configs/picosam9g45_defconfig
@@ -39,3 +39,5 @@ CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
 CONFIG_LCD=y
 CONFIG_OF_LIBFDT=y
+CONFIG_WDT=y
+CONFIG_WDT_AT91=y
diff --git a/configs/smartweb_defconfig b/configs/smartweb_defconfig
index b0bb18a..0bda9ad 100644
--- a/configs/smartweb_defconfig
+++ b/configs/smartweb_defconfig
@@ -60,3 +60,5 @@ CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_MCS7830=y
 CONFIG_SPL_TINY_MEMSET=y
 # CONFIG_EFI_LOADER is not set
+CONFIG_WDT=y
+CONFIG_WDT_AT91=y
diff --git a/configs/taurus_defconfig b/configs/taurus_defconfig
index bafd8ab..fc4ac4a 100644
--- a/configs/taurus_defconfig
+++ b/configs/taurus_defconfig
@@ -62,3 +62,5 @@ CONFIG_USB_GADGET_VENDOR_NUM=0x0908
 CONFIG_USB_GADGET_PRODUCT_NUM=0x02d2
 CONFIG_USB_GADGET_DOWNLOAD=y
 CONF

[U-Boot] [PATCH v2 2/2] arm: at91: wdt: Convert watchdog config to Kconfig

2018-09-15 Thread Prasanthi Chellakumar
Convert "CONFIG_AT91SAM9_WATCHDOG" to new "CONFIG_WDT_AT91"
Kconfig option to support driver model and device tree.

Signed-off-by: Prasanthi Chellakumar 
---
 README| 3 ---
 arch/arm/dts/at91sam9260-smartweb.dts | 1 +
 arch/arm/dts/at91sam9g20-taurus.dts   | 1 +
 arch/arm/mach-at91/spl.c  | 2 +-
 arch/arm/mach-at91/spl_at91.c | 2 +-
 arch/arm/mach-at91/spl_atmel.c| 2 +-
 common/board_f.c  | 2 +-
 configs/picosam9g45_defconfig | 2 ++
 configs/smartweb_defconfig| 2 ++
 configs/taurus_defconfig  | 2 ++
 doc/README.at91   | 2 +-
 doc/README.watchdog   | 2 +-
 include/configs/picosam9g45.h | 4 
 include/configs/smartweb.h| 7 ---
 include/configs/taurus.h  | 7 ---
 scripts/config_whitelist.txt  | 2 --
 16 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/README b/README
index 09822a3..07b2be1 100644
--- a/README
+++ b/README
@@ -802,9 +802,6 @@ The following options need to be configured:
SoC, then define this variable and provide board
specific code for the "hw_watchdog_reset" function.
 
-   CONFIG_AT91_HW_WDT_TIMEOUT
-   specify the timeout in seconds. default 2 seconds.
-
 - Real-Time Clock:
 
When CONFIG_CMD_DATE is selected, the type of the RTC
diff --git a/arch/arm/dts/at91sam9260-smartweb.dts 
b/arch/arm/dts/at91sam9260-smartweb.dts
index e59781b..a22de2d 100644
--- a/arch/arm/dts/at91sam9260-smartweb.dts
+++ b/arch/arm/dts/at91sam9260-smartweb.dts
@@ -89,6 +89,7 @@
};
 
watchdog@fd40 {
+   timeout-sec = <15>;
status = "okay";
};
 
diff --git a/arch/arm/dts/at91sam9g20-taurus.dts 
b/arch/arm/dts/at91sam9g20-taurus.dts
index 7931c0a..cee228b 100644
--- a/arch/arm/dts/at91sam9g20-taurus.dts
+++ b/arch/arm/dts/at91sam9g20-taurus.dts
@@ -98,6 +98,7 @@
};
 
watchdog@fd40 {
+   timeout-sec = <15>;
status = "okay";
};
 
diff --git a/arch/arm/mach-at91/spl.c b/arch/arm/mach-at91/spl.c
index 8bfb2a4..6da6d41 100644
--- a/arch/arm/mach-at91/spl.c
+++ b/arch/arm/mach-at91/spl.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
 void at91_disable_wdt(void)
 {
struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
diff --git a/arch/arm/mach-at91/spl_at91.c b/arch/arm/mach-at91/spl_at91.c
index 8c36804..23ebaa9 100644
--- a/arch/arm/mach-at91/spl_at91.c
+++ b/arch/arm/mach-at91/spl_at91.c
@@ -76,7 +76,7 @@ void __weak spl_board_init(void)
 void board_init_f(ulong dummy)
 {
lowlevel_clock_init();
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
at91_disable_wdt();
 #endif
 
diff --git a/arch/arm/mach-at91/spl_atmel.c b/arch/arm/mach-at91/spl_atmel.c
index 597ff8c..ef745c9 100644
--- a/arch/arm/mach-at91/spl_atmel.c
+++ b/arch/arm/mach-at91/spl_atmel.c
@@ -98,7 +98,7 @@ void board_init_f(ulong dummy)
configure_2nd_sram_as_l2_cache();
 #endif
 
-#if !defined(CONFIG_AT91SAM9_WATCHDOG)
+#if !defined(CONFIG_WDT_AT91)
/* disable watchdog */
at91_disable_wdt();
 #endif
diff --git a/common/board_f.c b/common/board_f.c
index 88d7700..9c0487f 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -89,7 +89,7 @@ static int init_func_watchdog_init(void)
 {
 # if defined(CONFIG_HW_WATCHDOG) && \
(defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
-   defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
+   defined(CONFIG_SH) || \
defined(CONFIG_DESIGNWARE_WATCHDOG) || \
defined(CONFIG_IMX_WATCHDOG))
hw_watchdog_init();
diff --git a/configs/picosam9g45_defconfig b/configs/picosam9g45_defconfig
index 0b6234f..28bb6df 100644
--- a/configs/picosam9g45_defconfig
+++ b/configs/picosam9g45_defconfig
@@ -39,3 +39,5 @@ CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
 CONFIG_LCD=y
 CONFIG_OF_LIBFDT=y
+CONFIG_WDT=y
+CONFIG_WDT_AT91=y
diff --git a/configs/smartweb_defconfig b/configs/smartweb_defconfig
index b0bb18a..0bda9ad 100644
--- a/configs/smartweb_defconfig
+++ b/configs/smartweb_defconfig
@@ -60,3 +60,5 @@ CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_MCS7830=y
 CONFIG_SPL_TINY_MEMSET=y
 # CONFIG_EFI_LOADER is not set
+CONFIG_WDT=y
+CONFIG_WDT_AT91=y
diff --git a/configs/taurus_defconfig b/configs/taurus_defconfig
index bafd8ab..fc4ac4a 100644
--- a/configs/taurus_defconfig
+++ b/configs/taurus_defconfig
@@ -62,3 +62,5 @@ CONFIG_USB_GADGET_VENDOR_NUM=0x0908
 CONFIG_USB_GADGET_PRODUCT_NUM=0x02d2
 CONFIG_USB_GADGET_DOWNLOAD=y
 CONF

[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_TIMEOU

Re: [U-Boot] [PATCH v1] arm: at91: wdt: Convert watchdog driver to dm

2018-08-24 Thread Prasanthi . Chellakumar



On 08/10/2018 07:53 AM, Tom Rini wrote:

On Thu, Jul 26, 2018 at 02:56:27PM -0700, Prasanthi Chellakumar wrote:


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| 105 +
  4 files changed, 95 insertions(+), 31 deletions(-)

Thanks for doing the conversion.   It's fine to rename the config option
to match the rest of the WDT drivers but you need to update all of the
existing users now too, thanks!



Noted. Thanks for reviewing.

Prasanthi
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v1] arm: at91: wdt: Convert watchdog driver to dm

2018-07-28 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| 105 +
 4 files changed, 95 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 f405f51..3f4fd59 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), 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..d3f8fa6 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
+
+struct at91_wdt_priv {
+   void __iomem *regs;
+   u32 regval;
+};
 
 /*
  * 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) {
+   printf("Invalid watchdog counter