Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Precise Delay Loops for SuperH |
| 3 | * |
| 4 | * Copyright (C) 1999 Niibe Yutaka & Kaz Kojima |
| 5 | */ |
| 6 | |
| 7 | #include <linux/sched.h> |
| 8 | #include <linux/delay.h> |
| 9 | |
| 10 | void __delay(unsigned long loops) |
| 11 | { |
| 12 | __asm__ __volatile__( |
| 13 | "tst %0, %0\n\t" |
| 14 | "1:\t" |
| 15 | "bf/s 1b\n\t" |
| 16 | " dt %0" |
| 17 | : "=r" (loops) |
| 18 | : "0" (loops) |
| 19 | : "t"); |
| 20 | } |
| 21 | |
| 22 | inline void __const_udelay(unsigned long xloops) |
| 23 | { |
Stuart Menefy | bd4fb4d | 2009-08-24 18:18:50 +0900 | [diff] [blame] | 24 | xloops *= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | __asm__("dmulu.l %0, %2\n\t" |
| 26 | "sts mach, %0" |
| 27 | : "=r" (xloops) |
kogiidena | c71861e | 2007-05-08 20:45:46 +0900 | [diff] [blame] | 28 | : "0" (xloops), |
Stuart Menefy | bd4fb4d | 2009-08-24 18:18:50 +0900 | [diff] [blame] | 29 | "r" (cpu_data[raw_smp_processor_id()].loops_per_jiffy * (HZ/4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | : "macl", "mach"); |
Stuart Menefy | bd4fb4d | 2009-08-24 18:18:50 +0900 | [diff] [blame] | 31 | __delay(++xloops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void __udelay(unsigned long usecs) |
| 35 | { |
| 36 | __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */ |
| 37 | } |
| 38 | |
| 39 | void __ndelay(unsigned long nsecs) |
| 40 | { |
| 41 | __const_udelay(nsecs * 0x00000005); |
| 42 | } |
| 43 | |