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