1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <common.h>
36#include <malloc.h>
37#include <errno.h>
38#include <netdev.h>
39#include <asm/io.h>
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"
44
45static ulong timestamp;
46static ulong lastdec;
47
48static struct wdt *wdt_base = (struct wdt *)WDT_BASE;
49static struct systimer *systimer_base = (struct systimer *)SYSTIMER_BASE;
50static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
51
52static void flash__init(void);
53static void vexpress_timer_init(void);
54DECLARE_GLOBAL_DATA_PTR;
55
56#if defined(CONFIG_SHOW_BOOT_PROGRESS)
57void show_boot_progress(int progress)
58{
59 printf("Boot reached stage %d\n", progress);
60}
61#endif
62
63static inline void delay(ulong loops)
64{
65 __asm__ volatile ("1:\n"
66 "subs %0, %1, #1\n"
67 "bne 1b" : "=r" (loops) : "0" (loops));
68}
69
70int board_init(void)
71{
72 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
73 gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
74 gd->flags = 0;
75
76 icache_enable();
77 flash__init();
78 vexpress_timer_init();
79
80 return 0;
81}
82
83int board_eth_init(bd_t *bis)
84{
85 int rc = 0;
86#ifdef CONFIG_SMC911X
87 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
88#endif
89 return rc;
90}
91
92int cpu_mmc_init(bd_t *bis)
93{
94 int rc = 0;
95 (void) bis;
96#ifdef CONFIG_ARM_PL180_MMCI
97 struct pl180_mmc_host *host;
98
99 host = malloc(sizeof(struct pl180_mmc_host));
100 if (!host)
101 return -ENOMEM;
102 memset(host, 0, sizeof(*host));
103
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;
109 host->caps = 0;
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);
114#endif
115 return rc;
116}
117
118static void flash__init(void)
119{
120
121 writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
122 &sysctrl_base->scflashctrl);
123}
124
125int dram_init(void)
126{
127 gd->ram_size =
128 get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
129 return 0;
130}
131
132void dram_init_banksize(void)
133{
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);
140}
141
142int timer_init(void)
143{
144 return 0;
145}
146
147
148
149
150
151
152static void vexpress_timer_init(void)
153{
154
155
156
157
158
159 writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
160 SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
161 readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
162
163
164
165
166
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);
172
173 reset_timer_masked();
174}
175
176
177void reset_cpu(ulong addr)
178{
179 writeb(WDT_EN, &wdt_base->wdogcontrol);
180 writel(WDT_RESET_LOAD, &wdt_base->wdogload);
181 while (1)
182 ;
183}
184
185
186
187
188
189void __udelay(ulong usec)
190{
191 ulong tmo, tmp;
192
193 tmo = usec / 1000;
194 tmp = get_timer(0);
195
196
197
198
199
200
201 if ((tmo + tmp + 1) < tmp)
202 reset_timer_masked();
203 else
204 tmo += tmp;
205
206 while (get_timer_masked() < tmo)
207 ;
208}
209
210ulong get_timer(ulong base)
211{
212 return get_timer_masked() - base;
213}
214
215void reset_timer_masked(void)
216{
217 lastdec = readl(&systimer_base->timer0value) / 1000;
218 timestamp = 0;
219}
220
221ulong get_timer_masked(void)
222{
223 ulong now = readl(&systimer_base->timer0value) / 1000;
224
225 if (lastdec >= now) {
226 timestamp += lastdec - now;
227 } else {
228
229
230
231
232
233
234 timestamp += lastdec + SYSTIMER_RELOAD - now;
235 }
236 lastdec = now;
237
238 return timestamp;
239}
240
241void lowlevel_init(void)
242{
243}
244
245ulong get_board_rev(void){
246 return readl((u32 *)SYS_ID);
247}
248
249unsigned long long get_ticks(void)
250{
251 return get_timer(0);
252}
253
254ulong get_tbclk (void)
255{
256 return (ulong)CONFIG_SYS_HZ;
257}
258