blob: cdc79450538de2c35592d47d32d2de0cc24f2631 [file] [log] [blame]
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +02001/*
Wim Van Sebroeckcb711a12009-11-15 13:44:54 +00002 * intel TCO Watchdog Driver
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +02003 *
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +00004 * (c) Copyright 2006-2009 Wim Van Sebroeck <wim@iguana.be>.
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +02005 *
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 Sebroeckcb711a12009-11-15 13:44:54 +000017 * 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)
29 * document number 313056-003, 313057-017: 82801H (ICH8)
30 * document number 316972-004, 316973-012: 82801I (ICH9)
31 * document number 319973-002, 319974-002: 82801J (ICH10)
Seth Heasley3c9d8ec2010-01-14 20:58:05 +000032 * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH)
Imre Kaloz4946f832009-12-07 20:42:26 +010033 * document number 320066-003, 320257-008: EP80597 (IICH)
Seth Heasley3c9d8ec2010-01-14 20:58:05 +000034 * document number TBD : Cougar Point (CPT)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020035 */
36
37/*
38 * Includes, defines, variables, module parameters, ...
39 */
40
41/* Module and version information */
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +000042#define DRV_NAME "iTCO_wdt"
Pádraig Brady7e6811d2010-04-19 13:38:25 +010043#define DRV_VERSION "1.06"
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020044#define PFX DRV_NAME ": "
45
46/* Includes */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020047#include <linux/module.h> /* For module specific items */
48#include <linux/moduleparam.h> /* For new moduleparam's */
49#include <linux/types.h> /* For standard types (like size_t) */
50#include <linux/errno.h> /* For the -ENODEV/... values */
51#include <linux/kernel.h> /* For printk/panic/... */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010052#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
53 (WATCHDOG_MINOR) */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020054#include <linux/watchdog.h> /* For the watchdog specific items */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020055#include <linux/init.h> /* For __init/__exit/... */
56#include <linux/fs.h> /* For file operations */
57#include <linux/platform_device.h> /* For platform_driver framework */
58#include <linux/pci.h> /* For pci functions */
59#include <linux/ioport.h> /* For io-port access */
60#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010061#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
62#include <linux/io.h> /* For inb/outb/... */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020063
Alan Cox0e6fa3f2008-05-19 14:06:25 +010064#include "iTCO_vendor.h"
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020065
66/* TCO related info */
67enum iTCO_chipsets {
68 TCO_ICH = 0, /* ICH */
69 TCO_ICH0, /* ICH0 */
70 TCO_ICH2, /* ICH2 */
71 TCO_ICH2M, /* ICH2-M */
72 TCO_ICH3, /* ICH3-S */
73 TCO_ICH3M, /* ICH3-M */
74 TCO_ICH4, /* ICH4 */
75 TCO_ICH4M, /* ICH4-M */
76 TCO_CICH, /* C-ICH */
77 TCO_ICH5, /* ICH5 & ICH5R */
78 TCO_6300ESB, /* 6300ESB */
79 TCO_ICH6, /* ICH6 & ICH6R */
80 TCO_ICH6M, /* ICH6-M */
81 TCO_ICH6W, /* ICH6W & ICH6RW */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000082 TCO_631XESB, /* 631xESB/632xESB */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020083 TCO_ICH7, /* ICH7 & ICH7R */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000084 TCO_ICH7DH, /* ICH7DH */
85 TCO_ICH7M, /* ICH7-M & ICH7-U */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020086 TCO_ICH7MDH, /* ICH7-M DH */
Wim Van Sebroecka8edd742006-10-08 21:05:21 +020087 TCO_ICH8, /* ICH8 & ICH8R */
88 TCO_ICH8DH, /* ICH8DH */
89 TCO_ICH8DO, /* ICH8DO */
Wim Van Sebroeckacf60352007-08-31 08:23:10 +000090 TCO_ICH8M, /* ICH8M */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000091 TCO_ICH8ME, /* ICH8M-E */
Wim Van Sebroeck286201d2007-07-26 21:11:28 +000092 TCO_ICH9, /* ICH9 */
93 TCO_ICH9R, /* ICH9R */
94 TCO_ICH9DH, /* ICH9DH */
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +000095 TCO_ICH9DO, /* ICH9DO */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000096 TCO_ICH9M, /* ICH9M */
97 TCO_ICH9ME, /* ICH9M-E */
98 TCO_ICH10, /* ICH10 */
99 TCO_ICH10R, /* ICH10R */
100 TCO_ICH10D, /* ICH10D */
101 TCO_ICH10DO, /* ICH10DO */
Seth Heasley79e89412009-11-11 02:24:01 +0100102 TCO_PCH, /* PCH Desktop Full Featured */
103 TCO_PCHM, /* PCH Mobile Full Featured */
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000104 TCO_P55, /* P55 */
105 TCO_PM55, /* PM55 */
106 TCO_H55, /* H55 */
107 TCO_QM57, /* QM57 */
108 TCO_H57, /* H57 */
109 TCO_HM55, /* HM55 */
110 TCO_Q57, /* Q57 */
111 TCO_HM57, /* HM57 */
Seth Heasley79e89412009-11-11 02:24:01 +0100112 TCO_PCHMSFF, /* PCH Mobile SFF Full Featured */
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000113 TCO_QS57, /* QS57 */
114 TCO_3400, /* 3400 */
115 TCO_3420, /* 3420 */
116 TCO_3450, /* 3450 */
Imre Kaloz4946f832009-12-07 20:42:26 +0100117 TCO_EP80579, /* EP80579 */
Seth Heasley4c7d8492010-03-25 16:14:41 -0700118 TCO_CPT1, /* Cougar Point */
119 TCO_CPT2, /* Cougar Point Desktop */
120 TCO_CPT3, /* Cougar Point Mobile */
121 TCO_CPT4, /* Cougar Point */
122 TCO_CPT5, /* Cougar Point */
123 TCO_CPT6, /* Cougar Point */
124 TCO_CPT7, /* Cougar Point */
125 TCO_CPT8, /* Cougar Point */
126 TCO_CPT9, /* Cougar Point */
127 TCO_CPT10, /* Cougar Point */
128 TCO_CPT11, /* Cougar Point */
129 TCO_CPT12, /* Cougar Point */
130 TCO_CPT13, /* Cougar Point */
131 TCO_CPT14, /* Cougar Point */
132 TCO_CPT15, /* Cougar Point */
133 TCO_CPT16, /* Cougar Point */
134 TCO_CPT17, /* Cougar Point */
135 TCO_CPT18, /* Cougar Point */
136 TCO_CPT19, /* Cougar Point */
137 TCO_CPT20, /* Cougar Point */
138 TCO_CPT21, /* Cougar Point */
139 TCO_CPT22, /* Cougar Point */
140 TCO_CPT23, /* Cougar Point */
141 TCO_CPT24, /* Cougar Point */
142 TCO_CPT25, /* Cougar Point */
143 TCO_CPT26, /* Cougar Point */
144 TCO_CPT27, /* Cougar Point */
145 TCO_CPT28, /* Cougar Point */
146 TCO_CPT29, /* Cougar Point */
147 TCO_CPT30, /* Cougar Point */
148 TCO_CPT31, /* Cougar Point */
Seth Heasleycad0df32010-09-09 09:58:03 -0700149 TCO_PBG, /* Patsburg */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200150};
151
152static struct {
153 char *name;
154 unsigned int iTCO_version;
155} iTCO_chipset_info[] __devinitdata = {
156 {"ICH", 1},
157 {"ICH0", 1},
158 {"ICH2", 1},
159 {"ICH2-M", 1},
160 {"ICH3-S", 1},
161 {"ICH3-M", 1},
162 {"ICH4", 1},
163 {"ICH4-M", 1},
164 {"C-ICH", 1},
165 {"ICH5 or ICH5R", 1},
166 {"6300ESB", 1},
167 {"ICH6 or ICH6R", 2},
168 {"ICH6-M", 2},
169 {"ICH6W or ICH6RW", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000170 {"631xESB/632xESB", 2},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200171 {"ICH7 or ICH7R", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000172 {"ICH7DH", 2},
173 {"ICH7-M or ICH7-U", 2},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200174 {"ICH7-M DH", 2},
Arnaud Patard (Rtp)bcbf25b2006-10-04 14:18:29 +0200175 {"ICH8 or ICH8R", 2},
Wim Van Sebroecka8edd742006-10-08 21:05:21 +0200176 {"ICH8DH", 2},
177 {"ICH8DO", 2},
Wim Van Sebroeckacf60352007-08-31 08:23:10 +0000178 {"ICH8M", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000179 {"ICH8M-E", 2},
Wim Van Sebroeck286201d2007-07-26 21:11:28 +0000180 {"ICH9", 2},
181 {"ICH9R", 2},
182 {"ICH9DH", 2},
Gabriel Ca49056d2008-04-30 16:51:10 +0200183 {"ICH9DO", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000184 {"ICH9M", 2},
185 {"ICH9M-E", 2},
186 {"ICH10", 2},
187 {"ICH10R", 2},
188 {"ICH10D", 2},
189 {"ICH10DO", 2},
Seth Heasley79e89412009-11-11 02:24:01 +0100190 {"PCH Desktop Full Featured", 2},
191 {"PCH Mobile Full Featured", 2},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000192 {"P55", 2},
193 {"PM55", 2},
194 {"H55", 2},
195 {"QM57", 2},
196 {"H57", 2},
197 {"HM55", 2},
198 {"Q57", 2},
199 {"HM57", 2},
Seth Heasley79e89412009-11-11 02:24:01 +0100200 {"PCH Mobile SFF Full Featured", 2},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000201 {"QS57", 2},
202 {"3400", 2},
203 {"3420", 2},
204 {"3450", 2},
Imre Kaloz4946f832009-12-07 20:42:26 +0100205 {"EP80579", 2},
Seth Heasley4c7d8492010-03-25 16:14:41 -0700206 {"Cougar Point", 2},
207 {"Cougar Point", 2},
208 {"Cougar Point", 2},
209 {"Cougar Point", 2},
210 {"Cougar Point", 2},
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},
Seth Heasleycad0df32010-09-09 09:58:03 -0700237 {"Patsburg", 2},
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100238 {NULL, 0}
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200239};
240
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000241#define ITCO_PCI_DEVICE(dev, data) \
242 .vendor = PCI_VENDOR_ID_INTEL, \
243 .device = dev, \
244 .subvendor = PCI_ANY_ID, \
245 .subdevice = PCI_ANY_ID, \
246 .class = 0, \
247 .class_mask = 0, \
248 .driver_data = data
249
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200250/*
251 * This data only exists for exporting the supported PCI ids
252 * via MODULE_DEVICE_TABLE. We do not actually register a
253 * pci_driver, because the I/O Controller Hub has also other
254 * functions that probably will be registered by other drivers.
255 */
256static struct pci_device_id iTCO_wdt_pci_tbl[] = {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100257 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801AA_0, TCO_ICH)},
258 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801AB_0, TCO_ICH0)},
259 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801BA_0, TCO_ICH2)},
260 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801BA_10, TCO_ICH2M)},
261 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801CA_0, TCO_ICH3)},
262 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801CA_12, TCO_ICH3M)},
263 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801DB_0, TCO_ICH4)},
264 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801DB_12, TCO_ICH4M)},
265 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801E_0, TCO_CICH)},
266 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801EB_0, TCO_ICH5)},
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000267 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB_1, TCO_6300ESB)},
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100268 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_0, TCO_ICH6)},
269 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_1, TCO_ICH6M)},
270 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_2, TCO_ICH6W)},
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000271 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB2_0, TCO_631XESB)},
272 { ITCO_PCI_DEVICE(0x2671, TCO_631XESB)},
273 { ITCO_PCI_DEVICE(0x2672, TCO_631XESB)},
274 { ITCO_PCI_DEVICE(0x2673, TCO_631XESB)},
275 { ITCO_PCI_DEVICE(0x2674, TCO_631XESB)},
276 { ITCO_PCI_DEVICE(0x2675, TCO_631XESB)},
277 { ITCO_PCI_DEVICE(0x2676, TCO_631XESB)},
278 { ITCO_PCI_DEVICE(0x2677, TCO_631XESB)},
279 { ITCO_PCI_DEVICE(0x2678, TCO_631XESB)},
280 { ITCO_PCI_DEVICE(0x2679, TCO_631XESB)},
281 { ITCO_PCI_DEVICE(0x267a, TCO_631XESB)},
282 { ITCO_PCI_DEVICE(0x267b, TCO_631XESB)},
283 { ITCO_PCI_DEVICE(0x267c, TCO_631XESB)},
284 { ITCO_PCI_DEVICE(0x267d, TCO_631XESB)},
285 { ITCO_PCI_DEVICE(0x267e, TCO_631XESB)},
286 { ITCO_PCI_DEVICE(0x267f, TCO_631XESB)},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000287 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_0, TCO_ICH7)},
288 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_30, TCO_ICH7DH)},
289 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_1, TCO_ICH7M)},
290 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_31, TCO_ICH7MDH)},
291 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_0, TCO_ICH8)},
292 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_2, TCO_ICH8DH)},
293 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_3, TCO_ICH8DO)},
294 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_4, TCO_ICH8M)},
295 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_1, TCO_ICH8ME)},
296 { ITCO_PCI_DEVICE(0x2918, TCO_ICH9)},
297 { ITCO_PCI_DEVICE(0x2916, TCO_ICH9R)},
298 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH9_2, TCO_ICH9DH)},
299 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH9_4, TCO_ICH9DO)},
300 { ITCO_PCI_DEVICE(0x2919, TCO_ICH9M)},
301 { ITCO_PCI_DEVICE(0x2917, TCO_ICH9ME)},
302 { ITCO_PCI_DEVICE(0x3a18, TCO_ICH10)},
303 { ITCO_PCI_DEVICE(0x3a16, TCO_ICH10R)},
304 { ITCO_PCI_DEVICE(0x3a1a, TCO_ICH10D)},
305 { ITCO_PCI_DEVICE(0x3a14, TCO_ICH10DO)},
Seth Heasley79e89412009-11-11 02:24:01 +0100306 { ITCO_PCI_DEVICE(0x3b00, TCO_PCH)},
307 { ITCO_PCI_DEVICE(0x3b01, TCO_PCHM)},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000308 { ITCO_PCI_DEVICE(0x3b02, TCO_P55)},
309 { ITCO_PCI_DEVICE(0x3b03, TCO_PM55)},
310 { ITCO_PCI_DEVICE(0x3b06, TCO_H55)},
311 { ITCO_PCI_DEVICE(0x3b07, TCO_QM57)},
312 { ITCO_PCI_DEVICE(0x3b08, TCO_H57)},
313 { ITCO_PCI_DEVICE(0x3b09, TCO_HM55)},
314 { ITCO_PCI_DEVICE(0x3b0a, TCO_Q57)},
315 { ITCO_PCI_DEVICE(0x3b0b, TCO_HM57)},
Seth Heasley79e89412009-11-11 02:24:01 +0100316 { ITCO_PCI_DEVICE(0x3b0d, TCO_PCHMSFF)},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000317 { ITCO_PCI_DEVICE(0x3b0f, TCO_QS57)},
318 { ITCO_PCI_DEVICE(0x3b12, TCO_3400)},
319 { ITCO_PCI_DEVICE(0x3b14, TCO_3420)},
320 { ITCO_PCI_DEVICE(0x3b16, TCO_3450)},
Imre Kaloz4946f832009-12-07 20:42:26 +0100321 { ITCO_PCI_DEVICE(0x5031, TCO_EP80579)},
Seth Heasley4c7d8492010-03-25 16:14:41 -0700322 { ITCO_PCI_DEVICE(0x1c41, TCO_CPT1)},
323 { ITCO_PCI_DEVICE(0x1c42, TCO_CPT2)},
324 { ITCO_PCI_DEVICE(0x1c43, TCO_CPT3)},
325 { ITCO_PCI_DEVICE(0x1c44, TCO_CPT4)},
326 { ITCO_PCI_DEVICE(0x1c45, TCO_CPT5)},
327 { ITCO_PCI_DEVICE(0x1c46, TCO_CPT6)},
328 { ITCO_PCI_DEVICE(0x1c47, TCO_CPT7)},
329 { ITCO_PCI_DEVICE(0x1c48, TCO_CPT8)},
330 { ITCO_PCI_DEVICE(0x1c49, TCO_CPT9)},
331 { ITCO_PCI_DEVICE(0x1c4a, TCO_CPT10)},
332 { ITCO_PCI_DEVICE(0x1c4b, TCO_CPT11)},
333 { ITCO_PCI_DEVICE(0x1c4c, TCO_CPT12)},
334 { ITCO_PCI_DEVICE(0x1c4d, TCO_CPT13)},
335 { ITCO_PCI_DEVICE(0x1c4e, TCO_CPT14)},
336 { ITCO_PCI_DEVICE(0x1c4f, TCO_CPT15)},
337 { ITCO_PCI_DEVICE(0x1c50, TCO_CPT16)},
338 { ITCO_PCI_DEVICE(0x1c51, TCO_CPT17)},
339 { ITCO_PCI_DEVICE(0x1c52, TCO_CPT18)},
340 { ITCO_PCI_DEVICE(0x1c53, TCO_CPT19)},
341 { ITCO_PCI_DEVICE(0x1c54, TCO_CPT20)},
342 { ITCO_PCI_DEVICE(0x1c55, TCO_CPT21)},
343 { ITCO_PCI_DEVICE(0x1c56, TCO_CPT22)},
344 { ITCO_PCI_DEVICE(0x1c57, TCO_CPT23)},
345 { ITCO_PCI_DEVICE(0x1c58, TCO_CPT24)},
346 { ITCO_PCI_DEVICE(0x1c59, TCO_CPT25)},
347 { ITCO_PCI_DEVICE(0x1c5a, TCO_CPT26)},
348 { ITCO_PCI_DEVICE(0x1c5b, TCO_CPT27)},
349 { ITCO_PCI_DEVICE(0x1c5c, TCO_CPT28)},
350 { ITCO_PCI_DEVICE(0x1c5d, TCO_CPT29)},
351 { ITCO_PCI_DEVICE(0x1c5e, TCO_CPT30)},
352 { ITCO_PCI_DEVICE(0x1c5f, TCO_CPT31)},
Seth Heasleycad0df32010-09-09 09:58:03 -0700353 { ITCO_PCI_DEVICE(0x1d40, TCO_PBG)},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200354 { 0, }, /* End of list */
355};
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100356MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200357
358/* Address definitions for the TCO */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100359/* TCO base address */
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000360#define TCOBASE (iTCO_wdt_private.ACPIBASE + 0x60)
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100361/* SMI Control and Enable Register */
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000362#define SMI_EN (iTCO_wdt_private.ACPIBASE + 0x30)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200363
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000364#define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload and Curr. Value */
365#define TCOv1_TMR (TCOBASE + 0x01) /* TCOv1 Timer Initial Value */
366#define TCO_DAT_IN (TCOBASE + 0x02) /* TCO Data In Register */
367#define TCO_DAT_OUT (TCOBASE + 0x03) /* TCO Data Out Register */
368#define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */
369#define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */
370#define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */
371#define TCO2_CNT (TCOBASE + 0x0a) /* TCO2 Control Register */
372#define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200373
374/* internal variables */
375static unsigned long is_active;
376static char expect_release;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100377static struct { /* this is private data for the iTCO_wdt device */
378 /* TCO version/generation */
379 unsigned int iTCO_version;
380 /* The cards ACPIBASE address (TCOBASE = ACPIBASE+0x60) */
381 unsigned long ACPIBASE;
382 /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2)*/
383 unsigned long __iomem *gcs;
384 /* the lock for io operations */
385 spinlock_t io_lock;
386 /* the PCI-device */
387 struct pci_dev *pdev;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200388} iTCO_wdt_private;
389
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100390/* the watchdog platform device */
391static struct platform_device *iTCO_wdt_platform_device;
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200392
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200393/* module parameters */
394#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
395static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
396module_param(heartbeat, int, 0);
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100397MODULE_PARM_DESC(heartbeat, "Watchdog timeout in seconds. "
398 "5..76 (TCO v1) or 3..614 (TCO v2), default="
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000399 __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200400
401static int nowayout = WATCHDOG_NOWAYOUT;
402module_param(nowayout, int, 0);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100403MODULE_PARM_DESC(nowayout,
404 "Watchdog cannot be stopped once started (default="
405 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100406
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200407/*
408 * Some TCO specific functions
409 */
410
411static inline unsigned int seconds_to_ticks(int seconds)
412{
413 /* the internal timer is stored as ticks which decrement
414 * every 0.6 seconds */
415 return (seconds * 10) / 6;
416}
417
418static void iTCO_wdt_set_NO_REBOOT_bit(void)
419{
420 u32 val32;
421
422 /* Set the NO_REBOOT bit: this disables reboots */
423 if (iTCO_wdt_private.iTCO_version == 2) {
424 val32 = readl(iTCO_wdt_private.gcs);
425 val32 |= 0x00000020;
426 writel(val32, iTCO_wdt_private.gcs);
427 } else if (iTCO_wdt_private.iTCO_version == 1) {
428 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
429 val32 |= 0x00000002;
430 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
431 }
432}
433
434static int iTCO_wdt_unset_NO_REBOOT_bit(void)
435{
436 int ret = 0;
437 u32 val32;
438
439 /* Unset the NO_REBOOT bit: this enables reboots */
440 if (iTCO_wdt_private.iTCO_version == 2) {
441 val32 = readl(iTCO_wdt_private.gcs);
442 val32 &= 0xffffffdf;
443 writel(val32, iTCO_wdt_private.gcs);
444
445 val32 = readl(iTCO_wdt_private.gcs);
446 if (val32 & 0x00000020)
447 ret = -EIO;
448 } else if (iTCO_wdt_private.iTCO_version == 1) {
449 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
450 val32 &= 0xfffffffd;
451 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
452
453 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
454 if (val32 & 0x00000002)
455 ret = -EIO;
456 }
457
458 return ret; /* returns: 0 = OK, -EIO = Error */
459}
460
461static int iTCO_wdt_start(void)
462{
463 unsigned int val;
464
465 spin_lock(&iTCO_wdt_private.io_lock);
466
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100467 iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat);
468
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200469 /* disable chipset's NO_REBOOT bit */
470 if (iTCO_wdt_unset_NO_REBOOT_bit()) {
Roel Kluin2ba7d7b2007-10-23 03:08:27 +0200471 spin_unlock(&iTCO_wdt_private.io_lock);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000472 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, "
473 "reboot disabled by hardware\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200474 return -EIO;
475 }
476
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000477 /* Force the timer to its reload value by writing to the TCO_RLD
478 register */
479 if (iTCO_wdt_private.iTCO_version == 2)
480 outw(0x01, TCO_RLD);
481 else if (iTCO_wdt_private.iTCO_version == 1)
482 outb(0x01, TCO_RLD);
483
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200484 /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
485 val = inw(TCO1_CNT);
486 val &= 0xf7ff;
487 outw(val, TCO1_CNT);
488 val = inw(TCO1_CNT);
489 spin_unlock(&iTCO_wdt_private.io_lock);
490
491 if (val & 0x0800)
492 return -1;
493 return 0;
494}
495
496static int iTCO_wdt_stop(void)
497{
498 unsigned int val;
499
500 spin_lock(&iTCO_wdt_private.io_lock);
501
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100502 iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE);
503
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200504 /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
505 val = inw(TCO1_CNT);
506 val |= 0x0800;
507 outw(val, TCO1_CNT);
508 val = inw(TCO1_CNT);
509
510 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
511 iTCO_wdt_set_NO_REBOOT_bit();
512
513 spin_unlock(&iTCO_wdt_private.io_lock);
514
515 if ((val & 0x0800) == 0)
516 return -1;
517 return 0;
518}
519
520static int iTCO_wdt_keepalive(void)
521{
522 spin_lock(&iTCO_wdt_private.io_lock);
523
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100524 iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat);
525
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200526 /* Reload the timer by writing to the TCO Timer Counter register */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100527 if (iTCO_wdt_private.iTCO_version == 2)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200528 outw(0x01, TCO_RLD);
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100529 else if (iTCO_wdt_private.iTCO_version == 1) {
530 /* Reset the timeout status bit so that the timer
531 * needs to count down twice again before rebooting */
532 outw(0x0008, TCO1_STS); /* write 1 to clear bit */
533
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200534 outb(0x01, TCO_RLD);
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100535 }
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200536
537 spin_unlock(&iTCO_wdt_private.io_lock);
538 return 0;
539}
540
541static int iTCO_wdt_set_heartbeat(int t)
542{
543 unsigned int val16;
544 unsigned char val8;
545 unsigned int tmrval;
546
547 tmrval = seconds_to_ticks(t);
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100548
549 /* For TCO v1 the timer counts down twice before rebooting */
550 if (iTCO_wdt_private.iTCO_version == 1)
551 tmrval /= 2;
552
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200553 /* from the specs: */
554 /* "Values of 0h-3h are ignored and should not be attempted" */
555 if (tmrval < 0x04)
556 return -EINVAL;
557 if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) ||
558 ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
559 return -EINVAL;
560
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100561 iTCO_vendor_pre_set_heartbeat(tmrval);
562
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200563 /* Write new heartbeat to watchdog */
564 if (iTCO_wdt_private.iTCO_version == 2) {
565 spin_lock(&iTCO_wdt_private.io_lock);
566 val16 = inw(TCOv2_TMR);
567 val16 &= 0xfc00;
568 val16 |= tmrval;
569 outw(val16, TCOv2_TMR);
570 val16 = inw(TCOv2_TMR);
571 spin_unlock(&iTCO_wdt_private.io_lock);
572
573 if ((val16 & 0x3ff) != tmrval)
574 return -EINVAL;
575 } else if (iTCO_wdt_private.iTCO_version == 1) {
576 spin_lock(&iTCO_wdt_private.io_lock);
577 val8 = inb(TCOv1_TMR);
578 val8 &= 0xc0;
579 val8 |= (tmrval & 0xff);
580 outb(val8, TCOv1_TMR);
581 val8 = inb(TCOv1_TMR);
582 spin_unlock(&iTCO_wdt_private.io_lock);
583
584 if ((val8 & 0x3f) != tmrval)
585 return -EINVAL;
586 }
587
588 heartbeat = t;
589 return 0;
590}
591
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100592static int iTCO_wdt_get_timeleft(int *time_left)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200593{
594 unsigned int val16;
595 unsigned char val8;
596
597 /* read the TCO Timer */
598 if (iTCO_wdt_private.iTCO_version == 2) {
599 spin_lock(&iTCO_wdt_private.io_lock);
600 val16 = inw(TCO_RLD);
601 val16 &= 0x3ff;
602 spin_unlock(&iTCO_wdt_private.io_lock);
603
604 *time_left = (val16 * 6) / 10;
605 } else if (iTCO_wdt_private.iTCO_version == 1) {
606 spin_lock(&iTCO_wdt_private.io_lock);
607 val8 = inb(TCO_RLD);
608 val8 &= 0x3f;
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100609 if (!(inw(TCO1_STS) & 0x0008))
610 val8 += (inb(TCOv1_TMR) & 0x3f);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200611 spin_unlock(&iTCO_wdt_private.io_lock);
612
613 *time_left = (val8 * 6) / 10;
Jeff Garzik80060362006-10-10 03:40:44 -0400614 } else
615 return -EINVAL;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200616 return 0;
617}
618
619/*
620 * /dev/watchdog handling
621 */
622
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100623static int iTCO_wdt_open(struct inode *inode, struct file *file)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200624{
625 /* /dev/watchdog can only be opened once */
626 if (test_and_set_bit(0, &is_active))
627 return -EBUSY;
628
629 /*
630 * Reload and activate timer
631 */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200632 iTCO_wdt_start();
633 return nonseekable_open(inode, file);
634}
635
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100636static int iTCO_wdt_release(struct inode *inode, struct file *file)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200637{
638 /*
639 * Shut off the timer.
640 */
641 if (expect_release == 42) {
642 iTCO_wdt_stop();
643 } else {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100644 printk(KERN_CRIT PFX
645 "Unexpected close, not stopping watchdog!\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200646 iTCO_wdt_keepalive();
647 }
648 clear_bit(0, &is_active);
649 expect_release = 0;
650 return 0;
651}
652
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100653static ssize_t iTCO_wdt_write(struct file *file, const char __user *data,
654 size_t len, loff_t *ppos)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200655{
656 /* See if we got the magic character 'V' and reload the timer */
657 if (len) {
658 if (!nowayout) {
659 size_t i;
660
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100661 /* note: just in case someone wrote the magic
662 character five months ago... */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200663 expect_release = 0;
664
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100665 /* scan to see whether or not we got the
666 magic character */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200667 for (i = 0; i != len; i++) {
668 char c;
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +0000669 if (get_user(c, data + i))
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200670 return -EFAULT;
671 if (c == 'V')
672 expect_release = 42;
673 }
674 }
675
676 /* someone wrote to us, we should reload the timer */
677 iTCO_wdt_keepalive();
678 }
679 return len;
680}
681
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100682static long iTCO_wdt_ioctl(struct file *file, unsigned int cmd,
683 unsigned long arg)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200684{
685 int new_options, retval = -EINVAL;
686 int new_heartbeat;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200687 void __user *argp = (void __user *)arg;
688 int __user *p = argp;
Wim Van Sebroeck42747d72009-12-26 18:55:22 +0000689 static const struct watchdog_info ident = {
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200690 .options = WDIOF_SETTIMEOUT |
691 WDIOF_KEEPALIVEPING |
692 WDIOF_MAGICCLOSE,
693 .firmware_version = 0,
694 .identity = DRV_NAME,
695 };
696
697 switch (cmd) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100698 case WDIOC_GETSUPPORT:
699 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
700 case WDIOC_GETSTATUS:
701 case WDIOC_GETBOOTSTATUS:
702 return put_user(0, p);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200703
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100704 case WDIOC_SETOPTIONS:
705 {
706 if (get_user(new_options, p))
707 return -EFAULT;
708
709 if (new_options & WDIOS_DISABLECARD) {
710 iTCO_wdt_stop();
711 retval = 0;
712 }
713 if (new_options & WDIOS_ENABLECARD) {
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200714 iTCO_wdt_keepalive();
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100715 iTCO_wdt_start();
716 retval = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200717 }
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100718 return retval;
719 }
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000720 case WDIOC_KEEPALIVE:
721 iTCO_wdt_keepalive();
722 return 0;
723
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100724 case WDIOC_SETTIMEOUT:
725 {
726 if (get_user(new_heartbeat, p))
727 return -EFAULT;
728 if (iTCO_wdt_set_heartbeat(new_heartbeat))
729 return -EINVAL;
730 iTCO_wdt_keepalive();
731 /* Fall */
732 }
733 case WDIOC_GETTIMEOUT:
734 return put_user(heartbeat, p);
735 case WDIOC_GETTIMELEFT:
736 {
737 int time_left;
738 if (iTCO_wdt_get_timeleft(&time_left))
739 return -EINVAL;
740 return put_user(time_left, p);
741 }
742 default:
743 return -ENOTTY;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200744 }
745}
746
747/*
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200748 * Kernel Interfaces
749 */
750
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800751static const struct file_operations iTCO_wdt_fops = {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100752 .owner = THIS_MODULE,
753 .llseek = no_llseek,
754 .write = iTCO_wdt_write,
755 .unlocked_ioctl = iTCO_wdt_ioctl,
756 .open = iTCO_wdt_open,
757 .release = iTCO_wdt_release,
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200758};
759
760static struct miscdevice iTCO_wdt_miscdev = {
761 .minor = WATCHDOG_MINOR,
762 .name = "watchdog",
763 .fops = &iTCO_wdt_fops,
764};
765
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200766/*
767 * Init & exit routines
768 */
769
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100770static int __devinit iTCO_wdt_init(struct pci_dev *pdev,
771 const struct pci_device_id *ent, struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200772{
773 int ret;
774 u32 base_address;
775 unsigned long RCBA;
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000776 unsigned long val32;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200777
778 /*
779 * Find the ACPI/PM base I/O address which is the base
780 * for the TCO registers (TCOBASE=ACPIBASE + 0x60)
781 * ACPIBASE is bits [15:7] from 0x40-0x43
782 */
783 pci_read_config_dword(pdev, 0x40, &base_address);
Wim Van Sebroeck0d4804b2007-05-11 18:59:24 +0000784 base_address &= 0x0000ff80;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200785 if (base_address == 0x00000000) {
786 /* Something's wrong here, ACPIBASE has to be set */
787 printk(KERN_ERR PFX "failed to get TCOBASE address\n");
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200788 pci_dev_put(pdev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200789 return -ENODEV;
790 }
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100791 iTCO_wdt_private.iTCO_version =
792 iTCO_chipset_info[ent->driver_data].iTCO_version;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200793 iTCO_wdt_private.ACPIBASE = base_address;
794 iTCO_wdt_private.pdev = pdev;
795
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100796 /* Get the Memory-Mapped GCS register, we need it for the
797 NO_REBOOT flag (TCO v2). To get access to it you have to
798 read RCBA from PCI Config space 0xf0 and use it as base.
799 GCS = RCBA + ICH6_GCS(0x3410). */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200800 if (iTCO_wdt_private.iTCO_version == 2) {
801 pci_read_config_dword(pdev, 0xf0, &base_address);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400802 if ((base_address & 1) == 0) {
Naga Chumbalkarec269852010-02-09 00:42:02 +0100803 printk(KERN_ERR PFX "RCBA is disabled by hardware\n");
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400804 ret = -ENODEV;
805 goto out;
806 }
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200807 RCBA = base_address & 0xffffc000;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100808 iTCO_wdt_private.gcs = ioremap((RCBA + 0x3410), 4);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200809 }
810
811 /* Check chipset's NO_REBOOT bit */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100812 if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
Naga Chumbalkarec269852010-02-09 00:42:02 +0100813 printk(KERN_INFO PFX "unable to reset NO_REBOOT flag, "
814 "platform may have disabled it\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200815 ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400816 goto out_unmap;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200817 }
818
819 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
820 iTCO_wdt_set_NO_REBOOT_bit();
821
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000822 /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200823 if (!request_region(SMI_EN, 4, "iTCO_wdt")) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100824 printk(KERN_ERR PFX
825 "I/O address 0x%04lx already in use\n", SMI_EN);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200826 ret = -EIO;
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400827 goto out_unmap;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200828 }
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000829 /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
830 val32 = inl(SMI_EN);
831 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
832 outl(val32, SMI_EN);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200833
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100834 /* The TCO I/O registers reside in a 32-byte range pointed to
835 by the TCOBASE value */
836 if (!request_region(TCOBASE, 0x20, "iTCO_wdt")) {
837 printk(KERN_ERR PFX "I/O address 0x%04lx already in use\n",
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200838 TCOBASE);
839 ret = -EIO;
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000840 goto unreg_smi_en;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200841 }
842
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100843 printk(KERN_INFO PFX
844 "Found a %s TCO device (Version=%d, TCOBASE=0x%04lx)\n",
845 iTCO_chipset_info[ent->driver_data].name,
846 iTCO_chipset_info[ent->driver_data].iTCO_version,
847 TCOBASE);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200848
849 /* Clear out the (probably old) status */
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100850 outw(0x0008, TCO1_STS); /* Clear the Time Out Status bit */
851 outw(0x0002, TCO2_STS); /* Clear SECOND_TO_STS bit */
852 outw(0x0004, TCO2_STS); /* Clear BOOT_STS bit */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200853
854 /* Make sure the watchdog is not running */
855 iTCO_wdt_stop();
856
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100857 /* Check that the heartbeat value is within it's range;
858 if not reset to the default */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200859 if (iTCO_wdt_set_heartbeat(heartbeat)) {
860 iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000861 printk(KERN_INFO PFX
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100862 "timeout value out of range, using %d\n", heartbeat);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200863 }
864
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200865 ret = misc_register(&iTCO_wdt_miscdev);
866 if (ret != 0) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100867 printk(KERN_ERR PFX
868 "cannot register miscdev on minor=%d (err=%d)\n",
869 WATCHDOG_MINOR, ret);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200870 goto unreg_region;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200871 }
872
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100873 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
874 heartbeat, nowayout);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200875
876 return 0;
877
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200878unreg_region:
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100879 release_region(TCOBASE, 0x20);
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000880unreg_smi_en:
881 release_region(SMI_EN, 4);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400882out_unmap:
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200883 if (iTCO_wdt_private.iTCO_version == 2)
884 iounmap(iTCO_wdt_private.gcs);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400885out:
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200886 pci_dev_put(iTCO_wdt_private.pdev);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200887 iTCO_wdt_private.ACPIBASE = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200888 return ret;
889}
890
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000891static void __devexit iTCO_wdt_cleanup(void)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200892{
893 /* Stop the timer before we leave */
894 if (!nowayout)
895 iTCO_wdt_stop();
896
897 /* Deregister */
898 misc_deregister(&iTCO_wdt_miscdev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200899 release_region(TCOBASE, 0x20);
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000900 release_region(SMI_EN, 4);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200901 if (iTCO_wdt_private.iTCO_version == 2)
902 iounmap(iTCO_wdt_private.gcs);
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200903 pci_dev_put(iTCO_wdt_private.pdev);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200904 iTCO_wdt_private.ACPIBASE = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200905}
906
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000907static int __devinit iTCO_wdt_probe(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200908{
Naga Chumbalkarec269852010-02-09 00:42:02 +0100909 int ret = -ENODEV;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200910 int found = 0;
911 struct pci_dev *pdev = NULL;
912 const struct pci_device_id *ent;
913
914 spin_lock_init(&iTCO_wdt_private.io_lock);
915
916 for_each_pci_dev(pdev) {
917 ent = pci_match_id(iTCO_wdt_pci_tbl, pdev);
918 if (ent) {
Naga Chumbalkarec269852010-02-09 00:42:02 +0100919 found++;
920 ret = iTCO_wdt_init(pdev, ent, dev);
921 if (!ret)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200922 break;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200923 }
924 }
925
Naga Chumbalkarec269852010-02-09 00:42:02 +0100926 if (!found)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200927 printk(KERN_INFO PFX "No card detected\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200928
Naga Chumbalkarec269852010-02-09 00:42:02 +0100929 return ret;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200930}
931
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000932static int __devexit iTCO_wdt_remove(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200933{
934 if (iTCO_wdt_private.ACPIBASE)
935 iTCO_wdt_cleanup();
936
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200937 return 0;
938}
939
940static void iTCO_wdt_shutdown(struct platform_device *dev)
941{
942 iTCO_wdt_stop();
943}
944
945#define iTCO_wdt_suspend NULL
946#define iTCO_wdt_resume NULL
947
948static struct platform_driver iTCO_wdt_driver = {
949 .probe = iTCO_wdt_probe,
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000950 .remove = __devexit_p(iTCO_wdt_remove),
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200951 .shutdown = iTCO_wdt_shutdown,
952 .suspend = iTCO_wdt_suspend,
953 .resume = iTCO_wdt_resume,
954 .driver = {
955 .owner = THIS_MODULE,
956 .name = DRV_NAME,
957 },
958};
959
960static int __init iTCO_wdt_init_module(void)
961{
962 int err;
963
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000964 printk(KERN_INFO PFX "Intel TCO WatchDog Timer Driver v%s\n",
965 DRV_VERSION);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200966
967 err = platform_driver_register(&iTCO_wdt_driver);
968 if (err)
969 return err;
970
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100971 iTCO_wdt_platform_device = platform_device_register_simple(DRV_NAME,
972 -1, NULL, 0);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200973 if (IS_ERR(iTCO_wdt_platform_device)) {
974 err = PTR_ERR(iTCO_wdt_platform_device);
975 goto unreg_platform_driver;
976 }
977
978 return 0;
979
980unreg_platform_driver:
981 platform_driver_unregister(&iTCO_wdt_driver);
982 return err;
983}
984
985static void __exit iTCO_wdt_cleanup_module(void)
986{
987 platform_device_unregister(iTCO_wdt_platform_device);
988 platform_driver_unregister(&iTCO_wdt_driver);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200989 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
990}
991
992module_init(iTCO_wdt_init_module);
993module_exit(iTCO_wdt_cleanup_module);
994
995MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
996MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200997MODULE_VERSION(DRV_VERSION);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200998MODULE_LICENSE("GPL");
999MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);