blob: 9fbc3ac953dabbd066b4a959471f3bf53cdebac9 [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>
7#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -07008#include <hang.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +01009#include <spl.h>
Patrick Delaunayfc69c682018-03-20 10:54:54 +010010#include <asm/io.h>
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010011#include <asm/arch/sys_proto.h>
12#include <linux/libfdt.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010013
14u32 spl_boot_device(void)
15{
Patrick Delaunayfc69c682018-03-20 10:54:54 +010016 u32 boot_mode;
17
Patrick Delaunay18660a62019-02-27 17:01:12 +010018 boot_mode = get_bootmode();
Patrick Delaunayfc69c682018-03-20 10:54:54 +010019
20 switch (boot_mode) {
21 case BOOT_FLASH_SD_1:
22 case BOOT_FLASH_EMMC_1:
23 return BOOT_DEVICE_MMC1;
24 case BOOT_FLASH_SD_2:
25 case BOOT_FLASH_EMMC_2:
26 return BOOT_DEVICE_MMC2;
Patrick Delaunay18660a62019-02-27 17:01:12 +010027 case BOOT_SERIAL_UART_1:
28 case BOOT_SERIAL_UART_2:
29 case BOOT_SERIAL_UART_3:
30 case BOOT_SERIAL_UART_4:
31 case BOOT_SERIAL_UART_5:
32 case BOOT_SERIAL_UART_6:
33 case BOOT_SERIAL_UART_7:
34 case BOOT_SERIAL_UART_8:
35 return BOOT_DEVICE_UART;
36 case BOOT_SERIAL_USB_OTG:
37 return BOOT_DEVICE_USB;
38 case BOOT_FLASH_NAND_FMC:
39 return BOOT_DEVICE_NAND;
40 case BOOT_FLASH_NOR_QSPI:
41 return BOOT_DEVICE_SPI;
Patrick Delaunayfc69c682018-03-20 10:54:54 +010042 }
43
Patrick Delaunay85b53972018-03-12 10:46:10 +010044 return BOOT_DEVICE_MMC1;
45}
46
Harald Seiler0bf7ab12020-04-15 11:33:30 +020047u32 spl_mmc_boot_mode(const u32 boot_device)
Patrick Delaunay85b53972018-03-12 10:46:10 +010048{
49 return MMCSD_MODE_RAW;
50}
51
Harald Seilerbf16c302020-04-15 11:33:31 +020052int spl_mmc_boot_partition(const u32 boot_device)
Patrick Delaunayfc69c682018-03-20 10:54:54 +010053{
54 switch (boot_device) {
55 case BOOT_DEVICE_MMC1:
56 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
57 case BOOT_DEVICE_MMC2:
58 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
59 default:
60 return -EINVAL;
61 }
62}
63
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010064#ifdef CONFIG_SPL_DISPLAY_PRINT
65void spl_display_print(void)
66{
67 DECLARE_GLOBAL_DATA_PTR;
68 const char *model;
69
70 /* same code than show_board_info() but not compiled for SPL
71 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
72 */
73 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
74 if (model)
75 printf("Model: %s\n", model);
76}
77#endif
78
Marek Vasut70f85272020-04-22 13:18:10 +020079__weak int board_early_init_f(void)
80{
81 return 0;
82}
83
Patrick Delaunay85b53972018-03-12 10:46:10 +010084void board_init_f(ulong dummy)
85{
86 struct udevice *dev;
87 int ret;
88
89 arch_cpu_init();
90
91 ret = spl_early_init();
92 if (ret) {
93 debug("spl_early_init() failed: %d\n", ret);
94 hang();
95 }
96
97 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
98 if (ret) {
99 debug("Clock init failed: %d\n", ret);
100 return;
101 }
102
103 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
104 if (ret) {
105 debug("Reset init failed: %d\n", ret);
106 return;
107 }
108
109 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
110 if (ret) {
111 debug("%s: Cannot find pinctrl device\n", __func__);
112 return;
113 }
114
115 /* enable console uart printing */
116 preloader_console_init();
117
Marek Vasut70f85272020-04-22 13:18:10 +0200118 ret = board_early_init_f();
119 if (ret) {
120 debug("board_early_init_f() failed: %d\n", ret);
121 hang();
122 }
123
Patrick Delaunay85b53972018-03-12 10:46:10 +0100124 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
125 if (ret) {
Patrick Delaunaybb8de082019-02-27 17:01:17 +0100126 printf("DRAM init failed: %d\n", ret);
127 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100128 }
129}