NTC Overlay failing

Hello Toradex team,

I hope you are all doing great!

Hardware:

uname:

  • Linux verdin-imx8mp-14777482 5.15.77-6.3.0+git.ddc6ca4d76ea #1-TorizonCore SMP PREEMPT Thu Jun 29 10:14:22 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

Images tested:

  • torizon-core-docker-verdin-imx8mp-Tezi_6.3.0+build.4.tar (STABLE Release)

Guest OS:

  • macOS (M1 Pro ARM64)
  • Linux ubuntu (VM x86_64)

Issue:
I have custom NTC connected to the 3nd ADC of my toradex module, I’m able to access the voltage through the sysfs inerface as follow:

$ cat /dev/verdin-adc3
461

So far so good!

While I was looking at a solution to access this value in my device, I have found this kernel module: ntc_thermistor.c, I wrote the following overlay to use it:

/dts-v1/;
/plugin/;

/ {
	compatible = "toradex,verdin-imx8mp";
};

&adc {
	thermistor1: ncp15wf104f03rc {
		compatible      = "murata,ncp03wf104";
		pullup-uv         = <5000000>;
		pullup-ohm      = <100000>;
		pulldown-ohm = <10000>;
		io-channels      = <&adc 5>;
	};
};

/* EOF */

It compiles as expected but I have a strange error:

=> Adding device-tree overlay 'overlays/verdin-imx8mp_ntc.dts'
'verdin-imx8mp_ntc.dts' compiles successfully.

Failed to apply '/tmp/tmp5ehh2xhe': FDT_ERR_NOTFOUND

error: cannot apply device tree overlays ['/storage/dt/usr/lib/modules/5.15.77-6.3.0+git.ddc6ca4d76ea/dtb/overlays/verdin-imx8mp_disabled.dtbo', '/tmp/tmp5ehh2xhe'] against device tree /storage/dt/usr/lib/modules/5.15.77-6.3.0+git.ddc6ca4d76ea/dtb/imx8mp-verdin-wifi-dahlia.dtb.
error: overlay 'overlays/verdin-imx8mp_ntc.dts' is not applicable.

After some research on this forum, I have found this post that explain that a flag needs to be enable at the kernel level:

$ sudo tdx-info
Password:

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           5.15.77-6.3.0+git.ddc6ca4d76ea #1-TorizonCore SMP PREEMPT Thu Jun 29 10:14:22 UTC 2023
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.0/torizon/c81d517adf3f969ba1c9a43eec7622acd27c37404a413cfacc10deca8d035af7/0
Distro name:              NAME="TorizonCore"
Distro version:           VERSION_ID=6.3.0-build.4
Hostname:                 verdin-imx8mp-14777482
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Verdin iMX8M Plus WB on Dahlia Board
Toradex version:          0058 V1.1A
Serial number:            14777482
Processor arch:           aarch64
------------------------------------------------------------
$ zcat /proc/config.gz | grep -i NTC_THERMISTOR
# CONFIG_SENSORS_NTC_THERMISTOR is not set

Is my problem related to the fact that the driver is not enable on TorizonOS ? Is it possible to enable it without breaking anything else for me and other customers ?

I hope that my post is complete and you will be able to help me regarding this issue?

Best regards,
M

1 Like

If you are able to read the voltage drop on the thermistor and calculate its resistance (BTW - how exactly is the NTC connected to ADC?), then you can find the temperature using the formula provided in The NTC datasheet. So, you don’t need a special Linux driver to obtain the temperature. On the other hand, if you still wish to integrate the NTC driver, you can utilize the TorizonCore Builder Tool and create a custom Torizon core image with all the necessary additional drivers and Device Tree.

Hello @alex.tx,

Thank you for your quick reply!

I can indeed calculate the temperature using the formula provided by the datasheet but I want to use the kernel functionality to regulate to temperature and trigger action accordingly.

It’s connected directly to the ADC 3, and if you want to see the schematic (where TEMP is the direct link to the ADC):

As for the driver, it’s already build in the TorizonOS, so I can’t add it unfortunately. It works the same as this issue I had previous. Those tag need to be enable during the yocto build.

Best regards,

M

I see two potential problems here.

First of all the kernel config for the respective driver isn’t enabled as you already pointed out. We can enable this for you on our side (assuming no conflicts). Would you like us to do this? Also are you sure this is the correct driver for your hardware?

