xref: /openbmc/u-boot/arch/arm/mach-omap2/omap3/boot.c (revision ee943655)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * OMAP3 boot
4  *
5  * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
6  */
7 
8 #include <common.h>
9 #include <asm/io.h>
10 #include <asm/arch/sys_proto.h>
11 #include <spl.h>
12 
13 static u32 boot_devices[] = {
14 	BOOT_DEVICE_ONENAND,
15 	BOOT_DEVICE_NAND,
16 	BOOT_DEVICE_ONENAND,
17 	BOOT_DEVICE_MMC2,
18 	BOOT_DEVICE_ONENAND,
19 	BOOT_DEVICE_MMC2,
20 	BOOT_DEVICE_MMC1,
21 	BOOT_DEVICE_XIP,
22 	BOOT_DEVICE_XIPWAIT,
23 	BOOT_DEVICE_MMC2,
24 	BOOT_DEVICE_XIP,
25 	BOOT_DEVICE_XIPWAIT,
26 	BOOT_DEVICE_NAND,
27 	BOOT_DEVICE_XIP,
28 	BOOT_DEVICE_XIPWAIT,
29 	BOOT_DEVICE_NAND,
30 	BOOT_DEVICE_ONENAND,
31 	BOOT_DEVICE_MMC2,
32 	BOOT_DEVICE_MMC1,
33 	BOOT_DEVICE_XIP,
34 	BOOT_DEVICE_XIPWAIT,
35 	BOOT_DEVICE_NAND,
36 	BOOT_DEVICE_ONENAND,
37 	BOOT_DEVICE_MMC2,
38 	BOOT_DEVICE_MMC1,
39 	BOOT_DEVICE_XIP,
40 	BOOT_DEVICE_XIPWAIT,
41 	BOOT_DEVICE_NAND,
42 	BOOT_DEVICE_MMC2_2,
43 };
44 
45 u32 omap_sys_boot_device(void)
46 {
47 	struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
48 	u32 sys_boot;
49 
50 	/* Grab the first 5 bits of the status register for SYS_BOOT. */
51 	sys_boot = readl(&ctrl_base->status) & ((1 << 5) - 1);
52 
53 	if (sys_boot >= (sizeof(boot_devices) / sizeof(u32)))
54 		return BOOT_DEVICE_NONE;
55 
56 	return boot_devices[sys_boot];
57 }
58 
59 int omap_reboot_mode(char *mode, unsigned int length)
60 {
61 	u32 reboot_mode;
62 	char c;
63 
64 	if (length < 2)
65 		return -1;
66 
67 	reboot_mode = readl((u32 *)(OMAP34XX_SCRATCHPAD +
68 		OMAP_REBOOT_REASON_OFFSET));
69 
70 	c = (reboot_mode >> 24) & 0xff;
71 	if (c != 'B')
72 		return -1;
73 
74 	c = (reboot_mode >> 16) & 0xff;
75 	if (c != 'M')
76 		return -1;
77 
78 	c = reboot_mode & 0xff;
79 
80 	mode[0] = c;
81 	mode[1] = '\0';
82 
83 	return 0;
84 }
85 
86 int omap_reboot_mode_clear(void)
87 {
88 	writel(0, (u32 *)(OMAP34XX_SCRATCHPAD + OMAP_REBOOT_REASON_OFFSET));
89 
90 	return 0;
91 }
92 
93 int omap_reboot_mode_store(char *mode)
94 {
95 	u32 reboot_mode;
96 
97 	reboot_mode = 'B' << 24 | 'M' << 16 | mode[0];
98 
99 	writel(reboot_mode, (u32 *)(OMAP34XX_SCRATCHPAD +
100 		OMAP_REBOOT_REASON_OFFSET));
101 
102 	return 0;
103 }
104