2019-08-26 08:12:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2019 NXP
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <cpu.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <thermal.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/system.h>
|
2023-04-28 04:08:09 +00:00
|
|
|
#include <firmware/imx/sci/sci.h>
|
2019-08-26 08:12:19 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <asm/arch-imx/cpu.h>
|
|
|
|
#include <asm/armv8/cpu.h>
|
2023-04-28 04:08:14 +00:00
|
|
|
#include <imx_thermal.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2023-04-28 04:08:12 +00:00
|
|
|
#include <linux/clk-provider.h>
|
2019-08-26 08:12:19 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
struct cpu_imx_plat {
|
2019-08-26 08:12:19 +00:00
|
|
|
const char *name;
|
|
|
|
const char *rev;
|
|
|
|
const char *type;
|
2020-05-19 23:31:44 +00:00
|
|
|
u32 cpu_rsrc;
|
2019-08-26 08:12:19 +00:00
|
|
|
u32 cpurev;
|
|
|
|
u32 freq_mhz;
|
2020-05-03 13:58:52 +00:00
|
|
|
u32 mpidr;
|
2019-08-26 08:12:19 +00:00
|
|
|
};
|
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
static const char *get_imx_type_str(u32 imxtype)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
|
|
|
switch (imxtype) {
|
|
|
|
case MXC_CPU_IMX8QXP:
|
|
|
|
case MXC_CPU_IMX8QXP_A0:
|
2023-04-28 04:08:12 +00:00
|
|
|
return "8QXP";
|
2019-08-26 08:12:19 +00:00
|
|
|
case MXC_CPU_IMX8QM:
|
2023-04-28 04:08:12 +00:00
|
|
|
return "8QM";
|
|
|
|
case MXC_CPU_IMX93:
|
|
|
|
return "93(52)";/* iMX93 Dual core with NPU */
|
2023-04-28 04:08:32 +00:00
|
|
|
case MXC_CPU_IMX9351:
|
|
|
|
return "93(51)";/* iMX93 Single core with NPU */
|
|
|
|
case MXC_CPU_IMX9332:
|
|
|
|
return "93(32)";/* iMX93 Dual core without NPU */
|
|
|
|
case MXC_CPU_IMX9331:
|
|
|
|
return "93(31)";/* iMX93 Single core without NPU */
|
|
|
|
case MXC_CPU_IMX9322:
|
|
|
|
return "93(22)";/* iMX93 9x9 Dual core */
|
|
|
|
case MXC_CPU_IMX9321:
|
|
|
|
return "93(21)";/* iMX93 9x9 Single core */
|
|
|
|
case MXC_CPU_IMX9312:
|
|
|
|
return "93(12)";/* iMX93 9x9 Dual core without NPU */
|
|
|
|
case MXC_CPU_IMX9311:
|
|
|
|
return "93(11)";/* iMX93 9x9 Single core without NPU */
|
2019-08-26 08:12:19 +00:00
|
|
|
default:
|
|
|
|
return "??";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
static const char *get_imx_rev_str(u32 rev)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
2023-04-28 04:08:12 +00:00
|
|
|
static char revision[4];
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_IMX8)) {
|
|
|
|
switch (rev) {
|
|
|
|
case CHIP_REV_A:
|
|
|
|
return "A";
|
|
|
|
case CHIP_REV_B:
|
|
|
|
return "B";
|
|
|
|
case CHIP_REV_C:
|
|
|
|
return "C";
|
|
|
|
default:
|
|
|
|
return "?";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
revision[0] = '1' + (((rev & 0xf0) - CHIP_REV_1_0) >> 4);
|
|
|
|
revision[1] = '.';
|
|
|
|
revision[2] = '0' + (rev & 0xf);
|
|
|
|
revision[3] = '\0';
|
|
|
|
|
|
|
|
return revision;
|
2019-08-26 08:12:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 23:31:44 +00:00
|
|
|
static void set_core_data(struct udevice *dev)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct cpu_imx_plat *plat = dev_get_plat(dev);
|
2020-05-19 23:31:44 +00:00
|
|
|
|
|
|
|
if (device_is_compatible(dev, "arm,cortex-a35")) {
|
|
|
|
plat->cpu_rsrc = SC_R_A35;
|
|
|
|
plat->name = "A35";
|
|
|
|
} else if (device_is_compatible(dev, "arm,cortex-a53")) {
|
|
|
|
plat->cpu_rsrc = SC_R_A53;
|
|
|
|
plat->name = "A53";
|
|
|
|
} else if (device_is_compatible(dev, "arm,cortex-a72")) {
|
|
|
|
plat->cpu_rsrc = SC_R_A72;
|
|
|
|
plat->name = "A72";
|
2023-04-28 04:08:12 +00:00
|
|
|
} else if (device_is_compatible(dev, "arm,cortex-a55")) {
|
|
|
|
plat->name = "A55";
|
2020-05-19 23:31:44 +00:00
|
|
|
} else {
|
|
|
|
plat->cpu_rsrc = SC_R_A53;
|
|
|
|
plat->name = "?";
|
|
|
|
}
|
2019-08-26 08:12:19 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 04:08:13 +00:00
|
|
|
#if IS_ENABLED(CONFIG_DM_THERMAL)
|
2020-12-03 23:55:23 +00:00
|
|
|
static int cpu_imx_get_temp(struct cpu_imx_plat *plat)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
|
|
|
struct udevice *thermal_dev;
|
|
|
|
int cpu_tmp, ret;
|
2020-05-19 23:31:44 +00:00
|
|
|
int idx = 1; /* use "cpu-thermal0" device */
|
2019-08-26 08:12:19 +00:00
|
|
|
|
2023-04-28 04:08:13 +00:00
|
|
|
if (IS_ENABLED(CONFIG_IMX8)) {
|
|
|
|
if (plat->cpu_rsrc == SC_R_A72)
|
|
|
|
idx = 2; /* use "cpu-thermal1" device */
|
|
|
|
} else {
|
|
|
|
idx = 1;
|
|
|
|
}
|
2019-08-26 08:12:19 +00:00
|
|
|
|
2020-05-19 23:31:44 +00:00
|
|
|
ret = uclass_get_device(UCLASS_THERMAL, idx, &thermal_dev);
|
2019-08-26 08:12:19 +00:00
|
|
|
if (!ret) {
|
|
|
|
ret = thermal_get_temp(thermal_dev, &cpu_tmp);
|
|
|
|
if (ret)
|
|
|
|
return 0xdeadbeef;
|
|
|
|
} else {
|
|
|
|
return 0xdeadbeef;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpu_tmp;
|
|
|
|
}
|
|
|
|
#else
|
2020-12-03 23:55:23 +00:00
|
|
|
static int cpu_imx_get_temp(struct cpu_imx_plat *plat)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-04-28 04:08:14 +00:00
|
|
|
__weak u32 get_cpu_temp_grade(int *minc, int *maxc)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-28 04:08:11 +00:00
|
|
|
static int cpu_imx_get_desc(const struct udevice *dev, char *buf, int size)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct cpu_imx_plat *plat = dev_get_plat(dev);
|
2023-04-28 04:08:14 +00:00
|
|
|
const char *grade;
|
2020-05-03 13:58:54 +00:00
|
|
|
int ret, temp;
|
2023-04-28 04:08:14 +00:00
|
|
|
int minc, maxc;
|
2019-08-26 08:12:19 +00:00
|
|
|
|
|
|
|
if (size < 100)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
ret = snprintf(buf, size, "NXP i.MX%s Rev%s %s at %u MHz",
|
2019-08-26 08:12:19 +00:00
|
|
|
plat->type, plat->rev, plat->name, plat->freq_mhz);
|
|
|
|
|
2023-04-28 04:08:14 +00:00
|
|
|
if (IS_ENABLED(CONFIG_IMX9)) {
|
|
|
|
switch (get_cpu_temp_grade(&minc, &maxc)) {
|
|
|
|
case TEMP_AUTOMOTIVE:
|
|
|
|
grade = "Automotive temperature grade ";
|
|
|
|
break;
|
|
|
|
case TEMP_INDUSTRIAL:
|
|
|
|
grade = "Industrial temperature grade ";
|
|
|
|
break;
|
|
|
|
case TEMP_EXTCOMMERCIAL:
|
|
|
|
grade = "Extended Consumer temperature grade ";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
grade = "Consumer temperature grade ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = buf + ret;
|
|
|
|
size = size - ret;
|
|
|
|
ret = snprintf(buf, size, "\nCPU: %s (%dC to %dC)", grade, minc, maxc);
|
|
|
|
}
|
|
|
|
|
2023-04-28 04:08:13 +00:00
|
|
|
if (IS_ENABLED(CONFIG_DM_THERMAL)) {
|
2020-05-03 13:58:54 +00:00
|
|
|
temp = cpu_imx_get_temp(plat);
|
2019-08-26 08:12:19 +00:00
|
|
|
buf = buf + ret;
|
|
|
|
size = size - ret;
|
2020-05-03 13:58:54 +00:00
|
|
|
if (temp != 0xdeadbeef)
|
|
|
|
ret = snprintf(buf, size, " at %dC", temp);
|
|
|
|
else
|
|
|
|
ret = snprintf(buf, size, " - invalid sensor data");
|
2019-08-26 08:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf + ret, size - ret, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
static int cpu_imx_get_info(const struct udevice *dev, struct cpu_info *info)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct cpu_imx_plat *plat = dev_get_plat(dev);
|
2019-08-26 08:12:19 +00:00
|
|
|
|
|
|
|
info->cpu_freq = plat->freq_mhz * 1000;
|
|
|
|
info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
static int cpu_imx_get_count(const struct udevice *dev)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
2020-05-03 13:58:51 +00:00
|
|
|
ofnode node;
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
|
|
|
|
const char *device_type;
|
|
|
|
|
2022-09-07 02:27:17 +00:00
|
|
|
if (!ofnode_is_enabled(node))
|
2020-05-03 13:58:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
device_type = ofnode_read_string(node, "device_type");
|
|
|
|
if (!device_type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!strcmp(device_type, "cpu"))
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
2019-08-26 08:12:19 +00:00
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
static int cpu_imx_get_vendor(const struct udevice *dev, char *buf, int size)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
|
|
|
snprintf(buf, size, "NXP");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:58:52 +00:00
|
|
|
static int cpu_imx_is_current(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct cpu_imx_plat *plat = dev_get_plat(dev);
|
2020-05-03 13:58:52 +00:00
|
|
|
|
|
|
|
if (plat->mpidr == (read_mpidr() & 0xffff))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
static const struct cpu_ops cpu_imx_ops = {
|
2019-08-26 08:12:19 +00:00
|
|
|
.get_desc = cpu_imx_get_desc,
|
|
|
|
.get_info = cpu_imx_get_info,
|
|
|
|
.get_count = cpu_imx_get_count,
|
|
|
|
.get_vendor = cpu_imx_get_vendor,
|
2020-05-03 13:58:52 +00:00
|
|
|
.is_current = cpu_imx_is_current,
|
2019-08-26 08:12:19 +00:00
|
|
|
};
|
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
static const struct udevice_id cpu_imx_ids[] = {
|
2019-08-26 08:12:19 +00:00
|
|
|
{ .compatible = "arm,cortex-a35" },
|
|
|
|
{ .compatible = "arm,cortex-a53" },
|
2023-04-28 04:08:12 +00:00
|
|
|
{ .compatible = "arm,cortex-a55" },
|
2020-05-03 13:58:52 +00:00
|
|
|
{ .compatible = "arm,cortex-a72" },
|
2019-08-26 08:12:19 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
static ulong imx_get_cpu_rate(struct udevice *dev)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct cpu_imx_plat *plat = dev_get_plat(dev);
|
2023-04-28 04:08:12 +00:00
|
|
|
struct clk clk;
|
2019-08-26 08:12:19 +00:00
|
|
|
ulong rate;
|
2020-05-19 23:31:44 +00:00
|
|
|
int ret;
|
2019-08-26 08:12:19 +00:00
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
if (IS_ENABLED(CONFIG_IMX8)) {
|
|
|
|
ret = sc_pm_get_clock_rate(-1, plat->cpu_rsrc, SC_PM_CLK_CPU,
|
|
|
|
(sc_pm_clock_rate_t *)&rate);
|
|
|
|
} else {
|
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
|
|
|
if (!ret) {
|
|
|
|
rate = clk_get_rate(&clk);
|
|
|
|
if (!rate)
|
|
|
|
ret = -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 08:12:19 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("Could not read CPU frequency: %d\n", ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
static int imx_cpu_probe(struct udevice *dev)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct cpu_imx_plat *plat = dev_get_plat(dev);
|
2019-08-26 08:12:19 +00:00
|
|
|
u32 cpurev;
|
|
|
|
|
2020-05-19 23:31:44 +00:00
|
|
|
set_core_data(dev);
|
2019-08-26 08:12:19 +00:00
|
|
|
cpurev = get_cpu_rev();
|
|
|
|
plat->cpurev = cpurev;
|
2023-04-28 04:08:12 +00:00
|
|
|
plat->rev = get_imx_rev_str(cpurev & 0xFFF);
|
|
|
|
plat->type = get_imx_type_str((cpurev & 0xFF000) >> 12);
|
|
|
|
plat->freq_mhz = imx_get_cpu_rate(dev) / 1000000;
|
2020-05-03 13:58:52 +00:00
|
|
|
plat->mpidr = dev_read_addr(dev);
|
|
|
|
if (plat->mpidr == FDT_ADDR_T_NONE) {
|
|
|
|
printf("%s: Failed to get CPU reg property\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-08-26 08:12:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-28 04:08:12 +00:00
|
|
|
U_BOOT_DRIVER(cpu_imx_drv) = {
|
|
|
|
.name = "imx_cpu",
|
2019-08-26 08:12:19 +00:00
|
|
|
.id = UCLASS_CPU,
|
2023-04-28 04:08:12 +00:00
|
|
|
.of_match = cpu_imx_ids,
|
|
|
|
.ops = &cpu_imx_ops,
|
|
|
|
.probe = imx_cpu_probe,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct cpu_imx_plat),
|
2019-08-26 08:12:19 +00:00
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|