m8xx_wdt.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. static irqreturn_t m8xx_wdt_interrupt(int, void *, struct pt_regs *);
  21. static struct irqaction m8xx_wdt_irqaction = {
  22. .handler = m8xx_wdt_interrupt,
  23. .name = "watchdog",
  24. };
  25. void m8xx_wdt_reset(void)
  26. {
  27. volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
  28. out_be16(&imap->im_siu_conf.sc_swsr, 0x556c); /* write magic1 */
  29. out_be16(&imap->im_siu_conf.sc_swsr, 0xaa39); /* write magic2 */
  30. }
  31. static irqreturn_t m8xx_wdt_interrupt(int irq, void *dev, struct pt_regs *regs)
  32. {
  33. volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
  34. m8xx_wdt_reset();
  35. out_be16(&imap->im_sit.sit_piscr, in_be16(&imap->im_sit.sit_piscr) | PISCR_PS); /* clear irq */
  36. return IRQ_HANDLED;
  37. }
  38. void __init m8xx_wdt_handler_install(bd_t * binfo)
  39. {
  40. volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
  41. u32 pitc;
  42. u32 sypcr;
  43. u32 pitrtclk;
  44. sypcr = in_be32(&imap->im_siu_conf.sc_sypcr);
  45. if (!(sypcr & 0x04)) {
  46. printk(KERN_NOTICE "m8xx_wdt: wdt disabled (SYPCR: 0x%08X)\n",
  47. sypcr);
  48. return;
  49. }
  50. m8xx_wdt_reset();
  51. printk(KERN_NOTICE
  52. "m8xx_wdt: active wdt found (SWTC: 0x%04X, SWP: 0x%01X)\n",
  53. (sypcr >> 16), sypcr & 0x01);
  54. wdt_timeout = (sypcr >> 16) & 0xFFFF;
  55. if (!wdt_timeout)
  56. wdt_timeout = 0xFFFF;
  57. if (sypcr & 0x01)
  58. wdt_timeout *= 2048;
  59. /*
  60. * Fire trigger if half of the wdt ticked down
  61. */
  62. if (imap->im_sit.sit_rtcsc & RTCSC_38K)
  63. pitrtclk = 9600;
  64. else
  65. pitrtclk = 8192;
  66. if ((wdt_timeout) > (UINT_MAX / pitrtclk))
  67. pitc = wdt_timeout / binfo->bi_intfreq * pitrtclk / 2;
  68. else
  69. pitc = pitrtclk * wdt_timeout / binfo->bi_intfreq / 2;
  70. out_be32(&imap->im_sit.sit_pitc, pitc << 16);
  71. out_be16(&imap->im_sit.sit_piscr, (mk_int_int_mask(PIT_INTERRUPT) << 8) | PISCR_PIE | PISCR_PTE);
  72. if (setup_irq(PIT_INTERRUPT, &m8xx_wdt_irqaction))
  73. panic("m8xx_wdt: error setting up the watchdog irq!");
  74. printk(KERN_NOTICE
  75. "m8xx_wdt: keep-alive trigger installed (PITC: 0x%04X)\n", pitc);
  76. wdt_timeout /= binfo->bi_intfreq;
  77. }
  78. int m8xx_wdt_get_timeout(void)
  79. {
  80. return wdt_timeout;
  81. }