imx_watchdog.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_WDW 0x80
  20. #define SET_WCR_WT(x) (x << 8)
  21. #ifdef CONFIG_IMX_WATCHDOG
  22. void hw_watchdog_reset(void)
  23. {
  24. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  25. writew(0x5555, &wdog->wsr);
  26. writew(0xaaaa, &wdog->wsr);
  27. }
  28. void hw_watchdog_init(void)
  29. {
  30. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  31. u16 timeout;
  32. /*
  33. * The timer watchdog can be set between
  34. * 0.5 and 128 Seconds. If not defined
  35. * in configuration file, sets 128 Seconds
  36. */
  37. #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
  38. #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
  39. #endif
  40. timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
  41. writew(WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_WDT |
  42. WCR_WDW | SET_WCR_WT(timeout), &wdog->wcr);
  43. hw_watchdog_reset();
  44. }
  45. #endif
  46. void reset_cpu(ulong addr)
  47. {
  48. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  49. writew(WCR_WDE, &wdog->wcr);
  50. writew(0x5555, &wdog->wsr);
  51. writew(0xaaaa, &wdog->wsr); /* load minimum 1/2 second timeout */
  52. while (1) {
  53. /*
  54. * spin for .5 seconds before reset
  55. */
  56. }
  57. }