spi: efm32: Convert to use GPIO descriptors
[linux/fpc-iii.git] / arch / xtensa / include / asm / delay.h
blob24304b39a5c7c902042273d60ca6dd033bd282f4
1 /*
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
6 * for more details.
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");
24 else if (loops >= 2)
25 /* 2 cycles per loop. */
26 __asm__ __volatile__ ("1: addi %0, %0, -2; bgeui %0, 2, 1b"
27 : "+r" (loops));
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)
44 cpu_relax();
47 static inline void udelay(unsigned long usec)
49 if (__builtin_constant_p(usec) && usec >= __MAX_UDELAY)
50 __bad_udelay();
51 else
52 __udelay(usec);
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;
62 __delay(cycles);
65 #define ndelay(n) ndelay(n)
67 static inline void ndelay(unsigned long nsec)
69 if (__builtin_constant_p(nsec) && nsec >= __MAX_NDELAY)
70 __bad_ndelay();
71 else
72 __ndelay(nsec);
75 #endif