Re: dht11 vs iio-hwmon

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On 27.05.2022 12:31, Dag B wrote:

On 25.05.2022 18:18, Dag B wrote:


I have managed to make use of the dht11 driver and can get data from my sensor quite reliably.

I wanted to be able to read this sensor via lm-sensors, and was hoping to employ the iio-hwmon bridge for this purpose. Sadly, I do not get any nodes in the /sys/class/hwmon/ directory for the dht11 sensor.

Do iio-drivers (like dht11) have to be written with this bridge in mind, in order to get the hwmon entries? Or am I just missing a touch of magic somewhere?

root@rpi2:/boot# lsmod | egrep 'iio|hw|dht'
dht11                  16384  0
iio_hwmon              16384  0
raspberrypi_hwmon      16384  0
industrialio           81920  2 iio_hwmon,dht11
root@rpi2:/boot# cat /sys/bus/iio/devices/iio\:device0/in_temp_input
root@rpi2:/boot# ls -l /sys/class/hwmon/
total 0
lrwxrwxrwx 1 root root 0 May 25 08:59 hwmon0 -> ../../devices/virtual/thermal/thermal_zone0/hwmon0 lrwxrwxrwx 1 root root 0 May 25 08:59 hwmon1 -> ../../devices/platform/soc/soc:firmware/raspberrypi-hwmon/hwmon/hwmon1

So, I have employed my "monkey see, monkey do"-mode. I realize that other iio-drivers got something like this in the device tree specification:

        iio-hwmon {

                compatible = "iio-hwmon";
                io-channels = <&something N>, <&something N+1>;


Where 'something' most often is 'adc' and N is an integer. 'something' may also be 'tlaNNNN' or 'gpadc'.

'something' is either defined in the .dts file or an included .dtsi file. I have not yet managed to deduce to what extent these definitions are tied to the device-driver. If someone would be so kind to offer distilled insights, I would really appreciated it. My C-foo is weak, but the itch is real.

The dht11 driver provides for temperature and humidity through a single GPIO pin.


The .dts file is at:


The overlay referenced above is obviously not present in the upstream kernel. I was working on the Raspberry Pi kernel repo. Managed to butcher it to do what I want.

Patch attached for whoever finds themselves in the same position. Also posted to relevant RPi forum here:

Dag N

From 18baf344f61abe32154fe76a9548c381804fff3d Mon Sep 17 00:00:00 2001
From: Dag Bakke <dag@xxxxxxxxx>
Date: Mon, 30 May 2022 11:57:06 +0200
Subject: [PATCH] Add code to make sensor readable via the IIO hwmon bridge.

Signed-off-by: Dag Bakke <dag@xxxxxxxxx>
 arch/arm/boot/dts/overlays/dht11-overlay.dts | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/overlays/dht11-overlay.dts b/arch/arm/boot/dts/overlays/dht11-overlay.dts
index 6feeeb402493..3363e3075f75 100644
--- a/arch/arm/boot/dts/overlays/dht11-overlay.dts
+++ b/arch/arm/boot/dts/overlays/dht11-overlay.dts
@@ -17,7 +17,14 @@ dht11: dht11@0 {
 				pinctrl-0 = <&dht11_pins>;
 				gpios = <&gpio 4 0>;
 				status = "okay";
+				#io-channel-cells = <1>;
+			iio-hwmon {
+				compatible = "iio-hwmon";
+				status = "okay";
+				io-channels = <&dht11 0>, <&dht11 1>;
+			};

[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux