mpc8xx_wdt.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * mpc8xx_wdt.c - MPC8xx watchdog userspace interface
  3. *
  4. * Author: Florian Schirmer <jolt@tuxbox.org>
  5. *
  6. * 2002 (c) Florian Schirmer <jolt@tuxbox.org> This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/fs.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/miscdevice.h>
  16. #include <linux/module.h>
  17. #include <linux/watchdog.h>
  18. #include <asm/8xx_immap.h>
  19. #include <asm/uaccess.h>
  20. #include <syslib/m8xx_wdt.h>
  21. static unsigned long wdt_opened;
  22. static int wdt_status;
  23. static void mpc8xx_wdt_handler_disable(void)
  24. {
  25. volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
  26. if (!m8xx_has_internal_rtc)
  27. m8xx_wdt_stop_timer();
  28. else
  29. out_be32(imap->im_sit.sit_piscr, in_be32(&imap->im_sit.sit_piscr) & ~(PISCR_PIE | PISCR_PTE));
  30. printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler deactivated\n");
  31. }
  32. static void mpc8xx_wdt_handler_enable(void)
  33. {
  34. volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
  35. if (!m8xx_has_internal_rtc)
  36. m8xx_wdt_install_timer();
  37. else
  38. out_be32(&imap->im_sit.sit_piscr, in_be32(&imap->im_sit.sit_piscr) | PISCR_PIE | PISCR_PTE);
  39. printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler activated\n");
  40. }
  41. static int mpc8xx_wdt_open(struct inode *inode, struct file *file)
  42. {
  43. if (test_and_set_bit(0, &wdt_opened))
  44. return -EBUSY;
  45. m8xx_wdt_reset();
  46. mpc8xx_wdt_handler_disable();
  47. return 0;
  48. }
  49. static int mpc8xx_wdt_release(struct inode *inode, struct file *file)
  50. {
  51. m8xx_wdt_reset();
  52. #if !defined(CONFIG_WATCHDOG_NOWAYOUT)
  53. mpc8xx_wdt_handler_enable();
  54. #endif
  55. clear_bit(0, &wdt_opened);
  56. return 0;
  57. }
  58. static ssize_t mpc8xx_wdt_write(struct file *file, const char *data, size_t len,
  59. loff_t * ppos)
  60. {
  61. if (len)
  62. m8xx_wdt_reset();
  63. return len;
  64. }
  65. static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file,
  66. unsigned int cmd, unsigned long arg)
  67. {
  68. int timeout;
  69. static struct watchdog_info info = {
  70. .options = WDIOF_KEEPALIVEPING,
  71. .firmware_version = 0,
  72. .identity = "MPC8xx watchdog",
  73. };
  74. switch (cmd) {
  75. case WDIOC_GETSUPPORT:
  76. if (copy_to_user((void *)arg, &info, sizeof(info)))
  77. return -EFAULT;
  78. break;
  79. case WDIOC_GETSTATUS:
  80. case WDIOC_GETBOOTSTATUS:
  81. if (put_user(wdt_status, (int *)arg))
  82. return -EFAULT;
  83. wdt_status &= ~WDIOF_KEEPALIVEPING;
  84. break;
  85. case WDIOC_GETTEMP:
  86. return -EOPNOTSUPP;
  87. case WDIOC_SETOPTIONS:
  88. return -EOPNOTSUPP;
  89. case WDIOC_KEEPALIVE:
  90. m8xx_wdt_reset();
  91. wdt_status |= WDIOF_KEEPALIVEPING;
  92. break;
  93. case WDIOC_SETTIMEOUT:
  94. return -EOPNOTSUPP;
  95. case WDIOC_GETTIMEOUT:
  96. timeout = m8xx_wdt_get_timeout();
  97. if (put_user(timeout, (int *)arg))
  98. return -EFAULT;
  99. break;
  100. default:
  101. return -ENOIOCTLCMD;
  102. }
  103. return 0;
  104. }
  105. static struct file_operations mpc8xx_wdt_fops = {
  106. .owner = THIS_MODULE,
  107. .llseek = no_llseek,
  108. .write = mpc8xx_wdt_write,
  109. .ioctl = mpc8xx_wdt_ioctl,
  110. .open = mpc8xx_wdt_open,
  111. .release = mpc8xx_wdt_release,
  112. };
  113. static struct miscdevice mpc8xx_wdt_miscdev = {
  114. .minor = WATCHDOG_MINOR,
  115. .name = "watchdog",
  116. .fops = &mpc8xx_wdt_fops,
  117. };
  118. static int __init mpc8xx_wdt_init(void)
  119. {
  120. return misc_register(&mpc8xx_wdt_miscdev);
  121. }
  122. static void __exit mpc8xx_wdt_exit(void)
  123. {
  124. misc_deregister(&mpc8xx_wdt_miscdev);
  125. m8xx_wdt_reset();
  126. mpc8xx_wdt_handler_enable();
  127. }
  128. module_init(mpc8xx_wdt_init);
  129. module_exit(mpc8xx_wdt_exit);
  130. MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>");
  131. MODULE_DESCRIPTION("MPC8xx watchdog driver");
  132. MODULE_LICENSE("GPL");
  133. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);