3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
10 * Texas Instruments, <www.ti.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,
40 #include <asm/arch/systimer.h>
41 #include <asm/arch/sysctrl.h>
42 #include <asm/arch/wdt.h>
43 #include "../drivers/mmc/arm_pl180_mmci.h"
45 static ulong timestamp;
48 static struct wdt *wdt_base = (struct wdt *)WDT_BASE;
49 static struct systimer *systimer_base = (struct systimer *)SYSTIMER_BASE;
50 static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
52 static void flash__init(void);
53 static void vexpress_timer_init(void);
54 DECLARE_GLOBAL_DATA_PTR;
56 #if defined(CONFIG_SHOW_BOOT_PROGRESS)
57 void show_boot_progress(int progress)
59 printf("Boot reached stage %d\n", progress);
63 static inline void delay(ulong loops)
65 __asm__ volatile ("1:\n"
67 "bne 1b" : "=r" (loops) : "0" (loops));
72 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
73 gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
78 vexpress_timer_init();
83 int board_eth_init(bd_t *bis)
87 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
92 int cpu_mmc_init(bd_t *bis)
96 #ifdef CONFIG_ARM_PL180_MMCI
97 struct pl180_mmc_host *host;
99 host = malloc(sizeof(struct pl180_mmc_host));
102 memset(host, 0, sizeof(*host));
104 strcpy(host->name, "MMC");
105 host->base = (struct sdi_registers *)CONFIG_ARM_PL180_MMCI_BASE;
106 host->pwr_init = INIT_PWR;
107 host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V1 | SDI_CLKCR_CLKEN;
108 host->voltages = VOLTAGE_WINDOW_MMC;
110 host->clock_in = ARM_MCLK;
111 host->clock_min = ARM_MCLK / (2 * (SDI_CLKCR_CLKDIV_INIT_V1 + 1));
112 host->clock_max = CONFIG_ARM_PL180_MMCI_CLOCK_FREQ;
113 rc = arm_pl180_mmci_init(host);
118 static void flash__init(void)
120 /* Setup the sytem control register to allow writing to flash */
121 writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
122 &sysctrl_base->scflashctrl);
128 get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
132 void dram_init_banksize(void)
134 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
135 gd->bd->bi_dram[0].size =
136 get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
137 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
138 gd->bd->bi_dram[1].size =
139 get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
149 * Setup a 32 bit timer, running at 1KHz
150 * Versatile Express Motherboard provides 1 MHz timer
152 static void vexpress_timer_init(void)
155 * Set clock frequency in system controller:
156 * VEXPRESS_REFCLK is 32KHz
157 * VEXPRESS_TIMCLK is 1MHz
159 writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
160 SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
161 readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
165 * Enabled, free running, no interrupt, 32-bit, wrapping
167 writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
168 writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
169 writel(SYSTIMER_EN | SYSTIMER_32BIT | \
170 readl(&systimer_base->timer0control), \
171 &systimer_base->timer0control);
173 reset_timer_masked();
176 /* Use the ARM Watchdog System to cause reset */
177 void reset_cpu(ulong addr)
179 writeb(WDT_EN, &wdt_base->wdogcontrol);
180 writel(WDT_RESET_LOAD, &wdt_base->wdogload);
186 * Delay x useconds AND perserve advance timstamp value
187 * assumes timer is ticking at 1 msec
189 void __udelay(ulong usec)
194 tmp = get_timer(0); /* get current timestamp */
197 * If setting this forward will roll time stamp then
198 * reset "advancing" timestamp to 0 and set lastdec value
199 * otherwise set the advancing stamp to the wake up time
201 if ((tmo + tmp + 1) < tmp)
202 reset_timer_masked();
206 while (get_timer_masked() < tmo)
207 ; /* loop till wakeup event */
210 ulong get_timer(ulong base)
212 return get_timer_masked() - base;
215 void reset_timer_masked(void)
217 lastdec = readl(&systimer_base->timer0value) / 1000;
221 ulong get_timer_masked(void)
223 ulong now = readl(&systimer_base->timer0value) / 1000;
225 if (lastdec >= now) { /* normal mode (non roll) */
226 timestamp += lastdec - now;
227 } else { /* count down timer overflowed */
229 * nts = ts + ld - now
230 * ts = old stamp, ld = time before passing through - 1
231 * now = amount of time after passing though - 1
232 * nts = new "advancing time stamp"
234 timestamp += lastdec + SYSTIMER_RELOAD - now;
241 void lowlevel_init(void)
245 ulong get_board_rev(void){
246 return readl((u32 *)SYS_ID);
249 unsigned long long get_ticks(void)
254 ulong get_tbclk (void)
256 return (ulong)CONFIG_SYS_HZ;