blob: 7d5e5516f9fb165667426ac0fc746d877d838d28 [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>
David Fengab33c2c2015-01-31 11:55:29 +080018#include <dm/platform_data/serial_pl01x.h>
Liviu Dudau8d1fdc32015-10-19 11:08:32 +010019#include "pcie.h"
Alexander Graf5889e392016-03-04 01:09:51 +010020#include <asm/armv8/mmu.h>
Peter Hoyes8194cda2021-11-11 09:26:03 +000021#ifdef CONFIG_VIRTIO_NET
22#include <virtio_types.h>
23#include <virtio.h>
24#endif
David Feng3b5458c2013-12-14 11:47:37 +080025
26DECLARE_GLOBAL_DATA_PTR;
27
Simon Glassb75b15b2020-12-03 16:55:23 -070028static const struct pl01x_serial_plat serial_plat = {
David Fengab33c2c2015-01-31 11:55:29 +080029 .base = V2M_UART0,
30 .type = TYPE_PL011,
Linus Walleij31e476e2015-04-14 10:01:35 +020031 .clock = CONFIG_PL011_CLOCK,
David Fengab33c2c2015-01-31 11:55:29 +080032};
33
Simon Glass1d8364a2020-12-28 20:34:54 -070034U_BOOT_DRVINFO(vexpress_serials) = {
David Fengab33c2c2015-01-31 11:55:29 +080035 .name = "serial_pl01x",
Simon Glassb75b15b2020-12-03 16:55:23 -070036 .plat = &serial_plat,
David Fengab33c2c2015-01-31 11:55:29 +080037};
38
Alexander Graf5889e392016-03-04 01:09:51 +010039static struct mm_region vexpress64_mem_map[] = {
40 {
York Sunc7104e52016-06-24 16:46:22 -070041 .virt = 0x0UL,
42 .phys = 0x0UL,
Alexander Graf5889e392016-03-04 01:09:51 +010043 .size = 0x80000000UL,
44 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
45 PTE_BLOCK_NON_SHARE |
46 PTE_BLOCK_PXN | PTE_BLOCK_UXN
47 }, {
York Sunc7104e52016-06-24 16:46:22 -070048 .virt = 0x80000000UL,
49 .phys = 0x80000000UL,
Alexander Graf5889e392016-03-04 01:09:51 +010050 .size = 0xff80000000UL,
51 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
52 PTE_BLOCK_INNER_SHARE
53 }, {
54 /* List terminator */
55 0,
56 }
57};
58
59struct mm_region *mem_map = vexpress64_mem_map;
60
Ryan Harkin8961d502015-11-18 10:39:06 +000061/* This function gets replaced by platforms supporting PCIe.
62 * The replacement function, eg. on Juno, initialises the PCIe bus.
63 */
64__weak void vexpress64_pcie_init(void)
65{
66}
67
David Feng3b5458c2013-12-14 11:47:37 +080068int board_init(void)
69{
Liviu Dudau8d1fdc32015-10-19 11:08:32 +010070 vexpress64_pcie_init();
Peter Hoyes8194cda2021-11-11 09:26:03 +000071#ifdef CONFIG_VIRTIO_NET
72 virtio_init();
73#endif
David Feng3b5458c2013-12-14 11:47:37 +080074 return 0;
75}
76
77int dram_init(void)
78{
David Feng3b5458c2013-12-14 11:47:37 +080079 gd->ram_size = PHYS_SDRAM_1_SIZE;
80 return 0;
81}
82
Simon Glass2f949c32017-03-31 08:40:32 -060083int dram_init_banksize(void)
Liviu Dudau086c9772015-10-19 11:08:31 +010084{
85 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
86 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Ryan Harkin98d2fff2015-11-18 10:39:07 +000087#ifdef PHYS_SDRAM_2
Liviu Dudau086c9772015-10-19 11:08:31 +010088 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
89 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
Ryan Harkin98d2fff2015-11-18 10:39:07 +000090#endif
Simon Glass2f949c32017-03-31 08:40:32 -060091
92 return 0;
Liviu Dudau086c9772015-10-19 11:08:31 +010093}
94
Peter Hoyesbaf62cf2021-11-11 09:26:02 +000095/* Assigned in lowlevel_init.S
96 * Push the variable into the .data section so that it
97 * does not get cleared later.
98 */
99unsigned long __section(".data") prior_stage_fdt_address;
100
Andre Przywara94504f42020-04-27 19:18:01 +0100101#ifdef CONFIG_OF_BOARD
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000102
103#ifdef CONFIG_TARGET_VEXPRESS64_JUNO
Andre Przywara94504f42020-04-27 19:18:01 +0100104#define JUNO_FLASH_SEC_SIZE (256 * 1024)
105static phys_addr_t find_dtb_in_nor_flash(const char *partname)
106{
107 phys_addr_t sector = CONFIG_SYS_FLASH_BASE;
108 int i;
109
110 for (i = 0;
111 i < CONFIG_SYS_MAX_FLASH_SECT;
112 i++, sector += JUNO_FLASH_SEC_SIZE) {
113 int len = strlen(partname) + 1;
114 int offs;
115 phys_addr_t imginfo;
116 u32 reg;
117
118 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x04);
119 /* This makes up the string "HSLFTOOF" flash footer */
120 if (reg != 0x464F4F54U)
121 continue;
122 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x08);
123 if (reg != 0x464C5348U)
124 continue;
125
126 for (offs = 0; offs < 32; offs += 4, len -= 4) {
127 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x30 + offs);
128 if (strncmp(partname + offs, (char *)&reg,
129 len > 4 ? 4 : len))
130 break;
131
132 if (len > 4)
133 continue;
134
135 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x10);
136 imginfo = sector + JUNO_FLASH_SEC_SIZE - 0x30 - reg;
137 reg = readl(imginfo + 0x54);
138
139 return CONFIG_SYS_FLASH_BASE +
140 reg * JUNO_FLASH_SEC_SIZE;
141 }
142 }
143
144 printf("No DTB found\n");
145
146 return ~0;
147}
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000148#endif
Andre Przywara94504f42020-04-27 19:18:01 +0100149
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300150void *board_fdt_blob_setup(int *err)
Andre Przywara94504f42020-04-27 19:18:01 +0100151{
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000152#ifdef CONFIG_TARGET_VEXPRESS64_JUNO
Andre Przywara94504f42020-04-27 19:18:01 +0100153 phys_addr_t fdt_rom_addr = find_dtb_in_nor_flash(CONFIG_JUNO_DTB_PART);
154
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300155 *err = 0;
156 if (fdt_rom_addr == ~0UL) {
157 *err = -ENXIO;
Andre Przywara94504f42020-04-27 19:18:01 +0100158 return NULL;
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300159 }
Andre Przywara94504f42020-04-27 19:18:01 +0100160
161 return (void *)fdt_rom_addr;
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000162#endif
163
164#ifdef VEXPRESS_FDT_ADDR
165 if (fdt_magic(VEXPRESS_FDT_ADDR) == FDT_MAGIC) {
166 *err = 0;
167 return (void *)VEXPRESS_FDT_ADDR;
168 }
169#endif
170
Andre Przywara395e9a92022-03-04 16:30:11 +0000171 if (fdt_magic(prior_stage_fdt_address) == FDT_MAGIC &&
172 fdt_totalsize(prior_stage_fdt_address) > 0x100) {
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000173 *err = 0;
174 return (void *)prior_stage_fdt_address;
175 }
176
Andre Przywara395e9a92022-03-04 16:30:11 +0000177 if (fdt_magic(gd->fdt_blob) == FDT_MAGIC) {
178 *err = 0;
179 return (void *)gd->fdt_blob;
180 }
181
Peter Hoyesbaf62cf2021-11-11 09:26:02 +0000182 *err = -ENXIO;
183 return NULL;
Andre Przywara94504f42020-04-27 19:18:01 +0100184}
185#endif
186
Andre Przywara651c91b2020-04-27 19:18:02 +0100187/* Actual reset is done via PSCI. */
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100188void reset_cpu(void)
David Feng3b5458c2013-12-14 11:47:37 +0800189{
Darwin Rambod32d4112014-06-09 11:12:59 -0700190}
191
David Feng3b5458c2013-12-14 11:47:37 +0800192/*
193 * Board specific ethernet initialization routine.
194 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900195int board_eth_init(struct bd_info *bis)
David Feng3b5458c2013-12-14 11:47:37 +0800196{
197 int rc = 0;
Andre Przywarad263e762020-06-11 12:03:18 +0100198#ifndef CONFIG_DM_ETH
David Feng3b5458c2013-12-14 11:47:37 +0800199#ifdef CONFIG_SMC91111
200 rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
201#endif
Linus Walleij48b47552015-02-17 11:35:25 +0100202#ifdef CONFIG_SMC911X
203 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
204#endif
Andre Przywarad263e762020-06-11 12:03:18 +0100205#endif
David Feng3b5458c2013-12-14 11:47:37 +0800206 return rc;
207}