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