watchdog.c 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <asm/processor.h>
  4. #include <asm/system.h>
  5. #include <asm/io.h>
  6. #define WDT_BASE WTCNT
  7. #define WDT_WD (1 << 6)
  8. #define WDT_RST_P (0)
  9. #define WDT_RST_M (1 << 5)
  10. #define WDT_ENABLE (1 << 7)
  11. #if defined(CONFIG_WATCHDOG)
  12. static unsigned char csr_read(void)
  13. {
  14. return inb(WDT_BASE + 0x04);
  15. }
  16. static void cnt_write(unsigned char value)
  17. {
  18. outl((unsigned short)value | 0x5A00, WDT_BASE + 0x00);
  19. }
  20. static void csr_write(unsigned char value)
  21. {
  22. outl((unsigned short)value | 0xA500, WDT_BASE + 0x04);
  23. }
  24. void watchdog_reset(void)
  25. {
  26. outl(0x55000000, WDT_BASE + 0x08);
  27. }
  28. int watchdog_init(void)
  29. {
  30. /* Set overflow time*/
  31. cnt_write(0);
  32. /* Power on reset */
  33. csr_write(WDT_WD|WDT_RST_P|WDT_ENABLE);
  34. return 0;
  35. }
  36. int watchdog_disable(void)
  37. {
  38. csr_write(csr_read() & ~WDT_ENABLE);
  39. return 0;
  40. }
  41. #endif
  42. void reset_cpu(unsigned long ignored)
  43. {
  44. /* Address error with SR.BL=1 first. */
  45. trigger_address_error();
  46. while (1)
  47. ;
  48. }