Masahiro Yamada | 063eb1e | 2016-04-21 14:43:18 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <spl.h> |
| 9 | #include <linux/io.h> |
| 10 | |
| 11 | #include "../sg-regs.h" |
Masahiro Yamada | be46136 | 2016-06-04 22:39:09 +0900 | [diff] [blame] | 12 | #include "../soc-info.h" |
Masahiro Yamada | 063eb1e | 2016-04-21 14:43:18 +0900 | [diff] [blame] | 13 | #include "boot-device.h" |
| 14 | |
| 15 | static struct boot_device_info boot_device_table[] = { |
| 16 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 8, EraseSize 128KB, Addr 4)"}, |
| 17 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 16, EraseSize 128KB, Addr 4)"}, |
| 18 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 8, EraseSize 128KB, Addr 5)"}, |
| 19 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 16, EraseSize 128KB, Addr 5)"}, |
| 20 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 8, EraseSize 256KB, Addr 5)"}, |
| 21 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 16, EraseSize 256KB, Addr 5)"}, |
| 22 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 8, EraseSize 512KB, Addr 5)"}, |
| 23 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 16, EraseSize 512KB, Addr 5)"}, |
| 24 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 8, EraseSize 128KB, Addr 4)"}, |
| 25 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 16, EraseSize 128KB, Addr 4)"}, |
| 26 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 8, EraseSize 128KB, Addr 5)"}, |
| 27 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 16, EraseSize 128KB, Addr 5)"}, |
| 28 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 8, EraseSize 256KB, Addr 5)"}, |
| 29 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 16, EraseSize 256KB, Addr 5)"}, |
| 30 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 8, EraseSize 512KB, Addr 5)"}, |
| 31 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 16, EraseSize 512KB, Addr 5)"}, |
| 32 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 8, ONFI, Addr 4)"}, |
| 33 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 16, ONFI, Addr 4)"}, |
| 34 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 8, ONFI, Addr 5)"}, |
| 35 | {BOOT_DEVICE_NAND, "NAND (Mirror 8, ECC 16, ONFI, Addr 5)"}, |
| 36 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 8, ONFI Addr 4)"}, |
| 37 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 16, ONFI Addr 4)"}, |
| 38 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 8, ONFI Addr 5)"}, |
| 39 | {BOOT_DEVICE_NAND, "NAND (Mirror 1, ECC 16, ONFI Addr 5)"}, |
| 40 | {BOOT_DEVICE_MMC1, "eMMC (Legacy, 4bit, 1.8V, Training Off)"}, |
| 41 | {BOOT_DEVICE_MMC1, "eMMC (Legacy, 4bit, 1.8V, Training On)"}, |
| 42 | {BOOT_DEVICE_MMC1, "eMMC (Legacy, 8bit, 1.8V, Training Off)"}, |
| 43 | {BOOT_DEVICE_MMC1, "eMMC (Legacy, 8bit, 1.8V, Training On)"}, |
| 44 | {BOOT_DEVICE_MMC1, "eMMC (High Speed SDR, 8bit, 1.8V, Training Off)"}, |
| 45 | {BOOT_DEVICE_MMC1, "eMMC (High Speed SDR, 8bit, 1.8V, Training On)"}, |
| 46 | {BOOT_DEVICE_MMC1, "eMMC (Legacy, 4bit, 1.8V, Training Off)"}, |
Masahiro Yamada | fd9256d | 2016-05-24 21:13:58 +0900 | [diff] [blame] | 47 | {BOOT_DEVICE_NOR, "NOR (XECS1)"}, |
Masahiro Yamada | 063eb1e | 2016-04-21 14:43:18 +0900 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | static int get_boot_mode_sel(void) |
| 51 | { |
| 52 | return (readl(SG_PINMON0) >> 1) & 0x1f; |
| 53 | } |
| 54 | |
| 55 | u32 uniphier_ld20_boot_device(void) |
| 56 | { |
| 57 | int boot_mode; |
Masahiro Yamada | be46136 | 2016-06-04 22:39:09 +0900 | [diff] [blame] | 58 | u32 usb_boot_mask; |
| 59 | |
| 60 | switch (uniphier_get_soc_type()) { |
| 61 | #if defined(CONFIG_ARCH_UNIPHIER_LD11) |
| 62 | case SOC_UNIPHIER_LD11: |
| 63 | usb_boot_mask = 0x00000080; |
| 64 | break; |
| 65 | #endif |
| 66 | #if defined(CONFIG_ARCH_UNIPHIER_LD20) |
| 67 | case SOC_UNIPHIER_LD20: |
| 68 | usb_boot_mask = 0x00000780; |
| 69 | break; |
| 70 | #endif |
| 71 | default: |
| 72 | BUG(); |
| 73 | } |
Masahiro Yamada | 063eb1e | 2016-04-21 14:43:18 +0900 | [diff] [blame] | 74 | |
Masahiro Yamada | be46136 | 2016-06-04 22:39:09 +0900 | [diff] [blame] | 75 | if (~readl(SG_PINMON0) & usb_boot_mask) |
Masahiro Yamada | 063eb1e | 2016-04-21 14:43:18 +0900 | [diff] [blame] | 76 | return BOOT_DEVICE_USB; |
| 77 | |
| 78 | boot_mode = get_boot_mode_sel(); |
| 79 | |
| 80 | return boot_device_table[boot_mode].type; |
| 81 | } |
| 82 | |
| 83 | void uniphier_ld20_boot_mode_show(void) |
| 84 | { |
| 85 | int mode_sel, i; |
| 86 | |
| 87 | mode_sel = get_boot_mode_sel(); |
| 88 | |
| 89 | puts("Boot Mode Pin:\n"); |
| 90 | |
| 91 | for (i = 0; i < ARRAY_SIZE(boot_device_table); i++) |
| 92 | printf(" %c %02x %s\n", i == mode_sel ? '*' : ' ', i, |
| 93 | boot_device_table[i].info); |
| 94 | } |