]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - post/cpu/mpc8xx/watchdog.c
a070539b16f4107304e22f7bf9e6b7ddd07758e1
[karo-tx-uboot.git] / post / cpu / mpc8xx / watchdog.c
1 /*
2  * (C) Copyright 2002
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
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
20 #include <post.h>
21 #include <watchdog.h>
22
23 #if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG
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
59 #endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */