util.S 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 (gdt@linuxppc.org)
  7. *
  8. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  9. * and Paul Mackerras.
  10. *
  11. * kexec bits:
  12. * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
  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. bl 0f
  42. 0: mflr r6
  43. mtlr r5
  44. lis r5,0b@ha
  45. addi r5,r5,0b@l
  46. subf r5,r5,r6 /* In case we're relocated */
  47. addis r5,r5,timebase_period_ns@ha
  48. lwz r5,timebase_period_ns@l(r5)
  49. add r4,r4,r5
  50. addi r4,r4,-1
  51. divw r4,r4,r5 /* BUS ticks */
  52. 1: MFTBU(r5)
  53. MFTBL(r6)
  54. MFTBU(r7)
  55. cmpw 0,r5,r7
  56. bne 1b /* Get [synced] base time */
  57. addc r9,r6,r4 /* Compute end time */
  58. addze r8,r5
  59. 2: MFTBU(r5)
  60. cmpw 0,r5,r8
  61. blt 2b
  62. bgt 3f
  63. MFTBL(r6)
  64. cmpw 0,r6,r9
  65. blt 2b
  66. 3: blr