summaryrefslogtreecommitdiff
path: root/arch/xtensa/include/asm/delay.h
blob: 69ba4629bed09025e38de039e7a2d25d73a89a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * include/asm-xtensa/delay.h
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 2001 - 2005 Tensilica Inc.
 *
 */

#ifndef _XTENSA_DELAY_H
#define _XTENSA_DELAY_H

#include <asm/timex.h>
#include <asm/param.h>

extern unsigned long loops_per_jiffy;

static inline void __delay(unsigned long loops)
{
	if (__builtin_constant_p(loops) && loops < 2)
		__asm__ __volatile__ ("nop");
	else if (loops >= 2)
		/* 2 cycles per loop. */
		__asm__ __volatile__ ("1: addi %0, %0, -2; bgeui %0, 2, 1b"
				: "+r" (loops));
}

/* Undefined function to get compile-time error */
void __bad_udelay(void);

#define __MAX_UDELAY 30000

static inline void __udelay(unsigned long usecs)
{
	unsigned long start = get_ccount();
	unsigned long cycles = (usecs * (ccount_freq >> 15)) >> 5;

	/* Note: all variables are unsigned (can wrap around)! */
	while (((unsigned long)get_ccount()) - start < cycles)
		cpu_relax();
}

static inline void udelay(unsigned long usec)
{
	if (__builtin_constant_p(usec) && usec >= __MAX_UDELAY)
		__bad_udelay();
	else
		__udelay(usec);
}

#endif