blob: e44fbb31bc6faa1a24582475b4ee82b64a4f1339 [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)
32 * document number 322169-001, 322170-001: 5 Series, 3400 Series (PCH)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020033 */
34
35/*
36 * Includes, defines, variables, module parameters, ...
37 */
38
39/* Module and version information */
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +000040#define DRV_NAME "iTCO_wdt"
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000041#define DRV_VERSION "1.05"
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020042#define PFX DRV_NAME ": "
43
44/* Includes */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020045#include <linux/module.h> /* For module specific items */
46#include <linux/moduleparam.h> /* For new moduleparam's */
47#include <linux/types.h> /* For standard types (like size_t) */
48#include <linux/errno.h> /* For the -ENODEV/... values */
49#include <linux/kernel.h> /* For printk/panic/... */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010050#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
51 (WATCHDOG_MINOR) */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020052#include <linux/watchdog.h> /* For the watchdog specific items */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020053#include <linux/init.h> /* For __init/__exit/... */
54#include <linux/fs.h> /* For file operations */
55#include <linux/platform_device.h> /* For platform_driver framework */
56#include <linux/pci.h> /* For pci functions */
57#include <linux/ioport.h> /* For io-port access */
58#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010059#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
60#include <linux/io.h> /* For inb/outb/... */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020061
Alan Cox0e6fa3f2008-05-19 14:06:25 +010062#include "iTCO_vendor.h"
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020063
64/* TCO related info */
65enum iTCO_chipsets {
66 TCO_ICH = 0, /* ICH */
67 TCO_ICH0, /* ICH0 */
68 TCO_ICH2, /* ICH2 */
69 TCO_ICH2M, /* ICH2-M */
70 TCO_ICH3, /* ICH3-S */
71 TCO_ICH3M, /* ICH3-M */
72 TCO_ICH4, /* ICH4 */
73 TCO_ICH4M, /* ICH4-M */
74 TCO_CICH, /* C-ICH */
75 TCO_ICH5, /* ICH5 & ICH5R */
76 TCO_6300ESB, /* 6300ESB */
77 TCO_ICH6, /* ICH6 & ICH6R */
78 TCO_ICH6M, /* ICH6-M */
79 TCO_ICH6W, /* ICH6W & ICH6RW */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000080 TCO_631XESB, /* 631xESB/632xESB */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020081 TCO_ICH7, /* ICH7 & ICH7R */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000082 TCO_ICH7DH, /* ICH7DH */
83 TCO_ICH7M, /* ICH7-M & ICH7-U */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020084 TCO_ICH7MDH, /* ICH7-M DH */
Wim Van Sebroecka8edd742006-10-08 21:05:21 +020085 TCO_ICH8, /* ICH8 & ICH8R */
86 TCO_ICH8DH, /* ICH8DH */
87 TCO_ICH8DO, /* ICH8DO */
Wim Van Sebroeckacf60352007-08-31 08:23:10 +000088 TCO_ICH8M, /* ICH8M */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000089 TCO_ICH8ME, /* ICH8M-E */
Wim Van Sebroeck286201d2007-07-26 21:11:28 +000090 TCO_ICH9, /* ICH9 */
91 TCO_ICH9R, /* ICH9R */
92 TCO_ICH9DH, /* ICH9DH */
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +000093 TCO_ICH9DO, /* ICH9DO */
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +000094 TCO_ICH9M, /* ICH9M */
95 TCO_ICH9ME, /* ICH9M-E */
96 TCO_ICH10, /* ICH10 */
97 TCO_ICH10R, /* ICH10R */
98 TCO_ICH10D, /* ICH10D */
99 TCO_ICH10DO, /* ICH10DO */
Seth Heasley79e89412009-11-11 02:24:01 +0100100 TCO_PCH, /* PCH Desktop Full Featured */
101 TCO_PCHM, /* PCH Mobile Full Featured */
102 TCO_PCHMSFF, /* PCH Mobile SFF Full Featured */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200103};
104
105static struct {
106 char *name;
107 unsigned int iTCO_version;
108} iTCO_chipset_info[] __devinitdata = {
109 {"ICH", 1},
110 {"ICH0", 1},
111 {"ICH2", 1},
112 {"ICH2-M", 1},
113 {"ICH3-S", 1},
114 {"ICH3-M", 1},
115 {"ICH4", 1},
116 {"ICH4-M", 1},
117 {"C-ICH", 1},
118 {"ICH5 or ICH5R", 1},
119 {"6300ESB", 1},
120 {"ICH6 or ICH6R", 2},
121 {"ICH6-M", 2},
122 {"ICH6W or ICH6RW", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000123 {"631xESB/632xESB", 2},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200124 {"ICH7 or ICH7R", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000125 {"ICH7DH", 2},
126 {"ICH7-M or ICH7-U", 2},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200127 {"ICH7-M DH", 2},
Arnaud Patard (Rtp)bcbf25b2006-10-04 14:18:29 +0200128 {"ICH8 or ICH8R", 2},
Wim Van Sebroecka8edd742006-10-08 21:05:21 +0200129 {"ICH8DH", 2},
130 {"ICH8DO", 2},
Wim Van Sebroeckacf60352007-08-31 08:23:10 +0000131 {"ICH8M", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000132 {"ICH8M-E", 2},
Wim Van Sebroeck286201d2007-07-26 21:11:28 +0000133 {"ICH9", 2},
134 {"ICH9R", 2},
135 {"ICH9DH", 2},
Gabriel Ca49056d2008-04-30 16:51:10 +0200136 {"ICH9DO", 2},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000137 {"ICH9M", 2},
138 {"ICH9M-E", 2},
139 {"ICH10", 2},
140 {"ICH10R", 2},
141 {"ICH10D", 2},
142 {"ICH10DO", 2},
Seth Heasley79e89412009-11-11 02:24:01 +0100143 {"PCH Desktop Full Featured", 2},
144 {"PCH Mobile Full Featured", 2},
145 {"PCH Mobile SFF Full Featured", 2},
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100146 {NULL, 0}
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200147};
148
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000149#define ITCO_PCI_DEVICE(dev, data) \
150 .vendor = PCI_VENDOR_ID_INTEL, \
151 .device = dev, \
152 .subvendor = PCI_ANY_ID, \
153 .subdevice = PCI_ANY_ID, \
154 .class = 0, \
155 .class_mask = 0, \
156 .driver_data = data
157
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200158/*
159 * This data only exists for exporting the supported PCI ids
160 * via MODULE_DEVICE_TABLE. We do not actually register a
161 * pci_driver, because the I/O Controller Hub has also other
162 * functions that probably will be registered by other drivers.
163 */
164static struct pci_device_id iTCO_wdt_pci_tbl[] = {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100165 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801AA_0, TCO_ICH)},
166 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801AB_0, TCO_ICH0)},
167 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801BA_0, TCO_ICH2)},
168 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801BA_10, TCO_ICH2M)},
169 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801CA_0, TCO_ICH3)},
170 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801CA_12, TCO_ICH3M)},
171 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801DB_0, TCO_ICH4)},
172 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801DB_12, TCO_ICH4M)},
173 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801E_0, TCO_CICH)},
174 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_82801EB_0, TCO_ICH5)},
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000175 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB_1, TCO_6300ESB)},
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100176 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_0, TCO_ICH6)},
177 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_1, TCO_ICH6M)},
178 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH6_2, TCO_ICH6W)},
Wim Van Sebroeckc87b6392007-08-19 20:17:58 +0000179 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ESB2_0, TCO_631XESB)},
180 { ITCO_PCI_DEVICE(0x2671, TCO_631XESB)},
181 { ITCO_PCI_DEVICE(0x2672, TCO_631XESB)},
182 { ITCO_PCI_DEVICE(0x2673, TCO_631XESB)},
183 { ITCO_PCI_DEVICE(0x2674, TCO_631XESB)},
184 { ITCO_PCI_DEVICE(0x2675, TCO_631XESB)},
185 { ITCO_PCI_DEVICE(0x2676, TCO_631XESB)},
186 { ITCO_PCI_DEVICE(0x2677, TCO_631XESB)},
187 { ITCO_PCI_DEVICE(0x2678, TCO_631XESB)},
188 { ITCO_PCI_DEVICE(0x2679, TCO_631XESB)},
189 { ITCO_PCI_DEVICE(0x267a, TCO_631XESB)},
190 { ITCO_PCI_DEVICE(0x267b, TCO_631XESB)},
191 { ITCO_PCI_DEVICE(0x267c, TCO_631XESB)},
192 { ITCO_PCI_DEVICE(0x267d, TCO_631XESB)},
193 { ITCO_PCI_DEVICE(0x267e, TCO_631XESB)},
194 { ITCO_PCI_DEVICE(0x267f, TCO_631XESB)},
Wim Van Sebroeck28d41f52008-11-19 22:25:53 +0000195 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_0, TCO_ICH7)},
196 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_30, TCO_ICH7DH)},
197 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_1, TCO_ICH7M)},
198 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_31, TCO_ICH7MDH)},
199 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_0, TCO_ICH8)},
200 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_2, TCO_ICH8DH)},
201 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_3, TCO_ICH8DO)},
202 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_4, TCO_ICH8M)},
203 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_1, TCO_ICH8ME)},
204 { ITCO_PCI_DEVICE(0x2918, TCO_ICH9)},
205 { ITCO_PCI_DEVICE(0x2916, TCO_ICH9R)},
206 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH9_2, TCO_ICH9DH)},
207 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH9_4, TCO_ICH9DO)},
208 { ITCO_PCI_DEVICE(0x2919, TCO_ICH9M)},
209 { ITCO_PCI_DEVICE(0x2917, TCO_ICH9ME)},
210 { ITCO_PCI_DEVICE(0x3a18, TCO_ICH10)},
211 { ITCO_PCI_DEVICE(0x3a16, TCO_ICH10R)},
212 { ITCO_PCI_DEVICE(0x3a1a, TCO_ICH10D)},
213 { ITCO_PCI_DEVICE(0x3a14, TCO_ICH10DO)},
Seth Heasley79e89412009-11-11 02:24:01 +0100214 { ITCO_PCI_DEVICE(0x3b00, TCO_PCH)},
215 { ITCO_PCI_DEVICE(0x3b01, TCO_PCHM)},
216 { ITCO_PCI_DEVICE(0x3b0d, TCO_PCHMSFF)},
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200217 { 0, }, /* End of list */
218};
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100219MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200220
221/* Address definitions for the TCO */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100222/* TCO base address */
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000223#define TCOBASE (iTCO_wdt_private.ACPIBASE + 0x60)
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100224/* SMI Control and Enable Register */
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000225#define SMI_EN (iTCO_wdt_private.ACPIBASE + 0x30)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200226
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +0000227#define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload and Curr. Value */
228#define TCOv1_TMR (TCOBASE + 0x01) /* TCOv1 Timer Initial Value */
229#define TCO_DAT_IN (TCOBASE + 0x02) /* TCO Data In Register */
230#define TCO_DAT_OUT (TCOBASE + 0x03) /* TCO Data Out Register */
231#define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */
232#define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */
233#define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */
234#define TCO2_CNT (TCOBASE + 0x0a) /* TCO2 Control Register */
235#define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200236
237/* internal variables */
238static unsigned long is_active;
239static char expect_release;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100240static struct { /* this is private data for the iTCO_wdt device */
241 /* TCO version/generation */
242 unsigned int iTCO_version;
243 /* The cards ACPIBASE address (TCOBASE = ACPIBASE+0x60) */
244 unsigned long ACPIBASE;
245 /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2)*/
246 unsigned long __iomem *gcs;
247 /* the lock for io operations */
248 spinlock_t io_lock;
249 /* the PCI-device */
250 struct pci_dev *pdev;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200251} iTCO_wdt_private;
252
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100253/* the watchdog platform device */
254static struct platform_device *iTCO_wdt_platform_device;
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200255
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200256/* module parameters */
257#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
258static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
259module_param(heartbeat, int, 0);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000260MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. "
261 "(2<heartbeat<39 (TCO v1) or 613 (TCO v2), default="
262 __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200263
264static int nowayout = WATCHDOG_NOWAYOUT;
265module_param(nowayout, int, 0);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100266MODULE_PARM_DESC(nowayout,
267 "Watchdog cannot be stopped once started (default="
268 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100269
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200270/*
271 * Some TCO specific functions
272 */
273
274static inline unsigned int seconds_to_ticks(int seconds)
275{
276 /* the internal timer is stored as ticks which decrement
277 * every 0.6 seconds */
278 return (seconds * 10) / 6;
279}
280
281static void iTCO_wdt_set_NO_REBOOT_bit(void)
282{
283 u32 val32;
284
285 /* Set the NO_REBOOT bit: this disables reboots */
286 if (iTCO_wdt_private.iTCO_version == 2) {
287 val32 = readl(iTCO_wdt_private.gcs);
288 val32 |= 0x00000020;
289 writel(val32, iTCO_wdt_private.gcs);
290 } else if (iTCO_wdt_private.iTCO_version == 1) {
291 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
292 val32 |= 0x00000002;
293 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
294 }
295}
296
297static int iTCO_wdt_unset_NO_REBOOT_bit(void)
298{
299 int ret = 0;
300 u32 val32;
301
302 /* Unset the NO_REBOOT bit: this enables reboots */
303 if (iTCO_wdt_private.iTCO_version == 2) {
304 val32 = readl(iTCO_wdt_private.gcs);
305 val32 &= 0xffffffdf;
306 writel(val32, iTCO_wdt_private.gcs);
307
308 val32 = readl(iTCO_wdt_private.gcs);
309 if (val32 & 0x00000020)
310 ret = -EIO;
311 } else if (iTCO_wdt_private.iTCO_version == 1) {
312 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
313 val32 &= 0xfffffffd;
314 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
315
316 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
317 if (val32 & 0x00000002)
318 ret = -EIO;
319 }
320
321 return ret; /* returns: 0 = OK, -EIO = Error */
322}
323
324static int iTCO_wdt_start(void)
325{
326 unsigned int val;
327
328 spin_lock(&iTCO_wdt_private.io_lock);
329
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100330 iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat);
331
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200332 /* disable chipset's NO_REBOOT bit */
333 if (iTCO_wdt_unset_NO_REBOOT_bit()) {
Roel Kluin2ba7d7b2007-10-23 03:08:27 +0200334 spin_unlock(&iTCO_wdt_private.io_lock);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000335 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, "
336 "reboot disabled by hardware\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200337 return -EIO;
338 }
339
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000340 /* Force the timer to its reload value by writing to the TCO_RLD
341 register */
342 if (iTCO_wdt_private.iTCO_version == 2)
343 outw(0x01, TCO_RLD);
344 else if (iTCO_wdt_private.iTCO_version == 1)
345 outb(0x01, TCO_RLD);
346
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200347 /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
348 val = inw(TCO1_CNT);
349 val &= 0xf7ff;
350 outw(val, TCO1_CNT);
351 val = inw(TCO1_CNT);
352 spin_unlock(&iTCO_wdt_private.io_lock);
353
354 if (val & 0x0800)
355 return -1;
356 return 0;
357}
358
359static int iTCO_wdt_stop(void)
360{
361 unsigned int val;
362
363 spin_lock(&iTCO_wdt_private.io_lock);
364
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100365 iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE);
366
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200367 /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
368 val = inw(TCO1_CNT);
369 val |= 0x0800;
370 outw(val, TCO1_CNT);
371 val = inw(TCO1_CNT);
372
373 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
374 iTCO_wdt_set_NO_REBOOT_bit();
375
376 spin_unlock(&iTCO_wdt_private.io_lock);
377
378 if ((val & 0x0800) == 0)
379 return -1;
380 return 0;
381}
382
383static int iTCO_wdt_keepalive(void)
384{
385 spin_lock(&iTCO_wdt_private.io_lock);
386
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100387 iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat);
388
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200389 /* Reload the timer by writing to the TCO Timer Counter register */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100390 if (iTCO_wdt_private.iTCO_version == 2)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200391 outw(0x01, TCO_RLD);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100392 else if (iTCO_wdt_private.iTCO_version == 1)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200393 outb(0x01, TCO_RLD);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200394
395 spin_unlock(&iTCO_wdt_private.io_lock);
396 return 0;
397}
398
399static int iTCO_wdt_set_heartbeat(int t)
400{
401 unsigned int val16;
402 unsigned char val8;
403 unsigned int tmrval;
404
405 tmrval = seconds_to_ticks(t);
406 /* from the specs: */
407 /* "Values of 0h-3h are ignored and should not be attempted" */
408 if (tmrval < 0x04)
409 return -EINVAL;
410 if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) ||
411 ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
412 return -EINVAL;
413
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100414 iTCO_vendor_pre_set_heartbeat(tmrval);
415
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200416 /* Write new heartbeat to watchdog */
417 if (iTCO_wdt_private.iTCO_version == 2) {
418 spin_lock(&iTCO_wdt_private.io_lock);
419 val16 = inw(TCOv2_TMR);
420 val16 &= 0xfc00;
421 val16 |= tmrval;
422 outw(val16, TCOv2_TMR);
423 val16 = inw(TCOv2_TMR);
424 spin_unlock(&iTCO_wdt_private.io_lock);
425
426 if ((val16 & 0x3ff) != tmrval)
427 return -EINVAL;
428 } else if (iTCO_wdt_private.iTCO_version == 1) {
429 spin_lock(&iTCO_wdt_private.io_lock);
430 val8 = inb(TCOv1_TMR);
431 val8 &= 0xc0;
432 val8 |= (tmrval & 0xff);
433 outb(val8, TCOv1_TMR);
434 val8 = inb(TCOv1_TMR);
435 spin_unlock(&iTCO_wdt_private.io_lock);
436
437 if ((val8 & 0x3f) != tmrval)
438 return -EINVAL;
439 }
440
441 heartbeat = t;
442 return 0;
443}
444
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100445static int iTCO_wdt_get_timeleft(int *time_left)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200446{
447 unsigned int val16;
448 unsigned char val8;
449
450 /* read the TCO Timer */
451 if (iTCO_wdt_private.iTCO_version == 2) {
452 spin_lock(&iTCO_wdt_private.io_lock);
453 val16 = inw(TCO_RLD);
454 val16 &= 0x3ff;
455 spin_unlock(&iTCO_wdt_private.io_lock);
456
457 *time_left = (val16 * 6) / 10;
458 } else if (iTCO_wdt_private.iTCO_version == 1) {
459 spin_lock(&iTCO_wdt_private.io_lock);
460 val8 = inb(TCO_RLD);
461 val8 &= 0x3f;
462 spin_unlock(&iTCO_wdt_private.io_lock);
463
464 *time_left = (val8 * 6) / 10;
Jeff Garzik80060362006-10-10 03:40:44 -0400465 } else
466 return -EINVAL;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200467 return 0;
468}
469
470/*
471 * /dev/watchdog handling
472 */
473
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100474static int iTCO_wdt_open(struct inode *inode, struct file *file)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200475{
476 /* /dev/watchdog can only be opened once */
477 if (test_and_set_bit(0, &is_active))
478 return -EBUSY;
479
480 /*
481 * Reload and activate timer
482 */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200483 iTCO_wdt_start();
484 return nonseekable_open(inode, file);
485}
486
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100487static int iTCO_wdt_release(struct inode *inode, struct file *file)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200488{
489 /*
490 * Shut off the timer.
491 */
492 if (expect_release == 42) {
493 iTCO_wdt_stop();
494 } else {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100495 printk(KERN_CRIT PFX
496 "Unexpected close, not stopping watchdog!\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200497 iTCO_wdt_keepalive();
498 }
499 clear_bit(0, &is_active);
500 expect_release = 0;
501 return 0;
502}
503
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100504static ssize_t iTCO_wdt_write(struct file *file, const char __user *data,
505 size_t len, loff_t *ppos)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200506{
507 /* See if we got the magic character 'V' and reload the timer */
508 if (len) {
509 if (!nowayout) {
510 size_t i;
511
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100512 /* note: just in case someone wrote the magic
513 character five months ago... */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200514 expect_release = 0;
515
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100516 /* scan to see whether or not we got the
517 magic character */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200518 for (i = 0; i != len; i++) {
519 char c;
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +0000520 if (get_user(c, data + i))
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200521 return -EFAULT;
522 if (c == 'V')
523 expect_release = 42;
524 }
525 }
526
527 /* someone wrote to us, we should reload the timer */
528 iTCO_wdt_keepalive();
529 }
530 return len;
531}
532
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100533static long iTCO_wdt_ioctl(struct file *file, unsigned int cmd,
534 unsigned long arg)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200535{
536 int new_options, retval = -EINVAL;
537 int new_heartbeat;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200538 void __user *argp = (void __user *)arg;
539 int __user *p = argp;
540 static struct watchdog_info ident = {
541 .options = WDIOF_SETTIMEOUT |
542 WDIOF_KEEPALIVEPING |
543 WDIOF_MAGICCLOSE,
544 .firmware_version = 0,
545 .identity = DRV_NAME,
546 };
547
548 switch (cmd) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100549 case WDIOC_GETSUPPORT:
550 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
551 case WDIOC_GETSTATUS:
552 case WDIOC_GETBOOTSTATUS:
553 return put_user(0, p);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200554
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100555 case WDIOC_SETOPTIONS:
556 {
557 if (get_user(new_options, p))
558 return -EFAULT;
559
560 if (new_options & WDIOS_DISABLECARD) {
561 iTCO_wdt_stop();
562 retval = 0;
563 }
564 if (new_options & WDIOS_ENABLECARD) {
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200565 iTCO_wdt_keepalive();
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100566 iTCO_wdt_start();
567 retval = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200568 }
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100569 return retval;
570 }
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000571 case WDIOC_KEEPALIVE:
572 iTCO_wdt_keepalive();
573 return 0;
574
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100575 case WDIOC_SETTIMEOUT:
576 {
577 if (get_user(new_heartbeat, p))
578 return -EFAULT;
579 if (iTCO_wdt_set_heartbeat(new_heartbeat))
580 return -EINVAL;
581 iTCO_wdt_keepalive();
582 /* Fall */
583 }
584 case WDIOC_GETTIMEOUT:
585 return put_user(heartbeat, p);
586 case WDIOC_GETTIMELEFT:
587 {
588 int time_left;
589 if (iTCO_wdt_get_timeleft(&time_left))
590 return -EINVAL;
591 return put_user(time_left, p);
592 }
593 default:
594 return -ENOTTY;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200595 }
596}
597
598/*
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200599 * Kernel Interfaces
600 */
601
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800602static const struct file_operations iTCO_wdt_fops = {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100603 .owner = THIS_MODULE,
604 .llseek = no_llseek,
605 .write = iTCO_wdt_write,
606 .unlocked_ioctl = iTCO_wdt_ioctl,
607 .open = iTCO_wdt_open,
608 .release = iTCO_wdt_release,
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200609};
610
611static struct miscdevice iTCO_wdt_miscdev = {
612 .minor = WATCHDOG_MINOR,
613 .name = "watchdog",
614 .fops = &iTCO_wdt_fops,
615};
616
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200617/*
618 * Init & exit routines
619 */
620
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100621static int __devinit iTCO_wdt_init(struct pci_dev *pdev,
622 const struct pci_device_id *ent, struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200623{
624 int ret;
625 u32 base_address;
626 unsigned long RCBA;
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000627 unsigned long val32;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200628
629 /*
630 * Find the ACPI/PM base I/O address which is the base
631 * for the TCO registers (TCOBASE=ACPIBASE + 0x60)
632 * ACPIBASE is bits [15:7] from 0x40-0x43
633 */
634 pci_read_config_dword(pdev, 0x40, &base_address);
Wim Van Sebroeck0d4804b2007-05-11 18:59:24 +0000635 base_address &= 0x0000ff80;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200636 if (base_address == 0x00000000) {
637 /* Something's wrong here, ACPIBASE has to be set */
638 printk(KERN_ERR PFX "failed to get TCOBASE address\n");
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200639 pci_dev_put(pdev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200640 return -ENODEV;
641 }
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100642 iTCO_wdt_private.iTCO_version =
643 iTCO_chipset_info[ent->driver_data].iTCO_version;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200644 iTCO_wdt_private.ACPIBASE = base_address;
645 iTCO_wdt_private.pdev = pdev;
646
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100647 /* Get the Memory-Mapped GCS register, we need it for the
648 NO_REBOOT flag (TCO v2). To get access to it you have to
649 read RCBA from PCI Config space 0xf0 and use it as base.
650 GCS = RCBA + ICH6_GCS(0x3410). */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200651 if (iTCO_wdt_private.iTCO_version == 2) {
652 pci_read_config_dword(pdev, 0xf0, &base_address);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400653 if ((base_address & 1) == 0) {
654 printk(KERN_ERR PFX "RCBA is disabled by harddware\n");
655 ret = -ENODEV;
656 goto out;
657 }
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200658 RCBA = base_address & 0xffffc000;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100659 iTCO_wdt_private.gcs = ioremap((RCBA + 0x3410), 4);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200660 }
661
662 /* Check chipset's NO_REBOOT bit */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100663 if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000664 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, "
665 "reboot disabled by hardware\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200666 ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400667 goto out_unmap;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200668 }
669
670 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
671 iTCO_wdt_set_NO_REBOOT_bit();
672
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000673 /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200674 if (!request_region(SMI_EN, 4, "iTCO_wdt")) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100675 printk(KERN_ERR PFX
676 "I/O address 0x%04lx already in use\n", SMI_EN);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200677 ret = -EIO;
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400678 goto out_unmap;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200679 }
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000680 /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
681 val32 = inl(SMI_EN);
682 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
683 outl(val32, SMI_EN);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200684
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100685 /* The TCO I/O registers reside in a 32-byte range pointed to
686 by the TCOBASE value */
687 if (!request_region(TCOBASE, 0x20, "iTCO_wdt")) {
688 printk(KERN_ERR PFX "I/O address 0x%04lx already in use\n",
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200689 TCOBASE);
690 ret = -EIO;
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000691 goto unreg_smi_en;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200692 }
693
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100694 printk(KERN_INFO PFX
695 "Found a %s TCO device (Version=%d, TCOBASE=0x%04lx)\n",
696 iTCO_chipset_info[ent->driver_data].name,
697 iTCO_chipset_info[ent->driver_data].iTCO_version,
698 TCOBASE);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200699
700 /* Clear out the (probably old) status */
Wim Van Sebroeckc6904dd2008-11-19 20:02:02 +0000701 outb(8, TCO1_STS); /* Clear the Time Out Status bit */
702 outb(2, TCO2_STS); /* Clear SECOND_TO_STS bit */
703 outb(4, TCO2_STS); /* Clear BOOT_STS bit */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200704
705 /* Make sure the watchdog is not running */
706 iTCO_wdt_stop();
707
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100708 /* Check that the heartbeat value is within it's range;
709 if not reset to the default */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200710 if (iTCO_wdt_set_heartbeat(heartbeat)) {
711 iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000712 printk(KERN_INFO PFX
713 "heartbeat value must be 2 < heartbeat < 39 (TCO v1) "
714 "or 613 (TCO v2), using %d\n", heartbeat);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200715 }
716
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200717 ret = misc_register(&iTCO_wdt_miscdev);
718 if (ret != 0) {
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100719 printk(KERN_ERR PFX
720 "cannot register miscdev on minor=%d (err=%d)\n",
721 WATCHDOG_MINOR, ret);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200722 goto unreg_region;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200723 }
724
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100725 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
726 heartbeat, nowayout);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200727
728 return 0;
729
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200730unreg_region:
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100731 release_region(TCOBASE, 0x20);
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000732unreg_smi_en:
733 release_region(SMI_EN, 4);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400734out_unmap:
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200735 if (iTCO_wdt_private.iTCO_version == 2)
736 iounmap(iTCO_wdt_private.gcs);
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400737out:
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200738 pci_dev_put(iTCO_wdt_private.pdev);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200739 iTCO_wdt_private.ACPIBASE = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200740 return ret;
741}
742
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000743static void __devexit iTCO_wdt_cleanup(void)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200744{
745 /* Stop the timer before we leave */
746 if (!nowayout)
747 iTCO_wdt_stop();
748
749 /* Deregister */
750 misc_deregister(&iTCO_wdt_miscdev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200751 release_region(TCOBASE, 0x20);
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000752 release_region(SMI_EN, 4);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200753 if (iTCO_wdt_private.iTCO_version == 2)
754 iounmap(iTCO_wdt_private.gcs);
Wim Van Sebroeck4802c652006-07-19 22:39:13 +0200755 pci_dev_put(iTCO_wdt_private.pdev);
Wim Van Sebroeck1bef84b2006-08-05 20:59:01 +0200756 iTCO_wdt_private.ACPIBASE = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200757}
758
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000759static int __devinit iTCO_wdt_probe(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200760{
761 int found = 0;
762 struct pci_dev *pdev = NULL;
763 const struct pci_device_id *ent;
764
765 spin_lock_init(&iTCO_wdt_private.io_lock);
766
767 for_each_pci_dev(pdev) {
768 ent = pci_match_id(iTCO_wdt_pci_tbl, pdev);
769 if (ent) {
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200770 if (!(iTCO_wdt_init(pdev, ent, dev))) {
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200771 found++;
772 break;
773 }
774 }
775 }
776
777 if (!found) {
778 printk(KERN_INFO PFX "No card detected\n");
779 return -ENODEV;
780 }
781
782 return 0;
783}
784
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000785static int __devexit iTCO_wdt_remove(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200786{
787 if (iTCO_wdt_private.ACPIBASE)
788 iTCO_wdt_cleanup();
789
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200790 return 0;
791}
792
793static void iTCO_wdt_shutdown(struct platform_device *dev)
794{
795 iTCO_wdt_stop();
796}
797
798#define iTCO_wdt_suspend NULL
799#define iTCO_wdt_resume NULL
800
801static struct platform_driver iTCO_wdt_driver = {
802 .probe = iTCO_wdt_probe,
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000803 .remove = __devexit_p(iTCO_wdt_remove),
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200804 .shutdown = iTCO_wdt_shutdown,
805 .suspend = iTCO_wdt_suspend,
806 .resume = iTCO_wdt_resume,
807 .driver = {
808 .owner = THIS_MODULE,
809 .name = DRV_NAME,
810 },
811};
812
813static int __init iTCO_wdt_init_module(void)
814{
815 int err;
816
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000817 printk(KERN_INFO PFX "Intel TCO WatchDog Timer Driver v%s\n",
818 DRV_VERSION);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200819
820 err = platform_driver_register(&iTCO_wdt_driver);
821 if (err)
822 return err;
823
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100824 iTCO_wdt_platform_device = platform_device_register_simple(DRV_NAME,
825 -1, NULL, 0);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200826 if (IS_ERR(iTCO_wdt_platform_device)) {
827 err = PTR_ERR(iTCO_wdt_platform_device);
828 goto unreg_platform_driver;
829 }
830
831 return 0;
832
833unreg_platform_driver:
834 platform_driver_unregister(&iTCO_wdt_driver);
835 return err;
836}
837
838static void __exit iTCO_wdt_cleanup_module(void)
839{
840 platform_device_unregister(iTCO_wdt_platform_device);
841 platform_driver_unregister(&iTCO_wdt_driver);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200842 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
843}
844
845module_init(iTCO_wdt_init_module);
846module_exit(iTCO_wdt_cleanup_module);
847
848MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
849MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200850MODULE_VERSION(DRV_VERSION);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200851MODULE_LICENSE("GPL");
852MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);