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