blob: a3b0d6f38252a63a4e564e86e4adb1f6aaf52a2f [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>
8#include <spl.h>
Patrick Delaunayfc69c682018-03-20 10:54:54 +01009#include <asm/io.h>
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010010#include <asm/arch/sys_proto.h>
11#include <linux/libfdt.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010012
13u32 spl_boot_device(void)
14{
Patrick Delaunayfc69c682018-03-20 10:54:54 +010015 u32 boot_mode;
16
Patrick Delaunay18660a62019-02-27 17:01:12 +010017 boot_mode = get_bootmode();
Patrick Delaunayfc69c682018-03-20 10:54:54 +010018
19 switch (boot_mode) {
20 case BOOT_FLASH_SD_1:
21 case BOOT_FLASH_EMMC_1:
22 return BOOT_DEVICE_MMC1;
23 case BOOT_FLASH_SD_2:
24 case BOOT_FLASH_EMMC_2:
25 return BOOT_DEVICE_MMC2;
Patrick Delaunay18660a62019-02-27 17:01:12 +010026 case BOOT_SERIAL_UART_1:
27 case BOOT_SERIAL_UART_2:
28 case BOOT_SERIAL_UART_3:
29 case BOOT_SERIAL_UART_4:
30 case BOOT_SERIAL_UART_5:
31 case BOOT_SERIAL_UART_6:
32 case BOOT_SERIAL_UART_7:
33 case BOOT_SERIAL_UART_8:
34 return BOOT_DEVICE_UART;
35 case BOOT_SERIAL_USB_OTG:
36 return BOOT_DEVICE_USB;
37 case BOOT_FLASH_NAND_FMC:
38 return BOOT_DEVICE_NAND;
39 case BOOT_FLASH_NOR_QSPI:
40 return BOOT_DEVICE_SPI;
Patrick Delaunayfc69c682018-03-20 10:54:54 +010041 }
42
Patrick Delaunay85b53972018-03-12 10:46:10 +010043 return BOOT_DEVICE_MMC1;
44}
45
46u32 spl_boot_mode(const u32 boot_device)
47{
48 return MMCSD_MODE_RAW;
49}
50
Patrick Delaunayfc69c682018-03-20 10:54:54 +010051int spl_boot_partition(const u32 boot_device)
52{
53 switch (boot_device) {
54 case BOOT_DEVICE_MMC1:
55 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
56 case BOOT_DEVICE_MMC2:
57 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
58 default:
59 return -EINVAL;
60 }
61}
62
Patrick Delaunayaa4e6852019-02-27 17:01:14 +010063#ifdef CONFIG_SPL_DISPLAY_PRINT
64void spl_display_print(void)
65{
66 DECLARE_GLOBAL_DATA_PTR;
67 const char *model;
68
69 /* same code than show_board_info() but not compiled for SPL
70 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
71 */
72 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
73 if (model)
74 printf("Model: %s\n", model);
75}
76#endif
77
Patrick Delaunay85b53972018-03-12 10:46:10 +010078void board_init_f(ulong dummy)
79{
80 struct udevice *dev;
81 int ret;
82
83 arch_cpu_init();
84
85 ret = spl_early_init();
86 if (ret) {
87 debug("spl_early_init() failed: %d\n", ret);
88 hang();
89 }
90
91 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
92 if (ret) {
93 debug("Clock init failed: %d\n", ret);
94 return;
95 }
96
97 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
98 if (ret) {
99 debug("Reset init failed: %d\n", ret);
100 return;
101 }
102
103 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
104 if (ret) {
105 debug("%s: Cannot find pinctrl device\n", __func__);
106 return;
107 }
108
109 /* enable console uart printing */
110 preloader_console_init();
111
112 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
113 if (ret) {
Patrick Delaunaybb8de082019-02-27 17:01:17 +0100114 printf("DRAM init failed: %d\n", ret);
115 hang();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100116 }
117}