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