1 // SPDX-License-Identifier: GPL-2.0+
10 #include <asm/global_data.h>
11 #include <asm/system.h>
12 #include <asm/arch/sci/sci.h>
13 #include <asm/arch/sys_proto.h>
14 #include <asm/arch-imx/cpu.h>
15 #include <asm/armv8/cpu.h>
16 #include <linux/bitops.h>
18 DECLARE_GLOBAL_DATA_PTR;
30 const char *get_imx8_type(u32 imxtype)
34 case MXC_CPU_IMX8QXP_A0:
43 const char *get_imx8_rev(u32 rev)
57 static void set_core_data(struct udevice *dev)
59 struct cpu_imx_plat *plat = dev_get_plat(dev);
61 if (device_is_compatible(dev, "arm,cortex-a35")) {
62 plat->cpu_rsrc = SC_R_A35;
64 } else if (device_is_compatible(dev, "arm,cortex-a53")) {
65 plat->cpu_rsrc = SC_R_A53;
67 } else if (device_is_compatible(dev, "arm,cortex-a72")) {
68 plat->cpu_rsrc = SC_R_A72;
71 plat->cpu_rsrc = SC_R_A53;
76 #if IS_ENABLED(CONFIG_IMX_SCU_THERMAL)
77 static int cpu_imx_get_temp(struct cpu_imx_plat *plat)
79 struct udevice *thermal_dev;
81 int idx = 1; /* use "cpu-thermal0" device */
83 if (plat->cpu_rsrc == SC_R_A72)
84 idx = 2; /* use "cpu-thermal1" device */
86 ret = uclass_get_device(UCLASS_THERMAL, idx, &thermal_dev);
88 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
98 static int cpu_imx_get_temp(struct cpu_imx_plat *plat)
104 int cpu_imx_get_desc(const struct udevice *dev, char *buf, int size)
106 struct cpu_imx_plat *plat = dev_get_plat(dev);
112 ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
113 plat->type, plat->rev, plat->name, plat->freq_mhz);
115 if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
116 temp = cpu_imx_get_temp(plat);
119 if (temp != 0xdeadbeef)
120 ret = snprintf(buf, size, " at %dC", temp);
122 ret = snprintf(buf, size, " - invalid sensor data");
125 snprintf(buf + ret, size - ret, "\n");
130 static int cpu_imx_get_info(const struct udevice *dev, struct cpu_info *info)
132 struct cpu_imx_plat *plat = dev_get_plat(dev);
134 info->cpu_freq = plat->freq_mhz * 1000;
135 info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU);
139 static int cpu_imx_get_count(const struct udevice *dev)
144 ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
145 const char *device_type;
147 if (!ofnode_is_available(node))
150 device_type = ofnode_read_string(node, "device_type");
154 if (!strcmp(device_type, "cpu"))
161 static int cpu_imx_get_vendor(const struct udevice *dev, char *buf, int size)
163 snprintf(buf, size, "NXP");
167 static int cpu_imx_is_current(struct udevice *dev)
169 struct cpu_imx_plat *plat = dev_get_plat(dev);
171 if (plat->mpidr == (read_mpidr() & 0xffff))
177 static const struct cpu_ops cpu_imx8_ops = {
178 .get_desc = cpu_imx_get_desc,
179 .get_info = cpu_imx_get_info,
180 .get_count = cpu_imx_get_count,
181 .get_vendor = cpu_imx_get_vendor,
182 .is_current = cpu_imx_is_current,
185 static const struct udevice_id cpu_imx8_ids[] = {
186 { .compatible = "arm,cortex-a35" },
187 { .compatible = "arm,cortex-a53" },
188 { .compatible = "arm,cortex-a72" },
192 static ulong imx8_get_cpu_rate(struct udevice *dev)
194 struct cpu_imx_plat *plat = dev_get_plat(dev);
198 ret = sc_pm_get_clock_rate(-1, plat->cpu_rsrc, SC_PM_CLK_CPU,
199 (sc_pm_clock_rate_t *)&rate);
201 printf("Could not read CPU frequency: %d\n", ret);
208 static int imx8_cpu_probe(struct udevice *dev)
210 struct cpu_imx_plat *plat = dev_get_plat(dev);
214 cpurev = get_cpu_rev();
215 plat->cpurev = cpurev;
216 plat->rev = get_imx8_rev(cpurev & 0xFFF);
217 plat->type = get_imx8_type((cpurev & 0xFF000) >> 12);
218 plat->freq_mhz = imx8_get_cpu_rate(dev) / 1000000;
219 plat->mpidr = dev_read_addr(dev);
220 if (plat->mpidr == FDT_ADDR_T_NONE) {
221 printf("%s: Failed to get CPU reg property\n", __func__);
228 U_BOOT_DRIVER(cpu_imx8_drv) = {
231 .of_match = cpu_imx8_ids,
232 .ops = &cpu_imx8_ops,
233 .probe = imx8_cpu_probe,
234 .plat_auto = sizeof(struct cpu_imx_plat),
235 .flags = DM_FLAG_PRE_RELOC,