blob: 8ac291406ad762d02229020bc9009fd2ad12aaa6 [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
6#include <common.h>
Patrick Delaunay1a4f7cd2020-04-30 16:30:21 +02007#include <cpu_func.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +01008#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010011#include <spl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <asm/cache.h>
Patrick Delaunayfc69c682018-03-20 10:54:54 +010013#include <asm/io.h>
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010014#include <asm/arch/sys_proto.h>
15#include <linux/libfdt.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010016
17u32 spl_boot_device(void)
18{
Patrick Delaunayfc69c682018-03-20 10:54:54 +010019 u32 boot_mode;
20
Patrick Delaunay18660a62019-02-27 17:01:12 +010021 boot_mode = get_bootmode();
Patrick Delaunayfc69c682018-03-20 10:54:54 +010022
23 switch (boot_mode) {
24 case BOOT_FLASH_SD_1:
25 case BOOT_FLASH_EMMC_1:
26 return BOOT_DEVICE_MMC1;
27 case BOOT_FLASH_SD_2:
28 case BOOT_FLASH_EMMC_2:
29 return BOOT_DEVICE_MMC2;
Patrick Delaunay18660a62019-02-27 17:01:12 +010030 case BOOT_SERIAL_UART_1:
31 case BOOT_SERIAL_UART_2:
32 case BOOT_SERIAL_UART_3:
33 case BOOT_SERIAL_UART_4:
34 case BOOT_SERIAL_UART_5:
35 case BOOT_SERIAL_UART_6:
36 case BOOT_SERIAL_UART_7:
37 case BOOT_SERIAL_UART_8:
38 return BOOT_DEVICE_UART;
39 case BOOT_SERIAL_USB_OTG:
40 return BOOT_DEVICE_USB;
41 case BOOT_FLASH_NAND_FMC:
42 return BOOT_DEVICE_NAND;
43 case BOOT_FLASH_NOR_QSPI:
44 return BOOT_DEVICE_SPI;
Patrick Delaunayb5a7ca22020-03-18 09:22:52 +010045 case BOOT_FLASH_SPINAND_1:
46 return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
Patrick Delaunayfc69c682018-03-20 10:54:54 +010047 }
48
Patrick Delaunay85b53972018-03-12 10:46:10 +010049 return BOOT_DEVICE_MMC1;
50}
51
Harald Seiler0bf7ab12020-04-15 11:33:30 +020052u32 spl_mmc_boot_mode(const u32 boot_device)
Patrick Delaunay85b53972018-03-12 10:46:10 +010053{
54 return MMCSD_MODE_RAW;
55}
56
Harald Seilerbf16c302020-04-15 11:33:31 +020057int spl_mmc_boot_partition(const u32 boot_device)
Patrick Delaunayfc69c682018-03-20 10:54:54 +010058{
59 switch (boot_device) {
60 case BOOT_DEVICE_MMC1:
61 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
62 case BOOT_DEVICE_MMC2:
63 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
64 default:
65 return -EINVAL;
66 }
67}
68
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010069#ifdef CONFIG_SPL_DISPLAY_PRINT
70void spl_display_print(void)
71{
72 DECLARE_GLOBAL_DATA_PTR;
73 const char *model;
74
75 /* same code than show_board_info() but not compiled for SPL
76 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
77 */
78 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
79 if (model)
80 printf("Model: %s\n", model);
81}
82#endif
83
Marek Vasut70f85272020-04-22 13:18:10 +020084__weak int board_early_init_f(void)
85{
86 return 0;
87}
88
Patrick Delaunay85b53972018-03-12 10:46:10 +010089void board_init_f(ulong dummy)
90{
91 struct udevice *dev;
92 int ret;
93
94 arch_cpu_init();
95
96 ret = spl_early_init();
97 if (ret) {
98 debug("spl_early_init() failed: %d\n", ret);
99 hang();
100 }
101
102 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
103 if (ret) {
104 debug("Clock init failed: %d\n", ret);
Patrick Delaunay60fa0632020-04-22 14:29:10 +0200105 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100106 }
107
108 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
109 if (ret) {
110 debug("Reset 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_PINCTRL, 0, &dev);
115 if (ret) {
116 debug("%s: Cannot find pinctrl device\n", __func__);
Patrick Delaunay60fa0632020-04-22 14:29:10 +0200117 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100118 }
119
120 /* enable console uart printing */
121 preloader_console_init();
122
Marek Vasut70f85272020-04-22 13:18:10 +0200123 ret = board_early_init_f();
124 if (ret) {
125 debug("board_early_init_f() failed: %d\n", ret);
126 hang();
127 }
128
Patrick Delaunay85b53972018-03-12 10:46:10 +0100129 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
130 if (ret) {
Patrick Delaunaybb8de082019-02-27 17:01:17 +0100131 printf("DRAM init failed: %d\n", ret);
132 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100133 }
Patrick Delaunay1a4f7cd2020-04-30 16:30:21 +0200134
135 /*
136 * activate cache on DDR only when DDR is fully initialized
137 * to avoid speculative access and issue in get_ram_size()
138 */
139 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
140 mmu_set_region_dcache_behaviour(STM32_DDR_BASE, STM32_DDR_SIZE,
141 DCACHE_DEFAULT_OPTION);
142}
143
144void spl_board_prepare_for_boot(void)
145{
146 dcache_disable();
147}
148
149void spl_board_prepare_for_boot_linux(void)
150{
151 dcache_disable();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100152}