2005-09-12 23:56:56 +02:00
|
|
|
/*
|
|
|
|
* Watchdog driver for the mpcore watchdog timer
|
|
|
|
*
|
|
|
|
* (c) Copyright 2004 ARM Limited
|
|
|
|
*
|
|
|
|
* Based on the SoftDog driver:
|
2008-10-27 16:17:56 +01:00
|
|
|
* (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>,
|
2009-03-18 09:35:09 +01:00
|
|
|
* All Rights Reserved.
|
2005-09-12 23:56:56 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
|
|
|
|
* warranty for any of this software. This material is provided
|
|
|
|
* "AS-IS" and at no charge.
|
|
|
|
*
|
|
|
|
* (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
|
|
|
|
*
|
|
|
|
*/
|
2012-02-16 00:06:19 +01:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-09-12 23:56:56 +02:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
2005-10-29 20:07:23 +02:00
|
|
|
#include <linux/platform_device.h>
|
2008-05-19 15:07:15 +02:00
|
|
|
#include <linux/uaccess.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2010-05-12 06:53:26 +02:00
|
|
|
#include <linux/io.h>
|
2005-09-14 10:56:38 +02:00
|
|
|
|
2010-05-12 06:53:26 +02:00
|
|
|
#include <asm/smp_twd.h>
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
struct mpcore_wdt {
|
|
|
|
unsigned long timer_alive;
|
|
|
|
struct device *dev;
|
|
|
|
void __iomem *base;
|
|
|
|
int irq;
|
|
|
|
unsigned int perturb;
|
|
|
|
char expect_close;
|
|
|
|
};
|
|
|
|
|
2012-03-12 05:21:58 +01:00
|
|
|
static struct platform_device *mpcore_wdt_pdev;
|
2010-05-12 06:53:26 +02:00
|
|
|
static DEFINE_SPINLOCK(wdt_lock);
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
#define TIMER_MARGIN 60
|
|
|
|
static int mpcore_margin = TIMER_MARGIN;
|
|
|
|
module_param(mpcore_margin, int, 0);
|
2008-05-19 15:07:15 +02:00
|
|
|
MODULE_PARM_DESC(mpcore_margin,
|
|
|
|
"MPcore timer margin in seconds. (0 < mpcore_margin < 65536, default="
|
|
|
|
__MODULE_STRING(TIMER_MARGIN) ")");
|
2005-09-12 23:56:56 +02:00
|
|
|
|
2012-03-05 16:51:11 +01:00
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
module_param(nowayout, bool, 0);
|
2008-05-19 15:07:15 +02:00
|
|
|
MODULE_PARM_DESC(nowayout,
|
|
|
|
"Watchdog cannot be stopped once started (default="
|
|
|
|
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
#define ONLY_TESTING 0
|
|
|
|
static int mpcore_noboot = ONLY_TESTING;
|
|
|
|
module_param(mpcore_noboot, int, 0);
|
2009-04-14 22:20:07 +02:00
|
|
|
MODULE_PARM_DESC(mpcore_noboot, "MPcore watchdog action, "
|
|
|
|
"set to 1 to ignore reboots, 0 to reboot (default="
|
|
|
|
__MODULE_STRING(ONLY_TESTING) ")");
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the interrupt handler. Note that we only use this
|
|
|
|
* in testing mode, so don't actually do a reboot here.
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 15:55:46 +02:00
|
|
|
static irqreturn_t mpcore_wdt_fire(int irq, void *arg)
|
2005-09-12 23:56:56 +02:00
|
|
|
{
|
|
|
|
struct mpcore_wdt *wdt = arg;
|
|
|
|
|
|
|
|
/* Check it really was our interrupt */
|
|
|
|
if (readl(wdt->base + TWD_WDOG_INTSTAT)) {
|
2008-05-19 15:07:15 +02:00
|
|
|
dev_printk(KERN_CRIT, wdt->dev,
|
|
|
|
"Triggered - Reboot ignored.\n");
|
2005-09-12 23:56:56 +02:00
|
|
|
/* Clear the interrupt on the watchdog */
|
|
|
|
writel(1, wdt->base + TWD_WDOG_INTSTAT);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mpcore_wdt_keepalive - reload the timer
|
|
|
|
*
|
|
|
|
* Note that the spec says a DIFFERENT value must be written to the reload
|
|
|
|
* register each time. The "perturb" variable deals with this by adding 1
|
|
|
|
* to the count every other time the function is called.
|
|
|
|
*/
|
|
|
|
static void mpcore_wdt_keepalive(struct mpcore_wdt *wdt)
|
|
|
|
{
|
2010-05-12 06:53:26 +02:00
|
|
|
unsigned long count;
|
2005-09-12 23:56:56 +02:00
|
|
|
|
2010-05-12 06:53:26 +02:00
|
|
|
spin_lock(&wdt_lock);
|
2005-09-12 23:56:56 +02:00
|
|
|
/* Assume prescale is set to 256 */
|
2010-05-12 06:53:26 +02:00
|
|
|
count = __raw_readl(wdt->base + TWD_WDOG_COUNTER);
|
|
|
|
count = (0xFFFFFFFFU - count) * (HZ / 5);
|
|
|
|
count = (count / 256) * mpcore_margin;
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
/* Reload the counter */
|
|
|
|
writel(count + wdt->perturb, wdt->base + TWD_WDOG_LOAD);
|
|
|
|
wdt->perturb = wdt->perturb ? 0 : 1;
|
2008-05-19 15:07:15 +02:00
|
|
|
spin_unlock(&wdt_lock);
|
2005-09-12 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mpcore_wdt_stop(struct mpcore_wdt *wdt)
|
|
|
|
{
|
2008-05-19 15:07:15 +02:00
|
|
|
spin_lock(&wdt_lock);
|
2005-09-12 23:56:56 +02:00
|
|
|
writel(0x12345678, wdt->base + TWD_WDOG_DISABLE);
|
|
|
|
writel(0x87654321, wdt->base + TWD_WDOG_DISABLE);
|
|
|
|
writel(0x0, wdt->base + TWD_WDOG_CONTROL);
|
2008-05-19 15:07:15 +02:00
|
|
|
spin_unlock(&wdt_lock);
|
2005-09-12 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mpcore_wdt_start(struct mpcore_wdt *wdt)
|
|
|
|
{
|
|
|
|
dev_printk(KERN_INFO, wdt->dev, "enabling watchdog.\n");
|
|
|
|
|
|
|
|
/* This loads the count register but does NOT start the count yet */
|
|
|
|
mpcore_wdt_keepalive(wdt);
|
|
|
|
|
|
|
|
if (mpcore_noboot) {
|
|
|
|
/* Enable watchdog - prescale=256, watchdog mode=0, enable=1 */
|
|
|
|
writel(0x0000FF01, wdt->base + TWD_WDOG_CONTROL);
|
|
|
|
} else {
|
|
|
|
/* Enable watchdog - prescale=256, watchdog mode=1, enable=1 */
|
|
|
|
writel(0x0000FF09, wdt->base + TWD_WDOG_CONTROL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpcore_wdt_set_heartbeat(int t)
|
|
|
|
{
|
|
|
|
if (t < 0x0001 || t > 0xFFFF)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
mpcore_margin = t;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* /dev/watchdog handling
|
|
|
|
*/
|
|
|
|
static int mpcore_wdt_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2012-03-12 05:21:58 +01:00
|
|
|
struct mpcore_wdt *wdt = platform_get_drvdata(mpcore_wdt_pdev);
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
if (test_and_set_bit(0, &wdt->timer_alive))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (nowayout)
|
|
|
|
__module_get(THIS_MODULE);
|
|
|
|
|
|
|
|
file->private_data = wdt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Activate timer
|
|
|
|
*/
|
|
|
|
mpcore_wdt_start(wdt);
|
|
|
|
|
|
|
|
return nonseekable_open(inode, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpcore_wdt_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct mpcore_wdt *wdt = file->private_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shut off the timer.
|
2011-02-23 21:04:38 +01:00
|
|
|
* Lock it in if it's a module and we set nowayout
|
2005-09-12 23:56:56 +02:00
|
|
|
*/
|
2008-05-19 15:07:15 +02:00
|
|
|
if (wdt->expect_close == 42)
|
2005-09-12 23:56:56 +02:00
|
|
|
mpcore_wdt_stop(wdt);
|
2008-05-19 15:07:15 +02:00
|
|
|
else {
|
|
|
|
dev_printk(KERN_CRIT, wdt->dev,
|
|
|
|
"unexpected close, not stopping watchdog!\n");
|
2005-09-12 23:56:56 +02:00
|
|
|
mpcore_wdt_keepalive(wdt);
|
|
|
|
}
|
|
|
|
clear_bit(0, &wdt->timer_alive);
|
|
|
|
wdt->expect_close = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-19 15:07:15 +02:00
|
|
|
static ssize_t mpcore_wdt_write(struct file *file, const char *data,
|
|
|
|
size_t len, loff_t *ppos)
|
2005-09-12 23:56:56 +02:00
|
|
|
{
|
|
|
|
struct mpcore_wdt *wdt = file->private_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Refresh the timer.
|
|
|
|
*/
|
|
|
|
if (len) {
|
|
|
|
if (!nowayout) {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/* In case it was set long ago */
|
|
|
|
wdt->expect_close = 0;
|
|
|
|
|
|
|
|
for (i = 0; i != len; i++) {
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (get_user(c, data + i))
|
|
|
|
return -EFAULT;
|
|
|
|
if (c == 'V')
|
|
|
|
wdt->expect_close = 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mpcore_wdt_keepalive(wdt);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2009-12-26 19:55:22 +01:00
|
|
|
static const struct watchdog_info ident = {
|
2005-09-12 23:56:56 +02:00
|
|
|
.options = WDIOF_SETTIMEOUT |
|
|
|
|
WDIOF_KEEPALIVEPING |
|
|
|
|
WDIOF_MAGICCLOSE,
|
|
|
|
.identity = "MPcore Watchdog",
|
|
|
|
};
|
|
|
|
|
2008-05-19 15:07:15 +02:00
|
|
|
static long mpcore_wdt_ioctl(struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
2005-09-12 23:56:56 +02:00
|
|
|
{
|
|
|
|
struct mpcore_wdt *wdt = file->private_data;
|
|
|
|
int ret;
|
|
|
|
union {
|
|
|
|
struct watchdog_info ident;
|
|
|
|
int i;
|
|
|
|
} uarg;
|
|
|
|
|
|
|
|
if (_IOC_DIR(cmd) && _IOC_SIZE(cmd) > sizeof(uarg))
|
2006-09-09 17:34:31 +02:00
|
|
|
return -ENOTTY;
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
if (_IOC_DIR(cmd) & _IOC_WRITE) {
|
|
|
|
ret = copy_from_user(&uarg, (void __user *)arg, _IOC_SIZE(cmd));
|
|
|
|
if (ret)
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WDIOC_GETSUPPORT:
|
|
|
|
uarg.ident = ident;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
2008-07-18 13:41:17 +02:00
|
|
|
case WDIOC_GETSTATUS:
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
|
|
|
uarg.i = 0;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
2005-09-12 23:56:56 +02:00
|
|
|
case WDIOC_SETOPTIONS:
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (uarg.i & WDIOS_DISABLECARD) {
|
|
|
|
mpcore_wdt_stop(wdt);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
if (uarg.i & WDIOS_ENABLECARD) {
|
|
|
|
mpcore_wdt_start(wdt);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_KEEPALIVE:
|
|
|
|
mpcore_wdt_keepalive(wdt);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_SETTIMEOUT:
|
|
|
|
ret = mpcore_wdt_set_heartbeat(uarg.i);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
mpcore_wdt_keepalive(wdt);
|
|
|
|
/* Fall */
|
|
|
|
case WDIOC_GETTIMEOUT:
|
|
|
|
uarg.i = mpcore_margin;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-09-09 17:34:31 +02:00
|
|
|
return -ENOTTY;
|
2005-09-12 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0 && _IOC_DIR(cmd) & _IOC_READ) {
|
|
|
|
ret = copy_to_user((void __user *)arg, &uarg, _IOC_SIZE(cmd));
|
|
|
|
if (ret)
|
|
|
|
ret = -EFAULT;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* System shutdown handler. Turn off the watchdog if we're
|
|
|
|
* restarting or halting the system.
|
|
|
|
*/
|
2012-03-12 05:21:58 +01:00
|
|
|
static void mpcore_wdt_shutdown(struct platform_device *pdev)
|
2005-09-12 23:56:56 +02:00
|
|
|
{
|
2012-03-12 05:21:58 +01:00
|
|
|
struct mpcore_wdt *wdt = platform_get_drvdata(pdev);
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
if (system_state == SYSTEM_RESTART || system_state == SYSTEM_HALT)
|
|
|
|
mpcore_wdt_stop(wdt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel Interfaces
|
|
|
|
*/
|
2006-07-03 09:24:21 +02:00
|
|
|
static const struct file_operations mpcore_wdt_fops = {
|
2005-09-12 23:56:56 +02:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.write = mpcore_wdt_write,
|
2008-05-19 15:07:15 +02:00
|
|
|
.unlocked_ioctl = mpcore_wdt_ioctl,
|
2005-09-12 23:56:56 +02:00
|
|
|
.open = mpcore_wdt_open,
|
|
|
|
.release = mpcore_wdt_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice mpcore_wdt_miscdev = {
|
|
|
|
.minor = WATCHDOG_MINOR,
|
|
|
|
.name = "watchdog",
|
|
|
|
.fops = &mpcore_wdt_fops,
|
|
|
|
};
|
|
|
|
|
2012-03-12 05:21:58 +01:00
|
|
|
static int __devinit mpcore_wdt_probe(struct platform_device *pdev)
|
2005-09-12 23:56:56 +02:00
|
|
|
{
|
|
|
|
struct mpcore_wdt *wdt;
|
|
|
|
struct resource *res;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* We only accept one device, and it must have an id of -1 */
|
2012-03-12 05:21:58 +01:00
|
|
|
if (pdev->id != -1)
|
2005-09-12 23:56:56 +02:00
|
|
|
return -ENODEV;
|
|
|
|
|
2012-03-12 05:21:58 +01:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2012-03-12 05:21:59 +01:00
|
|
|
if (!res)
|
|
|
|
return -ENODEV;
|
2005-09-12 23:56:56 +02:00
|
|
|
|
2012-03-12 05:21:59 +01:00
|
|
|
wdt = devm_kzalloc(&pdev->dev, sizeof(struct mpcore_wdt), GFP_KERNEL);
|
|
|
|
if (!wdt)
|
|
|
|
return -ENOMEM;
|
2005-09-12 23:56:56 +02:00
|
|
|
|
2012-03-12 05:21:58 +01:00
|
|
|
wdt->dev = &pdev->dev;
|
|
|
|
wdt->irq = platform_get_irq(pdev, 0);
|
2012-03-12 05:22:00 +01:00
|
|
|
if (wdt->irq >= 0) {
|
|
|
|
ret = devm_request_irq(wdt->dev, wdt->irq, mpcore_wdt_fire, 0,
|
|
|
|
"mpcore_wdt", wdt);
|
|
|
|
if (ret) {
|
|
|
|
dev_printk(KERN_ERR, wdt->dev,
|
|
|
|
"cannot register IRQ%d for watchdog\n",
|
|
|
|
wdt->irq);
|
|
|
|
return ret;
|
|
|
|
}
|
2005-09-12 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 05:21:59 +01:00
|
|
|
wdt->base = devm_ioremap(wdt->dev, res->start, resource_size(res));
|
|
|
|
if (!wdt->base)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-03-12 05:21:58 +01:00
|
|
|
mpcore_wdt_miscdev.parent = &pdev->dev;
|
2005-09-12 23:56:56 +02:00
|
|
|
ret = misc_register(&mpcore_wdt_miscdev);
|
|
|
|
if (ret) {
|
2010-05-12 06:53:26 +02:00
|
|
|
dev_printk(KERN_ERR, wdt->dev,
|
2008-05-19 15:07:15 +02:00
|
|
|
"cannot register miscdev on minor=%d (err=%d)\n",
|
|
|
|
WATCHDOG_MINOR, ret);
|
2012-03-12 05:21:59 +01:00
|
|
|
return ret;
|
2005-09-12 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mpcore_wdt_stop(wdt);
|
2012-03-12 05:21:58 +01:00
|
|
|
platform_set_drvdata(pdev, wdt);
|
|
|
|
mpcore_wdt_pdev = pdev;
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-12 05:21:58 +01:00
|
|
|
static int __devexit mpcore_wdt_remove(struct platform_device *pdev)
|
2005-09-12 23:56:56 +02:00
|
|
|
{
|
2012-03-12 05:21:58 +01:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
misc_deregister(&mpcore_wdt_miscdev);
|
|
|
|
|
2012-03-12 05:21:58 +01:00
|
|
|
mpcore_wdt_pdev = NULL;
|
2005-09-12 23:56:56 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-15 22:18:32 +02:00
|
|
|
#ifdef CONFIG_PM
|
2012-03-12 05:21:58 +01:00
|
|
|
static int mpcore_wdt_suspend(struct platform_device *pdev, pm_message_t msg)
|
2011-06-15 22:18:32 +02:00
|
|
|
{
|
2012-03-12 05:21:58 +01:00
|
|
|
struct mpcore_wdt *wdt = platform_get_drvdata(pdev);
|
2011-06-15 22:18:32 +02:00
|
|
|
mpcore_wdt_stop(wdt); /* Turn the WDT off */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-12 05:21:58 +01:00
|
|
|
static int mpcore_wdt_resume(struct platform_device *pdev)
|
2011-06-15 22:18:32 +02:00
|
|
|
{
|
2012-03-12 05:21:58 +01:00
|
|
|
struct mpcore_wdt *wdt = platform_get_drvdata(pdev);
|
2011-06-15 22:18:32 +02:00
|
|
|
/* re-activate timer */
|
|
|
|
if (test_bit(0, &wdt->timer_alive))
|
|
|
|
mpcore_wdt_start(wdt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define mpcore_wdt_suspend NULL
|
|
|
|
#define mpcore_wdt_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2008-04-11 06:29:23 +02:00
|
|
|
/* work with hotplug and coldplug */
|
|
|
|
MODULE_ALIAS("platform:mpcore_wdt");
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
static struct platform_driver mpcore_wdt_driver = {
|
2005-09-12 23:56:56 +02:00
|
|
|
.probe = mpcore_wdt_probe,
|
|
|
|
.remove = __devexit_p(mpcore_wdt_remove),
|
2011-06-15 22:18:32 +02:00
|
|
|
.suspend = mpcore_wdt_suspend,
|
|
|
|
.resume = mpcore_wdt_resume,
|
2005-09-12 23:56:56 +02:00
|
|
|
.shutdown = mpcore_wdt_shutdown,
|
2005-11-09 23:32:44 +01:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "mpcore_wdt",
|
|
|
|
},
|
2005-09-12 23:56:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mpcore_wdt_init(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check that the margin value is within it's range;
|
|
|
|
* if not reset to the default
|
|
|
|
*/
|
|
|
|
if (mpcore_wdt_set_heartbeat(mpcore_margin)) {
|
|
|
|
mpcore_wdt_set_heartbeat(TIMER_MARGIN);
|
2012-02-16 00:06:19 +01:00
|
|
|
pr_info("mpcore_margin value must be 0 < mpcore_margin < 65536, using %d\n",
|
2005-09-12 23:56:56 +02:00
|
|
|
TIMER_MARGIN);
|
|
|
|
}
|
|
|
|
|
2012-02-16 00:06:19 +01:00
|
|
|
pr_info("MPcore Watchdog Timer: 0.1. mpcore_noboot=%d mpcore_margin=%d sec (nowayout= %d)\n",
|
|
|
|
mpcore_noboot, mpcore_margin, nowayout);
|
2005-09-12 23:56:56 +02:00
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
return platform_driver_register(&mpcore_wdt_driver);
|
2005-09-12 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mpcore_wdt_exit(void)
|
|
|
|
{
|
2005-11-09 23:32:44 +01:00
|
|
|
platform_driver_unregister(&mpcore_wdt_driver);
|
2005-09-12 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mpcore_wdt_init);
|
|
|
|
module_exit(mpcore_wdt_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("ARM Limited");
|
|
|
|
MODULE_DESCRIPTION("MPcore Watchdog Device Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
|