xref: /openbmc/u-boot/arch/powerpc/lib/ticks.S (revision 83f83d19354f9d9b4d5d6fc06dd9c00d2340dab5)
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:
50*83f83d19SJoakim Tjernlund	stwu	r1, -16(r1)
51*83f83d19SJoakim Tjernlund	mflr	r0		/* save link register */
52*83f83d19SJoakim Tjernlund	stw	r0, 20(r1)	/* Use r0 or GDB will be unhappy */
53a47a12beSStefan Roese	mr	r7, r3		/* save tick count */
54a47a12beSStefan Roese	bl	get_ticks	/* Get start time */
55a47a12beSStefan Roese
56a47a12beSStefan Roese	/* Calculate end time */
57a47a12beSStefan Roese	addc    r7, r4, r7	/* Compute end time lower */
58a47a12beSStefan Roese	addze	r6, r3		/*     and end time upper */
59a47a12beSStefan Roese
60a47a12beSStefan Roese	WATCHDOG_RESET		/* Trigger watchdog, if needed */
61a47a12beSStefan Roese1:	bl	get_ticks	/* Get current time */
62a47a12beSStefan Roese	subfc	r4, r4, r7	/* Subtract current time from end time */
63a47a12beSStefan Roese	subfe.	r3, r3, r6
64a47a12beSStefan Roese	bge	1b		/* Loop until time expired */
65a47a12beSStefan Roese
66*83f83d19SJoakim Tjernlund	mtlr	r0		/* restore link register */
67*83f83d19SJoakim Tjernlund	addi	r1,r1,16
68a47a12beSStefan Roese	blr
69