diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2021-02-05 13:04:18 +0100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-17 06:49:23 +0000 |
commit | fe93af445598a7d42615ce8a0e7c9d8d0f862ac1 (patch) | |
tree | 1bdc7d740b6afaa190dfc2fe8b58f7e7d04d7cd6 | |
parent | 2adcac085e240c00d4b32ba11404e98be36f1ee9 (diff) | |
download | chrome-ec-fe93af445598a7d42615ce8a0e7c9d8d0f862ac1.tar.gz |
zephyr: add shim temperature sensors
Add temperature sensors shim. Use platform/ec the temperature sensors
drivers. Generate needed global variables/types: enum temp_sensor_id
and temp_sensors from dts.
Each temperature sensor type has its own compatible property to assign
a correct read function in the temp_sensor_t temp_sensors[] array.
Themrmisors has also adc property to point an ADC channel connected to
the sensor.
Enable "temps" console command and EC_CMD_TEMP_SENSOR_GET_INFO host
command.
BUG=b:174851465
BRANCH=none
TEST=build Zephyr
TEST=Run "temps" command, it should return the current temperature
measurements
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: Ie680ec0771ea3da598066eb98db80944a93daca5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2687218
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | common/temp_sensor.c | 7 | ||||
-rw-r--r-- | zephyr/CMakeLists.txt | 4 | ||||
-rw-r--r-- | zephyr/Kconfig | 1 | ||||
-rw-r--r-- | zephyr/Kconfig.temperature | 68 | ||||
-rw-r--r-- | zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml | 9 | ||||
-rw-r--r-- | zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml | 9 | ||||
-rw-r--r-- | zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml | 9 | ||||
-rw-r--r-- | zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml | 9 | ||||
-rw-r--r-- | zephyr/dts/bindings/temp/thermistor.yaml | 17 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 30 | ||||
-rw-r--r-- | zephyr/shim/include/temp_sensor/temp_sensor.h | 21 | ||||
-rw-r--r-- | zephyr/shim/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/shim/src/temp_sensors.c | 46 |
13 files changed, 231 insertions, 0 deletions
diff --git a/common/temp_sensor.c b/common/temp_sensor.c index 5428b84949..8c72f1535c 100644 --- a/common/temp_sensor.c +++ b/common/temp_sensor.c @@ -15,6 +15,10 @@ #include "timer.h" #include "util.h" +#ifdef CONFIG_ZEPHYR +#include "temp_sensor/temp_sensor.h" +#endif + int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr) { const struct temp_sensor_t *sensor; @@ -113,6 +117,8 @@ 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%%", @@ -120,6 +126,7 @@ 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/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 0fbb7b6b99..5c25a033f5 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -254,6 +254,10 @@ 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/temp_sensor.c") +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_THERMISTOR + "${PLATFORM_EC}/driver/temp_sensor/thermistor.c") zephyr_sources_ifdef(CONFIG_PLATFORM_EC_THROTTLE_AP "${PLATFORM_EC}/common/throttle_ap.c") zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TIMER "${PLATFORM_EC}/common/timer.c") diff --git a/zephyr/Kconfig b/zephyr/Kconfig index fbeda8ac4b..20a671e394 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -40,6 +40,7 @@ rsource "Kconfig.led" rsource "Kconfig.powerseq" rsource "Kconfig.motionsense" rsource "Kconfig.tasks" +rsource "Kconfig.temperature" rsource "Kconfig.usbc" # Define PLATFORM_EC_... options to enable EC features. Each Kconfig should be diff --git a/zephyr/Kconfig.temperature b/zephyr/Kconfig.temperature new file mode 100644 index 0000000000..d949c60c84 --- /dev/null +++ b/zephyr/Kconfig.temperature @@ -0,0 +1,68 @@ +# 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. + +menuconfig PLATFORM_EC_TEMP_SENSOR + bool "Temperature sensors" + help + Support for temperature sensors. Once enabled, "temps" console + command and EC_CMD_TEMP_SENSOR_GET_INFO host command are available. + +if PLATFORM_EC_TEMP_SENSOR + +config PLATFORM_EC_THERMISTOR + bool "Thermistor support" + depends on PLATFORM_EC_ADC + help + Enables support for thermistors (resistor whose resistance is + strongly dependent on temperature) as temperature-sensor type. + +config PLATFORM_EC_STEINHART_HART_3V0_22K6_47K_4050B + bool "Steinhart-hart 3V0_22K6_47K_4050B" + depends on PLATFORM_EC_THERMISTOR + help + Enables support for measuring temperature using the Steinhart-Hart + equation model and the thermistor configured with the following + circuit configuration: + -3.0V reference voltage + -22.6 kilohm fixed resistor, connected to the reference voltage + -47 kilohm thermistor reference resistance at 25 C + -4050 B-constant (thermistor sensitivity) + +config PLATFORM_EC_STEINHART_HART_3V3_13K7_47K_4050B + bool "Steinhart-hart 3V3_13K7_47K_4050B" + depends on PLATFORM_EC_THERMISTOR + help + Enables support for measuring temperature using the Steinhart-Hart + equation model and the thermistor configured with the following + circuit configuration: + -3.3V reference voltage + -13.7 kilohm fixed resistor, connected to the reference voltage + -47 kilohm thermistor reference resistance at 25 C + -4050 B-constant (thermistor sensitivity) + +config PLATFORM_EC_STEINHART_HART_3V3_30K9_47K_4050B + bool "Steinhart-hart 3V3_30K9_47K_4050B" + depends on PLATFORM_EC_THERMISTOR + help + Enables support for measuring temperature using the Steinhart-Hart + equation model and the thermistor configured with the following + circuit configuration: + -3.3V reference voltage + -30.9 kilohm fixed resistor, connected to the reference voltage + -47 kilohm thermistor reference resistance at 25 C + -4050 B-constant (thermistor sensitivity) + +config PLATFORM_EC_STEINHART_HART_3V3_51K1_47K_4050B + bool "Steinhart-hart 3V3_51K1_47K_4050B" + depends on PLATFORM_EC_THERMISTOR + default y + help + Enables support for measuring temperature using the Steinhart-Hart + equation model and the thermistor configured with the following + circuit configuration: + -3.3V reference voltage + -51.1 kilohm fixed resistor, connected to the reference voltage + -47 kilohm thermistor reference resistance at 25 C + -4050 B-constant (thermistor sensitivity) +endif # PLATFORM_EC_TEMP_SENSOR diff --git a/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml b/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml new file mode 100644 index 0000000000..fb9061c33d --- /dev/null +++ b/zephyr/dts/bindings/temp/temp-3v0-22k6-47k-4050b.yaml @@ -0,0 +1,9 @@ +# 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. + +description: Thermistor 3v0-22k6-47k-4050b + +compatible: "temp-3v0-22k6-47k-4050b" + +include: 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 new file mode 100644 index 0000000000..325fcac8f1 --- /dev/null +++ b/zephyr/dts/bindings/temp/temp-3v3-13k7-47k-4050b.yaml @@ -0,0 +1,9 @@ +# 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. + +description: Thermistor 3v3-13k7-47k-4050b + +compatible: "temp-3v3-13k7-47k-4050b" + +include: 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 new file mode 100644 index 0000000000..99ab1cc015 --- /dev/null +++ b/zephyr/dts/bindings/temp/temp-3v3-30k9-47k-4050b.yaml @@ -0,0 +1,9 @@ +# 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. + +description: Thermistor 3v3-30k9-47k-4050b + +compatible: "temp-3v3-30k9-47k-4050b" + +include: 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 new file mode 100644 index 0000000000..6f54f98eb2 --- /dev/null +++ b/zephyr/dts/bindings/temp/temp-3v3-51k1-47k-4050b.yaml @@ -0,0 +1,9 @@ +# 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. + +description: Thermistor 3v3-51k1-47k-4050b + +compatible: "temp-3v3-51k1-47k-4050b" + +include: thermistor.yaml diff --git a/zephyr/dts/bindings/temp/thermistor.yaml b/zephyr/dts/bindings/temp/thermistor.yaml new file mode 100644 index 0000000000..6d53cdbff3 --- /dev/null +++ b/zephyr/dts/bindings/temp/thermistor.yaml @@ -0,0 +1,17 @@ +# 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. + +description: Thermistor properties + +properties: + label: + required: true + type: string + description: + Human-readable string describing the device (used as + device_get_binding() argument) + adc: + required: true + type: phandle + description: named-adc child node connected to the thermistor diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 502989d581..4298c5651d 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -282,6 +282,36 @@ enum battery_type { #define CONFIG_CMD_ADC #endif +#undef CONFIG_TEMP_SENSOR +#ifdef CONFIG_PLATFORM_EC_TEMP_SENSOR +#define CONFIG_TEMP_SENSOR +#endif + +#undef CONFIG_THERMISTOR +#ifdef CONFIG_PLATFORM_EC_THERMISTOR +#define CONFIG_THERMISTOR +#endif + +#undef CONFIG_STEINHART_HART_3V0_22K6_47K_4050B +#ifdef CONFIG_PLATFORM_EC_STEINHART_HART_3V0_22K6_47K_4050B +#define CONFIG_STEINHART_HART_3V0_22K6_47K_4050B +#endif + +#undef CONFIG_STEINHART_HART_3V3_13K7_47K_4050B +#ifdef CONFIG_PLATFORM_EC_STEINHART_HART_3V3_13K7_47K_4050B +#define CONFIG_STEINHART_HART_3V3_13K7_47K_4050B +#endif + +#undef CONFIG_STEINHART_HART_3V3_30K9_47K_4050B +#ifdef CONFIG_PLATFORM_EC_STEINHART_HART_3V3_30K9_47K_4050B +#define CONFIG_STEINHART_HART_3V3_30K9_47K_4050B +#endif + +#undef CONFIG_STEINHART_HART_3V3_51K1_47K_4050B +#ifdef CONFIG_PLATFORM_EC_STEINHART_HART_3V3_51K1_47K_4050B +#define CONFIG_STEINHART_HART_3V3_51K1_47K_4050B +#endif + #ifdef CONFIG_PLATFORM_EC_I2C /* Also see shim/include/i2c/i2c.h which defines the ports enum */ #define CONFIG_I2C diff --git a/zephyr/shim/include/temp_sensor/temp_sensor.h b/zephyr/shim/include/temp_sensor/temp_sensor.h new file mode 100644 index 0000000000..020d622ae1 --- /dev/null +++ b/zephyr/shim/include/temp_sensor/temp_sensor.h @@ -0,0 +1,21 @@ +/* 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. + */ + +#ifndef ZEPHYR_SHIM_INCLUDE_TEMP_SENSOR_TEMP_SENSOR_H_ +#define ZEPHYR_SHIM_INCLUDE_TEMP_SENSOR_TEMP_SENSOR_H_ + +#include <devicetree.h> + +#ifdef CONFIG_PLATFORM_EC_TEMP_SENSOR +#define NODE_ID_AND_COMMA(node_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) +#endif /* named_temp_sensors */ + TEMP_SENSOR_COUNT +}; +#endif /* CONFIG_PLATFORM_EC_TEMP_SENSOR */ + +#endif /* ZEPHYR_SHIM_INCLUDE_TEMP_SENSOR_TEMP_SENSOR_H_ */ diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt index a6a0670b19..aba067bca7 100644 --- a/zephyr/shim/src/CMakeLists.txt +++ b/zephyr/shim/src/CMakeLists.txt @@ -27,6 +27,7 @@ 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_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/temp_sensors.c b/zephyr/shim/src/temp_sensors.c new file mode 100644 index 0000000000..c43dfd8082 --- /dev/null +++ b/zephyr/shim/src/temp_sensors.c @@ -0,0 +1,46 @@ +/* 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 "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_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) +}; + +#endif /* named_temp_sensors */ |