Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 1 | /* |
Wim Van Sebroeck | cb711a1 | 2009-11-15 13:44:54 +0000 | [diff] [blame] | 2 | * intel TCO Watchdog Driver |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 3 | * |
Wim Van Sebroeck | d38bd47 | 2010-12-31 14:10:45 +0000 | [diff] [blame^] | 4 | * (c) Copyright 2006-2010 Wim Van Sebroeck <wim@iguana.be>. |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor |
| 12 | * provide warranty for any of this software. This material is |
| 13 | * provided "AS-IS" and at no charge. |
| 14 | * |
| 15 | * The TCO watchdog is implemented in the following I/O controller hubs: |
| 16 | * (See the intel documentation on http://developer.intel.com.) |
Wim Van Sebroeck | cb711a1 | 2009-11-15 13:44:54 +0000 | [diff] [blame] | 17 | * document number 290655-003, 290677-014: 82801AA (ICH), 82801AB (ICHO) |
| 18 | * document number 290687-002, 298242-027: 82801BA (ICH2) |
| 19 | * document number 290733-003, 290739-013: 82801CA (ICH3-S) |
| 20 | * document number 290716-001, 290718-007: 82801CAM (ICH3-M) |
| 21 | * document number 290744-001, 290745-025: 82801DB (ICH4) |
| 22 | * document number 252337-001, 252663-008: 82801DBM (ICH4-M) |
| 23 | * document number 273599-001, 273645-002: 82801E (C-ICH) |
| 24 | * document number 252516-001, 252517-028: 82801EB (ICH5), 82801ER (ICH5R) |
| 25 | * document number 300641-004, 300884-013: 6300ESB |
| 26 | * document number 301473-002, 301474-026: 82801F (ICH6) |
| 27 | * document number 313082-001, 313075-006: 631xESB, 632xESB |
| 28 | * document number 307013-003, 307014-024: 82801G (ICH7) |
Wim Van Sebroeck | d38bd47 | 2010-12-31 14:10:45 +0000 | [diff] [blame^] | 29 | * document number 322896-001, 322897-001: NM10 |
Wim Van Sebroeck | cb711a1 | 2009-11-15 13:44:54 +0000 | [diff] [blame] | 30 | * document number 313056-003, 313057-017: 82801H (ICH8) |
| 31 | * document number 316972-004, 316973-012: 82801I (ICH9) |
| 32 | * document number 319973-002, 319974-002: 82801J (ICH10) |
Seth Heasley | 3c9d8ec | 2010-01-14 20:58:05 +0000 | [diff] [blame] | 33 | * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH) |
Imre Kaloz | 4946f83 | 2009-12-07 20:42:26 +0100 | [diff] [blame] | 34 | * document number 320066-003, 320257-008: EP80597 (IICH) |
Seth Heasley | 3c9d8ec | 2010-01-14 20:58:05 +0000 | [diff] [blame] | 35 | * document number TBD : Cougar Point (CPT) |
Seth Heasley | c54fb81 | 2010-11-17 12:15:08 -0700 | [diff] [blame] | 36 | * document number TBD : Patsburg (PBG) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | /* |
| 40 | * Includes, defines, variables, module parameters, ... |
| 41 | */ |
| 42 | |
| 43 | /* Module and version information */ |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 44 | #define DRV_NAME "iTCO_wdt" |
Pádraig Brady | 7e6811d | 2010-04-19 13:38:25 +0100 | [diff] [blame] | 45 | #define DRV_VERSION "1.06" |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 46 | #define PFX DRV_NAME ": " |
| 47 | |
| 48 | /* Includes */ |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 49 | #include <linux/module.h> /* For module specific items */ |
| 50 | #include <linux/moduleparam.h> /* For new moduleparam's */ |
| 51 | #include <linux/types.h> /* For standard types (like size_t) */ |
| 52 | #include <linux/errno.h> /* For the -ENODEV/... values */ |
| 53 | #include <linux/kernel.h> /* For printk/panic/... */ |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 54 | #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV |
| 55 | (WATCHDOG_MINOR) */ |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 56 | #include <linux/watchdog.h> /* For the watchdog specific items */ |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 57 | #include <linux/init.h> /* For __init/__exit/... */ |
| 58 | #include <linux/fs.h> /* For file operations */ |
| 59 | #include <linux/platform_device.h> /* For platform_driver framework */ |
| 60 | #include <linux/pci.h> /* For pci functions */ |
| 61 | #include <linux/ioport.h> /* For io-port access */ |
| 62 | #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */ |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 63 | #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ |
| 64 | #include <linux/io.h> /* For inb/outb/... */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 65 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 66 | #include "iTCO_vendor.h" |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 67 | |
| 68 | /* TCO related info */ |
| 69 | enum iTCO_chipsets { |
| 70 | TCO_ICH = 0, /* ICH */ |
| 71 | TCO_ICH0, /* ICH0 */ |
| 72 | TCO_ICH2, /* ICH2 */ |
| 73 | TCO_ICH2M, /* ICH2-M */ |
| 74 | TCO_ICH3, /* ICH3-S */ |
| 75 | TCO_ICH3M, /* ICH3-M */ |
| 76 | TCO_ICH4, /* ICH4 */ |
| 77 | TCO_ICH4M, /* ICH4-M */ |
| 78 | TCO_CICH, /* C-ICH */ |
| 79 | TCO_ICH5, /* ICH5 & ICH5R */ |
| 80 | TCO_6300ESB, /* 6300ESB */ |
| 81 | TCO_ICH6, /* ICH6 & ICH6R */ |
| 82 | TCO_ICH6M, /* ICH6-M */ |
| 83 | TCO_ICH6W, /* ICH6W & ICH6RW */ |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 84 | TCO_631XESB, /* 631xESB/632xESB */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 85 | TCO_ICH7, /* ICH7 & ICH7R */ |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 86 | TCO_ICH7DH, /* ICH7DH */ |
| 87 | TCO_ICH7M, /* ICH7-M & ICH7-U */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 88 | TCO_ICH7MDH, /* ICH7-M DH */ |
Wim Van Sebroeck | d38bd47 | 2010-12-31 14:10:45 +0000 | [diff] [blame^] | 89 | TCO_NM10, /* NM10 */ |
Wim Van Sebroeck | a8edd74 | 2006-10-08 21:05:21 +0200 | [diff] [blame] | 90 | TCO_ICH8, /* ICH8 & ICH8R */ |
| 91 | TCO_ICH8DH, /* ICH8DH */ |
| 92 | TCO_ICH8DO, /* ICH8DO */ |
Wim Van Sebroeck | acf6035 | 2007-08-31 08:23:10 +0000 | [diff] [blame] | 93 | TCO_ICH8M, /* ICH8M */ |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 94 | TCO_ICH8ME, /* ICH8M-E */ |
Wim Van Sebroeck | 286201d | 2007-07-26 21:11:28 +0000 | [diff] [blame] | 95 | TCO_ICH9, /* ICH9 */ |
| 96 | TCO_ICH9R, /* ICH9R */ |
| 97 | TCO_ICH9DH, /* ICH9DH */ |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 98 | TCO_ICH9DO, /* ICH9DO */ |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 99 | TCO_ICH9M, /* ICH9M */ |
| 100 | TCO_ICH9ME, /* ICH9M-E */ |
| 101 | TCO_ICH10, /* ICH10 */ |
| 102 | TCO_ICH10R, /* ICH10R */ |
| 103 | TCO_ICH10D, /* ICH10D */ |
| 104 | TCO_ICH10DO, /* ICH10DO */ |
Seth Heasley | 79e8941 | 2009-11-11 02:24:01 +0100 | [diff] [blame] | 105 | TCO_PCH, /* PCH Desktop Full Featured */ |
| 106 | TCO_PCHM, /* PCH Mobile Full Featured */ |
Seth Heasley | 3c9d8ec | 2010-01-14 20:58:05 +0000 | [diff] [blame] | 107 | TCO_P55, /* P55 */ |
| 108 | TCO_PM55, /* PM55 */ |
| 109 | TCO_H55, /* H55 */ |
| 110 | TCO_QM57, /* QM57 */ |
| 111 | TCO_H57, /* H57 */ |
| 112 | TCO_HM55, /* HM55 */ |
| 113 | TCO_Q57, /* Q57 */ |
| 114 | TCO_HM57, /* HM57 */ |
Seth Heasley | 79e8941 | 2009-11-11 02:24:01 +0100 | [diff] [blame] | 115 | TCO_PCHMSFF, /* PCH Mobile SFF Full Featured */ |
Seth Heasley | 3c9d8ec | 2010-01-14 20:58:05 +0000 | [diff] [blame] | 116 | TCO_QS57, /* QS57 */ |
| 117 | TCO_3400, /* 3400 */ |
| 118 | TCO_3420, /* 3420 */ |
| 119 | TCO_3450, /* 3450 */ |
Imre Kaloz | 4946f83 | 2009-12-07 20:42:26 +0100 | [diff] [blame] | 120 | TCO_EP80579, /* EP80579 */ |
Seth Heasley | 4c7d849 | 2010-03-25 16:14:41 -0700 | [diff] [blame] | 121 | TCO_CPT1, /* Cougar Point */ |
| 122 | TCO_CPT2, /* Cougar Point Desktop */ |
| 123 | TCO_CPT3, /* Cougar Point Mobile */ |
| 124 | TCO_CPT4, /* Cougar Point */ |
| 125 | TCO_CPT5, /* Cougar Point */ |
| 126 | TCO_CPT6, /* Cougar Point */ |
| 127 | TCO_CPT7, /* Cougar Point */ |
| 128 | TCO_CPT8, /* Cougar Point */ |
| 129 | TCO_CPT9, /* Cougar Point */ |
| 130 | TCO_CPT10, /* Cougar Point */ |
| 131 | TCO_CPT11, /* Cougar Point */ |
| 132 | TCO_CPT12, /* Cougar Point */ |
| 133 | TCO_CPT13, /* Cougar Point */ |
| 134 | TCO_CPT14, /* Cougar Point */ |
| 135 | TCO_CPT15, /* Cougar Point */ |
| 136 | TCO_CPT16, /* Cougar Point */ |
| 137 | TCO_CPT17, /* Cougar Point */ |
| 138 | TCO_CPT18, /* Cougar Point */ |
| 139 | TCO_CPT19, /* Cougar Point */ |
| 140 | TCO_CPT20, /* Cougar Point */ |
| 141 | TCO_CPT21, /* Cougar Point */ |
| 142 | TCO_CPT22, /* Cougar Point */ |
| 143 | TCO_CPT23, /* Cougar Point */ |
| 144 | TCO_CPT24, /* Cougar Point */ |
| 145 | TCO_CPT25, /* Cougar Point */ |
| 146 | TCO_CPT26, /* Cougar Point */ |
| 147 | TCO_CPT27, /* Cougar Point */ |
| 148 | TCO_CPT28, /* Cougar Point */ |
| 149 | TCO_CPT29, /* Cougar Point */ |
| 150 | TCO_CPT30, /* Cougar Point */ |
| 151 | TCO_CPT31, /* Cougar Point */ |
Seth Heasley | c54fb81 | 2010-11-17 12:15:08 -0700 | [diff] [blame] | 152 | TCO_PBG1, /* Patsburg */ |
| 153 | TCO_PBG2, /* Patsburg */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | static struct { |
| 157 | char *name; |
| 158 | unsigned int iTCO_version; |
| 159 | } iTCO_chipset_info[] __devinitdata = { |
| 160 | {"ICH", 1}, |
| 161 | {"ICH0", 1}, |
| 162 | {"ICH2", 1}, |
| 163 | {"ICH2-M", 1}, |
| 164 | {"ICH3-S", 1}, |
| 165 | {"ICH3-M", 1}, |
| 166 | {"ICH4", 1}, |
| 167 | {"ICH4-M", 1}, |
| 168 | {"C-ICH", 1}, |
| 169 | {"ICH5 or ICH5R", 1}, |
| 170 | {"6300ESB", 1}, |
| 171 | {"ICH6 or ICH6R", 2}, |
| 172 | {"ICH6-M", 2}, |
| 173 | {"ICH6W or ICH6RW", 2}, |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 174 | {"631xESB/632xESB", 2}, |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 175 | {"ICH7 or ICH7R", 2}, |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 176 | {"ICH7DH", 2}, |
| 177 | {"ICH7-M or ICH7-U", 2}, |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 178 | {"ICH7-M DH", 2}, |
Wim Van Sebroeck | d38bd47 | 2010-12-31 14:10:45 +0000 | [diff] [blame^] | 179 | {"NM10", 2}, |
Arnaud Patard (Rtp) | bcbf25b | 2006-10-04 14:18:29 +0200 | [diff] [blame] | 180 | {"ICH8 or ICH8R", 2}, |
Wim Van Sebroeck | a8edd74 | 2006-10-08 21:05:21 +0200 | [diff] [blame] | 181 | {"ICH8DH", 2}, |
| 182 | {"ICH8DO", 2}, |
Wim Van Sebroeck | acf6035 | 2007-08-31 08:23:10 +0000 | [diff] [blame] | 183 | {"ICH8M", 2}, |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 184 | {"ICH8M-E", 2}, |
Wim Van Sebroeck | 286201d | 2007-07-26 21:11:28 +0000 | [diff] [blame] | 185 | {"ICH9", 2}, |
| 186 | {"ICH9R", 2}, |
| 187 | {"ICH9DH", 2}, |
Gabriel C | a49056d | 2008-04-30 16:51:10 +0200 | [diff] [blame] | 188 | {"ICH9DO", 2}, |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 189 | {"ICH9M", 2}, |
| 190 | {"ICH9M-E", 2}, |
| 191 | {"ICH10", 2}, |
| 192 | {"ICH10R", 2}, |
| 193 | {"ICH10D", 2}, |
| 194 | {"ICH10DO", 2}, |
Seth Heasley | 79e8941 | 2009-11-11 02:24:01 +0100 | [diff] [blame] | 195 | {"PCH Desktop Full Featured", 2}, |
| 196 | {"PCH Mobile Full Featured", 2}, |
Seth Heasley | 3c9d8ec | 2010-01-14 20:58:05 +0000 | [diff] [blame] | 197 | {"P55", 2}, |
| 198 | {"PM55", 2}, |
| 199 | {"H55", 2}, |
| 200 | {"QM57", 2}, |
| 201 | {"H57", 2}, |
| 202 | {"HM55", 2}, |
| 203 | {"Q57", 2}, |
| 204 | {"HM57", 2}, |
Seth Heasley | 79e8941 | 2009-11-11 02:24:01 +0100 | [diff] [blame] | 205 | {"PCH Mobile SFF Full Featured", 2}, |
Seth Heasley | 3c9d8ec | 2010-01-14 20:58:05 +0000 | [diff] [blame] | 206 | {"QS57", 2}, |
| 207 | {"3400", 2}, |
| 208 | {"3420", 2}, |
| 209 | {"3450", 2}, |
Imre Kaloz | 4946f83 | 2009-12-07 20:42:26 +0100 | [diff] [blame] | 210 | {"EP80579", 2}, |
Seth Heasley | 4c7d849 | 2010-03-25 16:14:41 -0700 | [diff] [blame] | 211 | {"Cougar Point", 2}, |
| 212 | {"Cougar Point", 2}, |
| 213 | {"Cougar Point", 2}, |
| 214 | {"Cougar Point", 2}, |
| 215 | {"Cougar Point", 2}, |
| 216 | {"Cougar Point", 2}, |
| 217 | {"Cougar Point", 2}, |
| 218 | {"Cougar Point", 2}, |
| 219 | {"Cougar Point", 2}, |
| 220 | {"Cougar Point", 2}, |
| 221 | {"Cougar Point", 2}, |
| 222 | {"Cougar Point", 2}, |
| 223 | {"Cougar Point", 2}, |
| 224 | {"Cougar Point", 2}, |
| 225 | {"Cougar Point", 2}, |
| 226 | {"Cougar Point", 2}, |
| 227 | {"Cougar Point", 2}, |
| 228 | {"Cougar Point", 2}, |
| 229 | {"Cougar Point", 2}, |
| 230 | {"Cougar Point", 2}, |
| 231 | {"Cougar Point", 2}, |
| 232 | {"Cougar Point", 2}, |
| 233 | {"Cougar Point", 2}, |
| 234 | {"Cougar Point", 2}, |
| 235 | {"Cougar Point", 2}, |
| 236 | {"Cougar Point", 2}, |
| 237 | {"Cougar Point", 2}, |
| 238 | {"Cougar Point", 2}, |
| 239 | {"Cougar Point", 2}, |
| 240 | {"Cougar Point", 2}, |
| 241 | {"Cougar Point", 2}, |
Seth Heasley | cad0df3 | 2010-09-09 09:58:03 -0700 | [diff] [blame] | 242 | {"Patsburg", 2}, |
Seth Heasley | c54fb81 | 2010-11-17 12:15:08 -0700 | [diff] [blame] | 243 | {"Patsburg", 2}, |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 244 | {NULL, 0} |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 245 | }; |
| 246 | |
Wim Van Sebroeck | c87b639 | 2007-08-19 20:17:58 +0000 | [diff] [blame] | 247 | #define ITCO_PCI_DEVICE(dev, data) \ |
| 248 | .vendor = PCI_VENDOR_ID_INTEL, \ |
| 249 | .device = dev, \ |
| 250 | .subvendor = PCI_ANY_ID, \ |
| 251 | .subdevice = PCI_ANY_ID, \ |
| 252 | .class = 0, \ |
| 253 | .class_mask = 0, \ |
| 254 | .driver_data = data |
| 255 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 256 | /* |
| 257 | * This data only exists for exporting the supported PCI ids |
| 258 | * via MODULE_DEVICE_TABLE. We do not actually register a |
| 259 | * pci_driver, because the I/O Controller Hub has also other |
| 260 | * functions that probably will be registered by other drivers. |
| 261 | */ |
| 262 | static struct pci_device_id iTCO_wdt_pci_tbl[] = { |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 263 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801AA_0, TCO_ICH)}, |
| 264 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801AB_0, TCO_ICH0)}, |
| 265 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801BA_0, TCO_ICH2)}, |
| 266 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801BA_10, TCO_ICH2M)}, |
| 267 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801CA_0, TCO_ICH3)}, |
| 268 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801CA_12, TCO_ICH3M)}, |
| 269 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801DB_0, TCO_ICH4)}, |
| 270 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801DB_12, TCO_ICH4M)}, |
| 271 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801E_0, TCO_CICH)}, |
| 272 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801EB_0, TCO_ICH5)}, |
Wim Van Sebroeck | c87b639 | 2007-08-19 20:17:58 +0000 | [diff] [blame] | 273 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB_1, TCO_6300ESB)}, |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 274 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_0, TCO_ICH6)}, |
| 275 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_1, TCO_ICH6M)}, |
| 276 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_2, TCO_ICH6W)}, |
Wim Van Sebroeck | c87b639 | 2007-08-19 20:17:58 +0000 | [diff] [blame] | 277 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB2_0, TCO_631XESB)}, |
| 278 | { ITCO_PCI_DEVICE(0x2671, TCO_631XESB)}, |
| 279 | { ITCO_PCI_DEVICE(0x2672, TCO_631XESB)}, |
| 280 | { ITCO_PCI_DEVICE(0x2673, TCO_631XESB)}, |
| 281 | { ITCO_PCI_DEVICE(0x2674, TCO_631XESB)}, |
| 282 | { ITCO_PCI_DEVICE(0x2675, TCO_631XESB)}, |
| 283 | { ITCO_PCI_DEVICE(0x2676, TCO_631XESB)}, |
| 284 | { ITCO_PCI_DEVICE(0x2677, TCO_631XESB)}, |
| 285 | { ITCO_PCI_DEVICE(0x2678, TCO_631XESB)}, |
| 286 | { ITCO_PCI_DEVICE(0x2679, TCO_631XESB)}, |
| 287 | { ITCO_PCI_DEVICE(0x267a, TCO_631XESB)}, |
| 288 | { ITCO_PCI_DEVICE(0x267b, TCO_631XESB)}, |
| 289 | { ITCO_PCI_DEVICE(0x267c, TCO_631XESB)}, |
| 290 | { ITCO_PCI_DEVICE(0x267d, TCO_631XESB)}, |
| 291 | { ITCO_PCI_DEVICE(0x267e, TCO_631XESB)}, |
| 292 | { ITCO_PCI_DEVICE(0x267f, TCO_631XESB)}, |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 293 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_0, TCO_ICH7)}, |
| 294 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_30, TCO_ICH7DH)}, |
| 295 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_1, TCO_ICH7M)}, |
| 296 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_31, TCO_ICH7MDH)}, |
Wim Van Sebroeck | d38bd47 | 2010-12-31 14:10:45 +0000 | [diff] [blame^] | 297 | { ITCO_PCI_DEVICE(0x27bc, TCO_NM10)}, |
Wim Van Sebroeck | 28d41f5 | 2008-11-19 22:25:53 +0000 | [diff] [blame] | 298 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_0, TCO_ICH8)}, |
| 299 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_2, TCO_ICH8DH)}, |
| 300 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_3, TCO_ICH8DO)}, |
| 301 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_4, TCO_ICH8M)}, |
| 302 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_1, TCO_ICH8ME)}, |
| 303 | { ITCO_PCI_DEVICE(0x2918, TCO_ICH9)}, |
| 304 | { ITCO_PCI_DEVICE(0x2916, TCO_ICH9R)}, |
| 305 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH9_2, TCO_ICH9DH)}, |
| 306 | { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH9_4, TCO_ICH9DO)}, |
| 307 | { ITCO_PCI_DEVICE(0x2919, TCO_ICH9M)}, |
| 308 | { ITCO_PCI_DEVICE(0x2917, TCO_ICH9ME)}, |
| 309 | { ITCO_PCI_DEVICE(0x3a18, TCO_ICH10)}, |
| 310 | { ITCO_PCI_DEVICE(0x3a16, TCO_ICH10R)}, |
| 311 | { ITCO_PCI_DEVICE(0x3a1a, TCO_ICH10D)}, |
| 312 | { ITCO_PCI_DEVICE(0x3a14, TCO_ICH10DO)}, |
Seth Heasley | 79e8941 | 2009-11-11 02:24:01 +0100 | [diff] [blame] | 313 | { ITCO_PCI_DEVICE(0x3b00, TCO_PCH)}, |
| 314 | { ITCO_PCI_DEVICE(0x3b01, TCO_PCHM)}, |
Seth Heasley | 3c9d8ec | 2010-01-14 20:58:05 +0000 | [diff] [blame] | 315 | { ITCO_PCI_DEVICE(0x3b02, TCO_P55)}, |
| 316 | { ITCO_PCI_DEVICE(0x3b03, TCO_PM55)}, |
| 317 | { ITCO_PCI_DEVICE(0x3b06, TCO_H55)}, |
| 318 | { ITCO_PCI_DEVICE(0x3b07, TCO_QM57)}, |
| 319 | { ITCO_PCI_DEVICE(0x3b08, TCO_H57)}, |
| 320 | { ITCO_PCI_DEVICE(0x3b09, TCO_HM55)}, |
| 321 | { ITCO_PCI_DEVICE(0x3b0a, TCO_Q57)}, |
| 322 | { ITCO_PCI_DEVICE(0x3b0b, TCO_HM57)}, |
Seth Heasley | 79e8941 | 2009-11-11 02:24:01 +0100 | [diff] [blame] | 323 | { ITCO_PCI_DEVICE(0x3b0d, TCO_PCHMSFF)}, |
Seth Heasley | 3c9d8ec | 2010-01-14 20:58:05 +0000 | [diff] [blame] | 324 | { ITCO_PCI_DEVICE(0x3b0f, TCO_QS57)}, |
| 325 | { ITCO_PCI_DEVICE(0x3b12, TCO_3400)}, |
| 326 | { ITCO_PCI_DEVICE(0x3b14, TCO_3420)}, |
| 327 | { ITCO_PCI_DEVICE(0x3b16, TCO_3450)}, |
Imre Kaloz | 4946f83 | 2009-12-07 20:42:26 +0100 | [diff] [blame] | 328 | { ITCO_PCI_DEVICE(0x5031, TCO_EP80579)}, |
Seth Heasley | 4c7d849 | 2010-03-25 16:14:41 -0700 | [diff] [blame] | 329 | { ITCO_PCI_DEVICE(0x1c41, TCO_CPT1)}, |
| 330 | { ITCO_PCI_DEVICE(0x1c42, TCO_CPT2)}, |
| 331 | { ITCO_PCI_DEVICE(0x1c43, TCO_CPT3)}, |
| 332 | { ITCO_PCI_DEVICE(0x1c44, TCO_CPT4)}, |
| 333 | { ITCO_PCI_DEVICE(0x1c45, TCO_CPT5)}, |
| 334 | { ITCO_PCI_DEVICE(0x1c46, TCO_CPT6)}, |
| 335 | { ITCO_PCI_DEVICE(0x1c47, TCO_CPT7)}, |
| 336 | { ITCO_PCI_DEVICE(0x1c48, TCO_CPT8)}, |
| 337 | { ITCO_PCI_DEVICE(0x1c49, TCO_CPT9)}, |
| 338 | { ITCO_PCI_DEVICE(0x1c4a, TCO_CPT10)}, |
| 339 | { ITCO_PCI_DEVICE(0x1c4b, TCO_CPT11)}, |
| 340 | { ITCO_PCI_DEVICE(0x1c4c, TCO_CPT12)}, |
| 341 | { ITCO_PCI_DEVICE(0x1c4d, TCO_CPT13)}, |
| 342 | { ITCO_PCI_DEVICE(0x1c4e, TCO_CPT14)}, |
| 343 | { ITCO_PCI_DEVICE(0x1c4f, TCO_CPT15)}, |
| 344 | { ITCO_PCI_DEVICE(0x1c50, TCO_CPT16)}, |
| 345 | { ITCO_PCI_DEVICE(0x1c51, TCO_CPT17)}, |
| 346 | { ITCO_PCI_DEVICE(0x1c52, TCO_CPT18)}, |
| 347 | { ITCO_PCI_DEVICE(0x1c53, TCO_CPT19)}, |
| 348 | { ITCO_PCI_DEVICE(0x1c54, TCO_CPT20)}, |
| 349 | { ITCO_PCI_DEVICE(0x1c55, TCO_CPT21)}, |
| 350 | { ITCO_PCI_DEVICE(0x1c56, TCO_CPT22)}, |
| 351 | { ITCO_PCI_DEVICE(0x1c57, TCO_CPT23)}, |
| 352 | { ITCO_PCI_DEVICE(0x1c58, TCO_CPT24)}, |
| 353 | { ITCO_PCI_DEVICE(0x1c59, TCO_CPT25)}, |
| 354 | { ITCO_PCI_DEVICE(0x1c5a, TCO_CPT26)}, |
| 355 | { ITCO_PCI_DEVICE(0x1c5b, TCO_CPT27)}, |
| 356 | { ITCO_PCI_DEVICE(0x1c5c, TCO_CPT28)}, |
| 357 | { ITCO_PCI_DEVICE(0x1c5d, TCO_CPT29)}, |
| 358 | { ITCO_PCI_DEVICE(0x1c5e, TCO_CPT30)}, |
| 359 | { ITCO_PCI_DEVICE(0x1c5f, TCO_CPT31)}, |
Seth Heasley | c54fb81 | 2010-11-17 12:15:08 -0700 | [diff] [blame] | 360 | { ITCO_PCI_DEVICE(0x1d40, TCO_PBG1)}, |
| 361 | { ITCO_PCI_DEVICE(0x1d41, TCO_PBG2)}, |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 362 | { 0, }, /* End of list */ |
| 363 | }; |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 364 | MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 365 | |
| 366 | /* Address definitions for the TCO */ |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 367 | /* TCO base address */ |
Wim Van Sebroeck | 0a7e658 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 368 | #define TCOBASE (iTCO_wdt_private.ACPIBASE + 0x60) |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 369 | /* SMI Control and Enable Register */ |
Wim Van Sebroeck | 0a7e658 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 370 | #define SMI_EN (iTCO_wdt_private.ACPIBASE + 0x30) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 371 | |
Wim Van Sebroeck | 0a7e658 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 372 | #define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload and Curr. Value */ |
| 373 | #define TCOv1_TMR (TCOBASE + 0x01) /* TCOv1 Timer Initial Value */ |
| 374 | #define TCO_DAT_IN (TCOBASE + 0x02) /* TCO Data In Register */ |
| 375 | #define TCO_DAT_OUT (TCOBASE + 0x03) /* TCO Data Out Register */ |
| 376 | #define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */ |
| 377 | #define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */ |
| 378 | #define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */ |
| 379 | #define TCO2_CNT (TCOBASE + 0x0a) /* TCO2 Control Register */ |
| 380 | #define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 381 | |
| 382 | /* internal variables */ |
| 383 | static unsigned long is_active; |
| 384 | static char expect_release; |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 385 | static struct { /* this is private data for the iTCO_wdt device */ |
| 386 | /* TCO version/generation */ |
| 387 | unsigned int iTCO_version; |
Prarit Bhargava | 641912f | 2010-08-06 11:41:24 -0400 | [diff] [blame] | 388 | /* The device's ACPIBASE address (TCOBASE = ACPIBASE+0x60) */ |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 389 | unsigned long ACPIBASE; |
| 390 | /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2)*/ |
| 391 | unsigned long __iomem *gcs; |
| 392 | /* the lock for io operations */ |
| 393 | spinlock_t io_lock; |
| 394 | /* the PCI-device */ |
| 395 | struct pci_dev *pdev; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 396 | } iTCO_wdt_private; |
| 397 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 398 | /* the watchdog platform device */ |
| 399 | static struct platform_device *iTCO_wdt_platform_device; |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 400 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 401 | /* module parameters */ |
| 402 | #define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */ |
| 403 | static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ |
| 404 | module_param(heartbeat, int, 0); |
Pádraig Brady | 7e6811d | 2010-04-19 13:38:25 +0100 | [diff] [blame] | 405 | MODULE_PARM_DESC(heartbeat, "Watchdog timeout in seconds. " |
| 406 | "5..76 (TCO v1) or 3..614 (TCO v2), default=" |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 407 | __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 408 | |
| 409 | static int nowayout = WATCHDOG_NOWAYOUT; |
| 410 | module_param(nowayout, int, 0); |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 411 | MODULE_PARM_DESC(nowayout, |
| 412 | "Watchdog cannot be stopped once started (default=" |
| 413 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 414 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 415 | /* |
| 416 | * Some TCO specific functions |
| 417 | */ |
| 418 | |
| 419 | static inline unsigned int seconds_to_ticks(int seconds) |
| 420 | { |
| 421 | /* the internal timer is stored as ticks which decrement |
| 422 | * every 0.6 seconds */ |
| 423 | return (seconds * 10) / 6; |
| 424 | } |
| 425 | |
| 426 | static void iTCO_wdt_set_NO_REBOOT_bit(void) |
| 427 | { |
| 428 | u32 val32; |
| 429 | |
| 430 | /* Set the NO_REBOOT bit: this disables reboots */ |
| 431 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 432 | val32 = readl(iTCO_wdt_private.gcs); |
| 433 | val32 |= 0x00000020; |
| 434 | writel(val32, iTCO_wdt_private.gcs); |
| 435 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 436 | pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32); |
| 437 | val32 |= 0x00000002; |
| 438 | pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | static int iTCO_wdt_unset_NO_REBOOT_bit(void) |
| 443 | { |
| 444 | int ret = 0; |
| 445 | u32 val32; |
| 446 | |
| 447 | /* Unset the NO_REBOOT bit: this enables reboots */ |
| 448 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 449 | val32 = readl(iTCO_wdt_private.gcs); |
| 450 | val32 &= 0xffffffdf; |
| 451 | writel(val32, iTCO_wdt_private.gcs); |
| 452 | |
| 453 | val32 = readl(iTCO_wdt_private.gcs); |
| 454 | if (val32 & 0x00000020) |
| 455 | ret = -EIO; |
| 456 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 457 | pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32); |
| 458 | val32 &= 0xfffffffd; |
| 459 | pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32); |
| 460 | |
| 461 | pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32); |
| 462 | if (val32 & 0x00000002) |
| 463 | ret = -EIO; |
| 464 | } |
| 465 | |
| 466 | return ret; /* returns: 0 = OK, -EIO = Error */ |
| 467 | } |
| 468 | |
| 469 | static int iTCO_wdt_start(void) |
| 470 | { |
| 471 | unsigned int val; |
| 472 | |
| 473 | spin_lock(&iTCO_wdt_private.io_lock); |
| 474 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 475 | iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat); |
| 476 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 477 | /* disable chipset's NO_REBOOT bit */ |
| 478 | if (iTCO_wdt_unset_NO_REBOOT_bit()) { |
Roel Kluin | 2ba7d7b | 2007-10-23 03:08:27 +0200 | [diff] [blame] | 479 | spin_unlock(&iTCO_wdt_private.io_lock); |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 480 | printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, " |
Prarit Bhargava | 641912f | 2010-08-06 11:41:24 -0400 | [diff] [blame] | 481 | "reboot disabled by hardware/BIOS\n"); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 482 | return -EIO; |
| 483 | } |
| 484 | |
Wim Van Sebroeck | 7cd5b08 | 2008-11-19 19:39:58 +0000 | [diff] [blame] | 485 | /* Force the timer to its reload value by writing to the TCO_RLD |
| 486 | register */ |
| 487 | if (iTCO_wdt_private.iTCO_version == 2) |
| 488 | outw(0x01, TCO_RLD); |
| 489 | else if (iTCO_wdt_private.iTCO_version == 1) |
| 490 | outb(0x01, TCO_RLD); |
| 491 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 492 | /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */ |
| 493 | val = inw(TCO1_CNT); |
| 494 | val &= 0xf7ff; |
| 495 | outw(val, TCO1_CNT); |
| 496 | val = inw(TCO1_CNT); |
| 497 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 498 | |
| 499 | if (val & 0x0800) |
| 500 | return -1; |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static int iTCO_wdt_stop(void) |
| 505 | { |
| 506 | unsigned int val; |
| 507 | |
| 508 | spin_lock(&iTCO_wdt_private.io_lock); |
| 509 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 510 | iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE); |
| 511 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 512 | /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */ |
| 513 | val = inw(TCO1_CNT); |
| 514 | val |= 0x0800; |
| 515 | outw(val, TCO1_CNT); |
| 516 | val = inw(TCO1_CNT); |
| 517 | |
| 518 | /* Set the NO_REBOOT bit to prevent later reboots, just for sure */ |
| 519 | iTCO_wdt_set_NO_REBOOT_bit(); |
| 520 | |
| 521 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 522 | |
| 523 | if ((val & 0x0800) == 0) |
| 524 | return -1; |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | static int iTCO_wdt_keepalive(void) |
| 529 | { |
| 530 | spin_lock(&iTCO_wdt_private.io_lock); |
| 531 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 532 | iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat); |
| 533 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 534 | /* Reload the timer by writing to the TCO Timer Counter register */ |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 535 | if (iTCO_wdt_private.iTCO_version == 2) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 536 | outw(0x01, TCO_RLD); |
Pádraig Brady | 7e6811d | 2010-04-19 13:38:25 +0100 | [diff] [blame] | 537 | else if (iTCO_wdt_private.iTCO_version == 1) { |
| 538 | /* Reset the timeout status bit so that the timer |
| 539 | * needs to count down twice again before rebooting */ |
| 540 | outw(0x0008, TCO1_STS); /* write 1 to clear bit */ |
| 541 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 542 | outb(0x01, TCO_RLD); |
Pádraig Brady | 7e6811d | 2010-04-19 13:38:25 +0100 | [diff] [blame] | 543 | } |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 544 | |
| 545 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | static int iTCO_wdt_set_heartbeat(int t) |
| 550 | { |
| 551 | unsigned int val16; |
| 552 | unsigned char val8; |
| 553 | unsigned int tmrval; |
| 554 | |
| 555 | tmrval = seconds_to_ticks(t); |
Pádraig Brady | 7e6811d | 2010-04-19 13:38:25 +0100 | [diff] [blame] | 556 | |
| 557 | /* For TCO v1 the timer counts down twice before rebooting */ |
| 558 | if (iTCO_wdt_private.iTCO_version == 1) |
| 559 | tmrval /= 2; |
| 560 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 561 | /* from the specs: */ |
| 562 | /* "Values of 0h-3h are ignored and should not be attempted" */ |
| 563 | if (tmrval < 0x04) |
| 564 | return -EINVAL; |
| 565 | if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) || |
| 566 | ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f))) |
| 567 | return -EINVAL; |
| 568 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 569 | iTCO_vendor_pre_set_heartbeat(tmrval); |
| 570 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 571 | /* Write new heartbeat to watchdog */ |
| 572 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 573 | spin_lock(&iTCO_wdt_private.io_lock); |
| 574 | val16 = inw(TCOv2_TMR); |
| 575 | val16 &= 0xfc00; |
| 576 | val16 |= tmrval; |
| 577 | outw(val16, TCOv2_TMR); |
| 578 | val16 = inw(TCOv2_TMR); |
| 579 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 580 | |
| 581 | if ((val16 & 0x3ff) != tmrval) |
| 582 | return -EINVAL; |
| 583 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 584 | spin_lock(&iTCO_wdt_private.io_lock); |
| 585 | val8 = inb(TCOv1_TMR); |
| 586 | val8 &= 0xc0; |
| 587 | val8 |= (tmrval & 0xff); |
| 588 | outb(val8, TCOv1_TMR); |
| 589 | val8 = inb(TCOv1_TMR); |
| 590 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 591 | |
| 592 | if ((val8 & 0x3f) != tmrval) |
| 593 | return -EINVAL; |
| 594 | } |
| 595 | |
| 596 | heartbeat = t; |
| 597 | return 0; |
| 598 | } |
| 599 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 600 | static int iTCO_wdt_get_timeleft(int *time_left) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 601 | { |
| 602 | unsigned int val16; |
| 603 | unsigned char val8; |
| 604 | |
| 605 | /* read the TCO Timer */ |
| 606 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 607 | spin_lock(&iTCO_wdt_private.io_lock); |
| 608 | val16 = inw(TCO_RLD); |
| 609 | val16 &= 0x3ff; |
| 610 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 611 | |
| 612 | *time_left = (val16 * 6) / 10; |
| 613 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 614 | spin_lock(&iTCO_wdt_private.io_lock); |
| 615 | val8 = inb(TCO_RLD); |
| 616 | val8 &= 0x3f; |
Pádraig Brady | 7e6811d | 2010-04-19 13:38:25 +0100 | [diff] [blame] | 617 | if (!(inw(TCO1_STS) & 0x0008)) |
| 618 | val8 += (inb(TCOv1_TMR) & 0x3f); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 619 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 620 | |
| 621 | *time_left = (val8 * 6) / 10; |
Jeff Garzik | 8006036 | 2006-10-10 03:40:44 -0400 | [diff] [blame] | 622 | } else |
| 623 | return -EINVAL; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | /* |
| 628 | * /dev/watchdog handling |
| 629 | */ |
| 630 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 631 | static int iTCO_wdt_open(struct inode *inode, struct file *file) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 632 | { |
| 633 | /* /dev/watchdog can only be opened once */ |
| 634 | if (test_and_set_bit(0, &is_active)) |
| 635 | return -EBUSY; |
| 636 | |
| 637 | /* |
| 638 | * Reload and activate timer |
| 639 | */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 640 | iTCO_wdt_start(); |
| 641 | return nonseekable_open(inode, file); |
| 642 | } |
| 643 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 644 | static int iTCO_wdt_release(struct inode *inode, struct file *file) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 645 | { |
| 646 | /* |
| 647 | * Shut off the timer. |
| 648 | */ |
| 649 | if (expect_release == 42) { |
| 650 | iTCO_wdt_stop(); |
| 651 | } else { |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 652 | printk(KERN_CRIT PFX |
| 653 | "Unexpected close, not stopping watchdog!\n"); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 654 | iTCO_wdt_keepalive(); |
| 655 | } |
| 656 | clear_bit(0, &is_active); |
| 657 | expect_release = 0; |
| 658 | return 0; |
| 659 | } |
| 660 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 661 | static ssize_t iTCO_wdt_write(struct file *file, const char __user *data, |
| 662 | size_t len, loff_t *ppos) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 663 | { |
| 664 | /* See if we got the magic character 'V' and reload the timer */ |
| 665 | if (len) { |
| 666 | if (!nowayout) { |
| 667 | size_t i; |
| 668 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 669 | /* note: just in case someone wrote the magic |
| 670 | character five months ago... */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 671 | expect_release = 0; |
| 672 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 673 | /* scan to see whether or not we got the |
| 674 | magic character */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 675 | for (i = 0; i != len; i++) { |
| 676 | char c; |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 677 | if (get_user(c, data + i)) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 678 | return -EFAULT; |
| 679 | if (c == 'V') |
| 680 | expect_release = 42; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | /* someone wrote to us, we should reload the timer */ |
| 685 | iTCO_wdt_keepalive(); |
| 686 | } |
| 687 | return len; |
| 688 | } |
| 689 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 690 | static long iTCO_wdt_ioctl(struct file *file, unsigned int cmd, |
| 691 | unsigned long arg) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 692 | { |
| 693 | int new_options, retval = -EINVAL; |
| 694 | int new_heartbeat; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 695 | void __user *argp = (void __user *)arg; |
| 696 | int __user *p = argp; |
Wim Van Sebroeck | 42747d7 | 2009-12-26 18:55:22 +0000 | [diff] [blame] | 697 | static const struct watchdog_info ident = { |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 698 | .options = WDIOF_SETTIMEOUT | |
| 699 | WDIOF_KEEPALIVEPING | |
| 700 | WDIOF_MAGICCLOSE, |
| 701 | .firmware_version = 0, |
| 702 | .identity = DRV_NAME, |
| 703 | }; |
| 704 | |
| 705 | switch (cmd) { |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 706 | case WDIOC_GETSUPPORT: |
| 707 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; |
| 708 | case WDIOC_GETSTATUS: |
| 709 | case WDIOC_GETBOOTSTATUS: |
| 710 | return put_user(0, p); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 711 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 712 | case WDIOC_SETOPTIONS: |
| 713 | { |
| 714 | if (get_user(new_options, p)) |
| 715 | return -EFAULT; |
| 716 | |
| 717 | if (new_options & WDIOS_DISABLECARD) { |
| 718 | iTCO_wdt_stop(); |
| 719 | retval = 0; |
| 720 | } |
| 721 | if (new_options & WDIOS_ENABLECARD) { |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 722 | iTCO_wdt_keepalive(); |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 723 | iTCO_wdt_start(); |
| 724 | retval = 0; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 725 | } |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 726 | return retval; |
| 727 | } |
Wim Van Sebroeck | 0c06090 | 2008-07-18 11:41:17 +0000 | [diff] [blame] | 728 | case WDIOC_KEEPALIVE: |
| 729 | iTCO_wdt_keepalive(); |
| 730 | return 0; |
| 731 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 732 | case WDIOC_SETTIMEOUT: |
| 733 | { |
| 734 | if (get_user(new_heartbeat, p)) |
| 735 | return -EFAULT; |
| 736 | if (iTCO_wdt_set_heartbeat(new_heartbeat)) |
| 737 | return -EINVAL; |
| 738 | iTCO_wdt_keepalive(); |
| 739 | /* Fall */ |
| 740 | } |
| 741 | case WDIOC_GETTIMEOUT: |
| 742 | return put_user(heartbeat, p); |
| 743 | case WDIOC_GETTIMELEFT: |
| 744 | { |
| 745 | int time_left; |
| 746 | if (iTCO_wdt_get_timeleft(&time_left)) |
| 747 | return -EINVAL; |
| 748 | return put_user(time_left, p); |
| 749 | } |
| 750 | default: |
| 751 | return -ENOTTY; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
| 755 | /* |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 756 | * Kernel Interfaces |
| 757 | */ |
| 758 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 759 | static const struct file_operations iTCO_wdt_fops = { |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 760 | .owner = THIS_MODULE, |
| 761 | .llseek = no_llseek, |
| 762 | .write = iTCO_wdt_write, |
| 763 | .unlocked_ioctl = iTCO_wdt_ioctl, |
| 764 | .open = iTCO_wdt_open, |
| 765 | .release = iTCO_wdt_release, |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 766 | }; |
| 767 | |
| 768 | static struct miscdevice iTCO_wdt_miscdev = { |
| 769 | .minor = WATCHDOG_MINOR, |
| 770 | .name = "watchdog", |
| 771 | .fops = &iTCO_wdt_fops, |
| 772 | }; |
| 773 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 774 | /* |
| 775 | * Init & exit routines |
| 776 | */ |
| 777 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 778 | static int __devinit iTCO_wdt_init(struct pci_dev *pdev, |
| 779 | const struct pci_device_id *ent, struct platform_device *dev) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 780 | { |
| 781 | int ret; |
| 782 | u32 base_address; |
| 783 | unsigned long RCBA; |
Wim Van Sebroeck | 12d60e2 | 2009-01-28 20:51:04 +0000 | [diff] [blame] | 784 | unsigned long val32; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 785 | |
| 786 | /* |
| 787 | * Find the ACPI/PM base I/O address which is the base |
| 788 | * for the TCO registers (TCOBASE=ACPIBASE + 0x60) |
| 789 | * ACPIBASE is bits [15:7] from 0x40-0x43 |
| 790 | */ |
| 791 | pci_read_config_dword(pdev, 0x40, &base_address); |
Wim Van Sebroeck | 0d4804b | 2007-05-11 18:59:24 +0000 | [diff] [blame] | 792 | base_address &= 0x0000ff80; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 793 | if (base_address == 0x00000000) { |
| 794 | /* Something's wrong here, ACPIBASE has to be set */ |
Prarit Bhargava | 641912f | 2010-08-06 11:41:24 -0400 | [diff] [blame] | 795 | printk(KERN_ERR PFX "failed to get TCOBASE address, " |
| 796 | "device disabled by hardware/BIOS\n"); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 797 | return -ENODEV; |
| 798 | } |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 799 | iTCO_wdt_private.iTCO_version = |
| 800 | iTCO_chipset_info[ent->driver_data].iTCO_version; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 801 | iTCO_wdt_private.ACPIBASE = base_address; |
| 802 | iTCO_wdt_private.pdev = pdev; |
| 803 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 804 | /* Get the Memory-Mapped GCS register, we need it for the |
| 805 | NO_REBOOT flag (TCO v2). To get access to it you have to |
| 806 | read RCBA from PCI Config space 0xf0 and use it as base. |
| 807 | GCS = RCBA + ICH6_GCS(0x3410). */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 808 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 809 | pci_read_config_dword(pdev, 0xf0, &base_address); |
Denis V. Lunev | de8cd9a | 2009-06-05 15:13:08 +0400 | [diff] [blame] | 810 | if ((base_address & 1) == 0) { |
Prarit Bhargava | 641912f | 2010-08-06 11:41:24 -0400 | [diff] [blame] | 811 | printk(KERN_ERR PFX "RCBA is disabled by hardware" |
| 812 | "/BIOS, device disabled\n"); |
Denis V. Lunev | de8cd9a | 2009-06-05 15:13:08 +0400 | [diff] [blame] | 813 | ret = -ENODEV; |
| 814 | goto out; |
| 815 | } |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 816 | RCBA = base_address & 0xffffc000; |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 817 | iTCO_wdt_private.gcs = ioremap((RCBA + 0x3410), 4); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /* Check chipset's NO_REBOOT bit */ |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 821 | if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) { |
Naga Chumbalkar | ec26985 | 2010-02-09 00:42:02 +0100 | [diff] [blame] | 822 | printk(KERN_INFO PFX "unable to reset NO_REBOOT flag, " |
Prarit Bhargava | 641912f | 2010-08-06 11:41:24 -0400 | [diff] [blame] | 823 | "device disabled by hardware/BIOS\n"); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 824 | ret = -ENODEV; /* Cannot reset NO_REBOOT bit */ |
Denis V. Lunev | de8cd9a | 2009-06-05 15:13:08 +0400 | [diff] [blame] | 825 | goto out_unmap; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | /* Set the NO_REBOOT bit to prevent later reboots, just for sure */ |
| 829 | iTCO_wdt_set_NO_REBOOT_bit(); |
| 830 | |
Wim Van Sebroeck | 7cd5b08 | 2008-11-19 19:39:58 +0000 | [diff] [blame] | 831 | /* The TCO logic uses the TCO_EN bit in the SMI_EN register */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 832 | if (!request_region(SMI_EN, 4, "iTCO_wdt")) { |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 833 | printk(KERN_ERR PFX |
Prarit Bhargava | 641912f | 2010-08-06 11:41:24 -0400 | [diff] [blame] | 834 | "I/O address 0x%04lx already in use, " |
| 835 | "device disabled\n", SMI_EN); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 836 | ret = -EIO; |
Denis V. Lunev | de8cd9a | 2009-06-05 15:13:08 +0400 | [diff] [blame] | 837 | goto out_unmap; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 838 | } |
Wim Van Sebroeck | 12d60e2 | 2009-01-28 20:51:04 +0000 | [diff] [blame] | 839 | /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */ |
| 840 | val32 = inl(SMI_EN); |
| 841 | val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */ |
| 842 | outl(val32, SMI_EN); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 843 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 844 | /* The TCO I/O registers reside in a 32-byte range pointed to |
| 845 | by the TCOBASE value */ |
| 846 | if (!request_region(TCOBASE, 0x20, "iTCO_wdt")) { |
Prarit Bhargava | 641912f | 2010-08-06 11:41:24 -0400 | [diff] [blame] | 847 | printk(KERN_ERR PFX "I/O address 0x%04lx already in use " |
| 848 | "device disabled\n", TCOBASE); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 849 | ret = -EIO; |
Wim Van Sebroeck | 7cd5b08 | 2008-11-19 19:39:58 +0000 | [diff] [blame] | 850 | goto unreg_smi_en; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 851 | } |
| 852 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 853 | printk(KERN_INFO PFX |
| 854 | "Found a %s TCO device (Version=%d, TCOBASE=0x%04lx)\n", |
| 855 | iTCO_chipset_info[ent->driver_data].name, |
| 856 | iTCO_chipset_info[ent->driver_data].iTCO_version, |
| 857 | TCOBASE); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 858 | |
| 859 | /* Clear out the (probably old) status */ |
Pádraig Brady | 7e6811d | 2010-04-19 13:38:25 +0100 | [diff] [blame] | 860 | outw(0x0008, TCO1_STS); /* Clear the Time Out Status bit */ |
| 861 | outw(0x0002, TCO2_STS); /* Clear SECOND_TO_STS bit */ |
| 862 | outw(0x0004, TCO2_STS); /* Clear BOOT_STS bit */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 863 | |
| 864 | /* Make sure the watchdog is not running */ |
| 865 | iTCO_wdt_stop(); |
| 866 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 867 | /* Check that the heartbeat value is within it's range; |
| 868 | if not reset to the default */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 869 | if (iTCO_wdt_set_heartbeat(heartbeat)) { |
| 870 | iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT); |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 871 | printk(KERN_INFO PFX |
Pádraig Brady | 7e6811d | 2010-04-19 13:38:25 +0100 | [diff] [blame] | 872 | "timeout value out of range, using %d\n", heartbeat); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 873 | } |
| 874 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 875 | ret = misc_register(&iTCO_wdt_miscdev); |
| 876 | if (ret != 0) { |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 877 | printk(KERN_ERR PFX |
| 878 | "cannot register miscdev on minor=%d (err=%d)\n", |
| 879 | WATCHDOG_MINOR, ret); |
Wim Van Sebroeck | 1bef84b | 2006-08-05 20:59:01 +0200 | [diff] [blame] | 880 | goto unreg_region; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 881 | } |
| 882 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 883 | printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n", |
| 884 | heartbeat, nowayout); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 885 | |
| 886 | return 0; |
| 887 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 888 | unreg_region: |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 889 | release_region(TCOBASE, 0x20); |
Wim Van Sebroeck | 7cd5b08 | 2008-11-19 19:39:58 +0000 | [diff] [blame] | 890 | unreg_smi_en: |
| 891 | release_region(SMI_EN, 4); |
Denis V. Lunev | de8cd9a | 2009-06-05 15:13:08 +0400 | [diff] [blame] | 892 | out_unmap: |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 893 | if (iTCO_wdt_private.iTCO_version == 2) |
| 894 | iounmap(iTCO_wdt_private.gcs); |
Denis V. Lunev | de8cd9a | 2009-06-05 15:13:08 +0400 | [diff] [blame] | 895 | out: |
Wim Van Sebroeck | 1bef84b | 2006-08-05 20:59:01 +0200 | [diff] [blame] | 896 | iTCO_wdt_private.ACPIBASE = 0; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 897 | return ret; |
| 898 | } |
| 899 | |
Wim Van Sebroeck | 08113e3 | 2007-08-31 08:15:34 +0000 | [diff] [blame] | 900 | static void __devexit iTCO_wdt_cleanup(void) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 901 | { |
| 902 | /* Stop the timer before we leave */ |
| 903 | if (!nowayout) |
| 904 | iTCO_wdt_stop(); |
| 905 | |
| 906 | /* Deregister */ |
| 907 | misc_deregister(&iTCO_wdt_miscdev); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 908 | release_region(TCOBASE, 0x20); |
Wim Van Sebroeck | 7cd5b08 | 2008-11-19 19:39:58 +0000 | [diff] [blame] | 909 | release_region(SMI_EN, 4); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 910 | if (iTCO_wdt_private.iTCO_version == 2) |
| 911 | iounmap(iTCO_wdt_private.gcs); |
Wim Van Sebroeck | 4802c65 | 2006-07-19 22:39:13 +0200 | [diff] [blame] | 912 | pci_dev_put(iTCO_wdt_private.pdev); |
Wim Van Sebroeck | 1bef84b | 2006-08-05 20:59:01 +0200 | [diff] [blame] | 913 | iTCO_wdt_private.ACPIBASE = 0; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 914 | } |
| 915 | |
Wim Van Sebroeck | 08113e3 | 2007-08-31 08:15:34 +0000 | [diff] [blame] | 916 | static int __devinit iTCO_wdt_probe(struct platform_device *dev) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 917 | { |
Naga Chumbalkar | ec26985 | 2010-02-09 00:42:02 +0100 | [diff] [blame] | 918 | int ret = -ENODEV; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 919 | int found = 0; |
| 920 | struct pci_dev *pdev = NULL; |
| 921 | const struct pci_device_id *ent; |
| 922 | |
| 923 | spin_lock_init(&iTCO_wdt_private.io_lock); |
| 924 | |
| 925 | for_each_pci_dev(pdev) { |
| 926 | ent = pci_match_id(iTCO_wdt_pci_tbl, pdev); |
| 927 | if (ent) { |
Naga Chumbalkar | ec26985 | 2010-02-09 00:42:02 +0100 | [diff] [blame] | 928 | found++; |
| 929 | ret = iTCO_wdt_init(pdev, ent, dev); |
| 930 | if (!ret) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 931 | break; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | |
Naga Chumbalkar | ec26985 | 2010-02-09 00:42:02 +0100 | [diff] [blame] | 935 | if (!found) |
Prarit Bhargava | 641912f | 2010-08-06 11:41:24 -0400 | [diff] [blame] | 936 | printk(KERN_INFO PFX "No device detected.\n"); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 937 | |
Naga Chumbalkar | ec26985 | 2010-02-09 00:42:02 +0100 | [diff] [blame] | 938 | return ret; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 939 | } |
| 940 | |
Wim Van Sebroeck | 08113e3 | 2007-08-31 08:15:34 +0000 | [diff] [blame] | 941 | static int __devexit iTCO_wdt_remove(struct platform_device *dev) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 942 | { |
| 943 | if (iTCO_wdt_private.ACPIBASE) |
| 944 | iTCO_wdt_cleanup(); |
| 945 | |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | static void iTCO_wdt_shutdown(struct platform_device *dev) |
| 950 | { |
| 951 | iTCO_wdt_stop(); |
| 952 | } |
| 953 | |
| 954 | #define iTCO_wdt_suspend NULL |
| 955 | #define iTCO_wdt_resume NULL |
| 956 | |
| 957 | static struct platform_driver iTCO_wdt_driver = { |
| 958 | .probe = iTCO_wdt_probe, |
Wim Van Sebroeck | 08113e3 | 2007-08-31 08:15:34 +0000 | [diff] [blame] | 959 | .remove = __devexit_p(iTCO_wdt_remove), |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 960 | .shutdown = iTCO_wdt_shutdown, |
| 961 | .suspend = iTCO_wdt_suspend, |
| 962 | .resume = iTCO_wdt_resume, |
| 963 | .driver = { |
| 964 | .owner = THIS_MODULE, |
| 965 | .name = DRV_NAME, |
| 966 | }, |
| 967 | }; |
| 968 | |
| 969 | static int __init iTCO_wdt_init_module(void) |
| 970 | { |
| 971 | int err; |
| 972 | |
Wim Van Sebroeck | 7cd5b08 | 2008-11-19 19:39:58 +0000 | [diff] [blame] | 973 | printk(KERN_INFO PFX "Intel TCO WatchDog Timer Driver v%s\n", |
| 974 | DRV_VERSION); |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 975 | |
| 976 | err = platform_driver_register(&iTCO_wdt_driver); |
| 977 | if (err) |
| 978 | return err; |
| 979 | |
Alan Cox | 0e6fa3f | 2008-05-19 14:06:25 +0100 | [diff] [blame] | 980 | iTCO_wdt_platform_device = platform_device_register_simple(DRV_NAME, |
| 981 | -1, NULL, 0); |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 982 | if (IS_ERR(iTCO_wdt_platform_device)) { |
| 983 | err = PTR_ERR(iTCO_wdt_platform_device); |
| 984 | goto unreg_platform_driver; |
| 985 | } |
| 986 | |
| 987 | return 0; |
| 988 | |
| 989 | unreg_platform_driver: |
| 990 | platform_driver_unregister(&iTCO_wdt_driver); |
| 991 | return err; |
| 992 | } |
| 993 | |
| 994 | static void __exit iTCO_wdt_cleanup_module(void) |
| 995 | { |
| 996 | platform_device_unregister(iTCO_wdt_platform_device); |
| 997 | platform_driver_unregister(&iTCO_wdt_driver); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 998 | printk(KERN_INFO PFX "Watchdog Module Unloaded.\n"); |
| 999 | } |
| 1000 | |
| 1001 | module_init(iTCO_wdt_init_module); |
| 1002 | module_exit(iTCO_wdt_cleanup_module); |
| 1003 | |
| 1004 | MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>"); |
| 1005 | MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver"); |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 1006 | MODULE_VERSION(DRV_VERSION); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 1007 | MODULE_LICENSE("GPL"); |
| 1008 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |