Release 4.7 drivers/watchdog/scx200_wdt.c
/* drivers/char/watchdog/scx200_wdt.c
National Semiconductor SCx200 Watchdog support
Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
Some code taken from:
National Semiconductor PC87307/PC97307 (ala SC1200) WDT driver
(c) Copyright 2002 Zwane Mwaikambo <zwane@commfireservices.com>
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.
The author(s) of this software shall not be held liable for damages
of any nature resulting due to the use of this software. This
software is provided AS-IS with no warranties. */
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/watchdog.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
#include <linux/fs.h>
#include <linux/ioport.h>
#include <linux/scx200.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#define DEBUG
MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
MODULE_DESCRIPTION("NatSemi SCx200 Watchdog Driver");
MODULE_LICENSE("GPL");
static int margin = 60;
/* in seconds */
module_param(margin, int, 0);
MODULE_PARM_DESC(margin, "Watchdog margin in seconds");
static bool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
static u16 wdto_restart;
static char expect_close;
static unsigned long open_lock;
static DEFINE_SPINLOCK(scx_lock);
/* Bits of the WDCNFG register */
#define W_ENABLE 0x00fa
/* Enable watchdog */
#define W_DISABLE 0x0000
/* Disable watchdog */
/* The scaling factor for the timer, this depends on the value of W_ENABLE */
#define W_SCALE (32768/1024)
static void scx200_wdt_ping(void)
{
spin_lock(&scx_lock);
outw(wdto_restart, scx200_cb_base + SCx200_WDT_WDTO);
spin_unlock(&scx_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 16 | 55.17% | 1 | 33.33% |
alan cox | alan cox | 12 | 41.38% | 1 | 33.33% |
henrik brix andersen | henrik brix andersen | 1 | 3.45% | 1 | 33.33% |
| Total | 29 | 100.00% | 3 | 100.00% |
static void scx200_wdt_update_margin(void)
{
pr_info("timer margin %d seconds\n", margin);
wdto_restart = margin * W_SCALE;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 17 | 80.95% | 1 | 50.00% |
joe perches | joe perches | 4 | 19.05% | 1 | 50.00% |
| Total | 21 | 100.00% | 2 | 100.00% |
static void scx200_wdt_enable(void)
{
pr_debug("enabling watchdog timer, wdto_restart = %d\n", wdto_restart);
spin_lock(&scx_lock);
outw(0, scx200_cb_base + SCx200_WDT_WDTO);
outb(SCx200_WDT_WDSTS_WDOVF, scx200_cb_base + SCx200_WDT_WDSTS);
outw(W_ENABLE, scx200_cb_base + SCx200_WDT_WDCNFG);
spin_unlock(&scx_lock);
scx200_wdt_ping();
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 38 | 66.67% | 1 | 25.00% |
alan cox | alan cox | 12 | 21.05% | 1 | 25.00% |
joe perches | joe perches | 4 | 7.02% | 1 | 25.00% |
henrik brix andersen | henrik brix andersen | 3 | 5.26% | 1 | 25.00% |
| Total | 57 | 100.00% | 4 | 100.00% |
static void scx200_wdt_disable(void)
{
pr_debug("disabling watchdog timer\n");
spin_lock(&scx_lock);
outw(0, scx200_cb_base + SCx200_WDT_WDTO);
outb(SCx200_WDT_WDSTS_WDOVF, scx200_cb_base + SCx200_WDT_WDSTS);
outw(W_DISABLE, scx200_cb_base + SCx200_WDT_WDCNFG);
spin_unlock(&scx_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 34 | 65.38% | 1 | 25.00% |
alan cox | alan cox | 12 | 23.08% | 1 | 25.00% |
joe perches | joe perches | 3 | 5.77% | 1 | 25.00% |
henrik brix andersen | henrik brix andersen | 3 | 5.77% | 1 | 25.00% |
| Total | 52 | 100.00% | 4 | 100.00% |
static int scx200_wdt_open(struct inode *inode, struct file *file)
{
/* only allow one at a time */
if (test_and_set_bit(0, &open_lock))
return -EBUSY;
scx200_wdt_enable();
return nonseekable_open(inode, file);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 32 | 76.19% | 1 | 33.33% |
linus torvalds | linus torvalds | 6 | 14.29% | 1 | 33.33% |
alan cox | alan cox | 4 | 9.52% | 1 | 33.33% |
| Total | 42 | 100.00% | 3 | 100.00% |
static int scx200_wdt_release(struct inode *inode, struct file *file)
{
if (expect_close != 42)
pr_warn("watchdog device closed unexpectedly, will not disable the watchdog timer\n");
else if (!nowayout)
scx200_wdt_disable();
expect_close = 0;
clear_bit(0, &open_lock);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 38 | 74.51% | 1 | 25.00% |
wim van sebroeck | wim van sebroeck | 6 | 11.76% | 1 | 25.00% |
alan cox | alan cox | 4 | 7.84% | 1 | 25.00% |
joe perches | joe perches | 3 | 5.88% | 1 | 25.00% |
| Total | 51 | 100.00% | 4 | 100.00% |
static int scx200_wdt_notify_sys(struct notifier_block *this,
unsigned long code, void *unused)
{
if (code == SYS_HALT || code == SYS_POWER_OFF)
if (!nowayout)
scx200_wdt_disable();
return NOTIFY_DONE;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 40 | 100.00% | 1 | 100.00% |
| Total | 40 | 100.00% | 1 | 100.00% |
static struct notifier_block scx200_wdt_notifier = {
.notifier_call = scx200_wdt_notify_sys,
};
static ssize_t scx200_wdt_write(struct file *file, const char __user *data,
size_t len, loff_t *ppos)
{
/* check for a magic close character */
if (len) {
size_t i;
scx200_wdt_ping();
expect_close = 0;
for (i = 0; i < len; ++i) {
char c;
if (get_user(c, data + i))
return -EFAULT;
if (c == 'V')
expect_close = 42;
}
return len;
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 88 | 97.78% | 1 | 33.33% |
al viro | al viro | 1 | 1.11% | 1 | 33.33% |
wim van sebroeck | wim van sebroeck | 1 | 1.11% | 1 | 33.33% |
| Total | 90 | 100.00% | 3 | 100.00% |
static long scx200_wdt_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
void __user *argp = (void __user *)arg;
int __user *p = argp;
static const struct watchdog_info ident = {
.identity = "NatSemi SCx200 Watchdog",
.firmware_version = 1,
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
WDIOF_MAGICCLOSE,
};
int new_margin;
switch (cmd) {
case WDIOC_GETSUPPORT:
if (copy_to_user(argp, &ident, sizeof(ident)))
return -EFAULT;
return 0;
case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS:
if (put_user(0, p))
return -EFAULT;
return 0;
case WDIOC_KEEPALIVE:
scx200_wdt_ping();
return 0;
case WDIOC_SETTIMEOUT:
if (get_user(new_margin, p))
return -EFAULT;
if (new_margin < 1)
return -EINVAL;
margin = new_margin;
scx200_wdt_update_margin();
scx200_wdt_ping();
case WDIOC_GETTIMEOUT:
if (put_user(margin, p))
return -EFAULT;
return 0;
default:
return -ENOTTY;
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 158 | 83.16% | 1 | 20.00% |
al viro | al viro | 23 | 12.11% | 1 | 20.00% |
wim van sebroeck | wim van sebroeck | 7 | 3.68% | 2 | 40.00% |
alan cox | alan cox | 2 | 1.05% | 1 | 20.00% |
| Total | 190 | 100.00% | 5 | 100.00% |
static const struct file_operations scx200_wdt_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.write = scx200_wdt_write,
.unlocked_ioctl = scx200_wdt_ioctl,
.open = scx200_wdt_open,
.release = scx200_wdt_release,
};
static struct miscdevice scx200_wdt_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &scx200_wdt_fops,
};
static int __init scx200_wdt_init(void)
{
int r;
pr_debug("NatSemi SCx200 Watchdog Driver\n");
/* check that we have found the configuration block */
if (!scx200_cb_present())
return -ENODEV;
if (!request_region(scx200_cb_base + SCx200_WDT_OFFSET,
SCx200_WDT_SIZE,
"NatSemi SCx200 Watchdog")) {
pr_warn("watchdog I/O region busy\n");
return -EBUSY;
}
scx200_wdt_update_margin();
scx200_wdt_disable();
r = register_reboot_notifier(&scx200_wdt_notifier);
if (r) {
pr_err("unable to register reboot notifier\n");
release_region(scx200_cb_base + SCx200_WDT_OFFSET,
SCx200_WDT_SIZE);
return r;
}
r = misc_register(&scx200_wdt_miscdev);
if (r) {
unregister_reboot_notifier(&scx200_wdt_notifier);
release_region(scx200_cb_base + SCx200_WDT_OFFSET,
SCx200_WDT_SIZE);
return r;
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 84 | 67.20% | 1 | 20.00% |
alan cox | alan cox | 18 | 14.40% | 1 | 20.00% |
joe perches | joe perches | 9 | 7.20% | 1 | 20.00% |
wim van sebroeck | wim van sebroeck | 8 | 6.40% | 1 | 20.00% |
henrik brix andersen | henrik brix andersen | 6 | 4.80% | 1 | 20.00% |
| Total | 125 | 100.00% | 5 | 100.00% |
static void __exit scx200_wdt_cleanup(void)
{
misc_deregister(&scx200_wdt_miscdev);
unregister_reboot_notifier(&scx200_wdt_notifier);
release_region(scx200_cb_base + SCx200_WDT_OFFSET,
SCx200_WDT_SIZE);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 25 | 83.33% | 1 | 33.33% |
wim van sebroeck | wim van sebroeck | 4 | 13.33% | 1 | 33.33% |
henrik brix andersen | henrik brix andersen | 1 | 3.33% | 1 | 33.33% |
| Total | 30 | 100.00% | 3 | 100.00% |
module_init(scx200_wdt_init);
module_exit(scx200_wdt_cleanup);
/*
Local variables:
compile-command: "make -k -C ../.. SUBDIRS=drivers/char modules"
c-basic-offset: 8
End:
*/
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christer weinigel | christer weinigel | 744 | 78.07% | 1 | 4.55% |
alan cox | alan cox | 79 | 8.29% | 2 | 9.09% |
wim van sebroeck | wim van sebroeck | 37 | 3.88% | 8 | 36.36% |
joe perches | joe perches | 31 | 3.25% | 1 | 4.55% |
al viro | al viro | 24 | 2.52% | 1 | 4.55% |
henrik brix andersen | henrik brix andersen | 15 | 1.57% | 1 | 4.55% |
andrew morton | andrew morton | 10 | 1.05% | 1 | 4.55% |
linus torvalds | linus torvalds | 6 | 0.63% | 1 | 4.55% |
art haas | art haas | 2 | 0.21% | 1 | 4.55% |
jean delvare | jean delvare | 1 | 0.10% | 1 | 4.55% |
olaf hering | olaf hering | 1 | 0.10% | 1 | 4.55% |
dave jones | dave jones | 1 | 0.10% | 1 | 4.55% |
andrey panin | andrey panin | 1 | 0.10% | 1 | 4.55% |
arjan van de ven | arjan van de ven | 1 | 0.10% | 1 | 4.55% |
| Total | 953 | 100.00% | 22 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.