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