mpc8xx_wdt.c 3.4 KB

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