Need to find an ntc thermistor temperature from within an I2C driver

I have a regulator driver, defined within the i2c4 block, on our board’s dts file, that needs to be able to also read a temperature sensed through an NTC thermistor and the A/D system (adc1 on pin 8).

It would seem sensible to use the drivers/hwmon/ntc_thermistor driver to read and convert the temperature and then get this value through the IIO system.

I have not had success, using ntc_thermistor or the iio system accessing the ADC. All suggestions are welcome as to how to define, configure and access from within an iio_channel, either the ADC (where I would do my own math) or the thermistor. The thermistor accessed by my kernel driver through iio seems the most elegant way to do it.

Using the information: https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt, one finds the suggestion that the NTC can be defined and named by defining in the board file against the adc1 entry (their example used the exynos adc@12d10000 entry):

adc@12d10000 {

/* NTC thermistor is a hwmon device */
ncp15wb473@0 {
	compatible = "murata,ncp15wb473";
	pullup-uv = <1800000>;
	pullup-ohm = <47000>;
	pulldown-ohm = <0>;
	io-channels = <&adc 4>;
};

};

CONFIG_NTC_THERMISTOR=y

When this is done the /sys dts hierarchy shows the compiled dts entry when the board is flashed, but I cannot find a SYSFS entry for the results, nor know how to setup access to it from my kernel driver.

I know that the iio system is reading the value since this shows up in /sys/bus/iio/devices/iio:device0/in_voltage0_raw

Trying to access this through the iio system with iio_get_channel and iio_raw_read results in the kernel starting the boot with the “Kernel Booting” message and then silently hanging.

What do I need to do to get this working:

  • define the ntc_thermistor (if I haven’t done it right)
  • get the ntc_thermistor driver to start
  • access the ntc_thermistor from my kernel driver

Thanks in advance for advice.

Hi

I assume you have your HW right. I.e. you have a thermistor with the “murata,ncp15wb473” behaviour.
You have 1.8V on your carrier board connected to the 47k pullup, the other side of the pullup goes to the NTC and to the ADC1_IN0 on pin 8, the other side of the NTC goes to GND.

With this you should be able to get a voltage measurement out of /sys/bus/iio/devices/iio:device0/in_voltage0_raw, calculate the resistance of the NTC and check if the reading makes sense, i.e. if your HW setup is correct.

You would need to add the driver by adding CONFIG_SENSORS_NTC_THERMISTOR=y (Note the additional SENSORS_) to the kernel config.
You would need to add a child node to the adc1 node, e.g.

diff --git a/arch/arm/boot/dts/imx7-colibri.dtsi b/arch/arm/boot/dts/imx7-colibri.dtsi
index c9e50f1149d4..13c0a7c242ee 100644
--- a/arch/arm/boot/dts/imx7-colibri.dtsi
+++ b/arch/arm/boot/dts/imx7-colibri.dtsi
@@ -93,6 +93,14 @@
 
 &adc1 {
        vref-supply = <&reg_DCDC3>;
+
+       thermistor1: ncp15wb473@0 {
+               compatible = "murata,ncp15wb473";
+               pullup-uv = <1800000>;
+               pullup-ohm = <47000>;
+               pulldown-ohm = <0>;
+               io-channels = <&adc1 0>;
+       };
 };
 
 &adc2 {

With that I expect some output of the driver in dmesg, i.e ‘dmesg | grep Therm’ and I expect a new IIO device under /sys which gives access to the temperature.

Now to read the temperature from within your own kernel driver.
Add a property with a reference to the ntc node to your regulator driver and read that reference from the device tree during probe.
You should be able to access that IIO device with said reference. Compere with how the NTC driver does read the IIO voltage.

Max

Thanks for the reply. I am about to head for vacation so I may not get a chance to try things out for a while.

Already had done the child node in adc1, and had the correct config item selected (entered the question when I was away from my development desktop).

The ADC reads correctly through the iio sysfs entry for in_voltage0_raw.

So though I may not reply for a bit, I will try thinks as quickly as possible.