blob: 2a36a25e27999c5745bd6d383b488be3f3b0225a [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
Paul Kocialkowski368beeb2015-07-15 16:02:24 +02008#include <asm/io.h>
9#include <asm/arch/sys_proto.h>
10#include <spl.h>
11
12static u32 boot_devices[] = {
13 BOOT_DEVICE_ONENAND,
14 BOOT_DEVICE_NAND,
15 BOOT_DEVICE_ONENAND,
16 BOOT_DEVICE_MMC2,
17 BOOT_DEVICE_ONENAND,
18 BOOT_DEVICE_MMC2,
19 BOOT_DEVICE_MMC1,
20 BOOT_DEVICE_XIP,
21 BOOT_DEVICE_XIPWAIT,
22 BOOT_DEVICE_MMC2,
23 BOOT_DEVICE_XIP,
24 BOOT_DEVICE_XIPWAIT,
25 BOOT_DEVICE_NAND,
26 BOOT_DEVICE_XIP,
27 BOOT_DEVICE_XIPWAIT,
28 BOOT_DEVICE_NAND,
29 BOOT_DEVICE_ONENAND,
30 BOOT_DEVICE_MMC2,
31 BOOT_DEVICE_MMC1,
32 BOOT_DEVICE_XIP,
33 BOOT_DEVICE_XIPWAIT,
34 BOOT_DEVICE_NAND,
35 BOOT_DEVICE_ONENAND,
36 BOOT_DEVICE_MMC2,
37 BOOT_DEVICE_MMC1,
38 BOOT_DEVICE_XIP,
39 BOOT_DEVICE_XIPWAIT,
40 BOOT_DEVICE_NAND,
41 BOOT_DEVICE_MMC2_2,
42};
43
44u32 omap_sys_boot_device(void)
45{
46 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
47 u32 sys_boot;
48
49 /* Grab the first 5 bits of the status register for SYS_BOOT. */
50 sys_boot = readl(&ctrl_base->status) & ((1 << 5) - 1);
51
52 if (sys_boot >= (sizeof(boot_devices) / sizeof(u32)))
53 return BOOT_DEVICE_NONE;
54
55 return boot_devices[sys_boot];
56}
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020057
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010058int omap_reboot_mode(char *mode, unsigned int length)
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020059{
60 u32 reboot_mode;
61 char c;
62
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010063 if (length < 2)
64 return -1;
65
Paul Kocialkowski324590d2016-02-27 19:26:42 +010066 reboot_mode = readl((u32 *)(OMAP34XX_SCRATCHPAD +
67 OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020068
69 c = (reboot_mode >> 24) & 0xff;
70 if (c != 'B')
71 return -1;
72
73 c = (reboot_mode >> 16) & 0xff;
74 if (c != 'M')
75 return -1;
76
77 c = reboot_mode & 0xff;
78
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010079 mode[0] = c;
80 mode[1] = '\0';
81
82 return 0;
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020083}
84
85int omap_reboot_mode_clear(void)
86{
Paul Kocialkowski324590d2016-02-27 19:26:42 +010087 writel(0, (u32 *)(OMAP34XX_SCRATCHPAD + OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020088
89 return 0;
90}
91
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010092int omap_reboot_mode_store(char *mode)
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020093{
94 u32 reboot_mode;
95
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +010096 reboot_mode = 'B' << 24 | 'M' << 16 | mode[0];
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +020097
Paul Kocialkowski324590d2016-02-27 19:26:42 +010098 writel(reboot_mode, (u32 *)(OMAP34XX_SCRATCHPAD +
99 OMAP_REBOOT_REASON_OFFSET));
Paul Kocialkowski7879ddc2015-07-20 15:17:10 +0200100
101 return 0;
102}