1 // SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/sci/sci.h>
11 #include <asm/arch/sys_proto.h>
12 #include <asm/arch-imx/cpu.h>
13 #include <asm/armv8/cpu.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 struct cpu_imx_platdata {
25 const char *get_imx8_type(u32 imxtype)
29 case MXC_CPU_IMX8QXP_A0:
38 const char *get_imx8_rev(u32 rev)
50 const char *get_core_name(void)
54 else if (is_cortex_a53())
56 else if (is_cortex_a72())
62 #if IS_ENABLED(CONFIG_IMX_SCU_THERMAL)
63 static int cpu_imx_get_temp(void)
65 struct udevice *thermal_dev;
68 ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal0",
72 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
82 static int cpu_imx_get_temp(void)
88 int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)
90 struct cpu_imx_platdata *plat = dev_get_platdata(dev);
96 ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
97 plat->type, plat->rev, plat->name, plat->freq_mhz);
99 if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
102 ret = snprintf(buf, size, " at %dC", cpu_imx_get_temp());
105 snprintf(buf + ret, size - ret, "\n");
110 static int cpu_imx_get_info(struct udevice *dev, struct cpu_info *info)
112 struct cpu_imx_platdata *plat = dev_get_platdata(dev);
114 info->cpu_freq = plat->freq_mhz * 1000;
115 info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU);
119 static int cpu_imx_get_count(struct udevice *dev)
124 static int cpu_imx_get_vendor(struct udevice *dev, char *buf, int size)
126 snprintf(buf, size, "NXP");
130 static const struct cpu_ops cpu_imx8_ops = {
131 .get_desc = cpu_imx_get_desc,
132 .get_info = cpu_imx_get_info,
133 .get_count = cpu_imx_get_count,
134 .get_vendor = cpu_imx_get_vendor,
137 static const struct udevice_id cpu_imx8_ids[] = {
138 { .compatible = "arm,cortex-a35" },
139 { .compatible = "arm,cortex-a53" },
143 static ulong imx8_get_cpu_rate(void)
147 int type = is_cortex_a35() ? SC_R_A35 : is_cortex_a53() ?
150 ret = sc_pm_get_clock_rate(-1, type, SC_PM_CLK_CPU,
151 (sc_pm_clock_rate_t *)&rate);
153 printf("Could not read CPU frequency: %d\n", ret);
160 static int imx8_cpu_probe(struct udevice *dev)
162 struct cpu_imx_platdata *plat = dev_get_platdata(dev);
165 cpurev = get_cpu_rev();
166 plat->cpurev = cpurev;
167 plat->name = get_core_name();
168 plat->rev = get_imx8_rev(cpurev & 0xFFF);
169 plat->type = get_imx8_type((cpurev & 0xFF000) >> 12);
170 plat->freq_mhz = imx8_get_cpu_rate() / 1000000;
174 U_BOOT_DRIVER(cpu_imx8_drv) = {
177 .of_match = cpu_imx8_ids,
178 .ops = &cpu_imx8_ops,
179 .probe = imx8_cpu_probe,
180 .platdata_auto_alloc_size = sizeof(struct cpu_imx_platdata),
181 .flags = DM_FLAG_PRE_RELOC,