blob: 8647d77cc9ad4590326fcbc335b930781069b8ec [file] [log] [blame]
Tom Rini10e47792018-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>
wdenk12e44072001-11-26 22:06:16 +000012
13/*
14 * unsigned long long get_ticks(void);
15 *
16 * read timebase as "long long"
17 */
18 .globl get_ticks
19get_ticks:
201: mftbu r3
21 mftb r4
22 mftbu r5
23 cmp 0,r3,r5
24 bne 1b
25 blr
26
27/*
28 * Delay for a number of ticks
29 */
30 .globl wait_ticks
31wait_ticks:
Joakim Tjernlund194c3bf2012-07-16 21:25:40 +000032 stwu r1, -16(r1)
33 mflr r0 /* save link register */
34 stw r0, 20(r1) /* Use r0 or GDB will be unhappy */
Mats Kärrmand1cdc1b2013-04-09 17:10:59 +020035 stw r14, 12(r1) /* save used registers */
36 stw r15, 8(r1)
37 mr r14, r3 /* save tick count */
wdenk12e44072001-11-26 22:06:16 +000038 bl get_ticks /* Get start time */
39
40 /* Calculate end time */
Mats Kärrmand1cdc1b2013-04-09 17:10:59 +020041 addc r14, r4, r14 /* Compute end time lower */
42 addze r15, r3 /* and end time upper */
wdenk12e44072001-11-26 22:06:16 +000043
Stefan Roese5b492ee2022-09-02 14:10:47 +020044#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
45 bl schedule /* Trigger watchdog, if needed */
46#endif
wdenk12e44072001-11-26 22:06:16 +0000471: bl get_ticks /* Get current time */
Mats Kärrmand1cdc1b2013-04-09 17:10:59 +020048 subfc r4, r4, r14 /* Subtract current time from end time */
49 subfe. r3, r3, r15
wdenk12e44072001-11-26 22:06:16 +000050 bge 1b /* Loop until time expired */
51
Mats Kärrmand1cdc1b2013-04-09 17:10:59 +020052 lwz r15, 8(r1) /* restore saved registers */
53 lwz r14, 12(r1)
54 lwz r0, 20(r1)
Joakim Tjernlund194c3bf2012-07-16 21:25:40 +000055 addi r1,r1,16
Mats Kärrmand1cdc1b2013-04-09 17:10:59 +020056 mtlr r0
wdenk12e44072001-11-26 22:06:16 +000057 blr