blob: cbaf665d0c218ab0997067c00681c0984da93fdf [file] [log] [blame]
Tom Rini4549e782018-05-06 18:27:01 -04001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Patrick Delaunay2514c2d2018-03-12 10:46:10 +01002/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunay2514c2d2018-03-12 10:46:10 +01004 */
5
6#include <common.h>
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +02007#include <cpu_func.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +01008#include <dm.h>
Simon Glassdb41d652019-12-28 10:45:07 -07009#include <hang.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010010#include <spl.h>
Simon Glass90526e92020-05-10 11:39:56 -060011#include <asm/cache.h>
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010012#include <asm/io.h>
Patrick Delaunay006ea182019-02-27 17:01:14 +010013#include <asm/arch/sys_proto.h>
14#include <linux/libfdt.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010015
16u32 spl_boot_device(void)
17{
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010018 u32 boot_mode;
19
Patrick Delaunay7f63c1e2019-02-27 17:01:12 +010020 boot_mode = get_bootmode();
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010021
22 switch (boot_mode) {
23 case BOOT_FLASH_SD_1:
24 case BOOT_FLASH_EMMC_1:
25 return BOOT_DEVICE_MMC1;
26 case BOOT_FLASH_SD_2:
27 case BOOT_FLASH_EMMC_2:
28 return BOOT_DEVICE_MMC2;
Patrick Delaunay7f63c1e2019-02-27 17:01:12 +010029 case BOOT_SERIAL_UART_1:
30 case BOOT_SERIAL_UART_2:
31 case BOOT_SERIAL_UART_3:
32 case BOOT_SERIAL_UART_4:
33 case BOOT_SERIAL_UART_5:
34 case BOOT_SERIAL_UART_6:
35 case BOOT_SERIAL_UART_7:
36 case BOOT_SERIAL_UART_8:
37 return BOOT_DEVICE_UART;
38 case BOOT_SERIAL_USB_OTG:
39 return BOOT_DEVICE_USB;
40 case BOOT_FLASH_NAND_FMC:
41 return BOOT_DEVICE_NAND;
42 case BOOT_FLASH_NOR_QSPI:
43 return BOOT_DEVICE_SPI;
Patrick Delaunayb664a742020-03-18 09:22:52 +010044 case BOOT_FLASH_SPINAND_1:
45 return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010046 }
47
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010048 return BOOT_DEVICE_MMC1;
49}
50
Harald Seilere9759062020-04-15 11:33:30 +020051u32 spl_mmc_boot_mode(const u32 boot_device)
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010052{
53 return MMCSD_MODE_RAW;
54}
55
Harald Seilerc51b7512020-04-15 11:33:31 +020056int spl_mmc_boot_partition(const u32 boot_device)
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010057{
58 switch (boot_device) {
59 case BOOT_DEVICE_MMC1:
60 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
61 case BOOT_DEVICE_MMC2:
62 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
63 default:
64 return -EINVAL;
65 }
66}
67
Patrick Delaunay006ea182019-02-27 17:01:14 +010068#ifdef CONFIG_SPL_DISPLAY_PRINT
69void spl_display_print(void)
70{
71 DECLARE_GLOBAL_DATA_PTR;
72 const char *model;
73
74 /* same code than show_board_info() but not compiled for SPL
75 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
76 */
77 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
78 if (model)
79 printf("Model: %s\n", model);
80}
81#endif
82
Marek Vasut65e38e82020-04-22 13:18:10 +020083__weak int board_early_init_f(void)
84{
85 return 0;
86}
87
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010088void board_init_f(ulong dummy)
89{
90 struct udevice *dev;
91 int ret;
92
93 arch_cpu_init();
94
95 ret = spl_early_init();
96 if (ret) {
97 debug("spl_early_init() failed: %d\n", ret);
98 hang();
99 }
100
101 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
102 if (ret) {
103 debug("Clock init failed: %d\n", ret);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200104 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100105 }
106
107 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
108 if (ret) {
109 debug("Reset init failed: %d\n", ret);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200110 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100111 }
112
113 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
114 if (ret) {
115 debug("%s: Cannot find pinctrl device\n", __func__);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200116 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100117 }
118
119 /* enable console uart printing */
120 preloader_console_init();
121
Marek Vasut65e38e82020-04-22 13:18:10 +0200122 ret = board_early_init_f();
123 if (ret) {
124 debug("board_early_init_f() failed: %d\n", ret);
125 hang();
126 }
127
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100128 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
129 if (ret) {
Patrick Delaunay105a5ad2019-02-27 17:01:17 +0100130 printf("DRAM init failed: %d\n", ret);
131 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100132 }
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +0200133
134 /*
135 * activate cache on DDR only when DDR is fully initialized
136 * to avoid speculative access and issue in get_ram_size()
137 */
138 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
139 mmu_set_region_dcache_behaviour(STM32_DDR_BASE, STM32_DDR_SIZE,
140 DCACHE_DEFAULT_OPTION);
141}
142
143void spl_board_prepare_for_boot(void)
144{
145 dcache_disable();
146}
147
148void spl_board_prepare_for_boot_linux(void)
149{
150 dcache_disable();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100151}