blob: 4bd3877ad895217697f38ec207ad6b26110d02e9 [file] [log] [blame]
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +02001/*
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +00002 * intel TCO Watchdog Driver (Used in i82801 and i63xxESB chipsets)
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.)
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 Sebroeck28d41f52008-11-19 22:25:53 +000023 * 82801DB (ICH4) : document number 290744-001, 290745-025,
24 * 82801DBM (ICH4-M) : document number 252337-001, 252663-008,
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020025 * 82801E (C-ICH) : document number 273599-001, 273645-002,
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000026 * 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 Heasley79e89412009-11-11 02:24:01 +010057 * 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 Sebroeck9e0ea342006-05-21 14:37:44 +020060 */
61
62/*
63 * Includes, defines, variables, module parameters, ...
64 */
65
66/* Module and version information */
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +000067#define DRV_NAME "iTCO_wdt"
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000068#define DRV_VERSION "1.05"
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020069#define PFX DRV_NAME ": "
70
71/* Includes */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020072#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 Cox0e6fa3f2008-05-19 14:06:25 +010077#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
78 (WATCHDOG_MINOR) */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020079#include <linux/watchdog.h> /* For the watchdog specific items */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020080#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 Cox0e6fa3f2008-05-19 14:06:25 +010086#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
87#include <linux/io.h> /* For inb/outb/... */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020088
Alan Cox0e6fa3f2008-05-19 14:06:25 +010089#include "iTCO_vendor.h"
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020090
91/* TCO related info */
92enum 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 Sebroeck28d41f52008-11-19 22:25:53 +0000107 TCO_631XESB, /* 631xESB/632xESB */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200108 TCO_ICH7, /* ICH7 & ICH7R */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000109 TCO_ICH7DH, /* ICH7DH */
110 TCO_ICH7M, /* ICH7-M & ICH7-U */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200111 TCO_ICH7MDH, /* ICH7-M DH */
Wim Van Sebroecka8edd742006-10-08 21:05:21 +0200112 TCO_ICH8, /* ICH8 & ICH8R */
113 TCO_ICH8DH, /* ICH8DH */
114 TCO_ICH8DO, /* ICH8DO */
Wim Van Sebroeckacf60352007-08-31 08:23:10 +0000115 TCO_ICH8M, /* ICH8M */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000116 TCO_ICH8ME, /* ICH8M-E */
Wim Van Sebroeck286201d2007-07-26 21:11:28 +0000117 TCO_ICH9, /* ICH9 */
118 TCO_ICH9R, /* ICH9R */
119 TCO_ICH9DH, /* ICH9DH */
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +0000120 TCO_ICH9DO, /* ICH9DO */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000121 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 Heasley79e89412009-11-11 02:24:01 +0100127 TCO_PCH, /* PCH Desktop Full Featured */
128 TCO_PCHM, /* PCH Mobile Full Featured */
129 TCO_PCHMSFF, /* PCH Mobile SFF Full Featured */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200130};
131
132static 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 Sebroeck28d41f52008-11-19 22:25:53 +0000150 {"631xESB/632xESB", 2},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200151 {"ICH7 or ICH7R", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000152 {"ICH7DH", 2},
153 {"ICH7-M or ICH7-U", 2},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200154 {"ICH7-M DH", 2},
Arnaud Patard (Rtp)bcbf25b2006-10-04 14:18:29 +0200155 {"ICH8 or ICH8R", 2},
Wim Van Sebroecka8edd742006-10-08 21:05:21 +0200156 {"ICH8DH", 2},
157 {"ICH8DO", 2},
Wim Van Sebroeckacf60352007-08-31 08:23:10 +0000158 {"ICH8M", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000159 {"ICH8M-E", 2},
Wim Van Sebroeck286201d2007-07-26 21:11:28 +0000160 {"ICH9", 2},
161 {"ICH9R", 2},
162 {"ICH9DH", 2},
Gabriel Ca49056d2008-04-30 16:51:10 +0200163 {"ICH9DO", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000164 {"ICH9M", 2},
165 {"ICH9M-E", 2},
166 {"ICH10", 2},
167 {"ICH10R", 2},
168 {"ICH10D", 2},
169 {"ICH10DO", 2},
Seth Heasley79e89412009-11-11 02:24:01 +0100170 {"PCH Desktop Full Featured", 2},
171 {"PCH Mobile Full Featured", 2},
172 {"PCH Mobile SFF Full Featured", 2},
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100173 {NULL, 0}
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200174};
175
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000176#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 Sebroeck9e0ea342006-05-21 14:37:44 +0200185/*
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 */
191static struct pci_device_id iTCO_wdt_pci_tbl[] = {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100192 { 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 Sebroeckc87b6392007-08-19 20:17:58 +0000202 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB_1, TCO_6300ESB)},
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100203 { 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 Sebroeckc87b6392007-08-19 20:17:58 +0000206 { 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 Sebroeck28d41f52008-11-19 22:25:53 +0000222 { 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 Heasley79e89412009-11-11 02:24:01 +0100241 { ITCO_PCI_DEVICE(0x3b00, TCO_PCH)},
242 { ITCO_PCI_DEVICE(0x3b01, TCO_PCHM)},
243 { ITCO_PCI_DEVICE(0x3b0d, TCO_PCHMSFF)},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200244 { 0, }, /* End of list */
245};
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100246MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200247
248/* Address definitions for the TCO */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100249/* TCO base address */
Wim Van Sebroeck0a7e6582009-04-14 20:20:07 +0000250#define TCOBASE (iTCO_wdt_private.ACPIBASE + 0x60)
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100251/* SMI Control and Enable Register */
Wim Van Sebroeck0a7e6582009-04-14 20:20:07 +0000252#define SMI_EN (iTCO_wdt_private.ACPIBASE + 0x30)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200253
Wim Van Sebroeck0a7e6582009-04-14 20:20:07 +0000254#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 Sebroeck9e0ea342006-05-21 14:37:44 +0200263
264/* internal variables */
265static unsigned long is_active;
266static char expect_release;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100267static 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200278} iTCO_wdt_private;
279
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100280/* the watchdog platform device */
281static struct platform_device *iTCO_wdt_platform_device;
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200282
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200283/* module parameters */
284#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
285static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
286module_param(heartbeat, int, 0);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000287MODULE_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 Sebroeck9e0ea342006-05-21 14:37:44 +0200290
291static int nowayout = WATCHDOG_NOWAYOUT;
292module_param(nowayout, int, 0);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100293MODULE_PARM_DESC(nowayout,
294 "Watchdog cannot be stopped once started (default="
295 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100296
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200297/*
298 * Some TCO specific functions
299 */
300
301static 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
308static 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
324static 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
351static int iTCO_wdt_start(void)
352{
353 unsigned int val;
354
355 spin_lock(&iTCO_wdt_private.io_lock);
356
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100357 iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat);
358
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200359 /* disable chipset's NO_REBOOT bit */
360 if (iTCO_wdt_unset_NO_REBOOT_bit()) {
Roel Kluin2ba7d7b2007-10-23 03:08:27 +0200361 spin_unlock(&iTCO_wdt_private.io_lock);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000362 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, "
363 "reboot disabled by hardware\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200364 return -EIO;
365 }
366
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000367 /* 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200374 /* 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
386static int iTCO_wdt_stop(void)
387{
388 unsigned int val;
389
390 spin_lock(&iTCO_wdt_private.io_lock);
391
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100392 iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE);
393
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200394 /* 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
410static int iTCO_wdt_keepalive(void)
411{
412 spin_lock(&iTCO_wdt_private.io_lock);
413
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100414 iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat);
415
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200416 /* Reload the timer by writing to the TCO Timer Counter register */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100417 if (iTCO_wdt_private.iTCO_version == 2)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200418 outw(0x01, TCO_RLD);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100419 else if (iTCO_wdt_private.iTCO_version == 1)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200420 outb(0x01, TCO_RLD);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200421
422 spin_unlock(&iTCO_wdt_private.io_lock);
423 return 0;
424}
425
426static 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 Sebroecke0333512006-11-12 18:05:09 +0100441 iTCO_vendor_pre_set_heartbeat(tmrval);
442
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200443 /* 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 Cox0e6fa3f2008-05-19 14:06:25 +0100472static int iTCO_wdt_get_timeleft(int *time_left)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200473{
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 Garzik80060362006-10-10 03:40:44 -0400492 } else
493 return -EINVAL;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200494 return 0;
495}
496
497/*
498 * /dev/watchdog handling
499 */
500
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100501static int iTCO_wdt_open(struct inode *inode, struct file *file)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200502{
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 Sebroeck9e0ea342006-05-21 14:37:44 +0200510 iTCO_wdt_start();
511 return nonseekable_open(inode, file);
512}
513
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100514static int iTCO_wdt_release(struct inode *inode, struct file *file)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200515{
516 /*
517 * Shut off the timer.
518 */
519 if (expect_release == 42) {
520 iTCO_wdt_stop();
521 } else {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100522 printk(KERN_CRIT PFX
523 "Unexpected close, not stopping watchdog!\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200524 iTCO_wdt_keepalive();
525 }
526 clear_bit(0, &is_active);
527 expect_release = 0;
528 return 0;
529}
530
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100531static ssize_t iTCO_wdt_write(struct file *file, const char __user *data,
532 size_t len, loff_t *ppos)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200533{
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 Cox0e6fa3f2008-05-19 14:06:25 +0100539 /* note: just in case someone wrote the magic
540 character five months ago... */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200541 expect_release = 0;
542
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100543 /* scan to see whether or not we got the
544 magic character */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200545 for (i = 0; i != len; i++) {
546 char c;
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +0000547 if (get_user(c, data + i))
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200548 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 Cox0e6fa3f2008-05-19 14:06:25 +0100560static long iTCO_wdt_ioctl(struct file *file, unsigned int cmd,
561 unsigned long arg)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200562{
563 int new_options, retval = -EINVAL;
564 int new_heartbeat;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200565 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 Cox0e6fa3f2008-05-19 14:06:25 +0100576 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200581
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100582 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200592 iTCO_wdt_keepalive();
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100593 iTCO_wdt_start();
594 retval = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200595 }
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100596 return retval;
597 }
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000598 case WDIOC_KEEPALIVE:
599 iTCO_wdt_keepalive();
600 return 0;
601
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100602 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200622 }
623}
624
625/*
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200626 * Kernel Interfaces
627 */
628
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800629static const struct file_operations iTCO_wdt_fops = {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100630 .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 Sebroeck9e0ea342006-05-21 14:37:44 +0200636};
637
638static struct miscdevice iTCO_wdt_miscdev = {
639 .minor = WATCHDOG_MINOR,
640 .name = "watchdog",
641 .fops = &iTCO_wdt_fops,
642};
643
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200644/*
645 * Init & exit routines
646 */
647
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100648static int __devinit iTCO_wdt_init(struct pci_dev *pdev,
649 const struct pci_device_id *ent, struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200650{
651 int ret;
652 u32 base_address;
653 unsigned long RCBA;
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000654 unsigned long val32;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200655
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 Sebroeck0d4804b2007-05-11 18:59:24 +0000662 base_address &= 0x0000ff80;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200663 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 Sebroeck4802c652006-07-19 22:39:13 +0200666 pci_dev_put(pdev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200667 return -ENODEV;
668 }
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100669 iTCO_wdt_private.iTCO_version =
670 iTCO_chipset_info[ent->driver_data].iTCO_version;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200671 iTCO_wdt_private.ACPIBASE = base_address;
672 iTCO_wdt_private.pdev = pdev;
673
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100674 /* 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200678 if (iTCO_wdt_private.iTCO_version == 2) {
679 pci_read_config_dword(pdev, 0xf0, &base_address);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400680 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200685 RCBA = base_address & 0xffffc000;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100686 iTCO_wdt_private.gcs = ioremap((RCBA + 0x3410), 4);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200687 }
688
689 /* Check chipset's NO_REBOOT bit */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100690 if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000691 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, "
692 "reboot disabled by hardware\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200693 ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400694 goto out_unmap;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200695 }
696
697 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
698 iTCO_wdt_set_NO_REBOOT_bit();
699
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000700 /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200701 if (!request_region(SMI_EN, 4, "iTCO_wdt")) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100702 printk(KERN_ERR PFX
703 "I/O address 0x%04lx already in use\n", SMI_EN);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200704 ret = -EIO;
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400705 goto out_unmap;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200706 }
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000707 /* 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200711
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100712 /* 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200716 TCOBASE);
717 ret = -EIO;
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000718 goto unreg_smi_en;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200719 }
720
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100721 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200726
727 /* Clear out the (probably old) status */
Wim Van Sebroeckc6904dd2008-11-19 20:02:02 +0000728 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200731
732 /* Make sure the watchdog is not running */
733 iTCO_wdt_stop();
734
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100735 /* Check that the heartbeat value is within it's range;
736 if not reset to the default */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200737 if (iTCO_wdt_set_heartbeat(heartbeat)) {
738 iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000739 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200742 }
743
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200744 ret = misc_register(&iTCO_wdt_miscdev);
745 if (ret != 0) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100746 printk(KERN_ERR PFX
747 "cannot register miscdev on minor=%d (err=%d)\n",
748 WATCHDOG_MINOR, ret);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200749 goto unreg_region;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200750 }
751
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100752 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
753 heartbeat, nowayout);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200754
755 return 0;
756
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200757unreg_region:
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100758 release_region(TCOBASE, 0x20);
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000759unreg_smi_en:
760 release_region(SMI_EN, 4);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400761out_unmap:
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200762 if (iTCO_wdt_private.iTCO_version == 2)
763 iounmap(iTCO_wdt_private.gcs);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400764out:
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200765 pci_dev_put(iTCO_wdt_private.pdev);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200766 iTCO_wdt_private.ACPIBASE = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200767 return ret;
768}
769
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000770static void __devexit iTCO_wdt_cleanup(void)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200771{
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 Sebroeck9e0ea342006-05-21 14:37:44 +0200778 release_region(TCOBASE, 0x20);
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000779 release_region(SMI_EN, 4);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200780 if (iTCO_wdt_private.iTCO_version == 2)
781 iounmap(iTCO_wdt_private.gcs);
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200782 pci_dev_put(iTCO_wdt_private.pdev);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200783 iTCO_wdt_private.ACPIBASE = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200784}
785
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000786static int __devinit iTCO_wdt_probe(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200787{
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 Sebroeck3836cc02006-06-30 08:44:53 +0200797 if (!(iTCO_wdt_init(pdev, ent, dev))) {
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200798 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 Sebroeck08113e32007-08-31 08:15:34 +0000812static int __devexit iTCO_wdt_remove(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200813{
814 if (iTCO_wdt_private.ACPIBASE)
815 iTCO_wdt_cleanup();
816
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200817 return 0;
818}
819
820static 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
828static struct platform_driver iTCO_wdt_driver = {
829 .probe = iTCO_wdt_probe,
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000830 .remove = __devexit_p(iTCO_wdt_remove),
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200831 .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
840static int __init iTCO_wdt_init_module(void)
841{
842 int err;
843
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000844 printk(KERN_INFO PFX "Intel TCO WatchDog Timer Driver v%s\n",
845 DRV_VERSION);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200846
847 err = platform_driver_register(&iTCO_wdt_driver);
848 if (err)
849 return err;
850
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100851 iTCO_wdt_platform_device = platform_device_register_simple(DRV_NAME,
852 -1, NULL, 0);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200853 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
860unreg_platform_driver:
861 platform_driver_unregister(&iTCO_wdt_driver);
862 return err;
863}
864
865static 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 Sebroeck9e0ea342006-05-21 14:37:44 +0200869 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
870}
871
872module_init(iTCO_wdt_init_module);
873module_exit(iTCO_wdt_cleanup_module);
874
875MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
876MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200877MODULE_VERSION(DRV_VERSION);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200878MODULE_LICENSE("GPL");
879MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);