Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) #ifndef _ASM_POWERPC_DELAY_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #define _ASM_POWERPC_DELAY_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #ifdef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <asm/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  * Copyright 1996, Paul Mackerras.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)  * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)  * PPC64 Support added by Dave Engebretsen, Todd Inglett, Mike Corrigan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)  * Anton Blanchard.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) extern void __delay(unsigned long loops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) extern void udelay(unsigned long usecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)  * On shared processor machines the generic implementation of mdelay can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)  * result in large errors. While each iteration of the loop inside mdelay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)  * is supposed to take 1ms, the hypervisor could sleep our partition for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  * longer (eg 10ms). With the right timing these errors can add up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  * Since there is no 32bit overflow issue on 64bit kernels, just call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  * udelay directly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define mdelay(n)	udelay((n) * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)  * spin_event_timeout - spin until a condition gets true or a timeout elapses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)  * @condition: a C expression to evalate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)  * @timeout: timeout, in microseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)  * @delay: the number of microseconds to delay between each evaluation of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)  *         @condition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)  * The process spins until the condition evaluates to true (non-zero) or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)  * timeout elapses.  The return value of this macro is the value of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)  * @condition when the loop terminates. This allows you to determine the cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)  * of the loop terminates.  If the return value is zero, then you know a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)  * timeout has occurred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)  * This primary purpose of this macro is to poll on a hardware register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)  * until a status bit changes.  The timeout ensures that the loop still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)  * terminates even if the bit never changes.  The delay is for devices that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)  * need a delay in between successive reads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)  * gcc will optimize out the if-statement if @delay is a constant.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define spin_event_timeout(condition, timeout, delay)                          \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ({                                                                             \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	typeof(condition) __ret;                                               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	unsigned long __loops = tb_ticks_per_usec * timeout;                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	unsigned long __start = mftb();                                     \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)                                                                                \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	if (delay) {                                                           \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		while (!(__ret = (condition)) &&                               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 				(tb_ticks_since(__start) <= __loops))          \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 			udelay(delay);                                         \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	} else {                                                               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		spin_begin();                                                  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		while (!(__ret = (condition)) &&                               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 				(tb_ticks_since(__start) <= __loops))          \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 			spin_cpu_relax();                                      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 		spin_end();                                                    \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	}                                                                      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	if (!__ret)                                                            \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 		__ret = (condition);                                           \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	__ret;		                                                       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #endif /* __KERNEL__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #endif /* _ASM_POWERPC_DELAY_H */