From: Domenico Andreoli <domenico.andreoli@linux.com>
To: linux-arch@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-mips@lvger.kernel.org,
Russell King <linux@arm.linux.org.uk>,
Arnd Bergmann <arnd@arndb.de>, Olof Johansson <olof@lixom.net>,
Ralf Baechle <ralf@linux-mips.org>,
Wim Van Sebroeck <wim@iguana.be>,
Domenico Andreoli <domenico.andreoli@linux.com>
Subject: [PATCH 11/11] ARM: sp805: use the common machine reset handling
Date: Thu, 31 Oct 2013 07:27:19 +0100 [thread overview]
Message-ID: <20131031063001.088351233@linux.com> (raw)
In-Reply-To: 20131031062708.520968323@linux.com
[-- Attachment #1: sp805-machine-reset.patch --]
[-- Type: text/plain, Size: 4019 bytes --]
From: Domenico Andreoli <domenico.andreoli@linux.com>
Proof of concept: sp805 as provider of reset hooks.
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Olof Johansson <olof@lixom.net>
Cc: Wim Van Sebroeck <wim@iguana.be>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
---
drivers/watchdog/Kconfig | 9 ++++++++
drivers/watchdog/sp805_wdt.c | 48 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
Index: b/drivers/watchdog/Kconfig
===================================================================
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -110,11 +110,20 @@ config WM8350_WATCHDOG
config ARM_SP805_WATCHDOG
tristate "ARM SP805 Watchdog"
depends on ARM && ARM_AMBA
+ select MACHINE_RESET
select WATCHDOG_CORE
help
ARM Primecell SP805 Watchdog timer. This will reboot your system when
the timeout is reached.
+config ARM_SP805_WATCHDOG_RESTART_HOOK
+ bool "ARM SP805 system restart hook"
+ depends on ARM_SP805_WATCHDOG
+ help
+ Register hook to reboot the system based on the SP805 Watchdog.
+
+ This can be overriden with cmdline option restart_hook=0.
+
config AT91RM9200_WATCHDOG
tristate "AT91RM9200 watchdog"
depends on ARCH_AT91RM9200
Index: b/drivers/watchdog/sp805_wdt.c
===================================================================
--- a/drivers/watchdog/sp805_wdt.c
+++ b/drivers/watchdog/sp805_wdt.c
@@ -28,6 +28,8 @@
#include <linux/spinlock.h>
#include <linux/types.h>
#include <linux/watchdog.h>
+#include <linux/machine_reset.h>
+#include <linux/delay.h>
/* default timeout in seconds */
#define DEFAULT_TIMEOUT 60
@@ -77,6 +79,11 @@ module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout,
"Set to 1 to keep watchdog running after device release");
+static bool restart_hook = IS_ENABLED(CONFIG_ARM_SP805_WATCHDOG_RESTART_HOOK);
+module_param(restart_hook, bool, 0);
+MODULE_PARM_DESC(restart_hook,
+ "Set to 1 to install a machine restart handler based on this watchdog");
+
/* This routine finds load value that will reset system in required timout */
static int wdt_setload(struct watchdog_device *wdd, unsigned int timeout)
{
@@ -189,6 +196,33 @@ static int wdt_disable(struct watchdog_d
return 0;
}
+/* trigger watchdog timer */
+static void wdt_atomic_trigger(struct watchdog_device *wdd)
+{
+ struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
+
+ spin_lock(&wdt->lock);
+
+ writel_relaxed(UNLOCK, wdt->base + WDTLOCK);
+ writel_relaxed(0, wdt->base + WDTCONTROL);
+ udelay(20);
+ writel_relaxed(INT_MASK, wdt->base + WDTINTCLR);
+ udelay(20);
+
+ /* Expire after 5 cycles */
+ writel_relaxed(5, wdt->base + WDTLOAD);
+
+ writel_relaxed(INT_ENABLE | RESET_ENABLE, wdt->base + WDTCONTROL);
+ writel_relaxed(LOCK, wdt->base + WDTLOCK);
+
+ /* Flush posted writes. */
+ readl_relaxed(wdt->base + WDTLOCK);
+ spin_unlock(&wdt->lock);
+
+ /* Wait the bite */
+ udelay(400);
+}
+
static const struct watchdog_info wdt_info = {
.options = WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
.identity = MODULE_NAME,
@@ -201,8 +235,15 @@ static const struct watchdog_ops wdt_ops
.ping = wdt_ping,
.set_timeout = wdt_setload,
.get_timeleft = wdt_timeleft,
+/* .atomic_trigger = wdt_atomic_trigger, */
};
+static void sp805_wdt_machine_restart(void *wdd, enum reboot_mode mode,
+ const char *cmd)
+{
+ wdt_atomic_trigger(wdd);
+}
+
static int
sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
{
@@ -247,6 +288,13 @@ sp805_wdt_probe(struct amba_device *adev
watchdog_set_drvdata(&wdt->wdd, wdt);
wdt_setload(&wdt->wdd, DEFAULT_TIMEOUT);
+ if (restart_hook) {
+ struct reset_hook hook;
+ reset_hook_init(&hook);
+ hook.restart = sp805_wdt_machine_restart;
+ set_machine_reset(RESET_RESTART, &hook, &wdt->wdd);
+ }
+
ret = watchdog_register_device(&wdt->wdd);
if (ret) {
dev_err(&adev->dev, "watchdog_register_device() failed: %d\n",
next prev parent reply other threads:[~2013-10-31 6:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-31 6:27 [PATCH 00/11] RFC: Common machine reset handling Domenico Andreoli
2013-10-31 6:27 ` [PATCH 01/11] machine-reset: platform generic handling Domenico Andreoli
2013-10-31 6:27 ` [PATCH 02/11] ARM: use the common machine reset handling Domenico Andreoli
2013-10-31 6:27 ` [PATCH 03/11] ARM64: " Domenico Andreoli
2013-10-31 6:27 ` [PATCH 04/11] MIPS: " Domenico Andreoli
2013-11-01 5:11 ` Vineet Gupta
2013-11-01 5:26 ` Domenico Andreoli
2013-10-31 6:27 ` [PATCH 05/11] ARM: vexpress: consolidate machine reset func Domenico Andreoli
2013-10-31 6:27 ` [PATCH 06/11] ARM: vexpress: use the common machine reset handling Domenico Andreoli
2013-10-31 6:27 ` [PATCH 07/11] ARM: bcm2835: " Domenico Andreoli
2013-10-31 6:27 ` [PATCH 08/11] ARM: u300: " Domenico Andreoli
2013-10-31 14:40 ` Linus Walleij
2013-10-31 15:19 ` Domenico Andreoli
2013-10-31 6:27 ` [PATCH 09/11] ARM: tps65910: " Domenico Andreoli
2013-10-31 6:27 ` [PATCH 10/11] max8907: " Domenico Andreoli
2013-10-31 6:27 ` Domenico Andreoli [this message]
2013-10-31 10:21 ` [PATCH 00/11] RFC: Common " Russell King - ARM Linux
2013-10-31 21:49 ` Stephen Warren
2013-11-01 5:16 ` Domenico Andreoli
2013-11-01 15:58 ` Stephen Warren
2013-11-01 16:12 ` Russell King - ARM Linux
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=20131031063001.088351233@linux.com \
--to=domenico.andreoli@linux.com \
--cc=arnd@arndb.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mips@lvger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=olof@lixom.net \
--cc=ralf@linux-mips.org \
--cc=wim@iguana.be \
/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;
as well as URLs for NNTP newsgroup(s).