2008-08-29 22:40:24 +00:00
|
|
|
/* riowd.c - driver for hw watchdog inside Super I/O of RIO
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2008-08-29 22:35:59 +00:00
|
|
|
* Copyright (C) 2001, 2008 David S. Miller (davem@davemloft.net)
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-15 23:06:19 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/miscdevice.h>
|
2008-08-29 22:35:59 +00:00
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2009-03-18 09:09:26 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* RIO uses the NatSemi Super I/O power management logical device
|
|
|
|
* as its' watchdog.
|
|
|
|
*
|
|
|
|
* When the watchdog triggers, it asserts a line to the BBC (Boot Bus
|
|
|
|
* Controller) of the machine. The BBC can only be configured to
|
|
|
|
* trigger a power-on reset when the signal is asserted. The BBC
|
|
|
|
* can be configured to ignore the signal entirely as well.
|
|
|
|
*
|
|
|
|
* The only Super I/O device register we care about is at index
|
|
|
|
* 0x05 (WDTO_INDEX) which is the watchdog time-out in minutes (1-255).
|
|
|
|
* If set to zero, this disables the watchdog. When set, the system
|
|
|
|
* must periodically (before watchdog expires) clear (set to zero) and
|
|
|
|
* re-set the watchdog else it will trigger.
|
|
|
|
*
|
|
|
|
* There are two other indexed watchdog registers inside this Super I/O
|
|
|
|
* logical device, but they are unused. The first, at index 0x06 is
|
|
|
|
* the watchdog control and can be used to make the watchdog timer re-set
|
|
|
|
* when the PS/2 mouse or serial lines show activity. The second, at
|
|
|
|
* index 0x07 is merely a sampling of the line from the watchdog to the
|
|
|
|
* BBC.
|
|
|
|
*
|
|
|
|
* The watchdog device generates no interrupts.
|
|
|
|
*/
|
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_DESCRIPTION("Hardware watchdog driver for Sun RIO");
|
|
|
|
MODULE_SUPPORTED_DEVICE("watchdog");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2008-08-29 22:42:31 +00:00
|
|
|
#define DRIVER_NAME "riowd"
|
|
|
|
#define PFX DRIVER_NAME ": "
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
struct riowd {
|
|
|
|
void __iomem *regs;
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct riowd *riowd_device;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define WDTO_INDEX 0x05
|
|
|
|
|
|
|
|
static int riowd_timeout = 1; /* in minutes */
|
|
|
|
module_param(riowd_timeout, int, 0);
|
|
|
|
MODULE_PARM_DESC(riowd_timeout, "Watchdog timeout in minutes");
|
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
static void riowd_writereg(struct riowd *p, u8 val, int index)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
spin_lock_irqsave(&p->lock, flags);
|
|
|
|
writeb(index, p->regs + 0);
|
|
|
|
writeb(val, p->regs + 1);
|
|
|
|
spin_unlock_irqrestore(&p->lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int riowd_open(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
nonseekable_open(inode, filp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int riowd_release(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-21 11:13:11 +00:00
|
|
|
static long riowd_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-12-26 18:55:22 +00:00
|
|
|
static const struct watchdog_info info = {
|
2008-08-29 22:35:59 +00:00
|
|
|
.options = WDIOF_SETTIMEOUT,
|
|
|
|
.firmware_version = 1,
|
2008-08-29 22:42:31 +00:00
|
|
|
.identity = DRIVER_NAME,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
void __user *argp = (void __user *)arg;
|
2008-08-29 22:35:59 +00:00
|
|
|
struct riowd *p = riowd_device;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int options;
|
|
|
|
int new_margin;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WDIOC_GETSUPPORT:
|
|
|
|
if (copy_to_user(argp, &info, sizeof(info)))
|
|
|
|
return -EFAULT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_GETSTATUS:
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
|
|
|
if (put_user(0, (int __user *)argp))
|
|
|
|
return -EFAULT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_KEEPALIVE:
|
2008-08-29 22:35:59 +00:00
|
|
|
riowd_writereg(p, riowd_timeout, WDTO_INDEX);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_SETOPTIONS:
|
|
|
|
if (copy_from_user(&options, argp, sizeof(options)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (options & WDIOS_DISABLECARD)
|
2008-08-29 22:35:59 +00:00
|
|
|
riowd_writereg(p, 0, WDTO_INDEX);
|
2005-04-16 22:20:36 +00:00
|
|
|
else if (options & WDIOS_ENABLECARD)
|
2008-08-29 22:35:59 +00:00
|
|
|
riowd_writereg(p, riowd_timeout, WDTO_INDEX);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_SETTIMEOUT:
|
|
|
|
if (get_user(new_margin, (int __user *)argp))
|
|
|
|
return -EFAULT;
|
|
|
|
if ((new_margin < 60) || (new_margin > (255 * 60)))
|
2008-08-29 22:35:59 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
riowd_timeout = (new_margin + 59) / 60;
|
2008-08-29 22:35:59 +00:00
|
|
|
riowd_writereg(p, riowd_timeout, WDTO_INDEX);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Fall */
|
|
|
|
|
|
|
|
case WDIOC_GETTIMEOUT:
|
|
|
|
return put_user(riowd_timeout * 60, (int __user *)argp);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-18 08:35:09 +00:00
|
|
|
static ssize_t riowd_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-08-29 22:35:59 +00:00
|
|
|
struct riowd *p = riowd_device;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (count) {
|
2008-08-29 22:35:59 +00:00
|
|
|
riowd_writereg(p, riowd_timeout, WDTO_INDEX);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-12 08:55:34 +00:00
|
|
|
static const struct file_operations riowd_fops = {
|
2009-01-21 11:13:11 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.unlocked_ioctl = riowd_ioctl,
|
|
|
|
.open = riowd_open,
|
|
|
|
.write = riowd_write,
|
|
|
|
.release = riowd_release,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
static struct miscdevice riowd_miscdev = {
|
|
|
|
.minor = WATCHDOG_MINOR,
|
|
|
|
.name = "watchdog",
|
|
|
|
.fops = &riowd_fops
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-19 18:21:41 +00:00
|
|
|
static int riowd_probe(struct platform_device *op)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-08-29 22:35:59 +00:00
|
|
|
struct riowd *p;
|
|
|
|
int err = -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
if (riowd_device)
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
err = -ENOMEM;
|
2013-04-30 05:01:59 +00:00
|
|
|
p = devm_kzalloc(&op->dev, sizeof(*p), GFP_KERNEL);
|
2008-08-29 22:35:59 +00:00
|
|
|
if (!p)
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
spin_lock_init(&p->lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-29 22:42:31 +00:00
|
|
|
p->regs = of_ioremap(&op->resource[0], 0, 2, DRIVER_NAME);
|
2008-08-29 22:35:59 +00:00
|
|
|
if (!p->regs) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_err("Cannot map registers\n");
|
2013-04-30 05:01:59 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-11-03 05:16:28 +00:00
|
|
|
/* Make miscdev useable right away */
|
|
|
|
riowd_device = p;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
err = misc_register(&riowd_miscdev);
|
|
|
|
if (err) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_err("Cannot register watchdog misc device\n");
|
2008-08-29 22:35:59 +00:00
|
|
|
goto out_iounmap;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Hardware watchdog [%i minutes], regs at %p\n",
|
|
|
|
riowd_timeout, p->regs);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-05-23 10:44:38 +00:00
|
|
|
platform_set_drvdata(op, p);
|
2009-10-14 08:18:26 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
out_iounmap:
|
2009-11-03 05:16:28 +00:00
|
|
|
riowd_device = NULL;
|
2008-08-29 22:35:59 +00:00
|
|
|
of_iounmap(&op->resource[0], p->regs, 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-29 22:35:59 +00:00
|
|
|
out:
|
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:24 +00:00
|
|
|
static int riowd_remove(struct platform_device *op)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-05-23 10:44:38 +00:00
|
|
|
struct riowd *p = platform_get_drvdata(op);
|
2008-08-29 22:35:59 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
misc_deregister(&riowd_miscdev);
|
2008-08-29 22:35:59 +00:00
|
|
|
of_iounmap(&op->resource[0], p->regs, 2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-31 08:23:17 +00:00
|
|
|
static const struct of_device_id riowd_match[] = {
|
2008-08-29 22:35:59 +00:00
|
|
|
{
|
|
|
|
.name = "pmc",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, riowd_match);
|
|
|
|
|
2011-02-17 09:43:24 +00:00
|
|
|
static struct platform_driver riowd_driver = {
|
2010-04-13 23:13:02 +00:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.of_match_table = riowd_match,
|
|
|
|
},
|
2008-08-29 22:35:59 +00:00
|
|
|
.probe = riowd_probe,
|
2012-11-19 18:21:12 +00:00
|
|
|
.remove = riowd_remove,
|
2008-08-29 22:35:59 +00:00
|
|
|
};
|
|
|
|
|
2011-11-29 05:56:27 +00:00
|
|
|
module_platform_driver(riowd_driver);
|