1/*
2 * BK Id: SCCS/s.delay.h 1.7 05/17/01 18:14:24 cort
3 */
4#ifdef __KERNEL__
5#ifndef _PPC_DELAY_H
6#define _PPC_DELAY_H
7
8#include <asm/param.h>
9
10/*
11 * Copyright 1996, Paul Mackerras.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 */
18
19extern unsigned long loops_per_jiffy;
20
21/* maximum permitted argument to udelay */
22#define __MAX_UDELAY	1000000
23
24extern void __delay(unsigned int loops);
25
26/* N.B. the `secs' parameter here is a fixed-point number with
27   the binary point to the left of the most-significant bit. */
28extern __inline__ void __const_udelay(unsigned int secs)
29{
30	unsigned int loops;
31
32	__asm__("mulhwu %0,%1,%2" : "=r" (loops) :
33		"r" (secs), "r" (loops_per_jiffy));
34	__delay(loops * HZ);
35}
36
37/*
38 * note that 4294 == 2^32 / 10^6, multiplying by 4294 converts from
39 * microseconds to a 32-bit fixed-point number of seconds.
40 */
41extern __inline__ void __udelay(unsigned int usecs)
42{
43	__const_udelay(usecs * 4294);
44}
45
46extern void __bad_udelay(void);		/* deliberately undefined */
47
48#define udelay(n) (__builtin_constant_p(n)? \
49		   ((n) > __MAX_UDELAY? __bad_udelay(): __const_udelay((n) * 4294u)) : \
50		   __udelay(n))
51
52#endif /* defined(_PPC_DELAY_H) */
53#endif /* __KERNEL__ */
54