blob: 66a634654eef7c671e2b274a12d3b40d4beb2990 [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>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010012#include <spl.h>
Simon Glass90526e92020-05-10 11:39:56 -060013#include <asm/cache.h>
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010014#include <asm/io.h>
Patrick Delaunay006ea182019-02-27 17:01:14 +010015#include <asm/arch/sys_proto.h>
16#include <linux/libfdt.h>
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010017
18u32 spl_boot_device(void)
19{
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010020 u32 boot_mode;
21
Patrick Delaunay7f63c1e2019-02-27 17:01:12 +010022 boot_mode = get_bootmode();
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010023
24 switch (boot_mode) {
25 case BOOT_FLASH_SD_1:
26 case BOOT_FLASH_EMMC_1:
27 return BOOT_DEVICE_MMC1;
28 case BOOT_FLASH_SD_2:
29 case BOOT_FLASH_EMMC_2:
30 return BOOT_DEVICE_MMC2;
Patrick Delaunay7f63c1e2019-02-27 17:01:12 +010031 case BOOT_SERIAL_UART_1:
32 case BOOT_SERIAL_UART_2:
33 case BOOT_SERIAL_UART_3:
34 case BOOT_SERIAL_UART_4:
35 case BOOT_SERIAL_UART_5:
36 case BOOT_SERIAL_UART_6:
37 case BOOT_SERIAL_UART_7:
38 case BOOT_SERIAL_UART_8:
39 return BOOT_DEVICE_UART;
40 case BOOT_SERIAL_USB_OTG:
41 return BOOT_DEVICE_USB;
42 case BOOT_FLASH_NAND_FMC:
43 return BOOT_DEVICE_NAND;
44 case BOOT_FLASH_NOR_QSPI:
45 return BOOT_DEVICE_SPI;
Patrick Delaunayb664a742020-03-18 09:22:52 +010046 case BOOT_FLASH_SPINAND_1:
47 return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010048 }
49
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010050 return BOOT_DEVICE_MMC1;
51}
52
Harald Seilere9759062020-04-15 11:33:30 +020053u32 spl_mmc_boot_mode(const u32 boot_device)
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010054{
55 return MMCSD_MODE_RAW;
56}
57
Richard Genoud40426d62020-10-12 16:11:09 +020058#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
Harald Seilerc51b7512020-04-15 11:33:31 +020059int spl_mmc_boot_partition(const u32 boot_device)
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010060{
61 switch (boot_device) {
62 case BOOT_DEVICE_MMC1:
63 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
64 case BOOT_DEVICE_MMC2:
65 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
66 default:
67 return -EINVAL;
68 }
69}
Richard Genoud40426d62020-10-12 16:11:09 +020070#endif
Patrick Delaunay11dfd1a2018-03-20 10:54:54 +010071
Patrick Delaunay006ea182019-02-27 17:01:14 +010072#ifdef CONFIG_SPL_DISPLAY_PRINT
73void spl_display_print(void)
74{
75 DECLARE_GLOBAL_DATA_PTR;
76 const char *model;
77
78 /* same code than show_board_info() but not compiled for SPL
79 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
80 */
81 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
82 if (model)
83 printf("Model: %s\n", model);
84}
85#endif
86
Marek Vasut65e38e82020-04-22 13:18:10 +020087__weak int board_early_init_f(void)
88{
89 return 0;
90}
91
Patrick Delaunay2514c2d2018-03-12 10:46:10 +010092void board_init_f(ulong dummy)
93{
94 struct udevice *dev;
95 int ret;
96
97 arch_cpu_init();
98
99 ret = spl_early_init();
100 if (ret) {
101 debug("spl_early_init() failed: %d\n", ret);
102 hang();
103 }
104
105 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
106 if (ret) {
107 debug("Clock init failed: %d\n", ret);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200108 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100109 }
110
111 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
112 if (ret) {
113 debug("Reset init failed: %d\n", ret);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200114 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100115 }
116
117 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
118 if (ret) {
119 debug("%s: Cannot find pinctrl device\n", __func__);
Patrick Delaunayeaec1f92020-04-22 14:29:10 +0200120 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100121 }
122
123 /* enable console uart printing */
124 preloader_console_init();
125
Marek Vasut65e38e82020-04-22 13:18:10 +0200126 ret = board_early_init_f();
127 if (ret) {
128 debug("board_early_init_f() failed: %d\n", ret);
129 hang();
130 }
131
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100132 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
133 if (ret) {
Patrick Delaunay105a5ad2019-02-27 17:01:17 +0100134 printf("DRAM init failed: %d\n", ret);
135 hang();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100136 }
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +0200137
138 /*
139 * activate cache on DDR only when DDR is fully initialized
140 * to avoid speculative access and issue in get_ram_size()
141 */
142 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Patrick Delaunay67f9f112020-09-04 12:55:19 +0200143 mmu_set_region_dcache_behaviour(STM32_DDR_BASE,
144 CONFIG_DDR_CACHEABLE_SIZE,
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +0200145 DCACHE_DEFAULT_OPTION);
146}
147
148void spl_board_prepare_for_boot(void)
149{
150 dcache_disable();
151}
152
Patrick Delaunay346034a2020-07-07 14:21:53 +0200153void spl_board_prepare_for_linux(void)
Patrick Delaunaydc7e5f12020-04-30 16:30:21 +0200154{
155 dcache_disable();
Patrick Delaunay2514c2d2018-03-12 10:46:10 +0100156}