Mike Frysinger | 9e83b98 | 2007-11-21 16:08:58 +0800 | [diff] [blame] | 1 | /* |
| 2 | * delay.h - delay functions |
| 3 | * |
| 4 | * Copyright (c) 2004-2007 Analog Devices Inc. |
| 5 | * |
| 6 | * Licensed under the GPL-2 or later. |
| 7 | */ |
| 8 | |
| 9 | #ifndef __ASM_DELAY_H__ |
| 10 | #define __ASM_DELAY_H__ |
| 11 | |
Bryan Wu | 639f657 | 2008-08-27 10:51:02 +0800 | [diff] [blame] | 12 | #include <mach/anomaly.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 13 | |
| 14 | static inline void __delay(unsigned long loops) |
| 15 | { |
Michael Hennerich | c8e6741 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 16 | __asm__ __volatile__ ( |
Mike Frysinger | 9e83b98 | 2007-11-21 16:08:58 +0800 | [diff] [blame] | 17 | "LSETUP(1f, 1f) LC0 = %0;" |
| 18 | "1: NOP;" |
| 19 | : |
| 20 | : "a" (loops) |
| 21 | : "LT0", "LB0", "LC0" |
| 22 | ); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | #include <linux/param.h> /* needed for HZ */ |
| 26 | |
| 27 | /* |
Michael Hennerich | 4e653e0 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 28 | * close approximation borrowed from m68knommu to avoid 64-bit math |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 29 | */ |
Michael Hennerich | 4e653e0 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 30 | |
| 31 | #define HZSCALE (268435456 / (1000000/HZ)) |
| 32 | |
Barry Song | 6388d14 | 2010-01-21 07:20:44 +0000 | [diff] [blame] | 33 | static inline unsigned long __to_delay(unsigned long scale) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 34 | { |
| 35 | extern unsigned long loops_per_jiffy; |
Barry Song | 6388d14 | 2010-01-21 07:20:44 +0000 | [diff] [blame] | 36 | return (((scale * HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Barry Song | 6388d14 | 2010-01-21 07:20:44 +0000 | [diff] [blame] | 39 | static inline void udelay(unsigned long usecs) |
| 40 | { |
| 41 | __delay(__to_delay(usecs)); |
| 42 | } |
| 43 | |
| 44 | static inline void ndelay(unsigned long nsecs) |
| 45 | { |
| 46 | __delay(__to_delay(1) * nsecs / 1000); |
| 47 | } |
| 48 | |
| 49 | #define ndelay ndelay |
| 50 | |
Mike Frysinger | 9e83b98 | 2007-11-21 16:08:58 +0800 | [diff] [blame] | 51 | #endif |