dm: wdt: arm: Move tnetv107x into drivers/watchdog/
authorMarek Vasut <marex@denx.de>
Sat, 21 Jul 2012 05:02:21 +0000 (05:02 +0000)
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>
Thu, 18 Oct 2012 04:52:02 +0000 (06:52 +0200)
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Oliver Brown <obrown@adventnetworks.com>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Albert Aribaud <albert.u.boot@aribaud.net>
Cc: U-Boot DM <u-boot-dm@lists.denx.de>
arch/arm/cpu/arm1176/tnetv107x/Makefile
arch/arm/cpu/arm1176/tnetv107x/wdt.c [deleted file]
drivers/watchdog/Makefile
drivers/watchdog/tnetv107x_wdt.c [new file with mode: 0644]
include/configs/tnetv107x_evm.h

index c63dc925efb725eea21858c7b13217e0da201081..c1d4d678c0cb6d6fa0eea55d5579e8f467a80b69 100644 (file)
@@ -21,7 +21,7 @@ include $(TOPDIR)/config.mk
 
 LIB    = $(obj)lib$(SOC).o
 
-COBJS  += aemif.o clock.o init.o mux.o timer.o wdt.o
+COBJS  += aemif.o clock.o init.o mux.o timer.o
 SOBJS  += lowlevel_init.o
 
 SRCS   := $(START:.o=.S) $(SOBJS:.o=.S) $(COBJS:.o=.c)
diff --git a/arch/arm/cpu/arm1176/tnetv107x/wdt.c b/arch/arm/cpu/arm1176/tnetv107x/wdt.c
deleted file mode 100644 (file)
index 18aadb0..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * TNETV107X: Watchdog timer implementation (for reset)
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <common.h>
-#include <asm/io.h>
-#include <asm/arch/clock.h>
-
-#define MAX_DIV                0xFFFE0001
-
-struct wdt_regs {
-       u32 kick_lock;
-#define KICK_LOCK_1    0x5555
-#define KICK_LOCK_2    0xaaaa
-       u32 kick;
-
-       u32 change_lock;
-#define CHANGE_LOCK_1  0x6666
-#define CHANGE_LOCK_2  0xbbbb
-       u32 change;
-
-       u32 disable_lock;
-#define DISABLE_LOCK_1 0x7777
-#define DISABLE_LOCK_2 0xcccc
-#define DISABLE_LOCK_3 0xdddd
-       u32 disable;
-
-       u32 prescale_lock;
-#define PRESCALE_LOCK_1        0x5a5a
-#define PRESCALE_LOCK_2        0xa5a5
-       u32 prescale;
-};
-
-static struct wdt_regs* regs = (struct wdt_regs *)TNETV107X_WDT0_ARM_BASE;
-
-#define wdt_reg_read(reg)      __raw_readl(&regs->reg)
-#define wdt_reg_write(reg, val)        __raw_writel((val), &regs->reg)
-
-static int write_prescale_reg(unsigned long prescale_value)
-{
-       wdt_reg_write(prescale_lock, PRESCALE_LOCK_1);
-       if ((wdt_reg_read(prescale_lock) & 0x3) != 0x1)
-               return -1;
-
-       wdt_reg_write(prescale_lock, PRESCALE_LOCK_2);
-       if ((wdt_reg_read(prescale_lock) & 0x3) != 0x3)
-               return -1;
-
-       wdt_reg_write(prescale, prescale_value);
-
-       return 0;
-}
-
-static int write_change_reg(unsigned long initial_timer_value)
-{
-       wdt_reg_write(change_lock, CHANGE_LOCK_1);
-       if ((wdt_reg_read(change_lock) & 0x3) != 0x1)
-               return -1;
-
-       wdt_reg_write(change_lock, CHANGE_LOCK_2);
-       if ((wdt_reg_read(change_lock) & 0x3) != 0x3)
-               return -1;
-
-       wdt_reg_write(change, initial_timer_value);
-
-       return 0;
-}
-
-static int wdt_control(unsigned long disable_value)
-{
-       wdt_reg_write(disable_lock, DISABLE_LOCK_1);
-       if ((wdt_reg_read(disable_lock) & 0x3) != 0x1)
-               return -1;
-
-       wdt_reg_write(disable_lock, DISABLE_LOCK_2);
-       if ((wdt_reg_read(disable_lock) & 0x3) != 0x2)
-               return -1;
-
-       wdt_reg_write(disable_lock, DISABLE_LOCK_3);
-       if ((wdt_reg_read(disable_lock) & 0x3) != 0x3)
-               return -1;
-
-       wdt_reg_write(disable, disable_value);
-       return 0;
-}
-
-static int wdt_set_period(unsigned long msec)
-{
-       unsigned long change_value, count_value;
-       unsigned long prescale_value = 1;
-       unsigned long refclk_khz, maxdiv;
-       int ret;
-
-       refclk_khz = clk_get_rate(TNETV107X_LPSC_WDT_ARM);
-       maxdiv = (MAX_DIV / refclk_khz);
-
-       if ((!msec) || (msec > maxdiv))
-               return -1;
-
-       count_value = refclk_khz * msec;
-       if (count_value > 0xffff) {
-               change_value = count_value / 0xffff + 1;
-               prescale_value = count_value / change_value;
-       } else {
-               change_value = count_value;
-       }
-
-       ret = write_prescale_reg(prescale_value - 1);
-       if (ret)
-               return ret;
-
-       ret = write_change_reg(change_value);
-       if (ret)
-               return ret;
-
-       return 0;
-}
-
-unsigned long last_wdt = -1;
-
-int wdt_start(unsigned long msecs)
-{
-       int ret;
-       ret = wdt_control(0);
-       if (ret)
-               return ret;
-       ret = wdt_set_period(msecs);
-       if (ret)
-               return ret;
-       ret = wdt_control(1);
-       if (ret)
-               return ret;
-       ret = wdt_kick();
-       last_wdt = msecs;
-       return ret;
-}
-
-int wdt_stop(void)
-{
-       last_wdt = -1;
-       return wdt_control(0);
-}
-
-int wdt_kick(void)
-{
-       wdt_reg_write(kick_lock, KICK_LOCK_1);
-       if ((wdt_reg_read(kick_lock) & 0x3) != 0x1)
-               return -1;
-
-       wdt_reg_write(kick_lock, KICK_LOCK_2);
-       if ((wdt_reg_read(kick_lock) & 0x3) != 0x3)
-               return -1;
-
-       wdt_reg_write(kick, 1);
-       return 0;
-}
-
-void reset_cpu(ulong addr)
-{
-       clk_enable(TNETV107X_LPSC_WDT_ARM);
-       wdt_start(1);
-       wdt_kick();
-}
index 5579bf2f1416a1a2b847b2bc038a3ac58f6f0c42..923acb9f3af40b8eb8329fbf146979d290102844 100644 (file)
@@ -27,6 +27,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  := $(COBJS-y)
 SRCS   := $(COBJS:.o=.c)
