2 * linux/arch/m32r/lib/delay.c
4 * Copyright (c) 2002 Hitoshi Yamamoto, Hirokazu Takata
5 * Copyright (c) 2004 Hirokazu Takata
8 #include <linux/param.h>
10 #include <linux/sched.h>
11 #include <asm/current.h>
13 #endif /* CONFIG_SMP */
14 #include <asm/processor.h>
16 void __delay(unsigned long loops
)
18 #ifdef CONFIG_ISA_DUAL_ISSUE
19 __asm__
__volatile__ (
25 "cmpz %0 || addi %0, #-1 \n\t"
26 "bc 2f || cmpz %0 \n\t"
27 "bc 2f || addi %0, #-1 \n\t"
28 "cmpz %0 || addi %0, #-1 \n\t"
29 "bc 2f || cmpz %0 \n\t"
30 "bnc 1b || addi %0, #-1 \n\t"
38 __asm__
__volatile__ (
58 void __const_udelay(unsigned long xloops
)
60 #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
62 * loops [1] = (xloops >> 32) [sec] * loops_per_jiffy [1/jiffy]
64 * = (xloops >> 32) [sec] * (loops_per_jiffy * HZ) [1/sec]
65 * = (((xloops * loops_per_jiffy) >> 32) * HZ) [1]
68 * - '[]' depicts variable's dimension in the above equation.
69 * - "rac" instruction rounds the accumulator in word size.
71 __asm__
__volatile__ (
73 "mulwhi %0, %1 ; a0 \n\t"
74 "mulwu1 %0, %1 ; a1 \n\t"
75 "sadd ; a0 += (a1 >> 16) \n\t"
79 : "r" (current_cpu_data
.loops_per_jiffy
)
82 #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
85 * ull = (u64)xloops * (u64)current_cpu_data.loops_per_jiffy;
86 * xloops = (ull >> 32);
88 __asm__
__volatile__ (
89 "and3 r4, %0, #0xffff \n\t"
90 "and3 r5, %1, #0xffff \n\t"
92 "srl3 r6, %0, #16 \n\t"
96 "and3 r5, %0, #0xffff \n\t"
97 "srl3 r6, %1, #16 \n\t"
100 "srl3 r5, %0, #16 \n\t"
106 : "r" (current_cpu_data
.loops_per_jiffy
)
110 #error unknown isa configuration
112 __delay(xloops
* HZ
);
115 void __udelay(unsigned long usecs
)
117 __const_udelay(usecs
* 0x000010c7); /* 2**32 / 1000000 (rounded up) */
120 void __ndelay(unsigned long nsecs
)
122 __const_udelay(nsecs
* 0x00005); /* 2**32 / 1000000000 (rounded up) */