Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <asm/io.h> |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 13 | |
| 14 | /************************************************************ |
| 15 | * sdelay() - simple spin loop. Will be constant time as |
| 16 | * its generally used in bypass conditions only. This |
| 17 | * is necessary until timers are accessible. |
| 18 | * |
| 19 | * not inline to increase chances its in cache when called |
| 20 | *************************************************************/ |
| 21 | void sdelay(unsigned long loops) |
| 22 | { |
| 23 | __asm__ volatile ("1:\n" "subs %0, %1, #1\n" |
| 24 | "bne 1b":"=r" (loops):"0"(loops)); |
| 25 | } |
| 26 | |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 27 | /********************************************************************* |
| 28 | * wait_on_value() - common routine to allow waiting for changes in |
| 29 | * volatile regs. |
| 30 | *********************************************************************/ |
| 31 | u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr, |
| 32 | u32 bound) |
| 33 | { |
| 34 | u32 i = 0, val; |
| 35 | do { |
| 36 | ++i; |
| 37 | val = readl((u32)read_addr) & read_bit_mask; |
| 38 | if (val == match_value) |
| 39 | return 1; |
| 40 | if (i == bound) |
| 41 | return 0; |
| 42 | } while (1); |
| 43 | } |