diff --git a/drivers/watchdog/tnetv107x_wdt.c b/drivers/watchdog/tnetv107x_wdt.c
new file mode 100644 (file)
index 0000000..18aadb0
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * TNETV107X: Watchdog timer implementation (for reset)
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/arch/clock.h>
+
+#define MAX_DIV                0xFFFE0001
+
+struct wdt_regs {
+       u32 kick_lock;
+#define KICK_LOCK_1    0x5555
+#define KICK_LOCK_2    0xaaaa
+       u32 kick;
+
+       u32 change_lock;
+#define CHANGE_LOCK_1  0x6666
+#define CHANGE_LOCK_2  0xbbbb
+       u32 change;
+
+       u32 disable_lock;
+#define DISABLE_LOCK_1 0x7777
+#define DISABLE_LOCK_2 0xcccc
+#define DISABLE_LOCK_3 0xdddd
+       u32 disable;
+
+       u32 prescale_lock;
+#define PRESCALE_LOCK_1        0x5a5a
+#define PRESCALE_LOCK_2        0xa5a5
+       u32 prescale;
+};
+
+static struct wdt_regs* regs = (struct wdt_regs *)TNETV107X_WDT0_ARM_BASE;
+
+#define wdt_reg_read(reg)      __raw_readl(&regs->reg)
+#define wdt_reg_write(reg, val)        __raw_writel((val), &regs->reg)
+
+static int write_prescale_reg(unsigned long prescale_value)
+{
+       wdt_reg_write(prescale_lock, PRESCALE_LOCK_1);
+       if ((wdt_reg_read(prescale_lock) & 0x3) != 0x1)
+               return -1;
+
+       wdt_reg_write(prescale_lock, PRESCALE_LOCK_2);
+       if ((wdt_reg_read(prescale_lock) & 0x3) != 0x3)
+               return -1;
+
+       wdt_reg_write(prescale, prescale_value);
+
+       return 0;
+}
+
+static int write_change_reg(unsigned long initial_timer_value)
+{
+       wdt_reg_write(change_lock, CHANGE_LOCK_1);
+       if ((wdt_reg_read(change_lock) & 0x3) != 0x1)
+               return -1;
+
+       wdt_reg_write(change_lock, CHANGE_LOCK_2);
+       if ((wdt_reg_read(change_lock) & 0x3) != 0x3)
+               return -1;
+
+       wdt_reg_write(change, initial_timer_value);
+
+       return 0;
+}
+
+static int wdt_control(unsigned long disable_value)
+{
+       wdt_reg_write(disable_lock, DISABLE_LOCK_1);
+       if ((wdt_reg_read(disable_lock) & 0x3) != 0x1)
+               return -1;
+
+       wdt_reg_write(disable_lock, DISABLE_LOCK_2);
+       if ((wdt_reg_read(disable_lock) & 0x3) != 0x2)
+               return -1;
+
+       wdt_reg_write(disable_lock, DISABLE_LOCK_3);
+       if ((wdt_reg_read(disable_lock) & 0x3) != 0x3)
+               return -1;
+
+       wdt_reg_write(disable, disable_value);
+       return 0;
+}
+
+static int wdt_set_period(unsigned long msec)
+{
+       unsigned long change_value, count_value;
+       unsigned long prescale_value = 1;
+       unsigned long refclk_khz, maxdiv;
+       int ret;
+
+       refclk_khz = clk_get_rate(TNETV107X_LPSC_WDT_ARM);
+       maxdiv = (MAX_DIV / refclk_khz);
+
+       if ((!msec) || (msec > maxdiv))
+               return -1;
+
+       count_value = refclk_khz * msec;
+       if (count_value > 0xffff) {
+               change_value = count_value / 0xffff + 1;
+               prescale_value = count_value / change_value;
+       } else {
+               change_value = count_value;
+       }
+
+       ret = write_prescale_reg(prescale_value - 1);
+       if (ret)
+               return ret;
+
+       ret = write_change_reg(change_value);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+unsigned long last_wdt = -1;
+
+int wdt_start(unsigned long msecs)
+{
+       int ret;
+       ret = wdt_control(0);
+       if (ret)
+               return ret;
+       ret = wdt_set_period(msecs);
+       if (ret)
+               return ret;
+       ret = wdt_control(1);
+       if (ret)
+               return ret;
+       ret = wdt_kick();
+       last_wdt = msecs;
+       return ret;
+}
+
+int wdt_stop(void)
+{
+       last_wdt = -1;
+       return wdt_control(0);
+}
+
+int wdt_kick(void)
+{
+       wdt_reg_write(kick_lock, KICK_LOCK_1);
+       if ((wdt_reg_read(kick_lock) & 0x3) != 0x1)
+               return -1;
+
+       wdt_reg_write(kick_lock, KICK_LOCK_2);
+       if ((wdt_reg_read(kick_lock) & 0x3) != 0x3)
+               return -1;
+
+       wdt_reg_write(kick, 1);
+       return 0;
+}
+
+void reset_cpu(ulong addr)
+{
+       clk_enable(TNETV107X_LPSC_WDT_ARM);
+       wdt_start(1);
+       wdt_kick();
+}
index 23cab88ded0ace05c93a591d110bc9a87c6b40e6..d6371fce4d044418f12e3377c0c0d5c8bdb2227d 100644 (file)
@@ -32,6 +32,7 @@
 #define CONFIG_ARM1176
 #define CONFIG_TNETV107X
 #define CONFIG_TNETV107X_EVM
+#define CONFIG_TNETV107X_WATCHDOG
 #define CONFIG_ARCH_CPU_INIT
 #define CONFIG_SYS_UBOOT_BASE          CONFIG_SYS_TEXT_BASE
 #define CONFIG_DISABLE_TCM