sp5100_tco.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /*
  2. * sp5100_tco : TCO timer driver for sp5100 chipsets
  3. *
  4. * (c) Copyright 2009 Google Inc., All Rights Reserved.
  5. *
  6. * Based on i8xx_tco.c:
  7. * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights
  8. * Reserved.
  9. * http://www.kernelconcepts.de
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. *
  16. * See AMD Publication 43009 "AMD SB700/710/750 Register Reference Guide",
  17. * AMD Publication 45482 "AMD SB800-Series Southbridges Register
  18. * Reference Guide"
  19. */
  20. /*
  21. * Includes, defines, variables, module parameters, ...
  22. */
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/module.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/types.h>
  27. #include <linux/miscdevice.h>
  28. #include <linux/watchdog.h>
  29. #include <linux/init.h>
  30. #include <linux/fs.h>
  31. #include <linux/pci.h>
  32. #include <linux/ioport.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/io.h>
  36. #include "sp5100_tco.h"
  37. /* Module and version information */
  38. #define TCO_VERSION "0.03"
  39. #define TCO_MODULE_NAME "SP5100 TCO timer"
  40. #define TCO_DRIVER_NAME TCO_MODULE_NAME ", v" TCO_VERSION
  41. /* internal variables */
  42. static u32 tcobase_phys;
  43. static u32 resbase_phys;
  44. static u32 tco_wdt_fired;
  45. static void __iomem *tcobase;
  46. static unsigned int pm_iobase;
  47. static DEFINE_SPINLOCK(tco_lock); /* Guards the hardware */
  48. static unsigned long timer_alive;
  49. static char tco_expect_close;
  50. static struct pci_dev *sp5100_tco_pci;
  51. static struct resource wdt_res = {
  52. .name = "Watchdog Timer",
  53. .flags = IORESOURCE_MEM,
  54. };
  55. /* the watchdog platform device */
  56. static struct platform_device *sp5100_tco_platform_device;
  57. /* module parameters */
  58. #define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat. */
  59. static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
  60. module_param(heartbeat, int, 0);
  61. MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (default="
  62. __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
  63. static bool nowayout = WATCHDOG_NOWAYOUT;
  64. module_param(nowayout, bool, 0);
  65. MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started."
  66. " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  67. static unsigned int force_addr;
  68. module_param(force_addr, uint, 0);
  69. MODULE_PARM_DESC(force_addr, "Force the use of specified MMIO address."
  70. " ONLY USE THIS PARAMETER IF YOU REALLY KNOW"
  71. " WHAT YOU ARE DOING (default=none)");
  72. /*
  73. * Some TCO specific functions
  74. */
  75. static void tco_timer_start(void)
  76. {
  77. u32 val;
  78. unsigned long flags;
  79. spin_lock_irqsave(&tco_lock, flags);
  80. val = readl(SP5100_WDT_CONTROL(tcobase));
  81. val |= SP5100_WDT_START_STOP_BIT;
  82. writel(val, SP5100_WDT_CONTROL(tcobase));
  83. spin_unlock_irqrestore(&tco_lock, flags);
  84. }
  85. static void tco_timer_stop(void)
  86. {
  87. u32 val;
  88. unsigned long flags;
  89. spin_lock_irqsave(&tco_lock, flags);
  90. val = readl(SP5100_WDT_CONTROL(tcobase));
  91. val &= ~SP5100_WDT_START_STOP_BIT;
  92. writel(val, SP5100_WDT_CONTROL(tcobase));
  93. spin_unlock_irqrestore(&tco_lock, flags);
  94. }
  95. static void tco_timer_keepalive(void)
  96. {
  97. u32 val;
  98. unsigned long flags;
  99. spin_lock_irqsave(&tco_lock, flags);
  100. val = readl(SP5100_WDT_CONTROL(tcobase));
  101. val |= SP5100_WDT_TRIGGER_BIT;
  102. writel(val, SP5100_WDT_CONTROL(tcobase));
  103. spin_unlock_irqrestore(&tco_lock, flags);
  104. }
  105. static int tco_timer_set_heartbeat(int t)
  106. {
  107. unsigned long flags;
  108. if (t < 0 || t > 0xffff)
  109. return -EINVAL;
  110. /* Write new heartbeat to watchdog */
  111. spin_lock_irqsave(&tco_lock, flags);
  112. writel(t, SP5100_WDT_COUNT(tcobase));
  113. spin_unlock_irqrestore(&tco_lock, flags);
  114. heartbeat = t;
  115. return 0;
  116. }
  117. static void tco_timer_enable(void)
  118. {
  119. int val;
  120. if (sp5100_tco_pci->revision >= 0x40) {
  121. /* For SB800 or later */
  122. /* Set the Watchdog timer resolution to 1 sec */
  123. outb(SB800_PM_WATCHDOG_CONFIG, SB800_IO_PM_INDEX_REG);
  124. val = inb(SB800_IO_PM_DATA_REG);
  125. val |= SB800_PM_WATCHDOG_SECOND_RES;
  126. outb(val, SB800_IO_PM_DATA_REG);
  127. /* Enable watchdog decode bit and watchdog timer */
  128. outb(SB800_PM_WATCHDOG_CONTROL, SB800_IO_PM_INDEX_REG);
  129. val = inb(SB800_IO_PM_DATA_REG);
  130. val |= SB800_PCI_WATCHDOG_DECODE_EN;
  131. val &= ~SB800_PM_WATCHDOG_DISABLE;
  132. outb(val, SB800_IO_PM_DATA_REG);
  133. } else {
  134. /* For SP5100 or SB7x0 */
  135. /* Enable watchdog decode bit */
  136. pci_read_config_dword(sp5100_tco_pci,
  137. SP5100_PCI_WATCHDOG_MISC_REG,
  138. &val);
  139. val |= SP5100_PCI_WATCHDOG_DECODE_EN;
  140. pci_write_config_dword(sp5100_tco_pci,
  141. SP5100_PCI_WATCHDOG_MISC_REG,
  142. val);
  143. /* Enable Watchdog timer and set the resolution to 1 sec */
  144. outb(SP5100_PM_WATCHDOG_CONTROL, SP5100_IO_PM_INDEX_REG);
  145. val = inb(SP5100_IO_PM_DATA_REG);
  146. val |= SP5100_PM_WATCHDOG_SECOND_RES;
  147. val &= ~SP5100_PM_WATCHDOG_DISABLE;
  148. outb(val, SP5100_IO_PM_DATA_REG);
  149. }
  150. }
  151. static void tco_timer_disable(void)
  152. {
  153. int val;
  154. if (sp5100_tco_pci->revision >= 0x40) {
  155. /* For SB800 or later */
  156. /* Enable watchdog decode bit and Disable watchdog timer */
  157. outb(SB800_PM_WATCHDOG_CONTROL, SB800_IO_PM_INDEX_REG);
  158. val = inb(SB800_IO_PM_DATA_REG);
  159. val |= SB800_PCI_WATCHDOG_DECODE_EN;
  160. val |= SB800_PM_WATCHDOG_DISABLE;
  161. outb(val, SB800_IO_PM_DATA_REG);
  162. } else {
  163. /* For SP5100 or SB7x0 */
  164. /* Enable watchdog decode bit */
  165. pci_read_config_dword(sp5100_tco_pci,
  166. SP5100_PCI_WATCHDOG_MISC_REG,
  167. &val);
  168. val |= SP5100_PCI_WATCHDOG_DECODE_EN;
  169. pci_write_config_dword(sp5100_tco_pci,
  170. SP5100_PCI_WATCHDOG_MISC_REG,
  171. val);
  172. /* Disable Watchdog timer */
  173. outb(SP5100_PM_WATCHDOG_CONTROL, SP5100_IO_PM_INDEX_REG);
  174. val = inb(SP5100_IO_PM_DATA_REG);
  175. val |= SP5100_PM_WATCHDOG_DISABLE;
  176. outb(val, SP5100_IO_PM_DATA_REG);
  177. }
  178. }
  179. /*
  180. * /dev/watchdog handling
  181. */
  182. static int sp5100_tco_open(struct inode *inode, struct file *file)
  183. {
  184. /* /dev/watchdog can only be opened once */
  185. if (test_and_set_bit(0, &timer_alive))
  186. return -EBUSY;
  187. /* Reload and activate timer */
  188. tco_timer_start();
  189. tco_timer_keepalive();
  190. return nonseekable_open(inode, file);
  191. }
  192. static int sp5100_tco_release(struct inode *inode, struct file *file)
  193. {
  194. /* Shut off the timer. */
  195. if (tco_expect_close == 42) {
  196. tco_timer_stop();
  197. } else {
  198. pr_crit("Unexpected close, not stopping watchdog!\n");
  199. tco_timer_keepalive();
  200. }
  201. clear_bit(0, &timer_alive);
  202. tco_expect_close = 0;
  203. return 0;
  204. }
  205. static ssize_t sp5100_tco_write(struct file *file, const char __user *data,
  206. size_t len, loff_t *ppos)
  207. {
  208. /* See if we got the magic character 'V' and reload the timer */
  209. if (len) {
  210. if (!nowayout) {
  211. size_t i;
  212. /* note: just in case someone wrote the magic character
  213. * five months ago... */
  214. tco_expect_close = 0;
  215. /* scan to see whether or not we got the magic character
  216. */
  217. for (i = 0; i != len; i++) {
  218. char c;
  219. if (get_user(c, data + i))
  220. return -EFAULT;
  221. if (c == 'V')
  222. tco_expect_close = 42;
  223. }
  224. }
  225. /* someone wrote to us, we should reload the timer */
  226. tco_timer_keepalive();
  227. }
  228. return len;
  229. }
  230. static long sp5100_tco_ioctl(struct file *file, unsigned int cmd,
  231. unsigned long arg)
  232. {
  233. int new_options, retval = -EINVAL;
  234. int new_heartbeat;
  235. void __user *argp = (void __user *)arg;
  236. int __user *p = argp;
  237. static const struct watchdog_info ident = {
  238. .options = WDIOF_SETTIMEOUT |
  239. WDIOF_KEEPALIVEPING |
  240. WDIOF_MAGICCLOSE,
  241. .firmware_version = 0,
  242. .identity = TCO_MODULE_NAME,
  243. };
  244. switch (cmd) {
  245. case WDIOC_GETSUPPORT:
  246. return copy_to_user(argp, &ident,
  247. sizeof(ident)) ? -EFAULT : 0;
  248. case WDIOC_GETSTATUS:
  249. case WDIOC_GETBOOTSTATUS:
  250. return put_user(0, p);
  251. case WDIOC_SETOPTIONS:
  252. if (get_user(new_options, p))
  253. return -EFAULT;
  254. if (new_options & WDIOS_DISABLECARD) {
  255. tco_timer_stop();
  256. retval = 0;
  257. }
  258. if (new_options & WDIOS_ENABLECARD) {
  259. tco_timer_start();
  260. tco_timer_keepalive();
  261. retval = 0;
  262. }
  263. return retval;
  264. case WDIOC_KEEPALIVE:
  265. tco_timer_keepalive();
  266. return 0;
  267. case WDIOC_SETTIMEOUT:
  268. if (get_user(new_heartbeat, p))
  269. return -EFAULT;
  270. if (tco_timer_set_heartbeat(new_heartbeat))
  271. return -EINVAL;
  272. tco_timer_keepalive();
  273. /* Fall through */
  274. case WDIOC_GETTIMEOUT:
  275. return put_user(heartbeat, p);
  276. default:
  277. return -ENOTTY;
  278. }
  279. }
  280. /*
  281. * Kernel Interfaces
  282. */
  283. static const struct file_operations sp5100_tco_fops = {
  284. .owner = THIS_MODULE,
  285. .llseek = no_llseek,
  286. .write = sp5100_tco_write,
  287. .unlocked_ioctl = sp5100_tco_ioctl,
  288. .open = sp5100_tco_open,
  289. .release = sp5100_tco_release,
  290. };
  291. static struct miscdevice sp5100_tco_miscdev = {
  292. .minor = WATCHDOG_MINOR,
  293. .name = "watchdog",
  294. .fops = &sp5100_tco_fops,
  295. };
  296. /*
  297. * Data for PCI driver interface
  298. *
  299. * This data only exists for exporting the supported
  300. * PCI ids via MODULE_DEVICE_TABLE. We do not actually
  301. * register a pci_driver, because someone else might
  302. * want to register another driver on the same PCI id.
  303. */
  304. static DEFINE_PCI_DEVICE_TABLE(sp5100_tco_pci_tbl) = {
  305. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, PCI_ANY_ID,
  306. PCI_ANY_ID, },
  307. { 0, }, /* End of list */
  308. };
  309. MODULE_DEVICE_TABLE(pci, sp5100_tco_pci_tbl);
  310. /*
  311. * Init & exit routines
  312. */
  313. static unsigned char sp5100_tco_setupdevice(void)
  314. {
  315. struct pci_dev *dev = NULL;
  316. const char *dev_name = NULL;
  317. u32 val;
  318. u32 index_reg, data_reg, base_addr;
  319. /* Match the PCI device */
  320. for_each_pci_dev(dev) {
  321. if (pci_match_id(sp5100_tco_pci_tbl, dev) != NULL) {
  322. sp5100_tco_pci = dev;
  323. break;
  324. }
  325. }
  326. if (!sp5100_tco_pci)
  327. return 0;
  328. pr_info("PCI Revision ID: 0x%x\n", sp5100_tco_pci->revision);
  329. /*
  330. * Determine type of southbridge chipset.
  331. */
  332. if (sp5100_tco_pci->revision >= 0x40) {
  333. dev_name = SB800_DEVNAME;
  334. index_reg = SB800_IO_PM_INDEX_REG;
  335. data_reg = SB800_IO_PM_DATA_REG;
  336. base_addr = SB800_PM_WATCHDOG_BASE;
  337. } else {
  338. dev_name = SP5100_DEVNAME;
  339. index_reg = SP5100_IO_PM_INDEX_REG;
  340. data_reg = SP5100_IO_PM_DATA_REG;
  341. base_addr = SP5100_PM_WATCHDOG_BASE;
  342. }
  343. /* Request the IO ports used by this driver */
  344. pm_iobase = SP5100_IO_PM_INDEX_REG;
  345. if (!request_region(pm_iobase, SP5100_PM_IOPORTS_SIZE, dev_name)) {
  346. pr_err("I/O address 0x%04x already in use\n", pm_iobase);
  347. goto exit;
  348. }
  349. /*
  350. * First, Find the watchdog timer MMIO address from indirect I/O.
  351. */
  352. outb(base_addr+3, index_reg);
  353. val = inb(data_reg);
  354. outb(base_addr+2, index_reg);
  355. val = val << 8 | inb(data_reg);
  356. outb(base_addr+1, index_reg);
  357. val = val << 8 | inb(data_reg);
  358. outb(base_addr+0, index_reg);
  359. /* Low three bits of BASE are reserved */
  360. val = val << 8 | (inb(data_reg) & 0xf8);
  361. pr_debug("Got 0x%04x from indirect I/O\n", val);
  362. /* Check MMIO address conflict */
  363. if (request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE,
  364. dev_name))
  365. goto setup_wdt;
  366. else
  367. pr_debug("MMIO address 0x%04x already in use\n", val);
  368. /*
  369. * Secondly, Find the watchdog timer MMIO address
  370. * from SBResource_MMIO register.
  371. */
  372. if (sp5100_tco_pci->revision >= 0x40) {
  373. /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */
  374. outb(SB800_PM_ACPI_MMIO_EN+3, SB800_IO_PM_INDEX_REG);
  375. val = inb(SB800_IO_PM_DATA_REG);
  376. outb(SB800_PM_ACPI_MMIO_EN+2, SB800_IO_PM_INDEX_REG);
  377. val = val << 8 | inb(SB800_IO_PM_DATA_REG);
  378. outb(SB800_PM_ACPI_MMIO_EN+1, SB800_IO_PM_INDEX_REG);
  379. val = val << 8 | inb(SB800_IO_PM_DATA_REG);
  380. outb(SB800_PM_ACPI_MMIO_EN+0, SB800_IO_PM_INDEX_REG);
  381. val = val << 8 | inb(SB800_IO_PM_DATA_REG);
  382. } else {
  383. /* Read SBResource_MMIO from PCI config(PCI_Reg: 9Ch) */
  384. pci_read_config_dword(sp5100_tco_pci,
  385. SP5100_SB_RESOURCE_MMIO_BASE, &val);
  386. }
  387. /* The SBResource_MMIO is enabled and mapped memory space? */
  388. if ((val & (SB800_ACPI_MMIO_DECODE_EN | SB800_ACPI_MMIO_SEL)) ==
  389. SB800_ACPI_MMIO_DECODE_EN) {
  390. /* Clear unnecessary the low twelve bits */
  391. val &= ~0xFFF;
  392. /* Add the Watchdog Timer offset to base address. */
  393. val += SB800_PM_WDT_MMIO_OFFSET;
  394. /* Check MMIO address conflict */
  395. if (request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE,
  396. dev_name)) {
  397. pr_debug("Got 0x%04x from SBResource_MMIO register\n",
  398. val);
  399. goto setup_wdt;
  400. } else
  401. pr_debug("MMIO address 0x%04x already in use\n", val);
  402. } else
  403. pr_debug("SBResource_MMIO is disabled(0x%04x)\n", val);
  404. /*
  405. * Lastly re-programming the watchdog timer MMIO address,
  406. * This method is a last resort...
  407. *
  408. * Before re-programming, to ensure that the watchdog timer
  409. * is disabled, disable the watchdog timer.
  410. */
  411. tco_timer_disable();
  412. if (force_addr) {
  413. /*
  414. * Force the use of watchdog timer MMIO address, and aligned to
  415. * 8byte boundary.
  416. */
  417. force_addr &= ~0x7;
  418. val = force_addr;
  419. pr_info("Force the use of 0x%04x as MMIO address\n", val);
  420. } else {
  421. /*
  422. * Get empty slot into the resource tree for watchdog timer.
  423. */
  424. if (allocate_resource(&iomem_resource,
  425. &wdt_res,
  426. SP5100_WDT_MEM_MAP_SIZE,
  427. 0xf0000000,
  428. 0xfffffff8,
  429. 0x8,
  430. NULL,
  431. NULL)) {
  432. pr_err("MMIO allocation failed\n");
  433. goto unreg_region;
  434. }
  435. val = resbase_phys = wdt_res.start;
  436. pr_debug("Got 0x%04x from resource tree\n", val);
  437. }
  438. /* Restore to the low three bits, if chipset is SB8x0(or later) */
  439. if (sp5100_tco_pci->revision >= 0x40) {
  440. u8 reserved_bit;
  441. reserved_bit = inb(base_addr) & 0x7;
  442. val |= (u32)reserved_bit;
  443. }
  444. /* Re-programming the watchdog timer base address */
  445. outb(base_addr+0, index_reg);
  446. /* Low three bits of BASE are reserved */
  447. outb((val >> 0) & 0xf8, data_reg);
  448. outb(base_addr+1, index_reg);
  449. outb((val >> 8) & 0xff, data_reg);
  450. outb(base_addr+2, index_reg);
  451. outb((val >> 16) & 0xff, data_reg);
  452. outb(base_addr+3, index_reg);
  453. outb((val >> 24) & 0xff, data_reg);
  454. /*
  455. * Clear unnecessary the low three bits,
  456. * if chipset is SB8x0(or later)
  457. */
  458. if (sp5100_tco_pci->revision >= 0x40)
  459. val &= ~0x7;
  460. if (!request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE,
  461. dev_name)) {
  462. pr_err("MMIO address 0x%04x already in use\n", val);
  463. goto unreg_resource;
  464. }
  465. setup_wdt:
  466. tcobase_phys = val;
  467. tcobase = ioremap(val, SP5100_WDT_MEM_MAP_SIZE);
  468. if (!tcobase) {
  469. pr_err("failed to get tcobase address\n");
  470. goto unreg_mem_region;
  471. }
  472. pr_info("Using 0x%04x for watchdog MMIO address\n", val);
  473. /* Setup the watchdog timer */
  474. tco_timer_enable();
  475. /* Check that the watchdog action is set to reset the system */
  476. val = readl(SP5100_WDT_CONTROL(tcobase));
  477. /*
  478. * Save WatchDogFired status, because WatchDogFired flag is
  479. * cleared here.
  480. */
  481. tco_wdt_fired = val & SP5100_PM_WATCHDOG_FIRED;
  482. val &= ~SP5100_PM_WATCHDOG_ACTION_RESET;
  483. writel(val, SP5100_WDT_CONTROL(tcobase));
  484. /* Set a reasonable heartbeat before we stop the timer */
  485. tco_timer_set_heartbeat(heartbeat);
  486. /*
  487. * Stop the TCO before we change anything so we don't race with
  488. * a zeroed timer.
  489. */
  490. tco_timer_stop();
  491. /* Done */
  492. return 1;
  493. unreg_mem_region:
  494. release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
  495. unreg_resource:
  496. if (resbase_phys)
  497. release_resource(&wdt_res);
  498. unreg_region:
  499. release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
  500. exit:
  501. return 0;
  502. }
  503. static int sp5100_tco_init(struct platform_device *dev)
  504. {
  505. int ret;
  506. char addr_str[16];
  507. /*
  508. * Check whether or not the hardware watchdog is there. If found, then
  509. * set it up.
  510. */
  511. if (!sp5100_tco_setupdevice())
  512. return -ENODEV;
  513. /* Check to see if last reboot was due to watchdog timeout */
  514. pr_info("Last reboot was %striggered by watchdog.\n",
  515. tco_wdt_fired ? "" : "not ");
  516. /*
  517. * Check that the heartbeat value is within it's range.
  518. * If not, reset to the default.
  519. */
  520. if (tco_timer_set_heartbeat(heartbeat)) {
  521. heartbeat = WATCHDOG_HEARTBEAT;
  522. tco_timer_set_heartbeat(heartbeat);
  523. }
  524. ret = misc_register(&sp5100_tco_miscdev);
  525. if (ret != 0) {
  526. pr_err("cannot register miscdev on minor=%d (err=%d)\n",
  527. WATCHDOG_MINOR, ret);
  528. goto exit;
  529. }
  530. clear_bit(0, &timer_alive);
  531. /* Show module parameters */
  532. if (force_addr == tcobase_phys)
  533. /* The force_addr is vaild */
  534. sprintf(addr_str, "0x%04x", force_addr);
  535. else
  536. strcpy(addr_str, "none");
  537. pr_info("initialized (0x%p). heartbeat=%d sec (nowayout=%d, "
  538. "force_addr=%s)\n",
  539. tcobase, heartbeat, nowayout, addr_str);
  540. return 0;
  541. exit:
  542. iounmap(tcobase);
  543. release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
  544. if (resbase_phys)
  545. release_resource(&wdt_res);
  546. release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
  547. return ret;
  548. }
  549. static void sp5100_tco_cleanup(void)
  550. {
  551. /* Stop the timer before we leave */
  552. if (!nowayout)
  553. tco_timer_stop();
  554. /* Deregister */
  555. misc_deregister(&sp5100_tco_miscdev);
  556. iounmap(tcobase);
  557. release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
  558. if (resbase_phys)
  559. release_resource(&wdt_res);
  560. release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
  561. }
  562. static int sp5100_tco_remove(struct platform_device *dev)
  563. {
  564. if (tcobase)
  565. sp5100_tco_cleanup();
  566. return 0;
  567. }
  568. static void sp5100_tco_shutdown(struct platform_device *dev)
  569. {
  570. tco_timer_stop();
  571. }
  572. static struct platform_driver sp5100_tco_driver = {
  573. .probe = sp5100_tco_init,
  574. .remove = sp5100_tco_remove,
  575. .shutdown = sp5100_tco_shutdown,
  576. .driver = {
  577. .owner = THIS_MODULE,
  578. .name = TCO_MODULE_NAME,
  579. },
  580. };
  581. static int __init sp5100_tco_init_module(void)
  582. {
  583. int err;
  584. pr_info("SP5100/SB800 TCO WatchDog Timer Driver v%s\n", TCO_VERSION);
  585. err = platform_driver_register(&sp5100_tco_driver);
  586. if (err)
  587. return err;
  588. sp5100_tco_platform_device = platform_device_register_simple(
  589. TCO_MODULE_NAME, -1, NULL, 0);
  590. if (IS_ERR(sp5100_tco_platform_device)) {
  591. err = PTR_ERR(sp5100_tco_platform_device);
  592. goto unreg_platform_driver;
  593. }
  594. return 0;
  595. unreg_platform_driver:
  596. platform_driver_unregister(&sp5100_tco_driver);
  597. return err;
  598. }
  599. static void __exit sp5100_tco_cleanup_module(void)
  600. {
  601. platform_device_unregister(sp5100_tco_platform_device);
  602. platform_driver_unregister(&sp5100_tco_driver);
  603. pr_info("SP5100/SB800 TCO Watchdog Module Unloaded\n");
  604. }
  605. module_init(sp5100_tco_init_module);
  606. module_exit(sp5100_tco_cleanup_module);
  607. MODULE_AUTHOR("Priyanka Gupta");
  608. MODULE_DESCRIPTION("TCO timer driver for SP5100/SB800 chipset");
  609. MODULE_LICENSE("GPL");
  610. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);