blob: 8348346a18dc7b27351cca97c66abca45f20064d [file] [log] [blame]
Yuri Tikhonov8f15d4a2008-02-04 14:10:42 +01001/*
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
25#include <common.h>
26
27/* This test verifies if the reason of last reset was an abnormal voltage
28 * condition, than it performs watchdog test, measuing time required to
29 * trigger watchdog reset.
30 */
31
32#ifdef CONFIG_POST
33
34#include <post.h>
35
36#if CONFIG_POST & CFG_POST_WATCHDOG
37
38#include <watchdog.h>
39#include <asm/gpio.h>
40#include <asm/io.h>
41
42static uint watchdog_magic_read(void)
43{
44 return in_be32((void *)CFG_WATCHDOG_FLAGS_ADDR) &
45 CFG_WATCHDOG_MAGIC_MASK;
46}
47
48static void watchdog_magic_write(uint value)
49{
50 out_be32((void *)CFG_WATCHDOG_FLAGS_ADDR, value |
51 (in_be32((void *)CFG_WATCHDOG_FLAGS_ADDR) &
52 ~CFG_WATCHDOG_MAGIC_MASK));
53}
54
55int sysmon1_post_test(int flags)
56{
57 if (gpio_read_in_bit(CFG_GPIO_SYSMON_STATUS)) {
58 /* 3.1. GPIO62 is low
59 * Assuming system voltage failure.
60 */
61 post_log("Abnormal voltage detected (GPIO62)\n");
62 return 1;
63 }
64
65 return 0;
66}
67
68int lwmon5_watchdog_post_test(int flags)
69{
70 /* On each reset scratch register 1 should be tested,
71 * but first test GPIO62:
72 */
73 if (!(flags & POST_MANUAL) && sysmon1_post_test(flags)) {
74 /* 3.1. GPIO62 is low
75 * Assuming system voltage failure.
76 */
77 /* 3.1.1. Set scratch register 1 to 0x0000xxxx */
78 watchdog_magic_write(0);
79 /* 3.1.2. Mark test as failed due to voltage?! */
80 return 1;
81 }
82
83 if (watchdog_magic_read() != CFG_WATCHDOG_MAGIC) {
84 /* 3.2. Scratch register 1 differs from magic value 0x1248xxxx
85 * Assuming PowerOn
86 */
87 int ints;
88 ulong base;
89 ulong time;
90
91 /* 3.2.1. Set magic value to scratch register */
92 watchdog_magic_write(CFG_WATCHDOG_MAGIC);
93
94 ints = disable_interrupts ();
95 /* 3.2.2. strobe watchdog once */
96 WATCHDOG_RESET();
97 out_be32((void *)CFG_WATCHDOG_TIME_ADDR, 0);
98 /* 3.2.3. save time of strobe in scratch register 2 */
99 base = post_time_ms (0);
100
101 /* 3.2.4. Wait for 150 ms (enough for reset to happen) */
102 while ((time = post_time_ms (base)) < 150)
103 out_be32((void *)CFG_WATCHDOG_TIME_ADDR, time);
104 if (ints)
105 enable_interrupts ();
106
107 /* 3.2.5. Reset didn't happen. - Set 0x0000xxxx
108 * into scratch register 1
109 */
110 watchdog_magic_write(0);
111 /* 3.2.6. Mark test as failed. */
112 post_log("hw watchdog time : %u ms, failed ", time);
113 return 2;
114 } else {
115 /* 3.3. Scratch register matches magic value 0x1248xxxx
116 * Assume this is watchdog-initiated reset
117 */
118 ulong time;
119 /* 3.3.1. So, the test succeed, save measured time to syslog. */
120 time = in_be32((void *)CFG_WATCHDOG_TIME_ADDR);
121 post_log("hw watchdog time : %u ms, passed ", time);
122 /* 3.3.2. Set scratch register 1 to 0x0000xxxx */
123 watchdog_magic_write(0);
124 return 0;
125 }
126 return -1;
127}
128
129
130#endif /* CONFIG_POST & CFG_POST_WATCHDOG */
131#endif /* CONFIG_POST */