blob: 4c7a7f46d59b0adcd38801e1baebc20bb8f3d8af [file] [log] [blame]
Matt Waddelb80e41a2010-10-07 15:48:45 -06001/*
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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020017 * SPDX-License-Identifier: GPL-2.0+
Matt Waddelb80e41a2010-10-07 15:48:45 -060018 */
19#include <common.h>
John Rigby10ed93d2012-07-31 08:59:31 +000020#include <malloc.h>
21#include <errno.h>
Matt Waddelb80e41a2010-10-07 15:48:45 -060022#include <netdev.h>
23#include <asm/io.h>
24#include <asm/arch/systimer.h>
25#include <asm/arch/sysctrl.h>
26#include <asm/arch/wdt.h>
Dirk Behmea6f479c2011-05-23 07:40:26 +000027#include "../drivers/mmc/arm_pl180_mmci.h"
Matt Waddelb80e41a2010-10-07 15:48:45 -060028
29static ulong timestamp;
30static ulong lastdec;
31
Ryan Harkincd4f46e2013-04-09 02:20:31 +000032static struct systimer *systimer_base = (struct systimer *)V2M_TIMER01;
Matt Waddelb80e41a2010-10-07 15:48:45 -060033static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
34
35static void flash__init(void);
36static void vexpress_timer_init(void);
37DECLARE_GLOBAL_DATA_PTR;
38
39#if defined(CONFIG_SHOW_BOOT_PROGRESS)
40void show_boot_progress(int progress)
41{
42 printf("Boot reached stage %d\n", progress);
43}
44#endif
45
46static inline void delay(ulong loops)
47{
48 __asm__ volatile ("1:\n"
49 "subs %0, %1, #1\n"
50 "bne 1b" : "=r" (loops) : "0" (loops));
51}
52
53int board_init(void)
54{
55 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
56 gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
57 gd->flags = 0;
58
59 icache_enable();
60 flash__init();
61 vexpress_timer_init();
62
63 return 0;
64}
65
66int board_eth_init(bd_t *bis)
67{
68 int rc = 0;
69#ifdef CONFIG_SMC911X
70 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
71#endif
72 return rc;
73}
74
Matt Waddelf0c64522011-04-16 11:54:08 +000075int cpu_mmc_init(bd_t *bis)
76{
77 int rc = 0;
John Rigby10ed93d2012-07-31 08:59:31 +000078 (void) bis;
Matt Waddelf0c64522011-04-16 11:54:08 +000079#ifdef CONFIG_ARM_PL180_MMCI
John Rigby10ed93d2012-07-31 08:59:31 +000080 struct pl180_mmc_host *host;
81
82 host = malloc(sizeof(struct pl180_mmc_host));
83 if (!host)
84 return -ENOMEM;
85 memset(host, 0, sizeof(*host));
86
87 strcpy(host->name, "MMC");
88 host->base = (struct sdi_registers *)CONFIG_ARM_PL180_MMCI_BASE;
89 host->pwr_init = INIT_PWR;
90 host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V1 | SDI_CLKCR_CLKEN;
91 host->voltages = VOLTAGE_WINDOW_MMC;
92 host->caps = 0;
93 host->clock_in = ARM_MCLK;
94 host->clock_min = ARM_MCLK / (2 * (SDI_CLKCR_CLKDIV_INIT_V1 + 1));
95 host->clock_max = CONFIG_ARM_PL180_MMCI_CLOCK_FREQ;
96 rc = arm_pl180_mmci_init(host);
Matt Waddelf0c64522011-04-16 11:54:08 +000097#endif
98 return rc;
99}
100
Matt Waddelb80e41a2010-10-07 15:48:45 -0600101static void flash__init(void)
102{
103 /* Setup the sytem control register to allow writing to flash */
104 writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
105 &sysctrl_base->scflashctrl);
106}
107
108int dram_init(void)
109{
Matt Waddel9d37cf32010-11-02 17:25:21 -0600110 gd->ram_size =
111 get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
Matt Waddelb80e41a2010-10-07 15:48:45 -0600112 return 0;
113}
114
115void dram_init_banksize(void)
116{
117 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
Matt Waddel9d37cf32010-11-02 17:25:21 -0600118 gd->bd->bi_dram[0].size =
119 get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
Matt Waddelb80e41a2010-10-07 15:48:45 -0600120 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
Matt Waddel9d37cf32010-11-02 17:25:21 -0600121 gd->bd->bi_dram[1].size =
122 get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
Matt Waddelb80e41a2010-10-07 15:48:45 -0600123}
124
125int timer_init(void)
126{
127 return 0;
128}
129
130/*
131 * Start timer:
132 * Setup a 32 bit timer, running at 1KHz
133 * Versatile Express Motherboard provides 1 MHz timer
134 */
135static void vexpress_timer_init(void)
136{
137 /*
138 * Set clock frequency in system controller:
139 * VEXPRESS_REFCLK is 32KHz
140 * VEXPRESS_TIMCLK is 1MHz
141 */
142 writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
143 SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
144 readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
145
146 /*
147 * Set Timer0 to be:
148 * Enabled, free running, no interrupt, 32-bit, wrapping
149 */
150 writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
151 writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
Ryan Harkin9b58a3f2013-04-09 02:20:30 +0000152 writel(SYSTIMER_EN | SYSTIMER_32BIT |
153 readl(&systimer_base->timer0control),
Matt Waddelb80e41a2010-10-07 15:48:45 -0600154 &systimer_base->timer0control);
155
156 reset_timer_masked();
157}
158
Ryan Harkincd4f46e2013-04-09 02:20:31 +0000159int v2m_cfg_write(u32 devfn, u32 data)
160{
161 /* Configuration interface broken? */
162 u32 val;
163
164 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
165
166 val = readl(V2M_SYS_CFGSTAT);
167 writel(val & ~SYS_CFG_COMPLETE, V2M_SYS_CFGSTAT);
168
169 writel(data, V2M_SYS_CFGDATA);
170 writel(devfn, V2M_SYS_CFGCTRL);
171
172 do {
173 val = readl(V2M_SYS_CFGSTAT);
174 } while (val == 0);
175
176 return !!(val & SYS_CFG_ERR);
177}
178
Matt Waddelb80e41a2010-10-07 15:48:45 -0600179/* Use the ARM Watchdog System to cause reset */
180void reset_cpu(ulong addr)
181{
Ryan Harkincd4f46e2013-04-09 02:20:31 +0000182 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
183 printf("Unable to reboot\n");
Matt Waddelb80e41a2010-10-07 15:48:45 -0600184}
185
186/*
187 * Delay x useconds AND perserve advance timstamp value
188 * assumes timer is ticking at 1 msec
189 */
Dirk Behme44b0a382010-11-29 19:56:59 +0100190void __udelay(ulong usec)
Matt Waddelb80e41a2010-10-07 15:48:45 -0600191{
192 ulong tmo, tmp;
193
194 tmo = usec / 1000;
195 tmp = get_timer(0); /* get current timestamp */
196
197 /*
198 * If setting this forward will roll time stamp then
199 * reset "advancing" timestamp to 0 and set lastdec value
200 * otherwise set the advancing stamp to the wake up time
201 */
202 if ((tmo + tmp + 1) < tmp)
203 reset_timer_masked();
204 else
205 tmo += tmp;
206
207 while (get_timer_masked() < tmo)
208 ; /* loop till wakeup event */
209}
210
211ulong get_timer(ulong base)
212{
213 return get_timer_masked() - base;
214}
215
216void reset_timer_masked(void)
217{
218 lastdec = readl(&systimer_base->timer0value) / 1000;
219 timestamp = 0;
220}
221
Matt Waddelb80e41a2010-10-07 15:48:45 -0600222ulong get_timer_masked(void)
223{
224 ulong now = readl(&systimer_base->timer0value) / 1000;
225
226 if (lastdec >= now) { /* normal mode (non roll) */
227 timestamp += lastdec - now;
228 } else { /* count down timer overflowed */
229 /*
230 * nts = ts + ld - now
231 * ts = old stamp, ld = time before passing through - 1
232 * now = amount of time after passing though - 1
233 * nts = new "advancing time stamp"
234 */
235 timestamp += lastdec + SYSTIMER_RELOAD - now;
236 }
237 lastdec = now;
238
239 return timestamp;
240}
241
242void lowlevel_init(void)
243{
244}
245
246ulong get_board_rev(void){
247 return readl((u32 *)SYS_ID);
248}
Liming Wangd721a3a2012-02-22 04:56:31 +0000249
250unsigned long long get_ticks(void)
251{
252 return get_timer(0);
253}
254
Ryan Harkin9b58a3f2013-04-09 02:20:30 +0000255ulong get_tbclk(void)
Liming Wangd721a3a2012-02-22 04:56:31 +0000256{
257 return (ulong)CONFIG_SYS_HZ;
258}