2010-02-04 21:08:56 +01:00
|
|
|
/*
|
|
|
|
* drivers/char/watchdog/max63xx_wdt.c
|
|
|
|
*
|
|
|
|
* Driver for max63{69,70,71,72,73,74} watchdog timers
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Marc Zyngier <maz@misterjones.org>
|
|
|
|
*
|
|
|
|
* This file is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2. This program is licensed "as is" without any
|
|
|
|
* warranty of any kind, whether express or implied.
|
|
|
|
*
|
|
|
|
* This driver assumes the watchdog pins are memory mapped (as it is
|
|
|
|
* the case for the Arcom Zeus). Should it be connected over GPIOs or
|
|
|
|
* another interface, some abstraction will have to be introduced.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/device.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-02-04 21:08:56 +01:00
|
|
|
|
|
|
|
#define DEFAULT_HEARTBEAT 60
|
|
|
|
#define MAX_HEARTBEAT 60
|
|
|
|
|
|
|
|
static int heartbeat = DEFAULT_HEARTBEAT;
|
|
|
|
static int nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory mapping: a single byte, 3 first lower bits to select bit 3
|
|
|
|
* to ping the watchdog.
|
|
|
|
*/
|
|
|
|
#define MAX6369_WDSET (7 << 0)
|
2011-02-23 21:04:38 +01:00
|
|
|
#define MAX6369_WDI (1 << 3)
|
2010-02-04 21:08:56 +01:00
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(io_lock);
|
|
|
|
|
|
|
|
static unsigned long wdt_status;
|
|
|
|
#define WDT_IN_USE 0
|
|
|
|
#define WDT_RUNNING 1
|
|
|
|
#define WDT_OK_TO_CLOSE 2
|
|
|
|
|
|
|
|
static int nodelay;
|
|
|
|
static struct resource *wdt_mem;
|
|
|
|
static void __iomem *wdt_base;
|
|
|
|
static struct platform_device *max63xx_pdev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The timeout values used are actually the absolute minimum the chip
|
|
|
|
* offers. Typical values on my board are slightly over twice as long
|
|
|
|
* (10s setting ends up with a 25s timeout), and can be up to 3 times
|
|
|
|
* the nominal setting (according to the datasheet). So please take
|
|
|
|
* these values with a grain of salt. Same goes for the initial delay
|
|
|
|
* "feature". Only max6373/74 have a few settings without this initial
|
|
|
|
* delay (selected with the "nodelay" parameter).
|
|
|
|
*
|
|
|
|
* I also decided to remove from the tables any timeout smaller than a
|
|
|
|
* second, as it looked completly overkill...
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Timeouts in second */
|
|
|
|
struct max63xx_timeout {
|
|
|
|
u8 wdset;
|
|
|
|
u8 tdelay;
|
|
|
|
u8 twd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct max63xx_timeout max6369_table[] = {
|
|
|
|
{ 5, 1, 1 },
|
|
|
|
{ 6, 10, 10 },
|
|
|
|
{ 7, 60, 60 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct max63xx_timeout max6371_table[] = {
|
|
|
|
{ 6, 60, 3 },
|
|
|
|
{ 7, 60, 60 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct max63xx_timeout max6373_table[] = {
|
|
|
|
{ 2, 60, 1 },
|
|
|
|
{ 5, 0, 1 },
|
|
|
|
{ 1, 3, 3 },
|
|
|
|
{ 7, 60, 10 },
|
|
|
|
{ 6, 0, 10 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct max63xx_timeout *current_timeout;
|
|
|
|
|
|
|
|
static struct max63xx_timeout *
|
|
|
|
max63xx_select_timeout(struct max63xx_timeout *table, int value)
|
|
|
|
{
|
|
|
|
while (table->twd) {
|
|
|
|
if (value <= table->twd) {
|
|
|
|
if (nodelay && table->tdelay == 0)
|
|
|
|
return table;
|
|
|
|
|
|
|
|
if (!nodelay)
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
table++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void max63xx_wdt_ping(void)
|
|
|
|
{
|
|
|
|
u8 val;
|
|
|
|
|
|
|
|
spin_lock(&io_lock);
|
|
|
|
|
|
|
|
val = __raw_readb(wdt_base);
|
|
|
|
|
|
|
|
__raw_writeb(val | MAX6369_WDI, wdt_base);
|
|
|
|
__raw_writeb(val & ~MAX6369_WDI, wdt_base);
|
|
|
|
|
|
|
|
spin_unlock(&io_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void max63xx_wdt_enable(struct max63xx_timeout *entry)
|
|
|
|
{
|
|
|
|
u8 val;
|
|
|
|
|
|
|
|
if (test_and_set_bit(WDT_RUNNING, &wdt_status))
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock(&io_lock);
|
|
|
|
|
|
|
|
val = __raw_readb(wdt_base);
|
|
|
|
val &= ~MAX6369_WDSET;
|
|
|
|
val |= entry->wdset;
|
|
|
|
__raw_writeb(val, wdt_base);
|
|
|
|
|
|
|
|
spin_unlock(&io_lock);
|
|
|
|
|
|
|
|
/* check for a edge triggered startup */
|
|
|
|
if (entry->tdelay == 0)
|
|
|
|
max63xx_wdt_ping();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void max63xx_wdt_disable(void)
|
|
|
|
{
|
2010-04-09 18:43:33 +02:00
|
|
|
u8 val;
|
|
|
|
|
2010-02-04 21:08:56 +01:00
|
|
|
spin_lock(&io_lock);
|
|
|
|
|
2010-04-09 18:43:33 +02:00
|
|
|
val = __raw_readb(wdt_base);
|
|
|
|
val &= ~MAX6369_WDSET;
|
|
|
|
val |= 3;
|
|
|
|
__raw_writeb(val, wdt_base);
|
2010-02-04 21:08:56 +01:00
|
|
|
|
|
|
|
spin_unlock(&io_lock);
|
|
|
|
|
|
|
|
clear_bit(WDT_RUNNING, &wdt_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int max63xx_wdt_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
if (test_and_set_bit(WDT_IN_USE, &wdt_status))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
max63xx_wdt_enable(current_timeout);
|
|
|
|
clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
|
|
|
|
|
|
|
|
return nonseekable_open(inode, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t max63xx_wdt_write(struct file *file, const char *data,
|
|
|
|
size_t len, loff_t *ppos)
|
|
|
|
{
|
|
|
|
if (len) {
|
|
|
|
if (!nowayout) {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
|
|
|
|
for (i = 0; i != len; i++) {
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (get_user(c, data + i))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (c == 'V')
|
|
|
|
set_bit(WDT_OK_TO_CLOSE, &wdt_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
max63xx_wdt_ping();
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct watchdog_info ident = {
|
|
|
|
.options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
|
|
|
|
.identity = "max63xx Watchdog",
|
|
|
|
};
|
|
|
|
|
|
|
|
static long max63xx_wdt_ioctl(struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WDIOC_GETSUPPORT:
|
|
|
|
ret = copy_to_user((struct watchdog_info *)arg, &ident,
|
|
|
|
sizeof(ident)) ? -EFAULT : 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_GETSTATUS:
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
|
|
|
ret = put_user(0, (int *)arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_KEEPALIVE:
|
|
|
|
max63xx_wdt_ping();
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_GETTIMEOUT:
|
|
|
|
ret = put_user(heartbeat, (int *)arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int max63xx_wdt_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
if (test_bit(WDT_OK_TO_CLOSE, &wdt_status))
|
|
|
|
max63xx_wdt_disable();
|
|
|
|
else
|
|
|
|
dev_crit(&max63xx_pdev->dev,
|
|
|
|
"device closed unexpectedly - timer will not stop\n");
|
|
|
|
|
|
|
|
clear_bit(WDT_IN_USE, &wdt_status);
|
|
|
|
clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations max63xx_wdt_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.write = max63xx_wdt_write,
|
|
|
|
.unlocked_ioctl = max63xx_wdt_ioctl,
|
|
|
|
.open = max63xx_wdt_open,
|
|
|
|
.release = max63xx_wdt_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice max63xx_wdt_miscdev = {
|
|
|
|
.minor = WATCHDOG_MINOR,
|
|
|
|
.name = "watchdog",
|
|
|
|
.fops = &max63xx_wdt_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __devinit max63xx_wdt_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int size;
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct max63xx_timeout *table;
|
|
|
|
|
|
|
|
table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
|
|
|
|
|
|
|
|
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
|
|
|
|
heartbeat = DEFAULT_HEARTBEAT;
|
|
|
|
|
|
|
|
dev_info(dev, "requesting %ds heartbeat\n", heartbeat);
|
|
|
|
current_timeout = max63xx_select_timeout(table, heartbeat);
|
|
|
|
|
|
|
|
if (!current_timeout) {
|
|
|
|
dev_err(dev, "unable to satisfy heartbeat request\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(dev, "using %ds heartbeat with %ds initial delay\n",
|
|
|
|
current_timeout->twd, current_timeout->tdelay);
|
|
|
|
|
|
|
|
heartbeat = current_timeout->twd;
|
|
|
|
|
|
|
|
max63xx_pdev = pdev;
|
|
|
|
|
2011-02-26 17:34:39 +01:00
|
|
|
wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (wdt_mem == NULL) {
|
2010-02-04 21:08:56 +01:00
|
|
|
dev_err(dev, "failed to get memory region resource\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:34:39 +01:00
|
|
|
size = resource_size(wdt_mem);
|
|
|
|
if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
|
2010-02-04 21:08:56 +01:00
|
|
|
dev_err(dev, "failed to get memory region\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:34:39 +01:00
|
|
|
wdt_base = ioremap(wdt_mem->start, size);
|
2010-02-04 21:08:56 +01:00
|
|
|
if (!wdt_base) {
|
|
|
|
dev_err(dev, "failed to map memory region\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_request;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = misc_register(&max63xx_wdt_miscdev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "cannot register misc device\n");
|
|
|
|
goto out_unmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_unmap:
|
|
|
|
iounmap(wdt_base);
|
|
|
|
out_request:
|
2011-02-26 17:34:39 +01:00
|
|
|
release_mem_region(wdt_mem->start, size);
|
|
|
|
wdt_mem = NULL;
|
2010-02-04 21:08:56 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit max63xx_wdt_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
misc_deregister(&max63xx_wdt_miscdev);
|
|
|
|
if (wdt_mem) {
|
2011-02-26 17:34:39 +01:00
|
|
|
release_mem_region(wdt_mem->start, resource_size(wdt_mem));
|
2010-02-04 21:08:56 +01:00
|
|
|
wdt_mem = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wdt_base)
|
|
|
|
iounmap(wdt_base);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_device_id max63xx_id_table[] = {
|
|
|
|
{ "max6369_wdt", (kernel_ulong_t)max6369_table, },
|
|
|
|
{ "max6370_wdt", (kernel_ulong_t)max6369_table, },
|
|
|
|
{ "max6371_wdt", (kernel_ulong_t)max6371_table, },
|
|
|
|
{ "max6372_wdt", (kernel_ulong_t)max6371_table, },
|
|
|
|
{ "max6373_wdt", (kernel_ulong_t)max6373_table, },
|
|
|
|
{ "max6374_wdt", (kernel_ulong_t)max6373_table, },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, max63xx_id_table);
|
|
|
|
|
|
|
|
static struct platform_driver max63xx_wdt_driver = {
|
|
|
|
.probe = max63xx_wdt_probe,
|
|
|
|
.remove = __devexit_p(max63xx_wdt_remove),
|
|
|
|
.id_table = max63xx_id_table,
|
|
|
|
.driver = {
|
|
|
|
.name = "max63xx_wdt",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init max63xx_wdt_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&max63xx_wdt_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit max63xx_wdt_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&max63xx_wdt_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(max63xx_wdt_init);
|
|
|
|
module_exit(max63xx_wdt_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Marc Zyngier <maz@misterjones.org>");
|
|
|
|
MODULE_DESCRIPTION("max63xx Watchdog Driver");
|
|
|
|
|
|
|
|
module_param(heartbeat, int, 0);
|
|
|
|
MODULE_PARM_DESC(heartbeat,
|
|
|
|
"Watchdog heartbeat period in seconds from 1 to "
|
|
|
|
__MODULE_STRING(MAX_HEARTBEAT) ", default "
|
|
|
|
__MODULE_STRING(DEFAULT_HEARTBEAT));
|
|
|
|
|
|
|
|
module_param(nowayout, int, 0);
|
|
|
|
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
|
|
|
|
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
|
|
|
|
|
|
|
module_param(nodelay, int, 0);
|
|
|
|
MODULE_PARM_DESC(nodelay,
|
|
|
|
"Force selection of a timeout setting without initial delay "
|
|
|
|
"(max6373/74 only, default=0)");
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
|