diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2022-09-07 08:24:56 +0200 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-20 08:21:48 +0000 |
commit | a95526e34496644c0af54f09ce2de82a1f2661fc (patch) | |
tree | 9860255c5a633ffd3d2a9642292bdb6694c383bb | |
parent | a5e6358f2f5ec41fce1665916d2e88aea0d44bc6 (diff) | |
download | chrome-ec-a95526e34496644c0af54f09ce2de82a1f2661fc.tar.gz |
zephyr: rework temperature sensors
Rework how the temperature sensors are presented in dts files.
A temperature sensor has to be declared independently from the
named-temp-sensors node. The sensor nodes have to specify all
properties that are handled by driver- i2c port/address, used adc
channel etc. Children nodes of the named-temp-sensors set meta values
needed for EC code like enum-names, power-good-pin and temperature
thresholds. Also, every child node has a pointer to a physical
temperature sensor.
It implicates a different way of indexing the temperature sensors.
This change is done to separate defining physical sensors from metadata
for EC application and move some sensors onto i2c buses
BUG=b:240619570
TEST=zmake build -a && ./twister -T zephyr/test/ &&
make sure temperature sensors work with the "temps" EC CC
BRANCH=main
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: Ia0dfc0b98455e8e28233c17d5feff27a7cc5b96d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3879364
Commit-Queue: Dawid Niedzwiecki <dawidn@google.com>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Keith Short <keithshort@chromium.org>
39 files changed, 749 insertions, 555 deletions
diff --git a/docs/zephyr/zephyr_temperature_sensor.md b/docs/zephyr/zephyr_temperature_sensor.md index e1865a2f2b..8ee87a84f7 100644 --- a/docs/zephyr/zephyr_temperature_sensor.md +++ b/docs/zephyr/zephyr_temperature_sensor.md @@ -74,21 +74,26 @@ on Zephyr-based boards. ## Device Tree Nodes -Temperature sensors are declared in a `named-temp-sensors section` in the device -tree. This example is from [zephyr/boards/arm/brya/brya.dts](../../zephyr/boards/arm/brya/brya.dts): +Temperature sensors are declared as separate nodes and additional properties are +defined by the `cros-ec,temp-sensors` node in the device tree. This example is +from [zephyr/projects/brya/temp_sensors.dts](../../zephyr/projects/brya/temp_sensors.dts): ``` + temp_ddr_soc: ddr_soc { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_ddr_soc>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; ddr_soc { - compatible = "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_1_DDR_SOC"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_ddr_soc>; + sensor = <&temp_ddr_soc>; }; ``` diff --git a/include/temp_sensor.h b/include/temp_sensor.h index 088160d1c9..469d4d4764 100644 --- a/include/temp_sensor.h +++ b/include/temp_sensor.h @@ -38,7 +38,7 @@ struct temp_sensor_t { * to all use OO style sensor argument to get adc idx. */ #ifdef CONFIG_ZEPHYR - struct zephyr_temp_sensor *zephyr_info; + const struct zephyr_temp_sensor *zephyr_info; #else /* Read sensor value in K into temp_ptr; return non-zero if error. */ int (*read)(int idx, int *temp_ptr); diff --git a/zephyr/dts/bindings/charger/richtek,rt9490.yaml b/zephyr/dts/bindings/charger/richtek,rt9490.yaml index 8335083277..ecd25696f3 100644 --- a/zephyr/dts/bindings/charger/richtek,rt9490.yaml +++ b/zephyr/dts/bindings/charger/richtek,rt9490.yaml @@ -7,3 +7,8 @@ description: Richtek RT9490 Charger compatible: "richtek,rt9490" include: chg-chip.yaml + +properties: + thermistor: + type: phandle + description: Underlying thermistor device to measure temperature diff --git a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-sb-tsi.yaml b/zephyr/dts/bindings/temp/amd,sb-tsi.yaml index 6e73d95e7b..f99c01081a 100644 --- a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-sb-tsi.yaml +++ b/zephyr/dts/bindings/temp/amd,sb-tsi.yaml @@ -5,12 +5,6 @@ description: > Properties for an Side Band Temperature Sensor Interface sensor -include: cros-ec,temp-sensor.yaml +compatible: "amd,sb-tsi" -compatible: "cros-ec,temp-sensor-sb-tsi" - -properties: - port: - required: true - type: phandle - description: phandle to the sensor's i2c port +include: i2c-device.yaml diff --git a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-pct2075.yaml b/zephyr/dts/bindings/temp/cros-ec,temp-sensor-pct2075.yaml deleted file mode 100644 index dba35d36bc..0000000000 --- a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-pct2075.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2022 The ChromiumOS Authors -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -description: > - Properties for a PCT2075 I2C temperature sensor - -include: cros-ec,temp-sensor.yaml - -compatible: "cros-ec,temp-sensor-pct2075" - -properties: - pct2075-name: - type: string - required: true - description: - Enum value to index into the PCT2075 specific sensors - enum: - - PCT2075_SOC - - PCT2075_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: - - PCT2075_I2C_ADDR_FLAGS0 - - PCT2075_I2C_ADDR_FLAGS1 - - PCT2075_I2C_ADDR_FLAGS2 - - PCT2075_I2C_ADDR_FLAGS3 - - PCT2075_I2C_ADDR_FLAGS4 - - PCT2075_I2C_ADDR_FLAGS5 - - PCT2075_I2C_ADDR_FLAGS6 - - PCT2075_I2C_ADDR_FLAGS7 diff --git a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-rt9490.yaml b/zephyr/dts/bindings/temp/cros-ec,temp-sensor-rt9490.yaml deleted file mode 100644 index 9e5af0dde3..0000000000 --- a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-rt9490.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2022 The ChromiumOS Authors -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -description: > - Properties for a thermistor on RT9490 - -include: cros-ec,temp-sensor.yaml - -compatible: "cros-ec,temp-sensor-rt9490" - -properties: - port: - required: true - type: phandle - description: phandle to the named i2c port - - thermistor: - type: phandle - description: Underlying thermistor device diff --git a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-thermistor.yaml b/zephyr/dts/bindings/temp/cros-ec,temp-sensor-thermistor.yaml index eb2abe4eef..958dbd79e9 100644 --- a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-thermistor.yaml +++ b/zephyr/dts/bindings/temp/cros-ec,temp-sensor-thermistor.yaml @@ -5,8 +5,6 @@ description: > Properties for a thermistor temperature sensor -include: cros-ec,temp-sensor.yaml - compatible: "cros-ec,temp-sensor-thermistor" properties: diff --git a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-tmp112.yaml b/zephyr/dts/bindings/temp/cros-ec,temp-sensor-tmp112.yaml index 25771bc7c6..43ab9386c9 100644 --- a/zephyr/dts/bindings/temp/cros-ec,temp-sensor-tmp112.yaml +++ b/zephyr/dts/bindings/temp/cros-ec,temp-sensor-tmp112.yaml @@ -5,31 +5,6 @@ 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 +include: i2c-device.yaml diff --git a/zephyr/dts/bindings/temp/cros-ec,temp-sensor.yaml b/zephyr/dts/bindings/temp/cros-ec,temp-sensors.yaml index 934529bc5e..66c5bc955a 100644 --- a/zephyr/dts/bindings/temp/cros-ec,temp-sensor.yaml +++ b/zephyr/dts/bindings/temp/cros-ec,temp-sensors.yaml @@ -3,36 +3,20 @@ # found in the LICENSE file. description: > - Common properties for temperature sensors + Common properties for temperature sensors that are not handled by drivers. Zero values in degrees K(-273 in degrees C)in thermal thresholds will be ignored -compatible: "cros-ec,temp-sensor" +compatible: "cros-ec,temp-sensors" -properties: - enum-name: - type: string +child-binding: + description: Named temperature sensor node + properties: + sensor: + type: phandle required: true description: - Enum values used in the source code to refer to the temperature sensors - enum: - - TEMP_SENSOR_1 - - TEMP_SENSOR_2 - - TEMP_SENSOR_3 - - TEMP_SENSOR_4 - - TEMP_SENSOR_AMB - - TEMP_SENSOR_CHARGER - - TEMP_SENSOR_CPU - - TEMP_SENSOR_DDR_SOC - - TEMP_SENSOR_FAN - - TEMP_SENSOR_MEMORY - - TEMP_SENSOR_PP3300_REGULATOR - - TEMP_SENSOR_PP5000_REGULATOR - - TEMP_SENSOR_SOC - - TEMP_SENSOR_1_DDR_SOC - - TEMP_SENSOR_2_AMBIENT - - TEMP_SENSOR_3_CHARGER - - TEMP_SENSOR_4_WWAN + A pointer to a coresponding temperature sensor node. power-good-pin: type: phandle diff --git a/zephyr/dts/bindings/temp/nxp,pct2075.yaml b/zephyr/dts/bindings/temp/nxp,pct2075.yaml new file mode 100644 index 0000000000..bca7f7125b --- /dev/null +++ b/zephyr/dts/bindings/temp/nxp,pct2075.yaml @@ -0,0 +1,10 @@ +# Copyright 2021 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +description: > + Properties for a PCT2075 I2C temperature sensor + +compatible: "nxp,pct2075" + +include: i2c-device.yaml diff --git a/zephyr/projects/brya/temp_sensors.dts b/zephyr/projects/brya/temp_sensors.dts index 53025785d4..ae436a2c6b 100644 --- a/zephyr/projects/brya/temp_sensors.dts +++ b/zephyr/projects/brya/temp_sensors.dts @@ -6,54 +6,66 @@ #include <cros/thermistor/thermistor.dtsi> / { + temp_ddr_soc: ddr_soc { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_ddr_soc>; + }; + + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_ambient>; + }; + + temp_charger: charger { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_charger>; + }; + + temp_wwan: wwan { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_wwan>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; ddr_soc { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_1_DDR_SOC"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_ddr_soc>; + sensor = <&temp_ddr_soc>; }; + ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_2_AMBIENT"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_ambient>; + sensor = <&temp_ambient>; }; + charger { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_3_CHARGER"; temp_fan_off = <35>; temp_fan_max = <65>; temp_host_high = <105>; temp_host_halt = <120>; temp_host_release_high = <90>; - adc = <&adc_charger>; + sensor = <&temp_charger>; }; + wwan { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_4_WWAN"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <130>; temp_host_halt = <130>; temp_host_release_high = <100>; - adc = <&adc_wwan>; + sensor = <&temp_wwan>; }; }; }; diff --git a/zephyr/projects/corsola/adc_magikarp.dts b/zephyr/projects/corsola/adc_magikarp.dts index 668f6a8068..358af6f0f4 100644 --- a/zephyr/projects/corsola/adc_magikarp.dts +++ b/zephyr/projects/corsola/adc_magikarp.dts @@ -44,13 +44,16 @@ }; / { + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_NCP15WB>; + adc = <&adc_ambient>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_NCP15WB>; - enum-name = "TEMP_SENSOR_AMB"; - adc = <&adc_ambient>; + sensor = <&temp_ambient>; }; }; }; diff --git a/zephyr/projects/corsola/adc_tentacruel.dts b/zephyr/projects/corsola/adc_tentacruel.dts index 7e1dcbaf5c..1b5e849589 100644 --- a/zephyr/projects/corsola/adc_tentacruel.dts +++ b/zephyr/projects/corsola/adc_tentacruel.dts @@ -44,20 +44,19 @@ }; / { + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_NCP15WB>; + adc = <&adc_ambient>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_NCP15WB>; - enum-name = "TEMP_SENSOR_AMB"; - adc = <&adc_ambient>; + sensor = <&temp_ambient>; }; - charger { - compatible = "cros-ec,temp-sensor-rt9490", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_rt9490>; - enum-name = "TEMP_SENSOR_CHARGER"; - port = <&i2c_charger>; + temp_charger: charger { + sensor = <&charger>; }; }; }; diff --git a/zephyr/projects/corsola/i2c_krabby.dts b/zephyr/projects/corsola/i2c_krabby.dts index 60ed7e9bd7..4b3c46ffe4 100644 --- a/zephyr/projects/corsola/i2c_krabby.dts +++ b/zephyr/projects/corsola/i2c_krabby.dts @@ -5,6 +5,14 @@ #include "i2c_krabby_tentacruel.dtsi" +&i2c0 { + charger: rt9490@53 { + compatible = "richtek,rt9490"; + status = "okay"; + reg = <0x53>; + }; +}; + &i2c4 { tusb1064_mux_1: tusb1064-mux-1@44 { compatible = "ti,tusb1064"; diff --git a/zephyr/projects/corsola/i2c_krabby_tentacruel.dtsi b/zephyr/projects/corsola/i2c_krabby_tentacruel.dtsi index beee4a9e4e..377eaafbca 100644 --- a/zephyr/projects/corsola/i2c_krabby_tentacruel.dtsi +++ b/zephyr/projects/corsola/i2c_krabby_tentacruel.dtsi @@ -54,12 +54,6 @@ &i2c0_data_gpb4_default>; pinctrl-names = "default"; - charger: rt9490@53 { - compatible = "richtek,rt9490"; - status = "okay"; - reg = <0x53>; - }; - cbi_eeprom: eeprom@50 { compatible = "atmel,at24"; reg = <0x50>; diff --git a/zephyr/projects/corsola/i2c_magikarp.dts b/zephyr/projects/corsola/i2c_magikarp.dts index 84e2363f68..2039398974 100644 --- a/zephyr/projects/corsola/i2c_magikarp.dts +++ b/zephyr/projects/corsola/i2c_magikarp.dts @@ -5,6 +5,14 @@ #include "i2c_krabby_tentacruel.dtsi" +&i2c0 { + charger: rt9490@53 { + compatible = "richtek,rt9490"; + status = "okay"; + reg = <0x53>; + }; +}; + &i2c4 { ps8743_mux_1: ps8743-mux-1@10 { compatible = "parade,ps8743"; diff --git a/zephyr/projects/corsola/i2c_tentacruel.dts b/zephyr/projects/corsola/i2c_tentacruel.dts index ceb1ed1c3a..e40dc02318 100644 --- a/zephyr/projects/corsola/i2c_tentacruel.dts +++ b/zephyr/projects/corsola/i2c_tentacruel.dts @@ -5,6 +5,15 @@ #include "i2c_krabby_tentacruel.dtsi" +&i2c0 { + charger: rt9490@53 { + compatible = "richtek,rt9490"; + status = "okay"; + reg = <0x53>; + thermistor = <&thermistor_rt9490>; + }; +}; + &i2c2 { bc12_port0: pi3usb9201@5f { compatible = "pericom,pi3usb9201"; diff --git a/zephyr/projects/corsola/src/krabby/temp_tentacruel.c b/zephyr/projects/corsola/src/krabby/temp_tentacruel.c index de7aa78d98..53a8312be6 100644 --- a/zephyr/projects/corsola/src/krabby/temp_tentacruel.c +++ b/zephyr/projects/corsola/src/krabby/temp_tentacruel.c @@ -29,7 +29,7 @@ static int average_tempature(void) static int avg_temp; int cur_temp, t; - temp_sensor_read(TEMP_SENSOR_CHARGER, &t); + temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL(temp_charger)), &t); cur_temp = K_TO_C(t); past_temp = temp_history_buffer[buff_ptr]; temp_history_buffer[buff_ptr] = cur_temp; diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_npcx/temp_sensor.dts b/zephyr/projects/intelrvp/adlrvp/adlrvp_npcx/temp_sensor.dts index 95d462bd75..93ecaa02f6 100644 --- a/zephyr/projects/intelrvp/adlrvp/adlrvp_npcx/temp_sensor.dts +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_npcx/temp_sensor.dts @@ -6,18 +6,36 @@ #include <cros/thermistor/thermistor.dtsi> / { + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V0_22K6_47K_4050B>; + adc = <&adc_ambient>; + }; + temp_ddr: ddr { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V0_22K6_47K_4050B>; + adc = <&adc_ddr>; + }; + temp_skin: skin { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V0_22K6_47K_4050B>; + adc = <&adc_skin>; + }; + temp_vr: vr { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V0_22K6_47K_4050B>; + adc = <&adc_vr>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V0_22K6_47K_4050B>; - enum-name = "TEMP_SENSOR_1"; temp_fan_off = <15>; temp_fan_max = <50>; temp_host_high = <75>; temp_host_halt = <80>; temp_host_release_high = <65>; - adc = <&adc_ambient>; + sensor = <&temp_ambient>; }; /* @@ -40,40 +58,28 @@ */ ddr { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V0_22K6_47K_4050B>; - enum-name = "TEMP_SENSOR_2"; temp_fan_off = <15>; temp_fan_max = <50>; temp_host_high = <75>; temp_host_halt = <80>; temp_host_release_high = <65>; - adc = <&adc_ddr>; + sensor = <&temp_ddr>; }; skin { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V0_22K6_47K_4050B>; - enum-name = "TEMP_SENSOR_3"; temp_fan_off = <15>; temp_fan_max = <50>; temp_host_high = <75>; temp_host_halt = <80>; temp_host_release_high = <65>; - adc = <&adc_skin>; + sensor = <&temp_skin>; }; vr { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V0_22K6_47K_4050B>; - enum-name = "TEMP_SENSOR_4"; temp_fan_off = <15>; temp_fan_max = <50>; temp_host_high = <75>; temp_host_halt = <80>; temp_host_release_high = <65>; - adc = <&adc_vr>; + sensor = <&temp_vr>; }; }; }; diff --git a/zephyr/projects/nissa/craask/overlay.dts b/zephyr/projects/nissa/craask/overlay.dts index 3c54941e9c..4dab00610c 100644 --- a/zephyr/projects/nissa/craask/overlay.dts +++ b/zephyr/projects/nissa/craask/overlay.dts @@ -146,45 +146,50 @@ gpio-en-sub-s5-rails = &gpio_sb_2; }; + temp_memory: memory { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_1>; + }; + temp_charger: charger { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_2>; + }; + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_3>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; memory { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_1"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_1>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_memory>; }; charger { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_2"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_2>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_charger>; }; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_3"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_3>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_ambient>; }; }; diff --git a/zephyr/projects/nissa/joxer/overlay.dts b/zephyr/projects/nissa/joxer/overlay.dts index e0b7422edd..a72072b5a3 100644 --- a/zephyr/projects/nissa/joxer/overlay.dts +++ b/zephyr/projects/nissa/joxer/overlay.dts @@ -172,45 +172,50 @@ gpio-en-sub-s5-rails = &gpio_sb_2; }; + temp_memory: memory { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_1>; + }; + temp_charger: charger { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_2>; + }; + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_3>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; memory { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_1"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_1>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_memory>; }; charger { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_CHARGER"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_2>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_charger>; }; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_AMB"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_3>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_ambient>; }; }; diff --git a/zephyr/projects/nissa/nereid/overlay.dts b/zephyr/projects/nissa/nereid/overlay.dts index a6fab925d8..76f6b197be 100644 --- a/zephyr/projects/nissa/nereid/overlay.dts +++ b/zephyr/projects/nissa/nereid/overlay.dts @@ -143,45 +143,50 @@ gpio-en-sub-s5-rails = &gpio_sb_2; }; + temp_memory: memory { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_1>; + }; + temp_charger: charger { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_2>; + }; + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_3>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; memory { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_1"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_1>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_memory>; }; charger { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_CHARGER"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_2>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_charger>; }; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_AMB"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_3>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_ambient>; }; }; diff --git a/zephyr/projects/nissa/nivviks/overlay.dts b/zephyr/projects/nissa/nivviks/overlay.dts index bb32f098e8..a6a256de3f 100644 --- a/zephyr/projects/nissa/nivviks/overlay.dts +++ b/zephyr/projects/nissa/nivviks/overlay.dts @@ -147,45 +147,50 @@ gpio-en-sub-s5-rails = &gpio_sb_2; }; + temp_memory: memory { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_1>; + }; + temp_charger: charger { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_2>; + }; + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_3>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; memory { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_1"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_1>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_memory>; }; charger { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_2"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_2>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_charger>; }; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_3"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_3>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_ambient>; }; }; diff --git a/zephyr/projects/nissa/pujjo/overlay.dts b/zephyr/projects/nissa/pujjo/overlay.dts index 943da4128d..60b3b60003 100644 --- a/zephyr/projects/nissa/pujjo/overlay.dts +++ b/zephyr/projects/nissa/pujjo/overlay.dts @@ -137,45 +137,50 @@ gpio-en-sub-s5-rails = &gpio_sb_2; }; + temp_cpu: cpu { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_1>; + }; + temp_ddr: ddr { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_2>; + }; + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_3>; + }; + named-temp-sensors { - CPU { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_1"; + compatible = "cros-ec,temp-sensors"; + cpu { temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <90>; temp_host_halt = <100>; temp_host_release_high = <85>; - adc = <&adc_temp_sensor_1>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_cpu>; }; - DDR { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_2"; + ddr { temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <90>; temp_host_halt = <100>; temp_host_release_high = <85>; - adc = <&adc_temp_sensor_2>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_ddr>; }; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_3"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <90>; temp_host_halt = <100>; temp_host_release_high = <85>; - adc = <&adc_temp_sensor_3>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_ambient>; }; }; diff --git a/zephyr/projects/nissa/xivu/overlay.dts b/zephyr/projects/nissa/xivu/overlay.dts index 2c7f685502..0a30a46457 100644 --- a/zephyr/projects/nissa/xivu/overlay.dts +++ b/zephyr/projects/nissa/xivu/overlay.dts @@ -128,54 +128,60 @@ gpio-en-sub-s5-rails = &gpio_sb_2; }; + temp_memory: memory { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_1>; + }; + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_2>; + }; + temp_charger1: charger1 { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_3>; + }; + temp_charger2: charger2 { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_4>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; memory { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_1"; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; temp_host_release_halt = <80>; - adc = <&adc_temp_sensor_1>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_memory>; }; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_2"; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; temp_host_release_halt = <80>; - adc = <&adc_temp_sensor_2>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_ambient>; }; charger1 { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_3"; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; temp_host_release_halt = <80>; - adc = <&adc_temp_sensor_3>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_charger1>; }; charger2 { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_4"; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; temp_host_release_halt = <80>; - adc = <&adc_temp_sensor_4>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_charger2>; }; }; diff --git a/zephyr/projects/nissa/yaviks/overlay.dts b/zephyr/projects/nissa/yaviks/overlay.dts index d425049c80..301aaaa020 100644 --- a/zephyr/projects/nissa/yaviks/overlay.dts +++ b/zephyr/projects/nissa/yaviks/overlay.dts @@ -136,45 +136,50 @@ gpio-en-sub-s5-rails = &gpio_sb_2; }; + temp_cpu: cpu { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_1>; + }; + temp_5v_regulator: 5v_regulator { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_2>; + }; + temp_charger: charger { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_temp_sensor_3>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; cpu { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_CPU"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_1>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_cpu>; }; 5v_regulator { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_PP5000_REGULATOR"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_2>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_5v_regulator>; }; charger { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_51K1_47K_4050B>; - enum-name = "TEMP_SENSOR_CHARGER"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_temp_sensor_3>; power-good-pin = <&gpio_ec_soc_dsw_pwrok>; + sensor = <&temp_charger>; }; }; diff --git a/zephyr/projects/rex/temp_sensors.dts b/zephyr/projects/rex/temp_sensors.dts index 53025785d4..680ebc8954 100644 --- a/zephyr/projects/rex/temp_sensors.dts +++ b/zephyr/projects/rex/temp_sensors.dts @@ -6,54 +6,60 @@ #include <cros/thermistor/thermistor.dtsi> / { + temp_ddr_soc: ddr_soc { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_ddr_soc>; + }; + temp_ambient: ambient { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_ambient>; + }; + temp_charger: charger { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_charger>; + }; + temp_wwan: wwan { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_wwan>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; ddr_soc { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_1_DDR_SOC"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_ddr_soc>; + sensor = <&temp_ddr_soc>; }; ambient { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_2_AMBIENT"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <85>; temp_host_halt = <90>; temp_host_release_high = <80>; - adc = <&adc_ambient>; + sensor = <&temp_ambient>; }; charger { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_3_CHARGER"; temp_fan_off = <35>; temp_fan_max = <65>; temp_host_high = <105>; temp_host_halt = <120>; temp_host_release_high = <90>; - adc = <&adc_charger>; + sensor = <&temp_charger>; }; wwan { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_4_WWAN"; temp_fan_off = <35>; temp_fan_max = <60>; temp_host_high = <130>; temp_host_halt = <130>; temp_host_release_high = <100>; - adc = <&adc_wwan>; + sensor = <&temp_wwan>; }; }; }; diff --git a/zephyr/projects/skyrim/adc.dts b/zephyr/projects/skyrim/adc.dts index e6f57b39fd..0f2ffd6436 100644 --- a/zephyr/projects/skyrim/adc.dts +++ b/zephyr/projects/skyrim/adc.dts @@ -27,39 +27,43 @@ }; }; + temp_charger_thermistor: charger-thermistor { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_temp_charger>; + }; + + temp_memory_thermistor: memory-thermistor { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_temp_memory>; + }; + named-temp-sensors { + compatible = "cros-ec,temp-sensors"; charger-thermistor { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_CHARGER"; temp_host_high = <100>; temp_host_halt = <105>; temp_host_release_high = <80>; - adc = <&adc_temp_charger>; + sensor = <&temp_charger_thermistor>; }; + memory-thermistor { - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - thermistor = <&thermistor_3V3_30K9_47K_4050B>; - enum-name = "TEMP_SENSOR_MEMORY"; temp_host_high = <100>; temp_host_halt = <105>; temp_host_release_high = <80>; - adc = <&adc_temp_memory>; power-good-pin = <&gpio_pg_pwr_s5>; + sensor = <&temp_memory_thermistor>; }; + cpu { - compatible = "cros-ec,temp-sensor-sb-tsi", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_CPU"; - port = <&i2c_soc_thermal>; temp_host_high = <100>; temp_host_halt = <105>; temp_host_release_high = <80>; temp_fan_off = <60>; temp_fan_max = <90>; power-good-pin = <&gpio_s0_pgood>; + sensor = <&temp_cpu>; }; }; }; diff --git a/zephyr/projects/skyrim/i2c_common.dtsi b/zephyr/projects/skyrim/i2c_common.dtsi index 381a375cac..3d6d292d0f 100644 --- a/zephyr/projects/skyrim/i2c_common.dtsi +++ b/zephyr/projects/skyrim/i2c_common.dtsi @@ -255,6 +255,16 @@ clock-frequency = <I2C_BITRATE_FAST>; pinctrl-0 = <&i2c6_1_sda_scl_gpe3_e4>; pinctrl-names = "default"; + + soc_pct2075: soc-pct2075@48 { + compatible = "nxp,pct2075"; + reg = <0x48>; + }; + + amb_pct2075: amb-pct2075@4f { + compatible = "nxp,pct2075"; + reg = <0x4f>; + }; }; &i2c_ctrl6 { @@ -267,6 +277,11 @@ clock-frequency = <I2C_BITRATE_FAST>; pinctrl-0 = <&i2c7_0_sda_scl_gpb2_b3>; pinctrl-names = "default"; + + temp_cpu: cpu@4c { + compatible = "amd,sb-tsi"; + reg = <0x4c>; + }; }; &i2c_ctrl7 { diff --git a/zephyr/projects/skyrim/morthal.dts b/zephyr/projects/skyrim/morthal.dts index 1ff2795144..b78478c331 100644 --- a/zephyr/projects/skyrim/morthal.dts +++ b/zephyr/projects/skyrim/morthal.dts @@ -11,13 +11,8 @@ }; named-temp-sensors { + compatible = "cros-ec,temp-sensors"; soc-pct2075 { - compatible = "cros-ec,temp-sensor-pct2075", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_SOC"; - pct2075-name = "PCT2075_SOC"; - port = <&i2c_sensor>; - i2c-addr-flags = "PCT2075_I2C_ADDR_FLAGS0"; temp_host_high = <100>; temp_host_halt = <105>; temp_host_release_high = <80>; @@ -25,15 +20,11 @@ temp_fan_off = <0>; temp_fan_max = <70>; power-good-pin = <&gpio_pg_pwr_s5>; + sensor = <&soc_pct2075>; }; amb-pct2075 { - compatible = "cros-ec,temp-sensor-pct2075", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_AMB"; - pct2075-name = "PCT2075_AMB"; - port = <&i2c_sensor>; - i2c-addr-flags = "PCT2075_I2C_ADDR_FLAGS7"; power-good-pin = <&gpio_pg_pwr_s5>; + sensor = <&amb_pct2075>; }; }; diff --git a/zephyr/projects/skyrim/skyrim.dts b/zephyr/projects/skyrim/skyrim.dts index ca631f21d3..1de22787bb 100644 --- a/zephyr/projects/skyrim/skyrim.dts +++ b/zephyr/projects/skyrim/skyrim.dts @@ -11,13 +11,8 @@ }; named-temp-sensors { + compatible = "cros-ec,temp-sensors"; soc-pct2075 { - compatible = "cros-ec,temp-sensor-pct2075", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_SOC"; - pct2075-name = "PCT2075_SOC"; - port = <&i2c_sensor>; - i2c-addr-flags = "PCT2075_I2C_ADDR_FLAGS0"; temp_host_high = <100>; temp_host_halt = <105>; temp_host_release_high = <80>; @@ -25,15 +20,11 @@ temp_fan_off = <35>; temp_fan_max = <70>; power-good-pin = <&gpio_pg_pwr_s5>; + sensor = <&soc_pct2075>; }; amb-pct2075 { - compatible = "cros-ec,temp-sensor-pct2075", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_AMB"; - pct2075-name = "PCT2075_AMB"; - port = <&i2c_sensor>; - i2c-addr-flags = "PCT2075_I2C_ADDR_FLAGS7"; power-good-pin = <&gpio_pg_pwr_s5>; + sensor = <&amb_pct2075>; }; }; diff --git a/zephyr/projects/skyrim/src/stt.c b/zephyr/projects/skyrim/src/stt.c index 15d5e4dbea..40743fbc68 100644 --- a/zephyr/projects/skyrim/src/stt.c +++ b/zephyr/projects/skyrim/src/stt.c @@ -14,7 +14,8 @@ int board_get_soc_temp_mk(int *temp_mk) if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) return EC_ERROR_NOT_POWERED; - return pct2075_get_val_mk(PCT2075_SOC, temp_mk); + return pct2075_get_val_mk(PCT2075_SENSOR_ID(DT_NODELABEL(soc_pct2075)), + temp_mk); } int board_get_ambient_temp_mk(int *temp_mk) @@ -22,5 +23,6 @@ int board_get_ambient_temp_mk(int *temp_mk) if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) return EC_ERROR_NOT_POWERED; - return pct2075_get_val_mk(PCT2075_AMB, temp_mk); + return pct2075_get_val_mk(PCT2075_SENSOR_ID(DT_NODELABEL(amb_pct2075)), + temp_mk); } diff --git a/zephyr/projects/skyrim/winterhold.dts b/zephyr/projects/skyrim/winterhold.dts index 298786071b..82bde53b54 100644 --- a/zephyr/projects/skyrim/winterhold.dts +++ b/zephyr/projects/skyrim/winterhold.dts @@ -11,13 +11,8 @@ }; named-temp-sensors { + compatible = "cros-ec,temp-sensors"; soc-pct2075 { - compatible = "cros-ec,temp-sensor-pct2075", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_SOC"; - pct2075-name = "PCT2075_SOC"; - port = <&i2c_sensor>; - i2c-addr-flags = "PCT2075_I2C_ADDR_FLAGS0"; temp_host_high = <100>; temp_host_halt = <105>; temp_host_release_high = <80>; @@ -25,15 +20,11 @@ temp_fan_off = <0>; temp_fan_max = <70>; power-good-pin = <&gpio_pg_pwr_s5>; + sensor = <&soc_pct2075>; }; amb-pct2075 { - compatible = "cros-ec,temp-sensor-pct2075", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_AMB"; - pct2075-name = "PCT2075_AMB"; - port = <&i2c_sensor>; - i2c-addr-flags = "PCT2075_I2C_ADDR_FLAGS7"; power-good-pin = <&gpio_pg_pwr_s5>; + sensor = <&amb_pct2075>; }; }; diff --git a/zephyr/shim/include/temp_sensor/temp_sensor.h b/zephyr/shim/include/temp_sensor/temp_sensor.h index 2aa49c5c19..9be18987eb 100644 --- a/zephyr/shim/include/temp_sensor/temp_sensor.h +++ b/zephyr/shim/include/temp_sensor/temp_sensor.h @@ -8,48 +8,133 @@ #include <zephyr/devicetree.h> #include "include/temp_sensor.h" +#include "charger/chg_rt9490.h" #ifdef CONFIG_PLATFORM_EC_TEMP_SENSOR -#define ZSHIM_TEMP_SENSOR_ID(node_id) DT_STRING_UPPER_TOKEN(node_id, enum_name) +#define PCT2075_COMPAT nxp_pct2075 +#define TMP112_COMPAT cros_ec_temp_sensor_tmp112 +#define SB_TSI_COMPAT amd_sb_tsi +#define THERMISTOR_COMPAT cros_ec_temp_sensor_thermistor +#define TEMP_SENSORS_COMPAT cros_ec_temp_sensors + +#define TEMP_SENSORS_NODEID DT_INST(0, TEMP_SENSORS_COMPAT) + +#define TEMP_RT9490_FN(node_id, fn) \ + COND_CODE_1(DT_NODE_HAS_PROP(node_id, thermistor), (fn(node_id)), ()) + +#define FOREACH_TEMP_SENSOR(fn) \ + DT_FOREACH_STATUS_OKAY(PCT2075_COMPAT, fn) \ + DT_FOREACH_STATUS_OKAY(TMP112_COMPAT, fn) \ + DT_FOREACH_STATUS_OKAY_VARGS(RT9490_CHG_COMPAT, TEMP_RT9490_FN, fn) \ + DT_FOREACH_STATUS_OKAY(SB_TSI_COMPAT, fn) \ + DT_FOREACH_STATUS_OKAY(THERMISTOR_COMPAT, fn) #define HAS_POWER_GOOD_PIN(node_id) DT_NODE_HAS_PROP(node_id, power_good_pin) || + #define ANY_INST_HAS_POWER_GOOD_PIN \ - (DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor, HAS_POWER_GOOD_PIN) 0) + (DT_FOREACH_CHILD(TEMP_SENSORS_NODEID, HAS_POWER_GOOD_PIN) 0) + +/* + * Get the enum temp_sensor_id value from a child node under + * "cros-ec,temp-sensors". + * + * Example devicetree fragment: + * + * temp_charger_thermistor: charger-thermistor { + * compatible = "cros-ec,temp-sensor-thermistor"; + * thermistor = <&thermistor_3V3_30K9_47K_4050B>; + * adc = <&adc_temp_charger>; + * }; + * + * named-temp-sensors { + * compatible = "cros-ec,temp-sensors"; + * temp_charger: charger-thermistor { + * temp_host_high = <100>; + * temp_host_halt = <105>; + * temp_host_release_high = <80>; + * sensor = <&temp_charger_thermistor>; + * }; + * }; + * + * Example usage to get the temperature sensor ID: + * + * TEMP_SENSOR_ID(DT_NODELABEL(temp_charger)) + * + * @param node_id: node id of a child of "cros-ec,temp-sensors" node + */ +#define TEMP_SENSOR_ID(node_id) DT_CAT(TEMP_SENSOR_, node_id) + +/* + * Get the enum temp_sensor_id value from a hardware device node. + * + * Example devicetree fragment: + * + * temp_charger_thermistor: charger-thermistor { + * compatible = "cros-ec,temp-sensor-thermistor"; + * thermistor = <&thermistor_3V3_30K9_47K_4050B>; + * adc = <&adc_temp_charger>; + * }; + * + * named-temp-sensors { + * compatible = "cros-ec,temp-sensors"; + * temp_charger: charger-thermistor { + * temp_host_high = <100>; + * temp_host_halt = <105>; + * temp_host_release_high = <80>; + * sensor = <&temp_charger_thermistor>; + * }; + * }; + * + * Example usage to get the temperature sensor ID: + * + * TEMP_SENSOR_ID_BY_DEV(DT_NODELABEL(temp_charger_thermistor)) + * + * which equals: + * + * TEMP_SENSOR_ID(DT_NODELABEL(temp_charger)) + * + * @param node_id: node id of a hardware device node + */ +#define TEMP_SENSOR_ID_BY_DEV(node_id) DT_CAT(TEMP_SENSOR_DEV, node_id) + +#define TEMP_SENSOR_ID_DEV(named_id) \ + TEMP_SENSOR_ID_BY_DEV(DT_PHANDLE(named_id, sensor)) = \ + TEMP_SENSOR_ID(named_id) enum temp_sensor_id { -#if DT_NODE_EXISTS(DT_PATH(named_temp_sensors)) - DT_FOREACH_CHILD_SEP(DT_PATH(named_temp_sensors), ZSHIM_TEMP_SENSOR_ID, - (, )), -#endif /* named_temp_sensors */ - TEMP_SENSOR_COUNT + DT_FOREACH_CHILD_SEP(TEMP_SENSORS_NODEID, TEMP_SENSOR_ID, (, )), + DT_FOREACH_CHILD_SEP(TEMP_SENSORS_NODEID, TEMP_SENSOR_ID_DEV, (, )), + TEMP_SENSOR_COUNT, }; /* PCT2075 access array */ -#define ZSHIM_PCT2075_SENSOR_ID(node_id) \ - DT_STRING_UPPER_TOKEN(node_id, pct2075_name) -#define PCT2075_SENSOR_ID_WITH_COMMA(node_id) ZSHIM_PCT2075_SENSOR_ID(node_id), +/* + * Get the PCT2075 sensor ID from a hardware device node. + * + * @param node_id: node id of a hardware PCT2075 sensor node + */ +#define PCT2075_SENSOR_ID(node_id) DT_CAT(PCT2075_, node_id) +#define PCT2075_SENSOR_ID_WITH_COMMA(node_id) PCT2075_SENSOR_ID(node_id), enum pct2075_sensor { -#if DT_HAS_COMPAT_STATUS_OKAY(cros_ec_temp_sensor_pct2075) - DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor_pct2075, - PCT2075_SENSOR_ID_WITH_COMMA) -#endif + DT_FOREACH_STATUS_OKAY(PCT2075_COMPAT, PCT2075_SENSOR_ID_WITH_COMMA) PCT2075_COUNT, }; #undef PCT2075_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), +/* + * Get the TMP112 sensor ID from a hardware device node. + * + * @param node_id: node id of a hardware TMP112 sensor node + */ +#define TMP112_SENSOR_ID(node_id) DT_CAT(TMP112_, node_id) +#define TMP112_SENSOR_ID_WITH_COMMA(node_id) 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 + DT_FOREACH_STATUS_OKAY(TMP112_COMPAT, TMP112_SENSOR_ID_WITH_COMMA) TMP112_COUNT, }; @@ -58,11 +143,11 @@ enum tmp112_sensor { struct zephyr_temp_sensor { /* Read sensor value in K into temp_ptr; return non-zero if error. */ int (*read)(const struct temp_sensor_t *sensor, int *temp_ptr); - struct thermistor_info *thermistor; + const struct thermistor_info *thermistor; #if ANY_INST_HAS_POWER_GOOD_PIN const struct device *power_good_dev; gpio_pin_t power_good_pin; -#endif +#endif /* ANY_INST_HAS_POWER_GOOD_PIN */ }; #endif /* CONFIG_PLATFORM_EC_TEMP_SENSOR */ diff --git a/zephyr/shim/src/temp_sensors.c b/zephyr/shim/src/temp_sensors.c index 3760e7fe57..371d7d7fc9 100644 --- a/zephyr/shim/src/temp_sensors.c +++ b/zephyr/shim/src/temp_sensors.c @@ -4,6 +4,7 @@ */ #include "adc.h" +#include "charger/chg_rt9490.h" #include "driver/charger/rt9490.h" #include "temp_sensor.h" #include "temp_sensor/pct2075.h" @@ -12,7 +13,10 @@ #include "temp_sensor/thermistor.h" #include "temp_sensor/tmp112.h" -#if DT_NODE_EXISTS(DT_PATH(named_temp_sensors)) +#if DT_HAS_COMPAT_STATUS_OKAY(TEMP_SENSORS_COMPAT) + +BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(TEMP_SENSORS_COMPAT) == 1, + "Only one temperature sensors node is allowed"); #define GET_POWER_GOOD_PROP(node_id) DT_PROP(node_id, power_good_pin) @@ -22,6 +26,19 @@ #define GET_POWER_GOOD_PIN(node_id) \ DT_GPIO_PIN(GET_POWER_GOOD_PROP(node_id), gpios) +#define POWER_GOOD_ENTRY(node_id) \ + .power_good_dev = GET_POWER_GOOD_DEV(node_id), \ + .power_good_pin = GET_POWER_GOOD_PIN(node_id), + +#define POWER_GOOD_ENTRY_NULL(node_id) \ + .power_good_dev = NULL, .power_good_pin = 0, + +#define POWER_GOOD(node_id) \ + [TEMP_SENSOR_ID(node_id)] = { COND_CODE_1( \ + DT_NODE_HAS_PROP(node_id, power_good_pin), \ + (POWER_GOOD_ENTRY(node_id)), \ + (POWER_GOOD_ENTRY_NULL(node_id))) } + #if ANY_INST_HAS_POWER_GOOD_PIN #define FILL_POWER_GOOD(node_id) \ COND_CODE_1(DT_NODE_HAS_PROP(node_id, power_good_pin), \ @@ -42,156 +59,181 @@ static int thermistor_get_temp(const struct temp_sensor_t *sensor, #define GET_THERMISTOR_DATUM(node_sample_id) \ [DT_PROP(node_sample_id, \ sample_index)] = { .mv = DT_PROP(node_sample_id, milivolt), \ - .temp = DT_PROP(node_sample_id, temp) }, + .temp = DT_PROP(node_sample_id, temp) } -#define DEFINE_THERMISTOR_DATA(node_id) \ - static const struct thermistor_data_pair DT_CAT( \ - node_id, _thermistor_data)[] = { \ - DT_FOREACH_CHILD(node_id, GET_THERMISTOR_DATUM) \ +#define DEFINE_THERMISTOR_DATA(node_id) \ + static const struct thermistor_data_pair DT_CAT( \ + node_id, _thermistor_data)[] = { \ + DT_FOREACH_CHILD_SEP(node_id, GET_THERMISTOR_DATUM, (, )) \ }; #define GET_THERMISTOR_INFO(node_id) \ - (&(struct thermistor_info){ \ + (&(const struct thermistor_info){ \ .scaling_factor = DT_PROP(node_id, scaling_factor), \ .num_pairs = DT_PROP(node_id, num_pairs), \ .data = DT_CAT(node_id, _thermistor_data), \ }) -#define GET_ZEPHYR_TEMP_SENSOR_THERMISTOR(node_id) \ - (&(struct zephyr_temp_sensor){ \ - .read = &thermistor_get_temp, \ - .thermistor = \ - GET_THERMISTOR_INFO(DT_PHANDLE(node_id, thermistor)), \ - FILL_POWER_GOOD(node_id) }) - -#define TEMP_THERMISTOR(node_id) \ - [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \ - .name = DT_NODE_FULL_NAME(node_id), \ - .idx = ZSHIM_ADC_ID(DT_PHANDLE(node_id, adc)), \ - .type = TEMP_SENSOR_TYPE_BOARD, \ - .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_THERMISTOR(node_id), \ - }, +#define GET_ZEPHYR_TEMP_SENSOR_THERMISTOR(named_id, sensor_id) \ + (&(const struct zephyr_temp_sensor){ \ + .read = &thermistor_get_temp, \ + .thermistor = GET_THERMISTOR_INFO( \ + DT_PHANDLE(sensor_id, thermistor)), \ + FILL_POWER_GOOD(named_id) }) + +#define TEMP_THERMISTOR(named_id, sensor_id) \ + [TEMP_SENSOR_ID(named_id)] = { \ + .name = DT_NODE_FULL_NAME(sensor_id), \ + .idx = ZSHIM_ADC_ID(DT_PHANDLE(sensor_id, adc)), \ + .type = TEMP_SENSOR_TYPE_BOARD, \ + .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_THERMISTOR(named_id, \ + sensor_id), \ + } DT_FOREACH_STATUS_OKAY(cros_ec_thermistor, DEFINE_THERMISTOR_DATA) -#if DT_HAS_COMPAT_STATUS_OKAY(cros_ec_temp_sensor_pct2075) -static int pct2075_get_temp(const struct temp_sensor_t *sensor, int *temp_ptr) +#if DT_HAS_COMPAT_STATUS_OKAY(PCT2075_COMPAT) +/* The function maybe unused because a temperature sensor can be added to dts + * without a reference in the cros_ec_temp_sensors node. + */ +__maybe_unused static int pct2075_get_temp(const struct temp_sensor_t *sensor, + int *temp_ptr) { return pct2075_get_val_k(sensor->idx, temp_ptr); } -#endif /* cros_ec_temp_sensor_pct2075 */ +#endif /* PCT2075_COMPAT */ -#define DEFINE_PCT2075_DATA(node_id) \ - [ZSHIM_PCT2075_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 DEFINE_PCT2075_DATA(node_id) \ + [PCT2075_SENSOR_ID(node_id)] = { \ + .i2c_port = I2C_PORT_BY_DEV(node_id), \ + .i2c_addr_flags = \ + (DT_REG_ADDR(node_id) | I2C_FLAG_BIG_ENDIAN), \ }, -#define GET_ZEPHYR_TEMP_SENSOR_PCT2075(node_id) \ - (&(struct zephyr_temp_sensor){ .read = &pct2075_get_temp, \ - .thermistor = NULL, \ - FILL_POWER_GOOD(node_id) }) - -#define TEMP_PCT2075(node_id) \ - [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \ - .name = DT_NODE_FULL_NAME(node_id), \ - .idx = ZSHIM_PCT2075_SENSOR_ID(node_id), \ - .type = TEMP_SENSOR_TYPE_BOARD, \ - .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_PCT2075(node_id), \ - }, +#define GET_ZEPHYR_TEMP_SENSOR_PCT2075(named_id) \ + (&(const struct zephyr_temp_sensor){ .read = &pct2075_get_temp, \ + .thermistor = NULL, \ + FILL_POWER_GOOD(named_id) }) + +#define TEMP_PCT2075(named_id, sensor_id) \ + [TEMP_SENSOR_ID(named_id)] = { \ + .name = DT_NODE_FULL_NAME(sensor_id), \ + .idx = PCT2075_SENSOR_ID(sensor_id), \ + .type = TEMP_SENSOR_TYPE_BOARD, \ + .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_PCT2075(named_id), \ + } const struct pct2075_sensor_t pct2075_sensors[PCT2075_COUNT] = { - DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor_pct2075, DEFINE_PCT2075_DATA) + DT_FOREACH_STATUS_OKAY(PCT2075_COMPAT, DEFINE_PCT2075_DATA) }; -#if DT_HAS_COMPAT_STATUS_OKAY(cros_ec_temp_sensor_sb_tsi) -static int sb_tsi_get_temp(const struct temp_sensor_t *sensor, int *temp_ptr) +#if DT_HAS_COMPAT_STATUS_OKAY(SB_TSI_COMPAT) +/* The function maybe unused because a temperature sensor can be added to dts + * without a reference in the cros_ec_temp_sensors node. + */ +__maybe_unused static int sb_tsi_get_temp(const struct temp_sensor_t *sensor, + int *temp_ptr) { return sb_tsi_get_val(sensor->idx, temp_ptr); } /* There can be only one SB TSI sensor with current driver */ -#if DT_NUM_INST_STATUS_OKAY(cros_ec_temp_sensor_sb_tsi) > 1 +#if DT_NUM_INST_STATUS_OKAY(SB_TSI_COMPAT) > 1 #error "Unsupported number of SB TSI sensors" #endif -#endif /* cros_ec_temp_sensor_sb_tsi */ +#endif /* SB_TSI_COMPAT */ -#define GET_ZEPHYR_TEMP_SENSOR_SB_TSI(node_id) \ - (&(struct zephyr_temp_sensor){ .read = &sb_tsi_get_temp, \ - .thermistor = NULL, \ - FILL_POWER_GOOD(node_id) }) +#define GET_ZEPHYR_TEMP_SENSOR_SB_TSI(named_id) \ + (&(const struct zephyr_temp_sensor){ .read = &sb_tsi_get_temp, \ + .thermistor = NULL, \ + FILL_POWER_GOOD(named_id) }) -#define TEMP_SB_TSI(node_id) \ - [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \ - .name = DT_NODE_FULL_NAME(node_id), \ - .idx = 0, \ - .type = TEMP_SENSOR_TYPE_CPU, \ - .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_SB_TSI(node_id), \ - }, +#define TEMP_SB_TSI(named_id, sensor_id) \ + [TEMP_SENSOR_ID(named_id)] = { \ + .name = DT_NODE_FULL_NAME(sensor_id), \ + .idx = 0, \ + .type = TEMP_SENSOR_TYPE_CPU, \ + .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_SB_TSI(named_id), \ + } -#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) +#if DT_HAS_COMPAT_STATUS_OKAY(TMP112_COMPAT) +/* The function maybe unused because a temperature sensor can be added to dts + * without a reference in the cros_ec_temp_sensors node. + */ +__maybe_unused 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 */ +#endif /* TMP112_COMPAT */ -#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 DEFINE_TMP112_DATA(node_id) \ + [TMP112_SENSOR_ID(node_id)] = { \ + .i2c_port = I2C_PORT_BY_DEV(node_id), \ + .i2c_addr_flags = DT_REG_ADDR(node_id), \ }, -#define GET_ZEPHYR_TEMP_SENSOR_TMP112(node_id) \ - (&(struct zephyr_temp_sensor){ .read = &tmp112_get_temp, \ - .thermistor = NULL, \ - FILL_POWER_GOOD(node_id) }) - -#define TEMP_TMP112(node_id) \ - [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \ - .name = DT_NODE_FULL_NAME(node_id), \ - .idx = ZSHIM_TMP112_SENSOR_ID(node_id), \ - .type = TEMP_SENSOR_TYPE_BOARD, \ - .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_TMP112(node_id), \ - }, +#define GET_ZEPHYR_TEMP_SENSOR_TMP112(named_id) \ + (&(const struct zephyr_temp_sensor){ .read = &tmp112_get_temp, \ + .thermistor = NULL, \ + FILL_POWER_GOOD(named_id) }) + +#define TEMP_TMP112(named_id, sensor_id) \ + [TEMP_SENSOR_ID(named_id)] = { \ + .name = DT_NODE_FULL_NAME(sensor_id), \ + .idx = TMP112_SENSOR_ID(sensor_id), \ + .type = TEMP_SENSOR_TYPE_BOARD, \ + .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_TMP112(named_id), \ + } const struct tmp112_sensor_t tmp112_sensors[TMP112_COUNT] = { - DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor_tmp112, DEFINE_TMP112_DATA) + DT_FOREACH_STATUS_OKAY(TMP112_COMPAT, DEFINE_TMP112_DATA) }; /* There can be only one thermistor on RT9490 with current driver */ -#if DT_NUM_INST_STATUS_OKAY(cros_ec_temp_sensor_rt9490) > 1 +#define ADD_ONE(node_id) 1 + +#if DT_FOREACH_STATUS_OKAY_VARGS(RT9490_CHG_COMPAT, TEMP_RT9490_FN, \ + ADD_ONE) 0 > 1 #error "Unsupported number of thermistor on RT9490" #endif - -#define GET_ZEPHYR_TEMP_SENSOR_RT9490(node_id) \ - (&(struct zephyr_temp_sensor){ \ - .read = &rt9490_get_thermistor_val, \ - .thermistor = \ - GET_THERMISTOR_INFO(DT_PHANDLE(node_id, thermistor)), \ - }) - -#define TEMP_RT9490(node_id) \ - [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \ - .name = DT_NODE_FULL_NAME(node_id), \ - .idx = 0, \ - .type = TEMP_SENSOR_TYPE_BOARD, \ - .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_RT9490(node_id), \ - }, - -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_pct2075, - TEMP_PCT2075) - DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor_sb_tsi, - TEMP_SB_TSI) - DT_FOREACH_STATUS_OKAY( - cros_ec_temp_sensor_tmp112, TEMP_TMP112) - DT_FOREACH_STATUS_OKAY( - cros_ec_temp_sensor_rt9490, - TEMP_RT9490) -}; +#undef ADD_ONE + +#define GET_ZEPHYR_TEMP_SENSOR_RT9490(named_id, sensor_id) \ + (&(const struct zephyr_temp_sensor){ \ + .read = &rt9490_get_thermistor_val, \ + .thermistor = GET_THERMISTOR_INFO( \ + DT_PHANDLE(sensor_id, thermistor)), \ + FILL_POWER_GOOD(named_id) }) + +#define TEMP_RT9490(named_id, sensor_id) \ + COND_CODE_1(DT_NODE_HAS_PROP(sensor_id, thermistor), ( \ + [TEMP_SENSOR_ID(named_id)] = { \ + .name = DT_NODE_FULL_NAME(sensor_id), \ + .idx = 0, \ + .type = TEMP_SENSOR_TYPE_BOARD, \ + .zephyr_info = GET_ZEPHYR_TEMP_SENSOR_RT9490(named_id, \ + sensor_id), \ + } ), ()) + +#define DT_DRV_COMPAT TEMP_SENSORS_COMPAT + +#define CHECK_COMPAT(compat, named_id, sensor_id, config_fn) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(sensor_id, compat), \ + (config_fn(named_id, sensor_id)), ()) + +#define TEMP_SENSOR_FIND(named_id, sensor_id) \ + CHECK_COMPAT(THERMISTOR_COMPAT, named_id, sensor_id, TEMP_THERMISTOR) \ + CHECK_COMPAT(PCT2075_COMPAT, named_id, sensor_id, TEMP_PCT2075) \ + CHECK_COMPAT(SB_TSI_COMPAT, named_id, sensor_id, TEMP_SB_TSI) \ + CHECK_COMPAT(TMP112_COMPAT, named_id, sensor_id, TEMP_TMP112) \ + CHECK_COMPAT(RT9490_CHG_COMPAT, named_id, sensor_id, TEMP_RT9490) + +#define TEMP_SENSOR_ENTRY(named_id) \ + TEMP_SENSOR_FIND(named_id, DT_PHANDLE(named_id, sensor)) + +const struct temp_sensor_t temp_sensors[] = { DT_FOREACH_CHILD_SEP( + TEMP_SENSORS_NODEID, TEMP_SENSOR_ENTRY, (, )) }; int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr) { @@ -212,4 +254,4 @@ int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr) return sensor->zephyr_info->read(sensor, temp_ptr); } -#endif /* named_temp_sensors */ +#endif /* DT_HAS_COMPAT_STATUS_OKAY(TEMP_SENSORS_COMPAT) */ diff --git a/zephyr/shim/src/thermal.c b/zephyr/shim/src/thermal.c index 4f6b89f2ef..abe6b7da9e 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) \ - [ZSHIM_TEMP_SENSOR_ID(node_id)] = { \ + [TEMP_SENSOR_ID(node_id)] = { \ .temp_host = { \ [EC_TEMP_THRESH_WARN] = \ C_TO_K(DT_PROP_OR(node_id, \ @@ -43,10 +43,10 @@ .temp_fan_max = C_TO_K(DT_PROP_OR(node_id, \ temp_fan_max, \ -273)), \ - }, + } 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 */ +#if DT_HAS_COMPAT_STATUS_OKAY(TEMP_SENSORS_COMPAT) + DT_FOREACH_CHILD_SEP(TEMP_SENSORS_NODEID, THERMAL_CONFIG, (, )) +#endif /* DT_HAS_COMPAT_STATUS_OKAY(TEMP_SENSORS_COMPAT) */ }; diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay index a9ee168bb4..03b59c8ac7 100644 --- a/zephyr/test/drivers/boards/native_posix.overlay +++ b/zephyr/test/drivers/boards/native_posix.overlay @@ -201,6 +201,9 @@ gpios = <&gpio1 4 GPIO_INPUT_PULL_UP>; enum-name = "GPIO_VOLUME_UP_L"; }; + gpio_ec_pg_pin_temp: ec_pg_pin_temp { + gpios = <&gpio0 4 GPIO_INPUT>; + }; }; gpio1: gpio@101 { @@ -389,58 +392,68 @@ }; }; + temp_charger: charger { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_13K7_47K_4050B>; + adc = <&adc_charger>; + }; + temp_pp3300_regulator: pp3300-regulator { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_30K9_47K_4050B>; + adc = <&adc_pp3300_regulator>; + }; + temp_ddr_soc: ddr-soc { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V3_51K1_47K_4050B>; + adc = <&adc_ddr_soc>; + }; + temp_fan: fan { + compatible = "cros-ec,temp-sensor-thermistor"; + thermistor = <&thermistor_3V0_22K6_47K_4050B>; + adc = <&adc_fan>; + }; + named-temp-sensors { - charger { - thermistor = <&thermistor_3V3_13K7_47K_4050B>; + compatible = "cros-ec,temp-sensors"; + named_temp_charger: charger { status = "okay"; - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_CHARGER"; temp_fan_off = <40>; temp_fan_max = <55>; temp_host_high = <75>; temp_host_halt = <80>; temp_host_release_high = <65>; - adc = <&adc_charger>; + power-good-pin = <&gpio_ec_pg_pin_temp>; + sensor = <&temp_charger>; }; - pp3300-regulator { - thermistor = <&thermistor_3V3_30K9_47K_4050B>; + named_temp_pp3300_regulator: pp3300-regulator { status = "okay"; - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_PP3300_REGULATOR"; temp_fan_off = <40>; temp_fan_max = <55>; temp_host_high = <75>; temp_host_halt = <80>; temp_host_release_high = <65>; - adc = <&adc_pp3300_regulator>; + power-good-pin = <&gpio_ec_pg_pin_temp>; + sensor = <&temp_pp3300_regulator>; }; - ddr-soc { - thermistor = <&thermistor_3V3_51K1_47K_4050B>; + named_temp_ddr_soc: ddr-soc { status = "okay"; - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_DDR_SOC"; temp_fan_off = <35>; temp_fan_max = <50>; temp_host_high = <70>; temp_host_halt = <80>; temp_host_release_high = <65>; - adc = <&adc_ddr_soc>; + power-good-pin = <&gpio_ec_pg_pin_temp>; + sensor = <&temp_ddr_soc>; }; - fan { - thermistor = <&thermistor_3V0_22K6_47K_4050B>; + named_temp_fan: fan { status = "okay"; - compatible = "cros-ec,temp-sensor-thermistor", - "cros-ec,temp-sensor"; - enum-name = "TEMP_SENSOR_FAN"; temp_fan_off = <35>; temp_fan_max = <50>; temp_host_high = <70>; temp_host_halt = <80>; temp_host_release_high = <65>; - adc = <&adc_fan>; + power-good-pin = <&gpio_ec_pg_pin_temp>; + sensor = <&temp_fan>; }; }; diff --git a/zephyr/test/drivers/default/src/temp_sensor.c b/zephyr/test/drivers/default/src/temp_sensor.c index ff07e2d375..5caecc556c 100644 --- a/zephyr/test/drivers/default/src/temp_sensor.c +++ b/zephyr/test/drivers/default/src/temp_sensor.c @@ -20,6 +20,9 @@ #define GPIO_PG_EC_DSW_PWROK_PATH DT_PATH(named_gpios, pg_ec_dsw_pwrok) #define GPIO_PG_EC_DSW_PWROK_PORT DT_GPIO_PIN(GPIO_PG_EC_DSW_PWROK_PATH, gpios) +#define GPIO_EC_PG_PIN_TEMP_PATH DT_PATH(named_gpios, ec_pg_pin_temp) +#define GPIO_EC_PG_PIN_TEMP_PORT DT_GPIO_PIN(GPIO_EC_PG_PIN_TEMP_PATH, gpios) + #define ADC_DEVICE_NODE DT_NODELABEL(adc0) #define ADC_CHANNELS_NUM DT_PROP(DT_NODELABEL(adc0), nchannels) @@ -49,13 +52,24 @@ ZTEST_USER(temp_sensor, test_temp_sensor_adc_error) NULL); zassert_equal(EC_ERROR_NOT_POWERED, - temp_sensor_read(TEMP_SENSOR_CHARGER, &temp), NULL); - zassert_equal(EC_ERROR_NOT_POWERED, - temp_sensor_read(TEMP_SENSOR_DDR_SOC, &temp), NULL); + temp_sensor_read( + TEMP_SENSOR_ID(DT_NODELABEL(named_temp_charger)), + &temp), + NULL); zassert_equal(EC_ERROR_NOT_POWERED, - temp_sensor_read(TEMP_SENSOR_FAN, &temp), NULL); + temp_sensor_read( + TEMP_SENSOR_ID(DT_NODELABEL(named_temp_ddr_soc)), + &temp), + NULL); + zassert_equal( + EC_ERROR_NOT_POWERED, + temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL(named_temp_fan)), + &temp), + NULL); zassert_equal(EC_ERROR_NOT_POWERED, - temp_sensor_read(TEMP_SENSOR_PP3300_REGULATOR, &temp), + temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL( + named_temp_pp3300_regulator)), + &temp), NULL); /* power ADC */ @@ -63,6 +77,45 @@ ZTEST_USER(temp_sensor, test_temp_sensor_adc_error) NULL); } +/** Test error code when temp_sensor_read() is called power-good-pin low */ +ZTEST_USER(temp_sensor, test_temp_sensor_pg_pin) +{ + const struct device *gpio_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_EC_PG_PIN_TEMP_PATH, gpios)); + int temp; + + zassert_not_null(gpio_dev, "Cannot get GPIO device"); + + /* ec_pg_pin_temp = 0 means temperature sensors are not powered. */ + zassert_ok(gpio_emul_input_set(gpio_dev, GPIO_EC_PG_PIN_TEMP_PORT, 0), + NULL); + + zassert_equal(EC_ERROR_NOT_POWERED, + temp_sensor_read( + TEMP_SENSOR_ID(DT_NODELABEL(named_temp_charger)), + &temp), + NULL); + zassert_equal(EC_ERROR_NOT_POWERED, + temp_sensor_read( + TEMP_SENSOR_ID(DT_NODELABEL(named_temp_ddr_soc)), + &temp), + NULL); + zassert_equal( + EC_ERROR_NOT_POWERED, + temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL(named_temp_fan)), + &temp), + NULL); + zassert_equal(EC_ERROR_NOT_POWERED, + temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL( + named_temp_pp3300_regulator)), + &temp), + NULL); + + /* power ADC */ + zassert_ok(gpio_emul_input_set(gpio_dev, GPIO_EC_PG_PIN_TEMP_PORT, 1), + NULL); +} + /** Simple ADC emulator custom function which always return error */ static int adc_error_func(const struct device *dev, unsigned int channel, void *param, uint32_t *result) @@ -109,10 +162,14 @@ ZTEST_USER(temp_sensor, test_temp_sensor_read) "channel %d adc_emul_value_func_set() failed", chan); } - check_valid_temperature(adc_dev, TEMP_SENSOR_CHARGER); - check_valid_temperature(adc_dev, TEMP_SENSOR_DDR_SOC); - check_valid_temperature(adc_dev, TEMP_SENSOR_FAN); - check_valid_temperature(adc_dev, TEMP_SENSOR_PP3300_REGULATOR); + check_valid_temperature( + adc_dev, TEMP_SENSOR_ID(DT_NODELABEL(named_temp_charger))); + check_valid_temperature( + adc_dev, TEMP_SENSOR_ID(DT_NODELABEL(named_temp_ddr_soc))); + check_valid_temperature(adc_dev, + TEMP_SENSOR_ID(DT_NODELABEL(named_temp_fan))); + check_valid_temperature(adc_dev, TEMP_SENSOR_ID(DT_NODELABEL( + named_temp_pp3300_regulator))); /* Return correct value on all ADC channels */ for (chan = 0; chan < ADC_CHANNELS_NUM; chan++) { @@ -126,11 +183,15 @@ static void *temp_sensor_setup(void) { const struct device *dev = DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_PG_EC_DSW_PWROK_PATH, gpios)); + const struct device *dev_pin = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_EC_PG_PIN_TEMP_PATH, gpios)); zassert_not_null(dev, NULL); - /* Before tests make sure that power pin is set. */ + /* Before tests make sure that power pins are set. */ zassert_ok(gpio_emul_input_set(dev, GPIO_PG_EC_DSW_PWROK_PORT, 1), NULL); + zassert_ok(gpio_emul_input_set(dev_pin, GPIO_EC_PG_PIN_TEMP_PORT, 1), + NULL); return NULL; } diff --git a/zephyr/test/drivers/default/src/thermistor.c b/zephyr/test/drivers/default/src/thermistor.c index 78fa508ad4..417b482d99 100644 --- a/zephyr/test/drivers/default/src/thermistor.c +++ b/zephyr/test/drivers/default/src/thermistor.c @@ -19,17 +19,19 @@ #define GPIO_PG_EC_DSW_PWROK_PATH DT_PATH(named_gpios, pg_ec_dsw_pwrok) #define GPIO_PG_EC_DSW_PWROK_PORT DT_GPIO_PIN(GPIO_PG_EC_DSW_PWROK_PATH, gpios) +#define GPIO_EC_PG_PIN_TEMP_PATH DT_PATH(named_gpios, ec_pg_pin_temp) +#define GPIO_EC_PG_PIN_TEMP_PORT DT_GPIO_PIN(GPIO_EC_PG_PIN_TEMP_PATH, gpios) + #define ADC_DEVICE_NODE DT_NODELABEL(adc0) /* TODO replace counting macros with DT macro when * https://github.com/zephyrproject-rtos/zephyr/issues/38715 lands */ #define _ACCUMULATOR(x) 1 + -#define NAMED_TEMP_SENSORS_SIZE \ - DT_FOREACH_CHILD(DT_PATH(named_temp_sensors), _ACCUMULATOR) \ - 0 -#define TEMP_SENSORS_ENABLED_SIZE \ - DT_FOREACH_STATUS_OKAY(cros_ec_temp_sensor, _ACCUMULATOR) 0 +#define NAMED_TEMP_SENSORS_SIZE \ + DT_FOREACH_CHILD(TEMP_SENSORS_NODEID, _ACCUMULATOR) 0 + +#define TEMP_SENSORS_ENABLED_SIZE FOREACH_TEMP_SENSOR(_ACCUMULATOR) 0 /* Conversion of temperature doesn't need to be 100% accurate */ #define TEMP_EPS 2 @@ -246,12 +248,12 @@ static void do_thermistor_test(const struct temp_sensor_t *temp_sensor, temp_sensor->name); } -#define GET_THERMISTOR_REF_MV(node_id) \ - [ZSHIM_TEMP_SENSOR_ID(node_id)] = DT_PROP( \ +#define GET_THERMISTOR_REF_MV(node_id) \ + [TEMP_SENSOR_ID_BY_DEV(node_id)] = DT_PROP( \ DT_PHANDLE(node_id, thermistor), steinhart_reference_mv), -#define GET_THERMISTOR_REF_RES(node_id) \ - [ZSHIM_TEMP_SENSOR_ID(node_id)] = DT_PROP( \ +#define GET_THERMISTOR_REF_RES(node_id) \ + [TEMP_SENSOR_ID_BY_DEV(node_id)] = DT_PROP( \ DT_PHANDLE(node_id, thermistor), steinhart_reference_res), ZTEST_USER(thermistor, test_thermistors_adc_temperature_conversion) @@ -259,9 +261,9 @@ ZTEST_USER(thermistor, test_thermistors_adc_temperature_conversion) int sensor_idx; const static int reference_mv_arr[] = { DT_FOREACH_STATUS_OKAY( - cros_ec_temp_sensor, GET_THERMISTOR_REF_MV) }; + THERMISTOR_COMPAT, GET_THERMISTOR_REF_MV) }; const static int reference_res_arr[] = { DT_FOREACH_STATUS_OKAY( - cros_ec_temp_sensor, GET_THERMISTOR_REF_RES) }; + THERMISTOR_COMPAT, GET_THERMISTOR_REF_RES) }; for (sensor_idx = 0; sensor_idx < NAMED_TEMP_SENSORS_SIZE; sensor_idx++) do_thermistor_test(&temp_sensors[sensor_idx], @@ -282,11 +284,15 @@ static void *thermistor_setup(void) { const struct device *dev = DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_PG_EC_DSW_PWROK_PATH, gpios)); + const struct device *dev_pin = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_EC_PG_PIN_TEMP_PATH, gpios)); zassert_not_null(dev, NULL); - /* Before tests make sure that power pin is set. */ + /* Before tests make sure that power pins are set. */ zassert_ok(gpio_emul_input_set(dev, GPIO_PG_EC_DSW_PWROK_PORT, 1), NULL); + zassert_ok(gpio_emul_input_set(dev_pin, GPIO_EC_PG_PIN_TEMP_PORT, 1), + NULL); return NULL; } @@ -297,9 +303,9 @@ static void thermistor_cleanup(void *state) const struct device *adc_dev = DEVICE_DT_GET(ADC_DEVICE_NODE); const static int reference_mv_arr[] = { DT_FOREACH_STATUS_OKAY( - cros_ec_temp_sensor, GET_THERMISTOR_REF_MV) }; + THERMISTOR_COMPAT, GET_THERMISTOR_REF_MV) }; const static int reference_res_arr[] = { DT_FOREACH_STATUS_OKAY( - cros_ec_temp_sensor, GET_THERMISTOR_REF_RES) }; + THERMISTOR_COMPAT, GET_THERMISTOR_REF_RES) }; if (adc_dev == NULL) TC_ERROR("Cannot get ADC device"); |