1/* 2 * This file is subject to the terms and conditions of the GNU General Public 3 * License. See the file "COPYING" in the main directory of this archive 4 * for more details. 5 * 6 * Copyright (C) 1994 by Waldorf Electronics 7 * Copyright (C) 1995 - 1998, 2001 by Ralf Baechle 8 */ 9#ifndef _ASM_DELAY_H 10#define _ASM_DELAY_H 11 12#include <linux/config.h> 13#include <linux/param.h> 14 15extern unsigned long loops_per_jiffy; 16 17extern __inline__ void 18__delay(unsigned long loops) 19{ 20 __asm__ __volatile__ ( 21 ".set\tnoreorder\n" 22 "1:\tbnez\t%0,1b\n\t" 23 "subu\t%0,1\n\t" 24 ".set\treorder" 25 :"=r" (loops) 26 :"0" (loops)); 27} 28 29/* 30 * Division by multiplication: you don't have to worry about 31 * loss of precision. 32 * 33 * Use only for very small delays ( < 1 msec). Should probably use a 34 * lookup table, really, as the multiplications take much too long with 35 * short delays. This is a "reasonable" implementation, though (and the 36 * first constant multiplications gets optimized away if the delay is 37 * a constant) 38 */ 39extern __inline__ void __udelay(unsigned long usecs, unsigned long lpj) 40{ 41 unsigned long lo; 42 43 /* 44 * Excessive precission? Probably ... 45 */ 46 usecs *= (unsigned long) (((0x8000000000000000ULL / (500000 / HZ)) + 47 0x80000000ULL) >> 32); 48 __asm__("multu\t%2,%3" 49 :"=h" (usecs), "=l" (lo) 50 :"r" (usecs),"r" (lpj)); 51 __delay(usecs); 52} 53 54#ifdef CONFIG_SMP 55#define __udelay_val cpu_data[smp_processor_id()].udelay_val 56#else 57#define __udelay_val loops_per_jiffy 58#endif 59 60#define udelay(usecs) __udelay((usecs),__udelay_val) 61 62#endif /* _ASM_DELAY_H */ 63