blob: a619b9b74991ae4c4ef072eb818cdd0df723ba5e [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"
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000043#define DRV_VERSION "1.05"
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 Heasley3c9d8ec2010-01-14 20:58:05 +0000118 TCO_CPTD, /* CPT Desktop */
119 TCO_CPTM, /* CPT Mobile */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200120};
121
122static struct {
123 char *name;
124 unsigned int iTCO_version;
125} iTCO_chipset_info[] __devinitdata = {
126 {"ICH", 1},
127 {"ICH0", 1},
128 {"ICH2", 1},
129 {"ICH2-M", 1},
130 {"ICH3-S", 1},
131 {"ICH3-M", 1},
132 {"ICH4", 1},
133 {"ICH4-M", 1},
134 {"C-ICH", 1},
135 {"ICH5 or ICH5R", 1},
136 {"6300ESB", 1},
137 {"ICH6 or ICH6R", 2},
138 {"ICH6-M", 2},
139 {"ICH6W or ICH6RW", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000140 {"631xESB/632xESB", 2},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200141 {"ICH7 or ICH7R", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000142 {"ICH7DH", 2},
143 {"ICH7-M or ICH7-U", 2},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200144 {"ICH7-M DH", 2},
Arnaud Patard (Rtp)bcbf25b2006-10-04 14:18:29 +0200145 {"ICH8 or ICH8R", 2},
Wim Van Sebroecka8edd742006-10-08 21:05:21 +0200146 {"ICH8DH", 2},
147 {"ICH8DO", 2},
Wim Van Sebroeckacf60352007-08-31 08:23:10 +0000148 {"ICH8M", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000149 {"ICH8M-E", 2},
Wim Van Sebroeck286201d2007-07-26 21:11:28 +0000150 {"ICH9", 2},
151 {"ICH9R", 2},
152 {"ICH9DH", 2},
Gabriel Ca49056d2008-04-30 16:51:10 +0200153 {"ICH9DO", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000154 {"ICH9M", 2},
155 {"ICH9M-E", 2},
156 {"ICH10", 2},
157 {"ICH10R", 2},
158 {"ICH10D", 2},
159 {"ICH10DO", 2},
Seth Heasley79e89412009-11-11 02:24:01 +0100160 {"PCH Desktop Full Featured", 2},
161 {"PCH Mobile Full Featured", 2},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000162 {"P55", 2},
163 {"PM55", 2},
164 {"H55", 2},
165 {"QM57", 2},
166 {"H57", 2},
167 {"HM55", 2},
168 {"Q57", 2},
169 {"HM57", 2},
Seth Heasley79e89412009-11-11 02:24:01 +0100170 {"PCH Mobile SFF Full Featured", 2},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000171 {"QS57", 2},
172 {"3400", 2},
173 {"3420", 2},
174 {"3450", 2},
Imre Kaloz4946f832009-12-07 20:42:26 +0100175 {"EP80579", 2},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000176 {"CPT Desktop", 2},
177 {"CPT Mobile", 2},
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100178 {NULL, 0}
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200179};
180
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000181#define ITCO_PCI_DEVICE(dev, data) \
182 .vendor = PCI_VENDOR_ID_INTEL, \
183 .device = dev, \
184 .subvendor = PCI_ANY_ID, \
185 .subdevice = PCI_ANY_ID, \
186 .class = 0, \
187 .class_mask = 0, \
188 .driver_data = data
189
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200190/*
191 * This data only exists for exporting the supported PCI ids
192 * via MODULE_DEVICE_TABLE. We do not actually register a
193 * pci_driver, because the I/O Controller Hub has also other
194 * functions that probably will be registered by other drivers.
195 */
196static struct pci_device_id iTCO_wdt_pci_tbl[] = {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100197 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801AA_0, TCO_ICH)},
198 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801AB_0, TCO_ICH0)},
199 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801BA_0, TCO_ICH2)},
200 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801BA_10, TCO_ICH2M)},
201 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801CA_0, TCO_ICH3)},
202 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801CA_12, TCO_ICH3M)},
203 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801DB_0, TCO_ICH4)},
204 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801DB_12, TCO_ICH4M)},
205 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801E_0, TCO_CICH)},
206 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801EB_0, TCO_ICH5)},
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000207 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB_1, TCO_6300ESB)},
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100208 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_0, TCO_ICH6)},
209 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_1, TCO_ICH6M)},
210 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_2, TCO_ICH6W)},
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000211 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB2_0, TCO_631XESB)},
212 { ITCO_PCI_DEVICE(0x2671, TCO_631XESB)},
213 { ITCO_PCI_DEVICE(0x2672, TCO_631XESB)},
214 { ITCO_PCI_DEVICE(0x2673, TCO_631XESB)},
215 { ITCO_PCI_DEVICE(0x2674, TCO_631XESB)},
216 { ITCO_PCI_DEVICE(0x2675, TCO_631XESB)},
217 { ITCO_PCI_DEVICE(0x2676, TCO_631XESB)},
218 { ITCO_PCI_DEVICE(0x2677, TCO_631XESB)},
219 { ITCO_PCI_DEVICE(0x2678, TCO_631XESB)},
220 { ITCO_PCI_DEVICE(0x2679, TCO_631XESB)},
221 { ITCO_PCI_DEVICE(0x267a, TCO_631XESB)},
222 { ITCO_PCI_DEVICE(0x267b, TCO_631XESB)},
223 { ITCO_PCI_DEVICE(0x267c, TCO_631XESB)},
224 { ITCO_PCI_DEVICE(0x267d, TCO_631XESB)},
225 { ITCO_PCI_DEVICE(0x267e, TCO_631XESB)},
226 { ITCO_PCI_DEVICE(0x267f, TCO_631XESB)},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000227 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_0, TCO_ICH7)},
228 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_30, TCO_ICH7DH)},
229 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_1, TCO_ICH7M)},
230 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_31, TCO_ICH7MDH)},
231 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_0, TCO_ICH8)},
232 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_2, TCO_ICH8DH)},
233 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_3, TCO_ICH8DO)},
234 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_4, TCO_ICH8M)},
235 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_1, TCO_ICH8ME)},
236 { ITCO_PCI_DEVICE(0x2918, TCO_ICH9)},
237 { ITCO_PCI_DEVICE(0x2916, TCO_ICH9R)},
238 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH9_2, TCO_ICH9DH)},
239 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH9_4, TCO_ICH9DO)},
240 { ITCO_PCI_DEVICE(0x2919, TCO_ICH9M)},
241 { ITCO_PCI_DEVICE(0x2917, TCO_ICH9ME)},
242 { ITCO_PCI_DEVICE(0x3a18, TCO_ICH10)},
243 { ITCO_PCI_DEVICE(0x3a16, TCO_ICH10R)},
244 { ITCO_PCI_DEVICE(0x3a1a, TCO_ICH10D)},
245 { ITCO_PCI_DEVICE(0x3a14, TCO_ICH10DO)},
Seth Heasley79e89412009-11-11 02:24:01 +0100246 { ITCO_PCI_DEVICE(0x3b00, TCO_PCH)},
247 { ITCO_PCI_DEVICE(0x3b01, TCO_PCHM)},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000248 { ITCO_PCI_DEVICE(0x3b02, TCO_P55)},
249 { ITCO_PCI_DEVICE(0x3b03, TCO_PM55)},
250 { ITCO_PCI_DEVICE(0x3b06, TCO_H55)},
251 { ITCO_PCI_DEVICE(0x3b07, TCO_QM57)},
252 { ITCO_PCI_DEVICE(0x3b08, TCO_H57)},
253 { ITCO_PCI_DEVICE(0x3b09, TCO_HM55)},
254 { ITCO_PCI_DEVICE(0x3b0a, TCO_Q57)},
255 { ITCO_PCI_DEVICE(0x3b0b, TCO_HM57)},
Seth Heasley79e89412009-11-11 02:24:01 +0100256 { ITCO_PCI_DEVICE(0x3b0d, TCO_PCHMSFF)},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000257 { ITCO_PCI_DEVICE(0x3b0f, TCO_QS57)},
258 { ITCO_PCI_DEVICE(0x3b12, TCO_3400)},
259 { ITCO_PCI_DEVICE(0x3b14, TCO_3420)},
260 { ITCO_PCI_DEVICE(0x3b16, TCO_3450)},
Imre Kaloz4946f832009-12-07 20:42:26 +0100261 { ITCO_PCI_DEVICE(0x5031, TCO_EP80579)},
Seth Heasley3c9d8ec2010-01-14 20:58:05 +0000262 { ITCO_PCI_DEVICE(0x1c42, TCO_CPTD)},
263 { ITCO_PCI_DEVICE(0x1c43, TCO_CPTM)},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200264 { 0, }, /* End of list */
265};
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100266MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200267
268/* Address definitions for the TCO */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100269/* TCO base address */
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000270#define TCOBASE (iTCO_wdt_private.ACPIBASE + 0x60)
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100271/* SMI Control and Enable Register */
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000272#define SMI_EN (iTCO_wdt_private.ACPIBASE + 0x30)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200273
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000274#define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload and Curr. Value */
275#define TCOv1_TMR (TCOBASE + 0x01) /* TCOv1 Timer Initial Value */
276#define TCO_DAT_IN (TCOBASE + 0x02) /* TCO Data In Register */
277#define TCO_DAT_OUT (TCOBASE + 0x03) /* TCO Data Out Register */
278#define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */
279#define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */
280#define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */
281#define TCO2_CNT (TCOBASE + 0x0a) /* TCO2 Control Register */
282#define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200283
284/* internal variables */
285static unsigned long is_active;
286static char expect_release;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100287static struct { /* this is private data for the iTCO_wdt device */
288 /* TCO version/generation */
289 unsigned int iTCO_version;
290 /* The cards ACPIBASE address (TCOBASE = ACPIBASE+0x60) */
291 unsigned long ACPIBASE;
292 /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2)*/
293 unsigned long __iomem *gcs;
294 /* the lock for io operations */
295 spinlock_t io_lock;
296 /* the PCI-device */
297 struct pci_dev *pdev;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200298} iTCO_wdt_private;
299
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100300/* the watchdog platform device */
301static struct platform_device *iTCO_wdt_platform_device;
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200302
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200303/* module parameters */
304#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
305static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
306module_param(heartbeat, int, 0);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000307MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. "
308 "(2<heartbeat<39 (TCO v1) or 613 (TCO v2), default="
309 __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200310
311static int nowayout = WATCHDOG_NOWAYOUT;
312module_param(nowayout, int, 0);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100313MODULE_PARM_DESC(nowayout,
314 "Watchdog cannot be stopped once started (default="
315 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100316
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200317/*
318 * Some TCO specific functions
319 */
320
321static inline unsigned int seconds_to_ticks(int seconds)
322{
323 /* the internal timer is stored as ticks which decrement
324 * every 0.6 seconds */
325 return (seconds * 10) / 6;
326}
327
328static void iTCO_wdt_set_NO_REBOOT_bit(void)
329{
330 u32 val32;
331
332 /* Set the NO_REBOOT bit: this disables reboots */
333 if (iTCO_wdt_private.iTCO_version == 2) {
334 val32 = readl(iTCO_wdt_private.gcs);
335 val32 |= 0x00000020;
336 writel(val32, iTCO_wdt_private.gcs);
337 } else if (iTCO_wdt_private.iTCO_version == 1) {
338 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
339 val32 |= 0x00000002;
340 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
341 }
342}
343
344static int iTCO_wdt_unset_NO_REBOOT_bit(void)
345{
346 int ret = 0;
347 u32 val32;
348
349 /* Unset the NO_REBOOT bit: this enables reboots */
350 if (iTCO_wdt_private.iTCO_version == 2) {
351 val32 = readl(iTCO_wdt_private.gcs);
352 val32 &= 0xffffffdf;
353 writel(val32, iTCO_wdt_private.gcs);
354
355 val32 = readl(iTCO_wdt_private.gcs);
356 if (val32 & 0x00000020)
357 ret = -EIO;
358 } else if (iTCO_wdt_private.iTCO_version == 1) {
359 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
360 val32 &= 0xfffffffd;
361 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
362
363 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
364 if (val32 & 0x00000002)
365 ret = -EIO;
366 }
367
368 return ret; /* returns: 0 = OK, -EIO = Error */
369}
370
371static int iTCO_wdt_start(void)
372{
373 unsigned int val;
374
375 spin_lock(&iTCO_wdt_private.io_lock);
376
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100377 iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat);
378
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200379 /* disable chipset's NO_REBOOT bit */
380 if (iTCO_wdt_unset_NO_REBOOT_bit()) {
Roel Kluin2ba7d7b2007-10-23 03:08:27 +0200381 spin_unlock(&iTCO_wdt_private.io_lock);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000382 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, "
383 "reboot disabled by hardware\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200384 return -EIO;
385 }
386
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000387 /* Force the timer to its reload value by writing to the TCO_RLD
388 register */
389 if (iTCO_wdt_private.iTCO_version == 2)
390 outw(0x01, TCO_RLD);
391 else if (iTCO_wdt_private.iTCO_version == 1)
392 outb(0x01, TCO_RLD);
393
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200394 /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
395 val = inw(TCO1_CNT);
396 val &= 0xf7ff;
397 outw(val, TCO1_CNT);
398 val = inw(TCO1_CNT);
399 spin_unlock(&iTCO_wdt_private.io_lock);
400
401 if (val & 0x0800)
402 return -1;
403 return 0;
404}
405
406static int iTCO_wdt_stop(void)
407{
408 unsigned int val;
409
410 spin_lock(&iTCO_wdt_private.io_lock);
411
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100412 iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE);
413
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200414 /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
415 val = inw(TCO1_CNT);
416 val |= 0x0800;
417 outw(val, TCO1_CNT);
418 val = inw(TCO1_CNT);
419
420 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
421 iTCO_wdt_set_NO_REBOOT_bit();
422
423 spin_unlock(&iTCO_wdt_private.io_lock);
424
425 if ((val & 0x0800) == 0)
426 return -1;
427 return 0;
428}
429
430static int iTCO_wdt_keepalive(void)
431{
432 spin_lock(&iTCO_wdt_private.io_lock);
433
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100434 iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat);
435
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200436 /* Reload the timer by writing to the TCO Timer Counter register */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100437 if (iTCO_wdt_private.iTCO_version == 2)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200438 outw(0x01, TCO_RLD);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100439 else if (iTCO_wdt_private.iTCO_version == 1)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200440 outb(0x01, TCO_RLD);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200441
442 spin_unlock(&iTCO_wdt_private.io_lock);
443 return 0;
444}
445
446static int iTCO_wdt_set_heartbeat(int t)
447{
448 unsigned int val16;
449 unsigned char val8;
450 unsigned int tmrval;
451
452 tmrval = seconds_to_ticks(t);
453 /* from the specs: */
454 /* "Values of 0h-3h are ignored and should not be attempted" */
455 if (tmrval < 0x04)
456 return -EINVAL;
457 if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) ||
458 ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
459 return -EINVAL;
460
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100461 iTCO_vendor_pre_set_heartbeat(tmrval);
462
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200463 /* Write new heartbeat to watchdog */
464 if (iTCO_wdt_private.iTCO_version == 2) {
465 spin_lock(&iTCO_wdt_private.io_lock);
466 val16 = inw(TCOv2_TMR);
467 val16 &= 0xfc00;
468 val16 |= tmrval;
469 outw(val16, TCOv2_TMR);
470 val16 = inw(TCOv2_TMR);
471 spin_unlock(&iTCO_wdt_private.io_lock);
472
473 if ((val16 & 0x3ff) != tmrval)
474 return -EINVAL;
475 } else if (iTCO_wdt_private.iTCO_version == 1) {
476 spin_lock(&iTCO_wdt_private.io_lock);
477 val8 = inb(TCOv1_TMR);
478 val8 &= 0xc0;
479 val8 |= (tmrval & 0xff);
480 outb(val8, TCOv1_TMR);
481 val8 = inb(TCOv1_TMR);
482 spin_unlock(&iTCO_wdt_private.io_lock);
483
484 if ((val8 & 0x3f) != tmrval)
485 return -EINVAL;
486 }
487
488 heartbeat = t;
489 return 0;
490}
491
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100492static int iTCO_wdt_get_timeleft(int *time_left)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200493{
494 unsigned int val16;
495 unsigned char val8;
496
497 /* read the TCO Timer */
498 if (iTCO_wdt_private.iTCO_version == 2) {
499 spin_lock(&iTCO_wdt_private.io_lock);
500 val16 = inw(TCO_RLD);
501 val16 &= 0x3ff;
502 spin_unlock(&iTCO_wdt_private.io_lock);
503
504 *time_left = (val16 * 6) / 10;
505 } else if (iTCO_wdt_private.iTCO_version == 1) {
506 spin_lock(&iTCO_wdt_private.io_lock);
507 val8 = inb(TCO_RLD);
508 val8 &= 0x3f;
509 spin_unlock(&iTCO_wdt_private.io_lock);
510
511 *time_left = (val8 * 6) / 10;
Jeff Garzik80060362006-10-10 03:40:44 -0400512 } else
513 return -EINVAL;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200514 return 0;
515}
516
517/*
518 * /dev/watchdog handling
519 */
520
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100521static int iTCO_wdt_open(struct inode *inode, struct file *file)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200522{
523 /* /dev/watchdog can only be opened once */
524 if (test_and_set_bit(0, &is_active))
525 return -EBUSY;
526
527 /*
528 * Reload and activate timer
529 */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200530 iTCO_wdt_start();
531 return nonseekable_open(inode, file);
532}
533
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100534static int iTCO_wdt_release(struct inode *inode, struct file *file)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200535{
536 /*
537 * Shut off the timer.
538 */
539 if (expect_release == 42) {
540 iTCO_wdt_stop();
541 } else {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100542 printk(KERN_CRIT PFX
543 "Unexpected close, not stopping watchdog!\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200544 iTCO_wdt_keepalive();
545 }
546 clear_bit(0, &is_active);
547 expect_release = 0;
548 return 0;
549}
550
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100551static ssize_t iTCO_wdt_write(struct file *file, const char __user *data,
552 size_t len, loff_t *ppos)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200553{
554 /* See if we got the magic character 'V' and reload the timer */
555 if (len) {
556 if (!nowayout) {
557 size_t i;
558
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100559 /* note: just in case someone wrote the magic
560 character five months ago... */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200561 expect_release = 0;
562
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100563 /* scan to see whether or not we got the
564 magic character */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200565 for (i = 0; i != len; i++) {
566 char c;
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +0000567 if (get_user(c, data + i))
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200568 return -EFAULT;
569 if (c == 'V')
570 expect_release = 42;
571 }
572 }
573
574 /* someone wrote to us, we should reload the timer */
575 iTCO_wdt_keepalive();
576 }
577 return len;
578}
579
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100580static long iTCO_wdt_ioctl(struct file *file, unsigned int cmd,
581 unsigned long arg)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200582{
583 int new_options, retval = -EINVAL;
584 int new_heartbeat;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200585 void __user *argp = (void __user *)arg;
586 int __user *p = argp;
587 static struct watchdog_info ident = {
588 .options = WDIOF_SETTIMEOUT |
589 WDIOF_KEEPALIVEPING |
590 WDIOF_MAGICCLOSE,
591 .firmware_version = 0,
592 .identity = DRV_NAME,
593 };
594
595 switch (cmd) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100596 case WDIOC_GETSUPPORT:
597 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
598 case WDIOC_GETSTATUS:
599 case WDIOC_GETBOOTSTATUS:
600 return put_user(0, p);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200601
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100602 case WDIOC_SETOPTIONS:
603 {
604 if (get_user(new_options, p))
605 return -EFAULT;
606
607 if (new_options & WDIOS_DISABLECARD) {
608 iTCO_wdt_stop();
609 retval = 0;
610 }
611 if (new_options & WDIOS_ENABLECARD) {
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200612 iTCO_wdt_keepalive();
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100613 iTCO_wdt_start();
614 retval = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200615 }
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100616 return retval;
617 }
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000618 case WDIOC_KEEPALIVE:
619 iTCO_wdt_keepalive();
620 return 0;
621
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100622 case WDIOC_SETTIMEOUT:
623 {
624 if (get_user(new_heartbeat, p))
625 return -EFAULT;
626 if (iTCO_wdt_set_heartbeat(new_heartbeat))
627 return -EINVAL;
628 iTCO_wdt_keepalive();
629 /* Fall */
630 }
631 case WDIOC_GETTIMEOUT:
632 return put_user(heartbeat, p);
633 case WDIOC_GETTIMELEFT:
634 {
635 int time_left;
636 if (iTCO_wdt_get_timeleft(&time_left))
637 return -EINVAL;
638 return put_user(time_left, p);
639 }
640 default:
641 return -ENOTTY;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200642 }
643}
644
645/*
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200646 * Kernel Interfaces
647 */
648
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800649static const struct file_operations iTCO_wdt_fops = {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100650 .owner = THIS_MODULE,
651 .llseek = no_llseek,
652 .write = iTCO_wdt_write,
653 .unlocked_ioctl = iTCO_wdt_ioctl,
654 .open = iTCO_wdt_open,
655 .release = iTCO_wdt_release,
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200656};
657
658static struct miscdevice iTCO_wdt_miscdev = {
659 .minor = WATCHDOG_MINOR,
660 .name = "watchdog",
661 .fops = &iTCO_wdt_fops,
662};
663
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200664/*
665 * Init & exit routines
666 */
667
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100668static int __devinit iTCO_wdt_init(struct pci_dev *pdev,
669 const struct pci_device_id *ent, struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200670{
671 int ret;
672 u32 base_address;
673 unsigned long RCBA;
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000674 unsigned long val32;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200675
676 /*
677 * Find the ACPI/PM base I/O address which is the base
678 * for the TCO registers (TCOBASE=ACPIBASE + 0x60)
679 * ACPIBASE is bits [15:7] from 0x40-0x43
680 */
681 pci_read_config_dword(pdev, 0x40, &base_address);
Wim Van Sebroeck0d4804b2007-05-11 18:59:24 +0000682 base_address &= 0x0000ff80;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200683 if (base_address == 0x00000000) {
684 /* Something's wrong here, ACPIBASE has to be set */
685 printk(KERN_ERR PFX "failed to get TCOBASE address\n");
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200686 pci_dev_put(pdev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200687 return -ENODEV;
688 }
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100689 iTCO_wdt_private.iTCO_version =
690 iTCO_chipset_info[ent->driver_data].iTCO_version;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200691 iTCO_wdt_private.ACPIBASE = base_address;
692 iTCO_wdt_private.pdev = pdev;
693
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100694 /* Get the Memory-Mapped GCS register, we need it for the
695 NO_REBOOT flag (TCO v2). To get access to it you have to
696 read RCBA from PCI Config space 0xf0 and use it as base.
697 GCS = RCBA + ICH6_GCS(0x3410). */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200698 if (iTCO_wdt_private.iTCO_version == 2) {
699 pci_read_config_dword(pdev, 0xf0, &base_address);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400700 if ((base_address & 1) == 0) {
Naga Chumbalkarec269852010-02-09 00:42:02 +0100701 printk(KERN_ERR PFX "RCBA is disabled by hardware\n");
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400702 ret = -ENODEV;
703 goto out;
704 }
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200705 RCBA = base_address & 0xffffc000;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100706 iTCO_wdt_private.gcs = ioremap((RCBA + 0x3410), 4);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200707 }
708
709 /* Check chipset's NO_REBOOT bit */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100710 if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
Naga Chumbalkarec269852010-02-09 00:42:02 +0100711 printk(KERN_INFO PFX "unable to reset NO_REBOOT flag, "
712 "platform may have disabled it\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200713 ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400714 goto out_unmap;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200715 }
716
717 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
718 iTCO_wdt_set_NO_REBOOT_bit();
719
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000720 /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200721 if (!request_region(SMI_EN, 4, "iTCO_wdt")) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100722 printk(KERN_ERR PFX
723 "I/O address 0x%04lx already in use\n", SMI_EN);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200724 ret = -EIO;
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400725 goto out_unmap;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200726 }
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000727 /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
728 val32 = inl(SMI_EN);
729 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
730 outl(val32, SMI_EN);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200731
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100732 /* The TCO I/O registers reside in a 32-byte range pointed to
733 by the TCOBASE value */
734 if (!request_region(TCOBASE, 0x20, "iTCO_wdt")) {
735 printk(KERN_ERR PFX "I/O address 0x%04lx already in use\n",
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200736 TCOBASE);
737 ret = -EIO;
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000738 goto unreg_smi_en;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200739 }
740
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100741 printk(KERN_INFO PFX
742 "Found a %s TCO device (Version=%d, TCOBASE=0x%04lx)\n",
743 iTCO_chipset_info[ent->driver_data].name,
744 iTCO_chipset_info[ent->driver_data].iTCO_version,
745 TCOBASE);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200746
747 /* Clear out the (probably old) status */
Wim Van Sebroeckc6904dd2008-11-19 20:02:02 +0000748 outb(8, TCO1_STS); /* Clear the Time Out Status bit */
749 outb(2, TCO2_STS); /* Clear SECOND_TO_STS bit */
750 outb(4, TCO2_STS); /* Clear BOOT_STS bit */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200751
752 /* Make sure the watchdog is not running */
753 iTCO_wdt_stop();
754
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100755 /* Check that the heartbeat value is within it's range;
756 if not reset to the default */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200757 if (iTCO_wdt_set_heartbeat(heartbeat)) {
758 iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000759 printk(KERN_INFO PFX
760 "heartbeat value must be 2 < heartbeat < 39 (TCO v1) "
761 "or 613 (TCO v2), using %d\n", heartbeat);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200762 }
763
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200764 ret = misc_register(&iTCO_wdt_miscdev);
765 if (ret != 0) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100766 printk(KERN_ERR PFX
767 "cannot register miscdev on minor=%d (err=%d)\n",
768 WATCHDOG_MINOR, ret);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200769 goto unreg_region;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200770 }
771
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100772 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
773 heartbeat, nowayout);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200774
775 return 0;
776
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200777unreg_region:
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100778 release_region(TCOBASE, 0x20);
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000779unreg_smi_en:
780 release_region(SMI_EN, 4);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400781out_unmap:
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200782 if (iTCO_wdt_private.iTCO_version == 2)
783 iounmap(iTCO_wdt_private.gcs);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400784out:
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200785 pci_dev_put(iTCO_wdt_private.pdev);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200786 iTCO_wdt_private.ACPIBASE = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200787 return ret;
788}
789
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000790static void __devexit iTCO_wdt_cleanup(void)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200791{
792 /* Stop the timer before we leave */
793 if (!nowayout)
794 iTCO_wdt_stop();
795
796 /* Deregister */
797 misc_deregister(&iTCO_wdt_miscdev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200798 release_region(TCOBASE, 0x20);
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000799 release_region(SMI_EN, 4);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200800 if (iTCO_wdt_private.iTCO_version == 2)
801 iounmap(iTCO_wdt_private.gcs);
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200802 pci_dev_put(iTCO_wdt_private.pdev);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200803 iTCO_wdt_private.ACPIBASE = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200804}
805
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000806static int __devinit iTCO_wdt_probe(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200807{
Naga Chumbalkarec269852010-02-09 00:42:02 +0100808 int ret = -ENODEV;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200809 int found = 0;
810 struct pci_dev *pdev = NULL;
811 const struct pci_device_id *ent;
812
813 spin_lock_init(&iTCO_wdt_private.io_lock);
814
815 for_each_pci_dev(pdev) {
816 ent = pci_match_id(iTCO_wdt_pci_tbl, pdev);
817 if (ent) {
Naga Chumbalkarec269852010-02-09 00:42:02 +0100818 found++;
819 ret = iTCO_wdt_init(pdev, ent, dev);
820 if (!ret)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200821 break;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200822 }
823 }
824
Naga Chumbalkarec269852010-02-09 00:42:02 +0100825 if (!found)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200826 printk(KERN_INFO PFX "No card detected\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200827
Naga Chumbalkarec269852010-02-09 00:42:02 +0100828 return ret;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200829}
830
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000831static int __devexit iTCO_wdt_remove(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200832{
833 if (iTCO_wdt_private.ACPIBASE)
834 iTCO_wdt_cleanup();
835
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200836 return 0;
837}
838
839static void iTCO_wdt_shutdown(struct platform_device *dev)
840{
841 iTCO_wdt_stop();
842}
843
844#define iTCO_wdt_suspend NULL
845#define iTCO_wdt_resume NULL
846
847static struct platform_driver iTCO_wdt_driver = {
848 .probe = iTCO_wdt_probe,
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000849 .remove = __devexit_p(iTCO_wdt_remove),
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200850 .shutdown = iTCO_wdt_shutdown,
851 .suspend = iTCO_wdt_suspend,
852 .resume = iTCO_wdt_resume,
853 .driver = {
854 .owner = THIS_MODULE,
855 .name = DRV_NAME,
856 },
857};
858
859static int __init iTCO_wdt_init_module(void)
860{
861 int err;
862
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000863 printk(KERN_INFO PFX "Intel TCO WatchDog Timer Driver v%s\n",
864 DRV_VERSION);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200865
866 err = platform_driver_register(&iTCO_wdt_driver);
867 if (err)
868 return err;
869
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100870 iTCO_wdt_platform_device = platform_device_register_simple(DRV_NAME,
871 -1, NULL, 0);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200872 if (IS_ERR(iTCO_wdt_platform_device)) {
873 err = PTR_ERR(iTCO_wdt_platform_device);
874 goto unreg_platform_driver;
875 }
876
877 return 0;
878
879unreg_platform_driver:
880 platform_driver_unregister(&iTCO_wdt_driver);
881 return err;
882}
883
884static void __exit iTCO_wdt_cleanup_module(void)
885{
886 platform_device_unregister(iTCO_wdt_platform_device);
887 platform_driver_unregister(&iTCO_wdt_driver);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200888 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
889}
890
891module_init(iTCO_wdt_init_module);
892module_exit(iTCO_wdt_cleanup_module);
893
894MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
895MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200896MODULE_VERSION(DRV_VERSION);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200897MODULE_LICENSE("GPL");
898MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);