The second issue is the matter of your overlay itself. You’re referencing a node with the label adc but there is no node in our device tree with that label. That’s probably what is causing the FDT_ERR_NOTFOUND that you see. I’m not completely sure how the overlay should look since I’ve never integrated this specific kind of peripheral before, but I did find the documentation for the device tree bindings for this driver: ntc_thermistor.txt « hwmon « bindings « devicetree « Documentation - linux-toradex.git - Linux kernel for Apalis, Colibri and Verdin modules

Of course even if you have the right overlay you still need the driver enabled as per the first point.

Best Regards,
Jeremias

Hello @jeremias.tx,

Thank you for reaching back to me!

For the first point, if it’s possible and accepted by the R&D team, you can ask them to enable the driver for a futur nightly. Thank you!

For the second point, you right about the adc not being declare. I’ll take a deeper look and maybe add it directly into the device tree inside the adc block as shown in your example. Thank you for pointing this out.

Best regards,

M

For the first point, if it’s possible and accepted by the R&D team, you can ask them to enable the driver for a futur nightly. Thank you!

Alright then, I’ll go ahead and make the request to our team to enable CONFIG_SENSORS_NTC_THERMISTOR in our kernel config. I’ll try and notify you when this is made available.

Best Regards,
Jeremias

1 Like

Hi @unablesalt,

This config option is now enabled in our latest nightly builds as seen here:

torizon@verdin-imx8mp-06849059:~$ cat /etc/os-release
ID=torizon
NAME="TorizonCore"
VERSION="6.4.0-devel-20230829+build.365 (kirkstone)"
VERSION_ID=6.4.0-devel-20230829-build.365
PRETTY_NAME="TorizonCore 6.4.0-devel-20230829+build.365 (kirkstone)"
DISTRO_CODENAME="kirkstone"
BUILD_ID="365"
ANSI_COLOR="1;34"
VARIANT="Docker"
torizon@verdin-imx8mp-06849059:~$ zcat /proc/config.gz | grep CONFIG_SENSORS_NTC_THERMISTOR
CONFIG_SENSORS_NTC_THERMISTOR=m

Best Regards,
Jeremias

Hello @jeremias.tx,

I hope you are doing great !

Sorry for the late reply, I had to deal with other stuff…

So I managed to compile with the latest version and the module is properly loaded! Unfortunately, I have an issue on my overlay… The issue is the following:

[    5.728544] ads1015 0-0049: invalid reg on /soc@0/bus@30800000/i2c@30a20000/adc@49/ncp15wf104f03rc

The difference I have, is named adc: adc@49 inside the device-tree (arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi), so the adc can be accessed outside of the scope.

And for the record, here is the overlay:

/dts-v1/;
/plugin/;

/ {
	compatible = "toradex,verdin-imx8mp";
};

&adc {
	thermistor1: ncp15wf104f03rc {
		compatible   = "murata,ncp03wf104";
		pullup-uv    = <5000000>;
		pullup-ohm   = <100000>;
		pulldown-ohm = <0>;
		io-channels  = <&adc 5>;
	};
};

I hope you will be able to help me.

Best regards,

M

To be clear I’ve never used this particular peripheral and I’m not familiar with it. But looking at the in-kernel documentation for the device tree bindings: ntc_thermistor.txt « hwmon « bindings « devicetree « Documentation - linux-toradex.git - Linux kernel for Apalis, Colibri and Verdin modules

I don’t think you’re suppose to define this device as part of the “adc” node. It looks like you define it as it’s own node then reference the adc node via the io-channels parameter. For example see how the node is defined in this other device tree I found: exynos4412-midas.dtsi « dts « boot « arm « arch - linux-toradex.git - Linux kernel for Apalis, Colibri and Verdin modules

Best Regards,
Jeremias

1 Like

Hello @jeremias.tx,

Thank you for the example! I’ll try this and keep you updated.

Best regards,
M

Hi Team,

Sorry for not responding for a while.

I’m still unable to use the module and the hardware, I followed all the ressources that you provided me and the one I could find online but nothing seems to work…

Maybe explaining what I’m trying to achieve can help you to understand my use-case:

I have a NTC placed in heat chamber (like a oven) and I want to trigger a GPIO when the temperature reach a certain point. I have found this gpio-fan but I have no idea how to link everything together… And the first part of the problem is the fact that the overlay is enable but there is no new iio.

I hope you will be able to help me.

Best regards,

M

Let’s just focus on the NTC thermistor for now. What exactly did you change or adjust in your overlay now? What are you seeing in terms of issues?

