imx_watchdog.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * watchdog.c - driver for i.mx on-chip watchdog
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <watchdog.h>
  9. #include <asm/arch/imx-regs.h>
  10. struct watchdog_regs {
  11. u16 wcr; /* Control */
  12. u16 wsr; /* Service */
  13. u16 wrsr; /* Reset Status */
  14. };
  15. #define WCR_WDZST 0x01
  16. #define WCR_WDBG 0x02
  17. #define WCR_WDE 0x04 /* WDOG enable */
  18. #define WCR_WDT 0x08
  19. #define WCR_SRS 0x10
  20. #define WCR_WDW 0x80
  21. #define SET_WCR_WT(x) (x << 8)
  22. #ifdef CONFIG_IMX_WATCHDOG
  23. void hw_watchdog_reset(void)
  24. {
  25. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  26. writew(0x5555, &wdog->wsr);
  27. writew(0xaaaa, &wdog->wsr);
  28. }
  29. void hw_watchdog_init(void)
  30. {
  31. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  32. u16 timeout;
  33. /*
  34. * The timer watchdog can be set between
  35. * 0.5 and 128 Seconds. If not defined
  36. * in configuration file, sets 128 Seconds
  37. */
  38. #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
  39. #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
  40. #endif
  41. timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
  42. writew(WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_WDT | WCR_SRS |
  43. WCR_WDW | SET_WCR_WT(timeout), &wdog->wcr);
  44. hw_watchdog_reset();
  45. }
  46. #endif
  47. void reset_cpu(ulong addr)
  48. {
  49. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  50. writew(WCR_WDE, &wdog->wcr);
  51. writew(0x5555, &wdog->wsr);
  52. writew(0xaaaa, &wdog->wsr); /* load minimum 1/2 second timeout */
  53. while (1) {
  54. /*
  55. * spin for .5 seconds before reset
  56. */
  57. }
  58. }