more verbose logging
[pandora-x-loader.git] / board / omap4430panda / syslib.c
1 /*
2  * (C) Copyright 2006
3  * Texas Instruments, <www.ti.com>
4  * Richard Woodruff <r-woodruff2@ti.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  */
21
22 #include <common.h>
23 #include <asm/arch/cpu.h>
24 #include <asm/io.h>
25 #include <asm/arch/bits.h>
26 #include <asm/arch/mem.h>
27 #include <asm/arch/clocks.h>
28 #include <asm/arch/sys_proto.h>
29 #include <asm/arch/sys_info.h>
30
31 /************************************************************
32  * sdelay() - simple spin loop.  Will be constant time as
33  *  its generally used in bypass conditions only.  This
34  *  is necessary until timers are accessible.
35  *
36  *  not inline to increase chances its in cache when called
37  *************************************************************/
38 void sdelay(unsigned long loops)
39 {
40         __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
41                                           "bne 1b" : "=r" (loops) : "0"(loops));
42 }
43
44 /*****************************************************************
45  * sr32 - clear & set a value in a bit range for a 32 bit address
46  *****************************************************************/
47 void sr32(u32 addr, u32 start_bit, u32 num_bits, u32 value)
48 {
49         u32 tmp, msk = 0;
50         msk = 1 << num_bits;
51         --msk;
52         tmp = __raw_readl(addr) & ~(msk << start_bit);
53         tmp |=  value << start_bit;
54         __raw_writel(tmp, addr);
55 }
56
57 /*********************************************************************
58  * wait_on_value() - common routine to allow waiting for changes in
59  *   volatile regs.
60  *********************************************************************/
61 u32 wait_on_value(u32 read_bit_mask, u32 match_value, u32 read_addr, u32 bound)
62 {
63         u32 i = 0, val;
64         do {
65                 ++i;
66                 val = __raw_readl(read_addr) & read_bit_mask;
67                 if (val == match_value)
68                         return 1;
69                 if (i == bound)
70                         return 0;
71         } while (1);
72 }
73