From patchwork Sun May 3 14:19:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 244906 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Sun, 3 May 2020 22:19:49 +0800 Subject: [PATCH 05/13] thermal: imx_tmu: Fix for temperature out of range In-Reply-To: <20200503141957.14635-1-peng.fan@nxp.com> References: <20200503141957.14635-1-peng.fan@nxp.com> Message-ID: <20200503141957.14635-6-peng.fan@nxp.com> When the temperature is out of sensor's range, the Valid bit won't be set in TRITSR register. So the polling loop won't go out. Change the codes to retry 10 times with 100ms interval for the Valid bit. If the timeout, we give a warning for the invalid data. Modifed from Ye's NXP patch Signed-off-by: Peng Fan --- drivers/thermal/imx_tmu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/imx_tmu.c b/drivers/thermal/imx_tmu.c index 049f32c39e..2a08d5085c 100644 --- a/drivers/thermal/imx_tmu.c +++ b/drivers/thermal/imx_tmu.c @@ -105,15 +105,22 @@ static int read_temperature(struct udevice *dev, int *temp) struct imx_tmu_plat *pdata = dev_get_platdata(dev); ulong drv_data = dev_get_driver_data(dev); u32 val; + u32 retry = 10; do { - if (drv_data & FLAGS_VER2) { + mdelay(100); + retry--; + + if (drv_data & FLAGS_VER2) val = readl(&pdata->regs->regs_v2.tritsr); else val = readl(&pdata->regs->regs_v1.site[pdata->id].tritsr); - } while (!(val & 0x80000000)); + } while (!(val & 0x80000000) && retry > 0); - *temp = (val & 0xff) * 1000; + if (retry > 0) + *temp = (val & 0xff) * 1000; + else + return -EINVAL; return 0; }