2 * include/asm-xtensa/delay.h
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
12 #ifndef _XTENSA_DELAY_H
13 #define _XTENSA_DELAY_H
15 #include <asm/timex.h>
16 #include <asm/param.h>
18 extern unsigned long loops_per_jiffy
;
20 static inline void __delay(unsigned long loops
)
22 if (__builtin_constant_p(loops
) && loops
< 2)
23 __asm__
__volatile__ ("nop");
25 /* 2 cycles per loop. */
26 __asm__
__volatile__ ("1: addi %0, %0, -2; bgeui %0, 2, 1b"
30 /* Undefined function to get compile-time error */
31 void __bad_udelay(void);
32 void __bad_ndelay(void);
34 #define __MAX_UDELAY 30000
35 #define __MAX_NDELAY 30000
37 static inline void __udelay(unsigned long usecs
)
39 unsigned long start
= get_ccount();
40 unsigned long cycles
= (usecs
* (ccount_freq
>> 15)) >> 5;
42 /* Note: all variables are unsigned (can wrap around)! */
43 while (((unsigned long)get_ccount()) - start
< cycles
)
47 static inline void udelay(unsigned long usec
)
49 if (__builtin_constant_p(usec
) && usec
>= __MAX_UDELAY
)
55 static inline void __ndelay(unsigned long nsec
)
58 * Inner shift makes sure multiplication doesn't overflow
59 * for legitimate nsec values
61 unsigned long cycles
= (nsec
* (ccount_freq
>> 15)) >> 15;
65 #define ndelay(n) ndelay(n)
67 static inline void ndelay(unsigned long nsec
)
69 if (__builtin_constant_p(nsec
) && nsec
>= __MAX_NDELAY
)