/* SPDX-License-Identifier: GPL-2.0 */1/*2* Copyright (C) 1995-2004 Russell King3*4* Delay routines, using a pre-computed "loops_per_second" value.5*/6#ifndef __ASM_ARM_DELAY_H7#define __ASM_ARM_DELAY_H89#include <asm/page.h>10#include <asm/param.h> /* HZ */1112/*13* Loop (or tick) based delay:14*15* loops = loops_per_jiffy * jiffies_per_sec * delay_us / us_per_sec16*17* where:18*19* jiffies_per_sec = HZ20* us_per_sec = 100000021*22* Therefore the constant part is HZ / 1000000 which is a small23* fractional number. To make this usable with integer math, we24* scale up this constant by 2^31, perform the actual multiplication,25* and scale the result back down by 2^31 with a simple shift:26*27* loops = (loops_per_jiffy * delay_us * UDELAY_MULT) >> 3128*29* where:30*31* UDELAY_MULT = 2^31 * HZ / 100000032* = (2^31 / 1000000) * HZ33* = 2147.483648 * HZ34* = 2147 * HZ + 483648 * HZ / 100000035*36* 31 is the biggest scale shift value that won't overflow 32 bits for37* delay_us * UDELAY_MULT assuming HZ <= 1000 and delay_us <= 2000.38*/39#define MAX_UDELAY_MS 240#define UDELAY_MULT UL(2147 * HZ + 483648 * HZ / 1000000)41#define UDELAY_SHIFT 314243#ifndef __ASSEMBLY__4445struct delay_timer {46unsigned long (*read_current_timer)(void);47unsigned long freq;48};4950extern struct arm_delay_ops {51void (*delay)(unsigned long);52void (*const_udelay)(unsigned long);53void (*udelay)(unsigned long);54unsigned long ticks_per_jiffy;55} arm_delay_ops;5657#define __delay(n) arm_delay_ops.delay(n)5859/*60* This function intentionally does not exist; if you see references to61* it, it means that you're calling udelay() with an out of range value.62*63* With currently imposed limits, this means that we support a max delay64* of 2000us. Further limits: HZ<=100065*/66extern void __bad_udelay(void);6768/*69* division by multiplication: you don't have to worry about70* loss of precision.71*72* Use only for very small delays ( < 2 msec). Should probably use a73* lookup table, really, as the multiplications take much too long with74* short delays. This is a "reasonable" implementation, though (and the75* first constant multiplications gets optimized away if the delay is76* a constant)77*/78#define __udelay(n) arm_delay_ops.udelay(n)79#define __const_udelay(n) arm_delay_ops.const_udelay(n)8081#define udelay(n) \82(__builtin_constant_p(n) ? \83((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \84__const_udelay((n) * UDELAY_MULT)) : \85__udelay(n))8687/* Loop-based definitions for assembly code. */88extern void __loop_delay(unsigned long loops);89extern void __loop_udelay(unsigned long usecs);90extern void __loop_const_udelay(unsigned long);9192/* Delay-loop timer registration. */93#define ARCH_HAS_READ_CURRENT_TIMER94extern void register_current_timer_delay(const struct delay_timer *timer);9596#endif /* __ASSEMBLY__ */9798#endif /* defined(_ARM_DELAY_H) */99100101102