blob: e84bdad7bfc06ab7329877638271df2f7e04c43a [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>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010012#include <spl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <asm/cache.h>
Patrick Delaunayfc69c682018-03-20 10:54:54 +010014#include <asm/io.h>
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010015#include <asm/arch/sys_proto.h>
16#include <linux/libfdt.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010017
18u32 spl_boot_device(void)
19{
Patrick Delaunayfc69c682018-03-20 10:54:54 +010020 u32 boot_mode;
21
Patrick Delaunay18660a62019-02-27 17:01:12 +010022 boot_mode = get_bootmode();
Patrick Delaunayfc69c682018-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 Delaunay18660a62019-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 Delaunayb5a7ca22020-03-18 09:22:52 +010046 case BOOT_FLASH_SPINAND_1:
47 return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
Patrick Delaunayfc69c682018-03-20 10:54:54 +010048 }
49
Patrick Delaunay85b53972018-03-12 10:46:10 +010050 return BOOT_DEVICE_MMC1;
51}
52
Harald Seiler0bf7ab12020-04-15 11:33:30 +020053u32 spl_mmc_boot_mode(const u32 boot_device)
Patrick Delaunay85b53972018-03-12 10:46:10 +010054{
55 return MMCSD_MODE_RAW;
56}
57
Harald Seilerbf16c302020-04-15 11:33:31 +020058int spl_mmc_boot_partition(const u32 boot_device)
Patrick Delaunayfc69c682018-03-20 10:54:54 +010059{
60 switch (boot_device) {
61 case BOOT_DEVICE_MMC1:
62 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
63 case BOOT_DEVICE_MMC2:
64 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
65 default:
66 return -EINVAL;
67 }
68}
69
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010070#ifdef CONFIG_SPL_DISPLAY_PRINT
71void spl_display_print(void)
72{
73 DECLARE_GLOBAL_DATA_PTR;
74 const char *model;
75
76 /* same code than show_board_info() but not compiled for SPL
77 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
78 */
79 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
80 if (model)
81 printf("Model: %s\n", model);
82}
83#endif
84
Marek Vasut70f85272020-04-22 13:18:10 +020085__weak int board_early_init_f(void)
86{
87 return 0;
88}
89
Patrick Delaunay85b53972018-03-12 10:46:10 +010090void board_init_f(ulong dummy)
91{
92 struct udevice *dev;
93 int ret;
94
95 arch_cpu_init();
96
97 ret = spl_early_init();
98 if (ret) {
99 debug("spl_early_init() failed: %d\n", ret);
100 hang();
101 }
102
103 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
104 if (ret) {
105 debug("Clock init failed: %d\n", ret);
Patrick Delaunay60fa0632020-04-22 14:29:10 +0200106 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100107 }
108
109 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
110 if (ret) {
111 debug("Reset init failed: %d\n", ret);
Patrick Delaunay60fa0632020-04-22 14:29:10 +0200112 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100113 }
114
115 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
116 if (ret) {
117 debug("%s: Cannot find pinctrl device\n", __func__);
Patrick Delaunay60fa0632020-04-22 14:29:10 +0200118 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100119 }
120
121 /* enable console uart printing */
122 preloader_console_init();
123
Marek Vasut70f85272020-04-22 13:18:10 +0200124 ret = board_early_init_f();
125 if (ret) {
126 debug("board_early_init_f() failed: %d\n", ret);
127 hang();
128 }
129
Patrick Delaunay85b53972018-03-12 10:46:10 +0100130 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
131 if (ret) {
Patrick Delaunaybb8de082019-02-27 17:01:17 +0100132 printf("DRAM init failed: %d\n", ret);
133 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100134 }
Patrick Delaunay1a4f7cd2020-04-30 16:30:21 +0200135
136 /*
137 * activate cache on DDR only when DDR is fully initialized
138 * to avoid speculative access and issue in get_ram_size()
139 */
140 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
141 mmu_set_region_dcache_behaviour(STM32_DDR_BASE, STM32_DDR_SIZE,
142 DCACHE_DEFAULT_OPTION);
143}
144
145void spl_board_prepare_for_boot(void)
146{
147 dcache_disable();
148}
149
Patrick Delaunay3188ee92020-07-07 14:21:53 +0200150void spl_board_prepare_for_linux(void)
Patrick Delaunay1a4f7cd2020-04-30 16:30:21 +0200151{
152 dcache_disable();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100153}