Tom Rini | 4549e78 | 2018-05-06 18:27:01 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Delaunay | eb653ac | 2020-11-06 19:01:29 +0100 | [diff] [blame^] | 6 | #define LOG_CATEGORY LOGC_ARCH |
| 7 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 8 | #include <common.h> |
Patrick Delaunay | dc7e5f1 | 2020-04-30 16:30:21 +0200 | [diff] [blame] | 9 | #include <cpu_func.h> |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 11 | #include <hang.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 14 | #include <spl.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <asm/cache.h> |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 16 | #include <asm/io.h> |
Patrick Delaunay | 006ea18 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <linux/libfdt.h> |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 19 | |
| 20 | u32 spl_boot_device(void) |
| 21 | { |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 22 | u32 boot_mode; |
| 23 | |
Patrick Delaunay | 7f63c1e | 2019-02-27 17:01:12 +0100 | [diff] [blame] | 24 | boot_mode = get_bootmode(); |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 25 | |
| 26 | switch (boot_mode) { |
| 27 | case BOOT_FLASH_SD_1: |
| 28 | case BOOT_FLASH_EMMC_1: |
| 29 | return BOOT_DEVICE_MMC1; |
| 30 | case BOOT_FLASH_SD_2: |
| 31 | case BOOT_FLASH_EMMC_2: |
| 32 | return BOOT_DEVICE_MMC2; |
Patrick Delaunay | 7f63c1e | 2019-02-27 17:01:12 +0100 | [diff] [blame] | 33 | case BOOT_SERIAL_UART_1: |
| 34 | case BOOT_SERIAL_UART_2: |
| 35 | case BOOT_SERIAL_UART_3: |
| 36 | case BOOT_SERIAL_UART_4: |
| 37 | case BOOT_SERIAL_UART_5: |
| 38 | case BOOT_SERIAL_UART_6: |
| 39 | case BOOT_SERIAL_UART_7: |
| 40 | case BOOT_SERIAL_UART_8: |
| 41 | return BOOT_DEVICE_UART; |
| 42 | case BOOT_SERIAL_USB_OTG: |
| 43 | return BOOT_DEVICE_USB; |
| 44 | case BOOT_FLASH_NAND_FMC: |
| 45 | return BOOT_DEVICE_NAND; |
| 46 | case BOOT_FLASH_NOR_QSPI: |
| 47 | return BOOT_DEVICE_SPI; |
Patrick Delaunay | b664a74 | 2020-03-18 09:22:52 +0100 | [diff] [blame] | 48 | case BOOT_FLASH_SPINAND_1: |
| 49 | return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */ |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 52 | return BOOT_DEVICE_MMC1; |
| 53 | } |
| 54 | |
Harald Seiler | e975906 | 2020-04-15 11:33:30 +0200 | [diff] [blame] | 55 | u32 spl_mmc_boot_mode(const u32 boot_device) |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 56 | { |
| 57 | return MMCSD_MODE_RAW; |
| 58 | } |
| 59 | |
Richard Genoud | 40426d6 | 2020-10-12 16:11:09 +0200 | [diff] [blame] | 60 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION |
Harald Seiler | c51b751 | 2020-04-15 11:33:31 +0200 | [diff] [blame] | 61 | int spl_mmc_boot_partition(const u32 boot_device) |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 62 | { |
| 63 | switch (boot_device) { |
| 64 | case BOOT_DEVICE_MMC1: |
| 65 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION; |
| 66 | case BOOT_DEVICE_MMC2: |
| 67 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2; |
| 68 | default: |
| 69 | return -EINVAL; |
| 70 | } |
| 71 | } |
Richard Genoud | 40426d6 | 2020-10-12 16:11:09 +0200 | [diff] [blame] | 72 | #endif |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 73 | |
Patrick Delaunay | 006ea18 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 74 | #ifdef CONFIG_SPL_DISPLAY_PRINT |
| 75 | void spl_display_print(void) |
| 76 | { |
| 77 | DECLARE_GLOBAL_DATA_PTR; |
| 78 | const char *model; |
| 79 | |
| 80 | /* same code than show_board_info() but not compiled for SPL |
| 81 | * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c |
| 82 | */ |
| 83 | model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 84 | if (model) |
Patrick Delaunay | eb653ac | 2020-11-06 19:01:29 +0100 | [diff] [blame^] | 85 | log_info("Model: %s\n", model); |
Patrick Delaunay | 006ea18 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 86 | } |
| 87 | #endif |
| 88 | |
Marek Vasut | 65e38e8 | 2020-04-22 13:18:10 +0200 | [diff] [blame] | 89 | __weak int board_early_init_f(void) |
| 90 | { |
| 91 | return 0; |
| 92 | } |
| 93 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 94 | void board_init_f(ulong dummy) |
| 95 | { |
| 96 | struct udevice *dev; |
| 97 | int ret; |
| 98 | |
| 99 | arch_cpu_init(); |
| 100 | |
| 101 | ret = spl_early_init(); |
| 102 | if (ret) { |
Patrick Delaunay | eb653ac | 2020-11-06 19:01:29 +0100 | [diff] [blame^] | 103 | log_debug("spl_early_init() failed: %d\n", ret); |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 104 | hang(); |
| 105 | } |
| 106 | |
| 107 | ret = uclass_get_device(UCLASS_CLK, 0, &dev); |
| 108 | if (ret) { |
Patrick Delaunay | eb653ac | 2020-11-06 19:01:29 +0100 | [diff] [blame^] | 109 | log_debug("Clock init failed: %d\n", ret); |
Patrick Delaunay | eaec1f9 | 2020-04-22 14:29:10 +0200 | [diff] [blame] | 110 | hang(); |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | ret = uclass_get_device(UCLASS_RESET, 0, &dev); |
| 114 | if (ret) { |
Patrick Delaunay | eb653ac | 2020-11-06 19:01:29 +0100 | [diff] [blame^] | 115 | log_debug("Reset init failed: %d\n", ret); |
Patrick Delaunay | eaec1f9 | 2020-04-22 14:29:10 +0200 | [diff] [blame] | 116 | hang(); |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev); |
| 120 | if (ret) { |
Patrick Delaunay | eb653ac | 2020-11-06 19:01:29 +0100 | [diff] [blame^] | 121 | log_debug("%s: Cannot find pinctrl device\n", __func__); |
Patrick Delaunay | eaec1f9 | 2020-04-22 14:29:10 +0200 | [diff] [blame] | 122 | hang(); |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* enable console uart printing */ |
| 126 | preloader_console_init(); |
| 127 | |
Marek Vasut | 65e38e8 | 2020-04-22 13:18:10 +0200 | [diff] [blame] | 128 | ret = board_early_init_f(); |
| 129 | if (ret) { |
Patrick Delaunay | eb653ac | 2020-11-06 19:01:29 +0100 | [diff] [blame^] | 130 | log_debug("board_early_init_f() failed: %d\n", ret); |
Marek Vasut | 65e38e8 | 2020-04-22 13:18:10 +0200 | [diff] [blame] | 131 | hang(); |
| 132 | } |
| 133 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 134 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 135 | if (ret) { |
Patrick Delaunay | eb653ac | 2020-11-06 19:01:29 +0100 | [diff] [blame^] | 136 | log_err("DRAM init failed: %d\n", ret); |
Patrick Delaunay | 105a5ad | 2019-02-27 17:01:17 +0100 | [diff] [blame] | 137 | hang(); |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 138 | } |
Patrick Delaunay | dc7e5f1 | 2020-04-30 16:30:21 +0200 | [diff] [blame] | 139 | |
| 140 | /* |
| 141 | * activate cache on DDR only when DDR is fully initialized |
| 142 | * to avoid speculative access and issue in get_ram_size() |
| 143 | */ |
| 144 | if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) |
Patrick Delaunay | 67f9f11 | 2020-09-04 12:55:19 +0200 | [diff] [blame] | 145 | mmu_set_region_dcache_behaviour(STM32_DDR_BASE, |
| 146 | CONFIG_DDR_CACHEABLE_SIZE, |
Patrick Delaunay | dc7e5f1 | 2020-04-30 16:30:21 +0200 | [diff] [blame] | 147 | DCACHE_DEFAULT_OPTION); |
| 148 | } |
| 149 | |
| 150 | void spl_board_prepare_for_boot(void) |
| 151 | { |
| 152 | dcache_disable(); |
| 153 | } |
| 154 | |
Patrick Delaunay | 346034a | 2020-07-07 14:21:53 +0200 | [diff] [blame] | 155 | void spl_board_prepare_for_linux(void) |
Patrick Delaunay | dc7e5f1 | 2020-04-30 16:30:21 +0200 | [diff] [blame] | 156 | { |
| 157 | dcache_disable(); |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 158 | } |