/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _M68K_DELAY_H2#define _M68K_DELAY_H34#include <asm/param.h>56/*7* Copyright (C) 1994 Hamish Macdonald8* Copyright (C) 2004 Greg Ungerer <[email protected]>9*10* Delay routines, using a pre-computed "loops_per_jiffy" value.11*/1213#if defined(CONFIG_COLDFIRE)14/*15* The ColdFire runs the delay loop at significantly different speeds16* depending upon long word alignment or not. We'll pad it to17* long word alignment which is the faster version.18* The 0x4a8e is of course a 'tstl %fp' instruction. This is better19* than using a NOP (0x4e71) instruction because it executes in one20* cycle not three and doesn't allow for an arbitrary delay waiting21* for bus cycles to finish. Also fp/a6 isn't likely to cause a22* stall waiting for the register to become valid if such is added23* to the coldfire at some stage.24*/25#define DELAY_ALIGN ".balignw 4, 0x4a8e\n\t"26#else27/*28* No instruction alignment required for other m68k types.29*/30#define DELAY_ALIGN31#endif3233static inline void __delay(unsigned long loops)34{35__asm__ __volatile__ (36DELAY_ALIGN37"1: subql #1,%0\n\t"38"jcc 1b"39: "=d" (loops)40: "0" (loops));41}4243extern void __bad_udelay(void);444546#ifdef CONFIG_CPU_HAS_NO_MULDIV6447/*48* The simpler m68k and ColdFire processors do not have a 32*32->6449* multiply instruction. So we need to handle them a little differently.50* We use a bit of shifting and a single 32*32->32 multiply to get close.51*/52#define HZSCALE (268435456 / (1000000 / HZ))5354#define __const_udelay(u) \55__delay(((((u) * HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6)5657#else5859static inline void __xdelay(unsigned long xloops)60{61unsigned long tmp;6263__asm__ ("mulul %2,%0:%1"64: "=d" (xloops), "=d" (tmp)65: "d" (xloops), "1" (loops_per_jiffy));66__delay(xloops * HZ);67}6869/*70* The definition of __const_udelay is specifically made a macro so that71* the const factor (4295 = 2**32 / 1000000) can be optimized out when72* the delay is a const.73*/74#define __const_udelay(n) (__xdelay((n) * 4295))7576#endif7778static inline void __udelay(unsigned long usecs)79{80__const_udelay(usecs);81}8283/*84* Use only for very small delays ( < 1 msec). Should probably use a85* lookup table, really, as the multiplications take much too long with86* short delays. This is a "reasonable" implementation, though (and the87* first constant multiplications gets optimized away if the delay is88* a constant)89*/90#define udelay(n) (__builtin_constant_p(n) ? \91((n) > 20000 ? __bad_udelay() : __const_udelay(n)) : __udelay(n))9293/*94* nanosecond delay:95*96* ((((HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6) is the number of loops97* per microsecond98*99* 1000 / ((((HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6) is the number of100* nanoseconds per loop101*102* So n / ( 1000 / ((((HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6) ) would103* be the number of loops for n nanoseconds104*/105106/*107* The simpler m68k and ColdFire processors do not have a 32*32->64108* multiply instruction. So we need to handle them a little differently.109* We use a bit of shifting and a single 32*32->32 multiply to get close.110* This is a macro so that the const version can factor out the first111* multiply and shift.112*/113#define HZSCALE (268435456 / (1000000 / HZ))114115static inline void ndelay(unsigned long nsec)116{117__delay(DIV_ROUND_UP(nsec *118((((HZSCALE) >> 11) *119(loops_per_jiffy >> 11)) >> 6),1201000));121}122#define ndelay(n) ndelay(n)123124#endif /* defined(_M68K_DELAY_H) */125126127