summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDawid Niedzwiecki <dn@semihalf.com>2021-02-17 12:15:21 +0100
committerCommit Bot <commit-bot@chromium.org>2021-02-23 19:29:13 +0000
commita5a81dca4579961b9d78c7c85442d76b3c87dbbb (patch)
treec702e09f5137ecab4b8b69b5982543bf9a9f3e63
parent25fa055c3ecd98c5d339cc4002054c584f99cb1b (diff)
downloadchrome-ec-a5a81dca4579961b9d78c7c85442d76b3c87dbbb.tar.gz
zephyr: add shim thermal support
Add thermal support to Zephyr which includes handling temperature threshold for certain events. The thresholds are defined in the dts file as temperature sensor parameters - there are limits per temperature sensor. The struct ec_thermal_config thermal_params[] array with all parameters is generated automatically based on named_temp_sensors node. Enable "thermalget" and "thermalset" console commands along with EC_CMD_THERMAL_GET_THRESHOLD and EC_CMD_THERMAL_SET_THRESHOLD host commands. Also, add a few functions to utils needed to verify if an event occurred (falling/rising edge). BUG=b:179886912 BRANCH=none TEST=build Zephyr TEST=Run "thermalget" command to check current thresholds. Change the thresholds with "thermalset" to verify if AP throttling is requested. Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I5f527ceecab2427b3034fd8baa62bb8482f99ff3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2698845 Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/temp_sensor.c3
-rw-r--r--common/thermal.c4
-rw-r--r--zephyr/CMakeLists.txt1
-rw-r--r--zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml2
-rw-r--r--zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml2
-rw-r--r--zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml2
-rw-r--r--zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml2
-rw-r--r--zephyr/dts/bindings/temp/temp_sensor.yaml79
-rw-r--r--zephyr/dts/bindings/temp/thermistor.yaml8
-rw-r--r--zephyr/shim/src/CMakeLists.txt3
-rw-r--r--zephyr/shim/src/thermal.c36
-rw-r--r--zephyr/shim/src/util.c42
12 files changed, 169 insertions, 15 deletions
diff --git a/common/temp_sensor.c b/common/temp_sensor.c
index 8c72f1535c..55101a5345 100644
--- a/common/temp_sensor.c
+++ b/common/temp_sensor.c
@@ -117,8 +117,6 @@ int console_command_temps(int argc, char **argv)
case EC_SUCCESS:
ccprintf("%d K = %d C", t, K_TO_C(t));
#ifdef CONFIG_THROTTLE_AP
-#ifndef CONFIG_ZEPHYR
-/* TODO(b/179886912): Add thermal support */
if (thermal_params[i].temp_fan_off &&
thermal_params[i].temp_fan_max)
ccprintf(" %d%%",
@@ -126,7 +124,6 @@ int console_command_temps(int argc, char **argv)
thermal_params[i].temp_fan_off,
thermal_params[i].temp_fan_max,
t));
-#endif /* CONFIG_ZEPHYR */
#endif
ccprintf("\n");
break;
diff --git a/common/thermal.c b/common/thermal.c
index 821430482a..40577c0d43 100644
--- a/common/thermal.c
+++ b/common/thermal.c
@@ -19,6 +19,10 @@
#include "timer.h"
#include "util.h"
+#ifdef CONFIG_ZEPHYR
+#include "temp_sensor/temp_sensor.h"
+#endif
+
/* Console output macros */
#define CPUTS(outstr) cputs(CC_THERMAL, outstr)
#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ## args)
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index 8a7359ec65..855bd1d753 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -256,6 +256,7 @@ zephyr_sources_ifdef(CONFIG_PLATFORM_EC_SPI_FLASH_REGS
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TABLET_MODE
"${PLATFORM_EC}/common/tablet_mode.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TEMP_SENSOR
+ "${PLATFORM_EC}/common/thermal.c"
"${PLATFORM_EC}/common/temp_sensor.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_THERMISTOR
"${PLATFORM_EC}/driver/temp_sensor/thermistor.c")
diff --git a/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml b/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml
index fb9061c33d..b2a3c4c88a 100644
--- a/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml
+++ b/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml
@@ -6,4 +6,4 @@ description: Thermistor 3v0-22k6-47k-4050b
compatible: "temp-3v0-22k6-47k-4050b"
-include: thermistor.yaml
+include: [temp_sensor.yaml, thermistor.yaml]
diff --git a/zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml b/zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml
index 325fcac8f1..7928fcd54a 100644
--- a/zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml
+++ b/zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml
@@ -6,4 +6,4 @@ description: Thermistor 3v3-13k7-47k-4050b
compatible: "temp-3v3-13k7-47k-4050b"
-include: thermistor.yaml
+include: [temp_sensor.yaml, thermistor.yaml]
diff --git a/zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml b/zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml
index 99ab1cc015..d8745e7abd 100644
--- a/zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml
+++ b/zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml
@@ -6,4 +6,4 @@ description: Thermistor 3v3-30k9-47k-4050b
compatible: "temp-3v3-30k9-47k-4050b"
-include: thermistor.yaml
+include: [temp_sensor.yaml, thermistor.yaml]
diff --git a/zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml b/zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml
index 6f54f98eb2..da53437c01 100644
--- a/zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml
+++ b/zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml
@@ -6,4 +6,4 @@ description: Thermistor 3v3-51k1-47k-4050b
compatible: "temp-3v3-51k1-47k-4050b"
-include: thermistor.yaml
+include: [temp_sensor.yaml, thermistor.yaml]
diff --git a/zephyr/dts/bindings/temp/temp_sensor.yaml b/zephyr/dts/bindings/temp/temp_sensor.yaml
new file mode 100644
index 0000000000..b96e9c3262
--- /dev/null
+++ b/zephyr/dts/bindings/temp/temp_sensor.yaml
@@ -0,0 +1,79 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Common properties for temperature sensors
+# Zero values in degrees K(-273 in degrees C)in thermal thresholds will
+# be ignored
+
+properties:
+ label:
+ required: true
+ type: string
+ description:
+ Human-readable string describing the device (used as
+ device_get_binding() argument)
+
+ temp_fan_off:
+ required: false
+ type: int
+ default: -273
+ description:
+ Temperature threshold in degrees C when no active cooling
+ is needed
+
+ temp_fan_max:
+ required: false
+ type: int
+ default: -273
+ description:
+ Temperature threshold in degrees C when max active cooling
+ is needed
+
+ temp_host_warn:
+ required: false
+ type: int
+ default: -273
+ description:
+ Temperature threshold in degrees C of thermal warn.
+ Temperatures above the thermal warn threshold generate a
+ request to the AP to throttle itself.
+
+ temp_host_high:
+ required: false
+ type: int
+ default: -273
+ description:
+ Temperature threshold in degrees C of thermal high.
+ Temperatures above the thermal high threshold cause the EC to
+ assert a signal (usually PROCHOT) to the AP and force the AP to
+ throttle.
+
+ temp_host_halt:
+ required: false
+ type: int
+ default: -273
+ description:
+ Temperature threshold in degrees C that forces AP to shutdown
+ due to thermal reason
+
+ temp_host_release_warn:
+ required: false
+ type: int
+ default: -273
+ description:
+ Temperature release threshold in degrees C of thermal warn
+
+ temp_host_release_high:
+ required: false
+ type: int
+ default: -273
+ description:
+ Temperature release threshold in degrees C of thermal high
+
+ temp_host_release_halt:
+ required: false
+ type: int
+ default: -273
+ description:
+ Temperature release threshold in degrees C of thermal shutdown
diff --git a/zephyr/dts/bindings/temp/thermistor.yaml b/zephyr/dts/bindings/temp/thermistor.yaml
index 6d53cdbff3..80503ce4df 100644
--- a/zephyr/dts/bindings/temp/thermistor.yaml
+++ b/zephyr/dts/bindings/temp/thermistor.yaml
@@ -2,15 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-description: Thermistor properties
+# Common properties for thermistors
properties:
- label:
- required: true
- type: string
- description:
- Human-readable string describing the device (used as
- device_get_binding() argument)
adc:
required: true
type: phandle
diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt
index 38955f65d4..0311299074 100644
--- a/zephyr/shim/src/CMakeLists.txt
+++ b/zephyr/shim/src/CMakeLists.txt
@@ -27,7 +27,8 @@ zephyr_sources_ifdef(CONFIG_PLATFORM_EC_MPU mpu.c)
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_PANIC panic.c)
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_PWM pwm.c)
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_RTC rtc.c)
-zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TEMP_SENSOR temp_sensors.c)
+zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TEMP_SENSOR temp_sensors.c
+ thermal.c)
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c)
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_I2C i2c.c)
zephyr_sources_ifdef(CONFIG_SHIMMED_TASKS tasks.c)
diff --git a/zephyr/shim/src/thermal.c b/zephyr/shim/src/thermal.c
new file mode 100644
index 0000000000..2dd754b663
--- /dev/null
+++ b/zephyr/shim/src/thermal.c
@@ -0,0 +1,36 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "temp_sensor.h"
+#include "temp_sensor/temp_sensor.h"
+#include "ec_commands.h"
+
+#define THERMAL_CONFIG(node_id) \
+ [node_id] = { \
+ .temp_host = { \
+ [EC_TEMP_THRESH_WARN] = \
+ C_TO_K(DT_PROP(node_id, temp_host_warn)), \
+ [EC_TEMP_THRESH_HIGH] = \
+ C_TO_K(DT_PROP(node_id, temp_host_high)), \
+ [EC_TEMP_THRESH_HALT] = \
+ C_TO_K(DT_PROP(node_id, temp_host_halt)), \
+ }, \
+ .temp_host_release = { \
+ [EC_TEMP_THRESH_WARN] = C_TO_K( \
+ DT_PROP(node_id, temp_host_release_warn)), \
+ [EC_TEMP_THRESH_HIGH] = C_TO_K( \
+ DT_PROP(node_id, temp_host_release_high)), \
+ [EC_TEMP_THRESH_HALT] = C_TO_K( \
+ DT_PROP(node_id, temp_host_release_halt)), \
+ }, \
+ .temp_fan_off = C_TO_K(DT_PROP(node_id, temp_fan_off)), \
+ .temp_fan_max = C_TO_K(DT_PROP(node_id, temp_fan_max)), \
+ },
+
+struct ec_thermal_config thermal_params[] = {
+#if DT_NODE_EXISTS(DT_PATH(named_temp_sensors))
+ DT_FOREACH_CHILD(DT_PATH(named_temp_sensors), THERMAL_CONFIG)
+#endif /* named_temp_sensors */
+};
diff --git a/zephyr/shim/src/util.c b/zephyr/shim/src/util.c
index f915be9ad8..38a254bf47 100644
--- a/zephyr/shim/src/util.c
+++ b/zephyr/shim/src/util.c
@@ -226,3 +226,45 @@ char *strzcpy(char *dest, const char *src, int len)
*d = '\0';
return dest;
}
+
+/* stateful conditional stuff */
+enum cond_internal_bits {
+ COND_CURR_MASK = BIT(0), /* current value */
+ COND_RISE_MASK = BIT(1), /* set if 0->1 */
+ COND_FALL_MASK = BIT(2), /* set if 1->0 */
+};
+
+void cond_set(cond_t *c, int val)
+{
+ if (val && cond_is(c, 0))
+ *c |= COND_RISE_MASK;
+ else if (!val && cond_is(c, 1))
+ *c |= COND_FALL_MASK;
+ if (val)
+ *c |= COND_CURR_MASK;
+ else
+ *c &= ~COND_CURR_MASK;
+}
+
+int cond_went(cond_t *c, int val)
+{
+ int ret;
+
+ if (val) {
+ ret = *c & COND_RISE_MASK;
+ *c &= ~COND_RISE_MASK;
+ } else {
+ ret = *c & COND_FALL_MASK;
+ *c &= ~COND_FALL_MASK;
+ }
+
+ return ret;
+}
+
+int cond_is(cond_t *c, int val)
+{
+ if (val)
+ return *c & COND_CURR_MASK;
+ else
+ return !(*c & COND_CURR_MASK);
+}