iTCO_wdt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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/acpi.h> /* For ACPI support */
  51. #include <linux/module.h> /* For module specific items */
  52. #include <linux/moduleparam.h> /* For new moduleparam's */
  53. #include <linux/types.h> /* For standard types (like size_t) */
  54. #include <linux/errno.h> /* For the -ENODEV/... values */
  55. #include <linux/kernel.h> /* For printk/panic/... */
  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/platform_data/itco_wdt.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. /* whether or not the watchdog has been suspended */
  99. bool suspended;
  100. } iTCO_wdt_private;
  101. /* module parameters */
  102. #define WATCHDOG_TIMEOUT 30 /* 30 sec default heartbeat */
  103. static int heartbeat = WATCHDOG_TIMEOUT; /* in seconds */
  104. module_param(heartbeat, int, 0);
  105. MODULE_PARM_DESC(heartbeat, "Watchdog timeout in seconds. "
  106. "5..76 (TCO v1) or 3..614 (TCO v2), default="
  107. __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
  108. static bool nowayout = WATCHDOG_NOWAYOUT;
  109. module_param(nowayout, bool, 0);
  110. MODULE_PARM_DESC(nowayout,
  111. "Watchdog cannot be stopped once started (default="
  112. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  113. static int turn_SMI_watchdog_clear_off = 1;
  114. module_param(turn_SMI_watchdog_clear_off, int, 0);
  115. MODULE_PARM_DESC(turn_SMI_watchdog_clear_off,
  116. "Turn off SMI clearing watchdog (depends on TCO-version)(default=1)");
  117. /*
  118. * Some TCO specific functions
  119. */
  120. /*
  121. * The iTCO v1 and v2's internal timer is stored as ticks which decrement
  122. * every 0.6 seconds. v3's internal timer is stored as seconds (some
  123. * datasheets incorrectly state 0.6 seconds).
  124. */
  125. static inline unsigned int seconds_to_ticks(int secs)
  126. {
  127. return iTCO_wdt_private.iTCO_version == 3 ? secs : (secs * 10) / 6;
  128. }
  129. static inline unsigned int ticks_to_seconds(int ticks)
  130. {
  131. return iTCO_wdt_private.iTCO_version == 3 ? ticks : (ticks * 6) / 10;
  132. }
  133. static inline u32 no_reboot_bit(void)
  134. {
  135. u32 enable_bit;
  136. switch (iTCO_wdt_private.iTCO_version) {
  137. case 5:
  138. case 3:
  139. enable_bit = 0x00000010;
  140. break;
  141. case 2:
  142. enable_bit = 0x00000020;
  143. break;
  144. case 4:
  145. case 1:
  146. default:
  147. enable_bit = 0x00000002;
  148. break;
  149. }
  150. return enable_bit;
  151. }
  152. static void iTCO_wdt_set_NO_REBOOT_bit(void)
  153. {
  154. u32 val32;
  155. /* Set the NO_REBOOT bit: this disables reboots */
  156. if (iTCO_wdt_private.iTCO_version >= 2) {
  157. val32 = readl(iTCO_wdt_private.gcs_pmc);
  158. val32 |= no_reboot_bit();
  159. writel(val32, iTCO_wdt_private.gcs_pmc);
  160. } else if (iTCO_wdt_private.iTCO_version == 1) {
  161. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  162. val32 |= no_reboot_bit();
  163. pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
  164. }
  165. }
  166. static int iTCO_wdt_unset_NO_REBOOT_bit(void)
  167. {
  168. u32 enable_bit = no_reboot_bit();
  169. u32 val32 = 0;
  170. /* Unset the NO_REBOOT bit: this enables reboots */
  171. if (iTCO_wdt_private.iTCO_version >= 2) {
  172. val32 = readl(iTCO_wdt_private.gcs_pmc);
  173. val32 &= ~enable_bit;
  174. writel(val32, iTCO_wdt_private.gcs_pmc);
  175. val32 = readl(iTCO_wdt_private.gcs_pmc);
  176. } else if (iTCO_wdt_private.iTCO_version == 1) {
  177. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  178. val32 &= ~enable_bit;
  179. pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
  180. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  181. }
  182. if (val32 & enable_bit)
  183. return -EIO;
  184. return 0;
  185. }
  186. static int iTCO_wdt_start(struct watchdog_device *wd_dev)
  187. {
  188. unsigned int val;
  189. spin_lock(&iTCO_wdt_private.io_lock);
  190. iTCO_vendor_pre_start(iTCO_wdt_private.smi_res, wd_dev->timeout);
  191. /* disable chipset's NO_REBOOT bit */
  192. if (iTCO_wdt_unset_NO_REBOOT_bit()) {
  193. spin_unlock(&iTCO_wdt_private.io_lock);
  194. pr_err("failed to reset NO_REBOOT flag, reboot disabled by hardware/BIOS\n");
  195. return -EIO;
  196. }
  197. /* Force the timer to its reload value by writing to the TCO_RLD
  198. register */
  199. if (iTCO_wdt_private.iTCO_version >= 2)
  200. outw(0x01, TCO_RLD);
  201. else if (iTCO_wdt_private.iTCO_version == 1)
  202. outb(0x01, TCO_RLD);
  203. /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
  204. val = inw(TCO1_CNT);
  205. val &= 0xf7ff;
  206. outw(val, TCO1_CNT);
  207. val = inw(TCO1_CNT);
  208. spin_unlock(&iTCO_wdt_private.io_lock);
  209. if (val & 0x0800)
  210. return -1;
  211. return 0;
  212. }
  213. static int iTCO_wdt_stop(struct watchdog_device *wd_dev)
  214. {
  215. unsigned int val;
  216. spin_lock(&iTCO_wdt_private.io_lock);
  217. iTCO_vendor_pre_stop(iTCO_wdt_private.smi_res);
  218. /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
  219. val = inw(TCO1_CNT);
  220. val |= 0x0800;
  221. outw(val, TCO1_CNT);
  222. val = inw(TCO1_CNT);
  223. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  224. iTCO_wdt_set_NO_REBOOT_bit();
  225. spin_unlock(&iTCO_wdt_private.io_lock);
  226. if ((val & 0x0800) == 0)
  227. return -1;
  228. return 0;
  229. }
  230. static int iTCO_wdt_ping(struct watchdog_device *wd_dev)
  231. {
  232. spin_lock(&iTCO_wdt_private.io_lock);
  233. iTCO_vendor_pre_keepalive(iTCO_wdt_private.smi_res, wd_dev->timeout);
  234. /* Reload the timer by writing to the TCO Timer Counter register */
  235. if (iTCO_wdt_private.iTCO_version >= 2) {
  236. outw(0x01, TCO_RLD);
  237. } else if (iTCO_wdt_private.iTCO_version == 1) {
  238. /* Reset the timeout status bit so that the timer
  239. * needs to count down twice again before rebooting */
  240. outw(0x0008, TCO1_STS); /* write 1 to clear bit */
  241. outb(0x01, TCO_RLD);
  242. }
  243. spin_unlock(&iTCO_wdt_private.io_lock);
  244. return 0;
  245. }
  246. static int iTCO_wdt_set_timeout(struct watchdog_device *wd_dev, unsigned int t)
  247. {
  248. unsigned int val16;
  249. unsigned char val8;
  250. unsigned int tmrval;
  251. tmrval = seconds_to_ticks(t);
  252. /* For TCO v1 the timer counts down twice before rebooting */
  253. if (iTCO_wdt_private.iTCO_version == 1)
  254. tmrval /= 2;
  255. /* from the specs: */
  256. /* "Values of 0h-3h are ignored and should not be attempted" */
  257. if (tmrval < 0x04)
  258. return -EINVAL;
  259. if (((iTCO_wdt_private.iTCO_version >= 2) && (tmrval > 0x3ff)) ||
  260. ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
  261. return -EINVAL;
  262. iTCO_vendor_pre_set_heartbeat(tmrval);
  263. /* Write new heartbeat to watchdog */
  264. if (iTCO_wdt_private.iTCO_version >= 2) {
  265. spin_lock(&iTCO_wdt_private.io_lock);
  266. val16 = inw(TCOv2_TMR);
  267. val16 &= 0xfc00;
  268. val16 |= tmrval;
  269. outw(val16, TCOv2_TMR);
  270. val16 = inw(TCOv2_TMR);
  271. spin_unlock(&iTCO_wdt_private.io_lock);
  272. if ((val16 & 0x3ff) != tmrval)
  273. return -EINVAL;
  274. } else if (iTCO_wdt_private.iTCO_version == 1) {
  275. spin_lock(&iTCO_wdt_private.io_lock);
  276. val8 = inb(TCOv1_TMR);
  277. val8 &= 0xc0;
  278. val8 |= (tmrval & 0xff);
  279. outb(val8, TCOv1_TMR);
  280. val8 = inb(TCOv1_TMR);
  281. spin_unlock(&iTCO_wdt_private.io_lock);
  282. if ((val8 & 0x3f) != tmrval)
  283. return -EINVAL;
  284. }
  285. wd_dev->timeout = t;
  286. return 0;
  287. }
  288. static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
  289. {
  290. unsigned int val16;
  291. unsigned char val8;
  292. unsigned int time_left = 0;
  293. /* read the TCO Timer */
  294. if (iTCO_wdt_private.iTCO_version >= 2) {
  295. spin_lock(&iTCO_wdt_private.io_lock);
  296. val16 = inw(TCO_RLD);
  297. val16 &= 0x3ff;
  298. spin_unlock(&iTCO_wdt_private.io_lock);
  299. time_left = ticks_to_seconds(val16);
  300. } else if (iTCO_wdt_private.iTCO_version == 1) {
  301. spin_lock(&iTCO_wdt_private.io_lock);
  302. val8 = inb(TCO_RLD);
  303. val8 &= 0x3f;
  304. if (!(inw(TCO1_STS) & 0x0008))
  305. val8 += (inb(TCOv1_TMR) & 0x3f);
  306. spin_unlock(&iTCO_wdt_private.io_lock);
  307. time_left = ticks_to_seconds(val8);
  308. }
  309. return time_left;
  310. }
  311. /*
  312. * Kernel Interfaces
  313. */
  314. static const struct watchdog_info ident = {
  315. .options = WDIOF_SETTIMEOUT |
  316. WDIOF_KEEPALIVEPING |
  317. WDIOF_MAGICCLOSE,
  318. .firmware_version = 0,
  319. .identity = DRV_NAME,
  320. };
  321. static const struct watchdog_ops iTCO_wdt_ops = {
  322. .owner = THIS_MODULE,
  323. .start = iTCO_wdt_start,
  324. .stop = iTCO_wdt_stop,
  325. .ping = iTCO_wdt_ping,
  326. .set_timeout = iTCO_wdt_set_timeout,
  327. .get_timeleft = iTCO_wdt_get_timeleft,
  328. };
  329. static struct watchdog_device iTCO_wdt_watchdog_dev = {
  330. .info = &ident,
  331. .ops = &iTCO_wdt_ops,
  332. };
  333. /*
  334. * Init & exit routines
  335. */
  336. static void iTCO_wdt_cleanup(void)
  337. {
  338. /* Stop the timer before we leave */
  339. if (!nowayout)
  340. iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
  341. /* Deregister */
  342. watchdog_unregister_device(&iTCO_wdt_watchdog_dev);
  343. /* release resources */
  344. release_region(iTCO_wdt_private.tco_res->start,
  345. resource_size(iTCO_wdt_private.tco_res));
  346. release_region(iTCO_wdt_private.smi_res->start,
  347. resource_size(iTCO_wdt_private.smi_res));
  348. if (iTCO_wdt_private.iTCO_version >= 2) {
  349. iounmap(iTCO_wdt_private.gcs_pmc);
  350. release_mem_region(iTCO_wdt_private.gcs_pmc_res->start,
  351. resource_size(iTCO_wdt_private.gcs_pmc_res));
  352. }
  353. iTCO_wdt_private.tco_res = NULL;
  354. iTCO_wdt_private.smi_res = NULL;
  355. iTCO_wdt_private.gcs_pmc_res = NULL;
  356. iTCO_wdt_private.gcs_pmc = NULL;
  357. }
  358. static int iTCO_wdt_probe(struct platform_device *dev)
  359. {
  360. int ret = -ENODEV;
  361. unsigned long val32;
  362. struct itco_wdt_platform_data *pdata = dev_get_platdata(&dev->dev);
  363. if (!pdata)
  364. goto out;
  365. spin_lock_init(&iTCO_wdt_private.io_lock);
  366. iTCO_wdt_private.tco_res =
  367. platform_get_resource(dev, IORESOURCE_IO, ICH_RES_IO_TCO);
  368. if (!iTCO_wdt_private.tco_res)
  369. goto out;
  370. iTCO_wdt_private.smi_res =
  371. platform_get_resource(dev, IORESOURCE_IO, ICH_RES_IO_SMI);
  372. if (!iTCO_wdt_private.smi_res)
  373. goto out;
  374. iTCO_wdt_private.iTCO_version = pdata->version;
  375. iTCO_wdt_private.dev = dev;
  376. iTCO_wdt_private.pdev = to_pci_dev(dev->dev.parent);
  377. /*
  378. * Get the Memory-Mapped GCS or PMC register, we need it for the
  379. * NO_REBOOT flag (TCO v2 and v3).
  380. */
  381. if (iTCO_wdt_private.iTCO_version >= 2) {
  382. iTCO_wdt_private.gcs_pmc_res = platform_get_resource(dev,
  383. IORESOURCE_MEM,
  384. ICH_RES_MEM_GCS_PMC);
  385. if (!iTCO_wdt_private.gcs_pmc_res)
  386. goto out;
  387. if (!request_mem_region(iTCO_wdt_private.gcs_pmc_res->start,
  388. resource_size(iTCO_wdt_private.gcs_pmc_res), dev->name)) {
  389. ret = -EBUSY;
  390. goto out;
  391. }
  392. iTCO_wdt_private.gcs_pmc = ioremap(iTCO_wdt_private.gcs_pmc_res->start,
  393. resource_size(iTCO_wdt_private.gcs_pmc_res));
  394. if (!iTCO_wdt_private.gcs_pmc) {
  395. ret = -EIO;
  396. goto unreg_gcs_pmc;
  397. }
  398. }
  399. /* Check chipset's NO_REBOOT bit */
  400. if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
  401. pr_info("unable to reset NO_REBOOT flag, device disabled by hardware/BIOS\n");
  402. ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
  403. goto unmap_gcs_pmc;
  404. }
  405. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  406. iTCO_wdt_set_NO_REBOOT_bit();
  407. /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
  408. if (!request_region(iTCO_wdt_private.smi_res->start,
  409. resource_size(iTCO_wdt_private.smi_res), dev->name)) {
  410. pr_err("I/O address 0x%04llx already in use, device disabled\n",
  411. (u64)SMI_EN);
  412. ret = -EBUSY;
  413. goto unmap_gcs_pmc;
  414. }
  415. if (turn_SMI_watchdog_clear_off >= iTCO_wdt_private.iTCO_version) {
  416. /*
  417. * Bit 13: TCO_EN -> 0
  418. * Disables TCO logic generating an SMI#
  419. */
  420. val32 = inl(SMI_EN);
  421. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  422. outl(val32, SMI_EN);
  423. }
  424. if (!request_region(iTCO_wdt_private.tco_res->start,
  425. resource_size(iTCO_wdt_private.tco_res), dev->name)) {
  426. pr_err("I/O address 0x%04llx already in use, device disabled\n",
  427. (u64)TCOBASE);
  428. ret = -EBUSY;
  429. goto unreg_smi;
  430. }
  431. pr_info("Found a %s TCO device (Version=%d, TCOBASE=0x%04llx)\n",
  432. pdata->name, pdata->version, (u64)TCOBASE);
  433. /* Clear out the (probably old) status */
  434. switch (iTCO_wdt_private.iTCO_version) {
  435. case 5:
  436. case 4:
  437. outw(0x0008, TCO1_STS); /* Clear the Time Out Status bit */
  438. outw(0x0002, TCO2_STS); /* Clear SECOND_TO_STS bit */
  439. break;
  440. case 3:
  441. outl(0x20008, TCO1_STS);
  442. break;
  443. case 2:
  444. case 1:
  445. default:
  446. outw(0x0008, TCO1_STS); /* Clear the Time Out Status bit */
  447. outw(0x0002, TCO2_STS); /* Clear SECOND_TO_STS bit */
  448. outw(0x0004, TCO2_STS); /* Clear BOOT_STS bit */
  449. break;
  450. }
  451. iTCO_wdt_watchdog_dev.bootstatus = 0;
  452. iTCO_wdt_watchdog_dev.timeout = WATCHDOG_TIMEOUT;
  453. watchdog_set_nowayout(&iTCO_wdt_watchdog_dev, nowayout);
  454. iTCO_wdt_watchdog_dev.parent = &dev->dev;
  455. /* Make sure the watchdog is not running */
  456. iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
  457. /* Check that the heartbeat value is within it's range;
  458. if not reset to the default */
  459. if (iTCO_wdt_set_timeout(&iTCO_wdt_watchdog_dev, heartbeat)) {
  460. iTCO_wdt_set_timeout(&iTCO_wdt_watchdog_dev, WATCHDOG_TIMEOUT);
  461. pr_info("timeout value out of range, using %d\n",
  462. WATCHDOG_TIMEOUT);
  463. }
  464. ret = watchdog_register_device(&iTCO_wdt_watchdog_dev);
  465. if (ret != 0) {
  466. pr_err("cannot register watchdog device (err=%d)\n", ret);
  467. goto unreg_tco;
  468. }
  469. pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
  470. heartbeat, nowayout);
  471. return 0;
  472. unreg_tco:
  473. release_region(iTCO_wdt_private.tco_res->start,
  474. resource_size(iTCO_wdt_private.tco_res));
  475. unreg_smi:
  476. release_region(iTCO_wdt_private.smi_res->start,
  477. resource_size(iTCO_wdt_private.smi_res));
  478. unmap_gcs_pmc:
  479. if (iTCO_wdt_private.iTCO_version >= 2)
  480. iounmap(iTCO_wdt_private.gcs_pmc);
  481. unreg_gcs_pmc:
  482. if (iTCO_wdt_private.iTCO_version >= 2)
  483. release_mem_region(iTCO_wdt_private.gcs_pmc_res->start,
  484. resource_size(iTCO_wdt_private.gcs_pmc_res));
  485. out:
  486. iTCO_wdt_private.tco_res = NULL;
  487. iTCO_wdt_private.smi_res = NULL;
  488. iTCO_wdt_private.gcs_pmc_res = NULL;
  489. iTCO_wdt_private.gcs_pmc = NULL;
  490. return ret;
  491. }
  492. static int iTCO_wdt_remove(struct platform_device *dev)
  493. {
  494. if (iTCO_wdt_private.tco_res || iTCO_wdt_private.smi_res)
  495. iTCO_wdt_cleanup();
  496. return 0;
  497. }
  498. static void iTCO_wdt_shutdown(struct platform_device *dev)
  499. {
  500. iTCO_wdt_stop(NULL);
  501. }
  502. #ifdef CONFIG_PM_SLEEP
  503. /*
  504. * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
  505. * the watchdog cannot be pinged while in that state. In ACPI sleep states the
  506. * watchdog is stopped by the platform firmware.
  507. */
  508. #ifdef CONFIG_ACPI
  509. static inline bool need_suspend(void)
  510. {
  511. return acpi_target_system_state() == ACPI_STATE_S0;
  512. }
  513. #else
  514. static inline bool need_suspend(void) { return true; }
  515. #endif
  516. static int iTCO_wdt_suspend_noirq(struct device *dev)
  517. {
  518. int ret = 0;
  519. iTCO_wdt_private.suspended = false;
  520. if (watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) {
  521. ret = iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
  522. if (!ret)
  523. iTCO_wdt_private.suspended = true;
  524. }
  525. return ret;
  526. }
  527. static int iTCO_wdt_resume_noirq(struct device *dev)
  528. {
  529. if (iTCO_wdt_private.suspended)
  530. iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
  531. return 0;
  532. }
  533. static const struct dev_pm_ops iTCO_wdt_pm = {
  534. .suspend_noirq = iTCO_wdt_suspend_noirq,
  535. .resume_noirq = iTCO_wdt_resume_noirq,
  536. };
  537. #define ITCO_WDT_PM_OPS (&iTCO_wdt_pm)
  538. #else
  539. #define ITCO_WDT_PM_OPS NULL
  540. #endif /* CONFIG_PM_SLEEP */
  541. static struct platform_driver iTCO_wdt_driver = {
  542. .probe = iTCO_wdt_probe,
  543. .remove = iTCO_wdt_remove,
  544. .shutdown = iTCO_wdt_shutdown,
  545. .driver = {
  546. .name = DRV_NAME,
  547. .pm = ITCO_WDT_PM_OPS,
  548. },
  549. };
  550. static int __init iTCO_wdt_init_module(void)
  551. {
  552. int err;
  553. pr_info("Intel TCO WatchDog Timer Driver v%s\n", DRV_VERSION);
  554. err = platform_driver_register(&iTCO_wdt_driver);
  555. if (err)
  556. return err;
  557. return 0;
  558. }
  559. static void __exit iTCO_wdt_cleanup_module(void)
  560. {
  561. platform_driver_unregister(&iTCO_wdt_driver);
  562. pr_info("Watchdog Module Unloaded\n");
  563. }
  564. module_init(iTCO_wdt_init_module);
  565. module_exit(iTCO_wdt_cleanup_module);
  566. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
  567. MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
  568. MODULE_VERSION(DRV_VERSION);
  569. MODULE_LICENSE("GPL");
  570. MODULE_ALIAS("platform:" DRV_NAME);