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