From 68db4c74c43d4042b0b32bcd133121ab39b9b310 Mon Sep 17 00:00:00 2001 From: Zhikui Ren Date: Tue, 2 Feb 2021 14:49:28 -0800 Subject: [PATCH] DTS_CPU: filter first zero from RdPkgConfig 10 Peci command GetPkgConfig 10 can return 0 (hot) with cc 0x40 after cpu reset. Once pcode run time image is loaded and it returns 0x8000 as DTS margin data not ready Discard the first zero reading and return -ENODATA. Consecutive zeros will be returned so that real hot condition will still be detected and logged but possibly delayed by the sensor polling period, which is normally one second. Signed-off-by: Zhikui Ren --- drivers/hwmon/peci-cputemp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/hwmon/peci-cputemp.c b/drivers/hwmon/peci-cputemp.c index 19002f02bd91..e1860779aa66 100644 --- a/drivers/hwmon/peci-cputemp.c +++ b/drivers/hwmon/peci-cputemp.c @@ -17,6 +17,7 @@ struct temp_group { struct peci_sensor_data die; u32 die_raw_prev; struct peci_sensor_data dts; + u32 dts_raw_prev; struct peci_sensor_data tcontrol; struct peci_sensor_data tthrottle; struct peci_sensor_data tjmax; @@ -168,6 +169,7 @@ static int get_dts(struct peci_cputemp *priv) s32 dts_margin; u8 pkg_cfg[4]; int ret; + bool discard = false; if (!peci_sensor_need_update(&priv->temp.dts)) return 0; @@ -181,6 +183,22 @@ static int get_dts(struct peci_cputemp *priv) dts_margin = le16_to_cpup((__le16 *)pkg_cfg); + /* There is a small window (500us) for read dts_margin (RdPkgConfig 10) + * to return cc 0x40, and dts_margin of 0 after cpu reset, before runtime + * image is loaded to set it to 0x8000 (dts reading not ready). + * DTS sensor is polled by user application at a slower rate than this window. + * Treat the first zero reading as data not available. + * Consecutive zeros will be returned so true hot condition + * is not be missed. + */ + if (dts_margin == 0 && priv->temp.dts_raw_prev != 0) { + pr_err("peci-cputemp_dts: discard first 0 reading from RdPkgConfig 10\n"); + discard = true; + } + priv->temp.dts_raw_prev = dts_margin; + if (discard) + return -ENODATA; + /** * Processors return a value of DTS reading in 10.6 format * (10 bits signed decimal, 6 bits fractional). -- 2.17.1