blob: ceed39f26011a8aa0684e1768d919f38d119f93c [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 Sebroeckdeb91972011-10-19 23:59:26 +02004 * (c) Copyright 2006-2011 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)
Wim Van Sebroeckd38bd472010-12-31 14:10:45 +000029 * document number 322896-001, 322897-001: NM10
Wim Van Sebroeckcb711a12009-11-15 13:44:54 +000030 * document number 313056-003, 313057-017: 82801H (ICH8)
31 * document number 316972-004, 316973-012: 82801I (ICH9)
32 * document number 319973-002, 319974-002: 82801J (ICH10)
Seth Heasley3c9d8ec2010-01-14 20:58:05 +000033 * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH)
Imre Kaloz4946f832009-12-07 20:42:26 +010034 * document number 320066-003, 320257-008: EP80597 (IICH)
Seth Heasley203f8d82011-01-07 17:11:08 -080035 * document number 324645-001, 324646-001: Cougar Point (CPT)
Seth Heasleyc54fb812010-11-17 12:15:08 -070036 * document number TBD : Patsburg (PBG)
Seth Heasley203f8d82011-01-07 17:11:08 -080037 * document number TBD : DH89xxCC
Seth Heasleyaa1f4652011-04-20 10:56:20 -070038 * document number TBD : Panther Point
Seth Heasley84e83c22012-01-23 16:40:55 -080039 * document number TBD : Lynx Point
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020040 */
41
42/*
43 * Includes, defines, variables, module parameters, ...
44 */
45
Joe Perches27c766a2012-02-15 15:06:19 -080046#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
47
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020048/* Module and version information */
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +000049#define DRV_NAME "iTCO_wdt"
Wim Van Sebroeckbff23432012-06-09 14:10:28 +020050#define DRV_VERSION "1.10"
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020051
52/* Includes */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020053#include <linux/module.h> /* For module specific items */
54#include <linux/moduleparam.h> /* For new moduleparam's */
55#include <linux/types.h> /* For standard types (like size_t) */
56#include <linux/errno.h> /* For the -ENODEV/... values */
57#include <linux/kernel.h> /* For printk/panic/... */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010058#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
59 (WATCHDOG_MINOR) */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020060#include <linux/watchdog.h> /* For the watchdog specific items */
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +020061#include <linux/init.h> /* For __init/__exit/... */
62#include <linux/fs.h> /* For file operations */
63#include <linux/platform_device.h> /* For platform_driver framework */
64#include <linux/pci.h> /* For pci functions */
65#include <linux/ioport.h> /* For io-port access */
66#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010067#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
68#include <linux/io.h> /* For inb/outb/... */
Aaron Sierra887c8ec2012-04-20 14:14:11 -050069#include <linux/mfd/core.h>
70#include <linux/mfd/lpc_ich.h>
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020071
Alan Cox0e6fa3f2008-05-19 14:06:25 +010072#include "iTCO_vendor.h"
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020073
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020074/* Address definitions for the TCO */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010075/* TCO base address */
Aaron Sierra887c8ec2012-04-20 14:14:11 -050076#define TCOBASE (iTCO_wdt_private.tco_res->start)
Alan Cox0e6fa3f2008-05-19 14:06:25 +010077/* SMI Control and Enable Register */
Aaron Sierra887c8ec2012-04-20 14:14:11 -050078#define SMI_EN (iTCO_wdt_private.smi_res->start)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020079
Wim Van Sebroeck0a7e65822009-04-14 20:20:07 +000080#define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload and Curr. Value */
81#define TCOv1_TMR (TCOBASE + 0x01) /* TCOv1 Timer Initial Value */
82#define TCO_DAT_IN (TCOBASE + 0x02) /* TCO Data In Register */
83#define TCO_DAT_OUT (TCOBASE + 0x03) /* TCO Data Out Register */
84#define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */
85#define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */
86#define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */
87#define TCO2_CNT (TCOBASE + 0x0a) /* TCO2 Control Register */
88#define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +020089
90/* internal variables */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010091static struct { /* this is private data for the iTCO_wdt device */
92 /* TCO version/generation */
93 unsigned int iTCO_version;
Aaron Sierra887c8ec2012-04-20 14:14:11 -050094 struct resource *tco_res;
95 struct resource *smi_res;
96 struct resource *gcs_res;
Alan Cox0e6fa3f2008-05-19 14:06:25 +010097 /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2)*/
98 unsigned long __iomem *gcs;
99 /* the lock for io operations */
100 spinlock_t io_lock;
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500101 struct platform_device *dev;
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100102 /* the PCI-device */
103 struct pci_dev *pdev;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200104} iTCO_wdt_private;
105
106/* module parameters */
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200107#define WATCHDOG_TIMEOUT 30 /* 30 sec default heartbeat */
108static int heartbeat = WATCHDOG_TIMEOUT; /* in seconds */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200109module_param(heartbeat, int, 0);
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100110MODULE_PARM_DESC(heartbeat, "Watchdog timeout in seconds. "
111 "5..76 (TCO v1) or 3..614 (TCO v2), default="
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200112 __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200113
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +0100114static bool nowayout = WATCHDOG_NOWAYOUT;
115module_param(nowayout, bool, 0);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100116MODULE_PARM_DESC(nowayout,
117 "Watchdog cannot be stopped once started (default="
118 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100119
Wim Van Sebroeck0d098582011-12-26 15:23:51 +0100120static int turn_SMI_watchdog_clear_off = 1;
Wim Van Sebroeckdeb91972011-10-19 23:59:26 +0200121module_param(turn_SMI_watchdog_clear_off, int, 0);
122MODULE_PARM_DESC(turn_SMI_watchdog_clear_off,
Wim Van Sebroeck0d098582011-12-26 15:23:51 +0100123 "Turn off SMI clearing watchdog (depends on TCO-version)(default=1)");
Wim Van Sebroeckdeb91972011-10-19 23:59:26 +0200124
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200125/*
126 * Some TCO specific functions
127 */
128
129static inline unsigned int seconds_to_ticks(int seconds)
130{
131 /* the internal timer is stored as ticks which decrement
132 * every 0.6 seconds */
133 return (seconds * 10) / 6;
134}
135
136static void iTCO_wdt_set_NO_REBOOT_bit(void)
137{
138 u32 val32;
139
140 /* Set the NO_REBOOT bit: this disables reboots */
141 if (iTCO_wdt_private.iTCO_version == 2) {
142 val32 = readl(iTCO_wdt_private.gcs);
143 val32 |= 0x00000020;
144 writel(val32, iTCO_wdt_private.gcs);
145 } else if (iTCO_wdt_private.iTCO_version == 1) {
146 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
147 val32 |= 0x00000002;
148 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
149 }
150}
151
152static int iTCO_wdt_unset_NO_REBOOT_bit(void)
153{
154 int ret = 0;
155 u32 val32;
156
157 /* Unset the NO_REBOOT bit: this enables reboots */
158 if (iTCO_wdt_private.iTCO_version == 2) {
159 val32 = readl(iTCO_wdt_private.gcs);
160 val32 &= 0xffffffdf;
161 writel(val32, iTCO_wdt_private.gcs);
162
163 val32 = readl(iTCO_wdt_private.gcs);
164 if (val32 & 0x00000020)
165 ret = -EIO;
166 } else if (iTCO_wdt_private.iTCO_version == 1) {
167 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
168 val32 &= 0xfffffffd;
169 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
170
171 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
172 if (val32 & 0x00000002)
173 ret = -EIO;
174 }
175
176 return ret; /* returns: 0 = OK, -EIO = Error */
177}
178
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200179static int iTCO_wdt_start(struct watchdog_device *wd_dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200180{
181 unsigned int val;
182
183 spin_lock(&iTCO_wdt_private.io_lock);
184
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200185 iTCO_vendor_pre_start(iTCO_wdt_private.smi_res, wd_dev->timeout);
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100186
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200187 /* disable chipset's NO_REBOOT bit */
188 if (iTCO_wdt_unset_NO_REBOOT_bit()) {
Roel Kluin2ba7d7b2007-10-23 03:08:27 +0200189 spin_unlock(&iTCO_wdt_private.io_lock);
Joe Perches27c766a2012-02-15 15:06:19 -0800190 pr_err("failed to reset NO_REBOOT flag, reboot disabled by hardware/BIOS\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200191 return -EIO;
192 }
193
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000194 /* Force the timer to its reload value by writing to the TCO_RLD
195 register */
196 if (iTCO_wdt_private.iTCO_version == 2)
197 outw(0x01, TCO_RLD);
198 else if (iTCO_wdt_private.iTCO_version == 1)
199 outb(0x01, TCO_RLD);
200
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200201 /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
202 val = inw(TCO1_CNT);
203 val &= 0xf7ff;
204 outw(val, TCO1_CNT);
205 val = inw(TCO1_CNT);
206 spin_unlock(&iTCO_wdt_private.io_lock);
207
208 if (val & 0x0800)
209 return -1;
210 return 0;
211}
212
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200213static int iTCO_wdt_stop(struct watchdog_device *wd_dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200214{
215 unsigned int val;
216
217 spin_lock(&iTCO_wdt_private.io_lock);
218
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500219 iTCO_vendor_pre_stop(iTCO_wdt_private.smi_res);
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100220
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200221 /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
222 val = inw(TCO1_CNT);
223 val |= 0x0800;
224 outw(val, TCO1_CNT);
225 val = inw(TCO1_CNT);
226
227 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
228 iTCO_wdt_set_NO_REBOOT_bit();
229
230 spin_unlock(&iTCO_wdt_private.io_lock);
231
232 if ((val & 0x0800) == 0)
233 return -1;
234 return 0;
235}
236
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200237static int iTCO_wdt_ping(struct watchdog_device *wd_dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200238{
239 spin_lock(&iTCO_wdt_private.io_lock);
240
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200241 iTCO_vendor_pre_keepalive(iTCO_wdt_private.smi_res, wd_dev->timeout);
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100242
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200243 /* Reload the timer by writing to the TCO Timer Counter register */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100244 if (iTCO_wdt_private.iTCO_version == 2)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200245 outw(0x01, TCO_RLD);
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100246 else if (iTCO_wdt_private.iTCO_version == 1) {
247 /* Reset the timeout status bit so that the timer
248 * needs to count down twice again before rebooting */
249 outw(0x0008, TCO1_STS); /* write 1 to clear bit */
250
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200251 outb(0x01, TCO_RLD);
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100252 }
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200253
254 spin_unlock(&iTCO_wdt_private.io_lock);
255 return 0;
256}
257
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200258static int iTCO_wdt_set_timeout(struct watchdog_device *wd_dev, unsigned int t)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200259{
260 unsigned int val16;
261 unsigned char val8;
262 unsigned int tmrval;
263
264 tmrval = seconds_to_ticks(t);
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100265
266 /* For TCO v1 the timer counts down twice before rebooting */
267 if (iTCO_wdt_private.iTCO_version == 1)
268 tmrval /= 2;
269
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200270 /* from the specs: */
271 /* "Values of 0h-3h are ignored and should not be attempted" */
272 if (tmrval < 0x04)
273 return -EINVAL;
274 if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) ||
275 ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
276 return -EINVAL;
277
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100278 iTCO_vendor_pre_set_heartbeat(tmrval);
279
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200280 /* Write new heartbeat to watchdog */
281 if (iTCO_wdt_private.iTCO_version == 2) {
282 spin_lock(&iTCO_wdt_private.io_lock);
283 val16 = inw(TCOv2_TMR);
284 val16 &= 0xfc00;
285 val16 |= tmrval;
286 outw(val16, TCOv2_TMR);
287 val16 = inw(TCOv2_TMR);
288 spin_unlock(&iTCO_wdt_private.io_lock);
289
290 if ((val16 & 0x3ff) != tmrval)
291 return -EINVAL;
292 } else if (iTCO_wdt_private.iTCO_version == 1) {
293 spin_lock(&iTCO_wdt_private.io_lock);
294 val8 = inb(TCOv1_TMR);
295 val8 &= 0xc0;
296 val8 |= (tmrval & 0xff);
297 outb(val8, TCOv1_TMR);
298 val8 = inb(TCOv1_TMR);
299 spin_unlock(&iTCO_wdt_private.io_lock);
300
301 if ((val8 & 0x3f) != tmrval)
302 return -EINVAL;
303 }
304
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200305 wd_dev->timeout = t;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200306 return 0;
307}
308
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200309static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200310{
311 unsigned int val16;
312 unsigned char val8;
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200313 unsigned int time_left = 0;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200314
315 /* read the TCO Timer */
316 if (iTCO_wdt_private.iTCO_version == 2) {
317 spin_lock(&iTCO_wdt_private.io_lock);
318 val16 = inw(TCO_RLD);
319 val16 &= 0x3ff;
320 spin_unlock(&iTCO_wdt_private.io_lock);
321
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200322 time_left = (val16 * 6) / 10;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200323 } else if (iTCO_wdt_private.iTCO_version == 1) {
324 spin_lock(&iTCO_wdt_private.io_lock);
325 val8 = inb(TCO_RLD);
326 val8 &= 0x3f;
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100327 if (!(inw(TCO1_STS) & 0x0008))
328 val8 += (inb(TCOv1_TMR) & 0x3f);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200329 spin_unlock(&iTCO_wdt_private.io_lock);
330
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200331 time_left = (val8 * 6) / 10;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200332 }
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200333 return time_left;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200334}
335
336/*
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200337 * Kernel Interfaces
338 */
339
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200340static const struct watchdog_info ident = {
341 .options = WDIOF_SETTIMEOUT |
342 WDIOF_KEEPALIVEPING |
343 WDIOF_MAGICCLOSE,
344 .firmware_version = 0,
345 .identity = DRV_NAME,
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200346};
347
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200348static const struct watchdog_ops iTCO_wdt_ops = {
349 .owner = THIS_MODULE,
350 .start = iTCO_wdt_start,
351 .stop = iTCO_wdt_stop,
352 .ping = iTCO_wdt_ping,
353 .set_timeout = iTCO_wdt_set_timeout,
354 .get_timeleft = iTCO_wdt_get_timeleft,
355};
356
357static struct watchdog_device iTCO_wdt_watchdog_dev = {
358 .info = &ident,
359 .ops = &iTCO_wdt_ops,
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200360};
361
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200362/*
363 * Init & exit routines
364 */
365
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500366static void __devexit iTCO_wdt_cleanup(void)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200367{
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500368 /* Stop the timer before we leave */
369 if (!nowayout)
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200370 iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500371
372 /* Deregister */
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200373 watchdog_unregister_device(&iTCO_wdt_watchdog_dev);
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500374
375 /* release resources */
376 release_region(iTCO_wdt_private.tco_res->start,
377 resource_size(iTCO_wdt_private.tco_res));
378 release_region(iTCO_wdt_private.smi_res->start,
379 resource_size(iTCO_wdt_private.smi_res));
380 if (iTCO_wdt_private.iTCO_version == 2) {
381 iounmap(iTCO_wdt_private.gcs);
382 release_mem_region(iTCO_wdt_private.gcs_res->start,
383 resource_size(iTCO_wdt_private.gcs_res));
384 }
385
386 iTCO_wdt_private.tco_res = NULL;
387 iTCO_wdt_private.smi_res = NULL;
388 iTCO_wdt_private.gcs_res = NULL;
389 iTCO_wdt_private.gcs = NULL;
390}
391
392static int __devinit iTCO_wdt_probe(struct platform_device *dev)
393{
394 int ret = -ENODEV;
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +0000395 unsigned long val32;
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500396 struct lpc_ich_info *ich_info = dev->dev.platform_data;
397
398 if (!ich_info)
399 goto out;
400
401 spin_lock_init(&iTCO_wdt_private.io_lock);
402
403 iTCO_wdt_private.tco_res =
404 platform_get_resource(dev, IORESOURCE_IO, ICH_RES_IO_TCO);
405 if (!iTCO_wdt_private.tco_res)
406 goto out;
407
408 iTCO_wdt_private.smi_res =
409 platform_get_resource(dev, IORESOURCE_IO, ICH_RES_IO_SMI);
410 if (!iTCO_wdt_private.smi_res)
411 goto out;
412
413 iTCO_wdt_private.iTCO_version = ich_info->iTCO_version;
414 iTCO_wdt_private.dev = dev;
415 iTCO_wdt_private.pdev = to_pci_dev(dev->dev.parent);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200416
417 /*
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500418 * Get the Memory-Mapped GCS register, we need it for the
419 * NO_REBOOT flag (TCO v2).
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200420 */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200421 if (iTCO_wdt_private.iTCO_version == 2) {
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500422 iTCO_wdt_private.gcs_res = platform_get_resource(dev,
423 IORESOURCE_MEM,
424 ICH_RES_MEM_GCS);
425
426 if (!iTCO_wdt_private.gcs_res)
427 goto out;
428
429 if (!request_mem_region(iTCO_wdt_private.gcs_res->start,
430 resource_size(iTCO_wdt_private.gcs_res), dev->name)) {
431 ret = -EBUSY;
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400432 goto out;
433 }
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500434 iTCO_wdt_private.gcs = ioremap(iTCO_wdt_private.gcs_res->start,
435 resource_size(iTCO_wdt_private.gcs_res));
436 if (!iTCO_wdt_private.gcs) {
437 ret = -EIO;
438 goto unreg_gcs;
439 }
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200440 }
441
442 /* Check chipset's NO_REBOOT bit */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100443 if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
Joe Perches27c766a2012-02-15 15:06:19 -0800444 pr_info("unable to reset NO_REBOOT flag, device disabled by hardware/BIOS\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200445 ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500446 goto unmap_gcs;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200447 }
448
449 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
450 iTCO_wdt_set_NO_REBOOT_bit();
451
Wim Van Sebroeck7cd5b082008-11-19 19:39:58 +0000452 /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500453 if (!request_region(iTCO_wdt_private.smi_res->start,
454 resource_size(iTCO_wdt_private.smi_res), dev->name)) {
455 pr_err("I/O address 0x%04llx already in use, device disabled\n",
Randy Dunlap4b98b322012-05-14 13:15:20 -0700456 (u64)SMI_EN);
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500457 ret = -EBUSY;
458 goto unmap_gcs;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200459 }
Wim Van Sebroeck0d098582011-12-26 15:23:51 +0100460 if (turn_SMI_watchdog_clear_off >= iTCO_wdt_private.iTCO_version) {
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500461 /*
462 * Bit 13: TCO_EN -> 0
463 * Disables TCO logic generating an SMI#
464 */
Wim Van Sebroeckdeb91972011-10-19 23:59:26 +0200465 val32 = inl(SMI_EN);
466 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
467 outl(val32, SMI_EN);
468 }
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200469
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500470 if (!request_region(iTCO_wdt_private.tco_res->start,
471 resource_size(iTCO_wdt_private.tco_res), dev->name)) {
472 pr_err("I/O address 0x%04llx already in use, device disabled\n",
Randy Dunlap4b98b322012-05-14 13:15:20 -0700473 (u64)TCOBASE);
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500474 ret = -EBUSY;
475 goto unreg_smi;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200476 }
477
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500478 pr_info("Found a %s TCO device (Version=%d, TCOBASE=0x%04llx)\n",
Randy Dunlap4b98b322012-05-14 13:15:20 -0700479 ich_info->name, ich_info->iTCO_version, (u64)TCOBASE);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200480
481 /* Clear out the (probably old) status */
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100482 outw(0x0008, TCO1_STS); /* Clear the Time Out Status bit */
483 outw(0x0002, TCO2_STS); /* Clear SECOND_TO_STS bit */
484 outw(0x0004, TCO2_STS); /* Clear BOOT_STS bit */
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200485
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200486 iTCO_wdt_watchdog_dev.bootstatus = 0;
487 iTCO_wdt_watchdog_dev.timeout = WATCHDOG_TIMEOUT;
488 watchdog_set_nowayout(&iTCO_wdt_watchdog_dev, nowayout);
489 iTCO_wdt_watchdog_dev.parent = dev->dev.parent;
490
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200491 /* Make sure the watchdog is not running */
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200492 iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200493
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100494 /* Check that the heartbeat value is within it's range;
495 if not reset to the default */
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200496 if (iTCO_wdt_set_timeout(&iTCO_wdt_watchdog_dev, heartbeat)) {
497 iTCO_wdt_set_timeout(&iTCO_wdt_watchdog_dev, WATCHDOG_TIMEOUT);
498 pr_info("timeout value out of range, using %d\n",
499 WATCHDOG_TIMEOUT);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200500 }
501
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200502 ret = watchdog_register_device(&iTCO_wdt_watchdog_dev);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200503 if (ret != 0) {
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200504 pr_err("cannot register watchdog device (err=%d)\n", ret);
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500505 goto unreg_tco;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200506 }
507
Joe Perches27c766a2012-02-15 15:06:19 -0800508 pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
509 heartbeat, nowayout);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200510
511 return 0;
512
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500513unreg_tco:
514 release_region(iTCO_wdt_private.tco_res->start,
515 resource_size(iTCO_wdt_private.tco_res));
516unreg_smi:
517 release_region(iTCO_wdt_private.smi_res->start,
518 resource_size(iTCO_wdt_private.smi_res));
519unmap_gcs:
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200520 if (iTCO_wdt_private.iTCO_version == 2)
521 iounmap(iTCO_wdt_private.gcs);
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500522unreg_gcs:
523 if (iTCO_wdt_private.iTCO_version == 2)
524 release_mem_region(iTCO_wdt_private.gcs_res->start,
525 resource_size(iTCO_wdt_private.gcs_res));
Denis V. Lunevde8cd9a2009-06-05 15:13:08 +0400526out:
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500527 iTCO_wdt_private.tco_res = NULL;
528 iTCO_wdt_private.smi_res = NULL;
529 iTCO_wdt_private.gcs_res = NULL;
530 iTCO_wdt_private.gcs = NULL;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200531
Naga Chumbalkarec269852010-02-09 00:42:02 +0100532 return ret;
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200533}
534
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000535static int __devexit iTCO_wdt_remove(struct platform_device *dev)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200536{
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500537 if (iTCO_wdt_private.tco_res || iTCO_wdt_private.smi_res)
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200538 iTCO_wdt_cleanup();
539
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200540 return 0;
541}
542
543static void iTCO_wdt_shutdown(struct platform_device *dev)
544{
Wim Van Sebroeckbff23432012-06-09 14:10:28 +0200545 iTCO_wdt_stop(NULL);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200546}
547
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200548static struct platform_driver iTCO_wdt_driver = {
549 .probe = iTCO_wdt_probe,
Wim Van Sebroeck08113e32007-08-31 08:15:34 +0000550 .remove = __devexit_p(iTCO_wdt_remove),
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200551 .shutdown = iTCO_wdt_shutdown,
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200552 .driver = {
553 .owner = THIS_MODULE,
554 .name = DRV_NAME,
555 },
556};
557
558static int __init iTCO_wdt_init_module(void)
559{
560 int err;
561
Joe Perches27c766a2012-02-15 15:06:19 -0800562 pr_info("Intel TCO WatchDog Timer Driver v%s\n", DRV_VERSION);
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200563
564 err = platform_driver_register(&iTCO_wdt_driver);
565 if (err)
566 return err;
567
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200568 return 0;
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200569}
570
571static void __exit iTCO_wdt_cleanup_module(void)
572{
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200573 platform_driver_unregister(&iTCO_wdt_driver);
Joe Perches27c766a2012-02-15 15:06:19 -0800574 pr_info("Watchdog Module Unloaded\n");
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200575}
576
577module_init(iTCO_wdt_init_module);
578module_exit(iTCO_wdt_cleanup_module);
579
580MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
581MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
Wim Van Sebroeck3836cc02006-06-30 08:44:53 +0200582MODULE_VERSION(DRV_VERSION);
Wim Van Sebroeck9e0ea342006-05-21 14:37:44 +0200583MODULE_LICENSE("GPL");
584MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
Jan Beuliche5de32e2012-06-22 16:41:00 +0100585MODULE_ALIAS("platform:" DRV_NAME);