blob: 238edbe6ba56ef1f4022ef589e3d7e300f16aa4e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese21b29fc2016-05-25 08:13:45 +02002/*
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
Stefan Roese21b29fc2016-05-25 08:13:45 +02004 */
5
6#include <common.h>
7#include <dm.h>
8#include <fdtdec.h>
Simon Glass67c4e9f2019-11-14 12:57:45 -07009#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060010#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glass25a58182020-05-10 11:40:06 -060012#include <asm/ptrace.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Baruch Siach2b4d9642018-11-11 12:31:04 +020014#include <linux/sizes.h>
Konstantin Porotchkinf4f194e2017-04-05 17:42:33 +030015#include <pci.h>
Stefan Roese21b29fc2016-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 Roese059f75d2016-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 Packham8fd3cf22022-05-20 16:39:22 +120031#define USABLE_RAM_SIZE 0x80000000ULL
Stefan Roese059f75d2016-11-11 08:18:44 +010032
33ulong board_get_usable_ram_top(ulong total_size)
34{
Chris Packham8fd3cf22022-05-20 16:39:22 +120035 unsigned long top = CONFIG_SYS_SDRAM_BASE + min(gd->ram_size, USABLE_RAM_SIZE);
Stefan Roese059f75d2016-11-11 08:18:44 +010036
Chris Packham8fd3cf22022-05-20 16:39:22 +120037 return (gd->ram_top > top) ? top : gd->ram_top;
Stefan Roese059f75d2016-11-11 08:18:44 +010038}
39
40/*
Stefan Roese21b29fc2016-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ún3b281ac2018-12-17 16:10:09 +010050__weak int dram_init_banksize(void)
Stefan Roese21b29fc2016-05-25 08:13:45 +020051{
Baruch Siach2b4d9642018-11-11 12:31:04 +020052 if (CONFIG_IS_ENABLED(ARMADA_8K))
Marek Behúnf075b422020-04-08 19:25:18 +020053 return a8k_dram_init_banksize();
Marek Behúna129f642020-04-08 19:25:19 +020054 else if (CONFIG_IS_ENABLED(ARMADA_3700))
55 return a3700_dram_init_banksize();
Baruch Siach2b4d9642018-11-11 12:31:04 +020056 else
Marek Behúnf075b422020-04-08 19:25:18 +020057 return fdtdec_setup_memory_banksize();
Stefan Roese21b29fc2016-05-25 08:13:45 +020058}
59
Marek Behún3b281ac2018-12-17 16:10:09 +010060__weak int dram_init(void)
Stefan Roese21b29fc2016-05-25 08:13:45 +020061{
Baruch Siach2b4d9642018-11-11 12:31:04 +020062 if (CONFIG_IS_ENABLED(ARMADA_8K)) {
63 gd->ram_size = a8k_dram_scan_ap_sz();
64 if (gd->ram_size != 0)
65 return 0;
66 }
67
Marek Behúna129f642020-04-08 19:25:19 +020068 if (CONFIG_IS_ENABLED(ARMADA_3700))
69 return a3700_dram_init();
70
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +053071 if (fdtdec_setup_mem_size_base() != 0)
Stefan Roese780f80c2017-05-08 08:31:30 +020072 return -EINVAL;
Simon Glass76b00ac2017-03-31 08:40:32 -060073
74 return 0;
Stefan Roese21b29fc2016-05-25 08:13:45 +020075}
76
77int arch_cpu_init(void)
78{
79 /* Nothing to do (yet) */
80 return 0;
81}
82
83int arch_early_init_r(void)
84{
85 struct udevice *dev;
86 int ret;
Stefan Roesed7dd3582016-10-25 18:12:40 +020087 int i;
Stefan Roese21b29fc2016-05-25 08:13:45 +020088
Stefan Roesed7dd3582016-10-25 18:12:40 +020089 /*
90 * Loop over all MISC uclass drivers to call the comphy code
91 * and init all CP110 devices enabled in the DT
92 */
93 i = 0;
94 while (1) {
95 /* Call the comphy code via the MISC uclass driver */
96 ret = uclass_get_device(UCLASS_MISC, i++, &dev);
97
98 /* We're done, once no further CP110 device is found */
99 if (ret)
100 break;
Stefan Roese21b29fc2016-05-25 08:13:45 +0200101 }
102
103 /* Cause the SATA device to do its early init */
104 uclass_first_device(UCLASS_AHCI, &dev);
105
Konstantin Porotchkinf4f194e2017-04-05 17:42:33 +0300106 /* Trigger PCIe devices detection */
Simon Glassebacc782021-08-01 18:54:36 -0600107 if (IS_ENABLED(CONFIG_PCI))
108 pci_init();
Konstantin Porotchkinf4f194e2017-04-05 17:42:33 +0300109
Stefan Roese21b29fc2016-05-25 08:13:45 +0200110 return 0;
111}