Skip to content

Commit

Permalink
LF-12054 thermal: qoriq: workaround the tmu temp jump on imx93
Browse files Browse the repository at this point in the history
On i.MX93, the temp read from tmu may jump wrongly(ERR052243),
and invalid temp will be read out. To workaround such issue, we
need to use the raising/falling edge threshold to filter out
the wrong temp. When reading the temp, need to check the TIDR
register to make sure no jump happens.

Please refer to NXP errata ERR052243 for more details.

Signed-off-by: Jacky Bai <ping.bai@nxp.com>
Reviewed-by: Ye Li <ye.li@nxp.com>
  • Loading branch information
JackyBai committed Apr 25, 2024
1 parent de54941 commit 407c2d4
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions drivers/thermal/qoriq_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
#define REGS_TIER 0x020 /* Interrupt Enable Register */
#define TIER_DISABLE 0x0

#define REGS_TIDR 0x24
#define TMRTRCTR 0x70
#define TMRTRCTR_EN BIT(31)
#define TMRTRCTR_TEMP(x) ((x) & 0xFF)
#define TMFTRCTR 0x74
#define TMFTRCTR_EN BIT(31)
#define TMFTRCTR_TEMP(x) ((x) & 0xFF)

#define REGS_TTCFGR 0x080 /* Temperature Configuration Register */
#define REGS_TSCFGR 0x084 /* Sensor Configuration Register */
Expand Down Expand Up @@ -103,7 +110,7 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct qoriq_sensor *qsensor = thermal_zone_device_priv(tz);
struct qoriq_tmu_data *qdata = qoriq_sensor_to_data(qsensor);
u32 val;
u32 val, tidr;
/*
* REGS_TRITSR(id) has the following layout:
*
Expand All @@ -128,6 +135,15 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
if (!(val & TMR_ME))
return -EAGAIN;

/* ERR052243: If there raising or falling edge happens, try later */
if (qdata->ver == TMU_VER93) {
regmap_read(qdata->regmap, REGS_TIDR, &tidr);
if (tidr & GENMASK(25, 24)) {
regmap_write(qdata->regmap, REGS_TIDR, GENMASK(25, 24));
return -EAGAIN;
}
}

if (regmap_read_poll_timeout(qdata->regmap,
REGS_TRITSR(qsensor->id),
val,
Expand All @@ -136,6 +152,15 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
10 * USEC_PER_MSEC))
return -ENODATA;

/*ERR052243: If there raising or falling edge happens, try later */
if (qdata->ver == TMU_VER93) {
regmap_read(qdata->regmap, REGS_TIDR, &tidr);
if (tidr & GENMASK(25, 24)) {
regmap_write(qdata->regmap, REGS_TIDR, GENMASK(25, 24));
return -EAGAIN;
}
}

if (qdata->ver == TMU_VER1) {
*temp = (val & GENMASK(7, 0)) * MILLIDEGREE_PER_DEGREE;
} else {
Expand Down Expand Up @@ -301,12 +326,14 @@ static void qoriq_tmu_init_device(struct qoriq_tmu_data *data)
regmap_write(data->regmap, REGS_TIER, TIER_DISABLE);

/* Set update_interval */

if (data->ver == TMU_VER1) {
regmap_write(data->regmap, REGS_TMTMIR, TMTMIR_DEFAULT);
} else if (data->ver == TMU_VER93) {
regmap_write(data->regmap, REGS_V2_TMTMIR, TMTMIR_DEFAULT);
regmap_write(data->regmap, REGS_V2_TEUMR(0), TEUMR0_V21);
/* ERR052243: Set the raising & falling edge monitor */
regmap_write(data->regmap, TMRTRCTR, TMRTRCTR_EN | TMRTRCTR_TEMP(0x7));
regmap_write(data->regmap, TMFTRCTR, TMFTRCTR_EN | TMFTRCTR_TEMP(0x7));
} else {
regmap_write(data->regmap, REGS_V2_TMTMIR, TMTMIR_DEFAULT);
regmap_write(data->regmap, REGS_V2_TEUMR(0), TEUMR0_V2);
Expand Down

0 comments on commit 407c2d4

Please sign in to comment.