Merge tag 'u-boot-stm32-20190723' of https://gitlab.denx.de/u-boot/custodians/u-boot-stm
[oweals/u-boot.git] / arch / arm / mach-stm32mp / spl.c
1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2 /*
3  * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <spl.h>
9 #include <asm/io.h>
10 #include <asm/arch/sys_proto.h>
11 #include <linux/libfdt.h>
12
13 u32 spl_boot_device(void)
14 {
15         u32 boot_mode;
16
17         boot_mode = get_bootmode();
18
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;
26         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;
41         }
42
43         return BOOT_DEVICE_MMC1;
44 }
45
46 u32 spl_boot_mode(const u32 boot_device)
47 {
48         return MMCSD_MODE_RAW;
49 }
50
51 int 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
63 #ifdef CONFIG_SPL_DISPLAY_PRINT
64 void 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
78 void 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) {
114                 printf("DRAM init failed: %d\n", ret);
115                 hang();
116         }
117 }