2005-04-16 18:20:36 -04:00
|
|
|
/*
|
|
|
|
* Watchdog driver for the SA11x0/PXA2xx
|
|
|
|
*
|
|
|
|
* (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
|
2008-10-27 11:17:56 -04:00
|
|
|
* Based on SoftDog driver by Alan Cox <alan@lxorguk.ukuu.org.uk>
|
2005-04-16 18:20:36 -04: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 Oleg Drokin nor iXcelerator.com admit liability nor provide
|
|
|
|
* warranty for any of this software. This material is provided
|
|
|
|
* "AS-IS" and at no charge.
|
|
|
|
*
|
|
|
|
* (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
|
|
|
|
*
|
|
|
|
* 27/11/2000 Initial release
|
|
|
|
*/
|
|
|
|
#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>
|
2007-10-19 02:40:25 -04:00
|
|
|
#include <linux/bitops.h>
|
2008-05-19 09:08:05 -04:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_PXA
|
2008-08-05 11:14:15 -04:00
|
|
|
#include <mach/pxa-regs.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
#endif
|
|
|
|
|
2008-08-07 06:05:25 -04:00
|
|
|
#include <mach/reset.h>
|
2008-08-05 11:14:15 -04:00
|
|
|
#include <mach/hardware.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
#define OSCR_FREQ CLOCK_TICK_RATE
|
|
|
|
|
|
|
|
static unsigned long sa1100wdt_users;
|
|
|
|
static int pre_margin;
|
|
|
|
static int boot_status;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow only one person to hold it open
|
|
|
|
*/
|
|
|
|
static int sa1100dog_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2008-05-19 09:08:05 -04:00
|
|
|
if (test_and_set_bit(1, &sa1100wdt_users))
|
2005-04-16 18:20:36 -04:00
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
/* Activate SA1100 Watchdog timer */
|
|
|
|
OSMR3 = OSCR + pre_margin;
|
|
|
|
OSSR = OSSR_M3;
|
|
|
|
OWER = OWER_WME;
|
|
|
|
OIER |= OIER_E3;
|
2007-07-24 17:38:37 -04:00
|
|
|
return nonseekable_open(inode, file);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-08-03 15:34:52 -04:00
|
|
|
* The watchdog cannot be disabled.
|
|
|
|
*
|
|
|
|
* Previous comments suggested that turning off the interrupt by
|
|
|
|
* clearing OIER[E3] would prevent the watchdog timing out but this
|
|
|
|
* does not appear to be true (at least on the PXA255).
|
2005-04-16 18:20:36 -04:00
|
|
|
*/
|
|
|
|
static int sa1100dog_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
2005-08-03 15:34:52 -04:00
|
|
|
printk(KERN_CRIT "WATCHDOG: Device closed - timer will not stop\n");
|
2005-04-16 18:20:36 -04:00
|
|
|
clear_bit(1, &sa1100wdt_users);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-19 09:08:05 -04:00
|
|
|
static ssize_t sa1100dog_write(struct file *file, const char __user *data,
|
|
|
|
size_t len, loff_t *ppos)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2005-08-03 15:34:52 -04:00
|
|
|
if (len)
|
2005-04-16 18:20:36 -04:00
|
|
|
/* Refresh OSMR3 timer. */
|
|
|
|
OSMR3 = OSCR + pre_margin;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-05-19 09:08:05 -04:00
|
|
|
static const struct watchdog_info ident = {
|
|
|
|
.options = WDIOF_CARDRESET | WDIOF_SETTIMEOUT
|
|
|
|
| WDIOF_KEEPALIVEPING,
|
2005-08-03 15:34:52 -04:00
|
|
|
.identity = "SA1100/PXA255 Watchdog",
|
2005-04-16 18:20:36 -04:00
|
|
|
};
|
|
|
|
|
2008-05-19 09:08:05 -04:00
|
|
|
static long sa1100dog_ioctl(struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2006-09-09 11:34:31 -04:00
|
|
|
int ret = -ENOTTY;
|
2005-04-16 18:20:36 -04:00
|
|
|
int time;
|
2005-11-07 05:21:24 -05:00
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
int __user *p = argp;
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WDIOC_GETSUPPORT:
|
2005-11-07 05:21:24 -05:00
|
|
|
ret = copy_to_user(argp, &ident,
|
2005-04-16 18:20:36 -04:00
|
|
|
sizeof(ident)) ? -EFAULT : 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_GETSTATUS:
|
2005-11-07 05:21:24 -05:00
|
|
|
ret = put_user(0, p);
|
2005-04-16 18:20:36 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
2005-11-07 05:21:24 -05:00
|
|
|
ret = put_user(boot_status, p);
|
2005-04-16 18:20:36 -04:00
|
|
|
break;
|
|
|
|
|
2008-07-18 07:41:17 -04:00
|
|
|
case WDIOC_KEEPALIVE:
|
|
|
|
OSMR3 = OSCR + pre_margin;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
case WDIOC_SETTIMEOUT:
|
2005-11-07 05:21:24 -05:00
|
|
|
ret = get_user(time, p);
|
2005-04-16 18:20:36 -04:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (time <= 0 || time > 255) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pre_margin = OSCR_FREQ * time;
|
|
|
|
OSMR3 = OSCR + pre_margin;
|
|
|
|
/*fall through*/
|
|
|
|
|
|
|
|
case WDIOC_GETTIMEOUT:
|
2005-11-07 05:21:24 -05:00
|
|
|
ret = put_user(pre_margin / OSCR_FREQ, p);
|
2005-04-16 18:20:36 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-19 09:08:05 -04:00
|
|
|
static const struct file_operations sa1100dog_fops = {
|
2005-04-16 18:20:36 -04:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.write = sa1100dog_write,
|
2008-05-19 09:08:05 -04:00
|
|
|
.unlocked_ioctl = sa1100dog_ioctl,
|
2005-04-16 18:20:36 -04:00
|
|
|
.open = sa1100dog_open,
|
|
|
|
.release = sa1100dog_release,
|
|
|
|
};
|
|
|
|
|
2008-05-19 09:08:05 -04:00
|
|
|
static struct miscdevice sa1100dog_miscdev = {
|
2005-04-16 18:20:36 -04:00
|
|
|
.minor = WATCHDOG_MINOR,
|
2005-08-03 15:34:52 -04:00
|
|
|
.name = "watchdog",
|
2005-04-16 18:20:36 -04:00
|
|
|
.fops = &sa1100dog_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int margin __initdata = 60; /* (secs) Default is 1 minute */
|
|
|
|
|
|
|
|
static int __init sa1100dog_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the reset status, and save it for later. If
|
|
|
|
* we suspend, RCSR will be cleared, and the watchdog
|
|
|
|
* reset reason will be lost.
|
|
|
|
*/
|
2008-07-29 02:39:34 -04:00
|
|
|
boot_status = (reset_status & RESET_STATUS_WATCHDOG) ?
|
|
|
|
WDIOF_CARDRESET : 0;
|
2005-04-16 18:20:36 -04:00
|
|
|
pre_margin = OSCR_FREQ * margin;
|
|
|
|
|
|
|
|
ret = misc_register(&sa1100dog_miscdev);
|
|
|
|
if (ret == 0)
|
2008-05-19 09:08:05 -04:00
|
|
|
printk(KERN_INFO
|
|
|
|
"SA1100/PXA2xx Watchdog Timer: timer margin %d sec\n",
|
|
|
|
margin);
|
2005-04-16 18:20:36 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit sa1100dog_exit(void)
|
|
|
|
{
|
|
|
|
misc_deregister(&sa1100dog_miscdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(sa1100dog_init);
|
|
|
|
module_exit(sa1100dog_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Oleg Drokin <green@crimea.edu>");
|
|
|
|
MODULE_DESCRIPTION("SA1100/PXA2xx Watchdog");
|
|
|
|
|
|
|
|
module_param(margin, int, 0);
|
|
|
|
MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)");
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
|