Thank you for the advices which make me one step closer.
Just some updates at this stage. Desperately seeking for advice and solution.
I tried to write the dts file based on what @angus mentioned above.
As the device tree concept is quite new to me, I tried to compile the dts file by using device-tree-compiler and added the output dtbo file back to customized overlay directory via below cmd,
dtc -I dts -O dtb -o dht11.dtbo dht11-overlay.dts
cat dht11.dtbo > /sys/kernel/config/device-tree/overlays/dht11/dtbo
/* dth11-overlay.dts
* Overlay to enable DHT-11/DHT-22 Temperature/Humidity Senor
* I applied gpiox_7 with default high voltage, i.e. 86 0, as the dts is not including dt-bindings files
*/
/dts-v1/;
/plugin/;
/ {
compatible = "libretech,cc", "amlogic,s905x", "amlogic,meson-gxl";
fragment@0 {
target-path = "/";
__overlay__ {
dht11: dht11@0 {
compatible = "dht11";
gpios = <&gpio 86 0>;
status = "okay";
};
};
};
};
By doing these I can find the corresponding overlay in two places,
“/proc/device-tree/dht11@0”;
“/sys/bus/iio/devices/iio:device1/”;
After all these have been done, I created a Demo.c to see how far I went,
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef struct DHT11_SENSOR_DATA
{
u16 temp;//temperature
u16 hum;//humidity
}dht11_data;
int main ( void )
{
int fd ;
int retval ;
dht11_data Curdht11_data;
//fd = open ( "/proc/device-tree/dht11@0/gpios" , O_RDONLY) ;
fd = open ("/sys/bus/iio/devices/iio:device1/subsystem/drivers_probe" , O_RDONLY);
if ( fd == -1 )
{
perror ( "open dht11 error\n" ) ;
exit ( -1 ) ;
}
//printf ( "open /proc/device-tree/dht11@0 successfully\n" ) ;
printf("open /sys/bus/iio/devices/iio:device1/subsystem\n");
sleep ( 2 ) ;
while ( 1 )
{
sleep ( 1 ) ;
retval = read ( fd , &Curdht11_data , sizeof(Curdht11_data) );
if ( retval == -1 )
{
perror ( "read dht11 error" ) ;
printf ( "read dht11 error" ) ;
exit ( -1 ) ;
}
if(Curdht11_data.temp != 0xffff)
printf ( "Temperature:%d.%d C,Humidity:%d.%d %%RH\n",Curdht11_data.temp>>8,Curdht11_data.temp&0xff,\
Curdht11_data.hum>>8,Curdht11_data.hum&0xff ) ;
}
close ( fd ) ;
}
However, the readings are still incorrect. I’m contemplating those drivers_probe and drivers_autoprobe file under subsystem folder at the moment…