blob: 709ebf3fb0854cc4fbdd35cba584a9903000dac6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
David Feng3b5458c2013-12-14 11:47:37 +08002/*
3 * (C) Copyright 2013
4 * David Feng <fenghua@phytium.com.cn>
5 * Sharma Bhupesh <bhupesh.sharma@freescale.com>
David Feng3b5458c2013-12-14 11:47:37 +08006 */
7#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07008#include <cpu_func.h>
Simon Glass11c89f32017-05-17 17:18:03 -06009#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
David Feng3b5458c2013-12-14 11:47:37 +080011#include <malloc.h>
12#include <errno.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
David Feng3b5458c2013-12-14 11:47:37 +080014#include <netdev.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
David Feng3b5458c2013-12-14 11:47:37 +080016#include <asm/io.h>
17#include <linux/compiler.h>
Andre Przywara87de4b72022-03-04 16:30:16 +000018#include <linux/sizes.h>
David Fengab33c2c2015-01-31 11:55:29 +080019#include <dm/platform_data/serial_pl01x.h>
Liviu Dudau8d1fdc32015-10-19 11:08:32 +010020#include "pcie.h"
Alexander Graf5889e392016-03-04 01:09:51 +010021#include <asm/armv8/mmu.h>
Peter Hoyes8194cda2021-11-11 09:26:03 +000022#ifdef CONFIG_VIRTIO_NET
23#include <virtio_types.h>
24#include <virtio.h>
25#endif
David Feng3b5458c2013-12-14 11:47:37 +080026
27DECLARE_GLOBAL_DATA_PTR;
28
Simon Glassb75b15b2020-12-03 16:55:23 -070029static const struct pl01x_serial_plat serial_plat = {
David Fengab33c2c2015-01-31 11:55:29 +080030 .base = V2M_UART0,
31 .type = TYPE_PL011,
Linus Walleij31e476e2015-04-14 10:01:35 +020032 .clock = CONFIG_PL011_CLOCK,
David Fengab33c2c2015-01-31 11:55:29 +080033};
34
Simon Glass1d8364a2020-12-28 20:34:54 -070035U_BOOT_DRVINFO(vexpress_serials) = {
David Fengab33c2c2015-01-31 11:55:29 +080036 .name = "serial_pl01x",
Simon Glassb75b15b2020-12-03 16:55:23 -070037 .plat = &serial_plat,
David Fengab33c2c2015-01-31 11:55:29 +080038};
39
Alexander Graf5889e392016-03-04 01:09:51 +010040static struct mm_region vexpress64_mem_map[] = {
41 {
Andre Przywara87de4b72022-03-04 16:30:16 +000042 .virt = V2M_PA_BASE,
43 .phys = V2M_PA_BASE,
44 .size = SZ_2G,
Alexander Graf5889e392016-03-04 01:09:51 +010045 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
46 PTE_BLOCK_NON_SHARE |
47 PTE_BLOCK_PXN | PTE_BLOCK_UXN
48 }, {
Andre Przywara87de4b72022-03-04 16:30:16 +000049 .virt = V2M_DRAM_BASE,
50 .phys = V2M_DRAM_BASE,
51 .size = SZ_2G,
52 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
53 PTE_BLOCK_INNER_SHARE
54 }, {
55 /*
56 * DRAM beyond 2 GiB is located high. Let's map just some
57 * of it, although U-Boot won't realistically use it, and
58 * the actual available amount might be smaller on the model.
59 */
60 .virt = 0x880000000UL, /* 32 + 2 GiB */
61 .phys = 0x880000000UL,
62 .size = 6UL * SZ_1G,
Alexander Graf5889e392016-03-04 01:09:51 +010063 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
64 PTE_BLOCK_INNER_SHARE
65 }, {
66 /* List terminator */
67 0,
68 }
69};
70
71struct mm_region *mem_map = vexpress64_mem_map;
72
Ryan Harkin8961d502015-11-18 10:39:06 +000073/* This function gets replaced by platforms supporting PCIe.
74 * The replacement function, eg. on Juno, initialises the PCIe bus.
75 */
76__weak void vexpress64_pcie_init(void)
77{
78}
79
David Feng3b5458c2013-12-14 11:47:37 +080080int board_init(void)
81{
Liviu Dudau8d1fdc32015-10-19 11:08:32 +010082 vexpress64_pcie_init();
Peter Hoyes8194cda2021-11-11 09:26:03 +000083#ifdef CONFIG_VIRTIO_NET
84 virtio_init();
85#endif
David Feng3b5458c2013-12-14 11:47:37 +080086 return 0;
87}
88
89int dram_init(void)
90{
Andre Przywara2b97f122022-03-04 16:30:17 +000091 return fdtdec_setup_mem_size_base();
David Feng3b5458c2013-12-14 11:47:37 +080092}
93
Simon Glass2f949c32017-03-31 08:40:32 -060094int dram_init_banksize(void)
Liviu Dudau086c9772015-10-19 11:08:31 +010095{
Andre Przywara2b97f122022-03-04 16:30:17 +000096 return fdtdec_setup_memory_banksize();
Liviu Dudau086c9772015-10-19 11:08:31 +010097}
98
Peter Hoyesbaf62cf2021-11-11 09:26:02 +000099/* Assigned in lowlevel_init.S
100 * Push the variable into the .data section so that it
101 * does not get cleared later.
102 */
103unsigned long __section(".data") prior_stage_fdt_address;
104
Andre Przywara94504f42020-04-27 19:18:01 +0100105#ifdef CONFIG_OF_BOARD
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000106
107#ifdef CONFIG_TARGET_VEXPRESS64_JUNO
Andre Przywara94504f42020-04-27 19:18:01 +0100108#define JUNO_FLASH_SEC_SIZE (256 * 1024)
109static phys_addr_t find_dtb_in_nor_flash(const char *partname)
110{
111 phys_addr_t sector = CONFIG_SYS_FLASH_BASE;
112 int i;
113
114 for (i = 0;
115 i < CONFIG_SYS_MAX_FLASH_SECT;
116 i++, sector += JUNO_FLASH_SEC_SIZE) {
117 int len = strlen(partname) + 1;
118 int offs;
119 phys_addr_t imginfo;
120 u32 reg;
121
122 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x04);
123 /* This makes up the string "HSLFTOOF" flash footer */
124 if (reg != 0x464F4F54U)
125 continue;
126 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x08);
127 if (reg != 0x464C5348U)
128 continue;
129
130 for (offs = 0; offs < 32; offs += 4, len -= 4) {
131 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x30 + offs);
132 if (strncmp(partname + offs, (char *)&reg,
133 len > 4 ? 4 : len))
134 break;
135
136 if (len > 4)
137 continue;
138
139 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x10);
140 imginfo = sector + JUNO_FLASH_SEC_SIZE - 0x30 - reg;
141 reg = readl(imginfo + 0x54);
142
143 return CONFIG_SYS_FLASH_BASE +
144 reg * JUNO_FLASH_SEC_SIZE;
145 }
146 }
147
148 printf("No DTB found\n");
149
150 return ~0;
151}
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000152#endif
Andre Przywara94504f42020-04-27 19:18:01 +0100153
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300154void *board_fdt_blob_setup(int *err)
Andre Przywara94504f42020-04-27 19:18:01 +0100155{
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000156#ifdef CONFIG_TARGET_VEXPRESS64_JUNO
Andre Przywara94504f42020-04-27 19:18:01 +0100157 phys_addr_t fdt_rom_addr = find_dtb_in_nor_flash(CONFIG_JUNO_DTB_PART);
158
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300159 *err = 0;
160 if (fdt_rom_addr == ~0UL) {
161 *err = -ENXIO;
Andre Przywara94504f42020-04-27 19:18:01 +0100162 return NULL;
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300163 }
Andre Przywara94504f42020-04-27 19:18:01 +0100164
165 return (void *)fdt_rom_addr;
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000166#endif
167
168#ifdef VEXPRESS_FDT_ADDR
169 if (fdt_magic(VEXPRESS_FDT_ADDR) == FDT_MAGIC) {
170 *err = 0;
171 return (void *)VEXPRESS_FDT_ADDR;
172 }
173#endif
174
Andre Przywara395e9a92022-03-04 16:30:11 +0000175 if (fdt_magic(prior_stage_fdt_address) == FDT_MAGIC &&
176 fdt_totalsize(prior_stage_fdt_address) > 0x100) {
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000177 *err = 0;
178 return (void *)prior_stage_fdt_address;
179 }
180
Andre Przywara395e9a92022-03-04 16:30:11 +0000181 if (fdt_magic(gd->fdt_blob) == FDT_MAGIC) {
182 *err = 0;
183 return (void *)gd->fdt_blob;
184 }
185
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000186 *err = -ENXIO;
187 return NULL;
Andre Przywara94504f42020-04-27 19:18:01 +0100188}
189#endif
190
Andre Przywara651c91b2020-04-27 19:18:02 +0100191/* Actual reset is done via PSCI. */
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100192void reset_cpu(void)
David Feng3b5458c2013-12-14 11:47:37 +0800193{
Darwin Rambod32d4112014-06-09 11:12:59 -0700194}
195
David Feng3b5458c2013-12-14 11:47:37 +0800196/*
197 * Board specific ethernet initialization routine.
198 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900199int board_eth_init(struct bd_info *bis)
David Feng3b5458c2013-12-14 11:47:37 +0800200{
201 int rc = 0;
Andre Przywarad263e762020-06-11 12:03:18 +0100202#ifndef CONFIG_DM_ETH
David Feng3b5458c2013-12-14 11:47:37 +0800203#ifdef CONFIG_SMC91111
204 rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
205#endif
Linus Walleij48b47552015-02-17 11:35:25 +0100206#ifdef CONFIG_SMC911X
207 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
208#endif
Andre Przywarad263e762020-06-11 12:03:18 +0100209#endif
David Feng3b5458c2013-12-14 11:47:37 +0800210 return rc;
211}