blob: dc81ca8dc0dd4b0ccd81ae2edc78b059aa8fd016 [file] [log] [blame]
Ralf Baechle56369192009-02-28 09:44:28 +00001/*
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 - 2000, 01, 03 by Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 * Copyright (C) 2007 Maciej W. Rozycki
10 */
11#include <linux/module.h>
12#include <linux/param.h>
13#include <linux/smp.h>
14
15#include <asm/compiler.h>
16#include <asm/war.h>
17
David Daney5210edc2012-09-28 11:34:10 -070018void __delay(unsigned long loops)
Ralf Baechle56369192009-02-28 09:44:28 +000019{
20 __asm__ __volatile__ (
21 " .set noreorder \n"
22 " .align 3 \n"
23 "1: bnez %0, 1b \n"
David Daney5210edc2012-09-28 11:34:10 -070024#if __SIZEOF_LONG__ == 4
Ralf Baechle56369192009-02-28 09:44:28 +000025 " subu %0, 1 \n"
David Daney5210edc2012-09-28 11:34:10 -070026#else
27 " dsubu %0, 1 \n"
28#endif
Ralf Baechle56369192009-02-28 09:44:28 +000029 " .set reorder \n"
30 : "=r" (loops)
31 : "0" (loops));
32}
33EXPORT_SYMBOL(__delay);
34
35/*
36 * Division by multiplication: you don't have to worry about
37 * loss of precision.
38 *
39 * Use only for very small delays ( < 1 msec). Should probably use a
40 * lookup table, really, as the multiplications take much too long with
41 * short delays. This is a "reasonable" implementation, though (and the
42 * first constant multiplications gets optimized away if the delay is
43 * a constant)
44 */
45
46void __udelay(unsigned long us)
47{
Ralf Baechleabe5b412010-03-10 16:16:04 +010048 unsigned int lpj = raw_current_cpu_data.udelay_val;
Ralf Baechle56369192009-02-28 09:44:28 +000049
Atsushi Nemoto3cb3a662009-06-09 11:12:48 +090050 __delay((us * 0x000010c7ull * HZ * lpj) >> 32);
Ralf Baechle56369192009-02-28 09:44:28 +000051}
52EXPORT_SYMBOL(__udelay);
53
54void __ndelay(unsigned long ns)
55{
Ralf Baechleabe5b412010-03-10 16:16:04 +010056 unsigned int lpj = raw_current_cpu_data.udelay_val;
Ralf Baechle56369192009-02-28 09:44:28 +000057
Atsushi Nemoto3cb3a662009-06-09 11:12:48 +090058 __delay((ns * 0x00000005ull * HZ * lpj) >> 32);
Ralf Baechle56369192009-02-28 09:44:28 +000059}
60EXPORT_SYMBOL(__ndelay);