watchdog.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
  3. *
  4. * Developed for DENX Software Engineering GmbH
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. /* This test verifies if the reason of last reset was an abnormal voltage
  10. * condition, than it performs watchdog test, measuing time required to
  11. * trigger watchdog reset.
  12. */
  13. #include <post.h>
  14. #if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG
  15. #include <watchdog.h>
  16. #include <asm/ppc4xx-gpio.h>
  17. #include <asm/io.h>
  18. static uint watchdog_magic_read(void)
  19. {
  20. return in_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR) &
  21. CONFIG_SYS_WATCHDOG_MAGIC_MASK;
  22. }
  23. static void watchdog_magic_write(uint value)
  24. {
  25. out_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR, value |
  26. (in_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR) &
  27. ~CONFIG_SYS_WATCHDOG_MAGIC_MASK));
  28. }
  29. int sysmon1_post_test(int flags)
  30. {
  31. if (gpio_read_in_bit(CONFIG_SYS_GPIO_SYSMON_STATUS) == 0) {
  32. /*
  33. * 3.1. GPIO62 is low
  34. * Assuming system voltage failure.
  35. */
  36. post_log("sysmon1 Abnormal voltage detected (GPIO62)\n");
  37. post_log("POST sysmon1 FAILED\n");
  38. return 1;
  39. } else {
  40. post_log("sysmon1 PASSED\n");
  41. }
  42. return 0;
  43. }
  44. int lwmon5_watchdog_post_test(int flags)
  45. {
  46. /* On each reset scratch register 1 should be tested,
  47. * but first test GPIO62:
  48. */
  49. if (!(flags & POST_MANUAL) && sysmon1_post_test(flags)) {
  50. /* 3.1. GPIO62 is low
  51. * Assuming system voltage failure.
  52. */
  53. /* 3.1.1. Set scratch register 1 to 0x0000xxxx */
  54. watchdog_magic_write(0);
  55. /* 3.1.2. Mark test as failed due to voltage?! */
  56. return 1;
  57. }
  58. if (watchdog_magic_read() != CONFIG_SYS_WATCHDOG_MAGIC) {
  59. /* 3.2. Scratch register 1 differs from magic value 0x1248xxxx
  60. * Assuming PowerOn
  61. */
  62. int ints;
  63. ulong base;
  64. ulong time;
  65. /* 3.2.1. Set magic value to scratch register */
  66. watchdog_magic_write(CONFIG_SYS_WATCHDOG_MAGIC);
  67. ints = disable_interrupts ();
  68. /* 3.2.2. strobe watchdog once */
  69. WATCHDOG_RESET();
  70. out_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR, 0);
  71. /* 3.2.3. save time of strobe in scratch register 2 */
  72. base = post_time_ms (0);
  73. /* 3.2.4. Wait for 150 ms (enough for reset to happen) */
  74. while ((time = post_time_ms (base)) < 150)
  75. out_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR, time);
  76. if (ints)
  77. enable_interrupts ();
  78. /* 3.2.5. Reset didn't happen. - Set 0x0000xxxx
  79. * into scratch register 1
  80. */
  81. watchdog_magic_write(0);
  82. /* 3.2.6. Mark test as failed. */
  83. post_log("hw watchdog time : %u ms, failed ", time);
  84. return 2;
  85. } else {
  86. /* 3.3. Scratch register matches magic value 0x1248xxxx
  87. * Assume this is watchdog-initiated reset
  88. */
  89. ulong time;
  90. /* 3.3.1. So, the test succeed, save measured time to syslog. */
  91. time = in_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR);
  92. if (time > 90 ) { /* ms*/
  93. post_log("hw watchdog time : %u ms, passed ", time);
  94. /* 3.3.2. Set scratch register 1 to 0x0000xxxx */
  95. watchdog_magic_write(0);
  96. return 0;
  97. } else {
  98. /*test minimum watchdogtime */
  99. post_log("hw watchdog time : %u ms, failed ", time);
  100. return 2;
  101. }
  102. }
  103. return -1;
  104. }
  105. #endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */