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