Merge remote-tracking branch 'asoc/fix/wm8993' into asoc-linus
[deliverable/linux.git] / arch / xtensa / include / asm / delay.h
CommitLineData
9a8fd558
CZ
1/*
2 * include/asm-xtensa/delay.h
3 *
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.
7 *
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 *
10 */
11
12#ifndef _XTENSA_DELAY_H
13#define _XTENSA_DELAY_H
14
8102f47a 15#include <asm/timex.h>
9a8fd558
CZ
16#include <asm/param.h>
17
18extern unsigned long loops_per_jiffy;
19
d99cf715 20static inline void __delay(unsigned long loops)
9a8fd558 21{
01e3b3cb
MF
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));
9a8fd558
CZ
28}
29
58f60c22
MF
30/* Undefined function to get compile-time error */
31void __bad_udelay(void);
9ed82c68 32void __bad_ndelay(void);
9a8fd558 33
58f60c22 34#define __MAX_UDELAY 30000
9ed82c68 35#define __MAX_NDELAY 30000
58f60c22
MF
36
37static inline void __udelay(unsigned long usecs)
9a8fd558 38{
8102f47a 39 unsigned long start = get_ccount();
58f60c22 40 unsigned long cycles = (usecs * (ccount_freq >> 15)) >> 5;
9a8fd558
CZ
41
42 /* Note: all variables are unsigned (can wrap around)! */
8102f47a 43 while (((unsigned long)get_ccount()) - start < cycles)
58f60c22
MF
44 cpu_relax();
45}
46
47static inline void udelay(unsigned long usec)
48{
49 if (__builtin_constant_p(usec) && usec >= __MAX_UDELAY)
50 __bad_udelay();
51 else
52 __udelay(usec);
9a8fd558
CZ
53}
54
9ed82c68
MF
55static inline void __ndelay(unsigned long nsec)
56{
57 /*
58 * Inner shift makes sure multiplication doesn't overflow
59 * for legitimate nsec values
60 */
61 unsigned long cycles = (nsec * (ccount_freq >> 15)) >> 15;
62 __delay(cycles);
63}
64
65#define ndelay(n) ndelay(n)
66
67static inline void ndelay(unsigned long nsec)
68{
69 if (__builtin_constant_p(nsec) && nsec >= __MAX_NDELAY)
70 __bad_ndelay();
71 else
72 __ndelay(nsec);
73}
74
9a8fd558 75#endif
This page took 0.627573 seconds and 5 git commands to generate.