summaryrefslogtreecommitdiff
path: root/packages/linux/linux-mtx-1-2.4.27/23-mtx-1_watchdog_autotrigger.patch
blob: c6bb0aae68a5efcdf9afcc26f3eaccfda2f3fecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--- linux/arch/mips/au1000/mtx-1/mtx-1_watchdog.c.orig	2005-03-22 17:18:01.000000000 +0100
+++ linux/arch/mips/au1000/mtx-1/mtx-1_watchdog.c	2005-07-06 12:10:06.000000000 +0200
@@ -39,6 +39,7 @@
 #include <linux/watchdog.h>
 #include <linux/slab.h>
 #include <linux/init.h>
+#include <asm/uaccess.h>
 
 #include <asm/au1000.h>
 
@@ -115,6 +116,8 @@
 
 //---------[ 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;
@@ -134,6 +137,10 @@
 
 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;
@@ -141,22 +148,53 @@
 
 
 static ssize_t mtx1wd_write (struct file *file, const char *buf, size_t count, loff_t *ppos) {
-	if (ppos!=&file->f_pos)
-		return -ESPIPE;
 
-	if (count) {
 		mtx1_trigger_wd ();
-		return 1;
+
+	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,
 	.llseek = NULL,
-	.read = NULL,
+	.read = mtx1wd_read,
 	.write = mtx1wd_write,
 	.readdir = NULL,
 	.poll = NULL,
@@ -194,6 +232,8 @@
 {
 	printk("MTX-1 watchdog driver\n");
 
+	restart_after_close = 0;
+
 	mtx1_enable_wd ();
 
 	//-- trigger it for the first time.