]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
0e94f2ee VD |
2 | * w83627hf/thf WDT driver |
3 | * | |
30a83695 GR |
4 | * (c) Copyright 2013 Guenter Roeck |
5 | * converted to watchdog infrastructure | |
6 | * | |
0e94f2ee VD |
7 | * (c) Copyright 2007 Vlad Drukker <[email protected]> |
8 | * added support for W83627THF. | |
1da177e4 | 9 | * |
d36b6910 | 10 | * (c) Copyright 2003,2007 Pádraig Brady <[email protected]> |
1da177e4 LT |
11 | * |
12 | * Based on advantechwdt.c which is based on wdt.c. | |
13 | * Original copyright messages: | |
14 | * | |
15 | * (c) Copyright 2000-2001 Marek Michalkiewicz <[email protected]> | |
16 | * | |
29fa0586 AC |
17 | * (c) Copyright 1996 Alan Cox <[email protected]>, |
18 | * All Rights Reserved. | |
1da177e4 LT |
19 | * |
20 | * This program is free software; you can redistribute it and/or | |
21 | * modify it under the terms of the GNU General Public License | |
22 | * as published by the Free Software Foundation; either version | |
23 | * 2 of the License, or (at your option) any later version. | |
24 | * | |
25 | * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide | |
26 | * warranty for any of this software. This material is provided | |
27 | * "AS-IS" and at no charge. | |
28 | * | |
29fa0586 | 29 | * (c) Copyright 1995 Alan Cox <[email protected]> |
1da177e4 LT |
30 | */ |
31 | ||
27c766aa JP |
32 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
33 | ||
1da177e4 LT |
34 | #include <linux/module.h> |
35 | #include <linux/moduleparam.h> | |
36 | #include <linux/types.h> | |
1da177e4 | 37 | #include <linux/watchdog.h> |
1da177e4 LT |
38 | #include <linux/ioport.h> |
39 | #include <linux/notifier.h> | |
40 | #include <linux/reboot.h> | |
41 | #include <linux/init.h> | |
46a3949d | 42 | #include <linux/io.h> |
1da177e4 | 43 | |
9c67bea4 | 44 | #define WATCHDOG_NAME "w83627hf/thf/hg/dhg WDT" |
1da177e4 LT |
45 | #define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */ |
46 | ||
1da177e4 LT |
47 | /* You must set this - there is no sane way to probe for this board. */ |
48 | static int wdt_io = 0x2E; | |
49 | module_param(wdt_io, int, 0); | |
0e94f2ee | 50 | MODULE_PARM_DESC(wdt_io, "w83627hf/thf WDT io port (default 0x2E)"); |
1da177e4 | 51 | |
30a83695 | 52 | static int timeout; /* in seconds */ |
1da177e4 | 53 | module_param(timeout, int, 0); |
46a3949d AC |
54 | MODULE_PARM_DESC(timeout, |
55 | "Watchdog timeout in seconds. 1 <= timeout <= 255, default=" | |
56 | __MODULE_STRING(WATCHDOG_TIMEOUT) "."); | |
1da177e4 | 57 | |
86a1e189 WVS |
58 | static bool nowayout = WATCHDOG_NOWAYOUT; |
59 | module_param(nowayout, bool, 0); | |
46a3949d AC |
60 | MODULE_PARM_DESC(nowayout, |
61 | "Watchdog cannot be stopped once started (default=" | |
62 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | |
1da177e4 LT |
63 | |
64 | /* | |
65 | * Kernel methods. | |
66 | */ | |
67 | ||
68 | #define WDT_EFER (wdt_io+0) /* Extended Function Enable Registers */ | |
46a3949d AC |
69 | #define WDT_EFIR (wdt_io+0) /* Extended Function Index Register |
70 | (same as EFER) */ | |
1da177e4 LT |
71 | #define WDT_EFDR (WDT_EFIR+1) /* Extended Function Data Register */ |
72 | ||
ef0c1a6b GR |
73 | #define W83627HF_LD_WDT 0x08 |
74 | ||
75 | static void superio_outb(int reg, int val) | |
76 | { | |
77 | outb(reg, WDT_EFER); | |
78 | outb(val, WDT_EFDR); | |
79 | } | |
80 | ||
81 | static inline int superio_inb(int reg) | |
82 | { | |
83 | outb(reg, WDT_EFER); | |
84 | return inb(WDT_EFDR); | |
85 | } | |
86 | ||
87 | static int superio_enter(void) | |
1da177e4 | 88 | { |
ef0c1a6b GR |
89 | if (!request_muxed_region(wdt_io, 2, WATCHDOG_NAME)) |
90 | return -EBUSY; | |
91 | ||
1da177e4 LT |
92 | outb_p(0x87, WDT_EFER); /* Enter extended function mode */ |
93 | outb_p(0x87, WDT_EFER); /* Again according to manual */ | |
ef0c1a6b GR |
94 | |
95 | return 0; | |
1da177e4 LT |
96 | } |
97 | ||
ef0c1a6b GR |
98 | static void superio_select(int ld) |
99 | { | |
100 | superio_outb(0x07, ld); | |
101 | } | |
102 | ||
103 | static void superio_exit(void) | |
1da177e4 LT |
104 | { |
105 | outb_p(0xAA, WDT_EFER); /* Leave extended function mode */ | |
ef0c1a6b | 106 | release_region(wdt_io, 2); |
1da177e4 LT |
107 | } |
108 | ||
109 | /* tyan motherboards seem to set F5 to 0x4C ? | |
110 | * So explicitly init to appropriate value. */ | |
46a3949d | 111 | |
ef0c1a6b | 112 | static int w83627hf_init(struct watchdog_device *wdog) |
1da177e4 | 113 | { |
ef0c1a6b | 114 | int ret; |
1da177e4 LT |
115 | unsigned char t; |
116 | ||
ef0c1a6b GR |
117 | ret = superio_enter(); |
118 | if (ret) | |
119 | return ret; | |
1da177e4 | 120 | |
ef0c1a6b GR |
121 | superio_select(W83627HF_LD_WDT); |
122 | t = superio_inb(0x20); /* check chip version */ | |
8f526389 | 123 | if (t == 0x82) { /* W83627THF */ |
ef0c1a6b GR |
124 | t = (superio_inb(0x2b) & 0xf7); |
125 | superio_outb(0x2b, t | 0x04); /* set GPIO3 to WDT0 */ | |
8f526389 | 126 | } else if (t == 0x88 || t == 0xa0) { /* W83627EHF / W83627DHG */ |
ef0c1a6b GR |
127 | t = superio_inb(0x2d); |
128 | superio_outb(0x2d, t & ~0x01); /* set GPIO5 to WDT0 */ | |
8f526389 GR |
129 | } |
130 | ||
ef0c1a6b GR |
131 | /* set CR30 bit 0 to activate GPIO2 */ |
132 | t = superio_inb(0x30); | |
ac461103 | 133 | if (!(t & 0x01)) |
ef0c1a6b | 134 | superio_outb(0x30, t | 0x01); |
8f526389 | 135 | |
ef0c1a6b | 136 | t = superio_inb(0xF6); |
93642ecd | 137 | if (t != 0) { |
27c766aa | 138 | pr_info("Watchdog already running. Resetting timeout to %d sec\n", |
30a83695 | 139 | wdog->timeout); |
ef0c1a6b | 140 | superio_outb(0xF6, wdog->timeout); |
93642ecd | 141 | } |