2 * Driver for the MTX-1 Watchdog.
4 * (C) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
5 * http://www.4g-systems.biz
7 * (C) Copyright 2007 OpenWrt.org, Florian Fainelli <florian@openwrt.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * Neither Michael Stickel nor 4G Systems admit liability nor provide
15 * warranty for any of this software. This material is provided
16 * "AS-IS" and at no charge.
18 * (c) Copyright 2005 4G Systems <info@4g-systems.biz>
21 * Author: Michael Stickel michael.stickel@4g-systems.biz
24 * Author: Florian Fainelli florian@openwrt.org
25 * use the Linux watchdog/timer APIs
27 * The Watchdog is configured to reset the MTX-1
28 * if it is not triggered for 100 seconds.
29 * It should not be triggered more often than 1.6 seconds.
31 * A timer triggers the watchdog every 5 seconds, until
32 * it is opened for the first time. After the first open
33 * it MUST be triggered every 2..95 seconds.
36 #include <linux/module.h>
37 #include <linux/moduleparam.h>
38 #include <linux/types.h>
39 #include <linux/errno.h>
40 #include <linux/miscdevice.h>
42 #include <linux/init.h>
43 #include <linux/ioport.h>
44 #include <linux/timer.h>
45 #include <linux/completion.h>
46 #include <linux/jiffies.h>
47 #include <linux/watchdog.h>
48 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
50 #include <linux/platform_device.h>
52 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
54 #include <asm/uaccess.h>
56 #include <asm/mach-au1x00/au1000.h>
57 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
60 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
62 #define MTX1_WDT_INTERVAL (5 * HZ)
64 static int ticks
= 100 * HZ
;
67 struct completion stop
;
68 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
72 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
73 struct timer_list timer
;
74 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
78 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
81 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
84 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
87 static void mtx1_wdt_trigger(unsigned long unused
)
91 if (mtx1_wdt_device
.running
)
96 tmp
= au_readl(GPIO2_DIR
);
97 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
98 tmp
= (tmp
& ~(1<<15)) | ((~tmp
) & (1<<15));
100 tmp
= (tmp
& ~(1 << mtx1_wdt_device
.gpio
)) |
101 ((~tmp
) & (1 << mtx1_wdt_device
.gpio
));
102 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
103 au_writel (tmp
, GPIO2_DIR
);
105 if (mtx1_wdt_device
.queue
&& ticks
)
106 mod_timer(&mtx1_wdt_device
.timer
, jiffies
+ MTX1_WDT_INTERVAL
);
108 complete(&mtx1_wdt_device
.stop
);
112 static void mtx1_wdt_reset(void)
114 ticks
= mtx1_wdt_device
.default_ticks
;
118 static void mtx1_wdt_start(void)
120 if (!mtx1_wdt_device
.queue
) {
121 mtx1_wdt_device
.queue
= 1;
122 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
123 au_writel (au_readl(GPIO2_DIR
) | (u32
)(1<<15), GPIO2_DIR
);
125 gpio_set_value(mtx1_wdt_device
.gpio
, 1);
126 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
127 mod_timer(&mtx1_wdt_device
.timer
, jiffies
+ MTX1_WDT_INTERVAL
);
129 mtx1_wdt_device
.running
++;
132 static int mtx1_wdt_stop(void)
134 if (mtx1_wdt_device
.queue
) {
135 mtx1_wdt_device
.queue
= 0;
136 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
137 au_writel (au_readl(GPIO2_DIR
) & ~((u32
)(1<<15)), GPIO2_DIR
);
139 gpio_set_value(mtx1_wdt_device
.gpio
, 0);
140 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
143 ticks
= mtx1_wdt_device
.default_ticks
;
148 /* Filesystem functions */
150 static int mtx1_wdt_open(struct inode
*inode
, struct file
*file
)
152 if (test_and_set_bit(0, &mtx1_wdt_device
.inuse
))
155 return nonseekable_open(inode
, file
);
159 static int mtx1_wdt_release(struct inode
*inode
, struct file
*file
)
161 clear_bit(0, &mtx1_wdt_device
.inuse
);
165 static int mtx1_wdt_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
167 void __user
*argp
= (void __user
*)arg
;
169 static struct watchdog_info ident
=
171 .options
= WDIOF_CARDRESET
,
172 .identity
= "MTX-1 WDT",
176 case WDIOC_KEEPALIVE
:
179 case WDIOC_GETSTATUS
:
180 case WDIOC_GETBOOTSTATUS
:
181 if ( copy_to_user(argp
, &value
, sizeof(int)) )
184 case WDIOC_GETSUPPORT
:
185 if ( copy_to_user(argp
, &ident
, sizeof(ident
)) )
188 case WDIOC_SETOPTIONS
:
189 if ( copy_from_user(&value
, argp
, sizeof(int)) )
192 case WDIOS_ENABLECARD
:
195 case WDIOS_DISABLECARD
:
196 return mtx1_wdt_stop();
208 static ssize_t
mtx1_wdt_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
217 static const struct file_operations mtx1_wdt_fops
= {
218 .owner
= THIS_MODULE
,
220 .ioctl
= mtx1_wdt_ioctl
,
221 .open
= mtx1_wdt_open
,
222 .write
= mtx1_wdt_write
,
223 .release
= mtx1_wdt_release
227 static struct miscdevice mtx1_wdt_misc
= {
228 .minor
= WATCHDOG_MINOR
,
230 .fops
= &mtx1_wdt_fops
234 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
235 static int __init
mtx1_wdt_init(void)
237 static int mtx1_wdt_probe(struct platform_device
*pdev
)
238 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
242 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
244 mtx1_wdt_device
.gpio
= pdev
->resource
[0].start
;
246 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
247 if ((ret
= misc_register(&mtx1_wdt_misc
)) < 0) {
248 printk(KERN_ERR
" mtx-1_wdt : failed to register\n");
252 init_completion(&mtx1_wdt_device
.stop
);
253 mtx1_wdt_device
.queue
= 0;
255 clear_bit(0, &mtx1_wdt_device
.inuse
);
257 setup_timer(&mtx1_wdt_device
.timer
, mtx1_wdt_trigger
, 0L);
259 mtx1_wdt_device
.default_ticks
= ticks
;
263 printk(KERN_INFO
"MTX-1 Watchdog driver\n");
268 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
269 static void __exit
mtx1_wdt_exit(void)
271 static int mtx1_wdt_remove(struct platform_device
*pdev
)
272 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
274 if (mtx1_wdt_device
.queue
) {
275 mtx1_wdt_device
.queue
= 0;
276 wait_for_completion(&mtx1_wdt_device
.stop
);
278 misc_deregister(&mtx1_wdt_misc
);
279 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
284 static struct platform_driver mtx1_wdt
= {
285 .probe
= mtx1_wdt_probe
,
286 .remove
= mtx1_wdt_remove
,
287 .driver
.name
= "mtx1-wdt",
290 static int __init
mtx1_wdt_init(void)
292 return platform_driver_register(&mtx1_wdt
);
295 static void __exit
mtx1_wdt_exit(void)
297 platform_driver_unregister(&mtx1_wdt
);
298 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c
301 module_init(mtx1_wdt_init
);
302 module_exit(mtx1_wdt_exit
);
304 MODULE_AUTHOR("Michael Stickel, Florian Fainelli");
305 MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
306 MODULE_LICENSE("GPL");
307 <<<<<<< HEAD
:drivers
/watchdog
/mtx
-1_wdt
.c
309 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR
);
310 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/mtx
-1_wdt
.c