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