Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ALi M7101 PMU Computer Watchdog Timer driver |
| 3 | * |
| 4 | * Based on w83877f_wdt.c by Scott Jennings <linuxdrivers@oro.net> |
| 5 | * and the Cobalt kernel WDT timer driver by Tim Hockin |
| 6 | * <thockin@cobaltnet.com> |
| 7 | * |
| 8 | * (c)2002 Steve Hill <steve@navaho.co.uk> |
| 9 | * |
| 10 | * This WDT driver is different from most other Linux WDT |
| 11 | * drivers in that the driver will ping the watchdog by itself, |
| 12 | * because this particular WDT has a very short timeout (1.6 |
| 13 | * seconds) and it would be insane to count on any userspace |
| 14 | * daemon always getting scheduled within that time frame. |
| 15 | * |
| 16 | * Additions: |
| 17 | * Aug 23, 2004 - Added use_gpio module parameter for use on revision a1d PMUs |
| 18 | * found on very old cobalt hardware. |
| 19 | * -- Mike Waychison <michael.waychison@sun.com> |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/moduleparam.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/timer.h> |
| 26 | #include <linux/miscdevice.h> |
| 27 | #include <linux/watchdog.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/notifier.h> |
| 30 | #include <linux/reboot.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/fs.h> |
| 33 | #include <linux/pci.h> |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 34 | #include <linux/io.h> |
| 35 | #include <linux/uaccess.h> |
Wim Van Sebroeck | 089ab07 | 2008-07-15 11:46:11 +0000 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/system.h> |
| 38 | |
| 39 | #define OUR_NAME "alim7101_wdt" |
| 40 | #define PFX OUR_NAME ": " |
| 41 | |
| 42 | #define WDT_ENABLE 0x9C |
| 43 | #define WDT_DISABLE 0x8C |
| 44 | |
| 45 | #define ALI_7101_WDT 0x92 |
| 46 | #define ALI_7101_GPIO 0x7D |
| 47 | #define ALI_7101_GPIO_O 0x7E |
| 48 | #define ALI_WDT_ARM 0x01 |
| 49 | |
| 50 | /* |
| 51 | * We're going to use a 1 second timeout. |
| 52 | * If we reset the watchdog every ~250ms we should be safe. */ |
| 53 | |
| 54 | #define WDT_INTERVAL (HZ/4+1) |
| 55 | |
| 56 | /* |
| 57 | * We must not require too good response from the userspace daemon. |
| 58 | * Here we require the userspace daemon to send us a heartbeat |
| 59 | * char to /dev/watchdog every 30 seconds. |
| 60 | */ |
| 61 | |
| 62 | #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 63 | /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */ |
| 64 | static int timeout = WATCHDOG_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | module_param(timeout, int, 0); |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 66 | MODULE_PARM_DESC(timeout, |
| 67 | "Watchdog timeout in seconds. (1<=timeout<=3600, default=" |
| 68 | __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 70 | static int use_gpio; /* Use the pic (for a1d revision alim7101) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | module_param(use_gpio, int, 0); |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 72 | MODULE_PARM_DESC(use_gpio, |
| 73 | "Use the gpio watchdog (required by old cobalt boards)."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | static void wdt_timer_ping(unsigned long); |
Jiri Slaby | 82eb7c5 | 2007-02-08 18:39:36 +0100 | [diff] [blame] | 76 | static DEFINE_TIMER(timer, wdt_timer_ping, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static unsigned long next_heartbeat; |
| 78 | static unsigned long wdt_is_open; |
| 79 | static char wdt_expect_close; |
| 80 | static struct pci_dev *alim7101_pmu; |
| 81 | |
Andrey Panin | 4bfdf37 | 2005-07-27 11:43:58 -0700 | [diff] [blame] | 82 | static int nowayout = WATCHDOG_NOWAYOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | module_param(nowayout, int, 0); |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 84 | MODULE_PARM_DESC(nowayout, |
| 85 | "Watchdog cannot be stopped once started (default=" |
| 86 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Whack the dog |
| 90 | */ |
| 91 | |
| 92 | static void wdt_timer_ping(unsigned long data) |
| 93 | { |
| 94 | /* If we got a heartbeat pulse within the WDT_US_INTERVAL |
| 95 | * we agree to ping the WDT |
| 96 | */ |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 97 | char tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 99 | if (time_before(jiffies, next_heartbeat)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /* Ping the WDT (this is actually a disarm/arm sequence) */ |
| 101 | pci_read_config_byte(alim7101_pmu, 0x92, &tmp); |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 102 | pci_write_config_byte(alim7101_pmu, |
| 103 | ALI_7101_WDT, (tmp & ~ALI_WDT_ARM)); |
| 104 | pci_write_config_byte(alim7101_pmu, |
| 105 | ALI_7101_WDT, (tmp | ALI_WDT_ARM)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | if (use_gpio) { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 107 | pci_read_config_byte(alim7101_pmu, |
| 108 | ALI_7101_GPIO_O, &tmp); |
| 109 | pci_write_config_byte(alim7101_pmu, |
| 110 | ALI_7101_GPIO_O, tmp | 0x20); |
| 111 | pci_write_config_byte(alim7101_pmu, |
| 112 | ALI_7101_GPIO_O, tmp & ~0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | } else { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 115 | printk(KERN_WARNING PFX |
| 116 | "Heartbeat lost! Will not ping the watchdog\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | /* Re-set the timer interval */ |
Jiri Slaby | 82eb7c5 | 2007-02-08 18:39:36 +0100 | [diff] [blame] | 119 | mod_timer(&timer, jiffies + WDT_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Utility routines |
| 124 | */ |
| 125 | |
| 126 | static void wdt_change(int writeval) |
| 127 | { |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 128 | char tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | pci_read_config_byte(alim7101_pmu, ALI_7101_WDT, &tmp); |
| 131 | if (writeval == WDT_ENABLE) { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 132 | pci_write_config_byte(alim7101_pmu, |
| 133 | ALI_7101_WDT, (tmp | ALI_WDT_ARM)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | if (use_gpio) { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 135 | pci_read_config_byte(alim7101_pmu, |
| 136 | ALI_7101_GPIO_O, &tmp); |
| 137 | pci_write_config_byte(alim7101_pmu, |
| 138 | ALI_7101_GPIO_O, tmp & ~0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | } else { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 142 | pci_write_config_byte(alim7101_pmu, |
| 143 | ALI_7101_WDT, (tmp & ~ALI_WDT_ARM)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (use_gpio) { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 145 | pci_read_config_byte(alim7101_pmu, |
| 146 | ALI_7101_GPIO_O, &tmp); |
| 147 | pci_write_config_byte(alim7101_pmu, |
| 148 | ALI_7101_GPIO_O, tmp | 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | static void wdt_startup(void) |
| 154 | { |
| 155 | next_heartbeat = jiffies + (timeout * HZ); |
| 156 | |
| 157 | /* We must enable before we kick off the timer in case the timer |
| 158 | occurs as we ping it */ |
| 159 | |
| 160 | wdt_change(WDT_ENABLE); |
| 161 | |
| 162 | /* Start the timer */ |
Jiri Slaby | 82eb7c5 | 2007-02-08 18:39:36 +0100 | [diff] [blame] | 163 | mod_timer(&timer, jiffies + WDT_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | printk(KERN_INFO PFX "Watchdog timer is now enabled.\n"); |
| 166 | } |
| 167 | |
| 168 | static void wdt_turnoff(void) |
| 169 | { |
| 170 | /* Stop the timer */ |
| 171 | del_timer_sync(&timer); |
| 172 | wdt_change(WDT_DISABLE); |
| 173 | printk(KERN_INFO PFX "Watchdog timer is now disabled...\n"); |
| 174 | } |
| 175 | |
| 176 | static void wdt_keepalive(void) |
| 177 | { |
| 178 | /* user land ping */ |
| 179 | next_heartbeat = jiffies + (timeout * HZ); |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * /dev/watchdog handling |
| 184 | */ |
| 185 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 186 | static ssize_t fop_write(struct file *file, const char __user *buf, |
| 187 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
| 189 | /* See if we got the magic character 'V' and reload the timer */ |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 190 | if (count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | if (!nowayout) { |
| 192 | size_t ofs; |
| 193 | |
| 194 | /* note: just in case someone wrote the magic character |
| 195 | * five months ago... */ |
| 196 | wdt_expect_close = 0; |
| 197 | |
| 198 | /* now scan */ |
| 199 | for (ofs = 0; ofs != count; ofs++) { |
| 200 | char c; |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 201 | if (get_user(c, buf + ofs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | return -EFAULT; |
| 203 | if (c == 'V') |
| 204 | wdt_expect_close = 42; |
| 205 | } |
| 206 | } |
| 207 | /* someone wrote to us, we should restart timer */ |
| 208 | wdt_keepalive(); |
| 209 | } |
| 210 | return count; |
| 211 | } |
| 212 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 213 | static int fop_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
| 215 | /* Just in case we're already talking to someone... */ |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 216 | if (test_and_set_bit(0, &wdt_is_open)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return -EBUSY; |
| 218 | /* Good, fire up the show */ |
| 219 | wdt_startup(); |
| 220 | return nonseekable_open(inode, file); |
| 221 | } |
| 222 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 223 | static int fop_close(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 225 | if (wdt_expect_close == 42) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | wdt_turnoff(); |
| 227 | else { |
| 228 | /* wim: shouldn't there be a: del_timer(&timer); */ |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 229 | printk(KERN_CRIT PFX |
| 230 | "device file closed unexpectedly. Will not stop the WDT!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | clear_bit(0, &wdt_is_open); |
| 233 | wdt_expect_close = 0; |
| 234 | return 0; |
| 235 | } |
| 236 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 237 | static long fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | void __user *argp = (void __user *)arg; |
| 240 | int __user *p = argp; |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 241 | static struct watchdog_info ident = { |
| 242 | .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
| 243 | | WDIOF_MAGICCLOSE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | .firmware_version = 1, |
| 245 | .identity = "ALiM7101", |
| 246 | }; |
| 247 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 248 | switch (cmd) { |
| 249 | case WDIOC_GETSUPPORT: |
| 250 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; |
| 251 | case WDIOC_GETSTATUS: |
| 252 | case WDIOC_GETBOOTSTATUS: |
| 253 | return put_user(0, p); |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 254 | case WDIOC_SETOPTIONS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 256 | int new_options, retval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 258 | if (get_user(new_options, p)) |
| 259 | return -EFAULT; |
| 260 | if (new_options & WDIOS_DISABLECARD) { |
| 261 | wdt_turnoff(); |
| 262 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 264 | if (new_options & WDIOS_ENABLECARD) { |
| 265 | wdt_startup(); |
| 266 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 268 | return retval; |
| 269 | } |
Wim Van Sebroeck | 0c06090c | 2008-07-18 11:41:17 +0000 | [diff] [blame] | 270 | case WDIOC_KEEPALIVE: |
| 271 | wdt_keepalive(); |
| 272 | return 0; |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 273 | case WDIOC_SETTIMEOUT: |
| 274 | { |
| 275 | int new_timeout; |
| 276 | |
| 277 | if (get_user(new_timeout, p)) |
| 278 | return -EFAULT; |
| 279 | /* arbitrary upper limit */ |
| 280 | if (new_timeout < 1 || new_timeout > 3600) |
| 281 | return -EINVAL; |
| 282 | timeout = new_timeout; |
| 283 | wdt_keepalive(); |
| 284 | /* Fall through */ |
| 285 | } |
| 286 | case WDIOC_GETTIMEOUT: |
| 287 | return put_user(timeout, p); |
| 288 | default: |
| 289 | return -ENOTTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 293 | static const struct file_operations wdt_fops = { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 294 | .owner = THIS_MODULE, |
| 295 | .llseek = no_llseek, |
| 296 | .write = fop_write, |
| 297 | .open = fop_open, |
| 298 | .release = fop_close, |
| 299 | .unlocked_ioctl = fop_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | static struct miscdevice wdt_miscdev = { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 303 | .minor = WATCHDOG_MINOR, |
| 304 | .name = "watchdog", |
| 305 | .fops = &wdt_fops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | /* |
| 309 | * Notifier for system down |
| 310 | */ |
| 311 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 312 | static int wdt_notify_sys(struct notifier_block *this, |
| 313 | unsigned long code, void *unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 315 | if (code == SYS_DOWN || code == SYS_HALT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | wdt_turnoff(); |
| 317 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 318 | if (code == SYS_RESTART) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /* |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 320 | * Cobalt devices have no way of rebooting themselves other |
| 321 | * than getting the watchdog to pull reset, so we restart the |
| 322 | * watchdog on reboot with no heartbeat |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | */ |
| 324 | wdt_change(WDT_ENABLE); |
Wim Van Sebroeck | a77dba7 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 325 | printk(KERN_INFO PFX "Watchdog timer is now enabled " |
| 326 | "with no heartbeat - should reboot in ~1 second.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | return NOTIFY_DONE; |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * The WDT needs to learn about soft shutdowns in order to |
| 333 | * turn the timebomb registers off. |
| 334 | */ |
| 335 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 336 | static struct notifier_block wdt_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | .notifier_call = wdt_notify_sys, |
| 338 | }; |
| 339 | |
| 340 | static void __exit alim7101_wdt_unload(void) |
| 341 | { |
| 342 | wdt_turnoff(); |
| 343 | /* Deregister */ |
| 344 | misc_deregister(&wdt_miscdev); |
| 345 | unregister_reboot_notifier(&wdt_notifier); |
Jiri Slaby | 02be2ee | 2006-07-18 18:29:00 +0159 | [diff] [blame] | 346 | pci_dev_put(alim7101_pmu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | static int __init alim7101_wdt_init(void) |
| 350 | { |
| 351 | int rc = -EBUSY; |
| 352 | struct pci_dev *ali1543_south; |
| 353 | char tmp; |
| 354 | |
| 355 | printk(KERN_INFO PFX "Steve Hill <steve@navaho.co.uk>.\n"); |
Jiri Slaby | 02be2ee | 2006-07-18 18:29:00 +0159 | [diff] [blame] | 356 | alim7101_pmu = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, |
| 357 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (!alim7101_pmu) { |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 359 | printk(KERN_INFO PFX |
| 360 | "ALi M7101 PMU not present - WDT not set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | return -EBUSY; |
| 362 | } |
| 363 | |
| 364 | /* Set the WDT in the PMU to 1 second */ |
| 365 | pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, 0x02); |
| 366 | |
Jiri Slaby | 02be2ee | 2006-07-18 18:29:00 +0159 | [diff] [blame] | 367 | ali1543_south = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, |
| 368 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | if (!ali1543_south) { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 370 | printk(KERN_INFO PFX |
| 371 | "ALi 1543 South-Bridge not present - WDT not set\n"); |
Jiri Slaby | 02be2ee | 2006-07-18 18:29:00 +0159 | [diff] [blame] | 372 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | pci_read_config_byte(ali1543_south, 0x5e, &tmp); |
Jiri Slaby | 02be2ee | 2006-07-18 18:29:00 +0159 | [diff] [blame] | 375 | pci_dev_put(ali1543_south); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | if ((tmp & 0x1e) == 0x00) { |
| 377 | if (!use_gpio) { |
Wim Van Sebroeck | a77dba7 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 378 | printk(KERN_INFO PFX |
| 379 | "Detected old alim7101 revision 'a1d'. " |
| 380 | "If this is a cobalt board, set the 'use_gpio' " |
| 381 | "module parameter.\n"); |
Jiri Slaby | 02be2ee | 2006-07-18 18:29:00 +0159 | [diff] [blame] | 382 | goto err_out; |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | nowayout = 1; |
| 385 | } else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) { |
Wim Van Sebroeck | a77dba7 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 386 | printk(KERN_INFO PFX |
| 387 | "ALi 1543 South-Bridge does not have the correct " |
| 388 | "revision number (???1001?) - WDT not set\n"); |
Jiri Slaby | 02be2ee | 2006-07-18 18:29:00 +0159 | [diff] [blame] | 389 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 392 | if (timeout < 1 || timeout > 3600) { |
| 393 | /* arbitrary upper limit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | timeout = WATCHDOG_TIMEOUT; |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 395 | printk(KERN_INFO PFX |
| 396 | "timeout value must be 1 <= x <= 3600, using %d\n", |
| 397 | timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | rc = register_reboot_notifier(&wdt_notifier); |
| 401 | if (rc) { |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 402 | printk(KERN_ERR PFX |
| 403 | "cannot register reboot notifier (err=%d)\n", rc); |
Wim Van Sebroeck | c6cb13a | 2007-12-26 20:32:51 +0000 | [diff] [blame] | 404 | goto err_out; |
| 405 | } |
| 406 | |
| 407 | rc = misc_register(&wdt_miscdev); |
| 408 | if (rc) { |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 409 | printk(KERN_ERR PFX |
| 410 | "cannot register miscdev on minor=%d (err=%d)\n", |
Wim Van Sebroeck | c6cb13a | 2007-12-26 20:32:51 +0000 | [diff] [blame] | 411 | wdt_miscdev.minor, rc); |
| 412 | goto err_out_reboot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Alan Cox | 173d95b | 2008-05-19 14:04:57 +0100 | [diff] [blame] | 415 | if (nowayout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | __module_get(THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Wim Van Sebroeck | a77dba7 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 418 | printk(KERN_INFO PFX "WDT driver for ALi M7101 initialised. " |
| 419 | "timeout=%d sec (nowayout=%d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | timeout, nowayout); |
| 421 | return 0; |
| 422 | |
Wim Van Sebroeck | c6cb13a | 2007-12-26 20:32:51 +0000 | [diff] [blame] | 423 | err_out_reboot: |
| 424 | unregister_reboot_notifier(&wdt_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | err_out: |
Jiri Slaby | 02be2ee | 2006-07-18 18:29:00 +0159 | [diff] [blame] | 426 | pci_dev_put(alim7101_pmu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return rc; |
| 428 | } |
| 429 | |
| 430 | module_init(alim7101_wdt_init); |
| 431 | module_exit(alim7101_wdt_unload); |
| 432 | |
Ben Collins | 5cacb9f | 2006-10-18 08:24:30 -0400 | [diff] [blame] | 433 | static struct pci_device_id alim7101_pci_tbl[] __devinitdata = { |
Jiri Slaby | 29d73aa | 2007-02-12 00:51:48 -0800 | [diff] [blame] | 434 | { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533) }, |
| 435 | { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, |
Ben Collins | 5cacb9f | 2006-10-18 08:24:30 -0400 | [diff] [blame] | 436 | { } |
| 437 | }; |
| 438 | |
| 439 | MODULE_DEVICE_TABLE(pci, alim7101_pci_tbl); |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | MODULE_AUTHOR("Steve Hill"); |
| 442 | MODULE_DESCRIPTION("ALi M7101 PMU Computer Watchdog Timer driver"); |
| 443 | MODULE_LICENSE("GPL"); |
| 444 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |