iTCO_wdt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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. * document number TBD : Lynx Point-LP
  41. */
  42. /*
  43. * Includes, defines, variables, module parameters, ...
  44. */
  45. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  46. /* Module and version information */
  47. #define DRV_NAME "iTCO_wdt"
  48. #define DRV_VERSION "1.11"
  49. /* Includes */
  50. #include <linux/module.h> /* For module specific items */
  51. #include <linux/moduleparam.h> /* For new moduleparam's */
  52. #include <linux/types.h> /* For standard types (like size_t) */
  53. #include <linux/errno.h> /* For the -ENODEV/... values */
  54. #include <linux/kernel.h> /* For printk/panic/... */
  55. #include <linux/watchdog.h> /* For the watchdog specific items */
  56. #include <linux/init.h> /* For __init/__exit/... */
  57. #include <linux/fs.h> /* For file operations */
  58. #include <linux/platform_device.h> /* For platform_driver framework */
  59. #include <linux/pci.h> /* For pci functions */
  60. #include <linux/ioport.h> /* For io-port access */
  61. #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
  62. #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
  63. #include <linux/io.h> /* For inb/outb/... */
  64. #include <linux/mfd/core.h>
  65. #include <linux/mfd/lpc_ich.h>
  66. #include "iTCO_vendor.h"
  67. /* Address definitions for the TCO */
  68. /* TCO base address */
  69. #define TCOBASE (iTCO_wdt_private.tco_res->start)
  70. /* SMI Control and Enable Register */
  71. #define SMI_EN (iTCO_wdt_private.smi_res->start)
  72. #define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload and Curr. Value */
  73. #define TCOv1_TMR (TCOBASE + 0x01) /* TCOv1 Timer Initial Value */
  74. #define TCO_DAT_IN (TCOBASE + 0x02) /* TCO Data In Register */
  75. #define TCO_DAT_OUT (TCOBASE + 0x03) /* TCO Data Out Register */
  76. #define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */
  77. #define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */
  78. #define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */
  79. #define TCO2_CNT (TCOBASE + 0x0a) /* TCO2 Control Register */
  80. #define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value */
  81. /* internal variables */
  82. static struct { /* this is private data for the iTCO_wdt device */
  83. /* TCO version/generation */
  84. unsigned int iTCO_version;
  85. struct resource *tco_res;
  86. struct resource *smi_res;
  87. /*
  88. * NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2),
  89. * or memory-mapped PMC register bit 4 (TCO version 3).
  90. */
  91. struct resource *gcs_pmc_res;
  92. unsigned long __iomem *gcs_pmc;
  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_TIMEOUT 30 /* 30 sec default heartbeat */
  101. static int heartbeat = WATCHDOG_TIMEOUT; /* 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_TIMEOUT) ")");
  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. /*
  119. * The iTCO v1 and v2's internal timer is stored as ticks which decrement
  120. * every 0.6 seconds. v3's internal timer is stored as seconds (some
  121. * datasheets incorrectly state 0.6 seconds).
  122. */
  123. static inline unsigned int seconds_to_ticks(int secs)
  124. {
  125. return iTCO_wdt_private.iTCO_version == 3 ? secs : (secs * 10) / 6;
  126. }
  127. static inline unsigned int ticks_to_seconds(int ticks)
  128. {
  129. return iTCO_wdt_private.iTCO_version == 3 ? ticks : (ticks * 6) / 10;
  130. }
  131. static void iTCO_wdt_set_NO_REBOOT_bit(void)
  132. {
  133. u32 val32;
  134. /* Set the NO_REBOOT bit: this disables reboots */
  135. if (iTCO_wdt_private.iTCO_version == 3) {
  136. val32 = readl(iTCO_wdt_private.gcs_pmc);
  137. val32 |= 0x00000010;
  138. writel(val32, iTCO_wdt_private.gcs_pmc);
  139. } else if (iTCO_wdt_private.iTCO_version == 2) {
  140. val32 = readl(iTCO_wdt_private.gcs_pmc);
  141. val32 |= 0x00000020;
  142. writel(val32, iTCO_wdt_private.gcs_pmc);
  143. } else if (iTCO_wdt_private.iTCO_version == 1) {
  144. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  145. val32 |= 0x00000002;
  146. pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
  147. }
  148. }
  149. static int iTCO_wdt_unset_NO_REBOOT_bit(void)
  150. {
  151. int ret = 0;
  152. u32 val32;
  153. /* Unset the NO_REBOOT bit: this enables reboots */
  154. if (iTCO_wdt_private.iTCO_version == 3) {
  155. val32 = readl(iTCO_wdt_private.gcs_pmc);
  156. val32 &= 0xffffffef;
  157. writel(val32, iTCO_wdt_private.gcs_pmc);
  158. val32 = readl(iTCO_wdt_private.gcs_pmc);
  159. if (val32 & 0x00000010)
  160. ret = -EIO;
  161. } else if (iTCO_wdt_private.iTCO_version == 2) {
  162. val32 = readl(iTCO_wdt_private.gcs_pmc);
  163. val32 &= 0xffffffdf;
  164. writel(val32, iTCO_wdt_private.gcs_pmc);
  165. val32 = readl(iTCO_wdt_private.gcs_pmc);
  166. if (val32 & 0x00000020)
  167. ret = -EIO;
  168. } else if (iTCO_wdt_private.iTCO_version == 1) {
  169. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  170. val32 &= 0xfffffffd;
  171. pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
  172. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  173. if (val32 & 0x00000002)
  174. ret = -EIO;
  175. }
  176. return ret; /* returns: 0 = OK, -EIO = Error */
  177. }
  178. static int iTCO_wdt_start(struct watchdog_device *wd_dev)
  179. {
  180. unsigned int val;
  181. spin_lock(&iTCO_wdt_private.io_lock);
  182. iTCO_vendor_pre_start(iTCO_wdt_private.smi_res, wd_dev->timeout);
  183. /* disable chipset's NO_REBOOT bit */
  184. if (iTCO_wdt_unset_NO_REBOOT_bit()) {
  185. spin_unlock(&iTCO_wdt_private.io_lock);
  186. pr_err("failed to reset NO_REBOOT flag, reboot disabled by hardware/BIOS\n");
  187. return -EIO;
  188. }
  189. /* Force the timer to its reload value by writing to the TCO_RLD
  190. register */
  191. if (iTCO_wdt_private.iTCO_version >= 2)
  192. outw(0x01, TCO_RLD);
  193. else if (iTCO_wdt_private.iTCO_version == 1)
  194. outb(0x01, TCO_RLD);
  195. /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
  196. val = inw(TCO1_CNT);
  197. val &= 0xf7ff;
  198. outw(val, TCO1_CNT);
  199. val = inw(TCO1_CNT);
  200. spin_unlock(&iTCO_wdt_private.io_lock);
  201. if (val & 0x0800)
  202. return -1;
  203. return 0;
  204. }
  205. static int iTCO_wdt_stop(struct watchdog_device *wd_dev)
  206. {
  207. unsigned int val;
  208. spin_lock(&iTCO_wdt_private.io_lock);
  209. iTCO_vendor_pre_stop(iTCO_wdt_private.smi_res);
  210. /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
  211. val = inw(TCO1_CNT);
  212. val |= 0x0800;
  213. outw(val, TCO1_CNT);
  214. val = inw(TCO1_CNT);
  215. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  216. iTCO_wdt_set_NO_REBOOT_bit();
  217. spin_unlock(&iTCO_wdt_private.io_lock);
  218. if ((val & 0x0800) == 0)
  219. return -1;
  220. return 0;
  221. }
  222. static int iTCO_wdt_ping(struct watchdog_device *wd_dev)
  223. {
  224. spin_lock(&iTCO_wdt_private.io_lock);
  225. iTCO_vendor_pre_keepalive(iTCO_wdt_private.smi_res, wd_dev->timeout);
  226. /* Reload the timer by writing to the TCO Timer Counter register */
  227. if (iTCO_wdt_private.iTCO_version >= 2) {
  228. outw(0x01, TCO_RLD);
  229. } else if (iTCO_wdt_private.iTCO_version == 1) {
  230. /* Reset the timeout status bit so that the timer
  231. * needs to count down twice again before rebooting */
  232. outw(0x0008, TCO1_STS); /* write 1 to clear bit */
  233. outb(0x01, TCO_RLD);
  234. }
  235. spin_unlock(&iTCO_wdt_private.io_lock);
  236. return 0;
  237. }
  238. static int iTCO_wdt_set_timeout(struct watchdog_device *wd_dev, unsigned int t)
  239. {
  240. unsigned int val16;
  241. unsigned char val8;
  242. unsigned int tmrval;
  243. tmrval = seconds_to_ticks(t);
  244. /* For TCO v1 the timer counts down twice before rebooting */
  245. if (iTCO_wdt_private.iTCO_version == 1)
  246. tmrval /= 2;
  247. /* from the specs: */
  248. /* "Values of 0h-3h are ignored and should not be attempted" */
  249. if (tmrval < 0x04)
  250. return -EINVAL;
  251. if (((iTCO_wdt_private.iTCO_version >= 2) && (tmrval > 0x3ff)) ||
  252. ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
  253. return -EINVAL;
  254. iTCO_vendor_pre_set_heartbeat(tmrval);
  255. /* Write new heartbeat to watchdog */
  256. if (iTCO_wdt_private.iTCO_version >= 2) {
  257. spin_lock(&iTCO_wdt_private.io_lock);
  258. val16 = inw(TCOv2_TMR);
  259. val16 &= 0xfc00;
  260. val16 |= tmrval;
  261. outw(val16, TCOv2_TMR);
  262. val16 = inw(TCOv2_TMR);
  263. spin_unlock(&iTCO_wdt_private.io_lock);
  264. if ((val16 & 0x3ff) != tmrval)
  265. return -EINVAL;
  266. } else if (iTCO_wdt_private.iTCO_version == 1) {
  267. spin_lock(&iTCO_wdt_private.io_lock);
  268. val8 = inb(TCOv1_TMR);
  269. val8 &= 0xc0;
  270. val8 |= (tmrval & 0xff);
  271. outb(val8, TCOv1_TMR);
  272. val8 = inb(TCOv1_TMR);
  273. spin_unlock(&iTCO_wdt_private.io_lock);
  274. if ((val8 & 0x3f) != tmrval)
  275. return -EINVAL;
  276. }
  277. wd_dev->timeout = t;
  278. return 0;
  279. }
  280. static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
  281. {
  282. unsigned int val16;
  283. unsigned char val8;
  284. unsigned int time_left = 0;
  285. /* read the TCO Timer */
  286. if (iTCO_wdt_private.iTCO_version >= 2) {
  287. spin_lock(&iTCO_wdt_private.io_lock);
  288. val16 = inw(TCO_RLD);
  289. val16 &= 0x3ff;
  290. spin_unlock(&iTCO_wdt_private.io_lock);
  291. time_left = ticks_to_seconds(val16);
  292. } else if (iTCO_wdt_private.iTCO_version == 1) {
  293. spin_lock(&iTCO_wdt_private.io_lock);
  294. val8 = inb(TCO_RLD);
  295. val8 &= 0x3f;
  296. if (!(inw(TCO1_STS) & 0x0008))
  297. val8 += (inb(TCOv1_TMR) & 0x3f);
  298. spin_unlock(&iTCO_wdt_private.io_lock);
  299. time_left = ticks_to_seconds(val8);
  300. }
  301. return time_left;
  302. }
  303. /*
  304. * Kernel Interfaces
  305. */
  306. static const struct watchdog_info ident = {
  307. .options = WDIOF_SETTIMEOUT |
  308. WDIOF_KEEPALIVEPING |
  309. WDIOF_MAGICCLOSE,
  310. .firmware_version = 0,
  311. .identity = DRV_NAME,
  312. };
  313. static const struct watchdog_ops iTCO_wdt_ops = {
  314. .owner = THIS_MODULE,
  315. .start = iTCO_wdt_start,
  316. .stop = iTCO_wdt_stop,
  317. .ping = iTCO_wdt_ping,
  318. .set_timeout = iTCO_wdt_set_timeout,
  319. .get_timeleft = iTCO_wdt_get_timeleft,
  320. };
  321. static struct watchdog_device iTCO_wdt_watchdog_dev = {
  322. .info = &ident,
  323. .ops = &iTCO_wdt_ops,
  324. };
  325. /*
  326. * Init & exit routines
  327. */
  328. static void iTCO_wdt_cleanup(void)
  329. {
  330. /* Stop the timer before we leave */
  331. if (!nowayout)
  332. iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
  333. /* Deregister */
  334. watchdog_unregister_device(&iTCO_wdt_watchdog_dev);
  335. /* release resources */
  336. release_region(iTCO_wdt_private.tco_res->start,
  337. resource_size(iTCO_wdt_private.tco_res));
  338. release_region(iTCO_wdt_private.smi_res->start,
  339. resource_size(iTCO_wdt_private.smi_res));
  340. if (iTCO_wdt_private.iTCO_version >= 2) {
  341. iounmap(iTCO_wdt_private.gcs_pmc);
  342. release_mem_region(iTCO_wdt_private.gcs_pmc_res->start,
  343. resource_size(iTCO_wdt_private.gcs_pmc_res));
  344. }
  345. iTCO_wdt_private.tco_res = NULL;
  346. iTCO_wdt_private.smi_res = NULL;
  347. iTCO_wdt_private.gcs_pmc_res = NULL;
  348. iTCO_wdt_private.gcs_pmc = NULL;
  349. }
  350. static int iTCO_wdt_probe(struct platform_device *dev)
  351. {
  352. int ret = -ENODEV;
  353. unsigned long val32;
  354. struct lpc_ich_info *ich_info = dev_get_platdata(&dev->dev);
  355. if (!ich_info)
  356. goto out;
  357. spin_lock_init(&iTCO_wdt_private.io_lock);
  358. iTCO_wdt_private.tco_res =
  359. platform_get_resource(dev, IORESOURCE_IO, ICH_RES_IO_TCO);
  360. if (!iTCO_wdt_private.tco_res)
  361. goto out;
  362. iTCO_wdt_private.smi_res =
  363. platform_get_resource(dev, IORESOURCE_IO, ICH_RES_IO_SMI);
  364. if (!iTCO_wdt_private.smi_res)
  365. goto out;
  366. iTCO_wdt_private.iTCO_version = ich_info->iTCO_version;
  367. iTCO_wdt_private.dev = dev;
  368. iTCO_wdt_private.pdev = to_pci_dev(dev->dev.parent);
  369. /*
  370. * Get the Memory-Mapped GCS or PMC register, we need it for the
  371. * NO_REBOOT flag (TCO v2 and v3).
  372. */
  373. if (iTCO_wdt_private.iTCO_version >= 2) {
  374. iTCO_wdt_private.gcs_pmc_res = platform_get_resource(dev,
  375. IORESOURCE_MEM,
  376. ICH_RES_MEM_GCS_PMC);
  377. if (!iTCO_wdt_private.gcs_pmc_res)
  378. goto out;
  379. if (!request_mem_region(iTCO_wdt_private.gcs_pmc_res->start,
  380. resource_size(iTCO_wdt_private.gcs_pmc_res), dev->name)) {
  381. ret = -EBUSY;
  382. goto out;
  383. }
  384. iTCO_wdt_private.gcs_pmc = ioremap(iTCO_wdt_private.gcs_pmc_res->start,
  385. resource_size(iTCO_wdt_private.gcs_pmc_res));
  386. if (!iTCO_wdt_private.gcs_pmc) {
  387. ret = -EIO;
  388. goto unreg_gcs_pmc;
  389. }
  390. }
  391. /* Check chipset's NO_REBOOT bit */
  392. if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
  393. pr_info("unable to reset NO_REBOOT flag, device disabled by hardware/BIOS\n");
  394. ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
  395. goto unmap_gcs_pmc;
  396. }
  397. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  398. iTCO_wdt_set_NO_REBOOT_bit();
  399. /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
  400. if (!request_region(iTCO_wdt_private.smi_res->start,
  401. resource_size(iTCO_wdt_private.smi_res), dev->name)) {
  402. pr_err("I/O address 0x%04llx already in use, device disabled\n",
  403. (u64)SMI_EN);
  404. ret = -EBUSY;
  405. goto unmap_gcs_pmc;
  406. }
  407. if (turn_SMI_watchdog_clear_off >= iTCO_wdt_private.iTCO_version) {
  408. /*
  409. * Bit 13: TCO_EN -> 0
  410. * Disables TCO logic generating an SMI#
  411. */
  412. val32 = inl(SMI_EN);
  413. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  414. outl(val32, SMI_EN);
  415. }
  416. if (!request_region(iTCO_wdt_private.tco_res->start,
  417. resource_size(iTCO_wdt_private.tco_res), dev->name)) {
  418. pr_err("I/O address 0x%04llx already in use, device disabled\n",
  419. (u64)TCOBASE);
  420. ret = -EBUSY;
  421. goto unreg_smi;
  422. }
  423. pr_info("Found a %s TCO device (Version=%d, TCOBASE=0x%04llx)\n",
  424. ich_info->name, ich_info->iTCO_version, (u64)TCOBASE);
  425. /* Clear out the (probably old) status */
  426. if (iTCO_wdt_private.iTCO_version == 3) {
  427. outl(0x20008, TCO1_STS);
  428. } else {
  429. outw(0x0008, TCO1_STS); /* Clear the Time Out Status bit */
  430. outw(0x0002, TCO2_STS); /* Clear SECOND_TO_STS bit */
  431. outw(0x0004, TCO2_STS); /* Clear BOOT_STS bit */
  432. }
  433. iTCO_wdt_watchdog_dev.bootstatus = 0;
  434. iTCO_wdt_watchdog_dev.timeout = WATCHDOG_TIMEOUT;
  435. watchdog_set_nowayout(&iTCO_wdt_watchdog_dev, nowayout);
  436. iTCO_wdt_watchdog_dev.parent = &dev->dev;
  437. /* Make sure the watchdog is not running */
  438. iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
  439. /* Check that the heartbeat value is within it's range;
  440. if not reset to the default */
  441. if (iTCO_wdt_set_timeout(&iTCO_wdt_watchdog_dev, heartbeat)) {
  442. iTCO_wdt_set_timeout(&iTCO_wdt_watchdog_dev, WATCHDOG_TIMEOUT);
  443. pr_info("timeout value out of range, using %d\n",
  444. WATCHDOG_TIMEOUT);
  445. }
  446. ret = watchdog_register_device(&iTCO_wdt_watchdog_dev);
  447. if (ret != 0) {
  448. pr_err("cannot register watchdog device (err=%d)\n", ret);
  449. goto unreg_tco;
  450. }
  451. pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
  452. heartbeat, nowayout);
  453. return 0;
  454. unreg_tco:
  455. release_region(iTCO_wdt_private.tco_res->start,
  456. resource_size(iTCO_wdt_private.tco_res));
  457. unreg_smi:
  458. release_region(iTCO_wdt_private.smi_res->start,
  459. resource_size(iTCO_wdt_private.smi_res));
  460. unmap_gcs_pmc:
  461. if (iTCO_wdt_private.iTCO_version >= 2)
  462. iounmap(iTCO_wdt_private.gcs_pmc);
  463. unreg_gcs_pmc:
  464. if (iTCO_wdt_private.iTCO_version >= 2)
  465. release_mem_region(iTCO_wdt_private.gcs_pmc_res->start,
  466. resource_size(iTCO_wdt_private.gcs_pmc_res));
  467. out:
  468. iTCO_wdt_private.tco_res = NULL;
  469. iTCO_wdt_private.smi_res = NULL;
  470. iTCO_wdt_private.gcs_pmc_res = NULL;
  471. iTCO_wdt_private.gcs_pmc = NULL;
  472. return ret;
  473. }
  474. static int iTCO_wdt_remove(struct platform_device *dev)
  475. {
  476. if (iTCO_wdt_private.tco_res || iTCO_wdt_private.smi_res)
  477. iTCO_wdt_cleanup();
  478. return 0;
  479. }
  480. static void iTCO_wdt_shutdown(struct platform_device *dev)
  481. {
  482. iTCO_wdt_stop(NULL);
  483. }
  484. static struct platform_driver iTCO_wdt_driver = {
  485. .probe = iTCO_wdt_probe,
  486. .remove = iTCO_wdt_remove,
  487. .shutdown = iTCO_wdt_shutdown,
  488. .driver = {
  489. .owner = THIS_MODULE,
  490. .name = DRV_NAME,
  491. },
  492. };
  493. static int __init iTCO_wdt_init_module(void)
  494. {
  495. int err;
  496. pr_info("Intel TCO WatchDog Timer Driver v%s\n", DRV_VERSION);
  497. err = platform_driver_register(&iTCO_wdt_driver);
  498. if (err)
  499. return err;
  500. return 0;
  501. }
  502. static void __exit iTCO_wdt_cleanup_module(void)
  503. {
  504. platform_driver_unregister(&iTCO_wdt_driver);
  505. pr_info("Watchdog Module Unloaded\n");
  506. }
  507. module_init(iTCO_wdt_init_module);
  508. module_exit(iTCO_wdt_cleanup_module);
  509. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
  510. MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
  511. MODULE_VERSION(DRV_VERSION);
  512. MODULE_LICENSE("GPL");
  513. MODULE_ALIAS("platform:" DRV_NAME);