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