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>
16 DECLARE_GLOBAL_DATA_PTR;
18 struct cpu_imx_platdata {
27 const char *get_imx8_type(u32 imxtype)
31 case MXC_CPU_IMX8QXP_A0:
40 const char *get_imx8_rev(u32 rev)
54 const char *get_core_name(struct udevice *dev)
56 if (!device_is_compatible(dev, "arm,cortex-a35"))
58 else if (!device_is_compatible(dev, "arm,cortex-a53"))
60 else if (!device_is_compatible(dev, "arm,cortex-a72"))
66 #if IS_ENABLED(CONFIG_IMX_SCU_THERMAL)
67 static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
69 struct udevice *thermal_dev;
72 if (!strcmp(plat->name, "A72"))
73 ret = uclass_get_device(UCLASS_THERMAL, 1, &thermal_dev);
75 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
78 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
88 static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
94 int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)
96 struct cpu_imx_platdata *plat = dev_get_platdata(dev);
102 ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
103 plat->type, plat->rev, plat->name, plat->freq_mhz);
105 if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
106 temp = cpu_imx_get_temp(plat);
109 if (temp != 0xdeadbeef)
110 ret = snprintf(buf, size, " at %dC", temp);
112 ret = snprintf(buf, size, " - invalid sensor data");
115 snprintf(buf + ret, size - ret, "\n");
120 static int cpu_imx_get_info(struct udevice *dev, struct cpu_info *info)
122 struct cpu_imx_platdata *plat = dev_get_platdata(dev);
124 info->cpu_freq = plat->freq_mhz * 1000;
125 info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU);
129 static int cpu_imx_get_count(struct udevice *dev)
134 ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
135 const char *device_type;
137 if (!ofnode_is_available(node))
140 device_type = ofnode_read_string(node, "device_type");
144 if (!strcmp(device_type, "cpu"))
151 static int cpu_imx_get_vendor(struct udevice *dev, char *buf, int size)
153 snprintf(buf, size, "NXP");
157 static int cpu_imx_is_current(struct udevice *dev)
159 struct cpu_imx_platdata *plat = dev_get_platdata(dev);
161 if (plat->mpidr == (read_mpidr() & 0xffff))
167 static const struct cpu_ops cpu_imx8_ops = {
168 .get_desc = cpu_imx_get_desc,
169 .get_info = cpu_imx_get_info,
170 .get_count = cpu_imx_get_count,
171 .get_vendor = cpu_imx_get_vendor,
172 .is_current = cpu_imx_is_current,
175 static const struct udevice_id cpu_imx8_ids[] = {
176 { .compatible = "arm,cortex-a35" },
177 { .compatible = "arm,cortex-a53" },
178 { .compatible = "arm,cortex-a72" },
182 static ulong imx8_get_cpu_rate(struct udevice *dev)
187 if (!device_is_compatible(dev, "arm,cortex-a35"))
189 else if (!device_is_compatible(dev, "arm,cortex-a53"))
191 else if (!device_is_compatible(dev, "arm,cortex-a72"))
196 ret = sc_pm_get_clock_rate(-1, type, SC_PM_CLK_CPU,
197 (sc_pm_clock_rate_t *)&rate);
199 printf("Could not read CPU frequency: %d\n", ret);
206 static int imx8_cpu_probe(struct udevice *dev)
208 struct cpu_imx_platdata *plat = dev_get_platdata(dev);
211 cpurev = get_cpu_rev();
212 plat->cpurev = cpurev;
213 plat->name = get_core_name(dev);
214 plat->rev = get_imx8_rev(cpurev & 0xFFF);
215 plat->type = get_imx8_type((cpurev & 0xFF000) >> 12);
216 plat->freq_mhz = imx8_get_cpu_rate(dev) / 1000000;
217 plat->mpidr = dev_read_addr(dev);
218 if (plat->mpidr == FDT_ADDR_T_NONE) {
219 printf("%s: Failed to get CPU reg property\n", __func__);
226 U_BOOT_DRIVER(cpu_imx8_drv) = {
229 .of_match = cpu_imx8_ids,
230 .ops = &cpu_imx8_ops,
231 .probe = imx8_cpu_probe,
232 .platdata_auto_alloc_size = sizeof(struct cpu_imx_platdata),
233 .flags = DM_FLAG_PRE_RELOC,