3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
7 * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
10 * Texas Instruments, <www.ti.com>
11 * Kshitij Gupta <Kshitij@ti.com>
15 * Philippe Robin, <philippe.robin@arm.com>
17 * See file CREDITS for list of people who contributed to this
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.
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.
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,
38 #include <asm/arch/systimer.h>
39 #include <asm/arch/sysctrl.h>
40 #include <asm/arch/wdt.h>
42 static ulong timestamp;
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;
49 static void flash__init(void);
50 static void vexpress_timer_init(void);
51 DECLARE_GLOBAL_DATA_PTR;
53 #if defined(CONFIG_SHOW_BOOT_PROGRESS)
54 void show_boot_progress(int progress)
56 printf("Boot reached stage %d\n", progress);
60 static inline void delay(ulong loops)
62 __asm__ volatile ("1:\n"
64 "bne 1b" : "=r" (loops) : "0" (loops));
69 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
70 gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
75 vexpress_timer_init();
80 int board_eth_init(bd_t *bis)
84 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
89 static void flash__init(void)
91 /* Setup the sytem control register to allow writing to flash */
92 writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
93 &sysctrl_base->scflashctrl);
98 gd->ram_size = get_ram_size(CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
102 void dram_init_banksize(void)
104 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
105 gd->bd->bi_dram[0].size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
106 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
107 gd->bd->bi_dram[1].size = get_ram_size(PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
117 * Setup a 32 bit timer, running at 1KHz
118 * Versatile Express Motherboard provides 1 MHz timer
120 static void vexpress_timer_init(void)
123 * Set clock frequency in system controller:
124 * VEXPRESS_REFCLK is 32KHz
125 * VEXPRESS_TIMCLK is 1MHz
127 writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
128 SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
129 readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
133 * Enabled, free running, no interrupt, 32-bit, wrapping
135 writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
136 writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
137 writel(SYSTIMER_EN | SYSTIMER_32BIT | \
138 readl(&systimer_base->timer0control), \
139 &systimer_base->timer0control);
141 reset_timer_masked();
144 /* Use the ARM Watchdog System to cause reset */
145 void reset_cpu(ulong addr)
147 writeb(WDT_EN, &wdt_base->wdogcontrol);
148 writel(WDT_RESET_LOAD, &wdt_base->wdogload);
154 * Delay x useconds AND perserve advance timstamp value
155 * assumes timer is ticking at 1 msec
157 void udelay(ulong usec)
162 tmp = get_timer(0); /* get current timestamp */
165 * If setting this forward will roll time stamp then
166 * reset "advancing" timestamp to 0 and set lastdec value
167 * otherwise set the advancing stamp to the wake up time
169 if ((tmo + tmp + 1) < tmp)
170 reset_timer_masked();
174 while (get_timer_masked() < tmo)
175 ; /* loop till wakeup event */
178 ulong get_timer(ulong base)
180 return get_timer_masked() - base;
183 void reset_timer_masked(void)
185 lastdec = readl(&systimer_base->timer0value) / 1000;
189 void reset_timer(void)
191 reset_timer_masked();
194 ulong get_timer_masked(void)
196 ulong now = readl(&systimer_base->timer0value) / 1000;
198 if (lastdec >= now) { /* normal mode (non roll) */
199 timestamp += lastdec - now;
200 } else { /* count down timer overflowed */
202 * nts = ts + ld - now
203 * ts = old stamp, ld = time before passing through - 1
204 * now = amount of time after passing though - 1
205 * nts = new "advancing time stamp"
207 timestamp += lastdec + SYSTIMER_RELOAD - now;
214 void lowlevel_init(void)
218 ulong get_board_rev(void){
219 return readl((u32 *)SYS_ID);