1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2 /*
3  * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
4  * Copyright (C) 2020 Engicam S.r.l.
5  * Copyright (C) 2020 Amarula Solutions(India)
6  * Author: Jagan Teki <jagan@amarulasolutions.com>
7  */
8 
9 #include <common.h>
10 #include <env.h>
11 #include <env_internal.h>
12 #include <syscon.h>
13 #include <asm/io.h>
14 #include <asm/arch/sys_proto.h>
15 #include <power/regulator.h>
16 
17 DECLARE_GLOBAL_DATA_PTR;
18 
checkboard(void)19 int checkboard(void)
20 {
21 	char *mode;
22 	const char *fdt_compat;
23 	int fdt_compat_len;
24 
25 	if (IS_ENABLED(CONFIG_TFABOOT))
26 		mode = "trusted";
27 	else
28 		mode = "basic";
29 
30 	printf("Board: stm32mp1 in %s mode", mode);
31 	fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
32 				 &fdt_compat_len);
33 	if (fdt_compat && fdt_compat_len)
34 		printf(" (%s)", fdt_compat);
35 	puts("\n");
36 
37 	return 0;
38 }
39 
40 /* board dependent setup after realloc */
board_init(void)41 int board_init(void)
42 {
43 	if (IS_ENABLED(CONFIG_DM_REGULATOR))
44 		regulators_enable_boot_on(_DEBUG);
45 
46 	return 0;
47 }
48 
board_late_init(void)49 int board_late_init(void)
50 {
51 	return 0;
52 }
53 
env_get_location(enum env_operation op,int prio)54 enum env_location env_get_location(enum env_operation op, int prio)
55 {
56 	u32 bootmode = get_bootmode();
57 
58 	if (prio)
59 		return ENVL_UNKNOWN;
60 
61 	switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
62 	case BOOT_FLASH_SD:
63 	case BOOT_FLASH_EMMC:
64 		if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
65 			return ENVL_MMC;
66 		else if (CONFIG_IS_ENABLED(ENV_IS_IN_EXT4))
67 			return ENVL_EXT4;
68 		else
69 			return ENVL_NOWHERE;
70 
71 	case BOOT_FLASH_NAND:
72 	case BOOT_FLASH_SPINAND:
73 		if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI))
74 			return ENVL_UBI;
75 		else
76 			return ENVL_NOWHERE;
77 
78 	case BOOT_FLASH_NOR:
79 		if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
80 			return ENVL_SPI_FLASH;
81 		else
82 			return ENVL_NOWHERE;
83 
84 	default:
85 		return ENVL_NOWHERE;
86 	}
87 }
88 
env_ext4_get_intf(void)89 const char *env_ext4_get_intf(void)
90 {
91 	u32 bootmode = get_bootmode();
92 
93 	switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
94 	case BOOT_FLASH_SD:
95 	case BOOT_FLASH_EMMC:
96 		return "mmc";
97 	default:
98 		return "";
99 	}
100 }
101 
env_ext4_get_dev_part(void)102 const char *env_ext4_get_dev_part(void)
103 {
104 	static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
105 	u32 bootmode = get_bootmode();
106 
107 	return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
108 }
109 
mmc_get_env_dev(void)110 int mmc_get_env_dev(void)
111 {
112 	u32 bootmode = get_bootmode();
113 
114 	return (bootmode & TAMP_BOOT_INSTANCE_MASK) - 1;
115 }
116 
117 #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,struct bd_info * bd)118 int ft_board_setup(void *blob, struct bd_info *bd)
119 {
120 	return 0;
121 }
122 #endif
123