Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | d28d1a7 | 2020-01-28 21:14:28 +0900 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 8 | #include <stdbool.h> |
| 9 | #include <stddef.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
| 11 | #include <lib/mmio.h> |
| 12 | #include <lib/utils_def.h> |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 13 | |
| 14 | #include "uniphier.h" |
| 15 | |
Masahiro Yamada | 9e33b02 | 2020-02-03 19:33:35 +0900 | [diff] [blame] | 16 | #define UNIPHIER_PINMON0 0x0 |
| 17 | #define UNIPHIER_PINMON2 0x8 |
| 18 | |
| 19 | static const uintptr_t uniphier_pinmon_base[] = { |
| 20 | [UNIPHIER_SOC_LD11] = 0x5f900100, |
| 21 | [UNIPHIER_SOC_LD20] = 0x5f900100, |
| 22 | [UNIPHIER_SOC_PXS3] = 0x5f900100, |
| 23 | }; |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 24 | |
Masahiro Yamada | d28d1a7 | 2020-01-28 21:14:28 +0900 | [diff] [blame] | 25 | static bool uniphier_ld11_is_usb_boot(uint32_t pinmon) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 26 | { |
| 27 | return !!(~pinmon & 0x00000080); |
| 28 | } |
| 29 | |
Masahiro Yamada | d28d1a7 | 2020-01-28 21:14:28 +0900 | [diff] [blame] | 30 | static bool uniphier_ld20_is_usb_boot(uint32_t pinmon) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 31 | { |
| 32 | return !!(~pinmon & 0x00000780); |
| 33 | } |
| 34 | |
Masahiro Yamada | d28d1a7 | 2020-01-28 21:14:28 +0900 | [diff] [blame] | 35 | static bool uniphier_pxs3_is_usb_boot(uint32_t pinmon) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 36 | { |
Masahiro Yamada | 9e33b02 | 2020-02-03 19:33:35 +0900 | [diff] [blame] | 37 | uintptr_t pinmon_base = uniphier_pinmon_base[UNIPHIER_SOC_PXS3]; |
| 38 | uint32_t pinmon2 = mmio_read_32(pinmon_base + UNIPHIER_PINMON2); |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 39 | |
| 40 | return !!(pinmon2 & BIT(31)); |
| 41 | } |
| 42 | |
| 43 | static const unsigned int uniphier_ld11_boot_device_table[] = { |
| 44 | UNIPHIER_BOOT_DEVICE_NAND, |
| 45 | UNIPHIER_BOOT_DEVICE_NAND, |
| 46 | UNIPHIER_BOOT_DEVICE_NAND, |
| 47 | UNIPHIER_BOOT_DEVICE_NAND, |
| 48 | UNIPHIER_BOOT_DEVICE_NAND, |
| 49 | UNIPHIER_BOOT_DEVICE_NAND, |
| 50 | UNIPHIER_BOOT_DEVICE_NAND, |
| 51 | UNIPHIER_BOOT_DEVICE_NAND, |
| 52 | UNIPHIER_BOOT_DEVICE_NAND, |
| 53 | UNIPHIER_BOOT_DEVICE_NAND, |
| 54 | UNIPHIER_BOOT_DEVICE_NAND, |
| 55 | UNIPHIER_BOOT_DEVICE_NAND, |
| 56 | UNIPHIER_BOOT_DEVICE_NAND, |
| 57 | UNIPHIER_BOOT_DEVICE_NAND, |
| 58 | UNIPHIER_BOOT_DEVICE_NAND, |
| 59 | UNIPHIER_BOOT_DEVICE_NAND, |
| 60 | UNIPHIER_BOOT_DEVICE_NAND, |
| 61 | UNIPHIER_BOOT_DEVICE_NAND, |
| 62 | UNIPHIER_BOOT_DEVICE_NAND, |
| 63 | UNIPHIER_BOOT_DEVICE_NAND, |
| 64 | UNIPHIER_BOOT_DEVICE_NAND, |
| 65 | UNIPHIER_BOOT_DEVICE_NAND, |
| 66 | UNIPHIER_BOOT_DEVICE_NAND, |
| 67 | UNIPHIER_BOOT_DEVICE_NAND, |
| 68 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 69 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 70 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 71 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 72 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 73 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 74 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 75 | UNIPHIER_BOOT_DEVICE_NOR, |
| 76 | }; |
| 77 | |
| 78 | static unsigned int uniphier_ld11_get_boot_device(uint32_t pinmon) |
| 79 | { |
| 80 | unsigned int boot_sel = (pinmon >> 1) & 0x1f; |
| 81 | |
| 82 | assert(boot_sel < ARRAY_SIZE(uniphier_ld11_boot_device_table)); |
| 83 | |
| 84 | return uniphier_ld11_boot_device_table[boot_sel]; |
| 85 | } |
| 86 | |
| 87 | static const unsigned int uniphier_pxs3_boot_device_table[] = { |
| 88 | UNIPHIER_BOOT_DEVICE_NAND, |
| 89 | UNIPHIER_BOOT_DEVICE_NAND, |
| 90 | UNIPHIER_BOOT_DEVICE_NAND, |
| 91 | UNIPHIER_BOOT_DEVICE_NAND, |
| 92 | UNIPHIER_BOOT_DEVICE_NAND, |
| 93 | UNIPHIER_BOOT_DEVICE_NAND, |
| 94 | UNIPHIER_BOOT_DEVICE_NAND, |
| 95 | UNIPHIER_BOOT_DEVICE_NAND, |
| 96 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 97 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 98 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 99 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 100 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 101 | UNIPHIER_BOOT_DEVICE_EMMC, |
| 102 | UNIPHIER_BOOT_DEVICE_NAND, |
| 103 | UNIPHIER_BOOT_DEVICE_NAND, |
| 104 | }; |
| 105 | |
| 106 | static unsigned int uniphier_pxs3_get_boot_device(uint32_t pinmon) |
| 107 | { |
| 108 | unsigned int boot_sel = (pinmon >> 1) & 0xf; |
| 109 | |
| 110 | assert(boot_sel < ARRAY_SIZE(uniphier_pxs3_boot_device_table)); |
| 111 | |
| 112 | return uniphier_pxs3_boot_device_table[boot_sel]; |
| 113 | } |
| 114 | |
| 115 | struct uniphier_boot_device_info { |
Masahiro Yamada | 3d436a9 | 2020-02-03 19:28:13 +0900 | [diff] [blame] | 116 | bool have_boot_swap; |
| 117 | bool (*is_sd_boot)(uint32_t pinmon); |
Masahiro Yamada | d28d1a7 | 2020-01-28 21:14:28 +0900 | [diff] [blame] | 118 | bool (*is_usb_boot)(uint32_t pinmon); |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 119 | unsigned int (*get_boot_device)(uint32_t pinmon); |
| 120 | }; |
| 121 | |
| 122 | static const struct uniphier_boot_device_info uniphier_boot_device_info[] = { |
| 123 | [UNIPHIER_SOC_LD11] = { |
Masahiro Yamada | 3d436a9 | 2020-02-03 19:28:13 +0900 | [diff] [blame] | 124 | .have_boot_swap = true, |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 125 | .is_usb_boot = uniphier_ld11_is_usb_boot, |
| 126 | .get_boot_device = uniphier_ld11_get_boot_device, |
| 127 | }, |
| 128 | [UNIPHIER_SOC_LD20] = { |
Masahiro Yamada | 3d436a9 | 2020-02-03 19:28:13 +0900 | [diff] [blame] | 129 | .have_boot_swap = true, |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 130 | .is_usb_boot = uniphier_ld20_is_usb_boot, |
| 131 | .get_boot_device = uniphier_ld11_get_boot_device, |
| 132 | }, |
| 133 | [UNIPHIER_SOC_PXS3] = { |
Masahiro Yamada | 3d436a9 | 2020-02-03 19:28:13 +0900 | [diff] [blame] | 134 | .have_boot_swap = true, |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 135 | .is_usb_boot = uniphier_pxs3_is_usb_boot, |
| 136 | .get_boot_device = uniphier_pxs3_get_boot_device, |
| 137 | }, |
| 138 | }; |
| 139 | |
| 140 | unsigned int uniphier_get_boot_device(unsigned int soc) |
| 141 | { |
| 142 | const struct uniphier_boot_device_info *info; |
Masahiro Yamada | 9e33b02 | 2020-02-03 19:33:35 +0900 | [diff] [blame] | 143 | uintptr_t pinmon_base; |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 144 | uint32_t pinmon; |
| 145 | |
| 146 | assert(soc < ARRAY_SIZE(uniphier_boot_device_info)); |
| 147 | info = &uniphier_boot_device_info[soc]; |
| 148 | |
Masahiro Yamada | 9e33b02 | 2020-02-03 19:33:35 +0900 | [diff] [blame] | 149 | assert(soc < ARRAY_SIZE(uniphier_boot_device_info)); |
| 150 | pinmon_base = uniphier_pinmon_base[soc]; |
| 151 | |
| 152 | pinmon = mmio_read_32(pinmon_base + UNIPHIER_PINMON0); |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 153 | |
Masahiro Yamada | 3d436a9 | 2020-02-03 19:28:13 +0900 | [diff] [blame] | 154 | if (info->have_boot_swap && !(pinmon & BIT(29))) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 155 | return UNIPHIER_BOOT_DEVICE_NOR; |
| 156 | |
Masahiro Yamada | 3d436a9 | 2020-02-03 19:28:13 +0900 | [diff] [blame] | 157 | if (info->is_sd_boot && info->is_sd_boot(pinmon)) |
| 158 | return UNIPHIER_BOOT_DEVICE_SD; |
| 159 | |
| 160 | if (info->is_usb_boot && info->is_usb_boot(pinmon)) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 161 | return UNIPHIER_BOOT_DEVICE_USB; |
| 162 | |
| 163 | return info->get_boot_device(pinmon); |
| 164 | } |
| 165 | |
| 166 | static const bool uniphier_have_onchip_scp[] = { |
| 167 | [UNIPHIER_SOC_LD11] = true, |
| 168 | [UNIPHIER_SOC_LD20] = true, |
| 169 | [UNIPHIER_SOC_PXS3] = false, |
| 170 | }; |
| 171 | |
| 172 | unsigned int uniphier_get_boot_master(unsigned int soc) |
| 173 | { |
| 174 | assert(soc < ARRAY_SIZE(uniphier_have_onchip_scp)); |
| 175 | |
| 176 | if (uniphier_have_onchip_scp[soc]) { |
Masahiro Yamada | 9e33b02 | 2020-02-03 19:33:35 +0900 | [diff] [blame] | 177 | uintptr_t pinmon_base; |
| 178 | |
| 179 | assert(soc < ARRAY_SIZE(uniphier_boot_device_info)); |
| 180 | pinmon_base = uniphier_pinmon_base[soc]; |
| 181 | |
| 182 | if (mmio_read_32(pinmon_base + UNIPHIER_PINMON0) & BIT(27)) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 183 | return UNIPHIER_BOOT_MASTER_THIS; |
| 184 | else |
| 185 | return UNIPHIER_BOOT_MASTER_SCP; |
| 186 | } else { |
| 187 | return UNIPHIER_BOOT_MASTER_EXT; |
| 188 | } |
| 189 | } |