2019-06-21 00:28:46 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-08-10 03:38:00 +08:00
|
|
|
* Eurotech CPU-1220/1410/1420 on board WDT driver
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* (c) Copyright 2001 Ascensit <support@ascensit.com>
|
|
|
|
* (c) Copyright 2001 Rodolfo Giometti <giometti@ascensit.com>
|
|
|
|
* (c) Copyright 2002 Rob Radez <rob@osinvestor.com>
|
|
|
|
*
|
|
|
|
* Based on wdt.c.
|
|
|
|
* Original copyright messages:
|
|
|
|
*
|
2009-03-18 16:35:09 +08:00
|
|
|
* (c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>,
|
2008-10-27 23:17:56 +08:00
|
|
|
* All Rights Reserved.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2009-03-18 16:35:09 +08:00
|
|
|
* 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.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2009-03-18 16:35:09 +08:00
|
|
|
* (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>*
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Changelog:
|
2007-08-10 03:38:00 +08:00
|
|
|
*
|
|
|
|
* 2001 - Rodolfo Giometti
|
|
|
|
* Initial release
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* 2002/04/25 - Rob Radez
|
|
|
|
* clean up #includes
|
|
|
|
* clean up locking
|
|
|
|
* make __setup param unique
|
|
|
|
* proper options in watchdog_info
|
|
|
|
* add WDIOC_GETSTATUS and WDIOC_SETOPTIONS ioctls
|
|
|
|
* add expect_close support
|
|
|
|
*
|
|
|
|
* 2002.05.30 - Joel Becker <joel.becker@oracle.com>
|
2009-03-18 16:35:09 +08:00
|
|
|
* Added Matt Domsch's nowayout module option.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2007-08-10 03:38:00 +08:00
|
|
|
/*
|
|
|
|
* The eurotech CPU-1220/1410/1420's watchdog is a part
|
|
|
|
* of the on-board SUPER I/O device SMSC FDC 37B782.
|
|
|
|
*/
|
|
|
|
|
2012-02-16 07:06:19 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#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/ioport.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
#include <linux/init.h>
|
2008-05-19 21:05:41 +08:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
static unsigned long eurwdt_is_open;
|
|
|
|
static int eurwdt_timeout;
|
|
|
|
static char eur_expect_close;
|
2011-11-29 13:54:01 +08:00
|
|
|
static DEFINE_SPINLOCK(eurwdt_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* You must set these - there is no sane way to probe for this board.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int io = 0x3f0;
|
|
|
|
static int irq = 10;
|
|
|
|
static char *ev = "int";
|
|
|
|
|
|
|
|
#define WDT_TIMEOUT 60 /* 1 minute */
|
|
|
|
|
2012-03-05 23:51:11 +08:00
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
module_param(nowayout, bool, 0);
|
2008-05-19 21:05:41 +08:00
|
|
|
MODULE_PARM_DESC(nowayout,
|
|
|
|
"Watchdog cannot be stopped once started (default="
|
|
|
|
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some symbolic names
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define WDT_CTRL_REG 0x30
|
|
|
|
#define WDT_OUTPIN_CFG 0xe2
|
|
|
|
#define WDT_EVENT_INT 0x00
|
|
|
|
#define WDT_EVENT_REBOOT 0x08
|
|
|
|
#define WDT_UNIT_SEL 0xf1
|
|
|
|
#define WDT_UNIT_SECS 0x80
|
|
|
|
#define WDT_TIMEOUT_VAL 0xf2
|
|
|
|
#define WDT_TIMER_CFG 0xf3
|
|
|
|
|
|
|
|
|
2017-04-04 23:54:29 +08:00
|
|
|
module_param_hw(io, int, ioport, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_PARM_DESC(io, "Eurotech WDT io port (default=0x3f0)");
|
2017-04-04 23:54:29 +08:00
|
|
|
module_param_hw(irq, int, irq, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_PARM_DESC(irq, "Eurotech WDT irq (default=10)");
|
|
|
|
module_param(ev, charp, 0);
|
|
|
|
MODULE_PARM_DESC(ev, "Eurotech WDT event type (default is `int')");
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Programming support
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void eurwdt_write_reg(u8 index, u8 data)
|
|
|
|
{
|
|
|
|
outb(index, io);
|
|
|
|
outb(data, io+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void eurwdt_lock_chip(void)
|
|
|
|
{
|
|
|
|
outb(0xaa, io);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void eurwdt_unlock_chip(void)
|
|
|
|
{
|
|
|
|
outb(0x55, io);
|
|
|
|
eurwdt_write_reg(0x07, 0x08); /* set the logical device */
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void eurwdt_set_timeout(int timeout)
|
|
|
|
{
|
|
|
|
eurwdt_write_reg(WDT_TIMEOUT_VAL, (u8) timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void eurwdt_disable_timer(void)
|
|
|
|
{
|
|
|
|
eurwdt_set_timeout(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void eurwdt_activate_timer(void)
|
|
|
|
{
|
|
|
|
eurwdt_disable_timer();
|
|
|
|
eurwdt_write_reg(WDT_CTRL_REG, 0x01); /* activate the WDT */
|
2008-05-19 21:05:41 +08:00
|
|
|
eurwdt_write_reg(WDT_OUTPIN_CFG,
|
|
|
|
!strcmp("int", ev) ? WDT_EVENT_INT : WDT_EVENT_REBOOT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Setting interrupt line */
|
|
|
|
if (irq == 2 || irq > 15 || irq < 0) {
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_err("invalid irq number\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
irq = 0; /* if invalid we disable interrupt */
|
|
|
|
}
|
|
|
|
if (irq == 0)
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_info("interrupt disabled\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-18 16:35:09 +08:00
|
|
|
eurwdt_write_reg(WDT_TIMER_CFG, irq << 4);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
eurwdt_write_reg(WDT_UNIT_SEL, WDT_UNIT_SECS); /* we use seconds */
|
|
|
|
eurwdt_set_timeout(0); /* the default timeout */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel methods.
|
|
|
|
*/
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static irqreturn_t eurwdt_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_crit("timeout WDT timeout\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef ONLY_TESTING
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_crit("Would Reboot\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_crit("Initiating system reboot\n");
|
2005-07-27 12:41:37 +08:00
|
|
|
emergency_restart();
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eurwdt_ping:
|
|
|
|
*
|
|
|
|
* Reload counter one with the watchdog timeout.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void eurwdt_ping(void)
|
|
|
|
{
|
|
|
|
/* Write the watchdog default value */
|
|
|
|
eurwdt_set_timeout(eurwdt_timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eurwdt_write:
|
|
|
|
* @file: file handle to the watchdog
|
|
|
|
* @buf: buffer to write (unused as data does not matter here
|
|
|
|
* @count: count of bytes
|
|
|
|
* @ppos: pointer to the position to write. No seeks allowed
|
|
|
|
*
|
|
|
|
* A write to a watchdog device is defined as a keepalive signal. Any
|
|
|
|
* write of data will do, as we we don't define content meaning.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static ssize_t eurwdt_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
2011-02-24 04:04:38 +08:00
|
|
|
if (count) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!nowayout) {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
eur_expect_close = 0;
|
|
|
|
|
|
|
|
for (i = 0; i != count; i++) {
|
|
|
|
char c;
|
2008-08-07 04:19:41 +08:00
|
|
|
if (get_user(c, buf + i))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
if (c == 'V')
|
|
|
|
eur_expect_close = 42;
|
|
|
|
}
|
|
|
|
}
|
2008-05-19 21:05:41 +08:00
|
|
|
spin_lock(&eurwdt_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
eurwdt_ping(); /* the default timeout */
|
2008-05-19 21:05:41 +08:00
|
|
|
spin_unlock(&eurwdt_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eurwdt_ioctl:
|
|
|
|
* @file: file handle to the device
|
|
|
|
* @cmd: watchdog command
|
|
|
|
* @arg: argument pointer
|
|
|
|
*
|
|
|
|
* The watchdog API defines a common set of functions for all watchdogs
|
|
|
|
* according to their available features.
|
|
|
|
*/
|
|
|
|
|
2008-05-19 21:05:41 +08:00
|
|
|
static long eurwdt_ioctl(struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
int __user *p = argp;
|
2009-12-27 02:55:22 +08:00
|
|
|
static const struct watchdog_info ident = {
|
2008-05-19 21:05:41 +08:00
|
|
|
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
|
|
|
|
| WDIOF_MAGICCLOSE,
|
2005-04-17 06:20:36 +08:00
|
|
|
.firmware_version = 1,
|
|
|
|
.identity = "WDT Eurotech CPU-1220/1410",
|
|
|
|
};
|
|
|
|
|
|
|
|
int time;
|
|
|
|
int options, retval = -EINVAL;
|
|
|
|
|
2008-05-19 21:05:41 +08:00
|
|
|
switch (cmd) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case WDIOC_GETSUPPORT:
|
|
|
|
return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
|
|
|
|
|
|
|
|
case WDIOC_GETSTATUS:
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
|
|
|
return put_user(0, p);
|
|
|
|
|
2008-07-18 19:41:17 +08:00
|
|
|
case WDIOC_SETOPTIONS:
|
|
|
|
if (get_user(options, p))
|
|
|
|
return -EFAULT;
|
|
|
|
spin_lock(&eurwdt_lock);
|
|
|
|
if (options & WDIOS_DISABLECARD) {
|
|
|
|
eurwdt_disable_timer();
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
if (options & WDIOS_ENABLECARD) {
|
|
|
|
eurwdt_activate_timer();
|
|
|
|
eurwdt_ping();
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
spin_unlock(&eurwdt_lock);
|
|
|
|
return retval;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case WDIOC_KEEPALIVE:
|
2008-05-19 21:05:41 +08:00
|
|
|
spin_lock(&eurwdt_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
eurwdt_ping();
|
2008-05-19 21:05:41 +08:00
|
|
|
spin_unlock(&eurwdt_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WDIOC_SETTIMEOUT:
|
|
|
|
if (copy_from_user(&time, p, sizeof(int)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (time < 0 || time > 255)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-05-19 21:05:41 +08:00
|
|
|
spin_lock(&eurwdt_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
eurwdt_timeout = time;
|
|
|
|
eurwdt_set_timeout(time);
|
2008-05-19 21:05:41 +08:00
|
|
|
spin_unlock(&eurwdt_lock);
|
2020-07-08 01:11:21 +08:00
|
|
|
fallthrough;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
case WDIOC_GETTIMEOUT:
|
|
|
|
return put_user(eurwdt_timeout, p);
|
|
|
|
|
2008-07-18 19:41:17 +08:00
|
|
|
default:
|
|
|
|
return -ENOTTY;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eurwdt_open:
|
|
|
|
* @inode: inode of device
|
|
|
|
* @file: file handle to device
|
|
|
|
*
|
|
|
|
* The misc device has been opened. The watchdog device is single
|
|
|
|
* open and on opening we load the counter.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int eurwdt_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
if (test_and_set_bit(0, &eurwdt_is_open))
|
|
|
|
return -EBUSY;
|
|
|
|
eurwdt_timeout = WDT_TIMEOUT; /* initial timeout */
|
|
|
|
/* Activate the WDT */
|
|
|
|
eurwdt_activate_timer();
|
2019-03-27 04:51:19 +08:00
|
|
|
return stream_open(inode, file);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eurwdt_release:
|
|
|
|
* @inode: inode to board
|
|
|
|
* @file: file handle to board
|
|
|
|
*
|
|
|
|
* The watchdog has a configurable API. There is a religious dispute
|
|
|
|
* between people who want their watchdog to be able to shut down and
|
|
|
|
* those who want to be sure if the watchdog manager dies the machine
|
|
|
|
* reboots. In the former case we disable the counters, in the latter
|
|
|
|
* case you have to open it again very soon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int eurwdt_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
2008-05-19 21:05:41 +08:00
|
|
|
if (eur_expect_close == 42)
|
2005-04-17 06:20:36 +08:00
|
|
|
eurwdt_disable_timer();
|
2008-05-19 21:05:41 +08:00
|
|
|
else {
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_crit("Unexpected close, not stopping watchdog!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
eurwdt_ping();
|
|
|
|
}
|
|
|
|
clear_bit(0, &eurwdt_is_open);
|
|
|
|
eur_expect_close = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eurwdt_notify_sys:
|
|
|
|
* @this: our notifier block
|
|
|
|
* @code: the event being reported
|
|
|
|
* @unused: unused
|
|
|
|
*
|
|
|
|
* Our notifier is called on system shutdowns. We want to turn the card
|
|
|
|
* off at reboot otherwise the machine will reboot again during memory
|
|
|
|
* test or worse yet during the following fsck. This would suck, in fact
|
|
|
|
* trust me - if it happens it does suck.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int eurwdt_notify_sys(struct notifier_block *this, unsigned long code,
|
|
|
|
void *unused)
|
|
|
|
{
|
2008-08-07 04:19:41 +08:00
|
|
|
if (code == SYS_DOWN || code == SYS_HALT)
|
|
|
|
eurwdt_disable_timer(); /* Turn the card off */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel Interfaces
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2006-07-03 15:24:21 +08:00
|
|
|
static const struct file_operations eurwdt_fops = {
|
2008-05-19 21:05:41 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.write = eurwdt_write,
|
|
|
|
.unlocked_ioctl = eurwdt_ioctl,
|
2019-06-03 20:23:09 +08:00
|
|
|
.compat_ioctl = compat_ptr_ioctl,
|
2008-05-19 21:05:41 +08:00
|
|
|
.open = eurwdt_open,
|
2005-04-17 06:20:36 +08:00
|
|
|
.release = eurwdt_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice eurwdt_miscdev = {
|
|
|
|
.minor = WATCHDOG_MINOR,
|
|
|
|
.name = "watchdog",
|
|
|
|
.fops = &eurwdt_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The WDT card needs to learn about soft shutdowns in order to
|
|
|
|
* turn the timebomb registers off.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct notifier_block eurwdt_notifier = {
|
|
|
|
.notifier_call = eurwdt_notify_sys,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-03-22 14:53:37 +08:00
|
|
|
* eurwdt_exit:
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Unload the watchdog. You cannot do this with any file handles open.
|
|
|
|
* If your watchdog is set to continue ticking on close and you unload
|
|
|
|
* it, well it keeps ticking. We won't get the interrupt but the board
|
|
|
|
* will not touch PC memory so all is fine. You just have to load a new
|
|
|
|
* module in 60 seconds or reboot.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void __exit eurwdt_exit(void)
|
|
|
|
{
|
|
|
|
eurwdt_lock_chip();
|
|
|
|
|
|
|
|
misc_deregister(&eurwdt_miscdev);
|
|
|
|
|
|
|
|
unregister_reboot_notifier(&eurwdt_notifier);
|
|
|
|
release_region(io, 2);
|
|
|
|
free_irq(irq, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eurwdt_init:
|
|
|
|
*
|
|
|
|
* Set up the WDT watchdog board. After grabbing the resources
|
|
|
|
* we require we need also to unlock the device.
|
|
|
|
* The open() function will actually kick the board off.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int __init eurwdt_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-09-07 16:10:55 +08:00
|
|
|
ret = request_irq(irq, eurwdt_interrupt, 0, "eurwdt", NULL);
|
2008-05-19 21:05:41 +08:00
|
|
|
if (ret) {
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_err("IRQ %d is not free\n", irq);
|
2007-03-24 20:58:12 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!request_region(io, 2, "eurwdt")) {
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_err("IO %X is not free\n", io);
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -EBUSY;
|
|
|
|
goto outirq;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = register_reboot_notifier(&eurwdt_notifier);
|
|
|
|
if (ret) {
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_err("can't register reboot notifier (err=%d)\n", ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto outreg;
|
|
|
|
}
|
|
|
|
|
2007-03-24 20:58:12 +08:00
|
|
|
ret = misc_register(&eurwdt_miscdev);
|
|
|
|
if (ret) {
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_err("can't misc_register on minor=%d\n", WATCHDOG_MINOR);
|
2007-03-24 20:58:12 +08:00
|
|
|
goto outreboot;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
eurwdt_unlock_chip();
|
|
|
|
|
|
|
|
ret = 0;
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_info("Eurotech WDT driver 0.01 at %X (Interrupt %d) - timeout event: %s\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
io, irq, (!strcmp("int", ev) ? "int" : "reboot"));
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
|
2007-03-24 20:58:12 +08:00
|
|
|
outreboot:
|
|
|
|
unregister_reboot_notifier(&eurwdt_notifier);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
outreg:
|
|
|
|
release_region(io, 2);
|
|
|
|
|
|
|
|
outirq:
|
|
|
|
free_irq(irq, NULL);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(eurwdt_init);
|
|
|
|
module_exit(eurwdt_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Rodolfo Giometti");
|
|
|
|
MODULE_DESCRIPTION("Driver for Eurotech CPU-1220/1410 on board watchdog");
|
|
|
|
MODULE_LICENSE("GPL");
|