blob: 5932a4a0c7052408bc8d67334edb039eec92aa2d [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>
15#include <asm/io.h>
16#include <linux/compiler.h>
David Fengab33c2c2015-01-31 11:55:29 +080017#include <dm/platform_data/serial_pl01x.h>
Liviu Dudau8d1fdc32015-10-19 11:08:32 +010018#include "pcie.h"
Alexander Graf5889e392016-03-04 01:09:51 +010019#include <asm/armv8/mmu.h>
David Feng3b5458c2013-12-14 11:47:37 +080020
21DECLARE_GLOBAL_DATA_PTR;
22
David Fengab33c2c2015-01-31 11:55:29 +080023static const struct pl01x_serial_platdata serial_platdata = {
24 .base = V2M_UART0,
25 .type = TYPE_PL011,
Linus Walleij31e476e2015-04-14 10:01:35 +020026 .clock = CONFIG_PL011_CLOCK,
David Fengab33c2c2015-01-31 11:55:29 +080027};
28
29U_BOOT_DEVICE(vexpress_serials) = {
30 .name = "serial_pl01x",
31 .platdata = &serial_platdata,
32};
33
Alexander Graf5889e392016-03-04 01:09:51 +010034static struct mm_region vexpress64_mem_map[] = {
35 {
York Sunc7104e52016-06-24 16:46:22 -070036 .virt = 0x0UL,
37 .phys = 0x0UL,
Alexander Graf5889e392016-03-04 01:09:51 +010038 .size = 0x80000000UL,
39 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
40 PTE_BLOCK_NON_SHARE |
41 PTE_BLOCK_PXN | PTE_BLOCK_UXN
42 }, {
York Sunc7104e52016-06-24 16:46:22 -070043 .virt = 0x80000000UL,
44 .phys = 0x80000000UL,
Alexander Graf5889e392016-03-04 01:09:51 +010045 .size = 0xff80000000UL,
46 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
47 PTE_BLOCK_INNER_SHARE
48 }, {
49 /* List terminator */
50 0,
51 }
52};
53
54struct mm_region *mem_map = vexpress64_mem_map;
55
Ryan Harkin8961d502015-11-18 10:39:06 +000056/* This function gets replaced by platforms supporting PCIe.
57 * The replacement function, eg. on Juno, initialises the PCIe bus.
58 */
59__weak void vexpress64_pcie_init(void)
60{
61}
62
David Feng3b5458c2013-12-14 11:47:37 +080063int board_init(void)
64{
Liviu Dudau8d1fdc32015-10-19 11:08:32 +010065 vexpress64_pcie_init();
David Feng3b5458c2013-12-14 11:47:37 +080066 return 0;
67}
68
69int dram_init(void)
70{
David Feng3b5458c2013-12-14 11:47:37 +080071 gd->ram_size = PHYS_SDRAM_1_SIZE;
72 return 0;
73}
74
Simon Glass2f949c32017-03-31 08:40:32 -060075int dram_init_banksize(void)
Liviu Dudau086c9772015-10-19 11:08:31 +010076{
77 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
78 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Ryan Harkin98d2fff2015-11-18 10:39:07 +000079#ifdef PHYS_SDRAM_2
Liviu Dudau086c9772015-10-19 11:08:31 +010080 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
81 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
Ryan Harkin98d2fff2015-11-18 10:39:07 +000082#endif
Simon Glass2f949c32017-03-31 08:40:32 -060083
84 return 0;
Liviu Dudau086c9772015-10-19 11:08:31 +010085}
86
Andre Przywara94504f42020-04-27 19:18:01 +010087#ifdef CONFIG_OF_BOARD
88#define JUNO_FLASH_SEC_SIZE (256 * 1024)
89static phys_addr_t find_dtb_in_nor_flash(const char *partname)
90{
91 phys_addr_t sector = CONFIG_SYS_FLASH_BASE;
92 int i;
93
94 for (i = 0;
95 i < CONFIG_SYS_MAX_FLASH_SECT;
96 i++, sector += JUNO_FLASH_SEC_SIZE) {
97 int len = strlen(partname) + 1;
98 int offs;
99 phys_addr_t imginfo;
100 u32 reg;
101
102 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x04);
103 /* This makes up the string "HSLFTOOF" flash footer */
104 if (reg != 0x464F4F54U)
105 continue;
106 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x08);
107 if (reg != 0x464C5348U)
108 continue;
109
110 for (offs = 0; offs < 32; offs += 4, len -= 4) {
111 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x30 + offs);
112 if (strncmp(partname + offs, (char *)&reg,
113 len > 4 ? 4 : len))
114 break;
115
116 if (len > 4)
117 continue;
118
119 reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x10);
120 imginfo = sector + JUNO_FLASH_SEC_SIZE - 0x30 - reg;
121 reg = readl(imginfo + 0x54);
122
123 return CONFIG_SYS_FLASH_BASE +
124 reg * JUNO_FLASH_SEC_SIZE;
125 }
126 }
127
128 printf("No DTB found\n");
129
130 return ~0;
131}
132
133void *board_fdt_blob_setup(void)
134{
135 phys_addr_t fdt_rom_addr = find_dtb_in_nor_flash(CONFIG_JUNO_DTB_PART);
136
137 if (fdt_rom_addr == ~0UL)
138 return NULL;
139
140 return (void *)fdt_rom_addr;
141}
142#endif
143
Andre Przywara651c91b2020-04-27 19:18:02 +0100144/* Actual reset is done via PSCI. */
David Feng3b5458c2013-12-14 11:47:37 +0800145void reset_cpu(ulong addr)
146{
Darwin Rambod32d4112014-06-09 11:12:59 -0700147}
148
David Feng3b5458c2013-12-14 11:47:37 +0800149/*
150 * Board specific ethernet initialization routine.
151 */
152int board_eth_init(bd_t *bis)
153{
154 int rc = 0;
Andre Przywarad263e762020-06-11 12:03:18 +0100155#ifndef CONFIG_DM_ETH
David Feng3b5458c2013-12-14 11:47:37 +0800156#ifdef CONFIG_SMC91111
157 rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
158#endif
Linus Walleij48b47552015-02-17 11:35:25 +0100159#ifdef CONFIG_SMC911X
160 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
161#endif
Andre Przywarad263e762020-06-11 12:03:18 +0100162#endif
David Feng3b5458c2013-12-14 11:47:37 +0800163 return rc;
164}