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>
9 #include <linux/module.h>
11 #include <linux/sched.h>
12 #include <asm/current.h>
14 #endif /* CONFIG_SMP */
15 #include <asm/processor.h>
17 void __delay(unsigned long loops)
19 #ifdef CONFIG_ISA_DUAL_ISSUE
20 __asm__ __volatile__ (
26 "cmpz %0 || addi %0, #-1 \n\t"
27 "bc 2f || cmpz %0 \n\t"
28 "bc 2f || addi %0, #-1 \n\t"
29 "cmpz %0 || addi %0, #-1 \n\t"
30 "bc 2f || cmpz %0 \n\t"
31 "bnc 1b || addi %0, #-1 \n\t"
39 __asm__ __volatile__ (
59 void __const_udelay(unsigned long xloops)
61 #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
63 * loops [1] = (xloops >> 32) [sec] * loops_per_jiffy [1/jiffy]
65 * = (xloops >> 32) [sec] * (loops_per_jiffy * HZ) [1/sec]
66 * = (((xloops * loops_per_jiffy) >> 32) * HZ) [1]
69 * - '[]' depicts variable's dimension in the above equation.
70 * - "rac" instruction rounds the accumulator in word size.
72 __asm__ __volatile__ (
74 "mulwhi %0, %1 ; a0 \n\t"
75 "mulwu1 %0, %1 ; a1 \n\t"
76 "sadd ; a0 += (a1 >> 16) \n\t"
80 : "r" (current_cpu_data.loops_per_jiffy)
83 #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
86 * ull = (u64)xloops * (u64)current_cpu_data.loops_per_jiffy;
87 * xloops = (ull >> 32);
89 __asm__ __volatile__ (
90 "and3 r4, %0, #0xffff \n\t"
91 "and3 r5, %1, #0xffff \n\t"
93 "srl3 r6, %0, #16 \n\t"
97 "and3 r5, %0, #0xffff \n\t"
98 "srl3 r6, %1, #16 \n\t"
101 "srl3 r5, %0, #16 \n\t"
107 : "r" (current_cpu_data.loops_per_jiffy)
111 #error unknown isa configuration
113 __delay(xloops * HZ);
116 void __udelay(unsigned long usecs)
118 __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
121 void __ndelay(unsigned long nsecs)
123 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
125 EXPORT_SYMBOL(__ndelay);