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