1 // SPDX-License-Identifier: GPL-2.0+
10 #include <asm/system.h>
11 #include <asm/arch/sci/sci.h>
12 #include <asm/arch/sys_proto.h>
13 #include <asm/arch-imx/cpu.h>
14 #include <asm/armv8/cpu.h>
15 #include <linux/bitops.h>
17 DECLARE_GLOBAL_DATA_PTR;
29 const char *get_imx8_type(u32 imxtype)
33 case MXC_CPU_IMX8QXP_A0:
42 const char *get_imx8_rev(u32 rev)
56 static void set_core_data(struct udevice *dev)
58 struct cpu_imx_plat *plat = dev_get_plat(dev);
60 if (device_is_compatible(dev, "arm,cortex-a35")) {
61 plat->cpu_rsrc = SC_R_A35;
63 } else if (device_is_compatible(dev, "arm,cortex-a53")) {
64 plat->cpu_rsrc = SC_R_A53;
66 } else if (device_is_compatible(dev, "arm,cortex-a72")) {
67 plat->cpu_rsrc = SC_R_A72;
70 plat->cpu_rsrc = SC_R_A53;
75 #if IS_ENABLED(CONFIG_IMX_SCU_THERMAL)
76 static int cpu_imx_get_temp(struct cpu_imx_plat *plat)
78 struct udevice *thermal_dev;
80 int idx = 1; /* use "cpu-thermal0" device */
82 if (plat->cpu_rsrc == SC_R_A72)
83 idx = 2; /* use "cpu-thermal1" device */
85 ret = uclass_get_device(UCLASS_THERMAL, idx, &thermal_dev);
87 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
97 static int cpu_imx_get_temp(struct cpu_imx_plat *plat)
103 int cpu_imx_get_desc(const struct udevice *dev, char *buf, int size)
105 struct cpu_imx_plat *plat = dev_get_plat(dev);
111 ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
112 plat->type, plat->rev, plat->name, plat->freq_mhz);
114 if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
115 temp = cpu_imx_get_temp(plat);
118 if (temp != 0xdeadbeef)
119 ret = snprintf(buf, size, " at %dC", temp);
121 ret = snprintf(buf, size, " - invalid sensor data");
124 snprintf(buf + ret, size - ret, "\n");
129 static int cpu_imx_get_info(const struct udevice *dev, struct cpu_info *info)
131 struct cpu_imx_plat *plat = dev_get_plat(dev);
133 info->cpu_freq = plat->freq_mhz * 1000;
134 info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU);
138 static int cpu_imx_get_count(const struct udevice *dev)
143 ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
144 const char *device_type;
146 if (!ofnode_is_available(node))
149 device_type = ofnode_read_string(node, "device_type");
153 if (!strcmp(device_type, "cpu"))
160 static int cpu_imx_get_vendor(const struct udevice *dev, char *buf, int size)
162 snprintf(buf, size, "NXP");
166 static int cpu_imx_is_current(struct udevice *dev)
168 struct cpu_imx_plat *plat = dev_get_plat(dev);
170 if (plat->mpidr == (read_mpidr() & 0xffff))
176 static const struct cpu_ops cpu_imx8_ops = {
177 .get_desc = cpu_imx_get_desc,
178 .get_info = cpu_imx_get_info,
179 .get_count = cpu_imx_get_count,
180 .get_vendor = cpu_imx_get_vendor,
181 .is_current = cpu_imx_is_current,
184 static const struct udevice_id cpu_imx8_ids[] = {
185 { .compatible = "arm,cortex-a35" },
186 { .compatible = "arm,cortex-a53" },
187 { .compatible = "arm,cortex-a72" },
191 static ulong imx8_get_cpu_rate(struct udevice *dev)
193 struct cpu_imx_plat *plat = dev_get_plat(dev);
197 ret = sc_pm_get_clock_rate(-1, plat->cpu_rsrc, SC_PM_CLK_CPU,
198 (sc_pm_clock_rate_t *)&rate);
200 printf("Could not read CPU frequency: %d\n", ret);
207 static int imx8_cpu_probe(struct udevice *dev)
209 struct cpu_imx_plat *plat = dev_get_plat(dev);
213 cpurev = get_cpu_rev();
214 plat->cpurev = cpurev;
215 plat->rev = get_imx8_rev(cpurev & 0xFFF);
216 plat->type = get_imx8_type((cpurev & 0xFF000) >> 12);
217 plat->freq_mhz = imx8_get_cpu_rate(dev) / 1000000;
218 plat->mpidr = dev_read_addr(dev);
219 if (plat->mpidr == FDT_ADDR_T_NONE) {
220 printf("%s: Failed to get CPU reg property\n", __func__);
227 U_BOOT_DRIVER(cpu_imx8_drv) = {
230 .of_match = cpu_imx8_ids,
231 .ops = &cpu_imx8_ops,
232 .probe = imx8_cpu_probe,
233 .plat_auto = sizeof(struct cpu_imx_plat),
234 .flags = DM_FLAG_PRE_RELOC,