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: |
| 38 | return "8MM"; |
| 39 | case MXC_CPU_IMX8MN: |
| 40 | return "8MN"; |
| 41 | case MXC_CPU_IMX8MP: |
| 42 | return "8MP"; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 43 | case MXC_CPU_IMX8QXP: |
| 44 | case MXC_CPU_IMX8QXP_A0: |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 45 | return "8QXP"; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 46 | case MXC_CPU_IMX8QM: |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 47 | return "8QM"; |
| 48 | case MXC_CPU_IMX93: |
| 49 | return "93(52)";/* iMX93 Dual core with NPU */ |
Peng Fan | c3db3ad | 2023-04-28 12:08:32 +0800 | [diff] [blame] | 50 | case MXC_CPU_IMX9351: |
| 51 | return "93(51)";/* iMX93 Single core with NPU */ |
| 52 | case MXC_CPU_IMX9332: |
| 53 | return "93(32)";/* iMX93 Dual core without NPU */ |
| 54 | case MXC_CPU_IMX9331: |
| 55 | return "93(31)";/* iMX93 Single core without NPU */ |
| 56 | case MXC_CPU_IMX9322: |
| 57 | return "93(22)";/* iMX93 9x9 Dual core */ |
| 58 | case MXC_CPU_IMX9321: |
| 59 | return "93(21)";/* iMX93 9x9 Single core */ |
| 60 | case MXC_CPU_IMX9312: |
| 61 | return "93(12)";/* iMX93 9x9 Dual core without NPU */ |
| 62 | case MXC_CPU_IMX9311: |
| 63 | return "93(11)";/* iMX93 9x9 Single core without NPU */ |
Ye Li | 57b2ac4 | 2024-09-19 12:01:33 +0800 | [diff] [blame] | 64 | case MXC_CPU_IMX9302: |
| 65 | return "93(02)";/* iMX93 900Mhz Low performance Dual core without NPU */ |
| 66 | case MXC_CPU_IMX9301: |
| 67 | return "93(01)";/* iMX93 900Mhz Low performance Single core without NPU */ |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 68 | default: |
| 69 | return "??"; |
| 70 | } |
| 71 | } |
| 72 | |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame^] | 73 | 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] | 74 | { |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 75 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 76 | switch (rev) { |
| 77 | case CHIP_REV_A: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame^] | 78 | plat->rev[0] = 'A'; |
| 79 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 80 | case CHIP_REV_B: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame^] | 81 | plat->rev[0] = 'B'; |
| 82 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 83 | case CHIP_REV_C: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame^] | 84 | plat->rev[0] = 'C'; |
| 85 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 86 | default: |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame^] | 87 | plat->rev[0] = '?'; |
| 88 | break; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 89 | } |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame^] | 90 | plat->rev[1] = '\0'; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 91 | } else { |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame^] | 92 | plat->rev[0] = '1' + (((rev & 0xf0) - CHIP_REV_1_0) >> 4); |
| 93 | plat->rev[1] = '.'; |
| 94 | plat->rev[2] = '0' + (rev & 0xf); |
| 95 | plat->rev[3] = '\0'; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 99 | static void set_core_data(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 100 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 101 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 102 | |
| 103 | if (device_is_compatible(dev, "arm,cortex-a35")) { |
| 104 | plat->cpu_rsrc = SC_R_A35; |
| 105 | plat->name = "A35"; |
| 106 | } else if (device_is_compatible(dev, "arm,cortex-a53")) { |
| 107 | plat->cpu_rsrc = SC_R_A53; |
| 108 | plat->name = "A53"; |
| 109 | } else if (device_is_compatible(dev, "arm,cortex-a72")) { |
| 110 | plat->cpu_rsrc = SC_R_A72; |
| 111 | plat->name = "A72"; |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 112 | } else if (device_is_compatible(dev, "arm,cortex-a55")) { |
| 113 | plat->name = "A55"; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 114 | } else { |
| 115 | plat->cpu_rsrc = SC_R_A53; |
| 116 | plat->name = "?"; |
| 117 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 120 | #if IS_ENABLED(CONFIG_DM_THERMAL) |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 121 | static int cpu_imx_get_temp(struct cpu_imx_plat *plat) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 122 | { |
| 123 | struct udevice *thermal_dev; |
| 124 | int cpu_tmp, ret; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 125 | int idx = 1; /* use "cpu-thermal0" device */ |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 126 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 127 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 128 | if (plat->cpu_rsrc == SC_R_A72) |
| 129 | idx = 2; /* use "cpu-thermal1" device */ |
| 130 | } else { |
| 131 | idx = 1; |
| 132 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 133 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 134 | ret = uclass_get_device(UCLASS_THERMAL, idx, &thermal_dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 135 | if (!ret) { |
| 136 | ret = thermal_get_temp(thermal_dev, &cpu_tmp); |
| 137 | if (ret) |
| 138 | return 0xdeadbeef; |
| 139 | } else { |
| 140 | return 0xdeadbeef; |
| 141 | } |
| 142 | |
| 143 | return cpu_tmp; |
| 144 | } |
| 145 | #else |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 146 | static int cpu_imx_get_temp(struct cpu_imx_plat *plat) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 147 | { |
| 148 | return 0; |
| 149 | } |
| 150 | #endif |
| 151 | |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 152 | __weak u32 get_cpu_temp_grade(int *minc, int *maxc) |
| 153 | { |
| 154 | return 0; |
| 155 | } |
| 156 | |
Peng Fan | d3ee4de | 2023-04-28 12:08:11 +0800 | [diff] [blame] | 157 | 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] | 158 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 159 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 160 | const char *grade; |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 161 | int ret, temp; |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 162 | int minc, maxc; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 163 | |
| 164 | if (size < 100) |
| 165 | return -ENOSPC; |
| 166 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 167 | 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] | 168 | plat->type, plat->rev, plat->name, plat->freq_mhz); |
| 169 | |
Peng Fan | 81c694a | 2023-04-28 12:08:14 +0800 | [diff] [blame] | 170 | if (IS_ENABLED(CONFIG_IMX9)) { |
| 171 | switch (get_cpu_temp_grade(&minc, &maxc)) { |
| 172 | case TEMP_AUTOMOTIVE: |
| 173 | grade = "Automotive temperature grade "; |
| 174 | break; |
| 175 | case TEMP_INDUSTRIAL: |
| 176 | grade = "Industrial temperature grade "; |
| 177 | break; |
| 178 | case TEMP_EXTCOMMERCIAL: |
| 179 | grade = "Extended Consumer temperature grade "; |
| 180 | break; |
| 181 | default: |
| 182 | grade = "Consumer temperature grade "; |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | buf = buf + ret; |
| 187 | size = size - ret; |
| 188 | ret = snprintf(buf, size, "\nCPU: %s (%dC to %dC)", grade, minc, maxc); |
| 189 | } |
| 190 | |
Peng Fan | 32eaf67 | 2023-04-28 12:08:13 +0800 | [diff] [blame] | 191 | if (IS_ENABLED(CONFIG_DM_THERMAL)) { |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 192 | temp = cpu_imx_get_temp(plat); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 193 | buf = buf + ret; |
| 194 | size = size - ret; |
Ye Li | cd8d1c5 | 2020-05-03 21:58:54 +0800 | [diff] [blame] | 195 | if (temp != 0xdeadbeef) |
| 196 | ret = snprintf(buf, size, " at %dC", temp); |
| 197 | else |
| 198 | ret = snprintf(buf, size, " - invalid sensor data"); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 204 | 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] | 205 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 206 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 207 | |
Hou Zhiqiang | a1124da | 2024-08-01 11:59:50 +0800 | [diff] [blame] | 208 | info->cpu_freq = plat->freq_mhz * 1000000; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 209 | info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU); |
| 210 | return 0; |
| 211 | } |
| 212 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 213 | static int cpu_imx_get_count(const struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 214 | { |
Peng Fan | 8296b74 | 2020-05-03 21:58:51 +0800 | [diff] [blame] | 215 | ofnode node; |
| 216 | int num = 0; |
| 217 | |
| 218 | ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) { |
| 219 | const char *device_type; |
| 220 | |
Simon Glass | 2e4938b | 2022-09-06 20:27:17 -0600 | [diff] [blame] | 221 | if (!ofnode_is_enabled(node)) |
Peng Fan | 8296b74 | 2020-05-03 21:58:51 +0800 | [diff] [blame] | 222 | continue; |
| 223 | |
| 224 | device_type = ofnode_read_string(node, "device_type"); |
| 225 | if (!device_type) |
| 226 | continue; |
| 227 | |
| 228 | if (!strcmp(device_type, "cpu")) |
| 229 | num++; |
| 230 | } |
| 231 | |
| 232 | return num; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 235 | 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] | 236 | { |
| 237 | snprintf(buf, size, "NXP"); |
| 238 | return 0; |
| 239 | } |
| 240 | |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 241 | static int cpu_imx_is_current(struct udevice *dev) |
| 242 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 243 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 244 | |
| 245 | if (plat->mpidr == (read_mpidr() & 0xffff)) |
| 246 | return 1; |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Hou Zhiqiang | 863a154 | 2024-08-01 11:59:54 +0800 | [diff] [blame] | 251 | static int cpu_imx_release_core(const struct udevice *dev, phys_addr_t addr) |
| 252 | { |
| 253 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
| 254 | struct pt_regs regs; |
| 255 | |
| 256 | regs.regs[0] = PSCI_0_2_FN64_CPU_ON; |
| 257 | regs.regs[1] = plat->mpidr; |
| 258 | regs.regs[2] = addr; |
| 259 | regs.regs[3] = 0; |
| 260 | |
| 261 | smc_call(®s); |
| 262 | if (regs.regs[0]) { |
| 263 | printf("Failed to release CPU core (mpidr: 0x%x)\n", plat->mpidr); |
| 264 | return -1; |
| 265 | } |
| 266 | |
| 267 | printf("Released CPU core (mpidr: 0x%x) to address 0x%llx\n", plat->mpidr, addr); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 272 | static const struct cpu_ops cpu_imx_ops = { |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 273 | .get_desc = cpu_imx_get_desc, |
| 274 | .get_info = cpu_imx_get_info, |
| 275 | .get_count = cpu_imx_get_count, |
| 276 | .get_vendor = cpu_imx_get_vendor, |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 277 | .is_current = cpu_imx_is_current, |
Hou Zhiqiang | 863a154 | 2024-08-01 11:59:54 +0800 | [diff] [blame] | 278 | .release_core = cpu_imx_release_core, |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 279 | }; |
| 280 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 281 | static const struct udevice_id cpu_imx_ids[] = { |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 282 | { .compatible = "arm,cortex-a35" }, |
| 283 | { .compatible = "arm,cortex-a53" }, |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 284 | { .compatible = "arm,cortex-a55" }, |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 285 | { .compatible = "arm,cortex-a72" }, |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 286 | { } |
| 287 | }; |
| 288 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 289 | static ulong imx_get_cpu_rate(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 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 | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 292 | struct clk clk; |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 293 | ulong rate; |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 294 | int ret; |
Peng Fan | 4b1fbb7 | 2020-05-03 21:58:53 +0800 | [diff] [blame] | 295 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 296 | if (IS_ENABLED(CONFIG_IMX8)) { |
| 297 | ret = sc_pm_get_clock_rate(-1, plat->cpu_rsrc, SC_PM_CLK_CPU, |
| 298 | (sc_pm_clock_rate_t *)&rate); |
| 299 | } else { |
| 300 | ret = clk_get_by_index(dev, 0, &clk); |
| 301 | if (!ret) { |
| 302 | rate = clk_get_rate(&clk); |
| 303 | if (!rate) |
| 304 | ret = -EOPNOTSUPP; |
| 305 | } |
| 306 | } |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 307 | if (ret) { |
| 308 | printf("Could not read CPU frequency: %d\n", ret); |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | return rate; |
| 313 | } |
| 314 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 315 | static int imx_cpu_probe(struct udevice *dev) |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 316 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 317 | struct cpu_imx_plat *plat = dev_get_plat(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 318 | u32 cpurev; |
| 319 | |
Anatolij Gustschin | 50ca4a0 | 2020-05-20 01:31:44 +0200 | [diff] [blame] | 320 | set_core_data(dev); |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 321 | cpurev = get_cpu_rev(); |
| 322 | plat->cpurev = cpurev; |
Peng Fan | 7d5e7aa | 2024-10-18 15:34:32 +0800 | [diff] [blame^] | 323 | get_imx_rev_str(plat, cpurev & 0xFFF); |
Hou Zhiqiang | c5e1a11 | 2024-08-01 11:59:51 +0800 | [diff] [blame] | 324 | plat->type = get_imx_type_str((cpurev & 0x1FF000) >> 12); |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 325 | plat->freq_mhz = imx_get_cpu_rate(dev) / 1000000; |
Peng Fan | e2ded33 | 2020-05-03 21:58:52 +0800 | [diff] [blame] | 326 | plat->mpidr = dev_read_addr(dev); |
| 327 | if (plat->mpidr == FDT_ADDR_T_NONE) { |
| 328 | printf("%s: Failed to get CPU reg property\n", __func__); |
| 329 | return -EINVAL; |
| 330 | } |
| 331 | |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 335 | U_BOOT_DRIVER(cpu_imx_drv) = { |
| 336 | .name = "imx_cpu", |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 337 | .id = UCLASS_CPU, |
Peng Fan | 146cce9 | 2023-04-28 12:08:12 +0800 | [diff] [blame] | 338 | .of_match = cpu_imx_ids, |
| 339 | .ops = &cpu_imx_ops, |
| 340 | .probe = imx_cpu_probe, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 341 | .plat_auto = sizeof(struct cpu_imx_plat), |
Peng Fan | 21981d2 | 2019-08-26 08:12:19 +0000 | [diff] [blame] | 342 | .flags = DM_FLAG_PRE_RELOC, |
| 343 | }; |