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