blob: a070539b16f4107304e22f7bf9e6b7ddd07758e1 [file] [log] [blame]
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01006 */
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
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010020#include <post.h>
21#include <watchdog.h>
22
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023#if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010024
25static ulong gettbl (void)
26{
27 ulong r;
28
29 asm ("mftbl %0":"=r" (r));
30
31 return r;
32}
33
34int 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
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059#endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */