arm: mvebu: x530: Enable watchdog in SPL and U-Boot
authorChris Packham <judge.packham@gmail.com>
Sun, 17 Feb 2019 21:30:54 +0000 (10:30 +1300)
committerStefan Roese <sr@denx.de>
Fri, 12 Apr 2019 05:04:18 +0000 (07:04 +0200)
Enable the hardware watchdog to guard against system lock ups when
running in the SPL or U-Boot. Stop the watchdog just before booting so
that the OS can re-enable it if needed.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Reviewed-by: Stefan Roese <sr@denx.de>
Signed-off-by: Stefan Roese <sr@denx.de>
arch/arm/dts/armada-385-atl-x530-u-boot.dtsi
board/alliedtelesis/x530/x530.c
configs/x530_defconfig

index 7074a73537fa739a82a24d6aaa2890dbb271ae64..79b694cb84bce0935936d3a150576e8c9d1083c9 100644 (file)
@@ -11,3 +11,7 @@
 &uart0 {
        u-boot,dm-pre-reloc;
 };
+
+&watchdog {
+       u-boot,dm-pre-reloc;
+};
index d7d1942fe686aa59138894cff4a881c4a879e8eb..6934fd80173072c8ef5d1bf0624ff8819d7845ed 100644 (file)
@@ -7,6 +7,7 @@
 #include <command.h>
 #include <dm.h>
 #include <i2c.h>
+#include <wdt.h>
 #include <asm/gpio.h>
 #include <linux/mbus.h>
 #include <linux/io.h>
@@ -24,6 +25,10 @@ DECLARE_GLOBAL_DATA_PTR;
 #define CONFIG_NVS_LOCATION            0xf4800000
 #define CONFIG_NVS_SIZE                        (512 << 10)
 
+#ifdef CONFIG_WATCHDOG
+static struct udevice *watchdog_dev;
+#endif
+
 static struct serdes_map board_serdes_map[] = {
        {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
        {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
@@ -75,6 +80,10 @@ struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
 
 int board_early_init_f(void)
 {
+#ifdef CONFIG_WATCHDOG
+       watchdog_dev = NULL;
+#endif
+
        /* Configure MPP */
        writel(0x00001111, MVEBU_MPP_BASE + 0x00);
        writel(0x00000000, MVEBU_MPP_BASE + 0x04);
@@ -88,6 +97,17 @@ int board_early_init_f(void)
        return 0;
 }
 
+void spl_board_init(void)
+{
+#ifdef CONFIG_WATCHDOG
+       int ret;
+
+       ret = uclass_get_device(UCLASS_WDT, 0, &watchdog_dev);
+       if (!ret)
+               wdt_start(watchdog_dev, 120000, 0);
+#endif
+}
+
 int board_init(void)
 {
        /* address of boot parameters */
@@ -100,9 +120,37 @@ int board_init(void)
        /* DEV_READYn is not needed for NVS, ignore it when accessing CS1 */
        writel(0x00004001, MVEBU_DEV_BUS_BASE + 0xc8);
 
+       spl_board_init();
+
        return 0;
 }
 
+void arch_preboot_os(void)
+{
+#ifdef CONFIG_WATCHDOG
+       wdt_stop(watchdog_dev);
+#endif
+}
+
+#ifdef CONFIG_WATCHDOG
+void watchdog_reset(void)
+{
+       static ulong next_reset = 0;
+       ulong now;
+
+       if (!watchdog_dev)
+               return;
+
+       now = timer_get_us();
+
+       /* Do not reset the watchdog too often */
+       if (now > next_reset) {
+               wdt_reset(watchdog_dev);
+               next_reset = now + 1000;
+       }
+}
+#endif
+
 static int led_7seg_init(unsigned int segments)
 {
        int node;
index cd18e9eb454b61539ad17d6f318a8484c32058ec..c893c44452b185153dc8854494c32754d780bc93 100644 (file)
@@ -19,6 +19,8 @@ CONFIG_SILENT_CONSOLE=y
 CONFIG_SILENT_U_BOOT_ONLY=y
 CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC=y
 CONFIG_MISC_INIT_R=y
+CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_WATCHDOG_SUPPORT=y
 CONFIG_CMD_MEMINFO=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_GPIO=y
@@ -72,3 +74,6 @@ CONFIG_USB_STORAGE=y
 CONFIG_USB_HOST_ETHER=y
 CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_ASIX88179=y
+CONFIG_WATCHDOG=y
+CONFIG_WDT=y
+CONFIG_WDT_ORION=y