Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 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 | |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 20 | #include <post.h> |
| 21 | #include <watchdog.h> |
| 22 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | #if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | #endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */ |