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