]>
Commit | Line | Data |
---|---|---|
ad5bb451 WD |
1 | /* |
2 | * (C) Copyright 2002 | |
3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
ad5bb451 WD |
6 | */ |
7 | ||
8 | #include <common.h> | |
9 | ||
10 | /* | |
11 | * Watchdog test | |
12 | * | |
13 | * The test verifies the watchdog timer operation. | |
14 | * On the first iteration, the test routine disables interrupts and | |
15 | * makes a 10-second delay. If the system does not reboot during this delay, | |
16 | * the watchdog timer is not operational and the test fails. If the system | |
17 | * reboots, on the second iteration the test routine reports a success. | |
18 | */ | |
19 | ||
ad5bb451 WD |
20 | #include <post.h> |
21 | #include <watchdog.h> | |
22 | ||
6d0f6bcf | 23 | #if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG |
ad5bb451 WD |
24 | |
25 | static ulong gettbl (void) | |
26 | { | |
27 | ulong r; | |
28 | ||
29 | asm ("mftbl %0":"=r" (r)); | |
30 | ||
31 | return r; | |
32 | } | |
33 | ||
34 | int watchdog_post_test (int flags) | |
35 | { | |
36 | if (flags & POST_REBOOT) { | |
37 | /* Test passed */ | |
38 | ||
39 | return 0; | |
40 | } else { | |
41 | /* 10-second delay */ | |
42 | int ints = disable_interrupts (); | |
43 | ulong base = gettbl (); | |
44 | ulong clk = get_tbclk (); | |
45 | ||
46 | while ((gettbl () - base) / 10 < clk); | |
47 | ||
48 | if (ints) | |
49 | enable_interrupts (); | |
50 | ||
51 | /* | |
52 | * If we have reached this point, the watchdog timer | |
53 | * does not work | |
54 | */ | |
55 | return -1; | |
56 | } | |
57 | } | |
58 | ||
6d0f6bcf | 59 | #endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */ |