delay.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * linux/arch/m32r/lib/delay.c
  3. *
  4. * Copyright (c) 2002 Hitoshi Yamamoto, Hirokazu Takata
  5. * Copyright (c) 2004 Hirokazu Takata
  6. */
  7. #include <linux/param.h>
  8. #ifdef CONFIG_SMP
  9. #include <linux/sched.h>
  10. #include <asm/current.h>
  11. #include <asm/smp.h>
  12. #endif /* CONFIG_SMP */
  13. #include <asm/processor.h>
  14. void __delay(unsigned long loops)
  15. {
  16. #ifdef CONFIG_ISA_DUAL_ISSUE
  17. __asm__ __volatile__ (
  18. "beqz %0, 2f \n\t"
  19. "addi %0, #-1 \n\t"
  20. " .fillinsn \n\t"
  21. "1: \n\t"
  22. "cmpz %0 || addi %0, #-1 \n\t"
  23. "bc 2f || cmpz %0 \n\t"
  24. "bc 2f || addi %0, #-1 \n\t"
  25. "cmpz %0 || addi %0, #-1 \n\t"
  26. "bc 2f || cmpz %0 \n\t"
  27. "bnc 1b || addi %0, #-1 \n\t"
  28. " .fillinsn \n\t"
  29. "2: \n\t"
  30. : "+r" (loops)
  31. : "r" (0)
  32. : "cbit"
  33. );
  34. #else
  35. __asm__ __volatile__ (
  36. "beqz %0, 2f \n\t"
  37. " .fillinsn \n\t"
  38. "1: \n\t"
  39. "addi %0, #-1 \n\t"
  40. "blez %0, 2f \n\t"
  41. "addi %0, #-1 \n\t"
  42. "blez %0, 2f \n\t"
  43. "addi %0, #-1 \n\t"
  44. "blez %0, 2f \n\t"
  45. "addi %0, #-1 \n\t"
  46. "bgtz %0, 1b \n\t"
  47. " .fillinsn \n\t"
  48. "2: \n\t"
  49. : "+r" (loops)
  50. : "r" (0)
  51. );
  52. #endif
  53. }
  54. void __const_udelay(unsigned long xloops)
  55. {
  56. #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
  57. /*
  58. * loops [1] = (xloops >> 32) [sec] * loops_per_jiffy [1/jiffy]
  59. * * HZ [jiffy/sec]
  60. * = (xloops >> 32) [sec] * (loops_per_jiffy * HZ) [1/sec]
  61. * = (((xloops * loops_per_jiffy) >> 32) * HZ) [1]
  62. *
  63. * NOTE:
  64. * - '[]' depicts variable's dimension in the above equation.
  65. * - "rac" instruction rounds the accumulator in word size.
  66. */
  67. __asm__ __volatile__ (
  68. "srli %0, #1 \n\t"
  69. "mulwhi %0, %1 ; a0 \n\t"
  70. "mulwu1 %0, %1 ; a1 \n\t"
  71. "sadd ; a0 += (a1 >> 16) \n\t"
  72. "rac a0, a0, #1 \n\t"
  73. "mvfacmi %0, a0 \n\t"
  74. : "+r" (xloops)
  75. : "r" (current_cpu_data.loops_per_jiffy)
  76. : "a0", "a1"
  77. );
  78. #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
  79. /*
  80. * u64 ull;
  81. * ull = (u64)xloops * (u64)current_cpu_data.loops_per_jiffy;
  82. * xloops = (ull >> 32);
  83. */
  84. __asm__ __volatile__ (
  85. "and3 r4, %0, #0xffff \n\t"
  86. "and3 r5, %1, #0xffff \n\t"
  87. "mul r4, r5 \n\t"
  88. "srl3 r6, %0, #16 \n\t"
  89. "srli r4, #16 \n\t"
  90. "mul r5, r6 \n\t"
  91. "add r4, r5 \n\t"
  92. "and3 r5, %0, #0xffff \n\t"
  93. "srl3 r6, %1, #16 \n\t"
  94. "mul r5, r6 \n\t"
  95. "add r4, r5 \n\t"
  96. "srl3 r5, %0, #16 \n\t"
  97. "srli r4, #16 \n\t"
  98. "mul r5, r6 \n\t"
  99. "add r4, r5 \n\t"
  100. "mv %0, r4 \n\t"
  101. : "+r" (xloops)
  102. : "r" (current_cpu_data.loops_per_jiffy)
  103. : "r4", "r5", "r6"
  104. );
  105. #else
  106. #error unknown isa configuration
  107. #endif
  108. __delay(xloops * HZ);
  109. }
  110. void __udelay(unsigned long usecs)
  111. {
  112. __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
  113. }
  114. void __ndelay(unsigned long nsecs)
  115. {
  116. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  117. }