1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2016 Rockchip Electronics Co., Ltd
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <efi_loader.h>
9 #include <init.h>
10 #include <log.h>
11 #include <asm/arch-rockchip/periph.h>
12 #include <linux/kernel.h>
13 #include <power/regulator.h>
14 
15 #define ROCKPI4_UPDATABLE_IMAGES	2
16 
17 #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
18 static struct efi_fw_image fw_images[ROCKPI4_UPDATABLE_IMAGES] = {0};
19 
20 struct efi_capsule_update_info update_info = {
21 	.images = fw_images,
22 };
23 
24 u8 num_image_type_guids = ROCKPI4_UPDATABLE_IMAGES;
25 #endif
26 
27 #ifndef CONFIG_SPL_BUILD
board_early_init_f(void)28 int board_early_init_f(void)
29 {
30 	struct udevice *regulator;
31 	int ret;
32 
33 	ret = regulator_get_by_platname("vcc5v0_host", &regulator);
34 	if (ret) {
35 		debug("%s vcc5v0_host init fail! ret %d\n", __func__, ret);
36 		goto out;
37 	}
38 
39 	ret = regulator_set_enable(regulator, true);
40 	if (ret)
41 		debug("%s vcc5v0-host-en set fail! ret %d\n", __func__, ret);
42 
43 out:
44 	return 0;
45 }
46 
47 #if defined(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && defined(CONFIG_EFI_PARTITION)
board_is_rockpi_4b(void)48 static bool board_is_rockpi_4b(void)
49 {
50 	return CONFIG_IS_ENABLED(TARGET_EVB_RK3399) &&
51 		of_machine_is_compatible("radxa,rockpi4b");
52 }
53 
board_is_rockpi_4c(void)54 static bool board_is_rockpi_4c(void)
55 {
56 	return CONFIG_IS_ENABLED(TARGET_EVB_RK3399) &&
57 		of_machine_is_compatible("radxa,rockpi4c");
58 }
59 
rockchip_capsule_update_board_setup(void)60 void rockchip_capsule_update_board_setup(void)
61 {
62 	if (board_is_rockpi_4b()) {
63 		efi_guid_t idbldr_image_type_guid =
64 			ROCKPI_4B_IDBLOADER_IMAGE_GUID;
65 		efi_guid_t uboot_image_type_guid = ROCKPI_4B_UBOOT_IMAGE_GUID;
66 
67 		guidcpy(&fw_images[0].image_type_id, &idbldr_image_type_guid);
68 		guidcpy(&fw_images[1].image_type_id, &uboot_image_type_guid);
69 
70 		fw_images[0].fw_name = u"ROCKPI4B-IDBLOADER";
71 		fw_images[1].fw_name = u"ROCKPI4B-UBOOT";
72 	} else if (board_is_rockpi_4c()) {
73 		efi_guid_t idbldr_image_type_guid =
74 			ROCKPI_4C_IDBLOADER_IMAGE_GUID;
75 		efi_guid_t uboot_image_type_guid = ROCKPI_4C_UBOOT_IMAGE_GUID;
76 
77 		guidcpy(&fw_images[0].image_type_id, &idbldr_image_type_guid);
78 		guidcpy(&fw_images[1].image_type_id, &uboot_image_type_guid);
79 
80 		fw_images[0].fw_name = u"ROCKPI4C-IDBLOADER";
81 		fw_images[1].fw_name = u"ROCKPI4C-UBOOT";
82 	}
83 }
84 #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT && CONFIG_EFI_PARTITION */
85 #endif /* !CONFIG_SPL_BUILD */
86