util.S 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copied from <file:arch/powerpc/kernel/misc_32.S>
  4. *
  5. * This file contains miscellaneous low-level functions.
  6. * Copyright (C) 1995-1996 Gary Thomas ([email protected])
  7. *
  8. * Largely rewritten by Cort Dougan ([email protected])
  9. * and Paul Mackerras.
  10. *
  11. * kexec bits:
  12. * Copyright (C) 2002-2003 Eric Biederman <[email protected]>
  13. * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
  14. */
  15. #include "ppc_asm.h"
  16. #define SPRN_PVR 0x11F /* Processor Version Register */
  17. .text
  18. /* udelay needs to know the period of the
  19. * timebase in nanoseconds. This used to be hardcoded to be 60ns
  20. * (period of 66MHz/4). Now a variable is used that is initialized to
  21. * 60 for backward compatibility, but it can be overridden as necessary
  22. * with code something like this:
  23. * extern unsigned long timebase_period_ns;
  24. * timebase_period_ns = 1000000000 / bd->bi_tbfreq;
  25. */
  26. .data
  27. .globl timebase_period_ns
  28. timebase_period_ns:
  29. .long 60
  30. .text
  31. /*
  32. * Delay for a number of microseconds
  33. */
  34. .globl udelay
  35. udelay:
  36. mulli r4,r3,1000 /* nanoseconds */
  37. /* Change r4 to be the number of ticks using:
  38. * (nanoseconds + (timebase_period_ns - 1 )) / timebase_period_ns
  39. * timebase_period_ns defaults to 60 (16.6MHz) */
  40. mflr r5
  41. bcl 20,31,0f
  42. 0: mflr r6
  43. mtlr r5
  44. addis r5,r6,(timebase_period_ns-0b)@ha
  45. lwz r5,(timebase_period_ns-0b)@l(r5)
  46. add r4,r4,r5
  47. addi r4,r4,-1
  48. divw r4,r4,r5 /* BUS ticks */
  49. 1: MFTBU(r5)
  50. MFTBL(r6)
  51. MFTBU(r7)
  52. cmpw 0,r5,r7
  53. bne 1b /* Get [synced] base time */
  54. addc r9,r6,r4 /* Compute end time */
  55. addze r8,r5
  56. 2: MFTBU(r5)
  57. cmpw 0,r5,r8
  58. blt 2b
  59. bgt 3f
  60. MFTBL(r6)
  61. cmpw 0,r6,r9
  62. blt 2b
  63. 3: blr