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>
41 #include "../drivers/mmc/arm_pl180_mmci.h"
43 static ulong timestamp
;
46 static struct wdt
*wdt_base
= (struct wdt
*)WDT_BASE
;
47 static struct systimer
*systimer_base
= (struct systimer
*)SYSTIMER_BASE
;
48 static struct sysctrl
*sysctrl_base
= (struct sysctrl
*)SCTL_BASE
;
50 static void flash__init(void);
51 static void vexpress_timer_init(void);
52 DECLARE_GLOBAL_DATA_PTR
;
54 #if defined(CONFIG_SHOW_BOOT_PROGRESS)
55 void show_boot_progress(int progress
)
57 printf("Boot reached stage %d\n", progress
);
61 static inline void delay(ulong loops
)
63 __asm__
volatile ("1:\n"
65 "bne 1b" : "=r" (loops
) : "0" (loops
));
70 gd
->bd
->bi_boot_params
= LINUX_BOOT_PARAM_ADDR
;
71 gd
->bd
->bi_arch_number
= MACH_TYPE_VEXPRESS
;
76 vexpress_timer_init();
81 int board_eth_init(bd_t
*bis
)
85 rc
= smc911x_initialize(0, CONFIG_SMC911X_BASE
);
90 int cpu_mmc_init(bd_t
*bis
)
93 #ifdef CONFIG_ARM_PL180_MMCI
94 rc
= arm_pl180_mmci_init();
99 static void flash__init(void)
101 /* Setup the sytem control register to allow writing to flash */
102 writel(readl(&sysctrl_base
->scflashctrl
) | VEXPRESS_FLASHPROG_FLVPPEN
,
103 &sysctrl_base
->scflashctrl
);
109 get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
, PHYS_SDRAM_1_SIZE
);
113 void dram_init_banksize(void)
115 gd
->bd
->bi_dram
[0].start
= PHYS_SDRAM_1
;
116 gd
->bd
->bi_dram
[0].size
=
117 get_ram_size((long *)PHYS_SDRAM_1
, PHYS_SDRAM_1_SIZE
);
118 gd
->bd
->bi_dram
[1].start
= PHYS_SDRAM_2
;
119 gd
->bd
->bi_dram
[1].size
=
120 get_ram_size((long *)PHYS_SDRAM_2
, PHYS_SDRAM_2_SIZE
);
130 * Setup a 32 bit timer, running at 1KHz
131 * Versatile Express Motherboard provides 1 MHz timer
133 static void vexpress_timer_init(void)
136 * Set clock frequency in system controller:
137 * VEXPRESS_REFCLK is 32KHz
138 * VEXPRESS_TIMCLK is 1MHz
140 writel(SP810_TIMER0_ENSEL
| SP810_TIMER1_ENSEL
|
141 SP810_TIMER2_ENSEL
| SP810_TIMER3_ENSEL
|
142 readl(&sysctrl_base
->scctrl
), &sysctrl_base
->scctrl
);
146 * Enabled, free running, no interrupt, 32-bit, wrapping
148 writel(SYSTIMER_RELOAD
, &systimer_base
->timer0load
);
149 writel(SYSTIMER_RELOAD
, &systimer_base
->timer0value
);
150 writel(SYSTIMER_EN
| SYSTIMER_32BIT
| \
151 readl(&systimer_base
->timer0control
), \
152 &systimer_base
->timer0control
);
154 reset_timer_masked();
157 /* Use the ARM Watchdog System to cause reset */
158 void reset_cpu(ulong addr
)
160 writeb(WDT_EN
, &wdt_base
->wdogcontrol
);
161 writel(WDT_RESET_LOAD
, &wdt_base
->wdogload
);
167 * Delay x useconds AND perserve advance timstamp value
168 * assumes timer is ticking at 1 msec
170 void __udelay(ulong usec
)
175 tmp
= get_timer(0); /* get current timestamp */
178 * If setting this forward will roll time stamp then
179 * reset "advancing" timestamp to 0 and set lastdec value
180 * otherwise set the advancing stamp to the wake up time
182 if ((tmo
+ tmp
+ 1) < tmp
)
183 reset_timer_masked();
187 while (get_timer_masked() < tmo
)
188 ; /* loop till wakeup event */
191 ulong
get_timer(ulong base
)
193 return get_timer_masked() - base
;
196 void reset_timer_masked(void)
198 lastdec
= readl(&systimer_base
->timer0value
) / 1000;
202 ulong
get_timer_masked(void)
204 ulong now
= readl(&systimer_base
->timer0value
) / 1000;
206 if (lastdec
>= now
) { /* normal mode (non roll) */
207 timestamp
+= lastdec
- now
;
208 } else { /* count down timer overflowed */
210 * nts = ts + ld - now
211 * ts = old stamp, ld = time before passing through - 1
212 * now = amount of time after passing though - 1
213 * nts = new "advancing time stamp"
215 timestamp
+= lastdec
+ SYSTIMER_RELOAD
- now
;
222 void lowlevel_init(void)
226 ulong
get_board_rev(void){
227 return readl((u32
*)SYS_ID
);
230 unsigned long long get_ticks(void)
235 ulong
get_tbclk (void)
237 return (ulong
)CONFIG_SYS_HZ
;