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 <vlad@storewiz.com> |
8 | * added support for W83627THF. | |
1da177e4 | 9 | * |
d36b6910 | 10 | * (c) Copyright 2003,2007 Pádraig Brady <P@draigBrady.com> |
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 <marekm@linux.org.pl> | |
16 | * | |
29fa0586 AC |
17 | * (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>, |
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 <alan@lxorguk.ukuu.org.uk> |
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 | ||
46a3949d | 73 | static void w83627hf_select_wd_register(void) |
1da177e4 LT |
74 | { |
75 | outb_p(0x87, WDT_EFER); /* Enter extended function mode */ | |
76 | outb_p(0x87, WDT_EFER); /* Again according to manual */ | |
1da177e4 LT |
77 | outb_p(0x07, WDT_EFER); /* point to logical device number reg */ |
78 | outb_p(0x08, WDT_EFDR); /* select logical device 8 (GPIO2) */ | |
1da177e4 LT |
79 | } |
80 | ||
46a3949d | 81 | static void w83627hf_unselect_wd_register(void) |
1da177e4 LT |
82 | { |
83 | outb_p(0xAA, WDT_EFER); /* Leave extended function mode */ | |
84 | } | |
85 | ||
86 | /* tyan motherboards seem to set F5 to 0x4C ? | |
87 | * So explicitly init to appropriate value. */ | |
46a3949d | 88 | |
30a83695 | 89 | static void w83627hf_init(struct watchdog_device *wdog) |
1da177e4 LT |
90 | { |
91 | unsigned char t; | |
92 | ||
93 | w83627hf_select_wd_register(); | |
94 | ||
8f526389 GR |
95 | outb(0x20, WDT_EFER); /* check chip version */ |
96 | t = inb(WDT_EFDR); | |
97 | if (t == 0x82) { /* W83627THF */ | |
98 | outb_p(0x2b, WDT_EFER); /* select GPIO3 */ | |
99 | t = ((inb_p(WDT_EFDR) & 0xf7) | 0x04); /* select WDT0 */ | |
100 | outb_p(0x2b, WDT_EFER); | |
101 | outb_p(t, WDT_EFDR); /* set GPIO3 to WDT0 */ | |
102 | } else if (t == 0x88 || t == 0xa0) { /* W83627EHF / W83627DHG */ | |
103 | outb_p(0x2d, WDT_EFER); /* select GPIO5 */ | |
104 | t = inb_p(WDT_EFDR) & ~0x01; /* PIN77 -> WDT0# */ | |
105 | outb_p(0x2d, WDT_EFER); | |
106 | outb_p(t, WDT_EFDR); /* set GPIO5 to WDT0 */ | |
107 | } | |
108 | ||
109 | outb_p(0x30, WDT_EFER); /* select CR30 */ | |
ac461103 GR |
110 | t = inb(WDT_EFDR); |
111 | if (!(t & 0x01)) | |
112 | outb_p(t | 0x01, WDT_EFDR); /* set bit 0 to activate GPIO2 */ | |
8f526389 | 113 | |
93642ecd | 114 | outb_p(0xF6, WDT_EFER); /* Select CRF6 */ |
46a3949d | 115 | t = inb_p(WDT_EFDR); /* read CRF6 */ |
93642ecd | 116 | if (t != 0) { |
27c766aa | 117 | pr_info("Watchdog already running. Resetting timeout to %d sec\n", |
30a83695 GR |
118 | wdog->timeout); |
119 | outb_p(wdog->timeout, WDT_EFDR); /* Write back to CRF6 */ | |
93642ecd | 120 | } |