watchdog.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
  3. *
  4. * Developed for DENX Software Engineering GmbH
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. /* This test verifies if the reason of last reset was an abnormal voltage
  26. * condition, than it performs watchdog test, measuing time required to
  27. * trigger watchdog reset.
  28. */
  29. #include <post.h>
  30. #if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG
  31. #include <watchdog.h>
  32. #include <asm/ppc4xx-gpio.h>
  33. #include <asm/io.h>
  34. static uint watchdog_magic_read(void)
  35. {
  36. return in_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR) &
  37. CONFIG_SYS_WATCHDOG_MAGIC_MASK;
  38. }
  39. static void watchdog_magic_write(uint value)
  40. {
  41. out_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR, value |
  42. (in_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR) &
  43. ~CONFIG_SYS_WATCHDOG_MAGIC_MASK));
  44. }
  45. int sysmon1_post_test(int flags)
  46. {
  47. if (gpio_read_in_bit(CONFIG_SYS_GPIO_SYSMON_STATUS) == 0) {
  48. /*
  49. * 3.1. GPIO62 is low
  50. * Assuming system voltage failure.
  51. */
  52. post_log("sysmon1 Abnormal voltage detected (GPIO62)\n");
  53. post_log("POST sysmon1 FAILED\n");
  54. return 1;
  55. } else {
  56. post_log("sysmon1 PASSED\n");
  57. }
  58. return 0;
  59. }
  60. int lwmon5_watchdog_post_test(int flags)
  61. {
  62. /* On each reset scratch register 1 should be tested,
  63. * but first test GPIO62:
  64. */
  65. if (!(flags & POST_MANUAL) && sysmon1_post_test(flags)) {
  66. /* 3.1. GPIO62 is low
  67. * Assuming system voltage failure.
  68. */
  69. /* 3.1.1. Set scratch register 1 to 0x0000xxxx */
  70. watchdog_magic_write(0);
  71. /* 3.1.2. Mark test as failed due to voltage?! */
  72. return 1;
  73. }
  74. if (watchdog_magic_read() != CONFIG_SYS_WATCHDOG_MAGIC) {
  75. /* 3.2. Scratch register 1 differs from magic value 0x1248xxxx
  76. * Assuming PowerOn
  77. */
  78. int ints;
  79. ulong base;
  80. ulong time;
  81. /* 3.2.1. Set magic value to scratch register */
  82. watchdog_magic_write(CONFIG_SYS_WATCHDOG_MAGIC);
  83. ints = disable_interrupts ();
  84. /* 3.2.2. strobe watchdog once */
  85. WATCHDOG_RESET();
  86. out_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR, 0);
  87. /* 3.2.3. save time of strobe in scratch register 2 */
  88. base = post_time_ms (0);
  89. /* 3.2.4. Wait for 150 ms (enough for reset to happen) */
  90. while ((time = post_time_ms (base)) < 150)
  91. out_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR, time);
  92. if (ints)
  93. enable_interrupts ();
  94. /* 3.2.5. Reset didn't happen. - Set 0x0000xxxx
  95. * into scratch register 1
  96. */
  97. watchdog_magic_write(0);
  98. /* 3.2.6. Mark test as failed. */
  99. post_log("hw watchdog time : %u ms, failed ", time);
  100. return 2;
  101. } else {
  102. /* 3.3. Scratch register matches magic value 0x1248xxxx
  103. * Assume this is watchdog-initiated reset
  104. */
  105. ulong time;
  106. /* 3.3.1. So, the test succeed, save measured time to syslog. */
  107. time = in_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR);
  108. if (time > 90 ) { /* ms*/
  109. post_log("hw watchdog time : %u ms, passed ", time);
  110. /* 3.3.2. Set scratch register 1 to 0x0000xxxx */
  111. watchdog_magic_write(0);
  112. return 0;
  113. } else {
  114. /*test minimum watchdogtime */
  115. post_log("hw watchdog time : %u ms, failed ", time);
  116. return 2;
  117. }
  118. }
  119. return -1;
  120. }
  121. #endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */