mpc8xx_wdt.c 3.5 KB

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