blob: 64b242b752b2058d7d5b45effe4453f0907d25eb [file] [log] [blame]
Paul Kocialkowski368beeb2015-07-15 16:02:24 +02001/*
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
14static 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
46u32 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}
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020059
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010060int omap_reboot_mode(char *mode, unsigned int length)
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020061{
62 u32 reboot_mode;
63 char c;
64
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010065 if (length < 2)
66 return -1;
67
Paul Kocialkowski324590d2016-02-27 19:26:42 +010068 reboot_mode = readl((u32 *)(OMAP34XX_SCRATCHPAD +
69 OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020070
71 c = (reboot_mode >> 24) & 0xff;
72 if (c != 'B')
73 return -1;
74
75 c = (reboot_mode >> 16) & 0xff;
76 if (c != 'M')
77 return -1;
78
79 c = reboot_mode & 0xff;
80
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010081 mode[0] = c;
82 mode[1] = '\0';
83
84 return 0;
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020085}
86
87int omap_reboot_mode_clear(void)
88{
Paul Kocialkowski324590d2016-02-27 19:26:42 +010089 writel(0, (u32 *)(OMAP34XX_SCRATCHPAD + OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020090
91 return 0;
92}
93
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010094int omap_reboot_mode_store(char *mode)
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020095{
96 u32 reboot_mode;
97
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010098 reboot_mode = 'B' << 24 | 'M' << 16 | mode[0];
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020099
Paul Kocialkowski324590d2016-02-27 19:26:42 +0100100 writel(reboot_mode, (u32 *)(OMAP34XX_SCRATCHPAD +
101 OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +0200102
103 return 0;
104}