blob: ea26115b71189678f8190c0fc10ef7336c6e3a76 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Paul Kocialkowski368beeb2015-07-15 16:02:24 +02002/*
3 * OMAP3 boot
4 *
5 * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
Paul Kocialkowski368beeb2015-07-15 16:02:24 +02006 */
7
8#include <common.h>
9#include <asm/io.h>
10#include <asm/arch/sys_proto.h>
11#include <spl.h>
12
13static 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
45u32 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}
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020058
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010059int omap_reboot_mode(char *mode, unsigned int length)
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020060{
61 u32 reboot_mode;
62 char c;
63
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010064 if (length < 2)
65 return -1;
66
Paul Kocialkowski324590d2016-02-27 19:26:42 +010067 reboot_mode = readl((u32 *)(OMAP34XX_SCRATCHPAD +
68 OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020069
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
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010080 mode[0] = c;
81 mode[1] = '\0';
82
83 return 0;
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020084}
85
86int omap_reboot_mode_clear(void)
87{
Paul Kocialkowski324590d2016-02-27 19:26:42 +010088 writel(0, (u32 *)(OMAP34XX_SCRATCHPAD + OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020089
90 return 0;
91}
92
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010093int omap_reboot_mode_store(char *mode)
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020094{
95 u32 reboot_mode;
96
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010097 reboot_mode = 'B' << 24 | 'M' << 16 | mode[0];
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020098
Paul Kocialkowski324590d2016-02-27 19:26:42 +010099 writel(reboot_mode, (u32 *)(OMAP34XX_SCRATCHPAD +
100 OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +0200101
102 return 0;
103}