iTCO_wdt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * intel TCO Watchdog Driver
  3. *
  4. * (c) Copyright 2006-2011 Wim Van Sebroeck <wim@iguana.be>.
  5. *
  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. * 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 322896-001, 322897-001: NM10
  30. * 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)
  33. * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH)
  34. * document number 320066-003, 320257-008: EP80597 (IICH)
  35. * document number 324645-001, 324646-001: Cougar Point (CPT)
  36. * document number TBD : Patsburg (PBG)
  37. * document number TBD : DH89xxCC
  38. * document number TBD : Panther Point
  39. * document number TBD : Lynx Point
  40. */
  41. /*
  42. * Includes, defines, variables, module parameters, ...
  43. */
  44. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  45. /* Module and version information */
  46. #define DRV_NAME "iTCO_wdt"
  47. #define DRV_VERSION "1.07"
  48. /* Includes */
  49. #include <linux/module.h> /* For module specific items */
  50. #include <linux/moduleparam.h> /* For new moduleparam's */
  51. #include <linux/types.h> /* For standard types (like size_t) */
  52. #include <linux/errno.h> /* For the -ENODEV/... values */
  53. #include <linux/kernel.h> /* For printk/panic/... */
  54. #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
  55. (WATCHDOG_MINOR) */
  56. #include <linux/watchdog.h> /* For the watchdog specific items */
  57. #include <linux/init.h> /* For __init/__exit/... */
  58. #include <linux/fs.h> /* For file operations */
  59. #include <linux/platform_device.h> /* For platform_driver framework */
  60. #include <linux/pci.h> /* For pci functions */
  61. #include <linux/ioport.h> /* For io-port access */
  62. #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
  63. #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
  64. #include <linux/io.h> /* For inb/outb/... */
  65. #include <linux/mfd/core.h>
  66. #include <linux/mfd/lpc_ich.h>
  67. #include "iTCO_vendor.h"
  68. /* Address definitions for the TCO */
  69. /* TCO base address */
  70. #define TCOBASE (iTCO_wdt_private.tco_res->start)
  71. /* SMI Control and Enable Register */
  72. #define SMI_EN (iTCO_wdt_private.smi_res->start)
  73. #define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload and Curr. Value */
  74. #define TCOv1_TMR (TCOBASE + 0x01) /* TCOv1 Timer Initial Value */
  75. #define TCO_DAT_IN (TCOBASE + 0x02) /* TCO Data In Register */
  76. #define TCO_DAT_OUT (TCOBASE + 0x03) /* TCO Data Out Register */
  77. #define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */
  78. #define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */
  79. #define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */
  80. #define TCO2_CNT (TCOBASE + 0x0a) /* TCO2 Control Register */
  81. #define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value */
  82. /* internal variables */
  83. static unsigned long is_active;
  84. static char expect_release;
  85. static struct { /* this is private data for the iTCO_wdt device */
  86. /* TCO version/generation */
  87. unsigned int iTCO_version;
  88. struct resource *tco_res;
  89. struct resource *smi_res;
  90. struct resource *gcs_res;
  91. /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2)*/
  92. unsigned long __iomem *gcs;
  93. /* the lock for io operations */
  94. spinlock_t io_lock;
  95. struct platform_device *dev;
  96. /* the PCI-device */
  97. struct pci_dev *pdev;
  98. } iTCO_wdt_private;
  99. /* module parameters */
  100. #define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
  101. static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
  102. module_param(heartbeat, int, 0);
  103. MODULE_PARM_DESC(heartbeat, "Watchdog timeout in seconds. "
  104. "5..76 (TCO v1) or 3..614 (TCO v2), default="
  105. __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
  106. static bool nowayout = WATCHDOG_NOWAYOUT;
  107. module_param(nowayout, bool, 0);
  108. MODULE_PARM_DESC(nowayout,
  109. "Watchdog cannot be stopped once started (default="
  110. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  111. static int turn_SMI_watchdog_clear_off = 1;
  112. module_param(turn_SMI_watchdog_clear_off, int, 0);
  113. MODULE_PARM_DESC(turn_SMI_watchdog_clear_off,
  114. "Turn off SMI clearing watchdog (depends on TCO-version)(default=1)");
  115. /*
  116. * Some TCO specific functions
  117. */
  118. static inline unsigned int seconds_to_ticks(int seconds)
  119. {
  120. /* the internal timer is stored as ticks which decrement
  121. * every 0.6 seconds */
  122. return (seconds * 10) / 6;
  123. }
  124. static void iTCO_wdt_set_NO_REBOOT_bit(void)
  125. {
  126. u32 val32;
  127. /* Set the NO_REBOOT bit: this disables reboots */
  128. if (iTCO_wdt_private.iTCO_version == 2) {
  129. val32 = readl(iTCO_wdt_private.gcs);
  130. val32 |= 0x00000020;
  131. writel(val32, iTCO_wdt_private.gcs);
  132. } else if (iTCO_wdt_private.iTCO_version == 1) {
  133. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  134. val32 |= 0x00000002;
  135. pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
  136. }
  137. }
  138. static int iTCO_wdt_unset_NO_REBOOT_bit(void)
  139. {
  140. int ret = 0;
  141. u32 val32;
  142. /* Unset the NO_REBOOT bit: this enables reboots */
  143. if (iTCO_wdt_private.iTCO_version == 2) {
  144. val32 = readl(iTCO_wdt_private.gcs);
  145. val32 &= 0xffffffdf;
  146. writel(val32, iTCO_wdt_private.gcs);
  147. val32 = readl(iTCO_wdt_private.gcs);
  148. if (val32 & 0x00000020)
  149. ret = -EIO;
  150. } else if (iTCO_wdt_private.iTCO_version == 1) {
  151. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  152. val32 &= 0xfffffffd;
  153. pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
  154. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  155. if (val32 & 0x00000002)
  156. ret = -EIO;
  157. }
  158. return ret; /* returns: 0 = OK, -EIO = Error */
  159. }
  160. static int iTCO_wdt_start(void)
  161. {
  162. unsigned int val;
  163. spin_lock(&iTCO_wdt_private.io_lock);
  164. iTCO_vendor_pre_start(iTCO_wdt_private.smi_res, heartbeat);
  165. /* disable chipset's NO_REBOOT bit */
  166. if (iTCO_wdt_unset_NO_REBOOT_bit()) {
  167. spin_unlock(&iTCO_wdt_private.io_lock);
  168. pr_err("failed to reset NO_REBOOT flag, reboot disabled by hardware/BIOS\n");
  169. return -EIO;
  170. }
  171. /* Force the timer to its reload value by writing to the TCO_RLD
  172. register */
  173. if (iTCO_wdt_private.iTCO_version == 2)
  174. outw(0x01, TCO_RLD);
  175. else if (iTCO_wdt_private.iTCO_version == 1)
  176. outb(0x01, TCO_RLD);
  177. /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
  178. val = inw(TCO1_CNT);
  179. val &= 0xf7ff;
  180. outw(val, TCO1_CNT);
  181. val = inw(TCO1_CNT);
  182. spin_unlock(&iTCO_wdt_private.io_lock);
  183. if (val & 0x0800)
  184. return -1;
  185. return 0;
  186. }
  187. static int iTCO_wdt_stop(void)
  188. {
  189. unsigned int val;
  190. spin_lock(&iTCO_wdt_private.io_lock);
  191. iTCO_vendor_pre_stop(iTCO_wdt_private.smi_res);
  192. /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
  193. val = inw(TCO1_CNT);
  194. val |= 0x0800;
  195. outw(val, TCO1_CNT);
  196. val = inw(TCO1_CNT);
  197. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  198. iTCO_wdt_set_NO_REBOOT_bit();
  199. spin_unlock(&iTCO_wdt_private.io_lock);
  200. if ((val & 0x0800) == 0)
  201. return -1;
  202. return 0;
  203. }
  204. static int iTCO_wdt_keepalive(void)
  205. {
  206. spin_lock(&iTCO_wdt_private.io_lock);
  207. iTCO_vendor_pre_keepalive(iTCO_wdt_private.smi_res, heartbeat);
  208. /* Reload the timer by writing to the TCO Timer Counter register */
  209. if (iTCO_wdt_private.iTCO_version == 2)
  210. outw(0x01, TCO_RLD);
  211. else if (iTCO_wdt_private.iTCO_version == 1) {
  212. /* Reset the timeout status bit so that the timer
  213. * needs to count down twice again before rebooting */
  214. outw(0x0008, TCO1_STS); /* write 1 to clear bit */
  215. outb(0x01, TCO_RLD);
  216. }
  217. spin_unlock(&iTCO_wdt_private.io_lock);
  218. return 0;
  219. }
  220. static int iTCO_wdt_set_heartbeat(int t)
  221. {
  222. unsigned int val16;
  223. unsigned char val8;
  224. unsigned int tmrval;
  225. tmrval = seconds_to_ticks(t);
  226. /* For TCO v1 the timer counts down twice before rebooting */
  227. if (iTCO_wdt_private.iTCO_version == 1)
  228. tmrval /= 2;
  229. /* from the specs: */
  230. /* "Values of 0h-3h are ignored and should not be attempted" */
  231. if (tmrval < 0x04)
  232. return -EINVAL;
  233. if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) ||
  234. ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
  235. return -EINVAL;
  236. iTCO_vendor_pre_set_heartbeat(tmrval);
  237. /* Write new heartbeat to watchdog */
  238. if (iTCO_wdt_private.iTCO_version == 2) {
  239. spin_lock(&iTCO_wdt_private.io_lock);
  240. val16 = inw(TCOv2_TMR);
  241. val16 &= 0xfc00;
  242. val16 |= tmrval;
  243. outw(val16, TCOv2_TMR);
  244. val16 = inw(TCOv2_TMR);
  245. spin_unlock(&iTCO_wdt_private.io_lock);
  246. if ((val16 & 0x3ff) != tmrval)
  247. return -EINVAL;
  248. } else if (iTCO_wdt_private.iTCO_version == 1) {
  249. spin_lock(&iTCO_wdt_private.io_lock);
  250. val8 = inb(TCOv1_TMR);
  251. val8 &= 0xc0;
  252. val8 |= (tmrval & 0xff);
  253. outb(val8, TCOv1_TMR);
  254. val8 = inb(TCOv1_TMR);
  255. spin_unlock(&iTCO_wdt_private.io_lock);
  256. if ((val8 & 0x3f) != tmrval)
  257. return -EINVAL;
  258. }
  259. heartbeat = t;
  260. return 0;
  261. }
  262. static int iTCO_wdt_get_timeleft(int *time_left)
  263. {
  264. unsigned int val16;
  265. unsigned char val8;
  266. /* read the TCO Timer */
  267. if (iTCO_wdt_private.iTCO_version == 2) {
  268. spin_lock(&iTCO_wdt_private.io_lock);
  269. val16 = inw(TCO_RLD);
  270. val16 &= 0x3ff;
  271. spin_unlock(&iTCO_wdt_private.io_lock);
  272. *time_left = (val16 * 6) / 10;
  273. } else if (iTCO_wdt_private.iTCO_version == 1) {
  274. spin_lock(&iTCO_wdt_private.io_lock);
  275. val8 = inb(TCO_RLD);
  276. val8 &= 0x3f;
  277. if (!(inw(TCO1_STS) & 0x0008))
  278. val8 += (inb(TCOv1_TMR) & 0x3f);
  279. spin_unlock(&iTCO_wdt_private.io_lock);
  280. *time_left = (val8 * 6) / 10;
  281. } else
  282. return -EINVAL;
  283. return 0;
  284. }
  285. /*
  286. * /dev/watchdog handling
  287. */
  288. static int iTCO_wdt_open(struct inode *inode, struct file *file)
  289. {
  290. /* /dev/watchdog can only be opened once */
  291. if (test_and_set_bit(0, &is_active))
  292. return -EBUSY;
  293. /*
  294. * Reload and activate timer
  295. */
  296. iTCO_wdt_start();
  297. return nonseekable_open(inode, file);
  298. }
  299. static int iTCO_wdt_release(struct inode *inode, struct file *file)
  300. {
  301. /*
  302. * Shut off the timer.
  303. */
  304. if (expect_release == 42) {
  305. iTCO_wdt_stop();
  306. } else {
  307. pr_crit("Unexpected close, not stopping watchdog!\n");
  308. iTCO_wdt_keepalive();
  309. }
  310. clear_bit(0, &is_active);
  311. expect_release = 0;
  312. return 0;
  313. }
  314. static ssize_t iTCO_wdt_write(struct file *file, const char __user *data,
  315. size_t len, loff_t *ppos)
  316. {
  317. /* See if we got the magic character 'V' and reload the timer */
  318. if (len) {
  319. if (!nowayout) {
  320. size_t i;
  321. /* note: just in case someone wrote the magic
  322. character five months ago... */
  323. expect_release = 0;
  324. /* scan to see whether or not we got the
  325. magic character */
  326. for (i = 0; i != len; i++) {
  327. char c;
  328. if (get_user(c, data + i))
  329. return -EFAULT;
  330. if (c == 'V')
  331. expect_release = 42;
  332. }
  333. }
  334. /* someone wrote to us, we should reload the timer */
  335. iTCO_wdt_keepalive();
  336. }
  337. return len;
  338. }
  339. static long iTCO_wdt_ioctl(struct file *file, unsigned int cmd,
  340. unsigned long arg)
  341. {
  342. int new_options, retval = -EINVAL;
  343. int new_heartbeat;
  344. void __user *argp = (void __user *)arg;
  345. int __user *p = argp;
  346. static const struct watchdog_info ident = {
  347. .options = WDIOF_SETTIMEOUT |
  348. WDIOF_KEEPALIVEPING |
  349. WDIOF_MAGICCLOSE,
  350. .firmware_version = 0,
  351. .identity = DRV_NAME,
  352. };
  353. switch (cmd) {
  354. case WDIOC_GETSUPPORT:
  355. return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  356. case WDIOC_GETSTATUS:
  357. case WDIOC_GETBOOTSTATUS:
  358. return put_user(0, p);
  359. case WDIOC_SETOPTIONS:
  360. {
  361. if (get_user(new_options, p))
  362. return -EFAULT;
  363. if (new_options & WDIOS_DISABLECARD) {
  364. iTCO_wdt_stop();
  365. retval = 0;
  366. }
  367. if (new_options & WDIOS_ENABLECARD) {
  368. iTCO_wdt_keepalive();
  369. iTCO_wdt_start();
  370. retval = 0;
  371. }
  372. return retval;
  373. }
  374. case WDIOC_KEEPALIVE:
  375. iTCO_wdt_keepalive();
  376. return 0;
  377. case WDIOC_SETTIMEOUT:
  378. {
  379. if (get_user(new_heartbeat, p))
  380. return -EFAULT;
  381. if (iTCO_wdt_set_heartbeat(new_heartbeat))
  382. return -EINVAL;
  383. iTCO_wdt_keepalive();
  384. /* Fall */
  385. }
  386. case WDIOC_GETTIMEOUT:
  387. return put_user(heartbeat, p);
  388. case WDIOC_GETTIMELEFT:
  389. {
  390. int time_left;
  391. if (iTCO_wdt_get_timeleft(&time_left))
  392. return -EINVAL;
  393. return put_user(time_left, p);
  394. }
  395. default:
  396. return -ENOTTY;
  397. }
  398. }
  399. /*
  400. * Kernel Interfaces
  401. */
  402. static const struct file_operations iTCO_wdt_fops = {
  403. .owner = THIS_MODULE,
  404. .llseek = no_llseek,
  405. .write = iTCO_wdt_write,
  406. .unlocked_ioctl = iTCO_wdt_ioctl,
  407. .open = iTCO_wdt_open,
  408. .release = iTCO_wdt_release,
  409. };
  410. static struct miscdevice iTCO_wdt_miscdev = {
  411. .minor = WATCHDOG_MINOR,
  412. .name = "watchdog",
  413. .fops = &iTCO_wdt_fops,
  414. };
  415. /*
  416. * Init & exit routines
  417. */
  418. static void __devexit iTCO_wdt_cleanup(void)
  419. {
  420. /* Stop the timer before we leave */
  421. if (!nowayout)
  422. iTCO_wdt_stop();
  423. /* Deregister */
  424. misc_deregister(&iTCO_wdt_miscdev);
  425. /* release resources */
  426. release_region(iTCO_wdt_private.tco_res->start,
  427. resource_size(iTCO_wdt_private.tco_res));
  428. release_region(iTCO_wdt_private.smi_res->start,
  429. resource_size(iTCO_wdt_private.smi_res));
  430. if (iTCO_wdt_private.iTCO_version == 2) {
  431. iounmap(iTCO_wdt_private.gcs);
  432. release_mem_region(iTCO_wdt_private.gcs_res->start,
  433. resource_size(iTCO_wdt_private.gcs_res));
  434. }
  435. iTCO_wdt_private.tco_res = NULL;
  436. iTCO_wdt_private.smi_res = NULL;
  437. iTCO_wdt_private.gcs_res = NULL;
  438. iTCO_wdt_private.gcs = NULL;
  439. }
  440. static int __devinit iTCO_wdt_probe(struct platform_device *dev)
  441. {
  442. int ret = -ENODEV;
  443. unsigned long val32;
  444. struct lpc_ich_info *ich_info = dev->dev.platform_data;
  445. if (!ich_info)
  446. goto out;
  447. spin_lock_init(&iTCO_wdt_private.io_lock);
  448. iTCO_wdt_private.tco_res =
  449. platform_get_resource(dev, IORESOURCE_IO, ICH_RES_IO_TCO);
  450. if (!iTCO_wdt_private.tco_res)
  451. goto out;
  452. iTCO_wdt_private.smi_res =
  453. platform_get_resource(dev, IORESOURCE_IO, ICH_RES_IO_SMI);
  454. if (!iTCO_wdt_private.smi_res)
  455. goto out;
  456. iTCO_wdt_private.iTCO_version = ich_info->iTCO_version;
  457. iTCO_wdt_private.dev = dev;
  458. iTCO_wdt_private.pdev = to_pci_dev(dev->dev.parent);
  459. /*
  460. * Get the Memory-Mapped GCS register, we need it for the
  461. * NO_REBOOT flag (TCO v2).
  462. */
  463. if (iTCO_wdt_private.iTCO_version == 2) {
  464. iTCO_wdt_private.gcs_res = platform_get_resource(dev,
  465. IORESOURCE_MEM,
  466. ICH_RES_MEM_GCS);
  467. if (!iTCO_wdt_private.gcs_res)
  468. goto out;
  469. if (!request_mem_region(iTCO_wdt_private.gcs_res->start,
  470. resource_size(iTCO_wdt_private.gcs_res), dev->name)) {
  471. ret = -EBUSY;
  472. goto out;
  473. }
  474. iTCO_wdt_private.gcs = ioremap(iTCO_wdt_private.gcs_res->start,
  475. resource_size(iTCO_wdt_private.gcs_res));
  476. if (!iTCO_wdt_private.gcs) {
  477. ret = -EIO;
  478. goto unreg_gcs;
  479. }
  480. }
  481. /* Check chipset's NO_REBOOT bit */
  482. if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
  483. pr_info("unable to reset NO_REBOOT flag, device disabled by hardware/BIOS\n");
  484. ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
  485. goto unmap_gcs;
  486. }
  487. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  488. iTCO_wdt_set_NO_REBOOT_bit();
  489. /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
  490. if (!request_region(iTCO_wdt_private.smi_res->start,
  491. resource_size(iTCO_wdt_private.smi_res), dev->name)) {
  492. pr_err("I/O address 0x%04llx already in use, device disabled\n",
  493. (u64)SMI_EN);
  494. ret = -EBUSY;
  495. goto unmap_gcs;
  496. }
  497. if (turn_SMI_watchdog_clear_off >= iTCO_wdt_private.iTCO_version) {
  498. /*
  499. * Bit 13: TCO_EN -> 0
  500. * Disables TCO logic generating an SMI#
  501. */
  502. val32 = inl(SMI_EN);
  503. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  504. outl(val32, SMI_EN);
  505. }
  506. if (!request_region(iTCO_wdt_private.tco_res->start,
  507. resource_size(iTCO_wdt_private.tco_res), dev->name)) {
  508. pr_err("I/O address 0x%04llx already in use, device disabled\n",
  509. (u64)TCOBASE);
  510. ret = -EBUSY;
  511. goto unreg_smi;
  512. }
  513. pr_info("Found a %s TCO device (Version=%d, TCOBASE=0x%04llx)\n",
  514. ich_info->name, ich_info->iTCO_version, (u64)TCOBASE);
  515. /* Clear out the (probably old) status */
  516. outw(0x0008, TCO1_STS); /* Clear the Time Out Status bit */
  517. outw(0x0002, TCO2_STS); /* Clear SECOND_TO_STS bit */
  518. outw(0x0004, TCO2_STS); /* Clear BOOT_STS bit */
  519. /* Make sure the watchdog is not running */
  520. iTCO_wdt_stop();
  521. /* Check that the heartbeat value is within it's range;
  522. if not reset to the default */
  523. if (iTCO_wdt_set_heartbeat(heartbeat)) {
  524. iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT);
  525. pr_info("timeout value out of range, using %d\n", heartbeat);
  526. }
  527. ret = misc_register(&iTCO_wdt_miscdev);
  528. if (ret != 0) {
  529. pr_err("cannot register miscdev on minor=%d (err=%d)\n",
  530. WATCHDOG_MINOR, ret);
  531. goto unreg_tco;
  532. }
  533. pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
  534. heartbeat, nowayout);
  535. return 0;
  536. unreg_tco:
  537. release_region(iTCO_wdt_private.tco_res->start,
  538. resource_size(iTCO_wdt_private.tco_res));
  539. unreg_smi:
  540. release_region(iTCO_wdt_private.smi_res->start,
  541. resource_size(iTCO_wdt_private.smi_res));
  542. unmap_gcs:
  543. if (iTCO_wdt_private.iTCO_version == 2)
  544. iounmap(iTCO_wdt_private.gcs);
  545. unreg_gcs:
  546. if (iTCO_wdt_private.iTCO_version == 2)
  547. release_mem_region(iTCO_wdt_private.gcs_res->start,
  548. resource_size(iTCO_wdt_private.gcs_res));
  549. out:
  550. iTCO_wdt_private.tco_res = NULL;
  551. iTCO_wdt_private.smi_res = NULL;
  552. iTCO_wdt_private.gcs_res = NULL;
  553. iTCO_wdt_private.gcs = NULL;
  554. return ret;
  555. }
  556. static int __devexit iTCO_wdt_remove(struct platform_device *dev)
  557. {
  558. if (iTCO_wdt_private.tco_res || iTCO_wdt_private.smi_res)
  559. iTCO_wdt_cleanup();
  560. return 0;
  561. }
  562. static void iTCO_wdt_shutdown(struct platform_device *dev)
  563. {
  564. iTCO_wdt_stop();
  565. }
  566. static struct platform_driver iTCO_wdt_driver = {
  567. .probe = iTCO_wdt_probe,
  568. .remove = __devexit_p(iTCO_wdt_remove),
  569. .shutdown = iTCO_wdt_shutdown,
  570. .driver = {
  571. .owner = THIS_MODULE,
  572. .name = DRV_NAME,
  573. },
  574. };
  575. static int __init iTCO_wdt_init_module(void)
  576. {
  577. int err;
  578. pr_info("Intel TCO WatchDog Timer Driver v%s\n", DRV_VERSION);
  579. err = platform_driver_register(&iTCO_wdt_driver);
  580. if (err)
  581. return err;
  582. return 0;
  583. }
  584. static void __exit iTCO_wdt_cleanup_module(void)
  585. {
  586. platform_driver_unregister(&iTCO_wdt_driver);
  587. pr_info("Watchdog Module Unloaded\n");
  588. }
  589. module_init(iTCO_wdt_init_module);
  590. module_exit(iTCO_wdt_cleanup_module);
  591. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
  592. MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
  593. MODULE_VERSION(DRV_VERSION);
  594. MODULE_LICENSE("GPL");
  595. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);