]>
Commit | Line | Data |
---|---|---|
4549e789 | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
2514c2d0 PD |
2 | /* |
3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved | |
2514c2d0 PD |
4 | */ |
5 | ||
eb653acd PD |
6 | #define LOG_CATEGORY LOGC_ARCH |
7 | ||
2514c2d0 | 8 | #include <common.h> |
dc7e5f19 | 9 | #include <cpu_func.h> |
2514c2d0 | 10 | #include <dm.h> |
db41d65a | 11 | #include <hang.h> |
691d719d | 12 | #include <init.h> |
f7ae49fc | 13 | #include <log.h> |
2514c2d0 | 14 | #include <spl.h> |
90526e9f | 15 | #include <asm/cache.h> |
401d1c4f | 16 | #include <asm/global_data.h> |
11dfd1a3 | 17 | #include <asm/io.h> |
006ea189 PD |
18 | #include <asm/arch/sys_proto.h> |
19 | #include <linux/libfdt.h> | |
2514c2d0 PD |
20 | |
21 | u32 spl_boot_device(void) | |
22 | { | |
11dfd1a3 PD |
23 | u32 boot_mode; |
24 | ||
7f63c1e6 | 25 | boot_mode = get_bootmode(); |
11dfd1a3 PD |
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; | |
7f63c1e6 PD |
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; | |
b664a745 PD |
49 | case BOOT_FLASH_SPINAND_1: |
50 | return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */ | |
11dfd1a3 PD |
51 | } |
52 | ||
2514c2d0 PD |
53 | return BOOT_DEVICE_MMC1; |
54 | } | |
55 | ||
e9759065 | 56 | u32 spl_mmc_boot_mode(const u32 boot_device) |
2514c2d0 PD |
57 | { |
58 | return MMCSD_MODE_RAW; | |
59 | } | |
60 | ||
40426d6f | 61 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION |
c51b7518 | 62 | int spl_mmc_boot_partition(const u32 boot_device) |
11dfd1a3 PD |
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 | } | |
40426d6f | 73 | #endif |
11dfd1a3 | 74 | |
006ea189 PD |
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) | |
eb653acd | 86 | log_info("Model: %s\n", model); |
006ea189 PD |
87 | } |
88 | #endif | |
89 | ||
65e38e81 MV |
90 | __weak int board_early_init_f(void) |
91 | { | |
92 | return 0; | |
93 | } | |
94 | ||
2514c2d0 PD |
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) { | |
eb653acd | 104 | log_debug("spl_early_init() failed: %d\n", ret); |
2514c2d0 PD |
105 | hang(); |
106 | } | |
107 | ||
108 | ret = uclass_get_device(UCLASS_CLK, 0, &dev); | |
109 | if (ret) { | |
eb653acd | 110 | log_debug("Clock init failed: %d\n", ret); |
eaec1f9e | 111 | hang(); |
2514c2d0 PD |
112 | } |
113 | ||
114 | ret = uclass_get_device(UCLASS_RESET, 0, &dev); | |
115 | if (ret) { | |
eb653acd | 116 | log_debug("Reset init failed: %d\n", ret); |
eaec1f9e | 117 | hang(); |
2514c2d0 PD |
118 | } |
119 | ||
120 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev); | |
121 | if (ret) { | |
eb653acd | 122 | log_debug("%s: Cannot find pinctrl device\n", __func__); |
eaec1f9e | 123 | hang(); |
2514c2d0 PD |
124 | } |
125 | ||
126 | /* enable console uart printing */ | |
127 | preloader_console_init(); | |
128 | ||
65e38e81 MV |
129 | ret = board_early_init_f(); |
130 | if (ret) { | |
eb653acd | 131 | log_debug("board_early_init_f() failed: %d\n", ret); |
65e38e81 MV |
132 | hang(); |
133 | } | |
134 | ||
2514c2d0 PD |
135 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
136 | if (ret) { | |
eb653acd | 137 | log_err("DRAM init failed: %d\n", ret); |
105a5ad6 | 138 | hang(); |
2514c2d0 | 139 | } |
dc7e5f19 PD |
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)) | |
67f9f11f PD |
146 | mmu_set_region_dcache_behaviour(STM32_DDR_BASE, |
147 | CONFIG_DDR_CACHEABLE_SIZE, | |
dc7e5f19 PD |
148 | DCACHE_DEFAULT_OPTION); |
149 | } | |
150 | ||
151 | void spl_board_prepare_for_boot(void) | |
152 | { | |
153 | dcache_disable(); | |
154 | } | |
155 | ||
346034a7 | 156 | void spl_board_prepare_for_linux(void) |
dc7e5f19 PD |
157 | { |
158 | dcache_disable(); | |
2514c2d0 | 159 | } |