iTCO_wdt.c 18 KB

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