2020-05-03 14:19:46 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2017~2020 NXP
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <common.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-05-03 14:19:46 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/clock.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/device.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fuse.h>
|
2020-10-12 19:21:54 +00:00
|
|
|
#include <linux/delay.h>
|
2020-05-03 14:19:46 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <thermal.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#define SITES_MAX 16
|
2020-05-03 14:19:47 +00:00
|
|
|
#define FLAGS_VER2 0x1
|
2020-05-03 14:19:51 +00:00
|
|
|
#define FLAGS_VER3 0x2
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
#define TMR_DISABLE 0x0
|
|
|
|
#define TMR_ME 0x80000000
|
|
|
|
#define TMR_ALPF 0x0c000000
|
|
|
|
#define TMTMIR_DEFAULT 0x00000002
|
|
|
|
#define TIER_DISABLE 0x0
|
|
|
|
|
2020-05-03 14:19:47 +00:00
|
|
|
#define TER_EN 0x80000000
|
|
|
|
#define TER_ADC_PD 0x40000000
|
2020-05-03 14:19:51 +00:00
|
|
|
#define TER_ALPF 0x3
|
|
|
|
|
2020-05-03 14:19:46 +00:00
|
|
|
/*
|
|
|
|
* i.MX TMU Registers
|
|
|
|
*/
|
|
|
|
struct imx_tmu_site_regs {
|
|
|
|
u32 tritsr; /* Immediate Temperature Site Register */
|
|
|
|
u32 tratsr; /* Average Temperature Site Register */
|
|
|
|
u8 res0[0x8];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct imx_tmu_regs {
|
|
|
|
u32 tmr; /* Mode Register */
|
|
|
|
u32 tsr; /* Status Register */
|
|
|
|
u32 tmtmir; /* Temperature measurement interval Register */
|
|
|
|
u8 res0[0x14];
|
|
|
|
u32 tier; /* Interrupt Enable Register */
|
|
|
|
u32 tidr; /* Interrupt Detect Register */
|
|
|
|
u32 tiscr; /* Interrupt Site Capture Register */
|
|
|
|
u32 ticscr; /* Interrupt Critical Site Capture Register */
|
|
|
|
u8 res1[0x10];
|
|
|
|
u32 tmhtcrh; /* High Temperature Capture Register */
|
|
|
|
u32 tmhtcrl; /* Low Temperature Capture Register */
|
|
|
|
u8 res2[0x8];
|
|
|
|
u32 tmhtitr; /* High Temperature Immediate Threshold */
|
|
|
|
u32 tmhtatr; /* High Temperature Average Threshold */
|
|
|
|
u32 tmhtactr; /* High Temperature Average Crit Threshold */
|
|
|
|
u8 res3[0x24];
|
|
|
|
u32 ttcfgr; /* Temperature Configuration Register */
|
|
|
|
u32 tscfgr; /* Sensor Configuration Register */
|
|
|
|
u8 res4[0x78];
|
|
|
|
struct imx_tmu_site_regs site[SITES_MAX];
|
|
|
|
u8 res5[0x9f8];
|
|
|
|
u32 ipbrr0; /* IP Block Revision Register 0 */
|
|
|
|
u32 ipbrr1; /* IP Block Revision Register 1 */
|
|
|
|
u8 res6[0x310];
|
|
|
|
u32 ttr0cr; /* Temperature Range 0 Control Register */
|
|
|
|
u32 ttr1cr; /* Temperature Range 1 Control Register */
|
|
|
|
u32 ttr2cr; /* Temperature Range 2 Control Register */
|
|
|
|
u32 ttr3cr; /* Temperature Range 3 Control Register */
|
|
|
|
};
|
|
|
|
|
2020-05-03 14:19:47 +00:00
|
|
|
struct imx_tmu_regs_v2 {
|
|
|
|
u32 ter; /* TMU enable Register */
|
|
|
|
u32 tsr; /* Status Register */
|
|
|
|
u32 tier; /* Interrupt enable register */
|
|
|
|
u32 tidr; /* Interrupt detect register */
|
|
|
|
u32 tmhtitr; /* Monitor high temperature immediate threshold register */
|
|
|
|
u32 tmhtatr; /* Monitor high temperature average threshold register */
|
|
|
|
u32 tmhtactr; /* TMU monitor high temperature average critical threshold register */
|
|
|
|
u32 tscr; /* Sensor value capture register */
|
|
|
|
u32 tritsr; /* Report immediate temperature site register 0 */
|
|
|
|
u32 tratsr; /* Report average temperature site register 0 */
|
|
|
|
u32 tasr; /* Amplifier setting register */
|
|
|
|
u32 ttmc; /* Test MUX control */
|
|
|
|
u32 tcaliv;
|
|
|
|
};
|
|
|
|
|
2020-05-03 14:19:51 +00:00
|
|
|
struct imx_tmu_regs_v3 {
|
|
|
|
u32 ter; /* TMU enable Register */
|
|
|
|
u32 tps; /* Status Register */
|
|
|
|
u32 tier; /* Interrupt enable register */
|
|
|
|
u32 tidr; /* Interrupt detect register */
|
|
|
|
u32 tmhtitr; /* Monitor high temperature immediate threshold register */
|
|
|
|
u32 tmhtatr; /* Monitor high temperature average threshold register */
|
|
|
|
u32 tmhtactr; /* TMU monitor high temperature average critical threshold register */
|
|
|
|
u32 tscr; /* Sensor value capture register */
|
|
|
|
u32 tritsr; /* Report immediate temperature site register 0 */
|
|
|
|
u32 tratsr; /* Report average temperature site register 0 */
|
|
|
|
u32 tasr; /* Amplifier setting register */
|
|
|
|
u32 ttmc; /* Test MUX control */
|
|
|
|
u32 tcaliv0;
|
|
|
|
u32 tcaliv1;
|
|
|
|
u32 tcaliv_m40;
|
|
|
|
u32 trim;
|
|
|
|
};
|
|
|
|
|
2020-05-03 14:19:47 +00:00
|
|
|
union tmu_regs {
|
|
|
|
struct imx_tmu_regs regs_v1;
|
|
|
|
struct imx_tmu_regs_v2 regs_v2;
|
2020-05-03 14:19:51 +00:00
|
|
|
struct imx_tmu_regs_v3 regs_v3;
|
2020-05-03 14:19:47 +00:00
|
|
|
};
|
|
|
|
|
2020-05-03 14:19:46 +00:00
|
|
|
struct imx_tmu_plat {
|
|
|
|
int critical;
|
|
|
|
int alert;
|
|
|
|
int polling_delay;
|
|
|
|
int id;
|
|
|
|
bool zone_node;
|
2020-05-03 14:19:47 +00:00
|
|
|
union tmu_regs *regs;
|
2020-05-03 14:19:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int read_temperature(struct udevice *dev, int *temp)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct imx_tmu_plat *pdata = dev_get_plat(dev);
|
2020-05-03 14:19:47 +00:00
|
|
|
ulong drv_data = dev_get_driver_data(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
u32 val;
|
2020-05-03 14:19:49 +00:00
|
|
|
u32 retry = 10;
|
2020-05-03 14:19:50 +00:00
|
|
|
u32 valid = 0;
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
do {
|
2020-05-03 14:19:49 +00:00
|
|
|
mdelay(100);
|
|
|
|
retry--;
|
|
|
|
|
2020-05-03 14:19:51 +00:00
|
|
|
if (drv_data & FLAGS_VER3) {
|
|
|
|
val = readl(&pdata->regs->regs_v3.tritsr);
|
|
|
|
valid = val & (1 << (30 + pdata->id));
|
|
|
|
} else if (drv_data & FLAGS_VER2) {
|
2020-05-03 14:19:47 +00:00
|
|
|
val = readl(&pdata->regs->regs_v2.tritsr);
|
2020-05-03 14:19:50 +00:00
|
|
|
/*
|
|
|
|
* Check if TEMP is in valid range, the V bit in TRITSR
|
|
|
|
* only reflects the RAW uncalibrated data
|
|
|
|
*/
|
|
|
|
valid = ((val & 0xff) < 10 || (val & 0xff) > 125) ? 0 : 1;
|
|
|
|
} else {
|
2020-05-03 14:19:47 +00:00
|
|
|
val = readl(&pdata->regs->regs_v1.site[pdata->id].tritsr);
|
2020-05-03 14:19:50 +00:00
|
|
|
valid = val & 0x80000000;
|
|
|
|
}
|
|
|
|
} while (!valid && retry > 0);
|
2020-05-03 14:19:46 +00:00
|
|
|
|
2020-05-03 14:19:51 +00:00
|
|
|
if (retry > 0) {
|
|
|
|
if (drv_data & FLAGS_VER3) {
|
|
|
|
val = (val >> (pdata->id * 16)) & 0xff;
|
|
|
|
if (val & 0x80) /* Negative */
|
|
|
|
val = (~(val & 0x7f) + 1);
|
|
|
|
|
|
|
|
*temp = val;
|
|
|
|
if (*temp < -40 || *temp > 125) /* Check the range */
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*temp *= 1000;
|
|
|
|
} else {
|
|
|
|
*temp = (val & 0xff) * 1000;
|
|
|
|
}
|
|
|
|
} else {
|
2020-05-03 14:19:49 +00:00
|
|
|
return -EINVAL;
|
2020-05-03 14:19:51 +00:00
|
|
|
}
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int imx_tmu_get_temp(struct udevice *dev, int *temp)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct imx_tmu_plat *pdata = dev_get_plat(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
int cpu_tmp = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = read_temperature(dev, &cpu_tmp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
while (cpu_tmp >= pdata->alert) {
|
|
|
|
printf("CPU Temperature (%dC) has beyond alert (%dC), close to critical (%dC)", cpu_tmp, pdata->alert, pdata->critical);
|
|
|
|
puts(" waiting...\n");
|
|
|
|
mdelay(pdata->polling_delay);
|
|
|
|
ret = read_temperature(dev, &cpu_tmp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*temp = cpu_tmp / 1000;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dm_thermal_ops imx_tmu_ops = {
|
|
|
|
.get_temp = imx_tmu_get_temp,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int imx_tmu_calibration(struct udevice *dev)
|
|
|
|
{
|
|
|
|
int i, val, len, ret;
|
|
|
|
u32 range[4];
|
|
|
|
const fdt32_t *calibration;
|
2020-12-03 23:55:20 +00:00
|
|
|
struct imx_tmu_plat *pdata = dev_get_plat(dev);
|
2020-05-03 14:19:47 +00:00
|
|
|
ulong drv_data = dev_get_driver_data(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
debug("%s\n", __func__);
|
|
|
|
|
2020-05-03 14:19:51 +00:00
|
|
|
if (drv_data & (FLAGS_VER2 | FLAGS_VER3))
|
2020-05-03 14:19:47 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-05-03 14:19:46 +00:00
|
|
|
ret = dev_read_u32_array(dev, "fsl,tmu-range", range, 4);
|
|
|
|
if (ret) {
|
|
|
|
printf("TMU: missing calibration range, ret = %d.\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init temperature range registers */
|
2020-05-03 14:19:47 +00:00
|
|
|
writel(range[0], &pdata->regs->regs_v1.ttr0cr);
|
|
|
|
writel(range[1], &pdata->regs->regs_v1.ttr1cr);
|
|
|
|
writel(range[2], &pdata->regs->regs_v1.ttr2cr);
|
|
|
|
writel(range[3], &pdata->regs->regs_v1.ttr3cr);
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
calibration = dev_read_prop(dev, "fsl,tmu-calibration", &len);
|
|
|
|
if (!calibration || len % 8) {
|
|
|
|
printf("TMU: invalid calibration data.\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < len; i += 8, calibration += 2) {
|
|
|
|
val = fdt32_to_cpu(*calibration);
|
2020-05-03 14:19:47 +00:00
|
|
|
writel(val, &pdata->regs->regs_v1.ttcfgr);
|
2020-05-03 14:19:46 +00:00
|
|
|
val = fdt32_to_cpu(*(calibration + 1));
|
2020-05-03 14:19:47 +00:00
|
|
|
writel(val, &pdata->regs->regs_v1.tscfgr);
|
2020-05-03 14:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-03 14:19:48 +00:00
|
|
|
void __weak imx_tmu_arch_init(void *reg_base)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-03 14:19:47 +00:00
|
|
|
static void imx_tmu_init(struct udevice *dev)
|
2020-05-03 14:19:46 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct imx_tmu_plat *pdata = dev_get_plat(dev);
|
2020-05-03 14:19:47 +00:00
|
|
|
ulong drv_data = dev_get_driver_data(dev);
|
|
|
|
|
2020-05-03 14:19:46 +00:00
|
|
|
debug("%s\n", __func__);
|
|
|
|
|
2020-05-03 14:19:51 +00:00
|
|
|
if (drv_data & FLAGS_VER3) {
|
|
|
|
/* Disable monitoring */
|
|
|
|
writel(0x0, &pdata->regs->regs_v3.ter);
|
|
|
|
|
|
|
|
/* Disable interrupt, using polling instead */
|
|
|
|
writel(0x0, &pdata->regs->regs_v3.tier);
|
|
|
|
|
|
|
|
} else if (drv_data & FLAGS_VER2) {
|
2020-05-03 14:19:47 +00:00
|
|
|
/* Disable monitoring */
|
|
|
|
writel(0x0, &pdata->regs->regs_v2.ter);
|
|
|
|
|
|
|
|
/* Disable interrupt, using polling instead */
|
|
|
|
writel(0x0, &pdata->regs->regs_v2.tier);
|
|
|
|
} else {
|
|
|
|
/* Disable monitoring */
|
|
|
|
writel(TMR_DISABLE, &pdata->regs->regs_v1.tmr);
|
2020-05-03 14:19:46 +00:00
|
|
|
|
2020-05-03 14:19:47 +00:00
|
|
|
/* Disable interrupt, using polling instead */
|
|
|
|
writel(TIER_DISABLE, &pdata->regs->regs_v1.tier);
|
2020-05-03 14:19:46 +00:00
|
|
|
|
2020-05-03 14:19:47 +00:00
|
|
|
/* Set update_interval */
|
|
|
|
writel(TMTMIR_DEFAULT, &pdata->regs->regs_v1.tmtmir);
|
|
|
|
}
|
2020-05-03 14:19:48 +00:00
|
|
|
|
|
|
|
imx_tmu_arch_init((void *)pdata->regs);
|
2020-05-03 14:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_tmu_enable_msite(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct imx_tmu_plat *pdata = dev_get_plat(dev);
|
2020-05-03 14:19:47 +00:00
|
|
|
ulong drv_data = dev_get_driver_data(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
debug("%s\n", __func__);
|
|
|
|
|
|
|
|
if (!pdata->regs)
|
|
|
|
return -EIO;
|
|
|
|
|
2020-05-03 14:19:51 +00:00
|
|
|
if (drv_data & FLAGS_VER3) {
|
|
|
|
reg = readl(&pdata->regs->regs_v3.ter);
|
|
|
|
reg &= ~TER_EN;
|
|
|
|
writel(reg, &pdata->regs->regs_v3.ter);
|
|
|
|
|
|
|
|
writel(pdata->id << 30, &pdata->regs->regs_v3.tps);
|
|
|
|
|
|
|
|
reg &= ~TER_ALPF;
|
|
|
|
reg |= 0x1;
|
|
|
|
reg &= ~TER_ADC_PD;
|
|
|
|
writel(reg, &pdata->regs->regs_v3.ter);
|
|
|
|
|
|
|
|
/* Enable monitor */
|
|
|
|
reg |= TER_EN;
|
|
|
|
writel(reg, &pdata->regs->regs_v3.ter);
|
|
|
|
} else if (drv_data & FLAGS_VER2) {
|
2020-05-03 14:19:47 +00:00
|
|
|
reg = readl(&pdata->regs->regs_v2.ter);
|
|
|
|
reg &= ~TER_EN;
|
|
|
|
writel(reg, &pdata->regs->regs_v2.ter);
|
2020-05-03 14:19:46 +00:00
|
|
|
|
2020-05-03 14:19:47 +00:00
|
|
|
reg &= ~TER_ALPF;
|
|
|
|
reg |= 0x1;
|
|
|
|
writel(reg, &pdata->regs->regs_v2.ter);
|
2020-05-03 14:19:46 +00:00
|
|
|
|
2020-05-03 14:19:47 +00:00
|
|
|
/* Enable monitor */
|
|
|
|
reg |= TER_EN;
|
|
|
|
writel(reg, &pdata->regs->regs_v2.ter);
|
|
|
|
} else {
|
|
|
|
/* Clear the ME before setting MSITE and ALPF*/
|
|
|
|
reg = readl(&pdata->regs->regs_v1.tmr);
|
|
|
|
reg &= ~TMR_ME;
|
|
|
|
writel(reg, &pdata->regs->regs_v1.tmr);
|
|
|
|
|
|
|
|
reg |= 1 << (15 - pdata->id);
|
|
|
|
reg |= TMR_ALPF;
|
|
|
|
writel(reg, &pdata->regs->regs_v1.tmr);
|
|
|
|
|
|
|
|
/* Enable ME */
|
|
|
|
reg |= TMR_ME;
|
|
|
|
writel(reg, &pdata->regs->regs_v1.tmr);
|
|
|
|
}
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_tmu_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct imx_tmu_plat *pdata = dev_get_plat(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
int ret;
|
|
|
|
ofnode node, offset;
|
|
|
|
const char *name;
|
|
|
|
const void *prop;
|
2021-02-06 00:11:05 +00:00
|
|
|
int minc, maxc;
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
debug("%s dev name %s\n", __func__, dev->name);
|
|
|
|
|
|
|
|
prop = dev_read_prop(dev, "compatible", NULL);
|
|
|
|
if (!prop)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pdata->zone_node = 1;
|
2021-02-06 00:11:05 +00:00
|
|
|
/* default alert/crit temps based on temp grade */
|
|
|
|
get_cpu_temp_grade(&minc, &maxc);
|
|
|
|
pdata->critical = maxc * 1000;
|
|
|
|
pdata->alert = (maxc - 10) * 1000;
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
node = ofnode_path("/thermal-zones");
|
|
|
|
ofnode_for_each_subnode(offset, node) {
|
|
|
|
/* Bind the subnode to this driver */
|
|
|
|
name = ofnode_get_name(offset);
|
|
|
|
|
|
|
|
ret = device_bind_with_driver_data(dev, dev->driver, name,
|
|
|
|
dev->driver_data, offset,
|
|
|
|
NULL);
|
|
|
|
if (ret)
|
|
|
|
printf("Error binding driver '%s': %d\n",
|
|
|
|
dev->driver->name, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_tmu_parse_fdt(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct imx_tmu_plat *pdata = dev_get_plat(dev), *p_parent_data;
|
2020-05-03 14:19:46 +00:00
|
|
|
struct ofnode_phandle_args args;
|
|
|
|
ofnode trips_np;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
debug("%s dev name %s\n", __func__, dev->name);
|
|
|
|
|
|
|
|
if (pdata->zone_node) {
|
2020-05-03 14:19:47 +00:00
|
|
|
pdata->regs = (union tmu_regs *)dev_read_addr_ptr(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
|
|
|
|
if (!pdata->regs)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:20 +00:00
|
|
|
p_parent_data = dev_get_plat(dev->parent);
|
2020-05-03 14:19:46 +00:00
|
|
|
if (p_parent_data->zone_node)
|
|
|
|
pdata->regs = p_parent_data->regs;
|
|
|
|
|
|
|
|
ret = dev_read_phandle_with_args(dev, "thermal-sensors",
|
|
|
|
"#thermal-sensor-cells",
|
|
|
|
0, 0, &args);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!ofnode_equal(args.node, dev_ofnode(dev->parent)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (args.args_count >= 1)
|
|
|
|
pdata->id = args.args[0];
|
|
|
|
else
|
|
|
|
pdata->id = 0;
|
|
|
|
|
|
|
|
debug("args.args_count %d, id %d\n", args.args_count, pdata->id);
|
|
|
|
|
|
|
|
pdata->polling_delay = dev_read_u32_default(dev, "polling-delay", 1000);
|
|
|
|
|
|
|
|
trips_np = ofnode_path("/thermal-zones/cpu-thermal/trips");
|
|
|
|
ofnode_for_each_subnode(trips_np, trips_np) {
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
type = ofnode_get_property(trips_np, "type", NULL);
|
|
|
|
if (!type)
|
|
|
|
continue;
|
|
|
|
if (!strcmp(type, "critical"))
|
|
|
|
pdata->critical = ofnode_read_u32_default(trips_np, "temperature", 85);
|
|
|
|
else if (strcmp(type, "passive") == 0)
|
|
|
|
pdata->alert = ofnode_read_u32_default(trips_np, "temperature", 80);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("id %d polling_delay %d, critical %d, alert %d\n",
|
|
|
|
pdata->id, pdata->polling_delay, pdata->critical, pdata->alert);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_tmu_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct imx_tmu_plat *pdata = dev_get_plat(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = imx_tmu_parse_fdt(dev);
|
|
|
|
if (ret) {
|
|
|
|
printf("Error in parsing TMU FDT %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->zone_node) {
|
2020-05-03 14:19:47 +00:00
|
|
|
imx_tmu_init(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
imx_tmu_calibration(dev);
|
2021-02-06 00:11:05 +00:00
|
|
|
imx_tmu_enable_msite(dev);
|
2020-05-03 14:19:46 +00:00
|
|
|
} else {
|
|
|
|
imx_tmu_enable_msite(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id imx_tmu_ids[] = {
|
|
|
|
{ .compatible = "fsl,imx8mq-tmu", },
|
2020-05-03 14:19:47 +00:00
|
|
|
{ .compatible = "fsl,imx8mm-tmu", .data = FLAGS_VER2, },
|
2020-05-03 14:19:51 +00:00
|
|
|
{ .compatible = "fsl,imx8mp-tmu", .data = FLAGS_VER3, },
|
2020-05-03 14:19:46 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(imx_tmu) = {
|
|
|
|
.name = "imx_tmu",
|
|
|
|
.id = UCLASS_THERMAL,
|
|
|
|
.ops = &imx_tmu_ops,
|
|
|
|
.of_match = imx_tmu_ids,
|
|
|
|
.bind = imx_tmu_bind,
|
|
|
|
.probe = imx_tmu_probe,
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct imx_tmu_plat),
|
2020-05-03 14:19:46 +00:00
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|