blob: 0c50ad54df6a67927e41c3d79bf410b8d74f73c9 [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
Patrick Delaunayeb653ac2020-11-06 19:01:29 +01006#define LOG_CATEGORY LOGC_ARCH
7
Patrick Delaunay2514c2d2018-03-12 10:46:10 +01008#include <common.h>
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +02009#include <cpu_func.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010010#include <dm.h>
Simon Glassdb41d652019-12-28 10:45:07 -070011#include <hang.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010014#include <spl.h>
Simon Glass90526e92020-05-10 11:39:56 -060015#include <asm/cache.h>
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010016#include <asm/io.h>
Patrick Delaunay006ea182019-02-27 17:01:14 +010017#include <asm/arch/sys_proto.h>
18#include <linux/libfdt.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010019
20u32 spl_boot_device(void)
21{
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010022 u32 boot_mode;
23
Patrick Delaunay7f63c1e2019-02-27 17:01:12 +010024 boot_mode = get_bootmode();
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010025
26 switch (boot_mode) {
27 case BOOT_FLASH_SD_1:
28 case BOOT_FLASH_EMMC_1:
29 return BOOT_DEVICE_MMC1;
30 case BOOT_FLASH_SD_2:
31 case BOOT_FLASH_EMMC_2:
32 return BOOT_DEVICE_MMC2;
Patrick Delaunay7f63c1e2019-02-27 17:01:12 +010033 case BOOT_SERIAL_UART_1:
34 case BOOT_SERIAL_UART_2:
35 case BOOT_SERIAL_UART_3:
36 case BOOT_SERIAL_UART_4:
37 case BOOT_SERIAL_UART_5:
38 case BOOT_SERIAL_UART_6:
39 case BOOT_SERIAL_UART_7:
40 case BOOT_SERIAL_UART_8:
41 return BOOT_DEVICE_UART;
42 case BOOT_SERIAL_USB_OTG:
43 return BOOT_DEVICE_USB;
44 case BOOT_FLASH_NAND_FMC:
45 return BOOT_DEVICE_NAND;
46 case BOOT_FLASH_NOR_QSPI:
47 return BOOT_DEVICE_SPI;
Patrick Delaunayb664a742020-03-18 09:22:52 +010048 case BOOT_FLASH_SPINAND_1:
49 return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010050 }
51
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010052 return BOOT_DEVICE_MMC1;
53}
54
Harald Seilere9759062020-04-15 11:33:30 +020055u32 spl_mmc_boot_mode(const u32 boot_device)
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010056{
57 return MMCSD_MODE_RAW;
58}
59
Richard Genoud40426d62020-10-12 16:11:09 +020060#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
Harald Seilerc51b7512020-04-15 11:33:31 +020061int spl_mmc_boot_partition(const u32 boot_device)
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010062{
63 switch (boot_device) {
64 case BOOT_DEVICE_MMC1:
65 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
66 case BOOT_DEVICE_MMC2:
67 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
68 default:
69 return -EINVAL;
70 }
71}
Richard Genoud40426d62020-10-12 16:11:09 +020072#endif
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010073
Patrick Delaunay006ea182019-02-27 17:01:14 +010074#ifdef CONFIG_SPL_DISPLAY_PRINT
75void spl_display_print(void)
76{
77 DECLARE_GLOBAL_DATA_PTR;
78 const char *model;
79
80 /* same code than show_board_info() but not compiled for SPL
81 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
82 */
83 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
84 if (model)
Patrick Delaunayeb653ac2020-11-06 19:01:29 +010085 log_info("Model: %s\n", model);
Patrick Delaunay006ea182019-02-27 17:01:14 +010086}
87#endif
88
Marek Vasut65e38e82020-04-22 13:18:10 +020089__weak int board_early_init_f(void)
90{
91 return 0;
92}
93
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010094void board_init_f(ulong dummy)
95{
96 struct udevice *dev;
97 int ret;
98
99 arch_cpu_init();
100
101 ret = spl_early_init();
102 if (ret) {
Patrick Delaunayeb653ac2020-11-06 19:01:29 +0100103 log_debug("spl_early_init() failed: %d\n", ret);
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100104 hang();
105 }
106
107 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
108 if (ret) {
Patrick Delaunayeb653ac2020-11-06 19:01:29 +0100109 log_debug("Clock 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_RESET, 0, &dev);
114 if (ret) {
Patrick Delaunayeb653ac2020-11-06 19:01:29 +0100115 log_debug("Reset init failed: %d\n", ret);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200116 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100117 }
118
119 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
120 if (ret) {
Patrick Delaunayeb653ac2020-11-06 19:01:29 +0100121 log_debug("%s: Cannot find pinctrl device\n", __func__);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200122 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100123 }
124
125 /* enable console uart printing */
126 preloader_console_init();
127
Marek Vasut65e38e82020-04-22 13:18:10 +0200128 ret = board_early_init_f();
129 if (ret) {
Patrick Delaunayeb653ac2020-11-06 19:01:29 +0100130 log_debug("board_early_init_f() failed: %d\n", ret);
Marek Vasut65e38e82020-04-22 13:18:10 +0200131 hang();
132 }
133
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100134 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
135 if (ret) {
Patrick Delaunayeb653ac2020-11-06 19:01:29 +0100136 log_err("DRAM init failed: %d\n", ret);
Patrick Delaunay105a5ad2019-02-27 17:01:17 +0100137 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100138 }
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +0200139
140 /*
141 * activate cache on DDR only when DDR is fully initialized
142 * to avoid speculative access and issue in get_ram_size()
143 */
144 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Patrick Delaunay67f9f112020-09-04 12:55:19 +0200145 mmu_set_region_dcache_behaviour(STM32_DDR_BASE,
146 CONFIG_DDR_CACHEABLE_SIZE,
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +0200147 DCACHE_DEFAULT_OPTION);
148}
149
150void spl_board_prepare_for_boot(void)
151{
152 dcache_disable();
153}
154
Patrick Delaunay346034a2020-07-07 14:21:53 +0200155void spl_board_prepare_for_linux(void)
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +0200156{
157 dcache_disable();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100158}