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 */ |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 114 | default: |
| 115 | return "??"; |
| 116 | } |
| 117 | } |
| 118 | |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 119 | 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] | 120 | { |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 121 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 122 | switch (rev) { |
| 123 | case CHIP_REV_A: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 124 | plat->rev[0] = 'A'; |
| 125 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 126 | case CHIP_REV_B: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 127 | plat->rev[0] = 'B'; |
| 128 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 129 | case CHIP_REV_C: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 130 | plat->rev[0] = 'C'; |
| 131 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 132 | default: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 133 | plat->rev[0] = '?'; |
| 134 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 135 | } |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 136 | plat->rev[1] = '\0'; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 137 | } else { |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 138 | plat->rev[0] = '1' + (((rev & 0xf0) - CHIP_REV_1_0) >> 4); |
| 139 | plat->rev[1] = '.'; |
| 140 | plat->rev[2] = '0' + (rev & 0xf); |
| 141 | plat->rev[3] = '\0'; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 145 | static void set_core_data(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 146 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 147 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 148 | |
| 149 | if (device_is_compatible(dev, "arm,cortex-a35")) { |
| 150 | plat->cpu_rsrc = SC_R_A35; |
| 151 | plat->name = "A35"; |
| 152 | } else if (device_is_compatible(dev, "arm,cortex-a53")) { |
| 153 | plat->cpu_rsrc = SC_R_A53; |
| 154 | plat->name = "A53"; |
| 155 | } else if (device_is_compatible(dev, "arm,cortex-a72")) { |
| 156 | plat->cpu_rsrc = SC_R_A72; |
| 157 | plat->name = "A72"; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 158 | } else if (device_is_compatible(dev, "arm,cortex-a55")) { |
| 159 | plat->name = "A55"; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 160 | } else { |
| 161 | plat->cpu_rsrc = SC_R_A53; |
| 162 | plat->name = "?"; |
| 163 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 166 | #if IS_ENABLED(CONFIG_DM_THERMAL) |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 167 | static int cpu_imx_get_temp(struct cpu_imx_plat *plat) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 168 | { |
| 169 | struct udevice *thermal_dev; |
| 170 | int cpu_tmp, ret; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 171 | int idx = 1; /* use "cpu-thermal0" device */ |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 172 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 173 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 174 | if (plat->cpu_rsrc == SC_R_A72) |
| 175 | idx = 2; /* use "cpu-thermal1" device */ |
Peng Fan | 0ce300f | 2024-12-03 23:42:48 +0800 | [diff] [blame] | 176 | } else if (IS_ENABLED(CONFIG_IMX91)) { |
| 177 | idx = 0; |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 178 | } else { |
| 179 | idx = 1; |
| 180 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 181 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 182 | ret = uclass_get_device(UCLASS_THERMAL, idx, &thermal_dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 183 | if (!ret) { |
| 184 | ret = thermal_get_temp(thermal_dev, &cpu_tmp); |
| 185 | if (ret) |
| 186 | return 0xdeadbeef; |
| 187 | } else { |
| 188 | return 0xdeadbeef; |
| 189 | } |
| 190 | |
| 191 | return cpu_tmp; |
| 192 | } |
| 193 | #else |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 194 | static int cpu_imx_get_temp(struct cpu_imx_plat *plat) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 195 | { |
| 196 | return 0; |
| 197 | } |
| 198 | #endif |
| 199 | |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 200 | __weak u32 get_cpu_temp_grade(int *minc, int *maxc) |
| 201 | { |
| 202 | return 0; |
| 203 | } |
| 204 | |
Peng Fan | d3ee4de | 2023-04-28 12:08:11 +0800 | [diff] [blame] | 205 | 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] | 206 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 207 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 208 | const char *grade; |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 209 | int ret, temp; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 210 | int minc, maxc; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 211 | |
| 212 | if (size < 100) |
| 213 | return -ENOSPC; |
| 214 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 215 | 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] | 216 | plat->type, plat->rev, plat->name, plat->freq_mhz); |
| 217 | |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 218 | if (IS_ENABLED(CONFIG_IMX_TMU)) { |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 219 | switch (get_cpu_temp_grade(&minc, &maxc)) { |
| 220 | case TEMP_AUTOMOTIVE: |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 221 | grade = "Automotive temperature grade"; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 222 | break; |
| 223 | case TEMP_INDUSTRIAL: |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 224 | grade = "Industrial temperature grade"; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 225 | break; |
| 226 | case TEMP_EXTCOMMERCIAL: |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 227 | grade = "Extended Consumer temperature grade"; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 228 | break; |
| 229 | default: |
Adam Ford | 0b69ff2 | 2025-03-24 21:54:45 -0500 | [diff] [blame] | 230 | grade = "Consumer temperature grade"; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | |
| 234 | buf = buf + ret; |
| 235 | size = size - ret; |
| 236 | ret = snprintf(buf, size, "\nCPU: %s (%dC to %dC)", grade, minc, maxc); |
| 237 | } |
| 238 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 239 | if (IS_ENABLED(CONFIG_DM_THERMAL)) { |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 240 | temp = cpu_imx_get_temp(plat); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 241 | buf = buf + ret; |
| 242 | size = size - ret; |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 243 | if (temp != 0xdeadbeef) |
| 244 | ret = snprintf(buf, size, " at %dC", temp); |
| 245 | else |
| 246 | ret = snprintf(buf, size, " - invalid sensor data"); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 252 | 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] | 253 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 254 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 255 | |
Hou Zhiqiang | a1124da | 2024-08-01 11:59:50 +0800 | [diff] [blame] | 256 | info->cpu_freq = plat->freq_mhz * 1000000; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 257 | info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU); |
| 258 | return 0; |
| 259 | } |
| 260 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 261 | static int cpu_imx_get_count(const struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 262 | { |
Peng Fan | 8296b74 | 2020-05-03 21:58:51 +0800 | [diff] [blame] | 263 | ofnode node; |
| 264 | int num = 0; |
| 265 | |
| 266 | ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) { |
| 267 | const char *device_type; |
| 268 | |
Simon Glass | 2e4938b | 2022-09-06 20:27:17 -0600 | [diff] [blame] | 269 | if (!ofnode_is_enabled(node)) |
Peng Fan | 8296b74 | 2020-05-03 21:58:51 +0800 | [diff] [blame] | 270 | continue; |
| 271 | |
| 272 | device_type = ofnode_read_string(node, "device_type"); |
| 273 | if (!device_type) |
| 274 | continue; |
| 275 | |
| 276 | if (!strcmp(device_type, "cpu")) |
| 277 | num++; |
| 278 | } |
| 279 | |
| 280 | return num; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 283 | 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] | 284 | { |
| 285 | snprintf(buf, size, "NXP"); |
| 286 | return 0; |
| 287 | } |
| 288 | |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 289 | static int cpu_imx_is_current(struct udevice *dev) |
| 290 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 291 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 292 | |
| 293 | if (plat->mpidr == (read_mpidr() & 0xffff)) |
| 294 | return 1; |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
Hou Zhiqiang | 863a154 | 2024-08-01 11:59:54 +0800 | [diff] [blame] | 299 | static int cpu_imx_release_core(const struct udevice *dev, phys_addr_t addr) |
| 300 | { |
| 301 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
| 302 | struct pt_regs regs; |
| 303 | |
| 304 | regs.regs[0] = PSCI_0_2_FN64_CPU_ON; |
| 305 | regs.regs[1] = plat->mpidr; |
| 306 | regs.regs[2] = addr; |
| 307 | regs.regs[3] = 0; |
| 308 | |
| 309 | smc_call(®s); |
| 310 | if (regs.regs[0]) { |
| 311 | printf("Failed to release CPU core (mpidr: 0x%x)\n", plat->mpidr); |
| 312 | return -1; |
| 313 | } |
| 314 | |
| 315 | printf("Released CPU core (mpidr: 0x%x) to address 0x%llx\n", plat->mpidr, addr); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 320 | static const struct cpu_ops cpu_imx_ops = { |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 321 | .get_desc = cpu_imx_get_desc, |
| 322 | .get_info = cpu_imx_get_info, |
| 323 | .get_count = cpu_imx_get_count, |
| 324 | .get_vendor = cpu_imx_get_vendor, |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 325 | .is_current = cpu_imx_is_current, |
Hou Zhiqiang | 863a154 | 2024-08-01 11:59:54 +0800 | [diff] [blame] | 326 | .release_core = cpu_imx_release_core, |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 329 | static const struct udevice_id cpu_imx_ids[] = { |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 330 | { .compatible = "arm,cortex-a35" }, |
| 331 | { .compatible = "arm,cortex-a53" }, |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 332 | { .compatible = "arm,cortex-a55" }, |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 333 | { .compatible = "arm,cortex-a72" }, |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 334 | { } |
| 335 | }; |
| 336 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 337 | static ulong imx_get_cpu_rate(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 338 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 339 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 340 | struct clk clk; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 341 | ulong rate; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 342 | int ret; |
Peng Fan | 4b1fbb7 | 2020-05-03 21:58:53 +0800 | [diff] [blame] | 343 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 344 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 345 | ret = sc_pm_get_clock_rate(-1, plat->cpu_rsrc, SC_PM_CLK_CPU, |
| 346 | (sc_pm_clock_rate_t *)&rate); |
| 347 | } else { |
| 348 | ret = clk_get_by_index(dev, 0, &clk); |
| 349 | if (!ret) { |
| 350 | rate = clk_get_rate(&clk); |
| 351 | if (!rate) |
| 352 | ret = -EOPNOTSUPP; |
| 353 | } |
| 354 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 355 | if (ret) { |
| 356 | printf("Could not read CPU frequency: %d\n", ret); |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | return rate; |
| 361 | } |
| 362 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 363 | static int imx_cpu_probe(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 364 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 365 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 366 | u32 cpurev; |
| 367 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 368 | set_core_data(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 369 | cpurev = get_cpu_rev(); |
| 370 | plat->cpurev = cpurev; |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame] | 371 | get_imx_rev_str(plat, cpurev & 0xFFF); |
Hou Zhiqiang | c5e1a11 | 2024-08-01 11:59:51 +0800 | [diff] [blame] | 372 | plat->type = get_imx_type_str((cpurev & 0x1FF000) >> 12); |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 373 | plat->freq_mhz = imx_get_cpu_rate(dev) / 1000000; |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 374 | plat->mpidr = dev_read_addr(dev); |
| 375 | if (plat->mpidr == FDT_ADDR_T_NONE) { |
| 376 | printf("%s: Failed to get CPU reg property\n", __func__); |
| 377 | return -EINVAL; |
| 378 | } |
| 379 | |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 380 | return 0; |
| 381 | } |
| 382 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 383 | U_BOOT_DRIVER(cpu_imx_drv) = { |
| 384 | .name = "imx_cpu", |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 385 | .id = UCLASS_CPU, |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 386 | .of_match = cpu_imx_ids, |
| 387 | .ops = &cpu_imx_ops, |
| 388 | .probe = imx_cpu_probe, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 389 | .plat_auto = sizeof(struct cpu_imx_plat), |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 390 | .flags = DM_FLAG_PRE_RELOC, |
| 391 | }; |