blob: 8fea8ff35294cab8d3bc4fe9b6263feb432a6df1 [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 Glass1ea97892020-05-10 11:40:00 -060019#include <bootstage.h>
Simon Glass370382c2019-11-14 12:57:35 -070020#include <cpu_func.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070021#include <init.h>
John Rigby03f609b2012-07-31 08:59:31 +000022#include <malloc.h>
23#include <errno.h>
Simon Glass274e0b02020-05-10 11:39:56 -060024#include <net.h>
Matt Waddel35c638b2010-10-07 15:48:45 -060025#include <netdev.h>
26#include <asm/io.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060027#include <asm/mach-types.h>
Matt Waddel35c638b2010-10-07 15:48:45 -060028#include <asm/arch/systimer.h>
29#include <asm/arch/sysctrl.h>
30#include <asm/arch/wdt.h>
Dirk Behme89f4f0d2011-05-23 07:40:26 +000031#include "../drivers/mmc/arm_pl180_mmci.h"
Matt Waddel35c638b2010-10-07 15:48:45 -060032
Ryan Harkin0e5827f2013-04-09 02:20:31 +000033static struct systimer *systimer_base = (struct systimer *)V2M_TIMER01;
Matt Waddel35c638b2010-10-07 15:48:45 -060034static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
35
36static void flash__init(void);
37static void vexpress_timer_init(void);
38DECLARE_GLOBAL_DATA_PTR;
39
40#if defined(CONFIG_SHOW_BOOT_PROGRESS)
41void show_boot_progress(int progress)
42{
43 printf("Boot reached stage %d\n", progress);
44}
45#endif
46
47static inline void delay(ulong loops)
48{
49 __asm__ volatile ("1:\n"
50 "subs %0, %1, #1\n"
51 "bne 1b" : "=r" (loops) : "0" (loops));
52}
53
54int board_init(void)
55{
56 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
57 gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
Matt Waddel35c638b2010-10-07 15:48:45 -060058
59 icache_enable();
60 flash__init();
61 vexpress_timer_init();
62
63 return 0;
64}
65
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090066int board_eth_init(struct bd_info *bis)
Matt Waddel35c638b2010-10-07 15:48:45 -060067{
68 int rc = 0;
69#ifdef CONFIG_SMC911X
70 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
71#endif
72 return rc;
73}
74
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090075int cpu_mmc_init(struct bd_info *bis)
Matt Waddelc5a6a402011-04-16 11:54:08 +000076{
77 int rc = 0;
John Rigby03f609b2012-07-31 08:59:31 +000078 (void) bis;
Matt Waddelc5a6a402011-04-16 11:54:08 +000079#ifdef CONFIG_ARM_PL180_MMCI
John Rigby03f609b2012-07-31 08:59:31 +000080 struct pl180_mmc_host *host;
Patrice Chotard2a392fe2017-10-23 10:57:30 +020081 struct mmc *mmc;
John Rigby03f609b2012-07-31 08:59:31 +000082
83 host = malloc(sizeof(struct pl180_mmc_host));
84 if (!host)
85 return -ENOMEM;
86 memset(host, 0, sizeof(*host));
87
88 strcpy(host->name, "MMC");
89 host->base = (struct sdi_registers *)CONFIG_ARM_PL180_MMCI_BASE;
90 host->pwr_init = INIT_PWR;
91 host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V1 | SDI_CLKCR_CLKEN;
92 host->voltages = VOLTAGE_WINDOW_MMC;
93 host->caps = 0;
94 host->clock_in = ARM_MCLK;
95 host->clock_min = ARM_MCLK / (2 * (SDI_CLKCR_CLKDIV_INIT_V1 + 1));
96 host->clock_max = CONFIG_ARM_PL180_MMCI_CLOCK_FREQ;
Patrice Chotard2a392fe2017-10-23 10:57:30 +020097 rc = arm_pl180_mmci_init(host, &mmc);
Matt Waddelc5a6a402011-04-16 11:54:08 +000098#endif
99 return rc;
100}
101
Matt Waddel35c638b2010-10-07 15:48:45 -0600102static void flash__init(void)
103{
104 /* Setup the sytem control register to allow writing to flash */
105 writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
106 &sysctrl_base->scflashctrl);
107}
108
109int dram_init(void)
110{
Matt Waddela1d3bc42010-11-02 17:25:21 -0600111 gd->ram_size =
112 get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
Matt Waddel35c638b2010-10-07 15:48:45 -0600113 return 0;
114}
115
Simon Glass2f949c32017-03-31 08:40:32 -0600116int dram_init_banksize(void)
Matt Waddel35c638b2010-10-07 15:48:45 -0600117{
118 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
Matt Waddela1d3bc42010-11-02 17:25:21 -0600119 gd->bd->bi_dram[0].size =
120 get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
Matt Waddel35c638b2010-10-07 15:48:45 -0600121 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
Matt Waddela1d3bc42010-11-02 17:25:21 -0600122 gd->bd->bi_dram[1].size =
123 get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
Simon Glass2f949c32017-03-31 08:40:32 -0600124
125 return 0;
Matt Waddel35c638b2010-10-07 15:48:45 -0600126}
127
Matt Waddel35c638b2010-10-07 15:48:45 -0600128/*
129 * Start timer:
130 * Setup a 32 bit timer, running at 1KHz
131 * Versatile Express Motherboard provides 1 MHz timer
132 */
133static void vexpress_timer_init(void)
134{
135 /*
136 * Set clock frequency in system controller:
137 * VEXPRESS_REFCLK is 32KHz
138 * VEXPRESS_TIMCLK is 1MHz
139 */
140 writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
141 SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
142 readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
143
144 /*
145 * Set Timer0 to be:
146 * Enabled, free running, no interrupt, 32-bit, wrapping
147 */
148 writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
149 writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
Ryan Harkinf9f84812013-04-09 02:20:30 +0000150 writel(SYSTIMER_EN | SYSTIMER_32BIT |
151 readl(&systimer_base->timer0control),
Matt Waddel35c638b2010-10-07 15:48:45 -0600152 &systimer_base->timer0control);
Matt Waddel35c638b2010-10-07 15:48:45 -0600153}
154
Ryan Harkin0e5827f2013-04-09 02:20:31 +0000155int v2m_cfg_write(u32 devfn, u32 data)
156{
157 /* Configuration interface broken? */
158 u32 val;
159
160 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
161
162 val = readl(V2M_SYS_CFGSTAT);
163 writel(val & ~SYS_CFG_COMPLETE, V2M_SYS_CFGSTAT);
164
165 writel(data, V2M_SYS_CFGDATA);
166 writel(devfn, V2M_SYS_CFGCTRL);
167
168 do {
169 val = readl(V2M_SYS_CFGSTAT);
170 } while (val == 0);
171
172 return !!(val & SYS_CFG_ERR);
173}
174
Matt Waddel35c638b2010-10-07 15:48:45 -0600175/* Use the ARM Watchdog System to cause reset */
176void reset_cpu(ulong addr)
177{
Ryan Harkin0e5827f2013-04-09 02:20:31 +0000178 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
179 printf("Unable to reboot\n");
Matt Waddel35c638b2010-10-07 15:48:45 -0600180}
181
Matt Waddel35c638b2010-10-07 15:48:45 -0600182void lowlevel_init(void)
183{
184}
185
186ulong get_board_rev(void){
187 return readl((u32 *)SYS_ID);
188}
Liming Wang1acfeac2012-02-22 04:56:31 +0000189
Jan Kiszkaac31b5a2015-04-21 07:18:24 +0200190#ifdef CONFIG_ARMV7_NONSEC
Andre Przywara55b19aa2013-09-19 18:06:46 +0200191/* Setting the address at which secondary cores start from.
192 * Versatile Express uses one address for all cores, so ignore corenr
193 */
194void smp_set_core_boot_addr(unsigned long addr, int corenr)
195{
196 /* The SYSFLAGS register on VExpress needs to be cleared first
197 * by writing to the next address, since any writes to the address
198 * at offset 0 will only be ORed in
199 */
200 writel(~0, CONFIG_SYSFLAGS_ADDR + 4);
201 writel(addr, CONFIG_SYSFLAGS_ADDR);
202}
203#endif