To be clear, all I know about this peripheral is what is found in the Linux kernel documentation. According to here if everything is working okay there should be a sysfs interface with some values to read: Kernel driver ntc_thermistor — The Linux Kernel documentation

Best Regards,
Jeremias

Hello Jeremias,

So my changes are the following:

+++ b/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi
@@ -623,7 +623,7 @@ hwmon_temp_module: sensor@48 {
                vs-supply = <&reg_vdd_1v8>;
        };

-       adc@49 {
+       adc: adc@49 {
                compatible = "ti,ads1015";
                reg = <0x49>;
                #address-cells = <1>;

And the overlay looks like this:

/ {
	compatible = "fline,verdin-imx8mp",
	             "toradex,verdin-imx8mp";

	thermistor1 {
		compatible            = "murata,ncp03wf104";
		pullup-uv             = <5000000>;
		pullup-ohm            = <100000>;
		pulldown-ohm          = <0>;
		io-channels           = <&adc 5>;
		#thermal-sensor-cells = <0>;
		status                = "okay";
	};
};

I don’t see the module being loaded and no issue on the dmesg console, so either the module is not enable (but we know that it has been enable starting 6.4.0-devel-20230829+build.365 (kirkstone)) or I have an issue in the code and the overlay is not loaded properly but the debug console says that the overlay is loaded (Applying Overlay: verdin-imx8mp_ntc.dtbo)

Here is the info, same as yours:

torizon@verdin-imx8mp-14777482:~$ cat /etc/os-release
ID=torizon
NAME="TorizonCore"
VERSION="6.4.0-devel-20230922+build.395 (kirkstone)"
VERSION_ID=6.4.0-devel-20230922-build.395
PRETTY_NAME="TorizonCore 6.4.0-devel-20230922+build.395 (kirkstone)"
DISTRO_CODENAME="kirkstone"
BUILD_ID="395"
ANSI_COLOR="1;34"
VARIANT="Docker"
torizon@verdin-imx8mp-14777482:~$ zcat /proc/config.gz | grep CONFIG_SENSORS_NTC_THERMISTOR
CONFIG_SENSORS_NTC_THERMISTOR=m

I don’t know what have I done wrong on this…

Best regards,
M

Your overlay as written wouldn’t add thermistor1 to the root node of the device tree. If you want to add a new node to the root node of the device tree via an overlay, you should do something like this for example:

/dts-v1/;
/plugin/;

&{/} {
    prop1 = "value1";
};

With your overlay I’m not even sure when in the device tree your node would get instantiated, but definitely not under the root node.

Best Regards,
Jeremias

Hi @jeremias.tx,

Thank you for your answer. You were right, I made a mistake in my overlay, by changing it I finally get an output on the console:

[    5.173386] OF: /thermistor1: could not get #io-channel-cells for /soc@0/bus@30800000/i2c@30a20000/adc@49

We are making progress, but now I have no idea what I could do to have access to this channel on the ADC.

If anyone ever worked with ADC, I would be glad to understand it ?

Best regards,
M


UPDATE:
I have found this [link[(https://www.kernel.org/doc/Documentation/devicetree/bindings/iio/iio-bindings.txt) that explain that the adc needs to be declared with #io-channel-cells = <1>;.

Now, I can see a new hwmon device:

lrwxrwxrwx 1 root root 0 Oct 18 14:40 hwmon1 -> ../../devices/platform/thermistor1/hwmon/hwmon1

Good news ! But the value is not as expected, for temp1_input it returns 74496 or other related values. But I know that it’s not the temperature or do I need to process it ?

Best regards,
M

Good news ! But the value is not as expected, for temp1_input it returns 74496 or other related values. But I know that it’s not the temperature or do I need to process it ?

You probably need to process this. Looking at the driver source code here: https://git.toradex.com/cgit/linux-toradex.git/tree/drivers/hwmon/ntc_thermistor.c?h=toradex_5.15-2.1.x-imx#n547

There’s a comment saying:

/*
	 * First multiplying the table temperatures with 1000 to get to
	 * millicentigrades (which is what we want) and then interpolating
	 * will give the best precision.
	 */

Does millicentigrades make more sense for that value in your opinion? Otherwise you may need to refer to the datasheet or manufacturer to figure out how to process the value into actual temperature values. As the value transformation may be hardware specific to the specific thermistor.

Best Regards,
Jeremias

1 Like

I’ll check and keep you updated.

I can mark this problem as solved since I can access it.

Thank you for your help.

Best regards,
M

Glad I was able to help!

1 Like