blob: 14626c1f553eeee9365053fecf73e0509c9ecb49 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Matt Waddel35c638b2010-10-07 15:48:45 -06002/*
3 * (C) Copyright 2002
4 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
5 * Marius Groeger <mgroeger@sysgo.de>
6 *
7 * (C) Copyright 2002
8 * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
9 *
10 * (C) Copyright 2003
11 * Texas Instruments, <www.ti.com>
12 * Kshitij Gupta <Kshitij@ti.com>
13 *
14 * (C) Copyright 2004
15 * ARM Ltd.
16 * Philippe Robin, <philippe.robin@arm.com>
Matt Waddel35c638b2010-10-07 15:48:45 -060017 */
18#include <common.h>
Simon Glass370382c2019-11-14 12:57:35 -070019#include <cpu_func.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070020#include <init.h>
John Rigby03f609b2012-07-31 08:59:31 +000021#include <malloc.h>
22#include <errno.h>
Matt Waddel35c638b2010-10-07 15:48:45 -060023#include <netdev.h>
24#include <asm/io.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060025#include <asm/mach-types.h>
Matt Waddel35c638b2010-10-07 15:48:45 -060026#include <asm/arch/systimer.h>
27#include <asm/arch/sysctrl.h>
28#include <asm/arch/wdt.h>
Dirk Behme89f4f0d2011-05-23 07:40:26 +000029#include "../drivers/mmc/arm_pl180_mmci.h"
Matt Waddel35c638b2010-10-07 15:48:45 -060030
Ryan Harkin0e5827f2013-04-09 02:20:31 +000031static struct systimer *systimer_base = (struct systimer *)V2M_TIMER01;
Matt Waddel35c638b2010-10-07 15:48:45 -060032static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
33
34static void flash__init(void);
35static void vexpress_timer_init(void);
36DECLARE_GLOBAL_DATA_PTR;
37
38#if defined(CONFIG_SHOW_BOOT_PROGRESS)
39void show_boot_progress(int progress)
40{
41 printf("Boot reached stage %d\n", progress);
42}
43#endif
44
45static inline void delay(ulong loops)
46{
47 __asm__ volatile ("1:\n"
48 "subs %0, %1, #1\n"
49 "bne 1b" : "=r" (loops) : "0" (loops));
50}
51
52int board_init(void)
53{
54 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
55 gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
56 gd->flags = 0;
57
58 icache_enable();
59 flash__init();
60 vexpress_timer_init();
61
62 return 0;
63}
64
65int board_eth_init(bd_t *bis)
66{
67 int rc = 0;
68#ifdef CONFIG_SMC911X
69 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
70#endif
71 return rc;
72}
73
Matt Waddelc5a6a402011-04-16 11:54:08 +000074int cpu_mmc_init(bd_t *bis)
75{
76 int rc = 0;
John Rigby03f609b2012-07-31 08:59:31 +000077 (void) bis;
Matt Waddelc5a6a402011-04-16 11:54:08 +000078#ifdef CONFIG_ARM_PL180_MMCI
John Rigby03f609b2012-07-31 08:59:31 +000079 struct pl180_mmc_host *host;
Patrice Chotard2a392fe2017-10-23 10:57:30 +020080 struct mmc *mmc;
John Rigby03f609b2012-07-31 08:59:31 +000081
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;
Patrice Chotard2a392fe2017-10-23 10:57:30 +020096 rc = arm_pl180_mmci_init(host, &mmc);
Matt Waddelc5a6a402011-04-16 11:54:08 +000097#endif
98 return rc;
99}
100
Matt Waddel35c638b2010-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 Waddela1d3bc42010-11-02 17:25:21 -0600110 gd->ram_size =
111 get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
Matt Waddel35c638b2010-10-07 15:48:45 -0600112 return 0;
113}
114
Simon Glass2f949c32017-03-31 08:40:32 -0600115int dram_init_banksize(void)
Matt Waddel35c638b2010-10-07 15:48:45 -0600116{
117 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
Matt Waddela1d3bc42010-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 Waddel35c638b2010-10-07 15:48:45 -0600120 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
Matt Waddela1d3bc42010-11-02 17:25:21 -0600121 gd->bd->bi_dram[1].size =
122 get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
Simon Glass2f949c32017-03-31 08:40:32 -0600123
124 return 0;
Matt Waddel35c638b2010-10-07 15:48:45 -0600125}
126
Matt Waddel35c638b2010-10-07 15:48:45 -0600127/*
128 * Start timer:
129 * Setup a 32 bit timer, running at 1KHz
130 * Versatile Express Motherboard provides 1 MHz timer
131 */
132static void vexpress_timer_init(void)
133{
134 /*
135 * Set clock frequency in system controller:
136 * VEXPRESS_REFCLK is 32KHz
137 * VEXPRESS_TIMCLK is 1MHz
138 */
139 writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
140 SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
141 readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
142
143 /*
144 * Set Timer0 to be:
145 * Enabled, free running, no interrupt, 32-bit, wrapping
146 */
147 writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
148 writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
Ryan Harkinf9f84812013-04-09 02:20:30 +0000149 writel(SYSTIMER_EN | SYSTIMER_32BIT |
150 readl(&systimer_base->timer0control),
Matt Waddel35c638b2010-10-07 15:48:45 -0600151 &systimer_base->timer0control);
Matt Waddel35c638b2010-10-07 15:48:45 -0600152}
153
Ryan Harkin0e5827f2013-04-09 02:20:31 +0000154int v2m_cfg_write(u32 devfn, u32 data)
155{
156 /* Configuration interface broken? */
157 u32 val;
158
159 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
160
161 val = readl(V2M_SYS_CFGSTAT);
162 writel(val & ~SYS_CFG_COMPLETE, V2M_SYS_CFGSTAT);
163
164 writel(data, V2M_SYS_CFGDATA);
165 writel(devfn, V2M_SYS_CFGCTRL);
166
167 do {
168 val = readl(V2M_SYS_CFGSTAT);
169 } while (val == 0);
170
171 return !!(val & SYS_CFG_ERR);
172}
173
Matt Waddel35c638b2010-10-07 15:48:45 -0600174/* Use the ARM Watchdog System to cause reset */
175void reset_cpu(ulong addr)
176{
Ryan Harkin0e5827f2013-04-09 02:20:31 +0000177 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
178 printf("Unable to reboot\n");
Matt Waddel35c638b2010-10-07 15:48:45 -0600179}
180
Matt Waddel35c638b2010-10-07 15:48:45 -0600181void lowlevel_init(void)
182{
183}
184
185ulong get_board_rev(void){
186 return readl((u32 *)SYS_ID);
187}
Liming Wang1acfeac2012-02-22 04:56:31 +0000188
Jan Kiszkaac31b5a2015-04-21 07:18:24 +0200189#ifdef CONFIG_ARMV7_NONSEC
Andre Przywara55b19aa2013-09-19 18:06:46 +0200190/* Setting the address at which secondary cores start from.
191 * Versatile Express uses one address for all cores, so ignore corenr
192 */
193void smp_set_core_boot_addr(unsigned long addr, int corenr)
194{
195 /* The SYSFLAGS register on VExpress needs to be cleared first
196 * by writing to the next address, since any writes to the address
197 * at offset 0 will only be ORed in
198 */
199 writel(~0, CONFIG_SYSFLAGS_ADDR + 4);
200 writel(addr, CONFIG_SYSFLAGS_ADDR);
201}
202#endif