iTCO_wdt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * intel TCO Watchdog Driver
  4. *
  5. * (c) Copyright 2006-2011 Wim Van Sebroeck <wim@iguana.be>.
  6. *
  7. * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
  8. * provide warranty for any of this software. This material is
  9. * provided "AS-IS" and at no charge.
  10. *
  11. * The TCO watchdog is implemented in the following I/O controller hubs:
  12. * (See the intel documentation on http://developer.intel.com.)
  13. * document number 290655-003, 290677-014: 82801AA (ICH), 82801AB (ICHO)
  14. * document number 290687-002, 298242-027: 82801BA (ICH2)
  15. * document number 290733-003, 290739-013: 82801CA (ICH3-S)
  16. * document number 290716-001, 290718-007: 82801CAM (ICH3-M)
  17. * document number 290744-001, 290745-025: 82801DB (ICH4)
  18. * document number 252337-001, 252663-008: 82801DBM (ICH4-M)
  19. * document number 273599-001, 273645-002: 82801E (C-ICH)
  20. * document number 252516-001, 252517-028: 82801EB (ICH5), 82801ER (ICH5R)
  21. * document number 300641-004, 300884-013: 6300ESB
  22. * document number 301473-002, 301474-026: 82801F (ICH6)
  23. * document number 313082-001, 313075-006: 631xESB, 632xESB
  24. * document number 307013-003, 307014-024: 82801G (ICH7)
  25. * document number 322896-001, 322897-001: NM10
  26. * document number 313056-003, 313057-017: 82801H (ICH8)
  27. * document number 316972-004, 316973-012: 82801I (ICH9)
  28. * document number 319973-002, 319974-002: 82801J (ICH10)
  29. * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH)
  30. * document number 320066-003, 320257-008: EP80597 (IICH)
  31. * document number 324645-001, 324646-001: Cougar Point (CPT)
  32. * document number TBD : Patsburg (PBG)
  33. * document number TBD : DH89xxCC
  34. * document number TBD : Panther Point
  35. * document number TBD : Lynx Point
  36. * document number TBD : Lynx Point-LP
  37. */
  38. /*
  39. * Includes, defines, variables, module parameters, ...
  40. */
  41. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  42. /* Module and version information */
  43. #define DRV_NAME "iTCO_wdt"
  44. #define DRV_VERSION "1.11"
  45. /* Includes */
  46. #include <linux/acpi.h> /* For ACPI support */
  47. #include <linux/bits.h> /* For BIT() */
  48. #include <linux/module.h> /* For module specific items */
  49. #include <linux/moduleparam.h> /* For new moduleparam's */
  50. #include <linux/types.h> /* For standard types (like size_t) */
  51. #include <linux/errno.h> /* For the -ENODEV/... values */
  52. #include <linux/kernel.h> /* For printk/panic/... */
  53. #include <linux/watchdog.h> /* For the watchdog specific items */
  54. #include <linux/init.h> /* For __init/__exit/... */
  55. #include <linux/fs.h> /* For file operations */
  56. #include <linux/platform_device.h> /* For platform_driver framework */
  57. #include <linux/pci.h> /* For pci functions */
  58. #include <linux/ioport.h> /* For io-port access */
  59. #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
  60. #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
  61. #include <linux/io.h> /* For inb/outb/... */
  62. #include <linux/platform_data/itco_wdt.h>
  63. #include "iTCO_vendor.h"
  64. /* Address definitions for the TCO */
  65. /* TCO base address */
  66. #define TCOBASE(p) ((p)->tco_res->start)
  67. /* SMI Control and Enable Register */
  68. #define SMI_EN(p) ((p)->smi_res->start)
  69. #define TCO_RLD(p) (TCOBASE(p) + 0x00) /* TCO Timer Reload/Curr. Value */
  70. #define TCOv1_TMR(p) (TCOBASE(p) + 0x01) /* TCOv1 Timer Initial Value*/
  71. #define TCO_DAT_IN(p) (TCOBASE(p) + 0x02) /* TCO Data In Register */
  72. #define TCO_DAT_OUT(p) (TCOBASE(p) + 0x03) /* TCO Data Out Register */
  73. #define TCO1_STS(p) (TCOBASE(p) + 0x04) /* TCO1 Status Register */
  74. #define TCO2_STS(p) (TCOBASE(p) + 0x06) /* TCO2 Status Register */
  75. #define TCO1_CNT(p) (TCOBASE(p) + 0x08) /* TCO1 Control Register */
  76. #define TCO2_CNT(p) (TCOBASE(p) + 0x0a) /* TCO2 Control Register */
  77. #define TCOv2_TMR(p) (TCOBASE(p) + 0x12) /* TCOv2 Timer Initial Value*/
  78. /* internal variables */
  79. struct iTCO_wdt_private {
  80. struct watchdog_device wddev;
  81. /* TCO version/generation */
  82. unsigned int iTCO_version;
  83. struct resource *tco_res;
  84. struct resource *smi_res;
  85. /*
  86. * NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2),
  87. * or memory-mapped PMC register bit 4 (TCO version 3).
  88. */
  89. struct resource *gcs_pmc_res;
  90. unsigned long __iomem *gcs_pmc;
  91. /* the lock for io operations */
  92. spinlock_t io_lock;
  93. /* the PCI-device */
  94. struct pci_dev *pci_dev;
  95. /* whether or not the watchdog has been suspended */
  96. bool suspended;
  97. /* no reboot API private data */
  98. void *no_reboot_priv;
  99. /* no reboot update function pointer */
  100. int (*update_no_reboot_bit)(void *p, bool set);
  101. };
  102. /* module parameters */
  103. #define WATCHDOG_TIMEOUT 30 /* 30 sec default heartbeat */
  104. static int heartbeat = WATCHDOG_TIMEOUT; /* in seconds */
  105. module_param(heartbeat, int, 0);
  106. MODULE_PARM_DESC(heartbeat, "Watchdog timeout in seconds. "
  107. "5..76 (TCO v1) or 3..614 (TCO v2), default="
  108. __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
  109. static bool nowayout = WATCHDOG_NOWAYOUT;
  110. module_param(nowayout, bool, 0);
  111. MODULE_PARM_DESC(nowayout,
  112. "Watchdog cannot be stopped once started (default="
  113. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  114. static int turn_SMI_watchdog_clear_off = 1;
  115. module_param(turn_SMI_watchdog_clear_off, int, 0);
  116. MODULE_PARM_DESC(turn_SMI_watchdog_clear_off,
  117. "Turn off SMI clearing watchdog (depends on TCO-version)(default=1)");
  118. /*
  119. * Some TCO specific functions
  120. */
  121. /*
  122. * The iTCO v1 and v2's internal timer is stored as ticks which decrement
  123. * every 0.6 seconds. v3's internal timer is stored as seconds (some
  124. * datasheets incorrectly state 0.6 seconds).
  125. */
  126. static inline unsigned int seconds_to_ticks(struct iTCO_wdt_private *p,
  127. int secs)
  128. {
  129. return p->iTCO_version == 3 ? secs : (secs * 10) / 6;
  130. }
  131. static inline unsigned int ticks_to_seconds(struct iTCO_wdt_private *p,
  132. int ticks)
  133. {
  134. return p->iTCO_version == 3 ? ticks : (ticks * 6) / 10;
  135. }
  136. static inline u32 no_reboot_bit(struct iTCO_wdt_private *p)
  137. {
  138. u32 enable_bit;
  139. switch (p->iTCO_version) {
  140. case 5:
  141. case 3:
  142. enable_bit = 0x00000010;
  143. break;
  144. case 2:
  145. enable_bit = 0x00000020;
  146. break;
  147. case 4:
  148. case 1:
  149. default:
  150. enable_bit = 0x00000002;
  151. break;
  152. }
  153. return enable_bit;
  154. }
  155. static int update_no_reboot_bit_def(void *priv, bool set)
  156. {
  157. return 0;
  158. }
  159. static int update_no_reboot_bit_pci(void *priv, bool set)
  160. {
  161. struct iTCO_wdt_private *p = priv;
  162. u32 val32 = 0, newval32 = 0;
  163. pci_read_config_dword(p->pci_dev, 0xd4, &val32);
  164. if (set)
  165. val32 |= no_reboot_bit(p);
  166. else
  167. val32 &= ~no_reboot_bit(p);
  168. pci_write_config_dword(p->pci_dev, 0xd4, val32);
  169. pci_read_config_dword(p->pci_dev, 0xd4, &newval32);
  170. /* make sure the update is successful */
  171. if (val32 != newval32)
  172. return -EIO;
  173. return 0;
  174. }
  175. static int update_no_reboot_bit_mem(void *priv, bool set)
  176. {
  177. struct iTCO_wdt_private *p = priv;
  178. u32 val32 = 0, newval32 = 0;
  179. val32 = readl(p->gcs_pmc);
  180. if (set)
  181. val32 |= no_reboot_bit(p);
  182. else
  183. val32 &= ~no_reboot_bit(p);
  184. writel(val32, p->gcs_pmc);
  185. newval32 = readl(p->gcs_pmc);
  186. /* make sure the update is successful */
  187. if (val32 != newval32)
  188. return -EIO;
  189. return 0;
  190. }
  191. static int update_no_reboot_bit_cnt(void *priv, bool set)
  192. {
  193. struct iTCO_wdt_private *p = priv;
  194. u16 val, newval;
  195. val = inw(TCO1_CNT(p));
  196. if (set)
  197. val |= BIT(0);
  198. else
  199. val &= ~BIT(0);
  200. outw(val, TCO1_CNT(p));
  201. newval = inw(TCO1_CNT(p));
  202. /* make sure the update is successful */
  203. return val != newval ? -EIO : 0;
  204. }
  205. static void iTCO_wdt_no_reboot_bit_setup(struct iTCO_wdt_private *p,
  206. struct itco_wdt_platform_data *pdata)
  207. {
  208. if (pdata->update_no_reboot_bit) {
  209. p->update_no_reboot_bit = pdata->update_no_reboot_bit;
  210. p->no_reboot_priv = pdata->no_reboot_priv;
  211. return;
  212. }
  213. if (p->iTCO_version >= 6)
  214. p->update_no_reboot_bit = update_no_reboot_bit_cnt;
  215. else if (p->iTCO_version >= 2)
  216. p->update_no_reboot_bit = update_no_reboot_bit_mem;
  217. else if (p->iTCO_version == 1)
  218. p->update_no_reboot_bit = update_no_reboot_bit_pci;
  219. else
  220. p->update_no_reboot_bit = update_no_reboot_bit_def;
  221. p->no_reboot_priv = p;
  222. }
  223. static int iTCO_wdt_start(struct watchdog_device *wd_dev)
  224. {
  225. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  226. unsigned int val;
  227. spin_lock(&p->io_lock);
  228. iTCO_vendor_pre_start(p->smi_res, wd_dev->timeout);
  229. /* disable chipset's NO_REBOOT bit */
  230. if (p->update_no_reboot_bit(p->no_reboot_priv, false)) {
  231. spin_unlock(&p->io_lock);
  232. pr_err("failed to reset NO_REBOOT flag, reboot disabled by hardware/BIOS\n");
  233. return -EIO;
  234. }
  235. /* Force the timer to its reload value by writing to the TCO_RLD
  236. register */
  237. if (p->iTCO_version >= 2)
  238. outw(0x01, TCO_RLD(p));
  239. else if (p->iTCO_version == 1)
  240. outb(0x01, TCO_RLD(p));
  241. /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
  242. val = inw(TCO1_CNT(p));
  243. val &= 0xf7ff;
  244. outw(val, TCO1_CNT(p));
  245. val = inw(TCO1_CNT(p));
  246. spin_unlock(&p->io_lock);
  247. if (val & 0x0800)
  248. return -1;
  249. return 0;
  250. }
  251. static int iTCO_wdt_stop(struct watchdog_device *wd_dev)
  252. {
  253. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  254. unsigned int val;
  255. spin_lock(&p->io_lock);
  256. iTCO_vendor_pre_stop(p->smi_res);
  257. /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
  258. val = inw(TCO1_CNT(p));
  259. val |= 0x0800;
  260. outw(val, TCO1_CNT(p));
  261. val = inw(TCO1_CNT(p));
  262. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  263. p->update_no_reboot_bit(p->no_reboot_priv, true);
  264. spin_unlock(&p->io_lock);
  265. if ((val & 0x0800) == 0)
  266. return -1;
  267. return 0;
  268. }
  269. static int iTCO_wdt_ping(struct watchdog_device *wd_dev)
  270. {
  271. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  272. spin_lock(&p->io_lock);
  273. /* Reload the timer by writing to the TCO Timer Counter register */
  274. if (p->iTCO_version >= 2) {
  275. outw(0x01, TCO_RLD(p));
  276. } else if (p->iTCO_version == 1) {
  277. /* Reset the timeout status bit so that the timer
  278. * needs to count down twice again before rebooting */
  279. outw(0x0008, TCO1_STS(p)); /* write 1 to clear bit */
  280. outb(0x01, TCO_RLD(p));
  281. }
  282. spin_unlock(&p->io_lock);
  283. return 0;
  284. }
  285. static int iTCO_wdt_set_timeout(struct watchdog_device *wd_dev, unsigned int t)
  286. {
  287. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  288. unsigned int val16;
  289. unsigned char val8;
  290. unsigned int tmrval;
  291. tmrval = seconds_to_ticks(p, t);
  292. /* For TCO v1 the timer counts down twice before rebooting */
  293. if (p->iTCO_version == 1)
  294. tmrval /= 2;
  295. /* from the specs: */
  296. /* "Values of 0h-3h are ignored and should not be attempted" */
  297. if (tmrval < 0x04)
  298. return -EINVAL;
  299. if ((p->iTCO_version >= 2 && tmrval > 0x3ff) ||
  300. (p->iTCO_version == 1 && tmrval > 0x03f))
  301. return -EINVAL;
  302. /* Write new heartbeat to watchdog */
  303. if (p->iTCO_version >= 2) {
  304. spin_lock(&p->io_lock);
  305. val16 = inw(TCOv2_TMR(p));
  306. val16 &= 0xfc00;
  307. val16 |= tmrval;
  308. outw(val16, TCOv2_TMR(p));
  309. val16 = inw(TCOv2_TMR(p));
  310. spin_unlock(&p->io_lock);
  311. if ((val16 & 0x3ff) != tmrval)
  312. return -EINVAL;
  313. } else if (p->iTCO_version == 1) {
  314. spin_lock(&p->io_lock);
  315. val8 = inb(TCOv1_TMR(p));
  316. val8 &= 0xc0;
  317. val8 |= (tmrval & 0xff);
  318. outb(val8, TCOv1_TMR(p));
  319. val8 = inb(TCOv1_TMR(p));
  320. spin_unlock(&p->io_lock);
  321. if ((val8 & 0x3f) != tmrval)
  322. return -EINVAL;
  323. }
  324. wd_dev->timeout = t;
  325. return 0;
  326. }
  327. static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
  328. {
  329. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  330. unsigned int val16;
  331. unsigned char val8;
  332. unsigned int time_left = 0;
  333. /* read the TCO Timer */
  334. if (p->iTCO_version >= 2) {
  335. spin_lock(&p->io_lock);
  336. val16 = inw(TCO_RLD(p));
  337. val16 &= 0x3ff;
  338. spin_unlock(&p->io_lock);
  339. time_left = ticks_to_seconds(p, val16);
  340. } else if (p->iTCO_version == 1) {
  341. spin_lock(&p->io_lock);
  342. val8 = inb(TCO_RLD(p));
  343. val8 &= 0x3f;
  344. if (!(inw(TCO1_STS(p)) & 0x0008))
  345. val8 += (inb(TCOv1_TMR(p)) & 0x3f);
  346. spin_unlock(&p->io_lock);
  347. time_left = ticks_to_seconds(p, val8);
  348. }
  349. return time_left;
  350. }
  351. /*
  352. * Kernel Interfaces
  353. */
  354. static const struct watchdog_info ident = {
  355. .options = WDIOF_SETTIMEOUT |
  356. WDIOF_KEEPALIVEPING |
  357. WDIOF_MAGICCLOSE,
  358. .firmware_version = 0,
  359. .identity = DRV_NAME,
  360. };
  361. static const struct watchdog_ops iTCO_wdt_ops = {
  362. .owner = THIS_MODULE,
  363. .start = iTCO_wdt_start,
  364. .stop = iTCO_wdt_stop,
  365. .ping = iTCO_wdt_ping,
  366. .set_timeout = iTCO_wdt_set_timeout,
  367. .get_timeleft = iTCO_wdt_get_timeleft,
  368. };
  369. /*
  370. * Init & exit routines
  371. */
  372. static int iTCO_wdt_probe(struct platform_device *pdev)
  373. {
  374. struct device *dev = &pdev->dev;
  375. struct itco_wdt_platform_data *pdata = dev_get_platdata(dev);
  376. struct iTCO_wdt_private *p;
  377. unsigned long val32;
  378. int ret;
  379. if (!pdata)
  380. return -ENODEV;
  381. p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
  382. if (!p)
  383. return -ENOMEM;
  384. spin_lock_init(&p->io_lock);
  385. p->tco_res = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_IO_TCO);
  386. if (!p->tco_res)
  387. return -ENODEV;
  388. p->iTCO_version = pdata->version;
  389. p->pci_dev = to_pci_dev(dev->parent);
  390. p->smi_res = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_IO_SMI);
  391. if (p->smi_res) {
  392. /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
  393. if (!devm_request_region(dev, p->smi_res->start,
  394. resource_size(p->smi_res),
  395. pdev->name)) {
  396. pr_err("I/O address 0x%04llx already in use, device disabled\n",
  397. (u64)SMI_EN(p));
  398. return -EBUSY;
  399. }
  400. } else if (iTCO_vendorsupport ||
  401. turn_SMI_watchdog_clear_off >= p->iTCO_version) {
  402. pr_err("SMI I/O resource is missing\n");
  403. return -ENODEV;
  404. }
  405. iTCO_wdt_no_reboot_bit_setup(p, pdata);
  406. /*
  407. * Get the Memory-Mapped GCS or PMC register, we need it for the
  408. * NO_REBOOT flag (TCO v2 and v3).
  409. */
  410. if (p->iTCO_version >= 2 && p->iTCO_version < 6 &&
  411. !pdata->update_no_reboot_bit) {
  412. p->gcs_pmc_res = platform_get_resource(pdev,
  413. IORESOURCE_MEM,
  414. ICH_RES_MEM_GCS_PMC);
  415. p->gcs_pmc = devm_ioremap_resource(dev, p->gcs_pmc_res);
  416. if (IS_ERR(p->gcs_pmc))
  417. return PTR_ERR(p->gcs_pmc);
  418. }
  419. /* Check chipset's NO_REBOOT bit */
  420. if (p->update_no_reboot_bit(p->no_reboot_priv, false) &&
  421. iTCO_vendor_check_noreboot_on()) {
  422. pr_info("unable to reset NO_REBOOT flag, device disabled by hardware/BIOS\n");
  423. return -ENODEV; /* Cannot reset NO_REBOOT bit */
  424. }
  425. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  426. p->update_no_reboot_bit(p->no_reboot_priv, true);
  427. if (turn_SMI_watchdog_clear_off >= p->iTCO_version) {
  428. /*
  429. * Bit 13: TCO_EN -> 0
  430. * Disables TCO logic generating an SMI#
  431. */
  432. val32 = inl(SMI_EN(p));
  433. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  434. outl(val32, SMI_EN(p));
  435. }
  436. if (!devm_request_region(dev, p->tco_res->start,
  437. resource_size(p->tco_res),
  438. pdev->name)) {
  439. pr_err("I/O address 0x%04llx already in use, device disabled\n",
  440. (u64)TCOBASE(p));
  441. return -EBUSY;
  442. }
  443. pr_info("Found a %s TCO device (Version=%d, TCOBASE=0x%04llx)\n",
  444. pdata->name, pdata->version, (u64)TCOBASE(p));
  445. /* Clear out the (probably old) status */
  446. switch (p->iTCO_version) {
  447. case 6:
  448. case 5:
  449. case 4:
  450. outw(0x0008, TCO1_STS(p)); /* Clear the Time Out Status bit */
  451. outw(0x0002, TCO2_STS(p)); /* Clear SECOND_TO_STS bit */
  452. break;
  453. case 3:
  454. outl(0x20008, TCO1_STS(p));
  455. break;
  456. case 2:
  457. case 1:
  458. default:
  459. outw(0x0008, TCO1_STS(p)); /* Clear the Time Out Status bit */
  460. outw(0x0002, TCO2_STS(p)); /* Clear SECOND_TO_STS bit */
  461. outw(0x0004, TCO2_STS(p)); /* Clear BOOT_STS bit */
  462. break;
  463. }
  464. p->wddev.info = &ident,
  465. p->wddev.ops = &iTCO_wdt_ops,
  466. p->wddev.bootstatus = 0;
  467. p->wddev.timeout = WATCHDOG_TIMEOUT;
  468. watchdog_set_nowayout(&p->wddev, nowayout);
  469. p->wddev.parent = dev;
  470. watchdog_set_drvdata(&p->wddev, p);
  471. platform_set_drvdata(pdev, p);
  472. /* Make sure the watchdog is not running */
  473. iTCO_wdt_stop(&p->wddev);
  474. /* Check that the heartbeat value is within it's range;
  475. if not reset to the default */
  476. if (iTCO_wdt_set_timeout(&p->wddev, heartbeat)) {
  477. iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT);
  478. pr_info("timeout value out of range, using %d\n",
  479. WATCHDOG_TIMEOUT);
  480. }
  481. watchdog_stop_on_reboot(&p->wddev);
  482. watchdog_stop_on_unregister(&p->wddev);
  483. ret = devm_watchdog_register_device(dev, &p->wddev);
  484. if (ret != 0) {
  485. pr_err("cannot register watchdog device (err=%d)\n", ret);
  486. return ret;
  487. }
  488. pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
  489. heartbeat, nowayout);
  490. return 0;
  491. }
  492. #ifdef CONFIG_PM_SLEEP
  493. /*
  494. * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
  495. * the watchdog cannot be pinged while in that state. In ACPI sleep states the
  496. * watchdog is stopped by the platform firmware.
  497. */
  498. #ifdef CONFIG_ACPI
  499. static inline bool need_suspend(void)
  500. {
  501. return acpi_target_system_state() == ACPI_STATE_S0;
  502. }
  503. #else
  504. static inline bool need_suspend(void) { return true; }
  505. #endif
  506. static int iTCO_wdt_suspend_noirq(struct device *dev)
  507. {
  508. struct iTCO_wdt_private *p = dev_get_drvdata(dev);
  509. int ret = 0;
  510. p->suspended = false;
  511. if (watchdog_active(&p->wddev) && need_suspend()) {
  512. ret = iTCO_wdt_stop(&p->wddev);
  513. if (!ret)
  514. p->suspended = true;
  515. }
  516. return ret;
  517. }
  518. static int iTCO_wdt_resume_noirq(struct device *dev)
  519. {
  520. struct iTCO_wdt_private *p = dev_get_drvdata(dev);
  521. if (p->suspended)
  522. iTCO_wdt_start(&p->wddev);
  523. return 0;
  524. }
  525. static const struct dev_pm_ops iTCO_wdt_pm = {
  526. .suspend_noirq = iTCO_wdt_suspend_noirq,
  527. .resume_noirq = iTCO_wdt_resume_noirq,
  528. };
  529. #define ITCO_WDT_PM_OPS (&iTCO_wdt_pm)
  530. #else
  531. #define ITCO_WDT_PM_OPS NULL
  532. #endif /* CONFIG_PM_SLEEP */
  533. static struct platform_driver iTCO_wdt_driver = {
  534. .probe = iTCO_wdt_probe,
  535. .driver = {
  536. .name = DRV_NAME,
  537. .pm = ITCO_WDT_PM_OPS,
  538. },
  539. };
  540. static int __init iTCO_wdt_init_module(void)
  541. {
  542. pr_info("Intel TCO WatchDog Timer Driver v%s\n", DRV_VERSION);
  543. return platform_driver_register(&iTCO_wdt_driver);
  544. }
  545. static void __exit iTCO_wdt_cleanup_module(void)
  546. {
  547. platform_driver_unregister(&iTCO_wdt_driver);
  548. pr_info("Watchdog Module Unloaded\n");
  549. }
  550. module_init(iTCO_wdt_init_module);
  551. module_exit(iTCO_wdt_cleanup_module);
  552. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
  553. MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
  554. MODULE_VERSION(DRV_VERSION);
  555. MODULE_LICENSE("GPL");
  556. MODULE_ALIAS("platform:" DRV_NAME);