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