Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Stefan Roese <sr@denx.de> |
Stefan Roese | 21b29fc | 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 | 67c4e9f | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 10 | #include <asm/cache.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | 25a5818 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 12 | #include <asm/ptrace.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 13 | #include <linux/libfdt.h> |
Baruch Siach | 2b4d964 | 2018-11-11 12:31:04 +0200 | [diff] [blame] | 14 | #include <linux/sizes.h> |
Konstantin Porotchkin | f4f194e | 2017-04-05 17:42:33 +0300 | [diff] [blame] | 15 | #include <pci.h> |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 16 | #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 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | /* |
Stefan Roese | 059f75d | 2016-11-11 08:18:44 +0100 | [diff] [blame] | 25 | * 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 Packham | 8fd3cf2 | 2022-05-20 16:39:22 +1200 | [diff] [blame] | 31 | #define USABLE_RAM_SIZE 0x80000000ULL |
Stefan Roese | 059f75d | 2016-11-11 08:18:44 +0100 | [diff] [blame] | 32 | |
Pali Rohár | 049704f | 2022-09-09 17:32:40 +0200 | [diff] [blame] | 33 | phys_size_t board_get_usable_ram_top(phys_size_t total_size) |
Stefan Roese | 059f75d | 2016-11-11 08:18:44 +0100 | [diff] [blame] | 34 | { |
Tom Rini | aa6e94d | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 35 | unsigned long top = CFG_SYS_SDRAM_BASE + min(gd->ram_size, USABLE_RAM_SIZE); |
Stefan Roese | 059f75d | 2016-11-11 08:18:44 +0100 | [diff] [blame] | 36 | |
Chris Packham | 8fd3cf2 | 2022-05-20 16:39:22 +1200 | [diff] [blame] | 37 | return (gd->ram_top > top) ? top : gd->ram_top; |
Stefan Roese | 059f75d | 2016-11-11 08:18:44 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /* |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 41 | * 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 | */ |
| 45 | const struct mbus_dram_target_info *mvebu_mbus_dram_info(void) |
| 46 | { |
| 47 | return NULL; |
| 48 | } |
| 49 | |
Marek Behún | 3b281ac | 2018-12-17 16:10:09 +0100 | [diff] [blame] | 50 | __weak int dram_init_banksize(void) |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 51 | { |
Simon Glass | 611e9af | 2023-02-05 15:36:16 -0700 | [diff] [blame] | 52 | if (IS_ENABLED(CONFIG_ARMADA_8K)) |
Marek Behún | f075b42 | 2020-04-08 19:25:18 +0200 | [diff] [blame] | 53 | return a8k_dram_init_banksize(); |
Simon Glass | c1c5538 | 2023-02-05 15:36:15 -0700 | [diff] [blame] | 54 | else if (IS_ENABLED(CONFIG_ARMADA_3700)) |
Marek Behún | a129f64 | 2020-04-08 19:25:19 +0200 | [diff] [blame] | 55 | return a3700_dram_init_banksize(); |
Simon Glass | 51864cd | 2023-02-05 15:36:10 -0700 | [diff] [blame] | 56 | else if (IS_ENABLED(CONFIG_ALLEYCAT_5)) |
Chris Packham | 7d7bb99 | 2022-11-05 17:23:59 +1300 | [diff] [blame] | 57 | return alleycat5_dram_init_banksize(); |
Baruch Siach | 2b4d964 | 2018-11-11 12:31:04 +0200 | [diff] [blame] | 58 | else |
Marek Behún | f075b42 | 2020-04-08 19:25:18 +0200 | [diff] [blame] | 59 | return fdtdec_setup_memory_banksize(); |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Marek Behún | 3b281ac | 2018-12-17 16:10:09 +0100 | [diff] [blame] | 62 | __weak int dram_init(void) |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 63 | { |
Simon Glass | 611e9af | 2023-02-05 15:36:16 -0700 | [diff] [blame] | 64 | if (IS_ENABLED(CONFIG_ARMADA_8K)) { |
Baruch Siach | 2b4d964 | 2018-11-11 12:31:04 +0200 | [diff] [blame] | 65 | gd->ram_size = a8k_dram_scan_ap_sz(); |
| 66 | if (gd->ram_size != 0) |
| 67 | return 0; |
| 68 | } |
| 69 | |
Simon Glass | c1c5538 | 2023-02-05 15:36:15 -0700 | [diff] [blame] | 70 | if (IS_ENABLED(CONFIG_ARMADA_3700)) |
Marek Behún | a129f64 | 2020-04-08 19:25:19 +0200 | [diff] [blame] | 71 | return a3700_dram_init(); |
| 72 | |
Simon Glass | 51864cd | 2023-02-05 15:36:10 -0700 | [diff] [blame] | 73 | if (IS_ENABLED(CONFIG_ALLEYCAT_5)) |
Chris Packham | 7d7bb99 | 2022-11-05 17:23:59 +1300 | [diff] [blame] | 74 | return alleycat5_dram_init(); |
| 75 | |
Siva Durga Prasad Paladugu | 12308b1 | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 76 | if (fdtdec_setup_mem_size_base() != 0) |
Stefan Roese | 780f80c | 2017-05-08 08:31:30 +0200 | [diff] [blame] | 77 | return -EINVAL; |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 78 | |
| 79 | return 0; |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | int arch_cpu_init(void) |
| 83 | { |
| 84 | /* Nothing to do (yet) */ |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | int arch_early_init_r(void) |
| 89 | { |
| 90 | struct udevice *dev; |
| 91 | int ret; |
Stefan Roese | d7dd358 | 2016-10-25 18:12:40 +0200 | [diff] [blame] | 92 | int i; |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 93 | |
Stefan Roese | d7dd358 | 2016-10-25 18:12:40 +0200 | [diff] [blame] | 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); |
| 102 | |
| 103 | /* We're done, once no further CP110 device is found */ |
| 104 | if (ret) |
| 105 | break; |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* Cause the SATA device to do its early init */ |
| 109 | uclass_first_device(UCLASS_AHCI, &dev); |
| 110 | |
Konstantin Porotchkin | f4f194e | 2017-04-05 17:42:33 +0300 | [diff] [blame] | 111 | /* Trigger PCIe devices detection */ |
Simon Glass | ebacc78 | 2021-08-01 18:54:36 -0600 | [diff] [blame] | 112 | if (IS_ENABLED(CONFIG_PCI)) |
| 113 | pci_init(); |
Konstantin Porotchkin | f4f194e | 2017-04-05 17:42:33 +0300 | [diff] [blame] | 114 | |
Stefan Roese | 21b29fc | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 115 | return 0; |
| 116 | } |