Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2011 Richard Weinberger <richrd@nod.at>
0004  * Mostly copied from arch/x86/lib/delay.c
0005  */
0006 
0007 #include <linux/export.h>
0008 #include <linux/kernel.h>
0009 #include <linux/delay.h>
0010 #include <asm/param.h>
0011 
0012 void __delay(unsigned long loops)
0013 {
0014     asm volatile(
0015         "test %0,%0\n"
0016         "jz 3f\n"
0017         "jmp 1f\n"
0018 
0019         ".align 16\n"
0020         "1: jmp 2f\n"
0021 
0022         ".align 16\n"
0023         "2: dec %0\n"
0024         " jnz 2b\n"
0025         "3: dec %0\n"
0026 
0027         : /* we don't need output */
0028         : "a" (loops)
0029     );
0030 }
0031 EXPORT_SYMBOL(__delay);
0032 
0033 inline void __const_udelay(unsigned long xloops)
0034 {
0035     int d0;
0036 
0037     xloops *= 4;
0038     asm("mull %%edx"
0039         : "=d" (xloops), "=&a" (d0)
0040         : "1" (xloops), "0"
0041         (loops_per_jiffy * (HZ/4)));
0042 
0043     __delay(++xloops);
0044 }
0045 EXPORT_SYMBOL(__const_udelay);
0046 
0047 void __udelay(unsigned long usecs)
0048 {
0049     __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
0050 }
0051 EXPORT_SYMBOL(__udelay);
0052 
0053 void __ndelay(unsigned long nsecs)
0054 {
0055     __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
0056 }
0057 EXPORT_SYMBOL(__ndelay);