xref: /openbmc/u-boot/arch/arm/mach-stm32mp/spl.c (revision 23e8bd7e)
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 
11 u32 spl_boot_device(void)
12 {
13 	u32 boot_mode;
14 
15 	boot_mode = (readl(TAMP_BOOT_CONTEXT) & TAMP_BOOT_MODE_MASK) >>
16 		    TAMP_BOOT_MODE_SHIFT;
17 
18 	switch (boot_mode) {
19 	case BOOT_FLASH_SD_1:
20 	case BOOT_FLASH_EMMC_1:
21 		return BOOT_DEVICE_MMC1;
22 	case BOOT_FLASH_SD_2:
23 	case BOOT_FLASH_EMMC_2:
24 		return BOOT_DEVICE_MMC2;
25 	}
26 
27 	return BOOT_DEVICE_MMC1;
28 }
29 
30 u32 spl_boot_mode(const u32 boot_device)
31 {
32 	return MMCSD_MODE_RAW;
33 }
34 
35 int spl_boot_partition(const u32 boot_device)
36 {
37 	switch (boot_device) {
38 	case BOOT_DEVICE_MMC1:
39 		return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
40 	case BOOT_DEVICE_MMC2:
41 		return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
42 	default:
43 		return -EINVAL;
44 	}
45 }
46 
47 void board_init_f(ulong dummy)
48 {
49 	struct udevice *dev;
50 	int ret;
51 
52 	arch_cpu_init();
53 
54 	ret = spl_early_init();
55 	if (ret) {
56 		debug("spl_early_init() failed: %d\n", ret);
57 		hang();
58 	}
59 
60 	ret = uclass_get_device(UCLASS_CLK, 0, &dev);
61 	if (ret) {
62 		debug("Clock init failed: %d\n", ret);
63 		return;
64 	}
65 
66 	ret = uclass_get_device(UCLASS_RESET, 0, &dev);
67 	if (ret) {
68 		debug("Reset init failed: %d\n", ret);
69 		return;
70 	}
71 
72 	ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
73 	if (ret) {
74 		debug("%s: Cannot find pinctrl device\n", __func__);
75 		return;
76 	}
77 
78 	/* enable console uart printing */
79 	preloader_console_init();
80 
81 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
82 	if (ret) {
83 		debug("DRAM init failed: %d\n", ret);
84 		return;
85 	}
86 }
87