Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
delay.c
Go to the documentation of this file.
1 /*
2  * Delay loops based on the OpenRISC implementation.
3  *
4  * Copyright (C) 2012 ARM Limited
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Author: Will Deacon <[email protected]>
19  */
20 
21 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/timex.h>
26 
27 void __delay(unsigned long cycles)
28 {
30 
31  while ((get_cycles() - start) < cycles)
32  cpu_relax();
33 }
35 
36 inline void __const_udelay(unsigned long xloops)
37 {
38  unsigned long loops;
39 
40  loops = xloops * loops_per_jiffy * HZ;
41  __delay(loops >> 32);
42 }
44 
45 void __udelay(unsigned long usecs)
46 {
47  __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
48 }
50 
51 void __ndelay(unsigned long nsecs)
52 {
53  __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
54 }