cpwd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /* cpwd.c - driver implementation for hardware watchdog
  2. * timers found on Sun Microsystems CP1400 and CP1500 boards.
  3. *
  4. * This device supports both the generic Linux watchdog
  5. * interface and Solaris-compatible ioctls as best it is
  6. * able.
  7. *
  8. * NOTE: CP1400 systems appear to have a defective intr_mask
  9. * register on the PLD, preventing the disabling of
  10. * timer interrupts. We use a timer to periodically
  11. * reset 'stopped' watchdogs on affected platforms.
  12. *
  13. * Copyright (c) 2000 Eric Brower (ebrower@usa.net)
  14. * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/fs.h>
  19. #include <linux/errno.h>
  20. #include <linux/major.h>
  21. #include <linux/init.h>
  22. #include <linux/miscdevice.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/ioport.h>
  25. #include <linux/timer.h>
  26. #include <linux/slab.h>
  27. #include <linux/mutex.h>
  28. #include <linux/io.h>
  29. #include <linux/of.h>
  30. #include <linux/of_device.h>
  31. #include <linux/uaccess.h>
  32. #include <asm/irq.h>
  33. #include <asm/watchdog.h>
  34. #define DRIVER_NAME "cpwd"
  35. #define PFX DRIVER_NAME ": "
  36. #define WD_OBPNAME "watchdog"
  37. #define WD_BADMODEL "SUNW,501-5336"
  38. #define WD_BTIMEOUT (jiffies + (HZ * 1000))
  39. #define WD_BLIMIT 0xFFFF
  40. #define WD0_MINOR 212
  41. #define WD1_MINOR 213
  42. #define WD2_MINOR 214
  43. /* Internal driver definitions. */
  44. #define WD0_ID 0
  45. #define WD1_ID 1
  46. #define WD2_ID 2
  47. #define WD_NUMDEVS 3
  48. #define WD_INTR_OFF 0
  49. #define WD_INTR_ON 1
  50. #define WD_STAT_INIT 0x01 /* Watchdog timer is initialized */
  51. #define WD_STAT_BSTOP 0x02 /* Watchdog timer is brokenstopped */
  52. #define WD_STAT_SVCD 0x04 /* Watchdog interrupt occurred */
  53. /* Register value definitions
  54. */
  55. #define WD0_INTR_MASK 0x01 /* Watchdog device interrupt masks */
  56. #define WD1_INTR_MASK 0x02
  57. #define WD2_INTR_MASK 0x04
  58. #define WD_S_RUNNING 0x01 /* Watchdog device status running */
  59. #define WD_S_EXPIRED 0x02 /* Watchdog device status expired */
  60. struct cpwd {
  61. void __iomem *regs;
  62. spinlock_t lock;
  63. unsigned int irq;
  64. unsigned long timeout;
  65. bool enabled;
  66. bool reboot;
  67. bool broken;
  68. bool initialized;
  69. struct {
  70. struct miscdevice misc;
  71. void __iomem *regs;
  72. u8 intr_mask;
  73. u8 runstatus;
  74. u16 timeout;
  75. } devs[WD_NUMDEVS];
  76. };
  77. static DEFINE_MUTEX(cpwd_mutex);
  78. static struct cpwd *cpwd_device;
  79. /* Sun uses Altera PLD EPF8820ATC144-4
  80. * providing three hardware watchdogs:
  81. *
  82. * 1) RIC - sends an interrupt when triggered
  83. * 2) XIR - asserts XIR_B_RESET when triggered, resets CPU
  84. * 3) POR - asserts POR_B_RESET when triggered, resets CPU, backplane, board
  85. *
  86. *** Timer register block definition (struct wd_timer_regblk)
  87. *
  88. * dcntr and limit registers (halfword access):
  89. * -------------------
  90. * | 15 | ...| 1 | 0 |
  91. * -------------------
  92. * |- counter val -|
  93. * -------------------
  94. * dcntr - Current 16-bit downcounter value.
  95. * When downcounter reaches '0' watchdog expires.
  96. * Reading this register resets downcounter with
  97. * 'limit' value.
  98. * limit - 16-bit countdown value in 1/10th second increments.
  99. * Writing this register begins countdown with input value.
  100. * Reading from this register does not affect counter.
  101. * NOTES: After watchdog reset, dcntr and limit contain '1'
  102. *
  103. * status register (byte access):
  104. * ---------------------------
  105. * | 7 | ... | 2 | 1 | 0 |
  106. * --------------+------------
  107. * |- UNUSED -| EXP | RUN |
  108. * ---------------------------
  109. * status- Bit 0 - Watchdog is running
  110. * Bit 1 - Watchdog has expired
  111. *
  112. *** PLD register block definition (struct wd_pld_regblk)
  113. *
  114. * intr_mask register (byte access):
  115. * ---------------------------------
  116. * | 7 | ... | 3 | 2 | 1 | 0 |
  117. * +-------------+------------------
  118. * |- UNUSED -| WD3 | WD2 | WD1 |
  119. * ---------------------------------
  120. * WD3 - 1 == Interrupt disabled for watchdog 3
  121. * WD2 - 1 == Interrupt disabled for watchdog 2
  122. * WD1 - 1 == Interrupt disabled for watchdog 1
  123. *
  124. * pld_status register (byte access):
  125. * UNKNOWN, MAGICAL MYSTERY REGISTER
  126. *
  127. */
  128. #define WD_TIMER_REGSZ 16
  129. #define WD0_OFF 0
  130. #define WD1_OFF (WD_TIMER_REGSZ * 1)
  131. #define WD2_OFF (WD_TIMER_REGSZ * 2)
  132. #define PLD_OFF (WD_TIMER_REGSZ * 3)
  133. #define WD_DCNTR 0x00
  134. #define WD_LIMIT 0x04
  135. #define WD_STATUS 0x08
  136. #define PLD_IMASK (PLD_OFF + 0x00)
  137. #define PLD_STATUS (PLD_OFF + 0x04)
  138. static struct timer_list cpwd_timer;
  139. static int wd0_timeout;
  140. static int wd1_timeout;
  141. static int wd2_timeout;
  142. module_param(wd0_timeout, int, 0);
  143. MODULE_PARM_DESC(wd0_timeout, "Default watchdog0 timeout in 1/10secs");
  144. module_param(wd1_timeout, int, 0);
  145. MODULE_PARM_DESC(wd1_timeout, "Default watchdog1 timeout in 1/10secs");
  146. module_param(wd2_timeout, int, 0);
  147. MODULE_PARM_DESC(wd2_timeout, "Default watchdog2 timeout in 1/10secs");
  148. MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
  149. MODULE_DESCRIPTION("Hardware watchdog driver for Sun Microsystems CP1400/1500");
  150. MODULE_LICENSE("GPL");
  151. MODULE_SUPPORTED_DEVICE("watchdog");
  152. static void cpwd_writew(u16 val, void __iomem *addr)
  153. {
  154. writew(cpu_to_le16(val), addr);
  155. }
  156. static u16 cpwd_readw(void __iomem *addr)
  157. {
  158. u16 val = readw(addr);
  159. return le16_to_cpu(val);
  160. }
  161. static void cpwd_writeb(u8 val, void __iomem *addr)
  162. {
  163. writeb(val, addr);
  164. }
  165. static u8 cpwd_readb(void __iomem *addr)
  166. {
  167. return readb(addr);
  168. }
  169. /* Enable or disable watchdog interrupts
  170. * Because of the CP1400 defect this should only be
  171. * called during initialzation or by wd_[start|stop]timer()
  172. *
  173. * index - sub-device index, or -1 for 'all'
  174. * enable - non-zero to enable interrupts, zero to disable
  175. */
  176. static void cpwd_toggleintr(struct cpwd *p, int index, int enable)
  177. {
  178. unsigned char curregs = cpwd_readb(p->regs + PLD_IMASK);
  179. unsigned char setregs =
  180. (index == -1) ?
  181. (WD0_INTR_MASK | WD1_INTR_MASK | WD2_INTR_MASK) :
  182. (p->devs[index].intr_mask);
  183. if (enable == WD_INTR_ON)
  184. curregs &= ~setregs;
  185. else
  186. curregs |= setregs;
  187. cpwd_writeb(curregs, p->regs + PLD_IMASK);
  188. }
  189. /* Restarts timer with maximum limit value and
  190. * does not unset 'brokenstop' value.
  191. */
  192. static void cpwd_resetbrokentimer(struct cpwd *p, int index)
  193. {
  194. cpwd_toggleintr(p, index, WD_INTR_ON);
  195. cpwd_writew(WD_BLIMIT, p->devs[index].regs + WD_LIMIT);
  196. }
  197. /* Timer method called to reset stopped watchdogs--
  198. * because of the PLD bug on CP1400, we cannot mask
  199. * interrupts within the PLD so me must continually
  200. * reset the timers ad infinitum.
  201. */
  202. static void cpwd_brokentimer(unsigned long data)
  203. {
  204. struct cpwd *p = (struct cpwd *) data;
  205. int id, tripped = 0;
  206. /* kill a running timer instance, in case we
  207. * were called directly instead of by kernel timer
  208. */
  209. if (timer_pending(&cpwd_timer))
  210. del_timer(&cpwd_timer);
  211. for (id = 0; id < WD_NUMDEVS; id++) {
  212. if (p->devs[id].runstatus & WD_STAT_BSTOP) {
  213. ++tripped;
  214. cpwd_resetbrokentimer(p, id);
  215. }
  216. }
  217. if (tripped) {
  218. /* there is at least one timer brokenstopped-- reschedule */
  219. cpwd_timer.expires = WD_BTIMEOUT;
  220. add_timer(&cpwd_timer);
  221. }
  222. }
  223. /* Reset countdown timer with 'limit' value and continue countdown.
  224. * This will not start a stopped timer.
  225. */
  226. static void cpwd_pingtimer(struct cpwd *p, int index)
  227. {
  228. if (cpwd_readb(p->devs[index].regs + WD_STATUS) & WD_S_RUNNING)
  229. cpwd_readw(p->devs[index].regs + WD_DCNTR);
  230. }
  231. /* Stop a running watchdog timer-- the timer actually keeps
  232. * running, but the interrupt is masked so that no action is
  233. * taken upon expiration.
  234. */
  235. static void cpwd_stoptimer(struct cpwd *p, int index)
  236. {
  237. if (cpwd_readb(p->devs[index].regs + WD_STATUS) & WD_S_RUNNING) {
  238. cpwd_toggleintr(p, index, WD_INTR_OFF);
  239. if (p->broken) {
  240. p->devs[index].runstatus |= WD_STAT_BSTOP;
  241. cpwd_brokentimer((unsigned long) p);
  242. }
  243. }
  244. }
  245. /* Start a watchdog timer with the specified limit value
  246. * If the watchdog is running, it will be restarted with
  247. * the provided limit value.
  248. *
  249. * This function will enable interrupts on the specified
  250. * watchdog.
  251. */
  252. static void cpwd_starttimer(struct cpwd *p, int index)
  253. {
  254. if (p->broken)
  255. p->devs[index].runstatus &= ~WD_STAT_BSTOP;
  256. p->devs[index].runstatus &= ~WD_STAT_SVCD;
  257. cpwd_writew(p->devs[index].timeout, p->devs[index].regs + WD_LIMIT);
  258. cpwd_toggleintr(p, index, WD_INTR_ON);
  259. }
  260. static int cpwd_getstatus(struct cpwd *p, int index)
  261. {
  262. unsigned char stat = cpwd_readb(p->devs[index].regs + WD_STATUS);
  263. unsigned char intr = cpwd_readb(p->devs[index].regs + PLD_IMASK);
  264. unsigned char ret = WD_STOPPED;
  265. /* determine STOPPED */
  266. if (!stat)
  267. return ret;
  268. /* determine EXPIRED vs FREERUN vs RUNNING */
  269. else if (WD_S_EXPIRED & stat) {
  270. ret = WD_EXPIRED;
  271. } else if (WD_S_RUNNING & stat) {
  272. if (intr & p->devs[index].intr_mask) {
  273. ret = WD_FREERUN;
  274. } else {
  275. /* Fudge WD_EXPIRED status for defective CP1400--
  276. * IF timer is running
  277. * AND brokenstop is set
  278. * AND an interrupt has been serviced
  279. * we are WD_EXPIRED.
  280. *
  281. * IF timer is running
  282. * AND brokenstop is set
  283. * AND no interrupt has been serviced
  284. * we are WD_FREERUN.
  285. */
  286. if (p->broken &&
  287. (p->devs[index].runstatus & WD_STAT_BSTOP)) {
  288. if (p->devs[index].runstatus & WD_STAT_SVCD) {
  289. ret = WD_EXPIRED;
  290. } else {
  291. /* we could as well pretend
  292. * we are expired */
  293. ret = WD_FREERUN;
  294. }
  295. } else {
  296. ret = WD_RUNNING;
  297. }
  298. }
  299. }
  300. /* determine SERVICED */
  301. if (p->devs[index].runstatus & WD_STAT_SVCD)
  302. ret |= WD_SERVICED;
  303. return ret;
  304. }
  305. static irqreturn_t cpwd_interrupt(int irq, void *dev_id)
  306. {
  307. struct cpwd *p = dev_id;
  308. /* Only WD0 will interrupt-- others are NMI and we won't
  309. * see them here....
  310. */
  311. spin_lock_irq(&p->lock);
  312. cpwd_stoptimer(p, WD0_ID);
  313. p->devs[WD0_ID].runstatus |= WD_STAT_SVCD;
  314. spin_unlock_irq(&p->lock);
  315. return IRQ_HANDLED;
  316. }
  317. static int cpwd_open(struct inode *inode, struct file *f)
  318. {
  319. struct cpwd *p = cpwd_device;
  320. mutex_lock(&cpwd_mutex);
  321. switch (iminor(inode)) {
  322. case WD0_MINOR:
  323. case WD1_MINOR:
  324. case WD2_MINOR:
  325. break;
  326. default:
  327. mutex_unlock(&cpwd_mutex);
  328. return -ENODEV;
  329. }
  330. /* Register IRQ on first open of device */
  331. if (!p->initialized) {
  332. if (request_irq(p->irq, &cpwd_interrupt,
  333. IRQF_SHARED, DRIVER_NAME, p)) {
  334. printk(KERN_ERR PFX "Cannot register IRQ %d\n",
  335. p->irq);
  336. mutex_unlock(&cpwd_mutex);
  337. return -EBUSY;
  338. }
  339. p->initialized = true;
  340. }
  341. mutex_unlock(&cpwd_mutex);
  342. return nonseekable_open(inode, f);
  343. }
  344. static int cpwd_release(struct inode *inode, struct file *file)
  345. {
  346. return 0;
  347. }
  348. static long cpwd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  349. {
  350. static const struct watchdog_info info = {
  351. .options = WDIOF_SETTIMEOUT,
  352. .firmware_version = 1,
  353. .identity = DRIVER_NAME,
  354. };
  355. void __user *argp = (void __user *)arg;
  356. struct inode *inode = file->f_path.dentry->d_inode;
  357. int index = iminor(inode) - WD0_MINOR;
  358. struct cpwd *p = cpwd_device;
  359. int setopt = 0;
  360. switch (cmd) {
  361. /* Generic Linux IOCTLs */
  362. case WDIOC_GETSUPPORT:
  363. if (copy_to_user(argp, &info, sizeof(struct watchdog_info)))
  364. return -EFAULT;
  365. break;
  366. case WDIOC_GETSTATUS:
  367. case WDIOC_GETBOOTSTATUS:
  368. if (put_user(0, (int __user *)argp))
  369. return -EFAULT;
  370. break;
  371. case WDIOC_KEEPALIVE:
  372. cpwd_pingtimer(p, index);
  373. break;
  374. case WDIOC_SETOPTIONS:
  375. if (copy_from_user(&setopt, argp, sizeof(unsigned int)))
  376. return -EFAULT;
  377. if (setopt & WDIOS_DISABLECARD) {
  378. if (p->enabled)
  379. return -EINVAL;
  380. cpwd_stoptimer(p, index);
  381. } else if (setopt & WDIOS_ENABLECARD) {
  382. cpwd_starttimer(p, index);
  383. } else {
  384. return -EINVAL;
  385. }
  386. break;
  387. /* Solaris-compatible IOCTLs */
  388. case WIOCGSTAT:
  389. setopt = cpwd_getstatus(p, index);
  390. if (copy_to_user(argp, &setopt, sizeof(unsigned int)))
  391. return -EFAULT;
  392. break;
  393. case WIOCSTART:
  394. cpwd_starttimer(p, index);
  395. break;
  396. case WIOCSTOP:
  397. if (p->enabled)
  398. return -EINVAL;
  399. cpwd_stoptimer(p, index);
  400. break;
  401. default:
  402. return -EINVAL;
  403. }
  404. return 0;
  405. }
  406. static long cpwd_compat_ioctl(struct file *file, unsigned int cmd,
  407. unsigned long arg)
  408. {
  409. int rval = -ENOIOCTLCMD;
  410. switch (cmd) {
  411. /* solaris ioctls are specific to this driver */
  412. case WIOCSTART:
  413. case WIOCSTOP:
  414. case WIOCGSTAT:
  415. mutex_lock(&cpwd_mutex);
  416. rval = cpwd_ioctl(file, cmd, arg);
  417. mutex_unlock(&cpwd_mutex);
  418. break;
  419. /* everything else is handled by the generic compat layer */
  420. default:
  421. break;
  422. }
  423. return rval;
  424. }
  425. static ssize_t cpwd_write(struct file *file, const char __user *buf,
  426. size_t count, loff_t *ppos)
  427. {
  428. struct inode *inode = file->f_path.dentry->d_inode;
  429. struct cpwd *p = cpwd_device;
  430. int index = iminor(inode);
  431. if (count) {
  432. cpwd_pingtimer(p, index);
  433. return 1;
  434. }
  435. return 0;
  436. }
  437. static ssize_t cpwd_read(struct file *file, char __user *buffer,
  438. size_t count, loff_t *ppos)
  439. {
  440. return -EINVAL;
  441. }
  442. static const struct file_operations cpwd_fops = {
  443. .owner = THIS_MODULE,
  444. .unlocked_ioctl = cpwd_ioctl,
  445. .compat_ioctl = cpwd_compat_ioctl,
  446. .open = cpwd_open,
  447. .write = cpwd_write,
  448. .read = cpwd_read,
  449. .release = cpwd_release,
  450. .llseek = no_llseek,
  451. };
  452. static int __devinit cpwd_probe(struct platform_device *op)
  453. {
  454. struct device_node *options;
  455. const char *str_prop;
  456. const void *prop_val;
  457. int i, err = -EINVAL;
  458. struct cpwd *p;
  459. if (cpwd_device)
  460. return -EINVAL;
  461. p = kzalloc(sizeof(*p), GFP_KERNEL);
  462. err = -ENOMEM;
  463. if (!p) {
  464. printk(KERN_ERR PFX "Unable to allocate struct cpwd.\n");
  465. goto out;
  466. }
  467. p->irq = op->archdata.irqs[0];
  468. spin_lock_init(&p->lock);
  469. p->regs = of_ioremap(&op->resource[0], 0,
  470. 4 * WD_TIMER_REGSZ, DRIVER_NAME);
  471. if (!p->regs) {
  472. printk(KERN_ERR PFX "Unable to map registers.\n");
  473. goto out_free;
  474. }
  475. options = of_find_node_by_path("/options");
  476. err = -ENODEV;
  477. if (!options) {
  478. printk(KERN_ERR PFX "Unable to find /options node.\n");
  479. goto out_iounmap;
  480. }
  481. prop_val = of_get_property(options, "watchdog-enable?", NULL);
  482. p->enabled = (prop_val ? true : false);
  483. prop_val = of_get_property(options, "watchdog-reboot?", NULL);
  484. p->reboot = (prop_val ? true : false);
  485. str_prop = of_get_property(options, "watchdog-timeout", NULL);
  486. if (str_prop)
  487. p->timeout = simple_strtoul(str_prop, NULL, 10);
  488. /* CP1400s seem to have broken PLD implementations-- the
  489. * interrupt_mask register cannot be written, so no timer
  490. * interrupts can be masked within the PLD.
  491. */
  492. str_prop = of_get_property(op->dev.of_node, "model", NULL);
  493. p->broken = (str_prop && !strcmp(str_prop, WD_BADMODEL));
  494. if (!p->enabled)
  495. cpwd_toggleintr(p, -1, WD_INTR_OFF);
  496. for (i = 0; i < WD_NUMDEVS; i++) {
  497. static const char *cpwd_names[] = { "RIC", "XIR", "POR" };
  498. static int *parms[] = { &wd0_timeout,
  499. &wd1_timeout,
  500. &wd2_timeout };
  501. struct miscdevice *mp = &p->devs[i].misc;
  502. mp->minor = WD0_MINOR + i;
  503. mp->name = cpwd_names[i];
  504. mp->fops = &cpwd_fops;
  505. p->devs[i].regs = p->regs + (i * WD_TIMER_REGSZ);
  506. p->devs[i].intr_mask = (WD0_INTR_MASK << i);
  507. p->devs[i].runstatus &= ~WD_STAT_BSTOP;
  508. p->devs[i].runstatus |= WD_STAT_INIT;
  509. p->devs[i].timeout = p->timeout;
  510. if (*parms[i])
  511. p->devs[i].timeout = *parms[i];
  512. err = misc_register(&p->devs[i].misc);
  513. if (err) {
  514. printk(KERN_ERR "Could not register misc device for "
  515. "dev %d\n", i);
  516. goto out_unregister;
  517. }
  518. }
  519. if (p->broken) {
  520. init_timer(&cpwd_timer);
  521. cpwd_timer.function = cpwd_brokentimer;
  522. cpwd_timer.data = (unsigned long) p;
  523. cpwd_timer.expires = WD_BTIMEOUT;
  524. printk(KERN_INFO PFX "PLD defect workaround enabled for "
  525. "model " WD_BADMODEL ".\n");
  526. }
  527. dev_set_drvdata(&op->dev, p);
  528. cpwd_device = p;
  529. err = 0;
  530. out:
  531. return err;
  532. out_unregister:
  533. for (i--; i >= 0; i--)
  534. misc_deregister(&p->devs[i].misc);
  535. out_iounmap:
  536. of_iounmap(&op->resource[0], p->regs, 4 * WD_TIMER_REGSZ);
  537. out_free:
  538. kfree(p);
  539. goto out;
  540. }
  541. static int __devexit cpwd_remove(struct platform_device *op)
  542. {
  543. struct cpwd *p = dev_get_drvdata(&op->dev);
  544. int i;
  545. for (i = 0; i < WD_NUMDEVS; i++) {
  546. misc_deregister(&p->devs[i].misc);
  547. if (!p->enabled) {
  548. cpwd_stoptimer(p, i);
  549. if (p->devs[i].runstatus & WD_STAT_BSTOP)
  550. cpwd_resetbrokentimer(p, i);
  551. }
  552. }
  553. if (p->broken)
  554. del_timer_sync(&cpwd_timer);
  555. if (p->initialized)
  556. free_irq(p->irq, p);
  557. of_iounmap(&op->resource[0], p->regs, 4 * WD_TIMER_REGSZ);
  558. kfree(p);
  559. cpwd_device = NULL;
  560. return 0;
  561. }
  562. static const struct of_device_id cpwd_match[] = {
  563. {
  564. .name = "watchdog",
  565. },
  566. {},
  567. };
  568. MODULE_DEVICE_TABLE(of, cpwd_match);
  569. static struct platform_driver cpwd_driver = {
  570. .driver = {
  571. .name = DRIVER_NAME,
  572. .owner = THIS_MODULE,
  573. .of_match_table = cpwd_match,
  574. },
  575. .probe = cpwd_probe,
  576. .remove = __devexit_p(cpwd_remove),
  577. };
  578. static int __init cpwd_init(void)
  579. {
  580. return platform_driver_register(&cpwd_driver);
  581. }
  582. static void __exit cpwd_exit(void)
  583. {
  584. platform_driver_unregister(&cpwd_driver);
  585. }
  586. module_init(cpwd_init);
  587. module_exit(cpwd_exit);