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>
|
|
|
|
#include <asm/arch/sci/sci.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <asm/arch-imx/cpu.h>
|
|
|
|
#include <asm/armv8/cpu.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
struct cpu_imx_platdata {
|
|
|
|
const char *name;
|
|
|
|
const char *rev;
|
|
|
|
const char *type;
|
|
|
|
u32 cpurev;
|
|
|
|
u32 freq_mhz;
|
2020-05-03 13:58:52 +00:00
|
|
|
u32 mpidr;
|
2019-08-26 08:12:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *get_imx8_type(u32 imxtype)
|
|
|
|
{
|
|
|
|
switch (imxtype) {
|
|
|
|
case MXC_CPU_IMX8QXP:
|
|
|
|
case MXC_CPU_IMX8QXP_A0:
|
|
|
|
return "QXP";
|
|
|
|
case MXC_CPU_IMX8QM:
|
|
|
|
return "QM";
|
|
|
|
default:
|
|
|
|
return "??";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *get_imx8_rev(u32 rev)
|
|
|
|
{
|
|
|
|
switch (rev) {
|
|
|
|
case CHIP_REV_A:
|
|
|
|
return "A";
|
|
|
|
case CHIP_REV_B:
|
|
|
|
return "B";
|
|
|
|
default:
|
|
|
|
return "?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:58:53 +00:00
|
|
|
const char *get_core_name(struct udevice *dev)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
2020-05-03 13:58:53 +00:00
|
|
|
if (!device_is_compatible(dev, "arm,cortex-a35"))
|
2019-08-26 08:12:19 +00:00
|
|
|
return "A35";
|
2020-05-03 13:58:53 +00:00
|
|
|
else if (!device_is_compatible(dev, "arm,cortex-a53"))
|
2019-08-26 08:12:19 +00:00
|
|
|
return "A53";
|
2020-05-03 13:58:53 +00:00
|
|
|
else if (!device_is_compatible(dev, "arm,cortex-a72"))
|
2019-08-26 08:12:19 +00:00
|
|
|
return "A72";
|
|
|
|
else
|
|
|
|
return "?";
|
|
|
|
}
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_IMX_SCU_THERMAL)
|
2020-05-03 13:58:54 +00:00
|
|
|
static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
|
|
|
struct udevice *thermal_dev;
|
|
|
|
int cpu_tmp, ret;
|
|
|
|
|
2020-05-03 13:58:54 +00:00
|
|
|
if (!strcmp(plat->name, "A72"))
|
|
|
|
ret = uclass_get_device(UCLASS_THERMAL, 1, &thermal_dev);
|
|
|
|
else
|
|
|
|
ret = uclass_get_device(UCLASS_THERMAL, 0, &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-05-03 13:58:54 +00:00
|
|
|
static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)
|
|
|
|
{
|
|
|
|
struct cpu_imx_platdata *plat = dev_get_platdata(dev);
|
2020-05-03 13:58:54 +00:00
|
|
|
int ret, temp;
|
2019-08-26 08:12:19 +00:00
|
|
|
|
|
|
|
if (size < 100)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
|
|
|
|
plat->type, plat->rev, plat->name, plat->freq_mhz);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_IMX_SCU_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_imx_get_info(struct udevice *dev, struct cpu_info *info)
|
|
|
|
{
|
|
|
|
struct cpu_imx_platdata *plat = dev_get_platdata(dev);
|
|
|
|
|
|
|
|
info->cpu_freq = plat->freq_mhz * 1000;
|
|
|
|
info->features = BIT(CPU_FEAT_L1_CACHE) | BIT(CPU_FEAT_MMU);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_imx_get_count(struct udevice *dev)
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
if (!ofnode_is_available(node))
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_imx_get_vendor(struct udevice *dev, char *buf, int size)
|
|
|
|
{
|
|
|
|
snprintf(buf, size, "NXP");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:58:52 +00:00
|
|
|
static int cpu_imx_is_current(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct cpu_imx_platdata *plat = dev_get_platdata(dev);
|
|
|
|
|
|
|
|
if (plat->mpidr == (read_mpidr() & 0xffff))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-26 08:12:19 +00:00
|
|
|
static const struct cpu_ops cpu_imx8_ops = {
|
|
|
|
.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
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id cpu_imx8_ids[] = {
|
|
|
|
{ .compatible = "arm,cortex-a35" },
|
|
|
|
{ .compatible = "arm,cortex-a53" },
|
2020-05-03 13:58:52 +00:00
|
|
|
{ .compatible = "arm,cortex-a72" },
|
2019-08-26 08:12:19 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-05-03 13:58:53 +00:00
|
|
|
static ulong imx8_get_cpu_rate(struct udevice *dev)
|
2019-08-26 08:12:19 +00:00
|
|
|
{
|
|
|
|
ulong rate;
|
2020-05-03 13:58:53 +00:00
|
|
|
int ret, type;
|
|
|
|
|
|
|
|
if (!device_is_compatible(dev, "arm,cortex-a35"))
|
|
|
|
type = SC_R_A35;
|
|
|
|
else if (!device_is_compatible(dev, "arm,cortex-a53"))
|
|
|
|
type = SC_R_A53;
|
|
|
|
else if (!device_is_compatible(dev, "arm,cortex-a72"))
|
|
|
|
type = SC_R_A72;
|
|
|
|
else
|
|
|
|
return 0;
|
2019-08-26 08:12:19 +00:00
|
|
|
|
|
|
|
ret = sc_pm_get_clock_rate(-1, type, SC_PM_CLK_CPU,
|
|
|
|
(sc_pm_clock_rate_t *)&rate);
|
|
|
|
if (ret) {
|
|
|
|
printf("Could not read CPU frequency: %d\n", ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx8_cpu_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct cpu_imx_platdata *plat = dev_get_platdata(dev);
|
|
|
|
u32 cpurev;
|
|
|
|
|
|
|
|
cpurev = get_cpu_rev();
|
|
|
|
plat->cpurev = cpurev;
|
2020-05-03 13:58:53 +00:00
|
|
|
plat->name = get_core_name(dev);
|
2019-08-26 08:12:19 +00:00
|
|
|
plat->rev = get_imx8_rev(cpurev & 0xFFF);
|
|
|
|
plat->type = get_imx8_type((cpurev & 0xFF000) >> 12);
|
2020-05-03 13:58:53 +00:00
|
|
|
plat->freq_mhz = imx8_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(cpu_imx8_drv) = {
|
|
|
|
.name = "imx8x_cpu",
|
|
|
|
.id = UCLASS_CPU,
|
|
|
|
.of_match = cpu_imx8_ids,
|
|
|
|
.ops = &cpu_imx8_ops,
|
|
|
|
.probe = imx8_cpu_probe,
|
|
|
|
.platdata_auto_alloc_size = sizeof(struct cpu_imx_platdata),
|
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|