Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Hou Zhiqiang | a1124da | 2024-08-01 11:59:50 +0800 | [diff] [blame] | 3 | * Copyright 2019, 2024 NXP |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 6 | #include <cpu.h> |
| 7 | #include <dm.h> |
| 8 | #include <thermal.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Hou Zhiqiang | 863a154 | 2024-08-01 11:59:54 +0800 | [diff] [blame] | 10 | #include <asm/ptrace.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <asm/system.h> |
Peng Fan | 2e0644a | 2023-04-28 12:08:09 +0800 | [diff] [blame] | 12 | #include <firmware/imx/sci/sci.h> |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <asm/arch-imx/cpu.h> |
| 15 | #include <asm/armv8/cpu.h> |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 16 | #include <imx_thermal.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 17 | #include <linux/bitops.h> |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 18 | #include <linux/clk-provider.h> |
Hou Zhiqiang | 863a154 | 2024-08-01 11:59:54 +0800 | [diff] [blame] | 19 | #include <linux/psci.h> |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 23 | #define IMX_REV_LEN 4 |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 24 | struct cpu_imx_plat { |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 25 | const char *name; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 26 | const char *type; |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 27 | char rev[IMX_REV_LEN]; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 28 | u32 cpu_rsrc; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 29 | u32 cpurev; |
| 30 | u32 freq_mhz; |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 31 | u32 mpidr; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 34 | static const char *get_imx_type_str(u32 imxtype) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 35 | { |
| 36 | switch (imxtype) { |
Hou Zhiqiang | 78ff9db | 2024-08-01 11:59:53 +0800 | [diff] [blame] | 37 | case MXC_CPU_IMX8MM: |
Adam Ford | 8b45311 | 2025-03-24 21:54:43 -0500 | [diff] [blame] | 38 | return "8MMQ"; /* Quad-core version of the imx8mm */ |
| 39 | case MXC_CPU_IMX8MML: |
| 40 | return "8MMQL"; /* Quad-core Lite version of the imx8mm */ |
| 41 | case MXC_CPU_IMX8MMD: |
| 42 | return "8MMD"; /* Dual-core version of the imx8mm */ |
| 43 | case MXC_CPU_IMX8MMDL: |
| 44 | return "8MMDL"; /* Dual-core Lite version of the imx8mm */ |
| 45 | case MXC_CPU_IMX8MMS: |
| 46 | return "8MMS"; /* Single-core version of the imx8mm */ |
| 47 | case MXC_CPU_IMX8MMSL: |
| 48 | return "8MMSL"; /* Single-core Lite version of the imx8mm */ |
Hou Zhiqiang | 78ff9db | 2024-08-01 11:59:53 +0800 | [diff] [blame] | 49 | case MXC_CPU_IMX8MN: |
Adam Ford | 8b45311 | 2025-03-24 21:54:43 -0500 | [diff] [blame] | 50 | return "8MNano Quad"; /* Quad-core version */ |
| 51 | case MXC_CPU_IMX8MND: |
| 52 | return "8MNano Dual"; /* Dual-core version */ |
| 53 | case MXC_CPU_IMX8MNS: |
| 54 | return "8MNano Solo"; /* Single-core version */ |
| 55 | case MXC_CPU_IMX8MNL: |
| 56 | return "8MNano QuadLite"; /* Quad-core Lite version */ |
| 57 | case MXC_CPU_IMX8MNDL: |
| 58 | return "8MNano DualLite"; /* Dual-core Lite version */ |
| 59 | case MXC_CPU_IMX8MNSL: |
| 60 | return "8MNano SoloLite";/* Single-core Lite version of the imx8mn */ |
| 61 | case MXC_CPU_IMX8MNUQ: |
| 62 | return "8MNano UltraLite Quad";/* Quad-core UltraLite version of the imx8mn */ |
| 63 | case MXC_CPU_IMX8MNUD: |
| 64 | return "8MNano UltraLite Dual";/* Dual-core UltraLite version of the imx8mn */ |
| 65 | case MXC_CPU_IMX8MNUS: |
| 66 | return "8MNano UltraLite Solo";/* Single-core UltraLite version of the imx8mn */ |
Hou Zhiqiang | 78ff9db | 2024-08-01 11:59:53 +0800 | [diff] [blame] | 67 | case MXC_CPU_IMX8MP: |
Adam Ford | 8b45311 | 2025-03-24 21:54:43 -0500 | [diff] [blame] | 68 | return "8MP[8]"; /* Quad-core version of the imx8mp */ |
| 69 | case MXC_CPU_IMX8MPD: |
| 70 | return "8MP Dual[3]"; /* Dual-core version of the imx8mp */ |
| 71 | case MXC_CPU_IMX8MPL: |
| 72 | return "8MP Lite[4]"; /* Quad-core Lite version of the imx8mp */ |
| 73 | case MXC_CPU_IMX8MP6: |
| 74 | return "8MP[6]"; /* Quad-core version of the imx8mp, NPU fused */ |
| 75 | case MXC_CPU_IMX8MQ: |
| 76 | return "8MQ"; /* Quad-core version of the imx8mq */ |
| 77 | case MXC_CPU_IMX8MQL: |
| 78 | return "8MQLite"; /* Quad-core Lite version of the imx8mq */ |
| 79 | case MXC_CPU_IMX8MD: |
| 80 | return "8MD"; /* Dual-core version of the imx8mq */ |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 81 | case MXC_CPU_IMX8QXP: |
| 82 | case MXC_CPU_IMX8QXP_A0: |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 83 | return "8QXP"; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 84 | case MXC_CPU_IMX8QM: |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 85 | return "8QM"; |
| 86 | case MXC_CPU_IMX93: |
| 87 | return "93(52)";/* iMX93 Dual core with NPU */ |
Peng Fan | c3db3ad | 2023-04-28 12:08:32 +0800 | [diff] [blame] | 88 | case MXC_CPU_IMX9351: |
| 89 | return "93(51)";/* iMX93 Single core with NPU */ |
| 90 | case MXC_CPU_IMX9332: |
| 91 | return "93(32)";/* iMX93 Dual core without NPU */ |
| 92 | case MXC_CPU_IMX9331: |
| 93 | return "93(31)";/* iMX93 Single core without NPU */ |
| 94 | case MXC_CPU_IMX9322: |
| 95 | return "93(22)";/* iMX93 9x9 Dual core */ |
| 96 | case MXC_CPU_IMX9321: |
| 97 | return "93(21)";/* iMX93 9x9 Single core */ |
| 98 | case MXC_CPU_IMX9312: |
| 99 | return "93(12)";/* iMX93 9x9 Dual core without NPU */ |
| 100 | case MXC_CPU_IMX9311: |
| 101 | return "93(11)";/* iMX93 9x9 Single core without NPU */ |
Ye Li | 57b2ac4 | 2024-09-19 12:01:33 +0800 | [diff] [blame] | 102 | case MXC_CPU_IMX9302: |
| 103 | return "93(02)";/* iMX93 900Mhz Low performance Dual core without NPU */ |
| 104 | case MXC_CPU_IMX9301: |
| 105 | return "93(01)";/* iMX93 900Mhz Low performance Single core without NPU */ |
Peng Fan | 0ce300f | 2024-12-03 23:42:48 +0800 | [diff] [blame] | 106 | case MXC_CPU_IMX91: |
| 107 | return "91(31)";/* iMX91 11x11 Full feature */ |
| 108 | case MXC_CPU_IMX9121: |
| 109 | return "91(21)";/* iMX91 11x11 Low drive mode */ |
| 110 | case MXC_CPU_IMX9111: |
| 111 | return "91(11)";/* iMX91 9x9 Reduced feature */ |
| 112 | case MXC_CPU_IMX9101: |
| 113 | return "91(01)";/* iMX91 9x9 Specific feature */ |
Alice Guo | 22d6e2f | 2025-04-28 18:37:35 +0800 | [diff] [blame] | 114 | case MXC_CPU_IMX95: |
| 115 | return "95"; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 116 | default: |
| 117 | return "??"; |
| 118 | } |
| 119 | } |
| 120 | |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 121 | static void get_imx_rev_str(struct cpu_imx_plat *plat, u32 rev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 122 | { |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 123 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 124 | switch (rev) { |
| 125 | case CHIP_REV_A: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 126 | plat->rev[0] = 'A'; |
| 127 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 128 | case CHIP_REV_B: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 129 | plat->rev[0] = 'B'; |
| 130 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 131 | case CHIP_REV_C: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 132 | plat->rev[0] = 'C'; |
| 133 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 134 | default: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 135 | plat->rev[0] = '?'; |
| 136 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 137 | } |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 138 | plat->rev[1] = '\0'; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 139 | } else { |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 140 | plat->rev[0] = '1' + (((rev & 0xf0) - CHIP_REV_1_0) >> 4); |
| 141 | plat->rev[1] = '.'; |
| 142 | plat->rev[2] = '0' + (rev & 0xf); |
| 143 | plat->rev[3] = '\0'; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 147 | static void set_core_data(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 148 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 149 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 150 | |
| 151 | if (device_is_compatible(dev, "arm,cortex-a35")) { |
| 152 | plat->cpu_rsrc = SC_R_A35; |
| 153 | plat->name = "A35"; |
| 154 | } else if (device_is_compatible(dev, "arm,cortex-a53")) { |
| 155 | plat->cpu_rsrc = SC_R_A53; |
| 156 | plat->name = "A53"; |
| 157 | } else if (device_is_compatible(dev, "arm,cortex-a72")) { |
| 158 | plat->cpu_rsrc = SC_R_A72; |
| 159 | plat->name = "A72"; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 160 | } else if (device_is_compatible(dev, "arm,cortex-a55")) { |
| 161 | plat->name = "A55"; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 162 | } else { |
| 163 | plat->cpu_rsrc = SC_R_A53; |
| 164 | plat->name = "?"; |
| 165 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 168 | #if IS_ENABLED(CONFIG_DM_THERMAL) |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 169 | static int cpu_imx_get_temp(struct cpu_imx_plat *plat) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 170 | { |
| 171 | struct udevice *thermal_dev; |
| 172 | int cpu_tmp, ret; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 173 | int idx = 1; /* use "cpu-thermal0" device */ |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 174 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 175 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 176 | if (plat->cpu_rsrc == SC_R_A72) |
| 177 | idx = 2; /* use "cpu-thermal1" device */ |
Peng Fan | 0ce300f | 2024-12-03 23:42:48 +0800 | [diff] [blame] | 178 | } else if (IS_ENABLED(CONFIG_IMX91)) { |
| 179 | idx = 0; |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 180 | } else { |
| 181 | idx = 1; |
| 182 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 183 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 184 | ret = uclass_get_device(UCLASS_THERMAL, idx, &thermal_dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 185 | if (!ret) { |
| 186 | ret = thermal_get_temp(thermal_dev, &cpu_tmp); |
| 187 | if (ret) |
| 188 | return 0xdeadbeef; |
| 189 | } else { |
| 190 | return 0xdeadbeef; |
| 191 | } |
| 192 | |
| 193 | return cpu_tmp; |
| 194 | } |
| 195 | #else |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 196 | static int cpu_imx_get_temp(struct cpu_imx_plat *plat) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 197 | { |
| 198 | return 0; |
| 199 | } |
| 200 | #endif |
| 201 | |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 202 | __weak u32 get_cpu_temp_grade(int *minc, int *maxc) |
| 203 | { |
| 204 | return 0; |
| 205 | } |
| 206 | |
Peng Fan | d3ee4de | 2023-04-28 12:08:11 +0800 | [diff] [blame] | 207 | static int cpu_imx_get_desc(const struct udevice *dev, char *buf, int size) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 208 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 209 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 210 | const char *grade; |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 211 | int ret, temp; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 212 | int minc, maxc; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 213 | |
| 214 | if (size < 100) |
| 215 | return -ENOSPC; |
| 216 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 217 | ret = snprintf(buf, size, "NXP i.MX%s Rev%s %s at %u MHz", |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 218 | plat->type, plat->rev, plat->name, plat->freq_mhz); |
| 219 | |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 220 | if (IS_ENABLED(CONFIG_IMX_TMU)) { |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 221 | switch (get_cpu_temp_grade(&minc, &maxc)) { |
| 222 | case TEMP_AUTOMOTIVE: |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 223 | grade = "Automotive temperature grade"; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 224 | break; |
| 225 | case TEMP_INDUSTRIAL: |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 226 | grade = "Industrial temperature grade"; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 227 | break; |
| 228 | case TEMP_EXTCOMMERCIAL: |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 229 | grade = "Extended Consumer temperature grade"; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 230 | break; |
| 231 | default: |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 232 | grade = "Consumer temperature grade"; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 233 | break; |
| 234 | } |
| 235 | |
| 236 | buf = buf + ret; |
| 237 | size = size - ret; |
| 238 | ret = snprintf(buf, size, "\nCPU: %s (%dC to %dC)", grade, minc, maxc); |
| 239 | } |
| 240 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 241 | if (IS_ENABLED(CONFIG_DM_THERMAL)) { |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 242 | temp = cpu_imx_get_temp(plat); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 243 | buf = buf + ret; |
| 244 | size = size - ret; |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 245 | if (temp != 0xdeadbeef) |
| 246 | ret = snprintf(buf, size, " at %dC", temp); |
| 247 | else |
| 248 | ret = snprintf(buf, size, " - invalid sensor data"); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 254 | static int cpu_imx_get_info(const struct udevice *dev, struct cpu_info *info) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 255 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 256 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 257 | |
Hou Zhiqiang | a1124da | 2024-08-01 11:59:50 +0800 | [diff] [blame] | 258 | info->cpu_freq = plat->freq_mhz * 1000000; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 259 | info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU); |
| 260 | return 0; |
| 261 | } |
| 262 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 263 | static int cpu_imx_get_count(const struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 264 | { |
Peng Fan | 8296b74 | 2020-05-03 21:58:51 +0800 | [diff] [blame] | 265 | ofnode node; |
| 266 | int num = 0; |
| 267 | |
| 268 | ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) { |
| 269 | const char *device_type; |
| 270 | |
Simon Glass | 2e4938b | 2022-09-06 20:27:17 -0600 | [diff] [blame] | 271 | if (!ofnode_is_enabled(node)) |
Peng Fan | 8296b74 | 2020-05-03 21:58:51 +0800 | [diff] [blame] | 272 | continue; |
| 273 | |
| 274 | device_type = ofnode_read_string(node, "device_type"); |
| 275 | if (!device_type) |
| 276 | continue; |
| 277 | |
| 278 | if (!strcmp(device_type, "cpu")) |
| 279 | num++; |
| 280 | } |
| 281 | |
| 282 | return num; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 285 | static int cpu_imx_get_vendor(const struct udevice *dev, char *buf, int size) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 286 | { |
| 287 | snprintf(buf, size, "NXP"); |
| 288 | return 0; |
| 289 | } |
| 290 | |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 291 | static int cpu_imx_is_current(struct udevice *dev) |
| 292 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 293 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 294 | |
| 295 | if (plat->mpidr == (read_mpidr() & 0xffff)) |
| 296 | return 1; |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
Hou Zhiqiang | 863a154 | 2024-08-01 11:59:54 +0800 | [diff] [blame] | 301 | static int cpu_imx_release_core(const struct udevice *dev, phys_addr_t addr) |
| 302 | { |
| 303 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
| 304 | struct pt_regs regs; |
| 305 | |
| 306 | regs.regs[0] = PSCI_0_2_FN64_CPU_ON; |
| 307 | regs.regs[1] = plat->mpidr; |
| 308 | regs.regs[2] = addr; |
| 309 | regs.regs[3] = 0; |
| 310 | |
| 311 | smc_call(®s); |
| 312 | if (regs.regs[0]) { |
| 313 | printf("Failed to release CPU core (mpidr: 0x%x)\n", plat->mpidr); |
| 314 | return -1; |
| 315 | } |
| 316 | |
| 317 | printf("Released CPU core (mpidr: 0x%x) to address 0x%llx\n", plat->mpidr, addr); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 322 | static const struct cpu_ops cpu_imx_ops = { |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 323 | .get_desc = cpu_imx_get_desc, |
| 324 | .get_info = cpu_imx_get_info, |
| 325 | .get_count = cpu_imx_get_count, |
| 326 | .get_vendor = cpu_imx_get_vendor, |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 327 | .is_current = cpu_imx_is_current, |
Hou Zhiqiang | 863a154 | 2024-08-01 11:59:54 +0800 | [diff] [blame] | 328 | .release_core = cpu_imx_release_core, |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 329 | }; |
| 330 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 331 | static const struct udevice_id cpu_imx_ids[] = { |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 332 | { .compatible = "arm,cortex-a35" }, |
| 333 | { .compatible = "arm,cortex-a53" }, |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 334 | { .compatible = "arm,cortex-a55" }, |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 335 | { .compatible = "arm,cortex-a72" }, |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 336 | { } |
| 337 | }; |
| 338 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 339 | static ulong imx_get_cpu_rate(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 340 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 341 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 342 | struct clk clk; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 343 | ulong rate; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 344 | int ret; |
Peng Fan | 4b1fbb7 | 2020-05-03 21:58:53 +0800 | [diff] [blame] | 345 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 346 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 347 | ret = sc_pm_get_clock_rate(-1, plat->cpu_rsrc, SC_PM_CLK_CPU, |
| 348 | (sc_pm_clock_rate_t *)&rate); |
| 349 | } else { |
| 350 | ret = clk_get_by_index(dev, 0, &clk); |
| 351 | if (!ret) { |
| 352 | rate = clk_get_rate(&clk); |
| 353 | if (!rate) |
| 354 | ret = -EOPNOTSUPP; |
| 355 | } |
| 356 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 357 | if (ret) { |
| 358 | printf("Could not read CPU frequency: %d\n", ret); |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | return rate; |
| 363 | } |
| 364 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 365 | static int imx_cpu_probe(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 366 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 367 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 368 | u32 cpurev; |
| 369 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 370 | set_core_data(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 371 | cpurev = get_cpu_rev(); |
| 372 | plat->cpurev = cpurev; |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 373 | get_imx_rev_str(plat, cpurev & 0xFFF); |
Hou Zhiqiang | c5e1a11 | 2024-08-01 11:59:51 +0800 | [diff] [blame] | 374 | plat->type = get_imx_type_str((cpurev & 0x1FF000) >> 12); |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 375 | plat->freq_mhz = imx_get_cpu_rate(dev) / 1000000; |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 376 | plat->mpidr = dev_read_addr(dev); |
| 377 | if (plat->mpidr == FDT_ADDR_T_NONE) { |
| 378 | printf("%s: Failed to get CPU reg property\n", __func__); |
| 379 | return -EINVAL; |
| 380 | } |
| 381 | |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 382 | return 0; |
| 383 | } |
| 384 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 385 | U_BOOT_DRIVER(cpu_imx_drv) = { |
| 386 | .name = "imx_cpu", |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 387 | .id = UCLASS_CPU, |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 388 | .of_match = cpu_imx_ids, |
| 389 | .ops = &cpu_imx_ops, |
| 390 | .probe = imx_cpu_probe, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 391 | .plat_auto = sizeof(struct cpu_imx_plat), |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 392 | .flags = DM_FLAG_PRE_RELOC, |
| 393 | }; |