summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-kernel/linux/linux-aspeed/0005-Die_CPU-filter-first-zero-from-GetTemp.patch
blob: 54dced64fa6f93d4a60e6f3a2eae00c601a6198e (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
From b0740cbafa468ece35d26a797e7cf80f04fb5102 Mon Sep 17 00:00:00 2001
From: Zhikui Ren <zhikui.ren@intel.com>
Date: Mon, 11 Jan 2021 16:31:36 -0800
Subject: [PATCH] Die_CPU: filter first zero from GetTemp

Peci command GetTemp can return 0 during CPU reset.
It does not have a have completion code either.
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 500ms-1s.

Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
---
 drivers/hwmon/peci-cputemp.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/hwmon/peci-cputemp.c b/drivers/hwmon/peci-cputemp.c
index c5d92d1d2c25..49670bc80530 100644
--- a/drivers/hwmon/peci-cputemp.c
+++ b/drivers/hwmon/peci-cputemp.c
@@ -15,6 +15,7 @@
 
 struct temp_group {
 	struct peci_sensor_data		die;
+	u32				die_raw_prev;
 	struct peci_sensor_data		dts;
 	struct peci_sensor_data		tcontrol;
 	struct peci_sensor_data		tthrottle;
@@ -119,6 +120,7 @@ static int get_die_temp(struct peci_cputemp *priv)
 {
 	struct peci_get_temp_msg msg;
 	int ret;
+	bool discard = false;
 
 	if (!peci_sensor_need_update(&priv->temp.die))
 		return 0;
@@ -129,6 +131,20 @@ static int get_die_temp(struct peci_cputemp *priv)
 	if (ret)
 		return ret;
 
+	/*
+	 * GET_TEMP command does not have cc and can return zero during
+	 * cpu reset. Treat the first zero reading as data not available.
+	 * Consecutive zeros will be returned so true hot condition
+	 * is not be missed.
+	 */
+	if (msg.temp_raw == 0 && priv->temp.die_raw_prev != 0) {
+		dev_err(priv->dev, "discard first 0 reading from GetTemp\n");
+		discard = true;
+	}
+	priv->temp.die_raw_prev = msg.temp_raw;
+	if (discard)
+		return -ENODATA;
+
 	/* Note that the tjmax should be available before calling it */
 	priv->temp.die.value = priv->temp.tjmax.value +
 			       (msg.temp_raw * 1000 / 64);
-- 
2.17.1