global: Move remaining CONFIG_SYS_* to CFG_SYS_*
[platform/kernel/u-boot.git] / arch / arm / mach-imx / romapi.c
1 // SPDX-License-Identifier: GPL-2.0+
2
3 #include <asm/global_data.h>
4 #include <asm/arch/sys_proto.h>
5 #include <asm/mach-imx/boot_mode.h>
6
7 DECLARE_GLOBAL_DATA_PTR;
8
9 u32 rom_api_download_image(u8 *dest, u32 offset, u32 size)
10 {
11         u32 xor = (uintptr_t)dest ^ offset ^ size;
12         volatile gd_t *sgd = gd;
13         u32 ret;
14
15         ret = g_rom_api->download_image(dest, offset, size, xor);
16         set_gd(sgd);
17
18         return ret;
19 }
20
21 u32 rom_api_query_boot_infor(u32 info_type, u32 *info)
22 {
23         u32 xor = info_type ^ (uintptr_t)info;
24         volatile gd_t *sgd = gd;
25         u32 ret;
26
27         ret = g_rom_api->query_boot_infor(info_type, info, xor);
28         set_gd(sgd);
29
30         return ret;
31 }
32
33 extern struct rom_api *g_rom_api;
34
35 enum boot_device get_boot_device(void)
36 {
37         volatile gd_t *pgd = gd;
38         int ret;
39         u32 boot;
40         u16 boot_type;
41         u8 boot_instance;
42         enum boot_device boot_dev = SD1_BOOT;
43
44         ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
45                                           ((uintptr_t)&boot) ^ QUERY_BT_DEV);
46         set_gd(pgd);
47
48         if (ret != ROM_API_OKAY) {
49                 puts("ROMAPI: failure at query_boot_info\n");
50                 return -1;
51         }
52
53         boot_type = boot >> 16;
54         boot_instance = (boot >> 8) & 0xff;
55
56         switch (boot_type) {
57         case BT_DEV_TYPE_SD:
58                 boot_dev = boot_instance + SD1_BOOT;
59                 break;
60         case BT_DEV_TYPE_MMC:
61                 boot_dev = boot_instance + MMC1_BOOT;
62                 break;
63         case BT_DEV_TYPE_NAND:
64                 boot_dev = NAND_BOOT;
65                 break;
66         case BT_DEV_TYPE_FLEXSPINOR:
67                 boot_dev = QSPI_BOOT;
68                 break;
69         case BT_DEV_TYPE_USB:
70                 boot_dev = boot_instance + USB_BOOT;
71                 break;
72         default:
73                 break;
74         }
75
76         return boot_dev;
77 }