blob: 327653914007b808e1f753b12aa0598a2441aba0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh64/lib/udelay.c
3 *
4 * Delay routines, using a pre-computed "loops_per_jiffy" value.
5 *
6 * Copyright (C) 2000, 2001 Paolo Alberelli
7 * Copyright (C) 2003, 2004 Paul Mundt
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/sched.h>
14#include <asm/param.h>
15
16extern unsigned long loops_per_jiffy;
17
18/*
19 * Use only for very small delays (< 1 msec).
20 *
21 * The active part of our cycle counter is only 32-bits wide, and
22 * we're treating the difference between two marks as signed. On
23 * a 1GHz box, that's about 2 seconds.
24 */
25
26void __delay(int loops)
27{
28 long long dummy;
29 __asm__ __volatile__("gettr tr0, %1\n\t"
30 "pta $+4, tr0\n\t"
31 "addi %0, -1, %0\n\t"
32 "bne %0, r63, tr0\n\t"
33 "ptabs %1, tr0\n\t":"=r"(loops),
34 "=r"(dummy)
35 :"0"(loops));
36}
37
38void __udelay(unsigned long long usecs, unsigned long lpj)
39{
40 usecs *= (((unsigned long long) HZ << 32) / 1000000) * lpj;
41 __delay((long long) usecs >> 32);
42}
43
44void __ndelay(unsigned long long nsecs, unsigned long lpj)
45{
46 nsecs *= (((unsigned long long) HZ << 32) / 1000000000) * lpj;
47 __delay((long long) nsecs >> 32);
48}
49
50void udelay(unsigned long usecs)
51{
52 __udelay(usecs, loops_per_jiffy);
53}
54
55void ndelay(unsigned long nsecs)
56{
57 __ndelay(nsecs, loops_per_jiffy);
58}
59