Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Stefan Roese <sr@denx.de> |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <fdtdec.h> |
Simon Glass | 6980b6b | 2019-11-14 12:57:45 -0700 | [diff] [blame^] | 9 | #include <init.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 10 | #include <linux/libfdt.h> |
Baruch Siach | 3692741 | 2018-11-11 12:31:04 +0200 | [diff] [blame] | 11 | #include <linux/sizes.h> |
Konstantin Porotchkin | cc5d612 | 2017-04-05 17:42:33 +0300 | [diff] [blame] | 12 | #include <pci.h> |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <asm/system.h> |
| 15 | #include <asm/arch/cpu.h> |
| 16 | #include <asm/arch/soc.h> |
| 17 | #include <asm/armv8/mmu.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | /* |
Stefan Roese | b720ff4 | 2016-11-11 08:18:44 +0100 | [diff] [blame] | 22 | * Not all memory is mapped in the MMU. So we need to restrict the |
| 23 | * memory size so that U-Boot does not try to access it. Also, the |
| 24 | * internal registers are located at 0xf000.0000 - 0xffff.ffff. |
| 25 | * Currently only 2GiB are mapped for system memory. This is what |
| 26 | * we pass to the U-Boot subsystem here. |
| 27 | */ |
| 28 | #define USABLE_RAM_SIZE 0x80000000 |
| 29 | |
| 30 | ulong board_get_usable_ram_top(ulong total_size) |
| 31 | { |
| 32 | if (gd->ram_size > USABLE_RAM_SIZE) |
| 33 | return USABLE_RAM_SIZE; |
| 34 | |
| 35 | return gd->ram_size; |
| 36 | } |
| 37 | |
| 38 | /* |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 39 | * On ARMv8, MBus is not configured in U-Boot. To enable compilation |
| 40 | * of the already implemented drivers, lets add a dummy version of |
| 41 | * this function so that linking does not fail. |
| 42 | */ |
| 43 | const struct mbus_dram_target_info *mvebu_mbus_dram_info(void) |
| 44 | { |
| 45 | return NULL; |
| 46 | } |
| 47 | |
| 48 | /* DRAM init code ... */ |
| 49 | |
Baruch Siach | 3692741 | 2018-11-11 12:31:04 +0200 | [diff] [blame] | 50 | #define MV_SIP_DRAM_SIZE 0x82000010 |
| 51 | |
| 52 | static u64 a8k_dram_scan_ap_sz(void) |
| 53 | { |
| 54 | struct pt_regs pregs; |
| 55 | |
| 56 | pregs.regs[0] = MV_SIP_DRAM_SIZE; |
| 57 | pregs.regs[1] = SOC_REGS_PHY_BASE; |
| 58 | smc_call(&pregs); |
| 59 | |
| 60 | return pregs.regs[0]; |
| 61 | } |
| 62 | |
| 63 | static void a8k_dram_init_banksize(void) |
| 64 | { |
| 65 | /* |
| 66 | * The firmware (ATF) leaves a 1G whole above the 3G mark for IO |
| 67 | * devices. Higher RAM is mapped at 4G. |
| 68 | * |
| 69 | * Config 2 DRAM banks: |
| 70 | * Bank 0 - max size 4G - 1G |
| 71 | * Bank 1 - ram size - 4G + 1G |
| 72 | */ |
| 73 | phys_size_t max_bank0_size = SZ_4G - SZ_1G; |
| 74 | |
| 75 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 76 | if (gd->ram_size <= max_bank0_size) { |
| 77 | gd->bd->bi_dram[0].size = gd->ram_size; |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | gd->bd->bi_dram[0].size = max_bank0_size; |
| 82 | if (CONFIG_NR_DRAM_BANKS > 1) { |
| 83 | gd->bd->bi_dram[1].start = SZ_4G; |
| 84 | gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size; |
| 85 | } |
| 86 | } |
| 87 | |
Marek BehĂșn | 22a0ce3 | 2018-12-17 16:10:09 +0100 | [diff] [blame] | 88 | __weak int dram_init_banksize(void) |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 89 | { |
Baruch Siach | 3692741 | 2018-11-11 12:31:04 +0200 | [diff] [blame] | 90 | if (CONFIG_IS_ENABLED(ARMADA_8K)) |
| 91 | a8k_dram_init_banksize(); |
| 92 | else |
| 93 | fdtdec_setup_memory_banksize(); |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 94 | |
Stefan Roese | 412dcf8 | 2017-05-08 08:31:30 +0200 | [diff] [blame] | 95 | return 0; |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Marek BehĂșn | 22a0ce3 | 2018-12-17 16:10:09 +0100 | [diff] [blame] | 98 | __weak int dram_init(void) |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 99 | { |
Baruch Siach | 3692741 | 2018-11-11 12:31:04 +0200 | [diff] [blame] | 100 | if (CONFIG_IS_ENABLED(ARMADA_8K)) { |
| 101 | gd->ram_size = a8k_dram_scan_ap_sz(); |
| 102 | if (gd->ram_size != 0) |
| 103 | return 0; |
| 104 | } |
| 105 | |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 106 | if (fdtdec_setup_mem_size_base() != 0) |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 107 | return -EINVAL; |
| 108 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 109 | return 0; |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | int arch_cpu_init(void) |
| 113 | { |
| 114 | /* Nothing to do (yet) */ |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | int arch_early_init_r(void) |
| 119 | { |
| 120 | struct udevice *dev; |
| 121 | int ret; |
Stefan Roese | e13461b | 2016-10-25 18:12:40 +0200 | [diff] [blame] | 122 | int i; |
| 123 | |
| 124 | /* |
| 125 | * Loop over all MISC uclass drivers to call the comphy code |
| 126 | * and init all CP110 devices enabled in the DT |
| 127 | */ |
| 128 | i = 0; |
| 129 | while (1) { |
| 130 | /* Call the comphy code via the MISC uclass driver */ |
| 131 | ret = uclass_get_device(UCLASS_MISC, i++, &dev); |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 132 | |
Stefan Roese | e13461b | 2016-10-25 18:12:40 +0200 | [diff] [blame] | 133 | /* We're done, once no further CP110 device is found */ |
| 134 | if (ret) |
| 135 | break; |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /* Cause the SATA device to do its early init */ |
| 139 | uclass_first_device(UCLASS_AHCI, &dev); |
| 140 | |
Konstantin Porotchkin | cc5d612 | 2017-04-05 17:42:33 +0300 | [diff] [blame] | 141 | #ifdef CONFIG_DM_PCI |
| 142 | /* Trigger PCIe devices detection */ |
| 143 | pci_init(); |
| 144 | #endif |
| 145 | |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 146 | return 0; |
| 147 | } |