watchdog.c 993 B

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