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