* because this particular WDT has a very short timeout (1.6
* seconds) and it would be insane to count on any userspace
* daemon always getting scheduled within that time frame.
+ *
+ * Additions:
+ * Aug 23, 2004 - Added use_gpio module parameter for use on revision a1d PMUs
+ * found on very old cobalt hardware.
+ * -- Mike Waychison <michael.waychison@sun.com>
*/
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
#include <linux/init.h>
+#include <linux/fs.h>
#include <linux/pci.h>
#include <asm/io.h>
#define WDT_DISABLE 0x8C
#define ALI_7101_WDT 0x92
+#define ALI_7101_GPIO 0x7D
+#define ALI_7101_GPIO_O 0x7E
#define ALI_WDT_ARM 0x01
/*
module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
+static int use_gpio = 0; /* Use the pic (for a1d revision alim7101) */
+module_param(use_gpio, int, 0);
+MODULE_PARM_DESC(use_gpio, "Use the gpio watchdog. (required by old cobalt boards)");
+
static void wdt_timer_ping(unsigned long);
static struct timer_list timer;
static unsigned long next_heartbeat;
pci_read_config_byte(alim7101_pmu, 0x92, &tmp);
pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, (tmp & ~ALI_WDT_ARM));
pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, (tmp | ALI_WDT_ARM));
+ if (use_gpio) {
+ pci_read_config_byte(alim7101_pmu, ALI_7101_GPIO_O, &tmp);
+ pci_write_config_byte(alim7101_pmu, ALI_7101_GPIO_O, tmp
+ | 0x20);
+ pci_write_config_byte(alim7101_pmu, ALI_7101_GPIO_O, tmp
+ & ~0x20);
+ }
} else {
printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
}
{
char tmp;
- pci_read_config_byte(alim7101_pmu, 0x92, &tmp);
- if (writeval == WDT_ENABLE)
+ pci_read_config_byte(alim7101_pmu, ALI_7101_WDT, &tmp);
+ if (writeval == WDT_ENABLE) {
pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, (tmp | ALI_WDT_ARM));
- else
+ if (use_gpio) {
+ pci_read_config_byte(alim7101_pmu, ALI_7101_GPIO_O, &tmp);
+ pci_write_config_byte(alim7101_pmu, ALI_7101_GPIO_O, tmp & ~0x20);
+ }
+
+ } else {
pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, (tmp & ~ALI_WDT_ARM));
+ if (use_gpio) {
+ pci_read_config_byte(alim7101_pmu, ALI_7101_GPIO_O, &tmp);
+ pci_write_config_byte(alim7101_pmu, ALI_7101_GPIO_O, tmp | 0x20);
+ }
+ }
}
static void wdt_startup(void)
* /dev/watchdog handling
*/
-static ssize_t fop_write(struct file * file, const char * buf, size_t count, loff_t * ppos)
+static ssize_t fop_write(struct file * file, const char __user * buf, size_t count, loff_t * ppos)
{
- /* We can't seek */
- if(ppos != &file->f_pos)
- return -ESPIPE;
-
/* See if we got the magic character 'V' and reload the timer */
if(count) {
if (!nowayout) {
return -EBUSY;
/* Good, fire up the show */
wdt_startup();
- return 0;
+ return nonseekable_open(inode, file);
}
static int fop_close(struct inode * inode, struct file * file)
static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
+ void __user *argp = (void __user *)arg;
+ int __user *p = argp;
static struct watchdog_info ident =
{
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
switch(cmd)
{
case WDIOC_GETSUPPORT:
- return copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident))?-EFAULT:0;
+ return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS:
- return put_user(0, (int *)arg);
+ return put_user(0, p);
case WDIOC_KEEPALIVE:
wdt_keepalive();
return 0;
{
int new_options, retval = -EINVAL;
- if(get_user(new_options, (int *)arg))
+ if(get_user(new_options, p))
return -EFAULT;
if(new_options & WDIOS_DISABLECARD) {
{
int new_timeout;
- if(get_user(new_timeout, (int *)arg))
+ if(get_user(new_timeout, p))
return -EFAULT;
if(new_timeout < 1 || new_timeout > 3600) /* arbitrary upper limit */
/* Fall through */
}
case WDIOC_GETTIMEOUT:
- return put_user(timeout, (int *)arg);
+ return put_user(timeout, p);
default:
return -ENOIOCTLCMD;
}
return -EBUSY;
}
pci_read_config_byte(ali1543_south, 0x5e, &tmp);
- if ((tmp & 0x1e) != 0x12) {
+ if ((tmp & 0x1e) == 0x00) {
+ if (!use_gpio) {
+ printk(KERN_INFO PFX "Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n");
+ return -EBUSY;
+ }
+ nowayout = 1;
+ } else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) {
printk(KERN_INFO PFX "ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n");
return -EBUSY;
}
goto err_out_miscdev;
}
+ if (nowayout) {
+ __module_get(THIS_MODULE);
+ }
+
printk(KERN_INFO PFX "WDT driver for ALi M7101 initialised. timeout=%d sec (nowayout=%d)\n",
timeout, nowayout);
return 0;