summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/arm/dts/at91sam9260-smartweb.dts1
-rw-r--r--arch/arm/dts/at91sam9g20-taurus.dts1
-rw-r--r--arch/arm/mach-at91/include/mach/at91_wdt.h6
-rw-r--r--arch/arm/mach-at91/spl.c2
-rw-r--r--arch/arm/mach-at91/spl_at91.c2
-rw-r--r--arch/arm/mach-at91/spl_atmel.c2
-rw-r--r--common/board_f.c2
-rw-r--r--configs/picosam9g45_defconfig4
-rw-r--r--configs/smartweb_defconfig3
-rw-r--r--configs/taurus_defconfig3
-rw-r--r--doc/README.at912
-rw-r--r--doc/README.watchdog2
-rw-r--r--drivers/watchdog/Kconfig10
-rw-r--r--drivers/watchdog/Makefile2
-rw-r--r--drivers/watchdog/at91sam9_wdt.c104
-rw-r--r--include/configs/picosam9g45.h4
-rw-r--r--include/configs/smartweb.h7
-rw-r--r--include/configs/taurus.h7
-rw-r--r--scripts/config_whitelist.txt1
19 files changed, 114 insertions, 51 deletions
diff --git a/arch/arm/dts/at91sam9260-smartweb.dts b/arch/arm/dts/at91sam9260-smartweb.dts
index e59781bf45..a22de2d927 100644
--- a/arch/arm/dts/at91sam9260-smartweb.dts
+++ b/arch/arm/dts/at91sam9260-smartweb.dts
@@ -89,6 +89,7 @@
};
watchdog@fffffd40 {
+ timeout-sec = <15>;
status = "okay";
};
diff --git a/arch/arm/dts/at91sam9g20-taurus.dts b/arch/arm/dts/at91sam9g20-taurus.dts
index 7931c0af7b..cee228bb8c 100644
--- a/arch/arm/dts/at91sam9g20-taurus.dts
+++ b/arch/arm/dts/at91sam9g20-taurus.dts
@@ -98,6 +98,7 @@
};
watchdog@fffffd40 {
+ 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 99b0cc812d..cd2272367b 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 <plagnioj@jcrosoft.com>
* 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_CR 0x00
#define AT91_WDT_CR_WDRSTT 1
#define AT91_WDT_CR_KEY 0xa5000000 /* KEY Password */
+/* Watchdog Mode Register*/
+#define AT91_WDT_MR 0X04
#define AT91_WDT_MR_WDV(x) (x & 0xfff)
#define AT91_WDT_MR_WDFIEN 0x00001000
#define AT91_WDT_MR_WDRSTEN 0x00002000
diff --git a/arch/arm/mach-at91/spl.c b/arch/arm/mach-at91/spl.c
index 8bfb2a452b..6da6d41be2 100644
--- a/arch/arm/mach-at91/spl.c
+++ b/arch/arm/mach-at91/spl.c
@@ -11,7 +11,7 @@
#include <asm/arch/clk.h>
#include <spl.h>
-#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 8c368042a6..23ebaa99b1 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 597ff8c036..ef745c9477 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 96503ff8d3..f1a1432d86 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_defconfig b/configs/picosam9g45_defconfig
index df979f9326..699e2e230a 100644
--- a/configs/picosam9g45_defconfig
+++ b/configs/picosam9g45_defconfig
@@ -40,3 +40,7 @@ CONFIG_USB_EHCI_HCD=y
CONFIG_USB_STORAGE=y
CONFIG_LCD=y
CONFIG_OF_LIBFDT=y
+CONFIG_DM=y
+CONFIG_SPL_DM=y
+CONFIG_WDT=y
+CONFIG_WDT_AT91=y
diff --git a/configs/smartweb_defconfig b/configs/smartweb_defconfig
index cf6f2757ca..e9c2b63509 100644
--- a/configs/smartweb_defconfig
+++ b/configs/smartweb_defconfig
@@ -59,3 +59,6 @@ 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
+CONFIG_AT91_HW_WDT_TIMEOUT=y
diff --git a/configs/taurus_defconfig b/configs/taurus_defconfig
index ee5da43ccb..e53e075d48 100644
--- a/configs/taurus_defconfig
+++ b/configs/taurus_defconfig
@@ -61,3 +61,6 @@ CONFIG_USB_GADGET_VENDOR_NUM=0x0908
CONFIG_USB_GADGET_PRODUCT_NUM=0x02d2
CONFIG_USB_GADGET_DOWNLOAD=y
CONFIG_USE_TINY_PRINTF=y
+CONFIG_WDT=y
+CONFIG_WDT_AT91=y
+CONFIG_AT91_HW_WDT_TIMEOUT=y
diff --git a/doc/README.at91 b/doc/README.at91
index 67412136ee..39dd5632ba 100644
--- a/doc/README.at91
+++ b/doc/README.at91
@@ -171,4 +171,4 @@ III. Watchdog support
your code (make sure not to disable it in AT91Bootstrap for instance).
In the U-Boot configuration, the AT91 watchdog support is enabled using
- the CONFIG_AT91SAM9_WATCHDOG and CONFIG_HW_WATCHDOG options.
+ the CONFIG_WDT and CONFIG_WDT_AT91 options.
diff --git a/doc/README.watchdog b/doc/README.watchdog
index 7097c8766b..f23c923910 100644
--- a/doc/README.watchdog
+++ b/doc/README.watchdog
@@ -14,7 +14,7 @@ CONFIG_WATCHDOG_TIMEOUT_MSECS
If not given, will default to maximum timeout. This would
be 128000 msec for i.mx31/35/5x/6x.
-CONFIG_AT91SAM9_WATCHDOG
+CONFIG_WDT_AT91
Available for AT91SAM9 to service the watchdog.
CONFIG_FTWDT010_WATCHDOG
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 02f4e1e32f..a911dba73a 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -118,4 +118,14 @@ config IMX_WATCHDOG
Select this to enable the IMX and LSCH2 of Layerscape watchdog
driver.
+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.
+
+config AT91_HW_WDT_TIMEOUT
+ bool "AT91 watchdog timeout specified"
+ depends on WDT_AT91
endmenu
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 08406caa0f..a5c27b0f4c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -3,7 +3,7 @@
# (C) Copyright 2008
# Wolfgang Denk, DENX Software Engineering, wd@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 fca2849918..13f8772e41 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 <plagnioj@jcrosoft.com>
* Copyright (C) 2008 Renaud CERRATO r.cerrato@til-technologies.fr
@@ -14,38 +14,47 @@
* write to this register. Inform Linux to it too
*/
-#include <common.h>
-#include <watchdog.h>
-#include <asm/arch/hardware.h>
#include <asm/io.h>
#include <asm/arch/at91_wdt.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <wdt.h>
+
+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 */
- if (readl(&wd->mr) & AT91_WDT_MR_WDDIS) {
+ if (readl(priv->regs + AT91_WDT_MR) & AT91_WDT_MR_WDDIS) {
printf("sorry, watchdog is disabled\n");
return -1;
}
@@ -57,24 +66,71 @@ static int at91_wdt_settimeout(unsigned int timeout)
* 4096 / 256 = 16 seconds.
*/
- reg = AT91_WDT_MR_WDRSTEN /* causes watchdog reset */
+ priv->regval = AT91_WDT_MR_WDRSTEN /* causes watchdog reset */
| AT91_WDT_MR_WDDBGHLT /* disabled in debug mode */
| AT91_WDT_MR_WDD(0xfff) /* restart at any time */
| AT91_WDT_MR_WDV(timeout); /* timer value */
- writel(reg, &wd->mr);
+ writel(priv->regval, priv->regs + AT91_WDT_MR);
+
+ return 0;
+}
+
+static int at91_wdt_stop(struct udevice *dev)
+{
+ struct at91_wdt_priv *priv = dev_get_priv(dev);
+
+ /* Disable Watchdog Timer */
+ priv->regval |= AT91_WDT_MR_WDDIS;
+ writel(priv->regval, priv->regs + AT91_WDT_MR);
return 0;
}
-void hw_watchdog_reset(void)
+static int at91_wdt_reset(struct udevice *dev)
{
- at91_wdt_t *wd = (at91_wdt_t *) ATMEL_BASE_WDT;
- writel(AT91_WDT_CR_WDRSTT | AT91_WDT_CR_KEY, &wd->cr);
+ struct at91_wdt_priv *priv = dev_get_priv(dev);
+
+ writel(AT91_WDT_CR_WDRSTT | AT91_WDT_CR_KEY, priv->regs + AT91_WDT_CR);
+
+ return 0;
}
-void hw_watchdog_init(void)
+static const struct wdt_ops at91_wdt_ops = {
+ .start = at91_wdt_start,
+ .stop = at91_wdt_stop,
+ .reset = at91_wdt_reset,
+};
+
+static const struct udevice_id at91_wdt_ids[] = {
+ { .compatible = "atmel,at91sam9260-wdt" },
+ {}
+};
+
+static int at91_wdt_probe(struct udevice *dev)
{
- /* 16 seconds timer, resets enabled */
- at91_wdt_settimeout(ms_to_ticks(WDT_HW_TIMEOUT * 1000));
+ struct at91_wdt_priv *priv = dev_get_priv(dev);
+
+ priv->regs = dev_remap_addr(dev);
+ if (!priv->regs)
+ return -EINVAL;
+
+#ifdef CONFIG_AT91_HW_WDT_TIMEOUT
+ priv->timeout = dev_read_u32_default(dev, "timeout-sec",
+ WDT_DEFAULT_TIMEOUT);
+ debug("%s: timeout %d", __func__, priv->timeout);
+#endif
+
+ debug("%s: Probing wdt%u\n", __func__, dev->seq);
+
+ return 0;
}
+
+U_BOOT_DRIVER(at91_wdt) = {
+ .name = "at91_wdt",
+ .id = UCLASS_WDT,
+ .of_match = at91_wdt_ids,
+ .priv_auto_alloc_size = sizeof(struct at91_wdt_priv),
+ .ops = &at91_wdt_ops,
+ .probe = at91_wdt_probe,
+};
diff --git a/include/configs/picosam9g45.h b/include/configs/picosam9g45.h
index 0b240e7ebc..c2882e6daf 100644
--- a/include/configs/picosam9g45.h
+++ b/include/configs/picosam9g45.h
@@ -57,10 +57,6 @@
*/
#define CONFIG_BOOTP_BOOTFILESIZE
-/* Enable the watchdog */
-#define CONFIG_AT91SAM9_WATCHDOG
-#define CONFIG_HW_WATCHDOG
-
/*
* Command line configuration.
*/
diff --git a/include/configs/smartweb.h b/include/configs/smartweb.h
index 114b87e1b3..28af575bf2 100644
--- a/include/configs/smartweb.h
+++ b/include/configs/smartweb.h
@@ -112,13 +112,6 @@
"root=/dev/nfs ip=dhcp nfsroot=${serverip}:/srv/nfs/rootfs; " \
"dhcp"
-/* Enable the watchdog */
-#define CONFIG_AT91SAM9_WATCHDOG
-#if !defined(CONFIG_SPL_BUILD)
-#define CONFIG_HW_WATCHDOG
-#endif
-#define CONFIG_AT91_HW_WDT_TIMEOUT 15
-
#if !defined(CONFIG_SPL_BUILD)
/* USB configuration */
#define CONFIG_USB_ATMEL
diff --git a/include/configs/taurus.h b/include/configs/taurus.h
index 4fdb0dd962..f283ab7fca 100644
--- a/include/configs/taurus.h
+++ b/include/configs/taurus.h
@@ -85,13 +85,6 @@
#define CONFIG_RMII
#define CONFIG_AT91_WANTS_COMMON_PHY
-#define CONFIG_AT91SAM9_WATCHDOG
-#define CONFIG_AT91_HW_WDT_TIMEOUT 15
-#if !defined(CONFIG_SPL_BUILD)
-/* Enable the watchdog */
-#define CONFIG_HW_WATCHDOG
-#endif
-
/* USB */
#if defined(CONFIG_BOARD_TAURUS)
#define CONFIG_USB_ATMEL
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
index 0627024e71..abfb0ff89f 100644
--- a/scripts/config_whitelist.txt
+++ b/scripts/config_whitelist.txt
@@ -82,7 +82,6 @@ CONFIG_AT91SAM9G20EK_2MMC
CONFIG_AT91SAM9G45EKES
CONFIG_AT91SAM9G45_LCD_BASE
CONFIG_AT91SAM9M10G45EK
-CONFIG_AT91SAM9_WATCHDOG
CONFIG_AT91_CAN
CONFIG_AT91_EFLASH
CONFIG_AT91_GPIO_PULLUP