Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 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> |
Andrew Morton | 941e492 | 2008-02-06 01:36:42 -0800 | [diff] [blame] | 15 | #include <linux/timex.h> |
Haavard Skinnemoen | 3fc0eb4 | 2006-12-08 12:55:03 +0100 | [diff] [blame] | 16 | #include <linux/param.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 17 | #include <linux/types.h> |
Andrew Morton | 941e492 | 2008-02-06 01:36:42 -0800 | [diff] [blame] | 18 | #include <linux/init.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 19 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 20 | #include <asm/processor.h> |
| 21 | #include <asm/sysreg.h> |
| 22 | |
Andrew Morton | 941e492 | 2008-02-06 01:36:42 -0800 | [diff] [blame] | 23 | int __devinit read_current_timer(unsigned long *timer_value) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 24 | { |
| 25 | *timer_value = sysreg_read(COUNT); |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | void __delay(unsigned long loops) |
| 30 | { |
| 31 | unsigned bclock, now; |
| 32 | |
| 33 | bclock = sysreg_read(COUNT); |
| 34 | do { |
| 35 | now = sysreg_read(COUNT); |
| 36 | } while ((now - bclock) < loops); |
| 37 | } |
| 38 | |
| 39 | inline void __const_udelay(unsigned long xloops) |
| 40 | { |
| 41 | unsigned long long loops; |
| 42 | |
| 43 | asm("mulu.d %0, %1, %2" |
| 44 | : "=r"(loops) |
| 45 | : "r"(current_cpu_data.loops_per_jiffy * HZ), "r"(xloops)); |
| 46 | __delay(loops >> 32); |
| 47 | } |
| 48 | |
| 49 | void __udelay(unsigned long usecs) |
| 50 | { |
| 51 | __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */ |
| 52 | } |
| 53 | |
| 54 | void __ndelay(unsigned long nsecs) |
| 55 | { |
| 56 | __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */ |
| 57 | } |