blob: e4338b96387f59cfe8480950f50cbf62f3dbeb94 [file] [log] [blame]
Varun Wadekar28dcc212016-07-20 10:28:51 -07001/*
Anthony Zhou70262ef2017-03-22 14:37:04 +08002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
Varun Wadekar3923f882020-05-12 14:04:10 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar28dcc212016-07-20 10:28:51 -07004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar28dcc212016-07-20 10:28:51 -07006 */
7
8#include <arch_helpers.h>
Anthony Zhou70262ef2017-03-22 14:37:04 +08009#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <lib/mmio.h>
Varun Wadekar28dcc212016-07-20 10:28:51 -070011#include <tegra_def.h>
12#include <tegra_platform.h>
13#include <tegra_private.h>
14
15/*******************************************************************************
16 * Tegra platforms
17 ******************************************************************************/
18typedef enum tegra_platform {
Anthony Zhou4408e882017-07-07 14:29:51 +080019 TEGRA_PLATFORM_SILICON = 0U,
Varun Wadekar28dcc212016-07-20 10:28:51 -070020 TEGRA_PLATFORM_QT,
21 TEGRA_PLATFORM_FPGA,
22 TEGRA_PLATFORM_EMULATION,
Anthony Zhou70262ef2017-03-22 14:37:04 +080023 TEGRA_PLATFORM_LINSIM,
24 TEGRA_PLATFORM_UNIT_FPGA,
25 TEGRA_PLATFORM_VIRT_DEV_KIT,
Varun Wadekar28dcc212016-07-20 10:28:51 -070026 TEGRA_PLATFORM_MAX,
27} tegra_platform_t;
28
29/*******************************************************************************
30 * Tegra macros defining all the SoC minor versions
31 ******************************************************************************/
Anthony Zhou70262ef2017-03-22 14:37:04 +080032#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 Wadekar28dcc212016-07-20 10:28:51 -070039
40/*******************************************************************************
Anthony Zhou70262ef2017-03-22 14:37:04 +080041 * 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 Wadekar28dcc212016-07-20 10:28:51 -070050
Varun Wadekar28dcc212016-07-20 10:28:51 -070051/*
52 * Read the chip ID value
53 */
54static 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 Wadekarfc9b91e2017-03-10 09:53:37 -080062uint32_t tegra_get_chipid_major(void)
Varun Wadekar28dcc212016-07-20 10:28:51 -070063{
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 Wadekarfc9b91e2017-03-10 09:53:37 -080070uint32_t tegra_get_chipid_minor(void)
Varun Wadekar28dcc212016-07-20 10:28:51 -070071{
72 return (tegra_get_chipid() >> MINOR_VERSION_SHIFT) & MINOR_VERSION_MASK;
73}
74
Marvin Hsu589a7e12017-04-12 20:40:27 +080075/*
76 * Read the chip's pre_si_platform valus from the chip ID value
77 */
78static uint32_t tegra_get_chipid_pre_si_platform(void)
Varun Wadekar28dcc212016-07-20 10:28:51 -070079{
Marvin Hsu589a7e12017-04-12 20:40:27 +080080 return (tegra_get_chipid() >> PRE_SI_PLATFORM_SHIFT) & PRE_SI_PLATFORM_MASK;
81}
Varun Wadekar28dcc212016-07-20 10:28:51 -070082
Marvin Hsu589a7e12017-04-12 20:40:27 +080083bool tegra_chipid_is_t132(void)
84{
85 uint32_t chip_id = ((tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK);
86
Anthony Zhou4408e882017-07-07 14:29:51 +080087 return (chip_id == TEGRA_CHIPID_TEGRA13);
Varun Wadekar28dcc212016-07-20 10:28:51 -070088}
89
Marvin Hsu589a7e12017-04-12 20:40:27 +080090bool tegra_chipid_is_t186(void)
Varun Wadekar28dcc212016-07-20 10:28:51 -070091{
92 uint32_t chip_id = (tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK;
93
Marvin Hsu589a7e12017-04-12 20:40:27 +080094 return (chip_id == TEGRA_CHIPID_TEGRA18);
Varun Wadekar28dcc212016-07-20 10:28:51 -070095}
96
Marvin Hsu589a7e12017-04-12 20:40:27 +080097bool tegra_chipid_is_t210(void)
Varun Wadekarfdcdfe22017-04-13 14:12:49 -070098{
99 uint32_t chip_id = (tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK;
100
Anthony Zhou4408e882017-07-07 14:29:51 +0800101 return (chip_id == TEGRA_CHIPID_TEGRA21);
Varun Wadekarfdcdfe22017-04-13 14:12:49 -0700102}
103
Marvin Hsu589a7e12017-04-12 20:40:27 +0800104bool tegra_chipid_is_t210_b01(void)
Anthony Zhou70262ef2017-03-22 14:37:04 +0800105{
Anthony Zhou4408e882017-07-07 14:29:51 +0800106 return (tegra_chipid_is_t210() && (tegra_get_chipid_major() == 0x2U));
Anthony Zhou70262ef2017-03-22 14:37:04 +0800107}
108
109/*
Varun Wadekar28dcc212016-07-20 10:28:51 -0700110 * Read the chip ID value and derive the platform
111 */
112static tegra_platform_t tegra_get_platform(void)
113{
Anthony Zhou70262ef2017-03-22 14:37:04 +0800114 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 Wadekar28dcc212016-07-20 10:28:51 -0700150
Anthony Zhou70262ef2017-03-22 14:37:04 +0800151 /*
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 Hsu589a7e12017-04-12 20:40:27 +0800165
Anthony Zhou70262ef2017-03-22 14:37:04 +0800166 default:
Anthony Zhou70262ef2017-03-22 14:37:04 +0800167 ret = TEGRA_PLATFORM_MAX;
168 break;
169 }
Varun Wadekar28dcc212016-07-20 10:28:51 -0700170
Anthony Zhou70262ef2017-03-22 14:37:04 +0800171 } else if (pre_si_platform > 0U) {
Varun Wadekar28dcc212016-07-20 10:28:51 -0700172
Anthony Zhou70262ef2017-03-22 14:37:04 +0800173 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 Wadekar28dcc212016-07-20 10:28:51 -0700182
Anthony Zhou70262ef2017-03-22 14:37:04 +0800183 /*
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 Wadekar28dcc212016-07-20 10:28:51 -0700197
Anthony Zhou70262ef2017-03-22 14:37:04 +0800198 /*
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 Wadekar28dcc212016-07-20 10:28:51 -0700212
Anthony Zhou70262ef2017-03-22 14:37:04 +0800213 default:
Anthony Zhou70262ef2017-03-22 14:37:04 +0800214 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
226bool tegra_platform_is_silicon(void)
227{
228 return ((tegra_get_platform() == TEGRA_PLATFORM_SILICON) ? true : false);
Varun Wadekar28dcc212016-07-20 10:28:51 -0700229}
230
Anthony Zhou70262ef2017-03-22 14:37:04 +0800231bool tegra_platform_is_qt(void)
Varun Wadekar28dcc212016-07-20 10:28:51 -0700232{
Anthony Zhou70262ef2017-03-22 14:37:04 +0800233 return ((tegra_get_platform() == TEGRA_PLATFORM_QT) ? true : false);
Varun Wadekar28dcc212016-07-20 10:28:51 -0700234}
235
Anthony Zhou70262ef2017-03-22 14:37:04 +0800236bool tegra_platform_is_linsim(void)
Varun Wadekar28dcc212016-07-20 10:28:51 -0700237{
Anthony Zhou70262ef2017-03-22 14:37:04 +0800238 tegra_platform_t plat = tegra_get_platform();
239
240 return (((plat == TEGRA_PLATFORM_LINSIM) ||
241 (plat == TEGRA_PLATFORM_UNIT_FPGA)) ? true : false);
Varun Wadekar28dcc212016-07-20 10:28:51 -0700242}
243
Anthony Zhou70262ef2017-03-22 14:37:04 +0800244bool tegra_platform_is_fpga(void)
Varun Wadekar28dcc212016-07-20 10:28:51 -0700245{
Anthony Zhou70262ef2017-03-22 14:37:04 +0800246 return ((tegra_get_platform() == TEGRA_PLATFORM_FPGA) ? true : false);
Varun Wadekar28dcc212016-07-20 10:28:51 -0700247}
248
Anthony Zhou70262ef2017-03-22 14:37:04 +0800249bool tegra_platform_is_emulation(void)
Varun Wadekar28dcc212016-07-20 10:28:51 -0700250{
251 return (tegra_get_platform() == TEGRA_PLATFORM_EMULATION);
252}
Anthony Zhou70262ef2017-03-22 14:37:04 +0800253
254bool tegra_platform_is_unit_fpga(void)
255{
256 return ((tegra_get_platform() == TEGRA_PLATFORM_UNIT_FPGA) ? true : false);
257}
258
259bool tegra_platform_is_virt_dev_kit(void)
260{
261 return ((tegra_get_platform() == TEGRA_PLATFORM_VIRT_DEV_KIT) ? true : false);
262}
Varun Wadekar3923f882020-05-12 14:04:10 -0700263
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 */
271int32_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 */
285int32_t plat_get_soc_revision(void)
286{
287 return (int32_t)((tegra_get_chipid_major() << 8) | tegra_get_chipid_minor());
288}