diff --git a/drivers/sensor/ntc_thermistor/Kconfig b/drivers/sensor/ntc_thermistor/Kconfig index 691192b5282..3b73aebd205 100644 --- a/drivers/sensor/ntc_thermistor/Kconfig +++ b/drivers/sensor/ntc_thermistor/Kconfig @@ -5,7 +5,8 @@ config NTC_THERMISTOR bool "NTC Thermistor" default y - depends on DT_HAS_EPCOS_B57861S0103A039_ENABLED + depends on DT_HAS_NTC_THERMISTOR_GENERIC_ENABLED || \ + DT_HAS_EPCOS_B57861S0103A039_ENABLED select ADC help Enable driver for Zephyr NTC Thermistor. diff --git a/drivers/sensor/ntc_thermistor/ntc_thermistor.c b/drivers/sensor/ntc_thermistor/ntc_thermistor.c index 24b356af7c5..67f2318d4a4 100644 --- a/drivers/sensor/ntc_thermistor/ntc_thermistor.c +++ b/drivers/sensor/ntc_thermistor/ntc_thermistor.c @@ -132,7 +132,17 @@ static int ntc_thermistor_init(const struct device *dev) &ntc_thermistor_cfg_##id##inst, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \ &ntc_thermistor_driver_api); +/* ntc-thermistor-generic */ +#define DT_DRV_COMPAT ntc_thermistor_generic + +#define NTC_THERMISTOR_GENERIC_DEFINE(inst) \ + static const uint32_t comp_##inst[] = DT_INST_PROP(inst, zephyr_compensation_table); \ + NTC_THERMISTOR_DEFINE(inst, DT_DRV_COMPAT, comp_##inst) + +DT_INST_FOREACH_STATUS_OKAY(NTC_THERMISTOR_GENERIC_DEFINE) + /* epcos,b57861s0103a039 */ +#undef DT_DRV_COMPAT #define DT_DRV_COMPAT epcos_b57861s0103a039 static __unused const struct ntc_compensation comp_epcos_b57861s0103a039[] = { diff --git a/dts/bindings/sensor/ntc-thermistor-generic.yaml b/dts/bindings/sensor/ntc-thermistor-generic.yaml new file mode 100644 index 00000000000..217eacc7b79 --- /dev/null +++ b/dts/bindings/sensor/ntc-thermistor-generic.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Generic NTC thermistor + +compatible: "ntc-thermistor-generic" + +include: ntc-thermistor.yaml + +properties: + zephyr,compensation-table: + type: array + required: true + description: | + Compensation table, formatted as temperature, resistance pairs. A script + to generate a valid table is provided in + scripts/utils/ntc_thermistor_table.py. diff --git a/tests/drivers/build_all/sensor/adc.dtsi b/tests/drivers/build_all/sensor/adc.dtsi index abcc984b96d..52b41ce0f7c 100644 --- a/tests/drivers/build_all/sensor/adc.dtsi +++ b/tests/drivers/build_all/sensor/adc.dtsi @@ -23,6 +23,17 @@ test_adc_emul: adc { status = "okay"; }; +test_ntc_thermistor_generic: ntc-thermistor-generic { + compatible = "ntc-thermistor-generic"; + io-channels = <&adc0 0>; + r25-ohm = <10000>; + pullup-uv = <3300000>; + pullup-ohm = <0>; + pulldown-ohm = <10000>; + connected-positive; + zephyr,compensation-table = <0 0>, <1 1>; +}; + test_epcos_b57861s0103a039: epcos-b57861s0103a039 { compatible = "epcos,b57861s0103a039"; io-channels = <&adc0 0>;