summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-04-02 11:48:41 +1300
committerCommit Bot <commit-bot@chromium.org>2021-04-02 23:12:52 +0000
commit227d8ca20a7ac1cd6dd580b426998a36bdd22994 (patch)
tree95096a8f9b0ec5c1395d67dd36245424e653413e
parent5e52d647e27bc0f50e3387cdc13bc28e37a6d8f3 (diff)
downloadchrome-ec-227d8ca20a7ac1cd6dd580b426998a36bdd22994.tar.gz
zephyr: Update the temperature-sensor shim
At present this shim relies partially on a hard-coded mapping, in the temp_sensors.c file. Also it uses the node IDs as enum values, which makes it difficult to actually use the enums in the code. With the ADC shim we need to be able to support using ADC enums in the code, such as ADC_PSYS. This will force a change of naming in enum adc_channel, which temperature sensors refer to. Update the shim to use an enum for the temp-sensor ID and another for the function to call to read the temperature. BUG=b:175881324 BRANCH=none TEST=build Zephyr for lazor and volteer Change-Id: I08bd45568be525650b8527830053ee541d6240cf Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2801172 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml6
-rw-r--r--zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml6
-rw-r--r--zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml6
-rw-r--r--zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml6
-rw-r--r--zephyr/dts/bindings/temp/temp_sensor.yaml11
-rw-r--r--zephyr/dts/bindings/temp/thermistor.yaml26
-rw-r--r--zephyr/projects/volteer/boards/arm/volteer/volteer.dts4
-rw-r--r--zephyr/shim/include/temp_sensor/temp_sensor.h12
-rw-r--r--zephyr/shim/src/temp_sensors.c37
-rw-r--r--zephyr/shim/src/thermal.c2
10 files changed, 79 insertions, 37 deletions
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 b2a3c4c88a..09390a3656 100644
--- a/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml
+++ b/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml
@@ -7,3 +7,9 @@ description: Thermistor 3v0-22k6-47k-4050b
compatible: "temp-3v0-22k6-47k-4050b"
include: [temp_sensor.yaml, thermistor.yaml]
+
+properties:
+ get-temp-func:
+ enum:
+ - get_temp_3v0_22k6_47k_4050b
+ default: get_temp_3v0_22k6_47k_4050b
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 7928fcd54a..76b6dfaa30 100644
--- a/zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml
+++ b/zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml
@@ -7,3 +7,9 @@ description: Thermistor 3v3-13k7-47k-4050b
compatible: "temp-3v3-13k7-47k-4050b"
include: [temp_sensor.yaml, thermistor.yaml]
+
+properties:
+ get-temp-func:
+ enum:
+ - get_temp_3v3_13k7_47k_4050b
+ default: get_temp_3v3_13k7_47k_4050b
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 d8745e7abd..4d45a0eb51 100644
--- a/zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml
+++ b/zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml
@@ -7,3 +7,9 @@ description: Thermistor 3v3-30k9-47k-4050b
compatible: "temp-3v3-30k9-47k-4050b"
include: [temp_sensor.yaml, thermistor.yaml]
+
+properties:
+ get-temp-func:
+ enum:
+ - get_temp_3v3_30k9_47k_4050b
+ default: get_temp_3v3_30k9_47k_4050b
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 da53437c01..0b8343f909 100644
--- a/zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml
+++ b/zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml
@@ -7,3 +7,9 @@ description: Thermistor 3v3-51k1-47k-4050b
compatible: "temp-3v3-51k1-47k-4050b"
include: [temp_sensor.yaml, thermistor.yaml]
+
+properties:
+ get-temp-func:
+ enum:
+ - get_temp_3v3_51k1_47k_4050b
+ default: get_temp_3v3_51k1_47k_4050b
diff --git a/zephyr/dts/bindings/temp/temp_sensor.yaml b/zephyr/dts/bindings/temp/temp_sensor.yaml
index b96e9c3262..753cfab967 100644
--- a/zephyr/dts/bindings/temp/temp_sensor.yaml
+++ b/zephyr/dts/bindings/temp/temp_sensor.yaml
@@ -14,6 +14,17 @@ properties:
Human-readable string describing the device (used as
device_get_binding() argument)
+ enum-name:
+ type: string
+ required: true
+ description:
+ Enum values used in the source code to refer to the temperature sensors
+ enum:
+ - TEMP_SENSOR_CHARGER
+ - TEMP_SENSOR_DDR_SOC
+ - TEMP_SENSOR_FAN
+ - TEMP_SENSOR_PP3300_REGULATOR
+
temp_fan_off:
required: false
type: int
diff --git a/zephyr/dts/bindings/temp/thermistor.yaml b/zephyr/dts/bindings/temp/thermistor.yaml
index 80503ce4df..66a07de945 100644
--- a/zephyr/dts/bindings/temp/thermistor.yaml
+++ b/zephyr/dts/bindings/temp/thermistor.yaml
@@ -5,7 +5,25 @@
# Common properties for thermistors
properties:
- adc:
- required: true
- type: phandle
- description: named-adc child node connected to the thermistor
+ adc:
+ required: true
+ type: phandle
+ description: named-adc child node connected to the thermistor
+
+ get-temp-func:
+ type: string
+ required: false
+ description: >
+ Name of the board-provided function which reads the temperature. If you
+ have different values and need to add a new function, you can add that
+ here.
+
+ The name is get_temp_<v>_<rs>_<rn>_<b>:
+
+ v: voltage of resistor-divider circuit
+ rs: value of the resistor that is in series with the thermistor
+ rn: nominal resistance of thermistor at 25C
+ b: B value for temperature range 25C to 100C
+
+ See https://www.electronics-tutorials.ws/io/thermistors.html for more
+ information.
diff --git a/zephyr/projects/volteer/boards/arm/volteer/volteer.dts b/zephyr/projects/volteer/boards/arm/volteer/volteer.dts
index f2b3fbb940..1d1e694f0d 100644
--- a/zephyr/projects/volteer/boards/arm/volteer/volteer.dts
+++ b/zephyr/projects/volteer/boards/arm/volteer/volteer.dts
@@ -99,6 +99,7 @@
charger {
compatible = "temp-3v3-30k9-47k-4050b";
label = "TEMP_SENSOR_CHARGER";
+ enum-name = "TEMP_SENSOR_CHARGER";
temp_fan_off = <40>;
temp_fan_max = <55>;
temp_host_high = <75>;
@@ -109,6 +110,7 @@
pp3300_regulator {
compatible = "temp-3v3-30k9-47k-4050b";
label = "TEMP_SENSOR_PP3300_REGULATOR";
+ enum-name = "TEMP_SENSOR_PP3300_REGULATOR";
temp_fan_off = <40>;
temp_fan_max = <55>;
temp_host_high = <75>;
@@ -119,6 +121,7 @@
ddr_soc {
compatible = "temp-3v3-30k9-47k-4050b";
label = "TEMP_SENSOR_DDR_SOC";
+ enum-name = "TEMP_SENSOR_DDR_SOC";
temp_fan_off = <35>;
temp_fan_max = <50>;
temp_host_high = <70>;
@@ -129,6 +132,7 @@
fan {
compatible = "temp-3v3-30k9-47k-4050b";
label = "TEMP_SENSOR_FAN";
+ enum-name = "TEMP_SENSOR_FAN";
temp_fan_off = <35>;
temp_fan_max = <50>;
temp_host_high = <70>;
diff --git a/zephyr/shim/include/temp_sensor/temp_sensor.h b/zephyr/shim/include/temp_sensor/temp_sensor.h
index 020d622ae1..3107b7b638 100644
--- a/zephyr/shim/include/temp_sensor/temp_sensor.h
+++ b/zephyr/shim/include/temp_sensor/temp_sensor.h
@@ -9,13 +9,21 @@
#include <devicetree.h>
#ifdef CONFIG_PLATFORM_EC_TEMP_SENSOR
-#define NODE_ID_AND_COMMA(node_id) node_id,
+
+#define ZSHIM_TEMP_SENSOR_ID(node_id) \
+ DT_ENUM_UPPER_TOKEN(node_id, enum_name)
+#define TEMP_SENSOR_ID_WITH_COMMA(node_id) ZSHIM_TEMP_SENSOR_ID(node_id),
+
enum temp_sensor_id {
#if DT_NODE_EXISTS(DT_PATH(named_temp_sensors))
- DT_FOREACH_CHILD(DT_PATH(named_temp_sensors), NODE_ID_AND_COMMA)
+ DT_FOREACH_CHILD(DT_PATH(named_temp_sensors),
+ TEMP_SENSOR_ID_WITH_COMMA)
#endif /* named_temp_sensors */
TEMP_SENSOR_COUNT
};
+
+#undef TEMP_SENSOR_ID_WITH_COMMA
+
#endif /* CONFIG_PLATFORM_EC_TEMP_SENSOR */
#endif /* ZEPHYR_SHIM_INCLUDE_TEMP_SENSOR_TEMP_SENSOR_H_ */
diff --git a/zephyr/shim/src/temp_sensors.c b/zephyr/shim/src/temp_sensors.c
index c43dfd8082..dfe259f126 100644
--- a/zephyr/shim/src/temp_sensors.c
+++ b/zephyr/shim/src/temp_sensors.c
@@ -8,39 +8,16 @@
#include "adc.h"
#include "../driver/temp_sensor/thermistor.h"
-#define TEMP_THERMISTOR(node_id, fn) \
- [node_id] = { \
- .name = DT_LABEL(node_id), \
- .read = fn, \
- .idx = DT_PHANDLE(node_id, adc), \
- .type = TEMP_SENSOR_TYPE_BOARD, \
+#define TEMP_THERMISTOR(node_id) \
+ [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \
+ .name = DT_LABEL(node_id), \
+ .read = DT_ENUM_TOKEN(node_id, get_temp_func), \
+ .idx = DT_PHANDLE(node_id, adc), \
+ .type = TEMP_SENSOR_TYPE_BOARD, \
},
-#define TEMP_3V3_30K9_47K_4050B(node_id) \
- TEMP_THERMISTOR(node_id, get_temp_3v3_30k9_47k_4050b)
-
-#define TEMP_3V0_22K6_47K_4050B(node_id) \
- TEMP_THERMISTOR(node_id, get_temp_3v0_22k6_47k_4050b)
-
-#define TEMP_3V3_51K1_47K_4050B(node_id) \
- TEMP_THERMISTOR(node_id, get_temp_3v3_51k1_47k_4050b)
-
-#define TEMP_3V3_13K7_47K_4050B(node_id) \
- TEMP_THERMISTOR(node_id, get_temp_3v3_13k7_47k_4050b)
-
-#define TEMP_DEVICE_INST(inst, compat, expr) expr(DT_INST(inst, compat))
-
-#define TEMP_DEVICE(compat, expr) \
- UTIL_LISTIFY(DT_NUM_INST_STATUS_OKAY(compat), TEMP_DEVICE_INST, \
- compat, expr)
-
#if DT_NODE_EXISTS(DT_PATH(named_temp_sensors))
-
const struct temp_sensor_t temp_sensors[] = {
- TEMP_DEVICE(temp_3v3_13k7_47k_4050b, TEMP_3V3_13K7_47K_4050B)
- TEMP_DEVICE(temp_3v3_51k1_47k_4050b, TEMP_3V3_51K1_47K_4050B)
- TEMP_DEVICE(temp_3v0_22k6_47k_4050b, TEMP_3V0_22K6_47K_4050B)
- TEMP_DEVICE(temp_3v3_30k9_47k_4050b, TEMP_3V3_30K9_47K_4050B)
+ DT_FOREACH_CHILD(DT_PATH(named_temp_sensors), TEMP_THERMISTOR)
};
-
#endif /* named_temp_sensors */
diff --git a/zephyr/shim/src/thermal.c b/zephyr/shim/src/thermal.c
index 2dd754b663..ecac9242f8 100644
--- a/zephyr/shim/src/thermal.c
+++ b/zephyr/shim/src/thermal.c
@@ -8,7 +8,7 @@
#include "ec_commands.h"
#define THERMAL_CONFIG(node_id) \
- [node_id] = { \
+ [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \
.temp_host = { \
[EC_TEMP_THRESH_WARN] = \
C_TO_K(DT_PROP(node_id, temp_host_warn)), \