Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Watchdog Timer Driver |
| 3 | * for ITE IT87xx Environment Control - Low Pin Count Input / Output |
| 4 | * |
| 5 | * (c) Copyright 2007 Oliver Schuster <olivers137@aol.com> |
| 6 | * |
| 7 | * Based on softdog.c by Alan Cox, |
| 8 | * 83977f_wdt.c by Jose Goncalves, |
| 9 | * it87.c by Chris Gauthron, Jean Delvare |
| 10 | * |
| 11 | * Data-sheets: Publicly available at the ITE website |
| 12 | * http://www.ite.com.tw/ |
| 13 | * |
| 14 | * Support of the watchdog timers, which are available on |
Maciej S. Szmigiero | 0671612 | 2016-12-15 23:52:36 +0100 | [diff] [blame] | 15 | * IT8620, IT8702, IT8712, IT8716, IT8718, IT8720, IT8721, IT8726, |
Paolo Teti | f83918f | 2014-10-19 21:39:33 +0200 | [diff] [blame] | 16 | * IT8728 and IT8783. |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 17 | * |
| 18 | * This program is free software; you can redistribute it and/or |
| 19 | * modify it under the terms of the GNU General Public License |
| 20 | * as published by the Free Software Foundation; either version |
| 21 | * 2 of the License, or (at your option) any later version. |
| 22 | * |
| 23 | * This program is distributed in the hope that it will be useful, |
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | * GNU General Public License for more details. |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 27 | */ |
| 28 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/moduleparam.h> |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/kernel.h> |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 35 | #include <linux/init.h> |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 36 | #include <linux/watchdog.h> |
| 37 | #include <linux/notifier.h> |
| 38 | #include <linux/reboot.h> |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 39 | #include <linux/io.h> |
| 40 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 41 | #define WATCHDOG_NAME "IT87 WDT" |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 42 | |
| 43 | /* Defaults for Module Parameter */ |
Wim Van Sebroeck | 5f3b275 | 2011-02-23 20:04:38 +0000 | [diff] [blame] | 44 | #define DEFAULT_TIMEOUT 60 |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 45 | #define DEFAULT_TESTMODE 0 |
| 46 | #define DEFAULT_NOWAYOUT WATCHDOG_NOWAYOUT |
| 47 | |
| 48 | /* IO Ports */ |
| 49 | #define REG 0x2e |
| 50 | #define VAL 0x2f |
| 51 | |
| 52 | /* Logical device Numbers LDN */ |
| 53 | #define GPIO 0x07 |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 54 | |
| 55 | /* Configuration Registers and Functions */ |
| 56 | #define LDNREG 0x07 |
| 57 | #define CHIPID 0x20 |
Wim Van Sebroeck | 5f3b275 | 2011-02-23 20:04:38 +0000 | [diff] [blame] | 58 | #define CHIPREV 0x22 |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 59 | |
| 60 | /* Chip Id numbers */ |
| 61 | #define NO_DEV_ID 0xffff |
Maciej S. Szmigiero | 0671612 | 2016-12-15 23:52:36 +0100 | [diff] [blame] | 62 | #define IT8620_ID 0x8620 |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 63 | #define IT8702_ID 0x8702 |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 64 | #define IT8705_ID 0x8705 |
| 65 | #define IT8712_ID 0x8712 |
| 66 | #define IT8716_ID 0x8716 |
| 67 | #define IT8718_ID 0x8718 |
Ondrej Zajicek | ee3e965 | 2010-09-14 02:47:28 +0200 | [diff] [blame] | 68 | #define IT8720_ID 0x8720 |
Huaro Tomita | 4bc3027 | 2011-01-21 07:37:51 +0900 | [diff] [blame] | 69 | #define IT8721_ID 0x8721 |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 70 | #define IT8726_ID 0x8726 /* the data sheet suggest wrongly 0x8716 */ |
Diego Elio Pettenò | 198ca01 | 2012-03-14 20:49:04 +0100 | [diff] [blame] | 71 | #define IT8728_ID 0x8728 |
Paolo Teti | f83918f | 2014-10-19 21:39:33 +0200 | [diff] [blame] | 72 | #define IT8783_ID 0x8783 |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 73 | |
| 74 | /* GPIO Configuration Registers LDN=0x07 */ |
Wim Van Sebroeck | 5f3b275 | 2011-02-23 20:04:38 +0000 | [diff] [blame] | 75 | #define WDTCTRL 0x71 |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 76 | #define WDTCFG 0x72 |
| 77 | #define WDTVALLSB 0x73 |
| 78 | #define WDTVALMSB 0x74 |
| 79 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 80 | /* GPIO Bits WDTCFG */ |
| 81 | #define WDT_TOV1 0x80 |
| 82 | #define WDT_KRST 0x40 |
| 83 | #define WDT_TOVE 0x20 |
Huaro Tomita | 4bc3027 | 2011-01-21 07:37:51 +0900 | [diff] [blame] | 84 | #define WDT_PWROK 0x10 /* not in it8721 */ |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 85 | #define WDT_INT_MASK 0x0f |
| 86 | |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 87 | static unsigned int max_units, chip_type; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 88 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 89 | static unsigned int timeout = DEFAULT_TIMEOUT; |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 90 | static int testmode = DEFAULT_TESTMODE; |
| 91 | static bool nowayout = DEFAULT_NOWAYOUT; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 92 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 93 | module_param(timeout, int, 0); |
| 94 | MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds, default=" |
| 95 | __MODULE_STRING(DEFAULT_TIMEOUT)); |
| 96 | module_param(testmode, int, 0); |
| 97 | MODULE_PARM_DESC(testmode, "Watchdog test mode (1 = no reboot), default=" |
| 98 | __MODULE_STRING(DEFAULT_TESTMODE)); |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 99 | module_param(nowayout, bool, 0); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 100 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started, default=" |
| 101 | __MODULE_STRING(WATCHDOG_NOWAYOUT)); |
| 102 | |
| 103 | /* Superio Chip */ |
| 104 | |
Nat Gurumoorthy | a134b82 | 2011-05-09 11:45:07 -0700 | [diff] [blame] | 105 | static inline int superio_enter(void) |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 106 | { |
Nat Gurumoorthy | a134b82 | 2011-05-09 11:45:07 -0700 | [diff] [blame] | 107 | /* |
| 108 | * Try to reserve REG and REG + 1 for exclusive access. |
| 109 | */ |
| 110 | if (!request_muxed_region(REG, 2, WATCHDOG_NAME)) |
| 111 | return -EBUSY; |
| 112 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 113 | outb(0x87, REG); |
| 114 | outb(0x01, REG); |
| 115 | outb(0x55, REG); |
| 116 | outb(0x55, REG); |
Nat Gurumoorthy | a134b82 | 2011-05-09 11:45:07 -0700 | [diff] [blame] | 117 | return 0; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static inline void superio_exit(void) |
| 121 | { |
| 122 | outb(0x02, REG); |
| 123 | outb(0x02, VAL); |
Nat Gurumoorthy | a134b82 | 2011-05-09 11:45:07 -0700 | [diff] [blame] | 124 | release_region(REG, 2); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static inline void superio_select(int ldn) |
| 128 | { |
| 129 | outb(LDNREG, REG); |
| 130 | outb(ldn, VAL); |
| 131 | } |
| 132 | |
| 133 | static inline int superio_inb(int reg) |
| 134 | { |
| 135 | outb(reg, REG); |
| 136 | return inb(VAL); |
| 137 | } |
| 138 | |
| 139 | static inline void superio_outb(int val, int reg) |
| 140 | { |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 141 | outb(reg, REG); |
| 142 | outb(val, VAL); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static inline int superio_inw(int reg) |
| 146 | { |
| 147 | int val; |
| 148 | outb(reg++, REG); |
| 149 | val = inb(VAL) << 8; |
| 150 | outb(reg, REG); |
| 151 | val |= inb(VAL); |
| 152 | return val; |
| 153 | } |
| 154 | |
| 155 | static inline void superio_outw(int val, int reg) |
| 156 | { |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 157 | outb(reg++, REG); |
| 158 | outb(val >> 8, VAL); |
| 159 | outb(reg, REG); |
| 160 | outb(val, VAL); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 163 | /* Internal function, should be called after superio_select(GPIO) */ |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 164 | static void _wdt_update_timeout(unsigned int t) |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 165 | { |
Huaro Tomita | 4bc3027 | 2011-01-21 07:37:51 +0900 | [diff] [blame] | 166 | unsigned char cfg = WDT_KRST; |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 167 | |
| 168 | if (testmode) |
| 169 | cfg = 0; |
| 170 | |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 171 | if (t <= max_units) |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 172 | cfg |= WDT_TOV1; |
| 173 | else |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 174 | t /= 60; |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 175 | |
Huaro Tomita | 4bc3027 | 2011-01-21 07:37:51 +0900 | [diff] [blame] | 176 | if (chip_type != IT8721_ID) |
| 177 | cfg |= WDT_PWROK; |
| 178 | |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 179 | superio_outb(cfg, WDTCFG); |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 180 | superio_outb(t, WDTVALLSB); |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 181 | if (max_units > 255) |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 182 | superio_outb(t >> 8, WDTVALMSB); |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 185 | static int wdt_update_timeout(unsigned int t) |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 186 | { |
| 187 | int ret; |
| 188 | |
| 189 | ret = superio_enter(); |
| 190 | if (ret) |
| 191 | return ret; |
| 192 | |
| 193 | superio_select(GPIO); |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 194 | _wdt_update_timeout(t); |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 195 | superio_exit(); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 200 | static int wdt_round_time(int t) |
| 201 | { |
| 202 | t += 59; |
| 203 | t -= t % 60; |
| 204 | return t; |
| 205 | } |
| 206 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 207 | /* watchdog timer handling */ |
| 208 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 209 | static int wdt_start(struct watchdog_device *wdd) |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 210 | { |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 211 | return wdt_update_timeout(wdd->timeout); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 212 | } |
| 213 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 214 | static int wdt_stop(struct watchdog_device *wdd) |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 215 | { |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 216 | return wdt_update_timeout(0); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
| 220 | * wdt_set_timeout - set a new timeout value with watchdog ioctl |
| 221 | * @t: timeout value in seconds |
| 222 | * |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 223 | * The hardware device has a 8 or 16 bit watchdog timer (depends on |
| 224 | * chip version) that can be configured to count seconds or minutes. |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 225 | * |
| 226 | * Used within WDIOC_SETTIMEOUT watchdog device ioctl. |
| 227 | */ |
| 228 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 229 | static int wdt_set_timeout(struct watchdog_device *wdd, unsigned int t) |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 230 | { |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 231 | int ret = 0; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 232 | |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 233 | if (t > max_units) |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 234 | t = wdt_round_time(t); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 235 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 236 | wdd->timeout = t; |
Nat Gurumoorthy | a134b82 | 2011-05-09 11:45:07 -0700 | [diff] [blame] | 237 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 238 | if (watchdog_hw_running(wdd)) |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 239 | ret = wdt_update_timeout(t); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 240 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 241 | return ret; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Wim Van Sebroeck | 42747d7 | 2009-12-26 18:55:22 +0000 | [diff] [blame] | 244 | static const struct watchdog_info ident = { |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 245 | .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING, |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 246 | .firmware_version = 1, |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 247 | .identity = WATCHDOG_NAME, |
| 248 | }; |
| 249 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 250 | static struct watchdog_ops wdt_ops = { |
| 251 | .owner = THIS_MODULE, |
| 252 | .start = wdt_start, |
| 253 | .stop = wdt_stop, |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 254 | .set_timeout = wdt_set_timeout, |
| 255 | }; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 256 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 257 | static struct watchdog_device wdt_dev = { |
| 258 | .info = &ident, |
| 259 | .ops = &wdt_ops, |
| 260 | .min_timeout = 1, |
| 261 | }; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 262 | |
| 263 | static int wdt_notify_sys(struct notifier_block *this, unsigned long code, |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 264 | void *unused) |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 265 | { |
| 266 | if (code == SYS_DOWN || code == SYS_HALT) |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 267 | wdt_stop(&wdt_dev); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 268 | return NOTIFY_DONE; |
| 269 | } |
| 270 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 271 | static struct notifier_block wdt_notifier = { |
| 272 | .notifier_call = wdt_notify_sys, |
| 273 | }; |
| 274 | |
| 275 | static int __init it87_wdt_init(void) |
| 276 | { |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 277 | u8 chip_rev; |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 278 | int rc; |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 279 | |
Nat Gurumoorthy | a134b82 | 2011-05-09 11:45:07 -0700 | [diff] [blame] | 280 | rc = superio_enter(); |
| 281 | if (rc) |
| 282 | return rc; |
| 283 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 284 | chip_type = superio_inw(CHIPID); |
| 285 | chip_rev = superio_inb(CHIPREV) & 0x0f; |
| 286 | superio_exit(); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 287 | |
| 288 | switch (chip_type) { |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 289 | case IT8702_ID: |
| 290 | max_units = 255; |
| 291 | break; |
| 292 | case IT8712_ID: |
| 293 | max_units = (chip_rev < 8) ? 255 : 65535; |
| 294 | break; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 295 | case IT8716_ID: |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 296 | case IT8726_ID: |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 297 | max_units = 65535; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 298 | break; |
Maciej S. Szmigiero | 0671612 | 2016-12-15 23:52:36 +0100 | [diff] [blame] | 299 | case IT8620_ID: |
Ondrej Zajicek | ee3e965 | 2010-09-14 02:47:28 +0200 | [diff] [blame] | 300 | case IT8718_ID: |
| 301 | case IT8720_ID: |
Huaro Tomita | 4bc3027 | 2011-01-21 07:37:51 +0900 | [diff] [blame] | 302 | case IT8721_ID: |
Diego Elio Pettenò | 198ca01 | 2012-03-14 20:49:04 +0100 | [diff] [blame] | 303 | case IT8728_ID: |
Paolo Teti | f83918f | 2014-10-19 21:39:33 +0200 | [diff] [blame] | 304 | case IT8783_ID: |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 305 | max_units = 65535; |
Ondrej Zajicek | ee3e965 | 2010-09-14 02:47:28 +0200 | [diff] [blame] | 306 | break; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 307 | case IT8705_ID: |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 308 | pr_err("Unsupported Chip found, Chip %04x Revision %02x\n", |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 309 | chip_type, chip_rev); |
| 310 | return -ENODEV; |
| 311 | case NO_DEV_ID: |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 312 | pr_err("no device\n"); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 313 | return -ENODEV; |
| 314 | default: |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 315 | pr_err("Unknown Chip found, Chip %04x Revision %04x\n", |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 316 | chip_type, chip_rev); |
| 317 | return -ENODEV; |
| 318 | } |
| 319 | |
Nat Gurumoorthy | a134b82 | 2011-05-09 11:45:07 -0700 | [diff] [blame] | 320 | rc = superio_enter(); |
| 321 | if (rc) |
| 322 | return rc; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 323 | |
| 324 | superio_select(GPIO); |
| 325 | superio_outb(WDT_TOV1, WDTCFG); |
| 326 | superio_outb(0x00, WDTCTRL); |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 327 | superio_exit(); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 328 | |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 329 | if (timeout < 1 || timeout > max_units * 60) { |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 330 | timeout = DEFAULT_TIMEOUT; |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 331 | pr_warn("Timeout value out of range, use default %d sec\n", |
| 332 | DEFAULT_TIMEOUT); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Ondrej Zajicek | dfb0b8e | 2010-09-14 02:54:16 +0200 | [diff] [blame] | 335 | if (timeout > max_units) |
| 336 | timeout = wdt_round_time(timeout); |
| 337 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 338 | wdt_dev.timeout = timeout; |
| 339 | wdt_dev.max_timeout = max_units * 60; |
| 340 | |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 341 | rc = register_reboot_notifier(&wdt_notifier); |
| 342 | if (rc) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 343 | pr_err("Cannot register reboot notifier (err=%d)\n", rc); |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 344 | return rc; |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 345 | } |
| 346 | |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 347 | rc = watchdog_register_device(&wdt_dev); |
| 348 | if (rc) { |
| 349 | pr_err("Cannot register watchdog device (err=%d)\n", rc); |
| 350 | goto err_out_reboot; |
| 351 | } |
| 352 | |
Guenter Roeck | 893dc8b | 2017-06-10 21:04:34 -0700 | [diff] [blame^] | 353 | pr_info("Chip IT%04x revision %d initialized. timeout=%d sec (nowayout=%d testmode=%d)\n", |
| 354 | chip_type, chip_rev, timeout, nowayout, testmode); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 355 | |
| 356 | return 0; |
| 357 | |
| 358 | err_out_reboot: |
| 359 | unregister_reboot_notifier(&wdt_notifier); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 360 | return rc; |
| 361 | } |
| 362 | |
| 363 | static void __exit it87_wdt_exit(void) |
| 364 | { |
Guenter Roeck | 1d7b803 | 2017-06-10 21:04:33 -0700 | [diff] [blame] | 365 | watchdog_unregister_device(&wdt_dev); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 366 | unregister_reboot_notifier(&wdt_notifier); |
Oliver Schuster | e1fee94 | 2008-03-05 16:48:45 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | module_init(it87_wdt_init); |
| 370 | module_exit(it87_wdt_exit); |
| 371 | |
| 372 | MODULE_AUTHOR("Oliver Schuster"); |
| 373 | MODULE_DESCRIPTION("Hardware Watchdog Device Driver for IT87xx EC-LPC I/O"); |
| 374 | MODULE_LICENSE("GPL"); |