From: Stefan Roese <sr@denx.de>
Date: Tue, 9 Oct 2018 06:59:10 +0000 (+0200)
Subject: mips: mt76xx: Enable watchdog support
X-Git-Tag: v2025.01-rc5-pxa1908~3274^2~9
X-Git-Url: http://git.dujemihanovic.xyz/%22http:/kyber.dk/phpMyBuilder/static/%7B%7B%20%28.OutputFormats.Get?a=commitdiff_plain;h=4ff942b059c66c943a3ae94b6f96b3de239e9eaa;p=u-boot.git

mips: mt76xx: Enable watchdog support

This patch enables and starts the watchdog on the MT7620 platform.
Currently the WD timeout is configured to 60 seconds.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
[fixed build error due to missing function prototype arch_misc_init]
Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
---

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 8278c68817..1b1b1d7d00 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -79,6 +79,7 @@ config ARCH_MT7620
 	select DM_SERIAL
 	imply DM_SPI
 	imply DM_SPI_FLASH
+	select ARCH_MISC_INIT if WATCHDOG
 	select MIPS_TUNE_24KC
 	select OF_CONTROL
 	select ROM_EXCEPTION_VECTORS
diff --git a/arch/mips/include/asm/u-boot-mips.h b/arch/mips/include/asm/u-boot-mips.h
index f4bfbdc693..88438b9576 100644
--- a/arch/mips/include/asm/u-boot-mips.h
+++ b/arch/mips/include/asm/u-boot-mips.h
@@ -7,4 +7,6 @@ void exc_handler(void);
 void except_vec3_generic(void);
 void except_vec_ejtag_debug(void);
 
+int arch_misc_init(void);
+
 #endif /* _U_BOOT_MIPS_H_ */
diff --git a/arch/mips/mach-mt7620/cpu.c b/arch/mips/mach-mt7620/cpu.c
index 457f09f32c..87cc973b75 100644
--- a/arch/mips/mach-mt7620/cpu.c
+++ b/arch/mips/mach-mt7620/cpu.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <dm.h>
 #include <ram.h>
+#include <wdt.h>
 #include <asm/io.h>
 #include <linux/io.h>
 #include <linux/sizes.h>
@@ -67,3 +68,42 @@ int print_cpuinfo(void)
 
 	return 0;
 }
+
+#ifdef CONFIG_WATCHDOG
+static struct udevice *watchdog_dev;
+
+/* Called by macro WATCHDOG_RESET */
+void watchdog_reset(void)
+{
+	static ulong next_reset;
+	ulong now;
+
+	if (!watchdog_dev)
+		return;
+
+	now = get_timer(0);
+
+	/* Do not reset the watchdog too often */
+	if (now > next_reset) {
+		next_reset = now + 1000;	/* reset every 1000ms */
+		wdt_reset(watchdog_dev);
+	}
+}
+
+int arch_misc_init(void)
+{
+	/* Init watchdog */
+	if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) {
+		debug("Watchdog: Not found by seq!\n");
+		if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
+			puts("Watchdog: Not found!\n");
+			return 0;
+		}
+	}
+
+	wdt_start(watchdog_dev, 60000, 0);	/* 60 seconds */
+	printf("Watchdog: Started\n");
+
+	return 0;
+}
+#endif