xref: /optee_os/core/arch/arm/plat-imx/imx-common.c (revision 93aa02804b6bdf4f5b40dec0d0853f337496e0ff)
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 	anatop_addr = core_mmu_get_va(ANATOP_BASE, MEM_AREA_IO_SEC);
29 
30 	if (!anatop_addr)
31 		return;
32 
33 	digprog = io_read32(anatop_addr + DIGPROG_OFFSET);
34 
35 	/* Set the CPU type */
36 	imx_cpu_type = CPU_TYPE(digprog);
37 
38 #ifdef CFG_MX7
39 	imx_soc_revision = digprog & 0xFF;
40 #else
41 	/* Set the SOC revision: = (Major + 1)[11:4] | (Minor[3:0]) */
42 	imx_soc_revision =
43 		(SOC_REV_MAJOR(digprog) << 4) | SOC_REV_MINOR(digprog);
44 #endif
45 }
46 
47 static uint32_t imx_soc_rev_major(void)
48 {
49 	if (imx_soc_revision < 0)
50 		imx_digproc();
51 
52 	return imx_soc_revision >> 4;
53 }
54 
55 static uint32_t imx_soc_type(void)
56 {
57 	if (imx_cpu_type < 0)
58 		imx_digproc();
59 
60 	return imx_cpu_type;
61 }
62 
63 bool soc_is_imx6sl(void)
64 {
65 	return imx_soc_type() == SOC_MX6SL;
66 }
67 
68 bool soc_is_imx6sll(void)
69 {
70 	return imx_soc_type() == SOC_MX6SLL;
71 }
72 
73 bool soc_is_imx6sx(void)
74 {
75 	return imx_soc_type() == SOC_MX6SX;
76 }
77 
78 bool soc_is_imx6ul(void)
79 {
80 	return imx_soc_type() == SOC_MX6UL;
81 }
82 
83 bool soc_is_imx6ull(void)
84 {
85 	return imx_soc_type() == SOC_MX6ULL;
86 }
87 
88 bool soc_is_imx6sdl(void)
89 {
90 	return imx_soc_type() == SOC_MX6DL;
91 }
92 
93 bool soc_is_imx6dq(void)
94 {
95 	return (imx_soc_type() == SOC_MX6Q) && (imx_soc_rev_major() == 1);
96 }
97 
98 bool soc_is_imx6dqp(void)
99 {
100 	return (imx_soc_type() == SOC_MX6Q) && (imx_soc_rev_major() == 2);
101 }
102 
103 bool soc_is_imx6(void)
104 {
105 	return ((imx_soc_type() == SOC_MX6SX) ||
106 			(imx_soc_type() == SOC_MX6UL) ||
107 			(imx_soc_type() == SOC_MX6ULL) ||
108 			(imx_soc_type() == SOC_MX6DL) ||
109 			(imx_soc_type() == SOC_MX6Q));
110 }
111 
112 bool soc_is_imx7ds(void)
113 {
114 	return imx_soc_type() == SOC_MX7D;
115 }
116 
117