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 int cpu_mmc_init(bd_t *bis)
92 #ifdef CONFIG_ARM_PL180_MMCI
93 rc = arm_pl180_mmci_init();
98 static void flash__init(void)
100 /* Setup the sytem control register to allow writing to flash */
101 writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
102 &sysctrl_base->scflashctrl);
108 get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
112 void dram_init_banksize(void)
114 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
115 gd->bd->bi_dram[0].size =
116 get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
117 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
118 gd->bd->bi_dram[1].size =
119 get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
129 * Setup a 32 bit timer, running at 1KHz
130 * Versatile Express Motherboard provides 1 MHz timer
132 static void vexpress_timer_init(void)
135 * Set clock frequency in system controller:
136 * VEXPRESS_REFCLK is 32KHz
137 * VEXPRESS_TIMCLK is 1MHz
139 writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
140 SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
141 readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
145 * Enabled, free running, no interrupt, 32-bit, wrapping
147 writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
148 writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
149 writel(SYSTIMER_EN | SYSTIMER_32BIT | \
150 readl(&systimer_base->timer0control), \
151 &systimer_base->timer0control);
153 reset_timer_masked();
156 /* Use the ARM Watchdog System to cause reset */
157 void reset_cpu(ulong addr)
159 writeb(WDT_EN, &wdt_base->wdogcontrol);
160 writel(WDT_RESET_LOAD, &wdt_base->wdogload);
166 * Delay x useconds AND perserve advance timstamp value
167 * assumes timer is ticking at 1 msec
169 void __udelay(ulong usec)
174 tmp = get_timer(0); /* get current timestamp */
177 * If setting this forward will roll time stamp then
178 * reset "advancing" timestamp to 0 and set lastdec value
179 * otherwise set the advancing stamp to the wake up time
181 if ((tmo + tmp + 1) < tmp)
182 reset_timer_masked();
186 while (get_timer_masked() < tmo)
187 ; /* loop till wakeup event */
190 ulong get_timer(ulong base)
192 return get_timer_masked() - base;
195 void reset_timer_masked(void)
197 lastdec = readl(&systimer_base->timer0value) / 1000;
201 void reset_timer(void)
203 reset_timer_masked();
206 ulong get_timer_masked(void)
208 ulong now = readl(&systimer_base->timer0value) / 1000;
210 if (lastdec >= now) { /* normal mode (non roll) */
211 timestamp += lastdec - now;
212 } else { /* count down timer overflowed */
214 * nts = ts + ld - now
215 * ts = old stamp, ld = time before passing through - 1
216 * now = amount of time after passing though - 1
217 * nts = new "advancing time stamp"
219 timestamp += lastdec + SYSTIMER_RELOAD - now;
226 void lowlevel_init(void)
230 ulong get_board_rev(void){
231 return readl((u32 *)SYS_ID);