iTCO_wdt.c 19 KB

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