blob: b53659a698ad8ace64441746658185e51fe94aa6 [file] [log] [blame]
Tom Rini8b0c8a12018-05-06 18:27:01 -04001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Patrick Delaunay85b53972018-03-12 10:46:10 +01002/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunay85b53972018-03-12 10:46:10 +01004 */
5
Patrick Delaunayba779402020-11-06 19:01:29 +01006#define LOG_CATEGORY LOGC_ARCH
7
Patrick Delaunay85b53972018-03-12 10:46:10 +01008#include <common.h>
Patrick Delaunay1a4f7cd2020-04-30 16:30:21 +02009#include <cpu_func.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010010#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -070011#include <hang.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010014#include <spl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Patrick Delaunayfc69c682018-03-20 10:54:54 +010017#include <asm/io.h>
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010018#include <asm/arch/sys_proto.h>
19#include <linux/libfdt.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010020
21u32 spl_boot_device(void)
22{
Patrick Delaunayfc69c682018-03-20 10:54:54 +010023 u32 boot_mode;
24
Patrick Delaunay18660a62019-02-27 17:01:12 +010025 boot_mode = get_bootmode();
Patrick Delaunayfc69c682018-03-20 10:54:54 +010026
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;
Patrick Delaunay18660a62019-02-27 17:01:12 +010034 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;
Patrick Delaunayb5a7ca22020-03-18 09:22:52 +010049 case BOOT_FLASH_SPINAND_1:
50 return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
Patrick Delaunayfc69c682018-03-20 10:54:54 +010051 }
52
Patrick Delaunay85b53972018-03-12 10:46:10 +010053 return BOOT_DEVICE_MMC1;
54}
55
Harald Seiler0bf7ab12020-04-15 11:33:30 +020056u32 spl_mmc_boot_mode(const u32 boot_device)
Patrick Delaunay85b53972018-03-12 10:46:10 +010057{
58 return MMCSD_MODE_RAW;
59}
60
Richard Genoude93ee7b2020-10-12 16:11:09 +020061#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
Harald Seilerbf16c302020-04-15 11:33:31 +020062int spl_mmc_boot_partition(const u32 boot_device)
Patrick Delaunayfc69c682018-03-20 10:54:54 +010063{
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}
Richard Genoude93ee7b2020-10-12 16:11:09 +020073#endif
Patrick Delaunayfc69c682018-03-20 10:54:54 +010074
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010075#ifdef CONFIG_SPL_DISPLAY_PRINT
76void 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)
Patrick Delaunayba779402020-11-06 19:01:29 +010086 log_info("Model: %s\n", model);
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010087}
88#endif
89
Marek Vasut70f85272020-04-22 13:18:10 +020090__weak int board_early_init_f(void)
91{
92 return 0;
93}
94
Patrick Delaunay85b53972018-03-12 10:46:10 +010095void 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) {
Patrick Delaunayba779402020-11-06 19:01:29 +0100104 log_debug("spl_early_init() failed: %d\n", ret);
Patrick Delaunay85b53972018-03-12 10:46:10 +0100105 hang();
106 }
107
108 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
109 if (ret) {
Patrick Delaunayba779402020-11-06 19:01:29 +0100110 log_debug("Clock init failed: %d\n", ret);
Patrick Delaunay60fa0632020-04-22 14:29:10 +0200111 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100112 }
113
114 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
115 if (ret) {
Patrick Delaunayba779402020-11-06 19:01:29 +0100116 log_debug("Reset init failed: %d\n", ret);
Patrick Delaunay60fa0632020-04-22 14:29:10 +0200117 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100118 }
119
120 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
121 if (ret) {
Patrick Delaunayba779402020-11-06 19:01:29 +0100122 log_debug("%s: Cannot find pinctrl device\n", __func__);
Patrick Delaunay60fa0632020-04-22 14:29:10 +0200123 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100124 }
125
126 /* enable console uart printing */
127 preloader_console_init();
128
Marek Vasut70f85272020-04-22 13:18:10 +0200129 ret = board_early_init_f();
130 if (ret) {
Patrick Delaunayba779402020-11-06 19:01:29 +0100131 log_debug("board_early_init_f() failed: %d\n", ret);
Marek Vasut70f85272020-04-22 13:18:10 +0200132 hang();
133 }
134
Patrick Delaunay85b53972018-03-12 10:46:10 +0100135 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
136 if (ret) {
Patrick Delaunayba779402020-11-06 19:01:29 +0100137 log_err("DRAM init failed: %d\n", ret);
Patrick Delaunaybb8de082019-02-27 17:01:17 +0100138 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100139 }
Patrick Delaunay1a4f7cd2020-04-30 16:30:21 +0200140
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))
Patrick Delaunayab7d6442020-09-04 12:55:19 +0200146 mmu_set_region_dcache_behaviour(STM32_DDR_BASE,
147 CONFIG_DDR_CACHEABLE_SIZE,
Patrick Delaunay1a4f7cd2020-04-30 16:30:21 +0200148 DCACHE_DEFAULT_OPTION);
149}
150
151void spl_board_prepare_for_boot(void)
152{
153 dcache_disable();
154}
155
Patrick Delaunay3188ee92020-07-07 14:21:53 +0200156void spl_board_prepare_for_linux(void)
Patrick Delaunay1a4f7cd2020-04-30 16:30:21 +0200157{
158 dcache_disable();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100159}