imx_watchdog.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <fsl_wdog.h>
  11. #ifdef CONFIG_IMX_WATCHDOG
  12. void hw_watchdog_reset(void)
  13. {
  14. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  15. writew(0x5555, &wdog->wsr);
  16. writew(0xaaaa, &wdog->wsr);
  17. }
  18. void hw_watchdog_init(void)
  19. {
  20. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  21. u16 timeout;
  22. /*
  23. * The timer watchdog can be set between
  24. * 0.5 and 128 Seconds. If not defined
  25. * in configuration file, sets 128 Seconds
  26. */
  27. #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
  28. #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
  29. #endif
  30. timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
  31. writew(WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_WDT | WCR_SRS |
  32. WCR_WDA | SET_WCR_WT(timeout), &wdog->wcr);
  33. hw_watchdog_reset();
  34. }
  35. #endif
  36. void __attribute__((weak)) reset_cpu(ulong addr)
  37. {
  38. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  39. clrsetbits_le16(&wdog->wcr, WCR_WT_MSK, WCR_WDE);
  40. writew(0x5555, &wdog->wsr);
  41. writew(0xaaaa, &wdog->wsr); /* load minimum 1/2 second timeout */
  42. while (1) {
  43. /*
  44. * spin for .5 seconds before reset
  45. */
  46. }
  47. }