[U-Boot] [PATCH 04/22] ARM: sunxi: watchdog support

Henrik Nordström henrik at henriknordstrom.net
Sun Nov 25 12:47:11 CET 2012


This adds support for the hardware watchdog in Allwinner
sun4i & sun5i (sunxi) SoC familiy.

From: Henrik Nordstrom <henrik at henriknordstrom.net>

Signed-off-by: Henrik Nordstrom <henrik at henriknordstrom.net>
Signed-off-by: Stefan Roese <sr at denx.de>
---
 arch/arm/cpu/armv7/sunxi/board.c            |    3 ++
 arch/arm/include/asm/arch-sunxi/sys_proto.h |    1 -
 drivers/watchdog/Makefile                   |    1 +
 drivers/watchdog/sunxi_watchdog.c           |   49 +++++++++++++++++++++++++++
 include/configs/sunxi-common.h              |    4 ++
 5 files changed, 57 insertions(+), 1 deletions(-)
 create mode 100644 drivers/watchdog/sunxi_watchdog.c

diff --git a/arch/arm/cpu/armv7/sunxi/board.c b/arch/arm/cpu/armv7/sunxi/board.c
index 652c19d..5c94110 100644
--- a/arch/arm/cpu/armv7/sunxi/board.c
+++ b/arch/arm/cpu/armv7/sunxi/board.c
@@ -59,6 +59,9 @@ int gpio_init(void)
 /* do some early init */
 void s_init(void)
 {
+#if defined(CONFIG_WATCHDOG) && defined(CONFIG_SUNXI_WATCHDOG)
+	watchdog_set(23);	/* max possible timeout */
+#endif
 	clock_init();
 	gpio_init();
 }
diff --git a/arch/arm/include/asm/arch-sunxi/sys_proto.h b/arch/arm/include/asm/arch-sunxi/sys_proto.h
index 1e8ae5d..9729100 100644
--- a/arch/arm/include/asm/arch-sunxi/sys_proto.h
+++ b/arch/arm/include/asm/arch-sunxi/sys_proto.h
@@ -27,6 +27,5 @@
 
 void sr32(u32 *, u32, u32, u32);
 void sdelay(unsigned long);
-void watchdog_init(void);
 
 #endif
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 923acb9..50b5fae 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -28,6 +28,7 @@ LIB	:= $(obj)libwatchdog.o
 COBJS-$(CONFIG_AT91SAM9_WATCHDOG) += at91sam9_wdt.o
 COBJS-$(CONFIG_FTWDT010_WATCHDOG) += ftwdt010_wdt.o
 COBJS-$(CONFIG_TNETV107X_WATCHDOG) += tnetv107x_wdt.o
+COBJS-$(CONFIG_SUNXI_WATCHDOG)    += sunxi_watchdog.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/watchdog/sunxi_watchdog.c b/drivers/watchdog/sunxi_watchdog.c
new file mode 100644
index 0000000..65a763d
--- /dev/null
+++ b/drivers/watchdog/sunxi_watchdog.c
@@ -0,0 +1,49 @@
+/*
+ * (C) Copyright 2012 Henrik Nordstrom <henrik at hno.se>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <asm/arch/timer.h>
+#include <asm/armv7.h>
+#include <asm/io.h>
+
+void watchdog_reset(void)
+{
+	static struct sunxi_wdog *const wdog =
+		&((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
+
+	/* a little magic to reload the watchdog */
+	writel(0xA57 << 1 | 1 << 0, &wdog->ctl);
+}
+
+static void watchdog_set(int interval)
+{
+	static struct sunxi_wdog *const wdog =
+		&((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
+
+	/* Set timeout, reset & enable */
+	writel(interval << 2 | 1 << 1 | 1 << 0, &wdog->mode);
+	watchdog_reset();
+}
+
+void watchdog_init(void)
+{
+#ifdef CONFIG_WATCHDOG
+	watchdog_set(23);	/* max possible timeout */
+#endif
+}
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index c2d16fb..5bf8eea 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -202,4 +202,8 @@
 #define CONFIG_SYS_I2C_SLAVE		0x7f
 #define CONFIG_CMD_I2C
 
+/* Watchdog */
+/* #define CONFIG_WATCHDOG */
+/* #define CONFIG_SUNXI_WATCHDOG */
+
 #endif /* __CONFIG_H */
-- 
1.7.7.6




More information about the U-Boot mailing list