diff options
author | Diana Z <dzigterman@chromium.org> | 2021-12-14 15:54:28 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-16 17:56:23 +0000 |
commit | 6917761262746150a2136fef852e7a9369970585 (patch) | |
tree | 5d99d73c2e190dc76b1a1919ceecc737855a3358 | |
parent | 51da72512a68c5dee507c9cf659f1234ff788f3a (diff) | |
download | chrome-ec-6917761262746150a2136fef852e7a9369970585.tar.gz |
Zephyr: Add TMP112 device tree support
Add support to the device tree parsing and definition for the TMP112
i2c temperature sensors.
BRANCH=None
BUG=b:195137794
TEST=zmake testall
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I62d2c60962e4b831f3073c2037ca20db4f32bafa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3340223
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/dts/bindings/temp/cros_ec_temp_sensor_tmp112.yaml | 35 | ||||
-rw-r--r-- | zephyr/shim/include/temp_sensor/temp_sensor.h | 15 | ||||
-rw-r--r-- | zephyr/shim/src/temp_sensors.c | 29 |
3 files changed, 78 insertions, 1 deletions
diff --git a/zephyr/dts/bindings/temp/cros_ec_temp_sensor_tmp112.yaml b/zephyr/dts/bindings/temp/cros_ec_temp_sensor_tmp112.yaml new file mode 100644 index 0000000000..0cf05f48a0 --- /dev/null +++ b/zephyr/dts/bindings/temp/cros_ec_temp_sensor_tmp112.yaml @@ -0,0 +1,35 @@ +# 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: > + Properties for a TMP112 I2C temperature sensor + +include: cros_ec_temp_sensor.yaml + +compatible: cros-ec,temp-sensor-tmp112 + +properties: + tmp112-name: + type: string + required: true + description: + Enum value to index into the TMP112 specific sensors + enum: + - TMP112_SOC + - TMP112_AMB + + port: + required: true + type: phandle + description: phandle to the named i2c port + + i2c-addr-flags: + required: true + type: string + description: I2C address of chip + enum: + - TMP112_I2C_ADDR_FLAGS0 + - TMP112_I2C_ADDR_FLAGS1 + - TMP112_I2C_ADDR_FLAGS2 + - TMP112_I2C_ADDR_FLAGS3 diff --git a/zephyr/shim/include/temp_sensor/temp_sensor.h b/zephyr/shim/include/temp_sensor/temp_sensor.h index b0cadd4303..ef68cc5aa9 100644 --- a/zephyr/shim/include/temp_sensor/temp_sensor.h +++ b/zephyr/shim/include/temp_sensor/temp_sensor.h @@ -23,6 +23,21 @@ enum temp_sensor_id { #undef TEMP_SENSOR_ID_WITH_COMMA +/* TMP112 access array */ +#define ZSHIM_TMP112_SENSOR_ID(node_id) DT_STRING_UPPER_TOKEN(node_id, \ + tmp112_name) +#define TMP112_SENSOR_ID_WITH_COMMA(node_id) ZSHIM_TMP112_SENSOR_ID(node_id), + +enum tmp112_sensor { +#if DT_HAS_COMPAT_STATUS_OKAY(cros_ec_temp_sensor_tmp112) + DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor_tmp112, + TMP112_SENSOR_ID_WITH_COMMA) +#endif + TMP112_COUNT, +}; + +#undef TMP112_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 524270e35a..a8533202fa 100644 --- a/zephyr/shim/src/temp_sensors.c +++ b/zephyr/shim/src/temp_sensors.c @@ -3,10 +3,11 @@ * found in the LICENSE file. */ +#include "adc.h" #include "temp_sensor.h" #include "temp_sensor/temp_sensor.h" -#include "adc.h" #include "temp_sensor/thermistor.h" +#include "temp_sensor/tmp112.h" #if DT_NODE_EXISTS(DT_PATH(named_temp_sensors)) static int thermistor_get_temp(const struct temp_sensor_t *sensor, @@ -46,7 +47,33 @@ static int thermistor_get_temp(const struct temp_sensor_t *sensor, DT_FOREACH_STATUS_OKAY(cros_ec_thermistor, DEFINE_THERMISTOR_DATA) +#if DT_HAS_COMPAT_STATUS_OKAY(cros_ec_temp_sensor_tmp112) +static int tmp112_get_temp(const struct temp_sensor_t *sensor, int *temp_ptr) +{ + return tmp112_get_val_k(sensor->idx, temp_ptr); +} +#endif /* cros_ec_temp_sensor_tmp112 */ + +#define DEFINE_TMP112_DATA(node_id) \ + [ZSHIM_TMP112_SENSOR_ID(node_id)] = { \ + .i2c_port = I2C_PORT(DT_PHANDLE(node_id, port)), \ + .i2c_addr_flags = DT_STRING_TOKEN(node_id, i2c_addr_flags), \ + }, + +#define TEMP_TMP112(node_id) \ + [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \ + .name = DT_LABEL(node_id), \ + .read = tmp112_get_temp, \ + .idx = ZSHIM_TMP112_SENSOR_ID(node_id), \ + .type = TEMP_SENSOR_TYPE_BOARD, \ + }, + +const struct tmp112_sensor_t tmp112_sensors[TMP112_COUNT] = { + DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor_tmp112, DEFINE_TMP112_DATA) +}; + const struct temp_sensor_t temp_sensors[] = { DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor_thermistor, TEMP_THERMISTOR) + DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor_tmp112, TEMP_TMP112) }; #endif /* named_temp_sensors */ |