Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Paul Kocialkowski | 368beeb | 2015-07-15 16:02:24 +0200 | [diff] [blame] | 2 | /* |
| 3 | * OMAP3 boot |
| 4 | * |
| 5 | * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr> |
Paul Kocialkowski | 368beeb | 2015-07-15 16:02:24 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/sys_proto.h> |
| 11 | #include <spl.h> |
| 12 | |
| 13 | static 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 | |
| 45 | u32 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 Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 58 | |
Paul Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 59 | int omap_reboot_mode(char *mode, unsigned int length) |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 60 | { |
| 61 | u32 reboot_mode; |
| 62 | char c; |
| 63 | |
Paul Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 64 | if (length < 2) |
| 65 | return -1; |
| 66 | |
Paul Kocialkowski | 324590d | 2016-02-27 19:26:42 +0100 | [diff] [blame] | 67 | reboot_mode = readl((u32 *)(OMAP34XX_SCRATCHPAD + |
| 68 | OMAP_REBOOT_REASON_OFFSET)); |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 69 | |
| 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 Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 80 | mode[0] = c; |
| 81 | mode[1] = '\0'; |
| 82 | |
| 83 | return 0; |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | int omap_reboot_mode_clear(void) |
| 87 | { |
Paul Kocialkowski | 324590d | 2016-02-27 19:26:42 +0100 | [diff] [blame] | 88 | writel(0, (u32 *)(OMAP34XX_SCRATCHPAD + OMAP_REBOOT_REASON_OFFSET)); |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
Paul Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 93 | int omap_reboot_mode_store(char *mode) |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 94 | { |
| 95 | u32 reboot_mode; |
| 96 | |
Paul Kocialkowski | bb0ac14 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 97 | reboot_mode = 'B' << 24 | 'M' << 16 | mode[0]; |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 98 | |
Paul Kocialkowski | 324590d | 2016-02-27 19:26:42 +0100 | [diff] [blame] | 99 | writel(reboot_mode, (u32 *)(OMAP34XX_SCRATCHPAD + |
| 100 | OMAP_REBOOT_REASON_OFFSET)); |
Paul Kocialkowski | 7879ddc | 2015-07-20 15:17:10 +0200 | [diff] [blame] | 101 | |
| 102 | return 0; |
| 103 | } |