Update the watchdog driver to make it more linux look alike
SVN-Revision: 7100
This commit is contained in:
parent
6e93fa59ef
commit
b944dd2c57
2 changed files with 280 additions and 251 deletions
|
@ -0,0 +1,280 @@
|
|||
/*
|
||||
* Driver for the MTX-1 Watchdog.
|
||||
*
|
||||
* (c) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
|
||||
* http://www.4g-systems.biz
|
||||
*
|
||||
* (C) Copyright 2007 OpenWrt.org, Florian Fainelli <florian@openwrt.org>
|
||||
*
|
||||
* 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 Michael Stickel nor 4G Systems admit liability nor provide
|
||||
* warranty for any of this software. This material is provided
|
||||
* "AS-IS" and at no charge.
|
||||
*
|
||||
* (c) Copyright 2005 4G Systems <info@4g-systems.biz>
|
||||
*
|
||||
* Release 0.01.
|
||||
*
|
||||
* Author: Michael Stickel michael.stickel@4g-systems.biz
|
||||
*
|
||||
* Release 0.02.
|
||||
* Author: Florian Fainelli florian@openwrt.org
|
||||
* use the Linux watchdog API
|
||||
*
|
||||
* The Watchdog is configured to reset the MTX-1
|
||||
* if it is not triggered for 100 seconds.
|
||||
* It should not be triggered more often than 1.6 seconds.
|
||||
*
|
||||
* A timer triggers the watchdog every 5 seconds, until
|
||||
* it is opened for the first time. After the first open
|
||||
* it MUST be triggered every 2..95 seconds.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/watchdog.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include <asm/mach-au1x00/au1000.h>
|
||||
|
||||
#define MTX1_WDT_INTERVAL (5 * HZ)
|
||||
|
||||
static int ticks = 100 * HZ;
|
||||
|
||||
static struct {
|
||||
struct completion stop;
|
||||
volatile int running;
|
||||
struct timer_list timer;
|
||||
volatile int queue;
|
||||
int default_ticks;
|
||||
unsigned long inuse;
|
||||
} mtx1_wdt_device;
|
||||
|
||||
static void mtx1_wdt_trigger(unsigned long unused)
|
||||
{
|
||||
u32 tmp;
|
||||
|
||||
if (mtx1_wdt_device.running)
|
||||
ticks--;
|
||||
/*
|
||||
* toggle GPIO2_15
|
||||
*/
|
||||
tmp = au_readl(GPIO2_DIR);
|
||||
tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
|
||||
au_writel (tmp, GPIO2_DIR);
|
||||
|
||||
if (mtx1_wdt_device.queue && ticks)
|
||||
mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL);
|
||||
else {
|
||||
complete(&mtx1_wdt_device.stop);
|
||||
}
|
||||
}
|
||||
|
||||
static void mtx1_wdt_reset(void)
|
||||
{
|
||||
ticks = mtx1_wdt_device.default_ticks;
|
||||
}
|
||||
|
||||
|
||||
static void mtx1_wdt_start(void)
|
||||
{
|
||||
if (!mtx1_wdt_device.queue) {
|
||||
mtx1_wdt_device.queue = 1;
|
||||
au_writel (au_readl(GPIO2_DIR) | (u32)(1<<15), GPIO2_DIR);
|
||||
mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL);
|
||||
}
|
||||
mtx1_wdt_device.running++;
|
||||
}
|
||||
|
||||
static int mtx1_wdt_stop(void)
|
||||
{
|
||||
if (mtx1_wdt_device.queue) {
|
||||
mtx1_wdt_device.queue = 0;
|
||||
au_writel (au_readl(GPIO2_DIR) & ~((u32)(1<<15)), GPIO2_DIR);
|
||||
}
|
||||
|
||||
ticks = mtx1_wdt_device.default_ticks;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Filesystem functions */
|
||||
|
||||
static char restart_after_close;
|
||||
|
||||
static int mtx1_wdt_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
if (test_and_set_bit(0, &mtx1_wdt_device.inuse))
|
||||
return -EBUSY;
|
||||
|
||||
return nonseekable_open(inode, file);
|
||||
}
|
||||
|
||||
|
||||
static int mtx1_wdt_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
clear_bit(0, &mtx1_wdt_device.inuse);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mtx1_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
void __user *argp = (void __user *)arg;
|
||||
unsigned int value;
|
||||
static struct watchdog_info ident =
|
||||
{
|
||||
.options = WDIOF_CARDRESET,
|
||||
.identity = "MTX-1 WDT",
|
||||
};
|
||||
|
||||
switch(cmd) {
|
||||
case WDIOC_KEEPALIVE:
|
||||
mtx1_wdt_reset();
|
||||
break;
|
||||
case WDIOC_GETSTATUS:
|
||||
if ( copy_to_user(argp, &value, sizeof(int)) )
|
||||
return -EFAULT;
|
||||
break;
|
||||
case WDIOC_GETSUPPORT:
|
||||
if ( copy_to_user(argp, &ident, sizeof(ident)) )
|
||||
return -EFAULT;
|
||||
break;
|
||||
case WDIOC_SETOPTIONS:
|
||||
if ( copy_from_user(&value, argp, sizeof(int)) )
|
||||
return -EFAULT;
|
||||
switch(value) {
|
||||
case WDIOS_ENABLECARD:
|
||||
mtx1_wdt_start();
|
||||
break;
|
||||
case WDIOS_DISABLECARD:
|
||||
return mtx1_wdt_stop();
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -ENOTTY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ssize_t mtx1_wdt_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
if (!count)
|
||||
return -EIO;
|
||||
|
||||
mtx1_wdt_reset();
|
||||
|
||||
if (count > 0) {
|
||||
char buffer[10];
|
||||
int n = (count>9)?9:count;
|
||||
|
||||
if (copy_from_user (&buffer, buf, n))
|
||||
return -EFAULT;
|
||||
buffer[n]=0;
|
||||
|
||||
if (count >= 4 && strncmp("auto", buffer, 4)==0)
|
||||
restart_after_close = 1;
|
||||
|
||||
else if (count >= 6 && strncmp("manual", buffer, 6)==0)
|
||||
restart_after_close = 0;
|
||||
|
||||
return n;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static ssize_t mtx1_wdt_read (struct file *file, char *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
char * state = restart_after_close ? "auto\n" : "manual\n";
|
||||
int n = strlen(state)+1;
|
||||
|
||||
if (file->f_pos >= n)
|
||||
return 0;
|
||||
|
||||
if (count < n)
|
||||
return -EINVAL;
|
||||
|
||||
if(copy_to_user(buf, state, n))
|
||||
return -EFAULT;
|
||||
|
||||
file->f_pos += n;
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct file_operations mtx1_wdt_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.llseek = no_llseek,
|
||||
.ioctl = mtx1_wdt_ioctl,
|
||||
.open = mtx1_wdt_open,
|
||||
.write = mtx1_wdt_write,
|
||||
//.read = mtx1_wdt_read,
|
||||
.release = mtx1_wdt_release
|
||||
};
|
||||
|
||||
|
||||
static struct miscdevice mtx1_wdt_misc = {
|
||||
.minor = WATCHDOG_MINOR,
|
||||
.name = "watchdog",
|
||||
.fops = &mtx1_wdt_fops
|
||||
};
|
||||
|
||||
|
||||
static int __init mtx1_wdt_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = misc_register(&mtx1_wdt_misc)) < 0) {
|
||||
printk(KERN_ERR " mtx-1_wdt : failed to register\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
init_completion(&mtx1_wdt_device.stop);
|
||||
mtx1_wdt_device.queue = 0;
|
||||
|
||||
clear_bit(0, &mtx1_wdt_device.inuse);
|
||||
|
||||
setup_timer(&mtx1_wdt_device.timer, mtx1_wdt_trigger, 0L);
|
||||
|
||||
mtx1_wdt_device.default_ticks = ticks;
|
||||
|
||||
mtx1_wdt_start();
|
||||
|
||||
printk(KERN_INFO "MTX-1 Watchdog driver\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit mtx1_wdt_exit(void)
|
||||
{
|
||||
if (mtx1_wdt_device.queue) {
|
||||
mtx1_wdt_device.queue = 0;
|
||||
wait_for_completion(&mtx1_wdt_device.stop);
|
||||
}
|
||||
misc_deregister(&mtx1_wdt_misc);
|
||||
}
|
||||
|
||||
module_init(mtx1_wdt_init);
|
||||
module_exit(mtx1_wdt_exit);
|
||||
|
||||
MODULE_AUTHOR("Michael Stickel, Florian Fainelli");
|
||||
MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
|
||||
MODULE_LICENSE("GPL");
|
|
@ -26,254 +26,3 @@ diff -urN linux-2.6.16.7/drivers/char/watchdog/Makefile linux-2.6.16.7.new/drive
|
|||
+obj-$(CONFIG_MTX1_WATCHDOG) += mtx-1_watchdog.o
|
||||
|
||||
# S390 Architecture
|
||||
|
||||
diff -urN linux-2.6.16.7/drivers/char/watchdog/mtx-1_watchdog.c linux-2.6.16.7.new/drivers/char/watchdog/mtx-1_watchdog.c
|
||||
--- linux-2.6.16.7/drivers/char/watchdog/mtx-1_watchdog.c 1970-01-01 01:00:00.000000000 +0100
|
||||
+++ linux-2.6.16.7.new/drivers/char/watchdog/mtx-1_watchdog.c 2006-04-22 23:20:53.000000000 +0200
|
||||
@@ -0,0 +1,246 @@
|
||||
+/*
|
||||
+ * Driver for the MTX-1 Watchdog.
|
||||
+ *
|
||||
+ * (c) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
|
||||
+ * http://www.4g-systems.biz
|
||||
+ *
|
||||
+ * 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 Michael Stickel nor 4G Systems admit liability nor provide
|
||||
+ * warranty for any of this software. This material is provided
|
||||
+ * "AS-IS" and at no charge.
|
||||
+ *
|
||||
+ * (c) Copyright 2005 4G Systems <info@4g-systems.biz>
|
||||
+ *
|
||||
+ * Release 0.01.
|
||||
+ *
|
||||
+ * Author: Michael Stickel michael.stickel@4g-systems.biz
|
||||
+ *
|
||||
+ *
|
||||
+ * The Watchdog is configured to reset the MTX-1
|
||||
+ * if it is not triggered for 100 seconds.
|
||||
+ * It should not be triggered more often than 1.6 seconds.
|
||||
+ *
|
||||
+ * A timer triggers the watchdog every 5 seconds, until
|
||||
+ * it is opened for the first time. After the first open
|
||||
+ * it MUST be triggered every 2..95 seconds.
|
||||
+ */
|
||||
+#include <linux/autoconf.h>
|
||||
+#include <linux/module.h>
|
||||
+#include <linux/version.h>
|
||||
+#include <linux/types.h>
|
||||
+#include <linux/errno.h>
|
||||
+#include <linux/kernel.h>
|
||||
+#include <linux/sched.h>
|
||||
+#include <linux/miscdevice.h>
|
||||
+#include <linux/watchdog.h>
|
||||
+#include <linux/slab.h>
|
||||
+#include <linux/init.h>
|
||||
+#include <asm/uaccess.h>
|
||||
+#include <linux/fs.h>
|
||||
+
|
||||
+#include <asm/mach-au1x00/au1000.h>
|
||||
+
|
||||
+#ifndef FALSE
|
||||
+# define FALSE (0)
|
||||
+#endif
|
||||
+
|
||||
+#ifndef TRUE
|
||||
+# define TRUE (!FALSE)
|
||||
+#endif
|
||||
+
|
||||
+
|
||||
+//---------[ Hardware Functions ]-----------------
|
||||
+
|
||||
+static void mtx1_trigger_wd (void)
|
||||
+{
|
||||
+ /*
|
||||
+ * toggle GPIO2_15
|
||||
+ */
|
||||
+
|
||||
+ u32 tmp = au_readl(GPIO2_DIR);
|
||||
+ tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
|
||||
+ au_writel (tmp, GPIO2_DIR);
|
||||
+}
|
||||
+
|
||||
+static void mtx1_enable_wd (void)
|
||||
+{
|
||||
+ au_writel (au_readl(GPIO2_DIR) | (u32)(1<<15), GPIO2_DIR);
|
||||
+}
|
||||
+
|
||||
+static void mtx1_disable_wd (void)
|
||||
+{
|
||||
+ au_writel (au_readl(GPIO2_DIR) & ~((u32)(1<<15)), GPIO2_DIR);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+//---------[ Timer Functions ]-----------------
|
||||
+
|
||||
+static struct timer_list wd_trigger_timer;
|
||||
+static char timer_is_running = FALSE;
|
||||
+
|
||||
+static void wd_timer_callback (unsigned long data)
|
||||
+{
|
||||
+ if (timer_is_running)
|
||||
+ mod_timer (&wd_trigger_timer, jiffies + 5 * HZ);
|
||||
+ mtx1_trigger_wd();
|
||||
+}
|
||||
+
|
||||
+static void start_wd_timer (void)
|
||||
+{
|
||||
+ if (!timer_is_running) {
|
||||
+ struct timer_list *t = &wd_trigger_timer;
|
||||
+
|
||||
+ init_timer (t);
|
||||
+ t->function = wd_timer_callback;
|
||||
+ t->data = (unsigned long)0L;
|
||||
+ t->expires = jiffies + 5 * HZ; // 5 seconds.
|
||||
+ add_timer (t);
|
||||
+ timer_is_running = TRUE;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+
|
||||
+
|
||||
+static void stop_wd_timer (void)
|
||||
+{
|
||||
+ if (timer_is_running) {
|
||||
+ del_timer(&wd_trigger_timer);
|
||||
+ timer_is_running = FALSE;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+
|
||||
+//---------[ File Functions ]-----------------
|
||||
+
|
||||
+static char restart_after_close;
|
||||
+
|
||||
+static int mtx1wd_open (struct inode *inode, struct file *file)
|
||||
+{
|
||||
+ if (MINOR(inode->i_rdev) != WATCHDOG_MINOR) return -ENODEV;
|
||||
+ //MOD_INC_USE_COUNT;
|
||||
+
|
||||
+ // stop the timer, if it is running. It will not be
|
||||
+ // started again, until the module is loaded again.
|
||||
+ stop_wd_timer();
|
||||
+
|
||||
+ // sleep for 2 seconds, to ensure, that the wd is
|
||||
+ // not triggered more often than every 2 seconds.
|
||||
+ schedule_timeout (2 * HZ);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+static int mtx1wd_release (struct inode *inode, struct file *file) {
|
||||
+ if (MINOR(inode->i_rdev)==WATCHDOG_MINOR) {
|
||||
+ }
|
||||
+ if (restart_after_close)
|
||||
+ start_wd_timer();
|
||||
+ //MOD_DEC_USE_COUNT;
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+static ssize_t mtx1wd_write (struct file *file, const char *buf, size_t count, loff_t *ppos) {
|
||||
+
|
||||
+ mtx1_trigger_wd ();
|
||||
+
|
||||
+ if (count > 0) {
|
||||
+ char buffer[10];
|
||||
+ int n = (count>9)?9:count;
|
||||
+
|
||||
+ if (copy_from_user (&buffer, buf, n))
|
||||
+ return -EFAULT;
|
||||
+ buffer[n]=0;
|
||||
+
|
||||
+ if (count >= 4 && strncmp("auto", buffer, 4)==0)
|
||||
+ restart_after_close = 1;
|
||||
+
|
||||
+ else if (count >= 6 && strncmp("manual", buffer, 6)==0)
|
||||
+ restart_after_close = 0;
|
||||
+
|
||||
+ return n;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static ssize_t mtx1wd_read (struct file *file, char *buf, size_t count, loff_t *ppos)
|
||||
+{
|
||||
+ char * state = restart_after_close ? "auto\n" : "manual\n";
|
||||
+ int n = strlen(state)+1;
|
||||
+
|
||||
+ if (file->f_pos >= n)
|
||||
+ return 0;
|
||||
+
|
||||
+ if (count < n)
|
||||
+ return -EINVAL;
|
||||
+
|
||||
+ if(copy_to_user(buf, state, n))
|
||||
+ return -EFAULT;
|
||||
+
|
||||
+ file->f_pos += n;
|
||||
+
|
||||
+ return n;
|
||||
+}
|
||||
+
|
||||
+static struct file_operations mtx1wd_fops = {
|
||||
+ .owner = THIS_MODULE,
|
||||
+ .read = mtx1wd_read,
|
||||
+ .write = mtx1wd_write,
|
||||
+ .open = mtx1wd_open,
|
||||
+ .release = mtx1wd_release
|
||||
+};
|
||||
+
|
||||
+
|
||||
+static struct miscdevice mtx1wd_miscdev = {
|
||||
+ WATCHDOG_MINOR,
|
||||
+ "watchdog",
|
||||
+ &mtx1wd_fops
|
||||
+};
|
||||
+
|
||||
+
|
||||
+
|
||||
+//---------[ Module Functions ]-----------------
|
||||
+
|
||||
+
|
||||
+static int __init init_mtx1_watchdog(void)
|
||||
+{
|
||||
+ printk("MTX-1 watchdog driver\n");
|
||||
+
|
||||
+ misc_register(&mtx1wd_miscdev);
|
||||
+
|
||||
+ restart_after_close = 0;
|
||||
+
|
||||
+ mtx1_enable_wd ();
|
||||
+
|
||||
+ //-- trigger it for the first time.
|
||||
+ //-- We do not exactly know how long it has not been triggered.
|
||||
+ mtx1_trigger_wd ();
|
||||
+
|
||||
+ // start a timer, that calls mtx1_trigger_wd every 5 seconds.
|
||||
+ start_wd_timer();
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void __exit exit_mtx1_watchdog(void) {
|
||||
+
|
||||
+ // stop the timer, if it is running.
|
||||
+ stop_wd_timer();
|
||||
+
|
||||
+ misc_deregister(&mtx1wd_miscdev);
|
||||
+
|
||||
+ mtx1_disable_wd();
|
||||
+}
|
||||
+
|
||||
+module_init(init_mtx1_watchdog);
|
||||
+module_exit(exit_mtx1_watchdog);
|
||||
+
|
||||
+MODULE_AUTHOR("Michael Stickel");
|
||||
+MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
|
||||
+MODULE_LICENSE("GPL");
|
||||
|
|
Loading…
Reference in a new issue