m8xx_wdt.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * m8xx_wdt.c - MPC8xx watchdog driver
  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/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/kernel.h>
  15. #include <linux/sched.h>
  16. #include <asm/io.h>
  17. #include <asm/8xx_immap.h>
  18. #include <syslib/m8xx_wdt.h>
  19. static int wdt_timeout;
  20. int m8xx_has_internal_rtc = 0;
  21. static irqreturn_t m8xx_wdt_interrupt(int, void *, struct pt_regs *);
  22. static struct irqaction m8xx_wdt_irqaction = {
  23. .handler = m8xx_wdt_interrupt,
  24. .name = "watchdog",
  25. };
  26. void m8xx_wdt_reset(void)
  27. {
  28. volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
  29. out_be16(&imap->im_siu_conf.sc_swsr, 0x556c); /* write magic1 */
  30. out_be16(&imap->im_siu_conf.sc_swsr, 0xaa39); /* write magic2 */
  31. }
  32. static irqreturn_t m8xx_wdt_interrupt(int irq, void *dev, struct pt_regs *regs)
  33. {
  34. volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
  35. m8xx_wdt_reset();
  36. setbits16(&imap->im_sit.sit_piscr, PISCR_PS);
  37. return IRQ_HANDLED;
  38. }
  39. #define SYPCR_SWP 0x1
  40. #define SYPCR_SWE 0x4
  41. void __init m8xx_wdt_install_irq(volatile immap_t *imap, bd_t *binfo)
  42. {
  43. u32 pitc;
  44. u32 pitrtclk;
  45. /*
  46. * Fire trigger if half of the wdt ticked down
  47. */
  48. if (imap->im_sit.sit_rtcsc & RTCSC_38K)
  49. pitrtclk = 9600;
  50. else
  51. pitrtclk = 8192;
  52. if ((wdt_timeout) > (UINT_MAX / pitrtclk))
  53. pitc = wdt_timeout / binfo->bi_intfreq * pitrtclk / 2;
  54. else
  55. pitc = pitrtclk * wdt_timeout / binfo->bi_intfreq / 2;
  56. out_be32(&imap->im_sit.sit_pitc, pitc << 16);
  57. out_be16(&imap->im_sit.sit_piscr, (mk_int_int_mask(PIT_INTERRUPT) << 8) | PISCR_PIE | PISCR_PTE);
  58. if (setup_irq(PIT_INTERRUPT, &m8xx_wdt_irqaction))
  59. panic("m8xx_wdt: error setting up the watchdog irq!");
  60. printk(KERN_NOTICE
  61. "m8xx_wdt: keep-alive trigger installed (PITC: 0x%04X)\n", pitc);
  62. }
  63. static void m8xx_wdt_timer_func(unsigned long data);
  64. static struct timer_list m8xx_wdt_timer =
  65. TIMER_INITIALIZER(m8xx_wdt_timer_func, 0, 0);
  66. void m8xx_wdt_stop_timer(void)
  67. {
  68. del_timer(&m8xx_wdt_timer);
  69. }
  70. void m8xx_wdt_install_timer(void)
  71. {
  72. m8xx_wdt_timer.expires = jiffies + (HZ/2);
  73. add_timer(&m8xx_wdt_timer);
  74. }
  75. static void m8xx_wdt_timer_func(unsigned long data)
  76. {
  77. m8xx_wdt_reset();
  78. m8xx_wdt_install_timer();
  79. }
  80. void __init m8xx_wdt_handler_install(bd_t * binfo)
  81. {
  82. volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
  83. u32 sypcr;
  84. sypcr = in_be32(&imap->im_siu_conf.sc_sypcr);
  85. if (!(sypcr & SYPCR_SWE)) {
  86. printk(KERN_NOTICE "m8xx_wdt: wdt disabled (SYPCR: 0x%08X)\n",
  87. sypcr);
  88. return;
  89. }
  90. m8xx_wdt_reset();
  91. printk(KERN_NOTICE
  92. "m8xx_wdt: active wdt found (SWTC: 0x%04X, SWP: 0x%01X)\n",
  93. (sypcr >> 16), sypcr & SYPCR_SWP);
  94. wdt_timeout = (sypcr >> 16) & 0xFFFF;
  95. if (!wdt_timeout)
  96. wdt_timeout = 0xFFFF;
  97. if (sypcr & SYPCR_SWP)
  98. wdt_timeout *= 2048;
  99. m8xx_has_internal_rtc = in_be16(&imap->im_sit.sit_rtcsc) & RTCSC_RTE;
  100. /* if the internal RTC is off use a kernel timer */
  101. if (!m8xx_has_internal_rtc) {
  102. if (wdt_timeout < (binfo->bi_intfreq/HZ))
  103. printk(KERN_ERR "m8xx_wdt: timeout too short for ktimer!\n");
  104. m8xx_wdt_install_timer();
  105. } else
  106. m8xx_wdt_install_irq(imap, binfo);
  107. wdt_timeout /= binfo->bi_intfreq;
  108. }
  109. int m8xx_wdt_get_timeout(void)
  110. {
  111. return wdt_timeout;
  112. }