blob: c487f938fa8d1f12715fb077c1f4e1d258c43363 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
wdenk12e44072001-11-26 22:06:16 +00002/*
3 * (C) Copyright 2000, 2001
4 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
5 * base on code by
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk12e44072001-11-26 22:06:16 +00007 */
8
9#include <ppc_asm.tmpl>
10#include <ppc_defs.h>
11#include <config.h>
12#include <watchdog.h>
13
14/*
15 * unsigned long long get_ticks(void);
16 *
17 * read timebase as "long long"
18 */
19 .globl get_ticks
20get_ticks:
211: mftbu r3
22 mftb r4
23 mftbu r5
24 cmp 0,r3,r5
25 bne 1b
26 blr
27
28/*
29 * Delay for a number of ticks
30 */
31 .globl wait_ticks
32wait_ticks:
Joakim Tjernlund83f83d12012-07-16 21:25:40 +000033 stwu r1, -16(r1)
34 mflr r0 /* save link register */
35 stw r0, 20(r1) /* Use r0 or GDB will be unhappy */
Mats Kärrmanfac150e2013-04-09 17:10:59 +020036 stw r14, 12(r1) /* save used registers */
37 stw r15, 8(r1)
38 mr r14, r3 /* save tick count */
wdenk12e44072001-11-26 22:06:16 +000039 bl get_ticks /* Get start time */
40
41 /* Calculate end time */
Mats Kärrmanfac150e2013-04-09 17:10:59 +020042 addc r14, r4, r14 /* Compute end time lower */
43 addze r15, r3 /* and end time upper */
wdenk12e44072001-11-26 22:06:16 +000044
45 WATCHDOG_RESET /* Trigger watchdog, if needed */
461: bl get_ticks /* Get current time */
Mats Kärrmanfac150e2013-04-09 17:10:59 +020047 subfc r4, r4, r14 /* Subtract current time from end time */
48 subfe. r3, r3, r15
wdenk12e44072001-11-26 22:06:16 +000049 bge 1b /* Loop until time expired */
50
Mats Kärrmanfac150e2013-04-09 17:10:59 +020051 lwz r15, 8(r1) /* restore saved registers */
52 lwz r14, 12(r1)
53 lwz r0, 20(r1)
Joakim Tjernlund83f83d12012-07-16 21:25:40 +000054 addi r1,r1,16
Mats Kärrmanfac150e2013-04-09 17:10:59 +020055 mtlr r0
wdenk12e44072001-11-26 22:06:16 +000056 blr