| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Paul Mundt | a23ba43 | 2007-11-28 20:19:38 +0900 | [diff] [blame] | 2 |  * arch/sh/lib64/udelay.c | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 |  * | 
 | 4 |  * Delay routines, using a pre-computed "loops_per_jiffy" value. | 
 | 5 |  * | 
 | 6 |  * Copyright (C) 2000, 2001  Paolo Alberelli | 
 | 7 |  * Copyright (C) 2003, 2004  Paul Mundt | 
 | 8 |  * | 
 | 9 |  * This file is subject to the terms and conditions of the GNU General Public | 
 | 10 |  * License.  See the file "COPYING" in the main directory of this archive | 
 | 11 |  * for more details. | 
 | 12 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/sched.h> | 
 | 14 | #include <asm/param.h> | 
 | 15 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | /* | 
 | 17 |  * Use only for very small delays (< 1 msec). | 
 | 18 |  * | 
 | 19 |  * The active part of our cycle counter is only 32-bits wide, and | 
 | 20 |  * we're treating the difference between two marks as signed.  On | 
 | 21 |  * a 1GHz box, that's about 2 seconds. | 
 | 22 |  */ | 
 | 23 |  | 
| Paul Mundt | 7b9726a | 2008-03-06 17:23:15 +0900 | [diff] [blame] | 24 | void __delay(unsigned long loops) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { | 
 | 26 | 	long long dummy; | 
 | 27 | 	__asm__ __volatile__("gettr	tr0, %1\n\t" | 
 | 28 | 			     "pta	$+4, tr0\n\t" | 
 | 29 | 			     "addi	%0, -1, %0\n\t" | 
 | 30 | 			     "bne	%0, r63, tr0\n\t" | 
 | 31 | 			     "ptabs	%1, tr0\n\t":"=r"(loops), | 
 | 32 | 			     "=r"(dummy) | 
 | 33 | 			     :"0"(loops)); | 
 | 34 | } | 
 | 35 |  | 
| Paul Mundt | ef9f899 | 2009-05-08 17:36:57 +0900 | [diff] [blame] | 36 | void __const_udelay(unsigned long xloops) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { | 
| Paul Mundt | 7b9726a | 2008-03-06 17:23:15 +0900 | [diff] [blame] | 38 | 	__delay(xloops * (HZ * cpu_data[raw_smp_processor_id()].loops_per_jiffy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } | 
 | 40 |  | 
| Paul Mundt | 7b9726a | 2008-03-06 17:23:15 +0900 | [diff] [blame] | 41 | void __udelay(unsigned long usecs) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { | 
| Paul Mundt | 7b9726a | 2008-03-06 17:23:15 +0900 | [diff] [blame] | 43 | 	__const_udelay(usecs * 0x000010c6);  /* 2**32 / 1000000 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } | 
 | 45 |  | 
| Paul Mundt | 7b9726a | 2008-03-06 17:23:15 +0900 | [diff] [blame] | 46 | void __ndelay(unsigned long nsecs) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { | 
| Paul Mundt | 7b9726a | 2008-03-06 17:23:15 +0900 | [diff] [blame] | 48 | 	__const_udelay(nsecs * 0x00000005); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |