xref: /optee_os/core/arch/arm/plat-imx/imx-common.c (revision 0608dbc2fc99156fb8ec8aa0e4dc1c979461761a)
11bb92983SJerome Forissier // SPDX-License-Identifier: BSD-2-Clause
2552cad35SPeng Fan /*
3552cad35SPeng Fan  * Copyright (C) 2016 Freescale Semiconductor, Inc.
40a8e42ddSClement Faure  * Copyright 2017-2019, 2021 NXP
5552cad35SPeng Fan  *
6552cad35SPeng Fan  * Peng Fan <peng.fan@nxp.com>
7552cad35SPeng Fan  */
8552cad35SPeng Fan 
90a8e42ddSClement Faure #include <config.h>
10552cad35SPeng Fan #include <console.h>
11552cad35SPeng Fan #include <io.h>
12552cad35SPeng Fan #include <imx.h>
13552cad35SPeng Fan #include <mm/core_mmu.h>
14552cad35SPeng Fan #include <mm/core_memprot.h>
15552cad35SPeng Fan #include <platform_config.h>
16552cad35SPeng Fan 
170a8e42ddSClement Faure #define SOC_TYPE(reg)	       (((reg) & (0x00FF0000)) >> 16)
180a8e42ddSClement Faure #define SOC_REV_MAJOR(reg)     (((reg) & (0x0000FF00)) >> 8)
190a8e42ddSClement Faure #define SOC_REV_MINOR(reg)     ((reg) & (0x0000000F))
200a8e42ddSClement Faure #define SOC_REV_MINOR_MX7(reg) ((reg) & (0x000000FF))
21ad817142SPeng Fan 
220a8e42ddSClement Faure static uint32_t imx_digprog;
23247f081aSClement Faure 
240a8e42ddSClement Faure #ifdef ANATOP_BASE
imx_get_digprog(void)250a8e42ddSClement Faure uint32_t imx_get_digprog(void)
26247f081aSClement Faure {
270a8e42ddSClement Faure 	vaddr_t addr = 0;
28247f081aSClement Faure 
290a8e42ddSClement Faure 	if (imx_digprog)
300a8e42ddSClement Faure 		return imx_digprog;
31ad817142SPeng Fan 
320a8e42ddSClement Faure 	addr = core_mmu_get_va(ANATOP_BASE, MEM_AREA_IO_SEC, 0x1000);
330a8e42ddSClement Faure 	if (!addr)
340a8e42ddSClement Faure 		return 0;
35ad817142SPeng Fan 
360a8e42ddSClement Faure 	imx_digprog = io_read32(addr + DIGPROG_OFFSET);
37247f081aSClement Faure 
380a8e42ddSClement Faure #ifdef CFG_MX8MQ
390a8e42ddSClement Faure 	/*
400a8e42ddSClement Faure 	 * On the i.MX8MQ, the minor revision number must be updated to make
410a8e42ddSClement Faure 	 * the difference between B0 chip and the newer chips.
420a8e42ddSClement Faure 	 */
430a8e42ddSClement Faure 	addr = core_mmu_get_va(OCOTP_BASE, MEM_AREA_IO_SEC, OCOTP_SIZE);
440a8e42ddSClement Faure 	if (!addr)
450a8e42ddSClement Faure 		return 0;
460a8e42ddSClement Faure 
470a8e42ddSClement Faure 	if (io_read32(addr + OCOTP_SW_INFO_B1) == OCOTP_SW_MAGIC_B1)
480a8e42ddSClement Faure 		imx_digprog |= BIT32(0);
490a8e42ddSClement Faure #endif /* CFG_MX8MQ */
500a8e42ddSClement Faure 
510a8e42ddSClement Faure 	return imx_digprog;
520a8e42ddSClement Faure }
530a8e42ddSClement Faure #else  /* ANATOP_BASE */
imx_get_digprog(void)540a8e42ddSClement Faure uint32_t imx_get_digprog(void)
550a8e42ddSClement Faure {
560a8e42ddSClement Faure 	if (imx_digprog)
570a8e42ddSClement Faure 		return imx_digprog;
580a8e42ddSClement Faure 
590a8e42ddSClement Faure 	if (IS_ENABLED(CFG_MX7ULP))
600a8e42ddSClement Faure 		imx_digprog = SOC_MX7ULP << 16;
610a8e42ddSClement Faure 	else if (IS_ENABLED(CFG_MX8QX))
620a8e42ddSClement Faure 		imx_digprog = SOC_MX8QX << 16;
630a8e42ddSClement Faure 	else if (IS_ENABLED(CFG_MX8QM))
640a8e42ddSClement Faure 		imx_digprog = SOC_MX8QM << 16;
652a7ffe2fSSilvano di Ninno 	else if (IS_ENABLED(CFG_MX8DXL))
662a7ffe2fSSilvano di Ninno 		imx_digprog = SOC_MX8DXL << 16;
679781fbd2SClement Faure 	else if (IS_ENABLED(CFG_MX8ULP))
689781fbd2SClement Faure 		imx_digprog = SOC_MX8ULP << 16;
69d0d5da25SClement Faure 	else if (IS_ENABLED(CFG_MX93))
70d0d5da25SClement Faure 		imx_digprog = SOC_MX93 << 16;
71*0608dbc2SSahil Malhotra 	else if (IS_ENABLED(CFG_MX91))
72*0608dbc2SSahil Malhotra 		imx_digprog = SOC_MX91 << 16;
738536585dSSahil Malhotra 	else if (IS_ENABLED(CFG_MX95))
748536585dSSahil Malhotra 		imx_digprog = SOC_MX95 << 16;
750a8e42ddSClement Faure 
760a8e42ddSClement Faure 	return imx_digprog;
770a8e42ddSClement Faure }
780a8e42ddSClement Faure #endif /* ANATOP_BASE */
790a8e42ddSClement Faure 
imx_soc_rev_major(void)800a8e42ddSClement Faure uint32_t imx_soc_rev_major(void)
810a8e42ddSClement Faure {
820a8e42ddSClement Faure 	if (imx_digprog == 0)
830a8e42ddSClement Faure 		imx_get_digprog();
840a8e42ddSClement Faure 
850a8e42ddSClement Faure 	return SOC_REV_MAJOR(imx_digprog);
86ad817142SPeng Fan }
87ad817142SPeng Fan 
imx_soc_rev_minor(void)880a8e42ddSClement Faure uint32_t imx_soc_rev_minor(void)
89ad817142SPeng Fan {
900a8e42ddSClement Faure 	if (imx_digprog == 0)
910a8e42ddSClement Faure 		imx_get_digprog();
92247f081aSClement Faure 
930a8e42ddSClement Faure 	if (IS_ENABLED(CFG_MX7))
940a8e42ddSClement Faure 		return SOC_REV_MINOR_MX7(imx_digprog);
950a8e42ddSClement Faure 	else
960a8e42ddSClement Faure 		return SOC_REV_MINOR(imx_digprog);
97ad817142SPeng Fan }
98ad817142SPeng Fan 
imx_soc_type(void)990a8e42ddSClement Faure uint32_t imx_soc_type(void)
100ad817142SPeng Fan {
1010a8e42ddSClement Faure 	if (imx_digprog == 0)
1020a8e42ddSClement Faure 		imx_get_digprog();
103247f081aSClement Faure 
1040a8e42ddSClement Faure 	return SOC_TYPE(imx_digprog);
105ad817142SPeng Fan }
106ad817142SPeng Fan 
soc_is_imx6sl(void)10764de482eSBai Ping bool soc_is_imx6sl(void)
10864de482eSBai Ping {
10964de482eSBai Ping 	return imx_soc_type() == SOC_MX6SL;
11064de482eSBai Ping }
11164de482eSBai Ping 
soc_is_imx6sll(void)1124dac8328SBai Ping bool soc_is_imx6sll(void)
1134dac8328SBai Ping {
1144dac8328SBai Ping 	return imx_soc_type() == SOC_MX6SLL;
1154dac8328SBai Ping }
1164dac8328SBai Ping 
soc_is_imx6sx(void)11716e73240SCedric Neveux bool soc_is_imx6sx(void)
11816e73240SCedric Neveux {
11916e73240SCedric Neveux 	return imx_soc_type() == SOC_MX6SX;
12016e73240SCedric Neveux }
12116e73240SCedric Neveux 
soc_is_imx6ul(void)122ad817142SPeng Fan bool soc_is_imx6ul(void)
123ad817142SPeng Fan {
124ad817142SPeng Fan 	return imx_soc_type() == SOC_MX6UL;
125ad817142SPeng Fan }
126ad817142SPeng Fan 
soc_is_imx6ull(void)127ad817142SPeng Fan bool soc_is_imx6ull(void)
128ad817142SPeng Fan {
129ad817142SPeng Fan 	return imx_soc_type() == SOC_MX6ULL;
130ad817142SPeng Fan }
131ad817142SPeng Fan 
soc_is_imx6sdl(void)132ad817142SPeng Fan bool soc_is_imx6sdl(void)
133ad817142SPeng Fan {
134ad817142SPeng Fan 	return imx_soc_type() == SOC_MX6DL;
135ad817142SPeng Fan }
136ad817142SPeng Fan 
soc_is_imx6dq(void)137ad817142SPeng Fan bool soc_is_imx6dq(void)
138ad817142SPeng Fan {
1390a8e42ddSClement Faure 	return (imx_soc_type() == SOC_MX6Q) && (imx_soc_rev_major() == 0);
140ad817142SPeng Fan }
141ad817142SPeng Fan 
soc_is_imx6dqp(void)142ad817142SPeng Fan bool soc_is_imx6dqp(void)
143ad817142SPeng Fan {
1440a8e42ddSClement Faure 	return (imx_soc_type() == SOC_MX6Q) && (imx_soc_rev_major() == 1);
145ad817142SPeng Fan }
146ad817142SPeng Fan 
soc_is_imx6(void)14716e73240SCedric Neveux bool soc_is_imx6(void)
14816e73240SCedric Neveux {
149dab608c0SClement Faure 	uint32_t soc = imx_soc_type();
150dab608c0SClement Faure 
151dab608c0SClement Faure 	return (soc == SOC_MX6SLL) || (soc == SOC_MX6SL) ||
152dab608c0SClement Faure 	       (soc == SOC_MX6D) || (soc == SOC_MX6SX) ||
153dab608c0SClement Faure 	       (soc == SOC_MX6UL) || (soc == SOC_MX6ULL) ||
154dab608c0SClement Faure 	       (soc == SOC_MX6DL) || (soc == SOC_MX6Q);
15516e73240SCedric Neveux }
15616e73240SCedric Neveux 
soc_is_imx7ds(void)157ad817142SPeng Fan bool soc_is_imx7ds(void)
158ad817142SPeng Fan {
159ad817142SPeng Fan 	return imx_soc_type() == SOC_MX7D;
160ad817142SPeng Fan }
161ad817142SPeng Fan 
soc_is_imx7ulp(void)162c3d61baaSClement Faure bool soc_is_imx7ulp(void)
163c3d61baaSClement Faure {
164c3d61baaSClement Faure 	return imx_soc_type() == SOC_MX7ULP;
165c3d61baaSClement Faure }
1660a8e42ddSClement Faure 
soc_is_imx8mq(void)1670a8e42ddSClement Faure bool soc_is_imx8mq(void)
1680a8e42ddSClement Faure {
1690a8e42ddSClement Faure 	return imx_soc_type() == SOC_MX8M && imx_soc_rev_major() == 0x40;
1700a8e42ddSClement Faure }
1710a8e42ddSClement Faure 
soc_is_imx8mm(void)1720a8e42ddSClement Faure bool soc_is_imx8mm(void)
1730a8e42ddSClement Faure {
1740a8e42ddSClement Faure 	return imx_soc_type() == SOC_MX8M && imx_soc_rev_major() == 0x41;
1750a8e42ddSClement Faure }
1760a8e42ddSClement Faure 
soc_is_imx8mn(void)1770a8e42ddSClement Faure bool soc_is_imx8mn(void)
1780a8e42ddSClement Faure {
1790a8e42ddSClement Faure 	return imx_soc_type() == SOC_MX8M && imx_soc_rev_major() == 0x42;
1800a8e42ddSClement Faure }
1810a8e42ddSClement Faure 
soc_is_imx8mp(void)1820a8e42ddSClement Faure bool soc_is_imx8mp(void)
1830a8e42ddSClement Faure {
1840a8e42ddSClement Faure 	return imx_soc_type() == SOC_MX8M && imx_soc_rev_major() == 0x43;
1850a8e42ddSClement Faure }
1860a8e42ddSClement Faure 
soc_is_imx8m(void)1870a8e42ddSClement Faure bool soc_is_imx8m(void)
1880a8e42ddSClement Faure {
1890a8e42ddSClement Faure 	return soc_is_imx8mq() || soc_is_imx8mm() || soc_is_imx8mn() ||
1900a8e42ddSClement Faure 	       soc_is_imx8mp();
1910a8e42ddSClement Faure }
1920a8e42ddSClement Faure 
soc_is_imx8mq_b0_layer(void)1930a8e42ddSClement Faure bool soc_is_imx8mq_b0_layer(void)
1940a8e42ddSClement Faure {
1950a8e42ddSClement Faure 	if (soc_is_imx8mq() && imx_soc_rev_minor() == 0x0)
1960a8e42ddSClement Faure 		return true;
1970a8e42ddSClement Faure 	else
1980a8e42ddSClement Faure 		return false;
1990a8e42ddSClement Faure }
200