^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2011 Richard Weinberger <richrd@nod.at>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Mostly copied from arch/x86/lib/delay.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/param.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) void __delay(unsigned long loops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) "test %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) "jz 3f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) "jmp 1f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ".align 16\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) "1: jmp 2f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) ".align 16\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) "2: dec %0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) " jnz 2b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) "3: dec %0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) : /* we don't need output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) : "a" (loops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) EXPORT_SYMBOL(__delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) inline void __const_udelay(unsigned long xloops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int d0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) xloops *= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) asm("mull %%edx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) : "=d" (xloops), "=&a" (d0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) : "1" (xloops), "0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) (loops_per_jiffy * (HZ/4)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __delay(++xloops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) EXPORT_SYMBOL(__const_udelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) void __udelay(unsigned long usecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) EXPORT_SYMBOL(__udelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) void __ndelay(unsigned long nsecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) EXPORT_SYMBOL(__ndelay);