syslib.c 1.2 KB

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