From c60e4ec989d97243a39dc36f9a11253d70f1c24e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 28 Apr 2023 11:42:21 +0200 Subject: [PATCH] drivers: sensor: zephyr_thermistor: align connection type with Linux It looks like the Zephyr thermistor driver bindings were half-copied from Linux ntc-thermistor. Zephyr principle is to maintain compatibility with Linux, when possible, so there's no reason to deviate here. Convert the connection type from a custom enum to a boolean, as Linux does. Signed-off-by: Gerard Marull-Paretas --- boards/arm/tdk_robokit1/tdk_robokit1-common.dtsi | 2 +- .../sensor/zephyr_thermistor/zephyr_ntc_thermistor.c | 2 +- .../sensor/zephyr_thermistor/zephyr_ntc_thermistor.h | 7 +------ .../zephyr_ntc_thermistor_rt_table.c | 2 +- dts/bindings/sensor/zephyr,ntc-thermistor.yaml | 12 ++++++------ tests/drivers/build_all/sensor/adc.dtsi | 2 +- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/boards/arm/tdk_robokit1/tdk_robokit1-common.dtsi b/boards/arm/tdk_robokit1/tdk_robokit1-common.dtsi index 9d63cd7fe9a..1618ee6a451 100644 --- a/boards/arm/tdk_robokit1/tdk_robokit1-common.dtsi +++ b/boards/arm/tdk_robokit1/tdk_robokit1-common.dtsi @@ -52,7 +52,7 @@ pullup-uv = <3300000>; pullup-ohm = <0>; pulldown-ohm = <10000>; - connection-type = "NTC_CONNECTED_POSITIVE"; + connected-positive; }; }; diff --git a/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor.c b/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor.c index cbcd8176cc0..2adfb3d59ad 100644 --- a/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor.c +++ b/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor.c @@ -112,7 +112,7 @@ static int zephyr_ntc_thermistor_init(const struct device *dev) .pullup_uv = DT_INST_PROP(inst, pullup_uv), \ .pullup_ohm = DT_INST_PROP(inst, pullup_ohm), \ .pulldown_ohm = DT_INST_PROP(inst, pulldown_ohm), \ - .connection_type = DT_INST_STRING_TOKEN(inst, connection_type), \ + .connected_positive = DT_INST_PROP(inst, connected_positive), \ .type = &NTC_TYPE_NAME(DT_INST_PROP(inst, zephyr_rt_table)), \ }, \ }; \ diff --git a/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor.h b/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor.h index fef0272f658..04d716cd81c 100644 --- a/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor.h +++ b/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor.h @@ -14,11 +14,6 @@ struct ntc_compensation { const uint32_t ohm; }; -enum ntc_type_e { - NTC_CONNECTED_POSITIVE, - NTC_CONNECTED_GROUND -}; - struct ntc_type { const struct ntc_compensation *comp; int n_comp; @@ -26,7 +21,7 @@ struct ntc_type { }; struct ntc_config { - enum ntc_type_e connection_type; + bool connected_positive; uint32_t r25_ohm; uint32_t pullup_uv; uint32_t pullup_ohm; diff --git a/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor_rt_table.c b/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor_rt_table.c index 381e2926c13..5ec95bf1a3d 100644 --- a/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor_rt_table.c +++ b/drivers/sensor/zephyr_thermistor/zephyr_ntc_thermistor_rt_table.c @@ -104,7 +104,7 @@ uint32_t ntc_get_ohm_of_thermistor(const struct ntc_config *cfg, uint32_t max_ad { uint32_t ohm; - if (cfg->connection_type == NTC_CONNECTED_POSITIVE) { + if (cfg->connected_positive) { ohm = cfg->pulldown_ohm * max_adc / (raw_adc - 1); } else { ohm = cfg->pullup_ohm * (raw_adc - 1) / max_adc; diff --git a/dts/bindings/sensor/zephyr,ntc-thermistor.yaml b/dts/bindings/sensor/zephyr,ntc-thermistor.yaml index 08585a65706..e1c90339e3b 100644 --- a/dts/bindings/sensor/zephyr,ntc-thermistor.yaml +++ b/dts/bindings/sensor/zephyr,ntc-thermistor.yaml @@ -38,10 +38,10 @@ properties: description: | The pulldown resistance in the circuit. - connection-type: - type: string + connected-positive: + type: boolean description: | - The connection type of the circuit model used. - enum: - - NTC_CONNECTED_POSITIVE - - NTC_CONNECTED_GROUND + Indicates how the thermistor is connected in series with a pull-up and/or + a pull-down resistor. If this flag is NOT specified, the thermistor is + assumed to be connected-ground, which usually means a pull-down resistance + of zero but complex arrangements are possible. diff --git a/tests/drivers/build_all/sensor/adc.dtsi b/tests/drivers/build_all/sensor/adc.dtsi index bc7ef430e86..128ef293bd3 100644 --- a/tests/drivers/build_all/sensor/adc.dtsi +++ b/tests/drivers/build_all/sensor/adc.dtsi @@ -53,5 +53,5 @@ test_adc_b57861s: b57861s@0 { pullup-uv = <3300000>; pullup-ohm = <0>; pulldown-ohm = <10000>; - connection-type = "NTC_CONNECTED_POSITIVE"; + connected-positive; };