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