syslib.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2008
  4. * Texas Instruments, <www.ti.com>
  5. *
  6. * Richard Woodruff <r-woodruff2@ti.com>
  7. * Syed Mohammed Khasim <khasim@ti.com>
  8. */
  9. #include <common.h>
  10. #include <asm/io.h>
  11. /************************************************************
  12. * sdelay() - simple spin loop. Will be constant time as
  13. * its generally used in bypass conditions only. This
  14. * is necessary until timers are accessible.
  15. *
  16. * not inline to increase chances its in cache when called
  17. *************************************************************/
  18. void sdelay(unsigned long loops)
  19. {
  20. __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
  21. "bne 1b":"=r" (loops):"0"(loops));
  22. }
  23. /*********************************************************************
  24. * wait_on_value() - common routine to allow waiting for changes in
  25. * volatile regs.
  26. *********************************************************************/
  27. u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
  28. u32 bound)
  29. {
  30. u32 i = 0, val;
  31. do {
  32. ++i;
  33. val = readl((u32)read_addr) & read_bit_mask;
  34. if (val == match_value)
  35. return 1;
  36. if (i == bound)
  37. return 0;
  38. } while (1);
  39. }