Paul Kocialkowski | 368beeb | 2015-07-15 16:02:24 +0200 | [diff] [blame] | 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 | } |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 59 | |
Paul Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 60 | int omap_reboot_mode(char *mode, unsigned int length) |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 61 | { |
| 62 | u32 reboot_mode; |
| 63 | char c; |
| 64 | |
Paul Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 65 | if (length < 2) |
| 66 | return -1; |
| 67 | |
Paul Kocialkowski | 324590d | 2016-02-27 19:26:42 +0100 | [diff] [blame] | 68 | reboot_mode = readl((u32 *)(OMAP34XX_SCRATCHPAD + |
| 69 | OMAP_REBOOT_REASON_OFFSET)); |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 70 | |
| 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 Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 81 | mode[0] = c; |
| 82 | mode[1] = '\0'; |
| 83 | |
| 84 | return 0; |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | int omap_reboot_mode_clear(void) |
| 88 | { |
Paul Kocialkowski | 324590d | 2016-02-27 19:26:42 +0100 | [diff] [blame] | 89 | writel(0, (u32 *)(OMAP34XX_SCRATCHPAD + OMAP_REBOOT_REASON_OFFSET)); |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Paul Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 94 | int omap_reboot_mode_store(char *mode) |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 95 | { |
| 96 | u32 reboot_mode; |
| 97 | |
Paul Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 98 | reboot_mode = 'B' << 24 | 'M' << 16 | mode[0]; |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 99 | |
Paul Kocialkowski | 324590d | 2016-02-27 19:26:42 +0100 | [diff] [blame] | 100 | writel(reboot_mode, (u32 *)(OMAP34XX_SCRATCHPAD + |
| 101 | OMAP_REBOOT_REASON_OFFSET)); |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 102 | |
| 103 | return 0; |
| 104 | } |