2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1994 by Waldorf Electronics
7 * Copyright (C) 1995 - 2000, 01, 03 by Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 * Copyright (C) 2007 Maciej W. Rozycki
14 #include <linux/param.h>
15 #include <linux/smp.h>
17 #include <asm/compiler.h>
20 static inline void __delay(unsigned long loops)
22 if (sizeof(long) == 4)
23 __asm__ __volatile__ (
31 else if (sizeof(long) == 8 && !DADDI_WAR)
32 __asm__ __volatile__ (
40 else if (sizeof(long) == 8 && DADDI_WAR)
41 __asm__ __volatile__ (
48 : "0" (loops), "r" (1));
53 * Division by multiplication: you don't have to worry about
56 * Use only for very small delays ( < 1 msec). Should probably use a
57 * lookup table, really, as the multiplications take much too long with
58 * short delays. This is a "reasonable" implementation, though (and the
59 * first constant multiplications gets optimized away if the delay is
63 static inline void __udelay(unsigned long usecs, unsigned long lpj)
68 * The rates of 128 is rounded wrongly by the catchall case
69 * for 64-bit. Excessive precission? Probably ...
71 #if defined(CONFIG_64BIT) && (HZ == 128)
72 usecs *= 0x0008637bd05af6c7UL; /* 2**64 / (1000000 / HZ) */
73 #elif defined(CONFIG_64BIT)
74 usecs *= (0x8000000000000000UL / (500000 / HZ));
75 #else /* 32-bit junk follows here */
76 usecs *= (unsigned long) (((0x8000000000000000ULL / (500000 / HZ)) +
77 0x80000000ULL) >> 32);
80 if (sizeof(long) == 4)
81 __asm__("multu\t%2, %3"
82 : "=h" (usecs), "=l" (lo)
83 : "r" (usecs), "r" (lpj)
85 else if (sizeof(long) == 8 && !R4000_WAR)
86 __asm__("dmultu\t%2, %3"
87 : "=h" (usecs), "=l" (lo)
88 : "r" (usecs), "r" (lpj)
90 else if (sizeof(long) == 8 && R4000_WAR)
91 __asm__("dmultu\t%3, %4\n\tmfhi\t%0"
92 : "=r" (usecs), "=h" (hi), "=l" (lo)
93 : "r" (usecs), "r" (lpj)
99 #define __udelay_val cpu_data[raw_smp_processor_id()].udelay_val
101 #define udelay(usecs) __udelay((usecs), __udelay_val)
103 /* make sure "usecs *= ..." in udelay do not overflow. */
105 #define MAX_UDELAY_MS 1
107 #define MAX_UDELAY_MS 5
109 #define MAX_UDELAY_MS (1000 / HZ)
112 #endif /* _ASM_DELAY_H */