2005-06-24 13:01:26 +08:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2013-06-17 16:29:44 +08:00
|
|
|
#include <asm/timex.h>
|
2005-06-24 13:01:26 +08:00
|
|
|
#include <asm/param.h>
|
|
|
|
|
|
|
|
extern unsigned long loops_per_jiffy;
|
|
|
|
|
2005-09-04 06:57:53 +08:00
|
|
|
static inline void __delay(unsigned long loops)
|
2005-06-24 13:01:26 +08:00
|
|
|
{
|
2013-10-17 06:42:16 +08:00
|
|
|
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));
|
2005-06-24 13:01:26 +08:00
|
|
|
}
|
|
|
|
|
2014-01-10 16:02:18 +08:00
|
|
|
/* Undefined function to get compile-time error */
|
|
|
|
void __bad_udelay(void);
|
2005-06-24 13:01:26 +08:00
|
|
|
|
2014-01-10 16:02:18 +08:00
|
|
|
#define __MAX_UDELAY 30000
|
|
|
|
|
|
|
|
static inline void __udelay(unsigned long usecs)
|
2005-06-24 13:01:26 +08:00
|
|
|
{
|
2013-06-17 16:29:44 +08:00
|
|
|
unsigned long start = get_ccount();
|
2014-01-10 16:02:18 +08:00
|
|
|
unsigned long cycles = (usecs * (ccount_freq >> 15)) >> 5;
|
2005-06-24 13:01:26 +08:00
|
|
|
|
|
|
|
/* Note: all variables are unsigned (can wrap around)! */
|
2013-06-17 16:29:44 +08:00
|
|
|
while (((unsigned long)get_ccount()) - start < cycles)
|
2014-01-10 16:02:18 +08:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void udelay(unsigned long usec)
|
|
|
|
{
|
|
|
|
if (__builtin_constant_p(usec) && usec >= __MAX_UDELAY)
|
|
|
|
__bad_udelay();
|
|
|
|
else
|
|
|
|
__udelay(usec);
|
2005-06-24 13:01:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|