Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 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 | |
Baruch Siach | 8102f47 | 2013-06-17 11:29:44 +0300 | [diff] [blame] | 15 | #include <asm/timex.h> |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 16 | #include <asm/param.h> |
| 17 | |
| 18 | extern unsigned long loops_per_jiffy; |
| 19 | |
Adrian Bunk | d99cf71 | 2005-09-03 15:57:53 -0700 | [diff] [blame] | 20 | static inline void __delay(unsigned long loops) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 21 | { |
Max Filippov | 01e3b3c | 2013-10-17 02:42:16 +0400 | [diff] [blame] | 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)); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Max Filippov | 58f60c2 | 2014-01-10 12:02:18 +0400 | [diff] [blame^] | 30 | /* Undefined function to get compile-time error */ |
| 31 | void __bad_udelay(void); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 32 | |
Max Filippov | 58f60c2 | 2014-01-10 12:02:18 +0400 | [diff] [blame^] | 33 | #define __MAX_UDELAY 30000 |
| 34 | |
| 35 | static inline void __udelay(unsigned long usecs) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 36 | { |
Baruch Siach | 8102f47 | 2013-06-17 11:29:44 +0300 | [diff] [blame] | 37 | unsigned long start = get_ccount(); |
Max Filippov | 58f60c2 | 2014-01-10 12:02:18 +0400 | [diff] [blame^] | 38 | unsigned long cycles = (usecs * (ccount_freq >> 15)) >> 5; |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 39 | |
| 40 | /* Note: all variables are unsigned (can wrap around)! */ |
Baruch Siach | 8102f47 | 2013-06-17 11:29:44 +0300 | [diff] [blame] | 41 | while (((unsigned long)get_ccount()) - start < cycles) |
Max Filippov | 58f60c2 | 2014-01-10 12:02:18 +0400 | [diff] [blame^] | 42 | cpu_relax(); |
| 43 | } |
| 44 | |
| 45 | static inline void udelay(unsigned long usec) |
| 46 | { |
| 47 | if (__builtin_constant_p(usec) && usec >= __MAX_UDELAY) |
| 48 | __bad_udelay(); |
| 49 | else |
| 50 | __udelay(usec); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | #endif |