blob: 23c7d17fb9f7398b842c0c9a0b2a19faa2430930 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Paul Mundta23ba432007-11-28 20:19:38 +09002 * arch/sh/lib64/udelay.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070016/*
17 * Use only for very small delays (< 1 msec).
18 *
19 * The active part of our cycle counter is only 32-bits wide, and
20 * we're treating the difference between two marks as signed. On
21 * a 1GHz box, that's about 2 seconds.
22 */
23
24void __delay(int loops)
25{
26 long long dummy;
27 __asm__ __volatile__("gettr tr0, %1\n\t"
28 "pta $+4, tr0\n\t"
29 "addi %0, -1, %0\n\t"
30 "bne %0, r63, tr0\n\t"
31 "ptabs %1, tr0\n\t":"=r"(loops),
32 "=r"(dummy)
33 :"0"(loops));
34}
35
36void __udelay(unsigned long long usecs, unsigned long lpj)
37{
38 usecs *= (((unsigned long long) HZ << 32) / 1000000) * lpj;
39 __delay((long long) usecs >> 32);
40}
41
42void __ndelay(unsigned long long nsecs, unsigned long lpj)
43{
44 nsecs *= (((unsigned long long) HZ << 32) / 1000000000) * lpj;
45 __delay((long long) nsecs >> 32);
46}
47
48void udelay(unsigned long usecs)
49{
Paul Mundt99432702007-11-20 14:49:36 +090050 __udelay(usecs, cpu_data[raw_smp_processor_id()].loops_per_jiffy);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
53void ndelay(unsigned long nsecs)
54{
Paul Mundt99432702007-11-20 14:49:36 +090055 __ndelay(nsecs, cpu_data[raw_smp_processor_id()].loops_per_jiffy);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}