xref: /optee_os/core/arch/arm/plat-imx/imx-common.c (revision c3d61baa2e324dab3d3de3650020e1d932e59b85)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (C) 2016 Freescale Semiconductor, Inc.
4  * Copyright 2017-2019 NXP
5  *
6  * Peng Fan <peng.fan@nxp.com>
7  */
8 
9 #include <console.h>
10 #include <io.h>
11 #include <imx.h>
12 #include <mm/core_mmu.h>
13 #include <mm/core_memprot.h>
14 #include <platform_config.h>
15 
16 static int imx_cpu_type = -1;
17 static int imx_soc_revision = -1;
18 
19 #define CPU_TYPE(reg)		((reg & 0x00FF0000) >> 16)
20 #define SOC_REV_MAJOR(reg)	(((reg & 0x0000FF00) >> 8) + 1)
21 #define SOC_REV_MINOR(reg)	(reg & 0x0000000F)
22 
23 static void imx_digproc(void)
24 {
25 	uint32_t digprog = 0;
26 	vaddr_t __maybe_unused anatop_addr = 0;
27 
28 #ifdef CFG_MX7ULP
29 	digprog = SOC_MX7ULP << 16;
30 #else
31 	anatop_addr = core_mmu_get_va(ANATOP_BASE, MEM_AREA_IO_SEC);
32 
33 	if (!anatop_addr)
34 		return;
35 
36 	digprog = io_read32(anatop_addr + DIGPROG_OFFSET);
37 #endif
38 	/* Set the CPU type */
39 	imx_cpu_type = CPU_TYPE(digprog);
40 
41 #ifdef CFG_MX7
42 	imx_soc_revision = digprog & 0xFF;
43 #else
44 	/* Set the SOC revision: = (Major + 1)[11:4] | (Minor[3:0]) */
45 	imx_soc_revision =
46 		(SOC_REV_MAJOR(digprog) << 4) | SOC_REV_MINOR(digprog);
47 #endif
48 }
49 
50 static uint32_t imx_soc_rev_major(void)
51 {
52 	if (imx_soc_revision < 0)
53 		imx_digproc();
54 
55 	return imx_soc_revision >> 4;
56 }
57 
58 static uint32_t imx_soc_type(void)
59 {
60 	if (imx_cpu_type < 0)
61 		imx_digproc();
62 
63 	return imx_cpu_type;
64 }
65 
66 bool soc_is_imx6sl(void)
67 {
68 	return imx_soc_type() == SOC_MX6SL;
69 }
70 
71 bool soc_is_imx6sll(void)
72 {
73 	return imx_soc_type() == SOC_MX6SLL;
74 }
75 
76 bool soc_is_imx6sx(void)
77 {
78 	return imx_soc_type() == SOC_MX6SX;
79 }
80 
81 bool soc_is_imx6ul(void)
82 {
83 	return imx_soc_type() == SOC_MX6UL;
84 }
85 
86 bool soc_is_imx6ull(void)
87 {
88 	return imx_soc_type() == SOC_MX6ULL;
89 }
90 
91 bool soc_is_imx6sdl(void)
92 {
93 	return imx_soc_type() == SOC_MX6DL;
94 }
95 
96 bool soc_is_imx6dq(void)
97 {
98 	return (imx_soc_type() == SOC_MX6Q) && (imx_soc_rev_major() == 1);
99 }
100 
101 bool soc_is_imx6dqp(void)
102 {
103 	return (imx_soc_type() == SOC_MX6Q) && (imx_soc_rev_major() == 2);
104 }
105 
106 bool soc_is_imx6(void)
107 {
108 	return ((imx_soc_type() == SOC_MX6SX) ||
109 			(imx_soc_type() == SOC_MX6UL) ||
110 			(imx_soc_type() == SOC_MX6ULL) ||
111 			(imx_soc_type() == SOC_MX6DL) ||
112 			(imx_soc_type() == SOC_MX6Q));
113 }
114 
115 bool soc_is_imx7ds(void)
116 {
117 	return imx_soc_type() == SOC_MX7D;
118 }
119 
120 bool soc_is_imx7ulp(void)
121 {
122 	return imx_soc_type() == SOC_MX7ULP;
123 }
124