2 * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
4 * Developed for DENX Software Engineering GmbH
6 * SPDX-License-Identifier: GPL-2.0+
11 /* This test verifies if the reason of last reset was an abnormal voltage
12 * condition, than it performs watchdog test, measuing time required to
13 * trigger watchdog reset.
18 #if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG
21 #include <asm/ppc4xx-gpio.h>
24 static uint watchdog_magic_read(void)
26 return in_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR) &
27 CONFIG_SYS_WATCHDOG_MAGIC_MASK;
30 static void watchdog_magic_write(uint value)
32 out_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR, value |
33 (in_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR) &
34 ~CONFIG_SYS_WATCHDOG_MAGIC_MASK));
37 int sysmon1_post_test(int flags)
39 if (gpio_read_in_bit(CONFIG_SYS_GPIO_SYSMON_STATUS) == 0) {
42 * Assuming system voltage failure.
44 post_log("sysmon1 Abnormal voltage detected (GPIO62)\n");
45 post_log("POST sysmon1 FAILED\n");
48 post_log("sysmon1 PASSED\n");
54 int lwmon5_watchdog_post_test(int flags)
56 /* On each reset scratch register 1 should be tested,
57 * but first test GPIO62:
59 if (!(flags & POST_MANUAL) && sysmon1_post_test(flags)) {
61 * Assuming system voltage failure.
63 /* 3.1.1. Set scratch register 1 to 0x0000xxxx */
64 watchdog_magic_write(0);
65 /* 3.1.2. Mark test as failed due to voltage?! */
69 if (watchdog_magic_read() != CONFIG_SYS_WATCHDOG_MAGIC) {
70 /* 3.2. Scratch register 1 differs from magic value 0x1248xxxx
77 /* 3.2.1. Set magic value to scratch register */
78 watchdog_magic_write(CONFIG_SYS_WATCHDOG_MAGIC);
80 ints = disable_interrupts ();
81 /* 3.2.2. strobe watchdog once */
83 out_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR, 0);
84 /* 3.2.3. save time of strobe in scratch register 2 */
85 base = post_time_ms (0);
87 /* 3.2.4. Wait for 150 ms (enough for reset to happen) */
88 while ((time = post_time_ms (base)) < 150)
89 out_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR, time);
93 /* 3.2.5. Reset didn't happen. - Set 0x0000xxxx
94 * into scratch register 1
96 watchdog_magic_write(0);
97 /* 3.2.6. Mark test as failed. */
98 post_log("hw watchdog time : %u ms, failed ", time);
101 /* 3.3. Scratch register matches magic value 0x1248xxxx
102 * Assume this is watchdog-initiated reset
105 /* 3.3.1. So, the test succeed, save measured time to syslog. */
106 time = in_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR);
107 if (time > 90 ) { /* ms*/
108 post_log("hw watchdog time : %u ms, passed ", time);
109 /* 3.3.2. Set scratch register 1 to 0x0000xxxx */
110 watchdog_magic_write(0);
113 /*test minimum watchdogtime */
114 post_log("hw watchdog time : %u ms, failed ", time);
121 #endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */