Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / watchdog / mtx-1_wdt.c
blob4e89636b396672e86bd169e45760024233a87f61
1 /*
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>
20 * Release 0.01.
21 * Author: Michael Stickel michael.stickel@4g-systems.biz
23 * Release 0.02.
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>
41 #include <linux/fs.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
49 =======
50 #include <linux/platform_device.h>
52 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/mtx-1_wdt.c
53 #include <asm/io.h>
54 #include <asm/uaccess.h>
56 #include <asm/mach-au1x00/au1000.h>
57 <<<<<<< HEAD:drivers/watchdog/mtx-1_wdt.c
58 =======
59 #include <asm/gpio.h>
60 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/mtx-1_wdt.c
62 #define MTX1_WDT_INTERVAL (5 * HZ)
64 static int ticks = 100 * HZ;
66 static struct {
67 struct completion stop;
68 <<<<<<< HEAD:drivers/watchdog/mtx-1_wdt.c
69 volatile int running;
70 =======
71 int running;
72 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/mtx-1_wdt.c
73 struct timer_list timer;
74 <<<<<<< HEAD:drivers/watchdog/mtx-1_wdt.c
75 volatile int queue;
76 =======
77 int queue;
78 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/mtx-1_wdt.c
79 int default_ticks;
80 unsigned long inuse;
81 <<<<<<< HEAD:drivers/watchdog/mtx-1_wdt.c
82 =======
83 unsigned gpio;
84 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/mtx-1_wdt.c
85 } mtx1_wdt_device;
87 static void mtx1_wdt_trigger(unsigned long unused)
89 u32 tmp;
91 if (mtx1_wdt_device.running)
92 ticks--;
94 * toggle GPIO2_15
96 tmp = au_readl(GPIO2_DIR);
97 <<<<<<< HEAD:drivers/watchdog/mtx-1_wdt.c
98 tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
99 =======
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);
107 else {
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);
124 =======
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);
138 =======
139 gpio_set_value(mtx1_wdt_device.gpio, 0);
140 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/mtx-1_wdt.c
143 ticks = mtx1_wdt_device.default_ticks;
145 return 0;
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))
153 return -EBUSY;
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);
162 return 0;
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;
168 unsigned int value;
169 static struct watchdog_info ident =
171 .options = WDIOF_CARDRESET,
172 .identity = "MTX-1 WDT",
175 switch(cmd) {
176 case WDIOC_KEEPALIVE:
177 mtx1_wdt_reset();
178 break;
179 case WDIOC_GETSTATUS:
180 case WDIOC_GETBOOTSTATUS:
181 if ( copy_to_user(argp, &value, sizeof(int)) )
182 return -EFAULT;
183 break;
184 case WDIOC_GETSUPPORT:
185 if ( copy_to_user(argp, &ident, sizeof(ident)) )
186 return -EFAULT;
187 break;
188 case WDIOC_SETOPTIONS:
189 if ( copy_from_user(&value, argp, sizeof(int)) )
190 return -EFAULT;
191 switch(value) {
192 case WDIOS_ENABLECARD:
193 mtx1_wdt_start();
194 break;
195 case WDIOS_DISABLECARD:
196 return mtx1_wdt_stop();
197 default:
198 return -EINVAL;
200 break;
201 default:
202 return -ENOTTY;
204 return 0;
208 static ssize_t mtx1_wdt_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
210 if (!count)
211 return -EIO;
213 mtx1_wdt_reset();
214 return count;
217 static const struct file_operations mtx1_wdt_fops = {
218 .owner = THIS_MODULE,
219 .llseek = no_llseek,
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,
229 .name = "watchdog",
230 .fops = &mtx1_wdt_fops
234 <<<<<<< HEAD:drivers/watchdog/mtx-1_wdt.c
235 static int __init mtx1_wdt_init(void)
236 =======
237 static int mtx1_wdt_probe(struct platform_device *pdev)
238 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/mtx-1_wdt.c
240 int ret;
242 <<<<<<< HEAD:drivers/watchdog/mtx-1_wdt.c
243 =======
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");
249 return ret;
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;
261 mtx1_wdt_start();
263 printk(KERN_INFO "MTX-1 Watchdog driver\n");
265 return 0;
268 <<<<<<< HEAD:drivers/watchdog/mtx-1_wdt.c
269 static void __exit mtx1_wdt_exit(void)
270 =======
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
280 =======
281 return 0;
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
308 =======
309 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
310 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/mtx-1_wdt.c