Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 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> |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 11 | |
| 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 | |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 25 | /********************************************************************* |
| 26 | * wait_on_value() - common routine to allow waiting for changes in |
| 27 | * volatile regs. |
| 28 | *********************************************************************/ |
| 29 | u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr, |
| 30 | u32 bound) |
| 31 | { |
| 32 | u32 i = 0, val; |
| 33 | do { |
| 34 | ++i; |
| 35 | val = readl((u32)read_addr) & read_bit_mask; |
| 36 | if (val == match_value) |
| 37 | return 1; |
| 38 | if (i == bound) |
| 39 | return 0; |
| 40 | } while (1); |
| 41 | } |