iTCO_wdt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * intel TCO Watchdog Driver
  4. *
  5. * (c) Copyright 2006-2011 Wim Van Sebroeck <[email protected]>.
  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. /* Module and version information */
  42. #define DRV_NAME "iTCO_wdt"
  43. #define DRV_VERSION "1.11"
  44. /* Includes */
  45. #include <linux/acpi.h> /* For ACPI support */
  46. #include <linux/bits.h> /* For BIT() */
  47. #include <linux/module.h> /* For module specific items */
  48. #include <linux/moduleparam.h> /* For new moduleparam's */
  49. #include <linux/types.h> /* For standard types (like size_t) */
  50. #include <linux/errno.h> /* For the -ENODEV/... values */
  51. #include <linux/kernel.h> /* For printk/panic/... */
  52. #include <linux/watchdog.h> /* For the watchdog specific items */
  53. #include <linux/init.h> /* For __init/__exit/... */
  54. #include <linux/fs.h> /* For file operations */
  55. #include <linux/platform_device.h> /* For platform_driver framework */
  56. #include <linux/pci.h> /* For pci functions */
  57. #include <linux/ioport.h> /* For io-port access */
  58. #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
  59. #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
  60. #include <linux/io.h> /* For inb/outb/... */
  61. #include <linux/platform_data/itco_wdt.h>
  62. #include <linux/mfd/intel_pmc_bxt.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. unsigned long __iomem *gcs_pmc;
  90. /* the lock for io operations */
  91. spinlock_t io_lock;
  92. /* the PCI-device */
  93. struct pci_dev *pci_dev;
  94. /* whether or not the watchdog has been suspended */
  95. bool suspended;
  96. /* no reboot API private data */
  97. void *no_reboot_priv;
  98. /* no reboot update function pointer */
  99. int (*update_no_reboot_bit)(void *p, bool set);
  100. };
  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(struct iTCO_wdt_private *p,
  126. int secs)
  127. {
  128. return p->iTCO_version == 3 ? secs : (secs * 10) / 6;
  129. }
  130. static inline unsigned int ticks_to_seconds(struct iTCO_wdt_private *p,
  131. int ticks)
  132. {
  133. return p->iTCO_version == 3 ? ticks : (ticks * 6) / 10;
  134. }
  135. static inline u32 no_reboot_bit(struct iTCO_wdt_private *p)
  136. {
  137. u32 enable_bit;
  138. switch (p->iTCO_version) {
  139. case 5:
  140. case 3:
  141. enable_bit = 0x00000010;
  142. break;
  143. case 2:
  144. enable_bit = 0x00000020;
  145. break;
  146. case 4:
  147. case 1:
  148. default:
  149. enable_bit = 0x00000002;
  150. break;
  151. }
  152. return enable_bit;
  153. }
  154. static int update_no_reboot_bit_def(void *priv, bool set)
  155. {
  156. return 0;
  157. }
  158. static int update_no_reboot_bit_pci(void *priv, bool set)
  159. {
  160. struct iTCO_wdt_private *p = priv;
  161. u32 val32 = 0, newval32 = 0;
  162. pci_read_config_dword(p->pci_dev, 0xd4, &val32);
  163. if (set)
  164. val32 |= no_reboot_bit(p);
  165. else
  166. val32 &= ~no_reboot_bit(p);
  167. pci_write_config_dword(p->pci_dev, 0xd4, val32);
  168. pci_read_config_dword(p->pci_dev, 0xd4, &newval32);
  169. /* make sure the update is successful */
  170. if (val32 != newval32)
  171. return -EIO;
  172. return 0;
  173. }
  174. static int update_no_reboot_bit_mem(void *priv, bool set)
  175. {
  176. struct iTCO_wdt_private *p = priv;
  177. u32 val32 = 0, newval32 = 0;
  178. val32 = readl(p->gcs_pmc);
  179. if (set)
  180. val32 |= no_reboot_bit(p);
  181. else
  182. val32 &= ~no_reboot_bit(p);
  183. writel(val32, p->gcs_pmc);
  184. newval32 = readl(p->gcs_pmc);
  185. /* make sure the update is successful */
  186. if (val32 != newval32)
  187. return -EIO;
  188. return 0;
  189. }
  190. static int update_no_reboot_bit_cnt(void *priv, bool set)
  191. {
  192. struct iTCO_wdt_private *p = priv;
  193. u16 val, newval;
  194. val = inw(TCO1_CNT(p));
  195. if (set)
  196. val |= BIT(0);
  197. else
  198. val &= ~BIT(0);
  199. outw(val, TCO1_CNT(p));
  200. newval = inw(TCO1_CNT(p));
  201. /* make sure the update is successful */
  202. return val != newval ? -EIO : 0;
  203. }
  204. static int update_no_reboot_bit_pmc(void *priv, bool set)
  205. {
  206. struct intel_pmc_dev *pmc = priv;
  207. u32 bits = PMC_CFG_NO_REBOOT_EN;
  208. u32 value = set ? bits : 0;
  209. return intel_pmc_gcr_update(pmc, PMC_GCR_PMC_CFG_REG, bits, value);
  210. }
  211. static void iTCO_wdt_no_reboot_bit_setup(struct iTCO_wdt_private *p,
  212. struct platform_device *pdev,
  213. struct itco_wdt_platform_data *pdata)
  214. {
  215. if (pdata->no_reboot_use_pmc) {
  216. struct intel_pmc_dev *pmc = dev_get_drvdata(pdev->dev.parent);
  217. p->update_no_reboot_bit = update_no_reboot_bit_pmc;
  218. p->no_reboot_priv = pmc;
  219. return;
  220. }
  221. if (p->iTCO_version >= 6)
  222. p->update_no_reboot_bit = update_no_reboot_bit_cnt;
  223. else if (p->iTCO_version >= 2)
  224. p->update_no_reboot_bit = update_no_reboot_bit_mem;
  225. else if (p->iTCO_version == 1)
  226. p->update_no_reboot_bit = update_no_reboot_bit_pci;
  227. else
  228. p->update_no_reboot_bit = update_no_reboot_bit_def;
  229. p->no_reboot_priv = p;
  230. }
  231. static int iTCO_wdt_start(struct watchdog_device *wd_dev)
  232. {
  233. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  234. unsigned int val;
  235. spin_lock(&p->io_lock);
  236. iTCO_vendor_pre_start(p->smi_res, wd_dev->timeout);
  237. /* disable chipset's NO_REBOOT bit */
  238. if (p->update_no_reboot_bit(p->no_reboot_priv, false)) {
  239. spin_unlock(&p->io_lock);
  240. dev_err(wd_dev->parent, "failed to reset NO_REBOOT flag, reboot disabled by hardware/BIOS\n");
  241. return -EIO;
  242. }
  243. /* Force the timer to its reload value by writing to the TCO_RLD
  244. register */
  245. if (p->iTCO_version >= 2)
  246. outw(0x01, TCO_RLD(p));
  247. else if (p->iTCO_version == 1)
  248. outb(0x01, TCO_RLD(p));
  249. /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
  250. val = inw(TCO1_CNT(p));
  251. val &= 0xf7ff;
  252. outw(val, TCO1_CNT(p));
  253. val = inw(TCO1_CNT(p));
  254. spin_unlock(&p->io_lock);
  255. if (val & 0x0800)
  256. return -1;
  257. return 0;
  258. }
  259. static int iTCO_wdt_stop(struct watchdog_device *wd_dev)
  260. {
  261. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  262. unsigned int val;
  263. spin_lock(&p->io_lock);
  264. iTCO_vendor_pre_stop(p->smi_res);
  265. /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
  266. val = inw(TCO1_CNT(p));
  267. val |= 0x0800;
  268. outw(val, TCO1_CNT(p));
  269. val = inw(TCO1_CNT(p));
  270. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  271. p->update_no_reboot_bit(p->no_reboot_priv, true);
  272. spin_unlock(&p->io_lock);
  273. if ((val & 0x0800) == 0)
  274. return -1;
  275. return 0;
  276. }
  277. static int iTCO_wdt_ping(struct watchdog_device *wd_dev)
  278. {
  279. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  280. spin_lock(&p->io_lock);
  281. /* Reload the timer by writing to the TCO Timer Counter register */
  282. if (p->iTCO_version >= 2) {
  283. outw(0x01, TCO_RLD(p));
  284. } else if (p->iTCO_version == 1) {
  285. /* Reset the timeout status bit so that the timer
  286. * needs to count down twice again before rebooting */
  287. outw(0x0008, TCO1_STS(p)); /* write 1 to clear bit */
  288. outb(0x01, TCO_RLD(p));
  289. }
  290. spin_unlock(&p->io_lock);
  291. return 0;
  292. }
  293. static int iTCO_wdt_set_timeout(struct watchdog_device *wd_dev, unsigned int t)
  294. {
  295. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  296. unsigned int val16;
  297. unsigned char val8;
  298. unsigned int tmrval;
  299. tmrval = seconds_to_ticks(p, t);
  300. /* For TCO v1 the timer counts down twice before rebooting */
  301. if (p->iTCO_version == 1)
  302. tmrval /= 2;
  303. /* from the specs: */
  304. /* "Values of 0h-3h are ignored and should not be attempted" */
  305. if (tmrval < 0x04)
  306. return -EINVAL;
  307. if ((p->iTCO_version >= 2 && tmrval > 0x3ff) ||
  308. (p->iTCO_version == 1 && tmrval > 0x03f))
  309. return -EINVAL;
  310. /* Write new heartbeat to watchdog */
  311. if (p->iTCO_version >= 2) {
  312. spin_lock(&p->io_lock);
  313. val16 = inw(TCOv2_TMR(p));
  314. val16 &= 0xfc00;
  315. val16 |= tmrval;
  316. outw(val16, TCOv2_TMR(p));
  317. val16 = inw(TCOv2_TMR(p));
  318. spin_unlock(&p->io_lock);
  319. if ((val16 & 0x3ff) != tmrval)
  320. return -EINVAL;
  321. } else if (p->iTCO_version == 1) {
  322. spin_lock(&p->io_lock);
  323. val8 = inb(TCOv1_TMR(p));
  324. val8 &= 0xc0;
  325. val8 |= (tmrval & 0xff);
  326. outb(val8, TCOv1_TMR(p));
  327. val8 = inb(TCOv1_TMR(p));
  328. spin_unlock(&p->io_lock);
  329. if ((val8 & 0x3f) != tmrval)
  330. return -EINVAL;
  331. }
  332. wd_dev->timeout = t;
  333. return 0;
  334. }
  335. static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
  336. {
  337. struct iTCO_wdt_private *p = watchdog_get_drvdata(wd_dev);
  338. unsigned int val16;
  339. unsigned char val8;
  340. unsigned int time_left = 0;
  341. /* read the TCO Timer */
  342. if (p->iTCO_version >= 2) {
  343. spin_lock(&p->io_lock);
  344. val16 = inw(TCO_RLD(p));
  345. val16 &= 0x3ff;
  346. spin_unlock(&p->io_lock);
  347. time_left = ticks_to_seconds(p, val16);
  348. } else if (p->iTCO_version == 1) {
  349. spin_lock(&p->io_lock);
  350. val8 = inb(TCO_RLD(p));
  351. val8 &= 0x3f;
  352. if (!(inw(TCO1_STS(p)) & 0x0008))
  353. val8 += (inb(TCOv1_TMR(p)) & 0x3f);
  354. spin_unlock(&p->io_lock);
  355. time_left = ticks_to_seconds(p, val8);
  356. }
  357. return time_left;
  358. }
  359. /* Returns true if the watchdog was running */
  360. static bool iTCO_wdt_set_running(struct iTCO_wdt_private *p)
  361. {
  362. u16 val;
  363. /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled */
  364. val = inw(TCO1_CNT(p));
  365. if (!(val & BIT(11))) {
  366. set_bit(WDOG_HW_RUNNING, &p->wddev.status);
  367. return true;
  368. }
  369. return false;
  370. }
  371. /*
  372. * Kernel Interfaces
  373. */
  374. static const struct watchdog_info ident = {
  375. .options = WDIOF_SETTIMEOUT |
  376. WDIOF_KEEPALIVEPING |
  377. WDIOF_MAGICCLOSE,
  378. .firmware_version = 0,
  379. .identity = DRV_NAME,
  380. };
  381. static const struct watchdog_ops iTCO_wdt_ops = {
  382. .owner = THIS_MODULE,
  383. .start = iTCO_wdt_start,
  384. .stop = iTCO_wdt_stop,
  385. .ping = iTCO_wdt_ping,
  386. .set_timeout = iTCO_wdt_set_timeout,
  387. .get_timeleft = iTCO_wdt_get_timeleft,
  388. };
  389. /*
  390. * Init & exit routines
  391. */
  392. static int iTCO_wdt_probe(struct platform_device *pdev)
  393. {
  394. struct device *dev = &pdev->dev;
  395. struct itco_wdt_platform_data *pdata = dev_get_platdata(dev);
  396. struct iTCO_wdt_private *p;
  397. unsigned long val32;
  398. int ret;
  399. if (!pdata)
  400. return -ENODEV;
  401. p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
  402. if (!p)
  403. return -ENOMEM;
  404. spin_lock_init(&p->io_lock);
  405. p->tco_res = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_IO_TCO);
  406. if (!p->tco_res)
  407. return -ENODEV;
  408. p->iTCO_version = pdata->version;
  409. p->pci_dev = to_pci_dev(dev->parent);
  410. p->smi_res = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_IO_SMI);
  411. if (p->smi_res) {
  412. /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
  413. if (!devm_request_region(dev, p->smi_res->start,
  414. resource_size(p->smi_res),
  415. pdev->name)) {
  416. dev_err(dev, "I/O address 0x%04llx already in use, device disabled\n",
  417. (u64)SMI_EN(p));
  418. return -EBUSY;
  419. }
  420. } else if (iTCO_vendorsupport ||
  421. turn_SMI_watchdog_clear_off >= p->iTCO_version) {
  422. dev_err(dev, "SMI I/O resource is missing\n");
  423. return -ENODEV;
  424. }
  425. iTCO_wdt_no_reboot_bit_setup(p, pdev, pdata);
  426. /*
  427. * Get the Memory-Mapped GCS or PMC register, we need it for the
  428. * NO_REBOOT flag (TCO v2 and v3).
  429. */
  430. if (p->iTCO_version >= 2 && p->iTCO_version < 6 &&
  431. !pdata->no_reboot_use_pmc) {
  432. p->gcs_pmc = devm_platform_ioremap_resource(pdev, ICH_RES_MEM_GCS_PMC);
  433. if (IS_ERR(p->gcs_pmc))
  434. return PTR_ERR(p->gcs_pmc);
  435. }
  436. /* Check chipset's NO_REBOOT bit */
  437. if (p->update_no_reboot_bit(p->no_reboot_priv, false) &&
  438. iTCO_vendor_check_noreboot_on()) {
  439. dev_info(dev, "unable to reset NO_REBOOT flag, device disabled by hardware/BIOS\n");
  440. return -ENODEV; /* Cannot reset NO_REBOOT bit */
  441. }
  442. if (turn_SMI_watchdog_clear_off >= p->iTCO_version) {
  443. /*
  444. * Bit 13: TCO_EN -> 0
  445. * Disables TCO logic generating an SMI#
  446. */
  447. val32 = inl(SMI_EN(p));
  448. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  449. outl(val32, SMI_EN(p));
  450. }
  451. if (!devm_request_region(dev, p->tco_res->start,
  452. resource_size(p->tco_res),
  453. pdev->name)) {
  454. dev_err(dev, "I/O address 0x%04llx already in use, device disabled\n",
  455. (u64)TCOBASE(p));
  456. return -EBUSY;
  457. }
  458. dev_info(dev, "Found a %s TCO device (Version=%d, TCOBASE=0x%04llx)\n",
  459. pdata->name, pdata->version, (u64)TCOBASE(p));
  460. /* Clear out the (probably old) status */
  461. switch (p->iTCO_version) {
  462. case 6:
  463. case 5:
  464. case 4:
  465. outw(0x0008, TCO1_STS(p)); /* Clear the Time Out Status bit */
  466. outw(0x0002, TCO2_STS(p)); /* Clear SECOND_TO_STS bit */
  467. break;
  468. case 3:
  469. outl(0x20008, TCO1_STS(p));
  470. break;
  471. case 2:
  472. case 1:
  473. default:
  474. outw(0x0008, TCO1_STS(p)); /* Clear the Time Out Status bit */
  475. outw(0x0002, TCO2_STS(p)); /* Clear SECOND_TO_STS bit */
  476. outw(0x0004, TCO2_STS(p)); /* Clear BOOT_STS bit */
  477. break;
  478. }
  479. p->wddev.info = &ident,
  480. p->wddev.ops = &iTCO_wdt_ops,
  481. p->wddev.bootstatus = 0;
  482. p->wddev.timeout = WATCHDOG_TIMEOUT;
  483. watchdog_set_nowayout(&p->wddev, nowayout);
  484. p->wddev.parent = dev;
  485. watchdog_set_drvdata(&p->wddev, p);
  486. platform_set_drvdata(pdev, p);
  487. if (!iTCO_wdt_set_running(p)) {
  488. /*
  489. * If the watchdog was not running set NO_REBOOT now to
  490. * prevent later reboots.
  491. */
  492. p->update_no_reboot_bit(p->no_reboot_priv, true);
  493. }
  494. /* Check that the heartbeat value is within it's range;
  495. if not reset to the default */
  496. if (iTCO_wdt_set_timeout(&p->wddev, heartbeat)) {
  497. iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT);
  498. dev_info(dev, "timeout value out of range, using %d\n",
  499. WATCHDOG_TIMEOUT);
  500. }
  501. watchdog_stop_on_reboot(&p->wddev);
  502. watchdog_stop_on_unregister(&p->wddev);
  503. ret = devm_watchdog_register_device(dev, &p->wddev);
  504. if (ret != 0) {
  505. dev_err(dev, "cannot register watchdog device (err=%d)\n", ret);
  506. return ret;
  507. }
  508. dev_info(dev, "initialized. heartbeat=%d sec (nowayout=%d)\n",
  509. heartbeat, nowayout);
  510. return 0;
  511. }
  512. /*
  513. * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
  514. * the watchdog cannot be pinged while in that state. In ACPI sleep states the
  515. * watchdog is stopped by the platform firmware.
  516. */
  517. #ifdef CONFIG_ACPI
  518. static inline bool __maybe_unused need_suspend(void)
  519. {
  520. return acpi_target_system_state() == ACPI_STATE_S0;
  521. }
  522. #else
  523. static inline bool __maybe_unused need_suspend(void) { return true; }
  524. #endif
  525. static int __maybe_unused iTCO_wdt_suspend_noirq(struct device *dev)
  526. {
  527. struct iTCO_wdt_private *p = dev_get_drvdata(dev);
  528. int ret = 0;
  529. p->suspended = false;
  530. if (watchdog_active(&p->wddev) && need_suspend()) {
  531. ret = iTCO_wdt_stop(&p->wddev);
  532. if (!ret)
  533. p->suspended = true;
  534. }
  535. return ret;
  536. }
  537. static int __maybe_unused iTCO_wdt_resume_noirq(struct device *dev)
  538. {
  539. struct iTCO_wdt_private *p = dev_get_drvdata(dev);
  540. if (p->suspended)
  541. iTCO_wdt_start(&p->wddev);
  542. return 0;
  543. }
  544. static const struct dev_pm_ops iTCO_wdt_pm = {
  545. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(iTCO_wdt_suspend_noirq,
  546. iTCO_wdt_resume_noirq)
  547. };
  548. static struct platform_driver iTCO_wdt_driver = {
  549. .probe = iTCO_wdt_probe,
  550. .driver = {
  551. .name = DRV_NAME,
  552. .pm = &iTCO_wdt_pm,
  553. },
  554. };
  555. module_platform_driver(iTCO_wdt_driver);
  556. MODULE_AUTHOR("Wim Van Sebroeck <[email protected]>");
  557. MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
  558. MODULE_VERSION(DRV_VERSION);
  559. MODULE_LICENSE("GPL");
  560. MODULE_ALIAS("platform:" DRV_NAME);