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