blob: aaf7b7c4472c4f9834dc9957606ff010df82993f [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>
Masahiro Yamada75f82d02018-03-05 01:20:11 +09009#include <linux/libfdt.h>
Baruch Siach36927412018-11-11 12:31:04 +020010#include <linux/sizes.h>
Konstantin Porotchkincc5d6122017-04-05 17:42:33 +030011#include <pci.h>
Stefan Roesecb410332016-05-25 08:13:45 +020012#include <asm/io.h>
13#include <asm/system.h>
14#include <asm/arch/cpu.h>
15#include <asm/arch/soc.h>
16#include <asm/armv8/mmu.h>
17
18DECLARE_GLOBAL_DATA_PTR;
19
20/*
Stefan Roeseb720ff42016-11-11 08:18:44 +010021 * Not all memory is mapped in the MMU. So we need to restrict the
22 * memory size so that U-Boot does not try to access it. Also, the
23 * internal registers are located at 0xf000.0000 - 0xffff.ffff.
24 * Currently only 2GiB are mapped for system memory. This is what
25 * we pass to the U-Boot subsystem here.
26 */
27#define USABLE_RAM_SIZE 0x80000000
28
29ulong board_get_usable_ram_top(ulong total_size)
30{
31 if (gd->ram_size > USABLE_RAM_SIZE)
32 return USABLE_RAM_SIZE;
33
34 return gd->ram_size;
35}
36
37/*
Stefan Roesecb410332016-05-25 08:13:45 +020038 * On ARMv8, MBus is not configured in U-Boot. To enable compilation
39 * of the already implemented drivers, lets add a dummy version of
40 * this function so that linking does not fail.
41 */
42const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
43{
44 return NULL;
45}
46
47/* DRAM init code ... */
48
Baruch Siach36927412018-11-11 12:31:04 +020049#define MV_SIP_DRAM_SIZE 0x82000010
50
51static u64 a8k_dram_scan_ap_sz(void)
52{
53 struct pt_regs pregs;
54
55 pregs.regs[0] = MV_SIP_DRAM_SIZE;
56 pregs.regs[1] = SOC_REGS_PHY_BASE;
57 smc_call(&pregs);
58
59 return pregs.regs[0];
60}
61
62static void a8k_dram_init_banksize(void)
63{
64 /*
65 * The firmware (ATF) leaves a 1G whole above the 3G mark for IO
66 * devices. Higher RAM is mapped at 4G.
67 *
68 * Config 2 DRAM banks:
69 * Bank 0 - max size 4G - 1G
70 * Bank 1 - ram size - 4G + 1G
71 */
72 phys_size_t max_bank0_size = SZ_4G - SZ_1G;
73
74 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
75 if (gd->ram_size <= max_bank0_size) {
76 gd->bd->bi_dram[0].size = gd->ram_size;
77 return;
78 }
79
80 gd->bd->bi_dram[0].size = max_bank0_size;
81 if (CONFIG_NR_DRAM_BANKS > 1) {
82 gd->bd->bi_dram[1].start = SZ_4G;
83 gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size;
84 }
85}
86
Marek BehĂșn22a0ce32018-12-17 16:10:09 +010087__weak int dram_init_banksize(void)
Stefan Roesecb410332016-05-25 08:13:45 +020088{
Baruch Siach36927412018-11-11 12:31:04 +020089 if (CONFIG_IS_ENABLED(ARMADA_8K))
90 a8k_dram_init_banksize();
91 else
92 fdtdec_setup_memory_banksize();
Stefan Roesecb410332016-05-25 08:13:45 +020093
Stefan Roese412dcf82017-05-08 08:31:30 +020094 return 0;
Stefan Roesecb410332016-05-25 08:13:45 +020095}
96
Marek BehĂșn22a0ce32018-12-17 16:10:09 +010097__weak int dram_init(void)
Stefan Roesecb410332016-05-25 08:13:45 +020098{
Baruch Siach36927412018-11-11 12:31:04 +020099 if (CONFIG_IS_ENABLED(ARMADA_8K)) {
100 gd->ram_size = a8k_dram_scan_ap_sz();
101 if (gd->ram_size != 0)
102 return 0;
103 }
104
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530105 if (fdtdec_setup_mem_size_base() != 0)
Stefan Roesecb410332016-05-25 08:13:45 +0200106 return -EINVAL;
107
Simon Glass2f949c32017-03-31 08:40:32 -0600108 return 0;
Stefan Roesecb410332016-05-25 08:13:45 +0200109}
110
111int arch_cpu_init(void)
112{
113 /* Nothing to do (yet) */
114 return 0;
115}
116
117int arch_early_init_r(void)
118{
119 struct udevice *dev;
120 int ret;
Stefan Roesee13461b2016-10-25 18:12:40 +0200121 int i;
122
123 /*
124 * Loop over all MISC uclass drivers to call the comphy code
125 * and init all CP110 devices enabled in the DT
126 */
127 i = 0;
128 while (1) {
129 /* Call the comphy code via the MISC uclass driver */
130 ret = uclass_get_device(UCLASS_MISC, i++, &dev);
Stefan Roesecb410332016-05-25 08:13:45 +0200131
Stefan Roesee13461b2016-10-25 18:12:40 +0200132 /* We're done, once no further CP110 device is found */
133 if (ret)
134 break;
Stefan Roesecb410332016-05-25 08:13:45 +0200135 }
136
137 /* Cause the SATA device to do its early init */
138 uclass_first_device(UCLASS_AHCI, &dev);
139
Konstantin Porotchkincc5d6122017-04-05 17:42:33 +0300140#ifdef CONFIG_DM_PCI
141 /* Trigger PCIe devices detection */
142 pci_init();
143#endif
144
Stefan Roesecb410332016-05-25 08:13:45 +0200145 return 0;
146}