xref: /openbmc/u-boot/arch/powerpc/lib/ticks.S (revision fac150e83f403933e9ffc9d01f858c4a6313874e)
1a47a12beSStefan Roese/*
2a47a12beSStefan Roese * (C) Copyright 2000, 2001
3a47a12beSStefan Roese * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
4a47a12beSStefan Roese *  base on code by
5a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6a47a12beSStefan Roese *
7a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this
8a47a12beSStefan Roese * project.
9a47a12beSStefan Roese *
10a47a12beSStefan Roese * This program is free software; you can redistribute it and/or
11a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as
12a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of
13a47a12beSStefan Roese * the License, or (at your option) any later version.
14a47a12beSStefan Roese *
15a47a12beSStefan Roese * This program is distributed in the hope that it will be useful,
16a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of
17a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18a47a12beSStefan Roese * GNU General Public License for more details.
19a47a12beSStefan Roese *
20a47a12beSStefan Roese * You should have received a copy of the GNU General Public License
21a47a12beSStefan Roese * along with this program; if not, write to the Free Software
22a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23a47a12beSStefan Roese * MA 02111-1307 USA
24a47a12beSStefan Roese */
25a47a12beSStefan Roese
26a47a12beSStefan Roese#include <ppc_asm.tmpl>
27a47a12beSStefan Roese#include <ppc_defs.h>
28a47a12beSStefan Roese#include <config.h>
29a47a12beSStefan Roese#include <watchdog.h>
30a47a12beSStefan Roese
31a47a12beSStefan Roese/*
32a47a12beSStefan Roese * unsigned long long get_ticks(void);
33a47a12beSStefan Roese *
34a47a12beSStefan Roese * read timebase as "long long"
35a47a12beSStefan Roese */
36a47a12beSStefan Roese	.globl	get_ticks
37a47a12beSStefan Roeseget_ticks:
38a47a12beSStefan Roese1:	mftbu	r3
39a47a12beSStefan Roese	mftb	r4
40a47a12beSStefan Roese	mftbu	r5
41a47a12beSStefan Roese	cmp	0,r3,r5
42a47a12beSStefan Roese	bne	1b
43a47a12beSStefan Roese	blr
44a47a12beSStefan Roese
45a47a12beSStefan Roese/*
46a47a12beSStefan Roese * Delay for a number of ticks
47a47a12beSStefan Roese */
48a47a12beSStefan Roese	.globl	wait_ticks
49a47a12beSStefan Roesewait_ticks:
5083f83d19SJoakim Tjernlund	stwu	r1, -16(r1)
5183f83d19SJoakim Tjernlund	mflr	r0		/* save link register */
5283f83d19SJoakim Tjernlund	stw	r0, 20(r1)	/* Use r0 or GDB will be unhappy */
53*fac150e8SMats Kärrman	stw	r14, 12(r1)	/* save used registers */
54*fac150e8SMats Kärrman	stw	r15, 8(r1)
55*fac150e8SMats Kärrman	mr	r14, r3		/* save tick count */
56a47a12beSStefan Roese	bl	get_ticks	/* Get start time */
57a47a12beSStefan Roese
58a47a12beSStefan Roese	/* Calculate end time */
59*fac150e8SMats Kärrman	addc    r14, r4, r14	/* Compute end time lower */
60*fac150e8SMats Kärrman	addze	r15, r3		/*     and end time upper */
61a47a12beSStefan Roese
62a47a12beSStefan Roese	WATCHDOG_RESET		/* Trigger watchdog, if needed */
63a47a12beSStefan Roese1:	bl	get_ticks	/* Get current time */
64*fac150e8SMats Kärrman	subfc	r4, r4, r14	/* Subtract current time from end time */
65*fac150e8SMats Kärrman	subfe.	r3, r3, r15
66a47a12beSStefan Roese	bge	1b		/* Loop until time expired */
67a47a12beSStefan Roese
68*fac150e8SMats Kärrman	lwz     r15, 8(r1)	/* restore saved registers */
69*fac150e8SMats Kärrman	lwz     r14, 12(r1)
70*fac150e8SMats Kärrman	lwz     r0, 20(r1)
7183f83d19SJoakim Tjernlund	addi	r1,r1,16
72*fac150e8SMats Kärrman	mtlr	r0
73a47a12beSStefan Roese	blr
74