public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Simon Kagstrom <simon.kagstrom@netinsight.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/2]: arm:kirkwood: Add hardware watchdog support for Marvell Kirkwood boards
Date: Thu, 29 Oct 2009 09:11:05 +0100	[thread overview]
Message-ID: <20091029091105.57945628@marrow.netinsight.se> (raw)
In-Reply-To: <20091029090749.2a2c91d7@marrow.netinsight.se>

Initialize by calling the generic API watchdog_enable() with the number
of seconds for the watchdog to timeout. It's not possible to disable the
watchdog once it's on.

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
ChangeLog:
  v2:
     * Remove watchdog_disable()
     * Add check to see that the maximum timeout supported by the hardware
       is not exceeded

 cpu/arm926ejs/kirkwood/timer.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/cpu/arm926ejs/kirkwood/timer.c b/cpu/arm926ejs/kirkwood/timer.c
index 817ff42..69a5cb7 100644
--- a/cpu/arm926ejs/kirkwood/timer.c
+++ b/cpu/arm926ejs/kirkwood/timer.c
@@ -23,8 +23,10 @@
 
 #include <common.h>
 #include <asm/arch/kirkwood.h>
+#include <watchdog.h>
 
 #define UBOOT_CNTR	0	/* counter to use for uboot timer */
+#define WATCHDOG_TMR	2
 
 /* Timer reload and current value registers */
 struct kwtmr_val {
@@ -166,3 +168,39 @@ int timer_init(void)
 
 	return 0;
 }
+
+#if defined(CONFIG_HW_WATCHDOG)
+static unsigned long watchdog_timeout = 5;
+void hw_watchdog_reset(void)
+{
+	u32 time = CONFIG_SYS_TCLK * watchdog_timeout;
+
+	writel(time, CNTMR_VAL_REG(WATCHDOG_TMR));
+}
+
+#define MAX_TIMEOUT (0xffffffff / CONFIG_SYS_TCLK)
+int watchdog_enable(unsigned int timeout_secs)
+{
+	struct kwcpu_registers *cpureg =
+		(struct kwcpu_registers *)KW_CPU_REG_BASE;
+	u32 rstoutn_mask;
+	u32 cntmrctrl;
+
+	if (timeout_secs > MAX_TIMEOUT)
+		return -1;
+
+	watchdog_timeout = timeout_secs;
+	/* Enable CPU reset if watchdog expires */
+	rstoutn_mask = readl(cpureg->rstoutn_mask);
+	writel(rstoutn_mask |= 2, &cpureg->rstoutn_mask);
+	hw_watchdog_reset();
+
+	/* Enable the watchdog */
+	cntmrctrl = readl(CNTMR_CTRL_REG);
+	cntmrctrl |= CTCR_ARM_TIMER_EN(WATCHDOG_TMR);
+	cntmrctrl |= CTCR_ARM_TIMER_AUTO_EN(WATCHDOG_TMR);
+	writel(cntmrctrl, CNTMR_CTRL_REG);
+
+	return 0;
+}
+#endif
-- 
1.6.0.4

  parent reply	other threads:[~2009-10-29  8:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-28 14:11 [U-Boot] [PATCH 0/2]: Watchdog support from the command line Simon Kagstrom
2009-10-28 14:14 ` [U-Boot] [PATCH 1/2]: common: Add a watchdog CLI command Simon Kagstrom
2009-10-28 14:29   ` Prafulla Wadaskar
2009-10-28 14:49     ` Simon Kagstrom
2009-10-28 15:56       ` Wolfgang Denk
2009-10-28 14:15 ` [U-Boot] [PATCH 2/2]: arm:kirkwood: Add hardware watchdog support for Marvell Kirkwood boards Simon Kagstrom
2009-10-28 15:41   ` Prafulla Wadaskar
2009-10-29  8:07 ` [U-Boot] [PATCH v2 0/2]: Watchdog support from the command line Simon Kagstrom
2009-10-29  8:09   ` [U-Boot] [PATCH v2 1/2]: common: Add a watchdog CLI command Simon Kagstrom
2009-10-29  8:29     ` Prafulla Wadaskar
2009-11-06  9:28     ` Simon Kagstrom
2009-11-06  9:34       ` Prafulla Wadaskar
2009-11-06 11:18       ` Mike Frysinger
2009-10-29  8:11   ` Simon Kagstrom [this message]
2009-10-29  8:32     ` [U-Boot] [PATCH v2 2/2]: arm:kirkwood: Add hardware watchdog support for Marvell Kirkwood boards Prafulla Wadaskar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091029091105.57945628@marrow.netinsight.se \
    --to=simon.kagstrom@netinsight.net \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox