blob: b7e7e92ef678d758018e4441ef9c15d033081ec9 [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>
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010011#include <asm/io.h>
Patrick Delaunay006ea182019-02-27 17:01:14 +010012#include <asm/arch/sys_proto.h>
13#include <linux/libfdt.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010014
15u32 spl_boot_device(void)
16{
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010017 u32 boot_mode;
18
Patrick Delaunay7f63c1e2019-02-27 17:01:12 +010019 boot_mode = get_bootmode();
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010020
21 switch (boot_mode) {
22 case BOOT_FLASH_SD_1:
23 case BOOT_FLASH_EMMC_1:
24 return BOOT_DEVICE_MMC1;
25 case BOOT_FLASH_SD_2:
26 case BOOT_FLASH_EMMC_2:
27 return BOOT_DEVICE_MMC2;
Patrick Delaunay7f63c1e2019-02-27 17:01:12 +010028 case BOOT_SERIAL_UART_1:
29 case BOOT_SERIAL_UART_2:
30 case BOOT_SERIAL_UART_3:
31 case BOOT_SERIAL_UART_4:
32 case BOOT_SERIAL_UART_5:
33 case BOOT_SERIAL_UART_6:
34 case BOOT_SERIAL_UART_7:
35 case BOOT_SERIAL_UART_8:
36 return BOOT_DEVICE_UART;
37 case BOOT_SERIAL_USB_OTG:
38 return BOOT_DEVICE_USB;
39 case BOOT_FLASH_NAND_FMC:
40 return BOOT_DEVICE_NAND;
41 case BOOT_FLASH_NOR_QSPI:
42 return BOOT_DEVICE_SPI;
Patrick Delaunayb664a742020-03-18 09:22:52 +010043 case BOOT_FLASH_SPINAND_1:
44 return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010045 }
46
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010047 return BOOT_DEVICE_MMC1;
48}
49
Harald Seilere9759062020-04-15 11:33:30 +020050u32 spl_mmc_boot_mode(const u32 boot_device)
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010051{
52 return MMCSD_MODE_RAW;
53}
54
Harald Seilerc51b7512020-04-15 11:33:31 +020055int spl_mmc_boot_partition(const u32 boot_device)
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010056{
57 switch (boot_device) {
58 case BOOT_DEVICE_MMC1:
59 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
60 case BOOT_DEVICE_MMC2:
61 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
62 default:
63 return -EINVAL;
64 }
65}
66
Patrick Delaunay006ea182019-02-27 17:01:14 +010067#ifdef CONFIG_SPL_DISPLAY_PRINT
68void spl_display_print(void)
69{
70 DECLARE_GLOBAL_DATA_PTR;
71 const char *model;
72
73 /* same code than show_board_info() but not compiled for SPL
74 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
75 */
76 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
77 if (model)
78 printf("Model: %s\n", model);
79}
80#endif
81
Marek Vasut65e38e82020-04-22 13:18:10 +020082__weak int board_early_init_f(void)
83{
84 return 0;
85}
86
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010087void board_init_f(ulong dummy)
88{
89 struct udevice *dev;
90 int ret;
91
92 arch_cpu_init();
93
94 ret = spl_early_init();
95 if (ret) {
96 debug("spl_early_init() failed: %d\n", ret);
97 hang();
98 }
99
100 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
101 if (ret) {
102 debug("Clock init failed: %d\n", ret);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200103 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100104 }
105
106 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
107 if (ret) {
108 debug("Reset init failed: %d\n", ret);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200109 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100110 }
111
112 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
113 if (ret) {
114 debug("%s: Cannot find pinctrl device\n", __func__);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200115 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100116 }
117
118 /* enable console uart printing */
119 preloader_console_init();
120
Marek Vasut65e38e82020-04-22 13:18:10 +0200121 ret = board_early_init_f();
122 if (ret) {
123 debug("board_early_init_f() failed: %d\n", ret);
124 hang();
125 }
126
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100127 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
128 if (ret) {
Patrick Delaunay105a5ad2019-02-27 17:01:17 +0100129 printf("DRAM init failed: %d\n", ret);
130 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100131 }
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +0200132
133 /*
134 * activate cache on DDR only when DDR is fully initialized
135 * to avoid speculative access and issue in get_ram_size()
136 */
137 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
138 mmu_set_region_dcache_behaviour(STM32_DDR_BASE, STM32_DDR_SIZE,
139 DCACHE_DEFAULT_OPTION);
140}
141
142void spl_board_prepare_for_boot(void)
143{
144 dcache_disable();
145}
146
147void spl_board_prepare_for_boot_linux(void)
148{
149 dcache_disable();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100150}