![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * Copyright (C) 1995-2004 Russell King 0004 * 0005 * Delay routines, using a pre-computed "loops_per_second" value. 0006 */ 0007 #ifndef __ASM_ARM_DELAY_H 0008 #define __ASM_ARM_DELAY_H 0009 0010 #include <asm/memory.h> 0011 #include <asm/param.h> /* HZ */ 0012 0013 /* 0014 * Loop (or tick) based delay: 0015 * 0016 * loops = loops_per_jiffy * jiffies_per_sec * delay_us / us_per_sec 0017 * 0018 * where: 0019 * 0020 * jiffies_per_sec = HZ 0021 * us_per_sec = 1000000 0022 * 0023 * Therefore the constant part is HZ / 1000000 which is a small 0024 * fractional number. To make this usable with integer math, we 0025 * scale up this constant by 2^31, perform the actual multiplication, 0026 * and scale the result back down by 2^31 with a simple shift: 0027 * 0028 * loops = (loops_per_jiffy * delay_us * UDELAY_MULT) >> 31 0029 * 0030 * where: 0031 * 0032 * UDELAY_MULT = 2^31 * HZ / 1000000 0033 * = (2^31 / 1000000) * HZ 0034 * = 2147.483648 * HZ 0035 * = 2147 * HZ + 483648 * HZ / 1000000 0036 * 0037 * 31 is the biggest scale shift value that won't overflow 32 bits for 0038 * delay_us * UDELAY_MULT assuming HZ <= 1000 and delay_us <= 2000. 0039 */ 0040 #define MAX_UDELAY_MS 2 0041 #define UDELAY_MULT UL(2147 * HZ + 483648 * HZ / 1000000) 0042 #define UDELAY_SHIFT 31 0043 0044 #ifndef __ASSEMBLY__ 0045 0046 struct delay_timer { 0047 unsigned long (*read_current_timer)(void); 0048 unsigned long freq; 0049 }; 0050 0051 extern struct arm_delay_ops { 0052 void (*delay)(unsigned long); 0053 void (*const_udelay)(unsigned long); 0054 void (*udelay)(unsigned long); 0055 unsigned long ticks_per_jiffy; 0056 } arm_delay_ops; 0057 0058 #define __delay(n) arm_delay_ops.delay(n) 0059 0060 /* 0061 * This function intentionally does not exist; if you see references to 0062 * it, it means that you're calling udelay() with an out of range value. 0063 * 0064 * With currently imposed limits, this means that we support a max delay 0065 * of 2000us. Further limits: HZ<=1000 0066 */ 0067 extern void __bad_udelay(void); 0068 0069 /* 0070 * division by multiplication: you don't have to worry about 0071 * loss of precision. 0072 * 0073 * Use only for very small delays ( < 2 msec). Should probably use a 0074 * lookup table, really, as the multiplications take much too long with 0075 * short delays. This is a "reasonable" implementation, though (and the 0076 * first constant multiplications gets optimized away if the delay is 0077 * a constant) 0078 */ 0079 #define __udelay(n) arm_delay_ops.udelay(n) 0080 #define __const_udelay(n) arm_delay_ops.const_udelay(n) 0081 0082 #define udelay(n) \ 0083 (__builtin_constant_p(n) ? \ 0084 ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \ 0085 __const_udelay((n) * UDELAY_MULT)) : \ 0086 __udelay(n)) 0087 0088 /* Loop-based definitions for assembly code. */ 0089 extern void __loop_delay(unsigned long loops); 0090 extern void __loop_udelay(unsigned long usecs); 0091 extern void __loop_const_udelay(unsigned long); 0092 0093 /* Delay-loop timer registration. */ 0094 #define ARCH_HAS_READ_CURRENT_TIMER 0095 extern void register_current_timer_delay(const struct delay_timer *timer); 0096 0097 #endif /* __ASSEMBLY__ */ 0098 0099 #endif /* defined(_ARM_DELAY_H) */ 0100
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |