xref: /openbmc/u-boot/arch/powerpc/lib/ticks.S (revision b9553986)
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
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.
7 */
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:
33	stwu	r1, -16(r1)
34	mflr	r0		/* save link register */
35	stw	r0, 20(r1)	/* Use r0 or GDB will be unhappy */
36	stw	r14, 12(r1)	/* save used registers */
37	stw	r15, 8(r1)
38	mr	r14, r3		/* save tick count */
39	bl	get_ticks	/* Get start time */
40
41	/* Calculate end time */
42	addc    r14, r4, r14	/* Compute end time lower */
43	addze	r15, r3		/*     and end time upper */
44
45	WATCHDOG_RESET		/* Trigger watchdog, if needed */
461:	bl	get_ticks	/* Get current time */
47	subfc	r4, r4, r14	/* Subtract current time from end time */
48	subfe.	r3, r3, r15
49	bge	1b		/* Loop until time expired */
50
51	lwz     r15, 8(r1)	/* restore saved registers */
52	lwz     r14, 12(r1)
53	lwz     r0, 20(r1)
54	addi	r1,r1,16
55	mtlr	r0
56	blr
57