summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-kernel/linux/linux-aspeed/0006-DTS_CPU-filter-first-zero-from-RdPkgConfig-10.patch
blob: a498f9c197711b9461f7087580618a49f4f3175b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From 4d4e68e0eed7ccf899bc1b3799a93ed8eb44270d Mon Sep 17 00:00:00 2001
From: Zhikui Ren <zhikui.ren@intel.com>
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 <zhikui.ren@intel.com>
---
 drivers/hwmon/peci-cputemp.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/hwmon/peci-cputemp.c b/drivers/hwmon/peci-cputemp.c
index 49670bc80530..af1c09741120 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;
@@ -159,6 +160,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;
@@ -172,6 +174,24 @@ 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) {
+		dev_err(priv->dev,
+			"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