tizen 2.4 release
[kernel/u-boot-tm1.git] / board / armltd / vexpress / ca9x4_ct_vxp.c
1 /*
2  * (C) Copyright 2002
3  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4  * Marius Groeger <mgroeger@sysgo.de>
5  *
6  * (C) Copyright 2002
7  * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
8  *
9  * (C) Copyright 2003
10  * Texas Instruments, <www.ti.com>
11  * Kshitij Gupta <Kshitij@ti.com>
12  *
13  * (C) Copyright 2004
14  * ARM Ltd.
15  * Philippe Robin, <philippe.robin@arm.com>
16  *
17  * See file CREDITS for list of people who contributed to this
18  * project.
19  *
20  * This program is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU General Public License as
22  * published by the Free Software Foundation; either version 2 of
23  * the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33  * MA 02111-1307 USA
34  */
35 #include <common.h>
36 #include <netdev.h>
37 #include <asm/io.h>
38 #include <asm/arch/systimer.h>
39 #include <asm/arch/sysctrl.h>
40 #include <asm/arch/wdt.h>
41
42 static ulong timestamp;
43 static ulong lastdec;
44
45 static struct wdt *wdt_base = (struct wdt *)WDT_BASE;
46 static struct systimer *systimer_base = (struct systimer *)SYSTIMER_BASE;
47 static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
48
49 static void flash__init(void);
50 static void vexpress_timer_init(void);
51 DECLARE_GLOBAL_DATA_PTR;
52
53 #if defined(CONFIG_SHOW_BOOT_PROGRESS)
54 void show_boot_progress(int progress)
55 {
56         printf("Boot reached stage %d\n", progress);
57 }
58 #endif
59
60 static inline void delay(ulong loops)
61 {
62         __asm__ volatile ("1:\n"
63                 "subs %0, %1, #1\n"
64                 "bne 1b" : "=r" (loops) : "0" (loops));
65 }
66
67 int board_init(void)
68 {
69         gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
70         gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
71         gd->flags = 0;
72
73         icache_enable();
74         flash__init();
75         vexpress_timer_init();
76
77         return 0;
78 }
79
80 int board_eth_init(bd_t *bis)
81 {
82         int rc = 0;
83 #ifdef CONFIG_SMC911X
84         rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
85 #endif
86         return rc;
87 }
88
89 static void flash__init(void)
90 {
91         /* Setup the sytem control register to allow writing to flash */
92         writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
93                &sysctrl_base->scflashctrl);
94 }
95
96 int dram_init(void)
97 {
98         gd->ram_size =
99                 get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
100         return 0;
101 }
102
103 void dram_init_banksize(void)
104 {
105         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
106         gd->bd->bi_dram[0].size =
107                         get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
108         gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
109         gd->bd->bi_dram[1].size =
110                         get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
111 }
112
113 int timer_init(void)
114 {
115         return 0;
116 }
117
118 /*
119  * Start timer:
120  *    Setup a 32 bit timer, running at 1KHz
121  *    Versatile Express Motherboard provides 1 MHz timer
122  */
123 static void vexpress_timer_init(void)
124 {
125         /*
126          * Set clock frequency in system controller:
127          *   VEXPRESS_REFCLK is 32KHz
128          *   VEXPRESS_TIMCLK is 1MHz
129          */
130         writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
131                SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
132                readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
133
134         /*
135          * Set Timer0 to be:
136          *   Enabled, free running, no interrupt, 32-bit, wrapping
137          */
138         writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
139         writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
140         writel(SYSTIMER_EN | SYSTIMER_32BIT | \
141                readl(&systimer_base->timer0control), \
142                &systimer_base->timer0control);
143
144         reset_timer_masked();
145 }
146
147 /* Use the ARM Watchdog System to cause reset */
148 void reset_cpu(ulong addr)
149 {
150         writeb(WDT_EN, &wdt_base->wdogcontrol);
151         writel(WDT_RESET_LOAD, &wdt_base->wdogload);
152         while (1)
153                 ;
154 }
155
156 /*
157  * Delay x useconds AND perserve advance timstamp value
158  *     assumes timer is ticking at 1 msec
159  */
160 void __udelay(ulong usec)
161 {
162         ulong tmo, tmp;
163
164         tmo = usec / 1000;
165         tmp = get_timer(0);     /* get current timestamp */
166
167         /*
168          * If setting this forward will roll time stamp then
169          * reset "advancing" timestamp to 0 and set lastdec value
170          * otherwise set the advancing stamp to the wake up time
171          */
172         if ((tmo + tmp + 1) < tmp)
173                 reset_timer_masked();
174         else
175                 tmo += tmp;
176
177         while (get_timer_masked() < tmo)
178                 ; /* loop till wakeup event */
179 }
180
181 ulong get_timer(ulong base)
182 {
183         return get_timer_masked() - base;
184 }
185
186 void reset_timer_masked(void)
187 {
188         lastdec = readl(&systimer_base->timer0value) / 1000;
189         timestamp = 0;
190 }
191
192 void reset_timer(void)
193 {
194         reset_timer_masked();
195 }
196
197 ulong get_timer_masked(void)
198 {
199         ulong now = readl(&systimer_base->timer0value) / 1000;
200
201         if (lastdec >= now) {   /* normal mode (non roll) */
202                 timestamp += lastdec - now;
203         } else {                /* count down timer overflowed */
204                 /*
205                  * nts = ts + ld - now
206                  * ts = old stamp, ld = time before passing through - 1
207                  * now = amount of time after passing though - 1
208                  * nts = new "advancing time stamp"
209                  */
210                 timestamp += lastdec + SYSTIMER_RELOAD - now;
211         }
212         lastdec = now;
213
214         return timestamp;
215 }
216
217 void lowlevel_init(void)
218 {
219 }
220
221 ulong get_board_rev(void){
222         return readl((u32 *)SYS_ID);
223 }