~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux-2.6.17/drivers/char/watchdog/indydog.c

Version: ~ [ 2.6.16 ] ~ [ 2.6.17 ] ~
Architecture: ~ [ ia64 ] ~ [ i386 ] ~ [ arm ] ~ [ ppc ] ~ [ sparc64 ] ~

  1 /*
  2  *      IndyDog 0.3     A Hardware Watchdog Device for SGI IP22
  3  *
  4  *      (c) Copyright 2002 Guido Guenther <agx@sigxcpu.org>, All Rights Reserved.
  5  *
  6  *      This program is free software; you can redistribute it and/or
  7  *      modify it under the terms of the GNU General Public License
  8  *      as published by the Free Software Foundation; either version
  9  *      2 of the License, or (at your option) any later version.
 10  *
 11  *      based on softdog.c by Alan Cox <alan@redhat.com>
 12  */
 13 
 14 #include <linux/module.h>
 15 #include <linux/moduleparam.h>
 16 #include <linux/config.h>
 17 #include <linux/types.h>
 18 #include <linux/kernel.h>
 19 #include <linux/fs.h>
 20 #include <linux/mm.h>
 21 #include <linux/miscdevice.h>
 22 #include <linux/watchdog.h>
 23 #include <linux/notifier.h>
 24 #include <linux/reboot.h>
 25 #include <linux/init.h>
 26 #include <asm/uaccess.h>
 27 #include <asm/sgi/mc.h>
 28 
 29 #define PFX "indydog: "
 30 static int indydog_alive;
 31 
 32 #define WATCHDOG_TIMEOUT 30             /* 30 sec default timeout */
 33 
 34 static int nowayout = WATCHDOG_NOWAYOUT;
 35 module_param(nowayout, int, 0);
 36 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
 37 
 38 static void indydog_start(void)
 39 {
 40         u32 mc_ctrl0 = sgimc->cpuctrl0;
 41 
 42         mc_ctrl0 = sgimc->cpuctrl0 | SGIMC_CCTRL0_WDOG;
 43         sgimc->cpuctrl0 = mc_ctrl0;
 44 }
 45 
 46 static void indydog_stop(void)
 47 {
 48         u32 mc_ctrl0 = sgimc->cpuctrl0;
 49 
 50         mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG;
 51         sgimc->cpuctrl0 = mc_ctrl0;
 52 
 53         printk(KERN_INFO PFX "Stopped watchdog timer.\n");
 54 }
 55 
 56 static void indydog_ping(void)
 57 {
 58         sgimc->watchdogt = 0;
 59 }
 60 
 61 /*
 62  *      Allow only one person to hold it open
 63  */
 64 static int indydog_open(struct inode *inode, struct file *file)
 65 {
 66         if (indydog_alive)
 67                 return -EBUSY;
 68 
 69         if (nowayout)
 70                 __module_get(THIS_MODULE);
 71 
 72         /* Activate timer */
 73         indydog_start();
 74         indydog_ping();
 75 
 76         indydog_alive = 1;
 77         printk(KERN_INFO "Started watchdog timer.\n");
 78 
 79         return nonseekable_open(inode, file);
 80 }
 81 
 82 static int indydog_release(struct inode *inode, struct file *file)
 83 {
 84         /* Shut off the timer.
 85          * Lock it in if it's a module and we defined ...NOWAYOUT */
 86         if (!nowayout)
 87                 indydog_stop();         /* Turn the WDT off */
 88 
 89         indydog_alive = 0;
 90 
 91         return 0;
 92 }
 93 
 94 static ssize_t indydog_write(struct file *file, const char *data, size_t len, loff_t *ppos)
 95 {
 96         /* Refresh the timer. */
 97         if (len) {
 98                 indydog_ping();
 99         }
100         return len;
101 }
102 
103 static int indydog_ioctl(struct inode *inode, struct file *file,
104         unsigned int cmd, unsigned long arg)
105 {
106         int options, retval = -EINVAL;
107         static struct watchdog_info ident = {
108                 .options                = WDIOF_KEEPALIVEPING |
109                                           WDIOF_MAGICCLOSE,
110                 .firmware_version       = 0,
111                 .identity               = "Hardware Watchdog for SGI IP22",
112         };
113 
114         switch (cmd) {
115                 default:
116                         return -ENOIOCTLCMD;
117                 case WDIOC_GETSUPPORT:
118                         if (copy_to_user((struct watchdog_info *)arg,
119                                          &ident, sizeof(ident)))
120                                 return -EFAULT;
121                         return 0;
122                 case WDIOC_GETSTATUS:
123                 case WDIOC_GETBOOTSTATUS:
124                         return put_user(0,(int *)arg);
125                 case WDIOC_KEEPALIVE:
126                         indydog_ping();
127                         return 0;
128                 case WDIOC_GETTIMEOUT:
129                         return put_user(WATCHDOG_TIMEOUT,(int *)arg);
130                 case WDIOC_SETOPTIONS:
131                 {
132                         if (get_user(options, (int *)arg))
133                                 return -EFAULT;
134 
135                         if (options & WDIOS_DISABLECARD) {
136                                 indydog_stop();
137                                 retval = 0;
138                         }
139 
140                         if (options & WDIOS_ENABLECARD) {
141                                 indydog_start();
142                                 retval = 0;
143                         }
144 
145                         return retval;
146                 }
147         }
148 }
149 
150 static int indydog_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
151 {
152         if (code == SYS_DOWN || code == SYS_HALT)
153                 indydog_stop();         /* Turn the WDT off */
154 
155         return NOTIFY_DONE;
156 }
157 
158 static struct file_operations indydog_fops = {
159         .owner          = THIS_MODULE,
160         .llseek         = no_llseek,
161         .write          = indydog_write,
162         .ioctl          = indydog_ioctl,
163         .open           = indydog_open,
164         .release        = indydog_release,
165 };
166 
167 static struct miscdevice indydog_miscdev = {
168         .minor          = WATCHDOG_MINOR,
169         .name           = "watchdog",
170         .fops           = &indydog_fops,
171 };
172 
173 static struct notifier_block indydog_notifier = {
174         .notifier_call = indydog_notify_sys,
175 };
176 
177 static char banner[] __initdata =
178         KERN_INFO PFX "Hardware Watchdog Timer for SGI IP22: 0.3\n";
179 
180 static int __init watchdog_init(void)
181 {
182         int ret;
183 
184         ret = register_reboot_notifier(&indydog_notifier);
185         if (ret) {
186                 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
187                         ret);
188                 return ret;
189         }
190 
191         ret = misc_register(&indydog_miscdev);
192         if (ret) {
193                 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
194                         WATCHDOG_MINOR, ret);
195                 unregister_reboot_notifier(&indydog_notifier);
196                 return ret;
197         }
198 
199         printk(banner);
200 
201         return 0;
202 }
203 
204 static void __exit watchdog_exit(void)
205 {
206         misc_deregister(&indydog_miscdev);
207         unregister_reboot_notifier(&indydog_notifier);
208 }
209 
210 module_init(watchdog_init);
211 module_exit(watchdog_exit);
212 
213 MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>");
214 MODULE_DESCRIPTION("Hardware Watchdog Device for SGI IP22");
215 MODULE_LICENSE("GPL");
216 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
217 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.