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