Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | #include <common.h> |
Michael Walle | 3b185bc | 2021-11-15 23:45:46 +0100 | [diff] [blame] | 4 | #include <dm.h> |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 5 | #include <malloc.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 6 | #include <efi.h> |
| 7 | #include <efi_loader.h> |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 8 | #include <errno.h> |
| 9 | #include <fsl_ddr.h> |
| 10 | #include <fdt_support.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 14 | #include <env_internal.h> |
| 15 | #include <asm/arch-fsl-layerscape/soc.h> |
| 16 | #include <asm/arch-fsl-layerscape/fsl_icid.h> |
| 17 | #include <i2c.h> |
| 18 | #include <asm/arch/soc.h> |
| 19 | #include <fsl_immap.h> |
| 20 | #include <netdev.h> |
Michael Walle | 324b7b4 | 2021-11-15 23:45:49 +0100 | [diff] [blame] | 21 | #include <wdt.h> |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 22 | |
Michael Walle | 3b185bc | 2021-11-15 23:45:46 +0100 | [diff] [blame] | 23 | #include <sl28cpld.h> |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 24 | #include <fdtdec.h> |
| 25 | #include <miiphy.h> |
| 26 | |
Michael Walle | bf9c73c | 2022-08-23 11:30:15 +0200 | [diff] [blame] | 27 | #include "sl28.h" |
| 28 | |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Simon Glass | b819621 | 2023-02-05 15:39:42 -0700 | [diff] [blame] | 31 | #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 32 | struct efi_fw_image fw_images[] = { |
| 33 | { |
| 34 | .image_type_id = KONTRON_SL28_FIT_IMAGE_GUID, |
| 35 | .fw_name = u"KONTRON-SL28-FIT", |
| 36 | .image_index = 1, |
| 37 | }, |
| 38 | }; |
| 39 | |
| 40 | struct efi_capsule_update_info update_info = { |
| 41 | .dfu_string = "sf 0:0=u-boot-bin raw 0x210000 0x1d0000;" |
| 42 | "u-boot-env raw 0x3e0000 0x20000", |
Masahisa Kojima | 5d2438b | 2023-06-07 14:41:51 +0900 | [diff] [blame] | 43 | .num_images = ARRAY_SIZE(fw_images), |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 44 | .images = fw_images, |
| 45 | }; |
| 46 | |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 47 | #endif /* EFI_HAVE_CAPSULE_SUPPORT */ |
| 48 | |
Michael Walle | 101410e | 2021-01-08 00:08:59 +0100 | [diff] [blame] | 49 | int board_early_init_f(void) |
| 50 | { |
| 51 | fsl_lsch3_early_init_f(); |
| 52 | return 0; |
| 53 | } |
| 54 | |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 55 | int board_init(void) |
| 56 | { |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | int board_eth_init(struct bd_info *bis) |
| 61 | { |
| 62 | return pci_eth_init(bis); |
| 63 | } |
| 64 | |
Michael Walle | bf9c73c | 2022-08-23 11:30:15 +0200 | [diff] [blame] | 65 | enum env_location env_get_location(enum env_operation op, int prio) |
| 66 | { |
| 67 | enum boot_source src = sl28_boot_source(); |
| 68 | |
| 69 | if (prio) |
| 70 | return ENVL_UNKNOWN; |
| 71 | |
| 72 | if (!CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH)) |
| 73 | return ENVL_NOWHERE; |
| 74 | |
| 75 | /* write and erase always operate on the environment */ |
| 76 | if (op == ENVOP_SAVE || op == ENVOP_ERASE) |
| 77 | return ENVL_SPI_FLASH; |
| 78 | |
| 79 | /* failsafe boot will always use the compiled-in default environment */ |
| 80 | if (src == BOOT_SOURCE_SPI) |
| 81 | return ENVL_NOWHERE; |
| 82 | |
| 83 | return ENVL_SPI_FLASH; |
| 84 | } |
| 85 | |
Michael Walle | 3b185bc | 2021-11-15 23:45:46 +0100 | [diff] [blame] | 86 | static int __sl28cpld_read(uint reg) |
| 87 | { |
| 88 | struct udevice *dev; |
| 89 | int ret; |
| 90 | |
| 91 | ret = uclass_get_device_by_driver(UCLASS_NOP, |
| 92 | DM_DRIVER_GET(sl28cpld), &dev); |
| 93 | if (ret) |
| 94 | return ret; |
| 95 | |
| 96 | return sl28cpld_read(dev, reg); |
| 97 | } |
| 98 | |
| 99 | static void print_cpld_version(void) |
| 100 | { |
| 101 | int version = __sl28cpld_read(SL28CPLD_VERSION); |
| 102 | |
| 103 | if (version < 0) |
| 104 | printf("CPLD: error reading version (%d)\n", version); |
| 105 | else |
| 106 | printf("CPLD: v%d\n", version); |
| 107 | } |
| 108 | |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 109 | int checkboard(void) |
| 110 | { |
| 111 | printf("EL: %d\n", current_el()); |
Simon Glass | 9d9b4e5 | 2023-02-05 15:40:48 -0700 | [diff] [blame] | 112 | if (IS_ENABLED(CONFIG_SL28CPLD)) |
Michael Walle | 3b185bc | 2021-11-15 23:45:46 +0100 | [diff] [blame] | 113 | print_cpld_version(); |
| 114 | |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
Michael Walle | 324b7b4 | 2021-11-15 23:45:49 +0100 | [diff] [blame] | 118 | static void stop_recovery_watchdog(void) |
| 119 | { |
| 120 | struct udevice *dev; |
| 121 | int ret; |
| 122 | |
| 123 | ret = uclass_get_device_by_driver(UCLASS_WDT, |
| 124 | DM_DRIVER_GET(sl28cpld_wdt), &dev); |
| 125 | if (!ret) |
| 126 | wdt_stop(dev); |
| 127 | } |
| 128 | |
Michael Walle | 9b14606 | 2022-08-23 11:30:17 +0200 | [diff] [blame] | 129 | static void sl28_set_prompt(void) |
| 130 | { |
| 131 | enum boot_source src = sl28_boot_source(); |
| 132 | |
| 133 | switch (src) { |
| 134 | case BOOT_SOURCE_SPI: |
| 135 | env_set("PS1", "[FAILSAFE] => "); |
| 136 | break; |
| 137 | case BOOT_SOURCE_SDHC: |
| 138 | env_set("PS1", "[SDHC] => "); |
| 139 | break; |
| 140 | default: |
| 141 | env_set("PS1", NULL); |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | |
Michael Walle | 324b7b4 | 2021-11-15 23:45:49 +0100 | [diff] [blame] | 146 | int fsl_board_late_init(void) |
| 147 | { |
Michael Walle | 9b14606 | 2022-08-23 11:30:17 +0200 | [diff] [blame] | 148 | if (IS_ENABLED(CONFIG_CMDLINE_PS_SUPPORT)) |
| 149 | sl28_set_prompt(); |
| 150 | |
Michael Walle | 324b7b4 | 2021-11-15 23:45:49 +0100 | [diff] [blame] | 151 | /* |
| 152 | * Usually, the after a board reset, the watchdog is enabled by |
| 153 | * default. This is to supervise the bootloader boot-up. Therefore, |
| 154 | * to prevent a watchdog reset if we don't actively kick it, we have |
| 155 | * to disable it. |
| 156 | * |
| 157 | * If the watchdog isn't enabled at reset (which is a configuration |
| 158 | * option) disabling it doesn't hurt either. |
| 159 | */ |
Simon Glass | 00b41cb | 2023-02-05 15:44:31 -0700 | [diff] [blame] | 160 | if (!IS_ENABLED(CONFIG_WATCHDOG_AUTOSTART)) |
Michael Walle | 324b7b4 | 2021-11-15 23:45:49 +0100 | [diff] [blame] | 161 | stop_recovery_watchdog(); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 166 | void detail_board_ddr_info(void) |
| 167 | { |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 168 | print_ddr_info(0); |
| 169 | } |
| 170 | |
| 171 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 172 | { |
| 173 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 174 | u64 size[CONFIG_NR_DRAM_BANKS]; |
| 175 | int nbanks = CONFIG_NR_DRAM_BANKS; |
Michael Walle | 76427fb | 2020-11-18 17:46:02 +0100 | [diff] [blame] | 176 | int node; |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 177 | int i; |
| 178 | |
| 179 | ft_cpu_setup(blob, bd); |
| 180 | |
| 181 | /* fixup DT for the two GPP DDR banks */ |
| 182 | for (i = 0; i < nbanks; i++) { |
| 183 | base[i] = gd->bd->bi_dram[i].start; |
| 184 | size[i] = gd->bd->bi_dram[i].size; |
| 185 | } |
| 186 | |
| 187 | fdt_fixup_memory_banks(blob, base, size, nbanks); |
| 188 | |
| 189 | fdt_fixup_icid(blob); |
| 190 | |
Simon Glass | 1540e72 | 2023-02-05 15:40:49 -0700 | [diff] [blame] | 191 | if (IS_ENABLED(CONFIG_SL28_SPL_LOADS_OPTEE_BL32)) { |
Michael Walle | 76427fb | 2020-11-18 17:46:02 +0100 | [diff] [blame] | 192 | node = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz"); |
| 193 | if (node) |
Marek BehĂșn | f872e83 | 2021-11-26 14:57:08 +0100 | [diff] [blame] | 194 | fdt_set_node_status(blob, node, FDT_STATUS_OKAY); |
Michael Walle | 76427fb | 2020-11-18 17:46:02 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Michael Walle | 36ba764 | 2020-10-15 23:08:57 +0200 | [diff] [blame] | 197 | return 0; |
| 198 | } |