blob: 4c67f1aba4defc99baf6de63022d885c143b5c3a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roesecb410332016-05-25 08:13:45 +02002/*
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
Stefan Roesecb410332016-05-25 08:13:45 +02004 */
5
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Stefan Roesecb410332016-05-25 08:13:45 +02007#include <dm.h>
8#include <fdtdec.h>
Simon Glass6980b6b2019-11-14 12:57:45 -07009#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060012#include <asm/ptrace.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Baruch Siach36927412018-11-11 12:31:04 +020014#include <linux/sizes.h>
Konstantin Porotchkincc5d6122017-04-05 17:42:33 +030015#include <pci.h>
Stefan Roesecb410332016-05-25 08:13:45 +020016#include <asm/io.h>
17#include <asm/system.h>
18#include <asm/arch/cpu.h>
19#include <asm/arch/soc.h>
20#include <asm/armv8/mmu.h>
21
22DECLARE_GLOBAL_DATA_PTR;
23
24/*
Stefan Roeseb720ff42016-11-11 08:18:44 +010025 * Not all memory is mapped in the MMU. So we need to restrict the
26 * memory size so that U-Boot does not try to access it. Also, the
27 * internal registers are located at 0xf000.0000 - 0xffff.ffff.
28 * Currently only 2GiB are mapped for system memory. This is what
29 * we pass to the U-Boot subsystem here.
30 */
Chris Packhamc25eead2022-05-20 16:39:22 +120031#define USABLE_RAM_SIZE 0x80000000ULL
Stefan Roeseb720ff42016-11-11 08:18:44 +010032
Heinrich Schuchardt51a9aac2023-08-12 20:16:58 +020033phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
Stefan Roeseb720ff42016-11-11 08:18:44 +010034{
Tom Rinibb4dd962022-11-16 13:10:37 -050035 unsigned long top = CFG_SYS_SDRAM_BASE + min(gd->ram_size, USABLE_RAM_SIZE);
Stefan Roeseb720ff42016-11-11 08:18:44 +010036
Chris Packhamc25eead2022-05-20 16:39:22 +120037 return (gd->ram_top > top) ? top : gd->ram_top;
Stefan Roeseb720ff42016-11-11 08:18:44 +010038}
39
40/*
Stefan Roesecb410332016-05-25 08:13:45 +020041 * On ARMv8, MBus is not configured in U-Boot. To enable compilation
42 * of the already implemented drivers, lets add a dummy version of
43 * this function so that linking does not fail.
44 */
45const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
46{
47 return NULL;
48}
49
Marek Behún22a0ce32018-12-17 16:10:09 +010050__weak int dram_init_banksize(void)
Stefan Roesecb410332016-05-25 08:13:45 +020051{
Simon Glass2ed696c2023-02-05 15:36:16 -070052 if (IS_ENABLED(CONFIG_ARMADA_8K))
Marek Behúne577cc32020-04-08 19:25:18 +020053 return a8k_dram_init_banksize();
Simon Glassdab125f2023-02-05 15:36:15 -070054 else if (IS_ENABLED(CONFIG_ARMADA_3700))
Marek Behúnf9d5e732020-04-08 19:25:19 +020055 return a3700_dram_init_banksize();
Simon Glass519d3d52023-02-05 15:36:10 -070056 else if (IS_ENABLED(CONFIG_ALLEYCAT_5))
Chris Packhameaab4612022-11-05 17:23:59 +130057 return alleycat5_dram_init_banksize();
Baruch Siach36927412018-11-11 12:31:04 +020058 else
Marek Behúne577cc32020-04-08 19:25:18 +020059 return fdtdec_setup_memory_banksize();
Stefan Roesecb410332016-05-25 08:13:45 +020060}
61
Marek Behún22a0ce32018-12-17 16:10:09 +010062__weak int dram_init(void)
Stefan Roesecb410332016-05-25 08:13:45 +020063{
Simon Glass2ed696c2023-02-05 15:36:16 -070064 if (IS_ENABLED(CONFIG_ARMADA_8K)) {
Baruch Siach36927412018-11-11 12:31:04 +020065 gd->ram_size = a8k_dram_scan_ap_sz();
66 if (gd->ram_size != 0)
67 return 0;
68 }
69
Simon Glassdab125f2023-02-05 15:36:15 -070070 if (IS_ENABLED(CONFIG_ARMADA_3700))
Marek Behúnf9d5e732020-04-08 19:25:19 +020071 return a3700_dram_init();
72
Simon Glass519d3d52023-02-05 15:36:10 -070073 if (IS_ENABLED(CONFIG_ALLEYCAT_5))
Chris Packhameaab4612022-11-05 17:23:59 +130074 return alleycat5_dram_init();
75
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +053076 if (fdtdec_setup_mem_size_base() != 0)
Stefan Roesecb410332016-05-25 08:13:45 +020077 return -EINVAL;
78
Simon Glass2f949c32017-03-31 08:40:32 -060079 return 0;
Stefan Roesecb410332016-05-25 08:13:45 +020080}
81
82int arch_cpu_init(void)
83{
84 /* Nothing to do (yet) */
85 return 0;
86}
87
88int arch_early_init_r(void)
89{
90 struct udevice *dev;
91 int ret;
Stefan Roesee13461b2016-10-25 18:12:40 +020092 int i;
93
94 /*
95 * Loop over all MISC uclass drivers to call the comphy code
96 * and init all CP110 devices enabled in the DT
97 */
98 i = 0;
99 while (1) {
100 /* Call the comphy code via the MISC uclass driver */
101 ret = uclass_get_device(UCLASS_MISC, i++, &dev);
Stefan Roesecb410332016-05-25 08:13:45 +0200102
Stefan Roesee13461b2016-10-25 18:12:40 +0200103 /* We're done, once no further CP110 device is found */
104 if (ret)
105 break;
Stefan Roesecb410332016-05-25 08:13:45 +0200106 }
107
108 /* Cause the SATA device to do its early init */
109 uclass_first_device(UCLASS_AHCI, &dev);
110
Konstantin Porotchkincc5d6122017-04-05 17:42:33 +0300111 /* Trigger PCIe devices detection */
Simon Glass11bedd62021-08-01 18:54:36 -0600112 if (IS_ENABLED(CONFIG_PCI))
113 pci_init();
Konstantin Porotchkincc5d6122017-04-05 17:42:33 +0300114
Stefan Roesecb410332016-05-25 08:13:45 +0200115 return 0;
116}