Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 1 | /* |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | 3923f88 | 2020-05-12 14:04:10 -0700 | [diff] [blame] | 3 | * Copyright (c) 2020, NVIDIA Corporation. All rights reserved. |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 4 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 5 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <arch_helpers.h> |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 9 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <lib/mmio.h> |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 11 | #include <tegra_def.h> |
| 12 | #include <tegra_platform.h> |
| 13 | #include <tegra_private.h> |
| 14 | |
| 15 | /******************************************************************************* |
| 16 | * Tegra platforms |
| 17 | ******************************************************************************/ |
| 18 | typedef enum tegra_platform { |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 19 | TEGRA_PLATFORM_SILICON = 0U, |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 20 | TEGRA_PLATFORM_QT, |
| 21 | TEGRA_PLATFORM_FPGA, |
| 22 | TEGRA_PLATFORM_EMULATION, |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 23 | TEGRA_PLATFORM_LINSIM, |
| 24 | TEGRA_PLATFORM_UNIT_FPGA, |
| 25 | TEGRA_PLATFORM_VIRT_DEV_KIT, |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 26 | TEGRA_PLATFORM_MAX, |
| 27 | } tegra_platform_t; |
| 28 | |
| 29 | /******************************************************************************* |
| 30 | * Tegra macros defining all the SoC minor versions |
| 31 | ******************************************************************************/ |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 32 | #define TEGRA_MINOR_QT U(0) |
| 33 | #define TEGRA_MINOR_FPGA U(1) |
| 34 | #define TEGRA_MINOR_ASIM_QT U(2) |
| 35 | #define TEGRA_MINOR_ASIM_LINSIM U(3) |
| 36 | #define TEGRA_MINOR_DSIM_ASIM_LINSIM U(4) |
| 37 | #define TEGRA_MINOR_UNIT_FPGA U(5) |
| 38 | #define TEGRA_MINOR_VIRT_DEV_KIT U(6) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 39 | |
| 40 | /******************************************************************************* |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 41 | * Tegra macros defining all the SoC pre_si_platform |
| 42 | ******************************************************************************/ |
| 43 | #define TEGRA_PRE_SI_QT U(1) |
| 44 | #define TEGRA_PRE_SI_FPGA U(2) |
| 45 | #define TEGRA_PRE_SI_UNIT_FPGA U(3) |
| 46 | #define TEGRA_PRE_SI_ASIM_QT U(4) |
| 47 | #define TEGRA_PRE_SI_ASIM_LINSIM U(5) |
| 48 | #define TEGRA_PRE_SI_DSIM_ASIM_LINSIM U(6) |
| 49 | #define TEGRA_PRE_SI_VDK U(8) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 50 | |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Read the chip ID value |
| 53 | */ |
| 54 | static uint32_t tegra_get_chipid(void) |
| 55 | { |
| 56 | return mmio_read_32(TEGRA_MISC_BASE + HARDWARE_REVISION_OFFSET); |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Read the chip's major version from chip ID value |
| 61 | */ |
Varun Wadekar | fc9b91e | 2017-03-10 09:53:37 -0800 | [diff] [blame] | 62 | uint32_t tegra_get_chipid_major(void) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 63 | { |
| 64 | return (tegra_get_chipid() >> MAJOR_VERSION_SHIFT) & MAJOR_VERSION_MASK; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Read the chip's minor version from the chip ID value |
| 69 | */ |
Varun Wadekar | fc9b91e | 2017-03-10 09:53:37 -0800 | [diff] [blame] | 70 | uint32_t tegra_get_chipid_minor(void) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 71 | { |
| 72 | return (tegra_get_chipid() >> MINOR_VERSION_SHIFT) & MINOR_VERSION_MASK; |
| 73 | } |
| 74 | |
Marvin Hsu | 589a7e1 | 2017-04-12 20:40:27 +0800 | [diff] [blame] | 75 | /* |
| 76 | * Read the chip's pre_si_platform valus from the chip ID value |
| 77 | */ |
| 78 | static uint32_t tegra_get_chipid_pre_si_platform(void) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 79 | { |
Marvin Hsu | 589a7e1 | 2017-04-12 20:40:27 +0800 | [diff] [blame] | 80 | return (tegra_get_chipid() >> PRE_SI_PLATFORM_SHIFT) & PRE_SI_PLATFORM_MASK; |
| 81 | } |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 82 | |
Marvin Hsu | 589a7e1 | 2017-04-12 20:40:27 +0800 | [diff] [blame] | 83 | bool tegra_chipid_is_t132(void) |
| 84 | { |
| 85 | uint32_t chip_id = ((tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK); |
| 86 | |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 87 | return (chip_id == TEGRA_CHIPID_TEGRA13); |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Marvin Hsu | 589a7e1 | 2017-04-12 20:40:27 +0800 | [diff] [blame] | 90 | bool tegra_chipid_is_t186(void) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 91 | { |
| 92 | uint32_t chip_id = (tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK; |
| 93 | |
Marvin Hsu | 589a7e1 | 2017-04-12 20:40:27 +0800 | [diff] [blame] | 94 | return (chip_id == TEGRA_CHIPID_TEGRA18); |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Marvin Hsu | 589a7e1 | 2017-04-12 20:40:27 +0800 | [diff] [blame] | 97 | bool tegra_chipid_is_t210(void) |
Varun Wadekar | fdcdfe2 | 2017-04-13 14:12:49 -0700 | [diff] [blame] | 98 | { |
| 99 | uint32_t chip_id = (tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK; |
| 100 | |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 101 | return (chip_id == TEGRA_CHIPID_TEGRA21); |
Varun Wadekar | fdcdfe2 | 2017-04-13 14:12:49 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Marvin Hsu | 589a7e1 | 2017-04-12 20:40:27 +0800 | [diff] [blame] | 104 | bool tegra_chipid_is_t210_b01(void) |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 105 | { |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 106 | return (tegra_chipid_is_t210() && (tegra_get_chipid_major() == 0x2U)); |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 110 | * Read the chip ID value and derive the platform |
| 111 | */ |
| 112 | static tegra_platform_t tegra_get_platform(void) |
| 113 | { |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 114 | uint32_t major, minor, pre_si_platform; |
| 115 | tegra_platform_t ret; |
| 116 | |
| 117 | /* get the major/minor chip ID values */ |
| 118 | major = tegra_get_chipid_major(); |
| 119 | minor = tegra_get_chipid_minor(); |
| 120 | pre_si_platform = tegra_get_chipid_pre_si_platform(); |
| 121 | |
| 122 | if (major == 0U) { |
| 123 | /* |
| 124 | * The minor version number is used by simulation platforms |
| 125 | */ |
| 126 | switch (minor) { |
| 127 | /* |
| 128 | * Cadence's QuickTurn emulation system is a Solaris-based |
| 129 | * chip emulation system |
| 130 | */ |
| 131 | case TEGRA_MINOR_QT: |
| 132 | case TEGRA_MINOR_ASIM_QT: |
| 133 | ret = TEGRA_PLATFORM_QT; |
| 134 | break; |
| 135 | |
| 136 | /* |
| 137 | * FPGAs are used during early software/hardware development |
| 138 | */ |
| 139 | case TEGRA_MINOR_FPGA: |
| 140 | ret = TEGRA_PLATFORM_FPGA; |
| 141 | break; |
| 142 | /* |
| 143 | * Linsim is a reconfigurable, clock-driven, mixed RTL/cmodel |
| 144 | * simulation framework. |
| 145 | */ |
| 146 | case TEGRA_MINOR_ASIM_LINSIM: |
| 147 | case TEGRA_MINOR_DSIM_ASIM_LINSIM: |
| 148 | ret = TEGRA_PLATFORM_LINSIM; |
| 149 | break; |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 150 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 151 | /* |
| 152 | * Unit FPGAs run the actual hardware block IP on the FPGA with |
| 153 | * the other parts of the system using Linsim. |
| 154 | */ |
| 155 | case TEGRA_MINOR_UNIT_FPGA: |
| 156 | ret = TEGRA_PLATFORM_UNIT_FPGA; |
| 157 | break; |
| 158 | /* |
| 159 | * The Virtualizer Development Kit (VDK) is the standard chip |
| 160 | * development from Synopsis. |
| 161 | */ |
| 162 | case TEGRA_MINOR_VIRT_DEV_KIT: |
| 163 | ret = TEGRA_PLATFORM_VIRT_DEV_KIT; |
| 164 | break; |
Marvin Hsu | 589a7e1 | 2017-04-12 20:40:27 +0800 | [diff] [blame] | 165 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 166 | default: |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 167 | ret = TEGRA_PLATFORM_MAX; |
| 168 | break; |
| 169 | } |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 170 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 171 | } else if (pre_si_platform > 0U) { |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 172 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 173 | switch (pre_si_platform) { |
| 174 | /* |
| 175 | * Cadence's QuickTurn emulation system is a Solaris-based |
| 176 | * chip emulation system |
| 177 | */ |
| 178 | case TEGRA_PRE_SI_QT: |
| 179 | case TEGRA_PRE_SI_ASIM_QT: |
| 180 | ret = TEGRA_PLATFORM_QT; |
| 181 | break; |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 182 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 183 | /* |
| 184 | * FPGAs are used during early software/hardware development |
| 185 | */ |
| 186 | case TEGRA_PRE_SI_FPGA: |
| 187 | ret = TEGRA_PLATFORM_FPGA; |
| 188 | break; |
| 189 | /* |
| 190 | * Linsim is a reconfigurable, clock-driven, mixed RTL/cmodel |
| 191 | * simulation framework. |
| 192 | */ |
| 193 | case TEGRA_PRE_SI_ASIM_LINSIM: |
| 194 | case TEGRA_PRE_SI_DSIM_ASIM_LINSIM: |
| 195 | ret = TEGRA_PLATFORM_LINSIM; |
| 196 | break; |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 197 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 198 | /* |
| 199 | * Unit FPGAs run the actual hardware block IP on the FPGA with |
| 200 | * the other parts of the system using Linsim. |
| 201 | */ |
| 202 | case TEGRA_PRE_SI_UNIT_FPGA: |
| 203 | ret = TEGRA_PLATFORM_UNIT_FPGA; |
| 204 | break; |
| 205 | /* |
| 206 | * The Virtualizer Development Kit (VDK) is the standard chip |
| 207 | * development from Synopsis. |
| 208 | */ |
| 209 | case TEGRA_PRE_SI_VDK: |
| 210 | ret = TEGRA_PLATFORM_VIRT_DEV_KIT; |
| 211 | break; |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 212 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 213 | default: |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 214 | ret = TEGRA_PLATFORM_MAX; |
| 215 | break; |
| 216 | } |
| 217 | |
| 218 | } else { |
| 219 | /* Actual silicon platforms have a non-zero major version */ |
| 220 | ret = TEGRA_PLATFORM_SILICON; |
| 221 | } |
| 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
| 226 | bool tegra_platform_is_silicon(void) |
| 227 | { |
| 228 | return ((tegra_get_platform() == TEGRA_PLATFORM_SILICON) ? true : false); |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 231 | bool tegra_platform_is_qt(void) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 232 | { |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 233 | return ((tegra_get_platform() == TEGRA_PLATFORM_QT) ? true : false); |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 236 | bool tegra_platform_is_linsim(void) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 237 | { |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 238 | tegra_platform_t plat = tegra_get_platform(); |
| 239 | |
| 240 | return (((plat == TEGRA_PLATFORM_LINSIM) || |
| 241 | (plat == TEGRA_PLATFORM_UNIT_FPGA)) ? true : false); |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 244 | bool tegra_platform_is_fpga(void) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 245 | { |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 246 | return ((tegra_get_platform() == TEGRA_PLATFORM_FPGA) ? true : false); |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 249 | bool tegra_platform_is_emulation(void) |
Varun Wadekar | 28dcc21 | 2016-07-20 10:28:51 -0700 | [diff] [blame] | 250 | { |
| 251 | return (tegra_get_platform() == TEGRA_PLATFORM_EMULATION); |
| 252 | } |
Anthony Zhou | 70262ef | 2017-03-22 14:37:04 +0800 | [diff] [blame] | 253 | |
| 254 | bool tegra_platform_is_unit_fpga(void) |
| 255 | { |
| 256 | return ((tegra_get_platform() == TEGRA_PLATFORM_UNIT_FPGA) ? true : false); |
| 257 | } |
| 258 | |
| 259 | bool tegra_platform_is_virt_dev_kit(void) |
| 260 | { |
| 261 | return ((tegra_get_platform() == TEGRA_PLATFORM_VIRT_DEV_KIT) ? true : false); |
| 262 | } |
Varun Wadekar | 3923f88 | 2020-05-12 14:04:10 -0700 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * This function returns soc version which mainly consist of below fields |
| 266 | * |
| 267 | * soc_version[30:24] = JEP-106 continuation code for the SiP |
| 268 | * soc_version[23:16] = JEP-106 identification code with parity bit for the SiP |
| 269 | * soc_version[0:15] = chip identification |
| 270 | */ |
| 271 | int32_t plat_get_soc_version(void) |
| 272 | { |
| 273 | uint32_t chip_id = ((tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK); |
| 274 | uint32_t manfid = (JEDEC_NVIDIA_BKID << 24) | (JEDEC_NVIDIA_MFID << 16); |
| 275 | |
| 276 | return (int32_t)(manfid | (chip_id & 0xFFFF)); |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * This function returns soc revision in below format |
| 281 | * |
| 282 | * soc_revision[8:15] = major version number |
| 283 | * soc_revision[0:7] = minor version number |
| 284 | */ |
| 285 | int32_t plat_get_soc_revision(void) |
| 286 | { |
| 287 | return (int32_t)((tegra_get_chipid_major() << 8) | tegra_get_chipid_minor()); |
| 288 | } |