diff options
Diffstat (limited to 'arch/avr32/lib/delay.c')
-rw-r--r-- | arch/avr32/lib/delay.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/arch/avr32/lib/delay.c b/arch/avr32/lib/delay.c new file mode 100644 index 000000000000..462c8307b680 --- /dev/null +++ b/arch/avr32/lib/delay.c | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * Precise Delay Loops for avr32 | ||
3 | * | ||
4 | * Copyright (C) 1993 Linus Torvalds | ||
5 | * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz> | ||
6 | * Copyright (C) 2005-2006 Atmel Corporation | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #include <linux/delay.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/types.h> | ||
16 | |||
17 | #include <asm/delay.h> | ||
18 | #include <asm/processor.h> | ||
19 | #include <asm/sysreg.h> | ||
20 | |||
21 | int read_current_timer(unsigned long *timer_value) | ||
22 | { | ||
23 | *timer_value = sysreg_read(COUNT); | ||
24 | return 0; | ||
25 | } | ||
26 | |||
27 | void __delay(unsigned long loops) | ||
28 | { | ||
29 | unsigned bclock, now; | ||
30 | |||
31 | bclock = sysreg_read(COUNT); | ||
32 | do { | ||
33 | now = sysreg_read(COUNT); | ||
34 | } while ((now - bclock) < loops); | ||
35 | } | ||
36 | |||
37 | inline void __const_udelay(unsigned long xloops) | ||
38 | { | ||
39 | unsigned long long loops; | ||
40 | |||
41 | asm("mulu.d %0, %1, %2" | ||
42 | : "=r"(loops) | ||
43 | : "r"(current_cpu_data.loops_per_jiffy * HZ), "r"(xloops)); | ||
44 | __delay(loops >> 32); | ||
45 | } | ||
46 | |||
47 | void __udelay(unsigned long usecs) | ||
48 | { | ||
49 | __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */ | ||
50 | } | ||
51 | |||
52 | void __ndelay(unsigned long nsecs) | ||
53 | { | ||
54 | __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */ | ||
55 | } | ||