blob: 5357aa554db40c99897459d210bc4f8c448dbe90 [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
6#include <common.h>
7#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 */
31#define USABLE_RAM_SIZE 0x80000000
32
33ulong board_get_usable_ram_top(ulong total_size)
34{
35 if (gd->ram_size > USABLE_RAM_SIZE)
36 return USABLE_RAM_SIZE;
37
38 return gd->ram_size;
39}
40
41/*
Stefan Roesecb410332016-05-25 08:13:45 +020042 * On ARMv8, MBus is not configured in U-Boot. To enable compilation
43 * of the already implemented drivers, lets add a dummy version of
44 * this function so that linking does not fail.
45 */
46const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
47{
48 return NULL;
49}
50
Marek Behún22a0ce32018-12-17 16:10:09 +010051__weak int dram_init_banksize(void)
Stefan Roesecb410332016-05-25 08:13:45 +020052{
Baruch Siach36927412018-11-11 12:31:04 +020053 if (CONFIG_IS_ENABLED(ARMADA_8K))
Marek Behúne577cc32020-04-08 19:25:18 +020054 return a8k_dram_init_banksize();
Marek Behúnf9d5e732020-04-08 19:25:19 +020055 else if (CONFIG_IS_ENABLED(ARMADA_3700))
56 return a3700_dram_init_banksize();
Baruch Siach36927412018-11-11 12:31:04 +020057 else
Marek Behúne577cc32020-04-08 19:25:18 +020058 return fdtdec_setup_memory_banksize();
Stefan Roesecb410332016-05-25 08:13:45 +020059}
60
Marek Behún22a0ce32018-12-17 16:10:09 +010061__weak int dram_init(void)
Stefan Roesecb410332016-05-25 08:13:45 +020062{
Baruch Siach36927412018-11-11 12:31:04 +020063 if (CONFIG_IS_ENABLED(ARMADA_8K)) {
64 gd->ram_size = a8k_dram_scan_ap_sz();
65 if (gd->ram_size != 0)
66 return 0;
67 }
68
Marek Behúnf9d5e732020-04-08 19:25:19 +020069 if (CONFIG_IS_ENABLED(ARMADA_3700))
70 return a3700_dram_init();
71
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +053072 if (fdtdec_setup_mem_size_base() != 0)
Stefan Roesecb410332016-05-25 08:13:45 +020073 return -EINVAL;
74
Simon Glass2f949c32017-03-31 08:40:32 -060075 return 0;
Stefan Roesecb410332016-05-25 08:13:45 +020076}
77
78int arch_cpu_init(void)
79{
80 /* Nothing to do (yet) */
81 return 0;
82}
83
84int arch_early_init_r(void)
85{
86 struct udevice *dev;
87 int ret;
Stefan Roesee13461b2016-10-25 18:12:40 +020088 int i;
89
90 /*
91 * Loop over all MISC uclass drivers to call the comphy code
92 * and init all CP110 devices enabled in the DT
93 */
94 i = 0;
95 while (1) {
96 /* Call the comphy code via the MISC uclass driver */
97 ret = uclass_get_device(UCLASS_MISC, i++, &dev);
Stefan Roesecb410332016-05-25 08:13:45 +020098
Stefan Roesee13461b2016-10-25 18:12:40 +020099 /* We're done, once no further CP110 device is found */
100 if (ret)
101 break;
Stefan Roesecb410332016-05-25 08:13:45 +0200102 }
103
104 /* Cause the SATA device to do its early init */
105 uclass_first_device(UCLASS_AHCI, &dev);
106
Konstantin Porotchkincc5d6122017-04-05 17:42:33 +0300107 /* Trigger PCIe devices detection */
Simon Glass11bedd62021-08-01 18:54:36 -0600108 if (IS_ENABLED(CONFIG_PCI))
109 pci_init();
Konstantin Porotchkincc5d6122017-04-05 17:42:33 +0300110
Stefan Roesecb410332016-05-25 08:13:45 +0200111 return 0;
112}