Add AHT20 sensor bindings and fix driver initialization
Subsystems (2)
cover Add AHT20 sensor bindings and fix driver initialization
This patch series adds device tree binding documentation for the Aosong AHT10/AHT20 series sensors and fixes initialization issues in the driver.
The AHT20 sensor was tested on rk3566_lckfb board with I2C-2 port. Temperature and humidity readings are now accurate after fixing the initialization command sequence with aht20.
Patch 1/2: Add device tree binding documentation for AHT10 series Patch 2/2: Fix driver initialization commands and add DT support
Hao Yu (2):
dt-bindings: hwmon: add aosong,aht10 family
hwmon: (aht10) Fix initialization commands and add DT support
.../bindings/hwmon/aosong,aht10.yaml | 41 +++++++++++++++++++ drivers/hwmon/aht10.c | 16 +++++++- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/hwmon/aosong,aht10.yaml
Signature · 1 line
2.34.1
PATCH 1/2 dt-bindings: hwmon: add aosong,aht10 family
Add Aosong AHT10, AHT20, and DHT20 humidity and temperature sensors.
--- .../bindings/hwmon/aosong,aht10.yaml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/aosong,aht10.yaml
Documentation/devicetree/bindings/hwmon/aosong,aht10.yaml new file +41 -0
@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/aosong,aht10.yaml# +$schema: http://devicetree.org/meta-schema.yaml# + +title: Aosong AHT10/AHT20/DHT20 Temperature and Humidity Sensor + +maintainers: + - Hao Yu <[email protected]> + +description: | + The Aosong AHT10, AHT20, and DHT20 are I2C humidity and temperature sensors. + +properties: + compatible: + enum: + - aosong,aht10 + - aosong,aht20 + - aosong,dht20 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + sensor@38 { + compatible = "aosong,aht20"; + reg = <0x38>; + }; + };
Signature · 1 line
2.34.1
PATCH 2/2 hwmon: (aht10) Fix initialization commands and add DT support
In reply to Hao YuCorrect AHT20 initialization command sequence and
change DHT20 command format to 0bxxxxx notation.
Tested on rk3566_lckfb board with aht20 sensor connected at i2c-2 port.
--- drivers/hwmon/aht10.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/hwmon/aht10.c +14 -2
@@ -37,7 +37,9 @@#define AHT10_CMD_MEAS 0b10101100#define AHT10_CMD_RST 0b10111010 -#define DHT20_CMD_INIT 0x71 +#define AHT20_CMD_INIT 0b10111110 + +#define DHT20_CMD_INIT 0b01110001/* * Flags in the answer byte/command
@@ -60,6 +62,15 @@ static const struct i2c_device_id aht10_id[] = { };MODULE_DEVICE_TABLE (i2c, aht10_id); +static const struct of_device_id aht10_of_match[] = { + { .compatible ="aosong,aht10" , .data = (void *)aht10 }, + { .compatible ="aosong,aht20" , .data = (void *)aht20 }, + { .compatible ="aosong,dht20" , .data = (void *)dht20 }, + {} +}; + +MODULE_DEVICE_TABLE (of, aht10_of_match); +/** * struct aht10_data - All the data required to operate an AHT10/AHT20 chip * @client: the i2c client associated with the AHT10/AHT20
@@ -341,7 +352,7 @@ static int aht10_probe(struct i2c_client *client) data->meas_size =AHT20_MEAS_SIZE ; data->crc8 = true;crc8_populate_msb (crc8_table,AHT20_CRC8_POLY ); - data->init_cmd =AHT10_CMD_INIT ; + data->init_cmd =AHT20_CMD_INIT ;break ;case dht20: data->meas_size =AHT20_MEAS_SIZE ;
@@ -375,6 +386,7 @@ static int aht10_probe(struct i2c_client *client)static struct i2c_driver aht10_driver = { .driver = { .name ="aht10" , + .of_match_table = aht10_of_match, }, .probe = aht10_probe, .id_table = aht10_id,
Signature · 1 line
2.34.1
Guenter Roeck
maintainerRe: [PATCH 2/2] hwmon: (aht10) Fix initialization commands and add DT support
Quoted 3 lines · Hao Yu
Correct AHT20 initialization command sequence and
change DHT20 command format to 0bxxxxx notation.
That needs to explain what is wrong. The current initialization command is 0b11100001. Changing it to 0b10111110 but does not explain why the old value is incorrect. Something like "Per AHT20 datasheet, the initialization command for AHT20 is 0b10111110" plus an explanation that the AHT10 initialization sequence does not work as intended.
Quoted 3 lines
Tested on
rk3566_lckfbboard with aht20 sensor connected at i2c-2 port.Signed-off-by Hao Yu <[email protected]>
Quoted 9 lines
--- drivers/hwmon/aht10.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/hwmon/aht10.c +0
-0
drivers/hwmon/aht10.c line 40
Quoted 5 lines
drivers/hwmon/aht10.c +1
-1@@ -37,7 +37,9 @@#define AHT10_CMD_MEAS 0b10101100#define AHT10_CMD_RST 0b10111010 -#define DHT20_CMD_INIT 0x71 +#define AHT20_CMD_INIT 0b10111110
tab after AHT20_CMD_INIT
Thanks,
Guenter
Quoted 38 lines
drivers/hwmon/aht10.c +13
-1+ +#define DHT20_CMD_INIT 0b01110001/* * Flags in the answer byte/command @@ -60,6 +62,15 @@ static const struct i2c_device_id aht10_id[] = { };MODULE_DEVICE_TABLE (i2c, aht10_id); +static const struct of_device_id aht10_of_match[] = { + { .compatible ="aosong,aht10" , .data = (void *)aht10 }, + { .compatible ="aosong,aht20" , .data = (void *)aht20 }, + { .compatible ="aosong,dht20" , .data = (void *)dht20 }, + {} +}; + +MODULE_DEVICE_TABLE (of, aht10_of_match); +/** * struct aht10_data - All the data required to operate an AHT10/AHT20 chip * @client: the i2c client associated with the AHT10/AHT20 @@ -341,7 +352,7 @@ static int aht10_probe(struct i2c_client *client) data->meas_size =AHT20_MEAS_SIZE ; data->crc8 = true;crc8_populate_msb (crc8_table,AHT20_CRC8_POLY ); - data->init_cmd =AHT10_CMD_INIT ; + data->init_cmd =AHT20_CMD_INIT ;break ;case dht20: data->meas_size =AHT20_MEAS_SIZE ;@@ -375,6 +386,7 @@ static int aht10_probe(struct i2c_client *client)static struct i2c_driver aht10_driver = { .driver = { .name ="aht10" , + .of_match_table = aht10_of_match, }, .probe = aht10_probe, .id_table = aht10_id,
Guenter Roeck
maintainerRe: [PATCH 2/2] hwmon: (aht10) Fix initialization commands and add DT support
In reply to Hao YuQuoted 26 lines · Hao Yu
Correct AHT20 initialization command sequence and
change DHT20 command format to 0bxxxxx notation.Tested on
rk3566_lckfbboard with aht20 sensor connected at i2c-2 port.Signed-off-by Hao Yu <[email protected]>--- drivers/hwmon/aht10.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/hwmon/aht10.c +3
-1@@ -37,7 +37,9 @@#define AHT10_CMD_MEAS 0b10101100#define AHT10_CMD_RST 0b10111010 -#define DHT20_CMD_INIT 0x71 +#define AHT20_CMD_INIT 0b10111110 + +#define DHT20_CMD_INIT 0b01110001/* * Flags in the answer byte/command
drivers/hwmon/aht10.c static const struct i2c_device_id aht10_id[] = { · line 70
Quoted 9 lines
drivers/hwmon/aht10.c +6
-0@@ -60,6 +62,15 @@ static const struct i2c_device_id aht10_id[] = { };MODULE_DEVICE_TABLE (i2c, aht10_id); +static const struct of_device_id aht10_of_match[] = { + { .compatible ="aosong,aht10" , .data = (void *)aht10 }, + { .compatible ="aosong,aht20" , .data = (void *)aht20 }, + { .compatible ="aosong,dht20" , .data = (void *)dht20 }, + {} +};
Also, adding DT support needs a separate patch. One is a bug fix which needs to be marked as such for stable backport. Adding DT support is new code.
Thanks,
Guenter
Quoted 23 lines
drivers/hwmon/aht10.c +5
-1+ +MODULE_DEVICE_TABLE (of, aht10_of_match); +/** * struct aht10_data - All the data required to operate an AHT10/AHT20 chip * @client: the i2c client associated with the AHT10/AHT20 @@ -341,7 +352,7 @@ static int aht10_probe(struct i2c_client *client) data->meas_size =AHT20_MEAS_SIZE ; data->crc8 = true;crc8_populate_msb (crc8_table,AHT20_CRC8_POLY ); - data->init_cmd =AHT10_CMD_INIT ; + data->init_cmd =AHT20_CMD_INIT ;break ;case dht20: data->meas_size =AHT20_MEAS_SIZE ;@@ -375,6 +386,7 @@ static int aht10_probe(struct i2c_client *client)static struct i2c_driver aht10_driver = { .driver = { .name ="aht10" , + .of_match_table = aht10_of_match, }, .probe = aht10_probe, .id_table = aht10_id,
v3 cover hwmon: aht10: add Device Tree support
In reply to Hao YuThis series adds Device Tree support for Aosong AHT10, AHT20, and DHT20. Tested on linux_lckfb with AHT20, and the driver works as expected.
Changes in v3:
- Move bindings to trivial-devices.yaml per Krzysztof's suggestion.
- Link to v2: https://lore.kernel.org/linux-hwmon/[email protected]/
Hao Yu (2):
dt-bindings: hwmon: add Aosong AHT10/AHT20/DHT20 to trivial devices
hwmon: (aht10) add device tree ID matching
Documentation/devicetree/bindings/trivial-devices.yaml | 4 ++++ drivers/hwmon/aht10.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
Signature · 1 line
2.34.1
PATCH v3 1/2 dt-bindings: hwmon: add Aosong AHT10/AHT20/DHT20 to trivial devices
In reply to Hao YuAdd Aosong AHT10, AHT20 and DHT20 temperature and humidity sensors to the trivial-devices documentation. These sensors use a standard I2C interface and do not require complex binding definitions.
--- Documentation/devicetree/bindings/trivial-devices.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/trivial-devices.yaml +4 -0
@@ -59,6 +59,10 @@ properties: - adi,lt7182s # AMS iAQ-Core VOC Sensor - ams,iaq-core + # Aosong temperature & humidity sensors with I2C interface + - aosong,aht10 + - aosong,aht20 + - aosong,dht20 # Arduino microcontroller interface over SPI on UnoQ board - arduino,unoq-mcu # Temperature monitoring of Astera Labs PT5161L PCIe retimer
Signature · 1 line
2.34.1
Re: [PATCH v3 1/2] dt-bindings: hwmon: add Aosong AHT10/AHT20/DHT20 to trivial devices
Quoted 9 lines · Hao Yu
Add Aosong AHT10, AHT20 and DHT20 temperature and humidity sensors to the trivial-devices documentation. These sensors use a standard I2C interface and do not require complex binding definitions.
Signed-off-by Hao Yu <[email protected]>--- Documentation/devicetree/bindings/trivial-devices.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Best regards,
Krzysztof
Re: [PATCH v3 1/2] dt-bindings: hwmon: add Aosong AHT10/AHT20/DHT20 to trivial devices
In reply to Hao YuQuoted 6 lines · Hao Yu
Add Aosong AHT10, AHT20 and DHT20 temperature and humidity sensors to the trivial-devices documentation. These sensors use a standard I2C interface and do not require complex binding definitions.
Signed-off-by Hao Yu <[email protected]>
Applied.
Thanks,
Guenter
PATCH v3 2/2 hwmon: (aht10) add device tree ID matching
In reply to Hao YuAdd of_device_id table to allow the driver to be matched via Device Tree. This is required for supporting the AHT10/20/DHT20 sensors on platforms using DT.
--- drivers/hwmon/aht10.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/hwmon/aht10.c +10 -0
@@ -60,6 +60,15 @@ static const struct i2c_device_id aht10_id[] = { };MODULE_DEVICE_TABLE (i2c, aht10_id); +static const struct of_device_id aht10_of_match[] = { + { .compatible ="aosong,aht10" , .data = (void *)aht10 }, + { .compatible ="aosong,aht20" , .data = (void *)aht20 }, + { .compatible ="aosong,dht20" , .data = (void *)dht20 }, + {} +}; + +MODULE_DEVICE_TABLE (of, aht10_of_match); +/** * struct aht10_data - All the data required to operate an AHT10/AHT20 chip * @client: the i2c client associated with the AHT10/AHT20
@@ -375,6 +384,7 @@ static int aht10_probe(struct i2c_client *client)static struct i2c_driver aht10_driver = { .driver = { .name ="aht10" , + .of_match_table = aht10_of_match, }, .probe = aht10_probe, .id_table = aht10_id,
Signature · 1 line
2.34.1
Re: [PATCH v3 2/2] hwmon: (aht10) add device tree ID matching
Quoted 5 lines · Hao Yu
Add
of_device_idtable to allow the driver to be matched via Device Tree. This is required for supporting the AHT10/20/DHT20 sensors on platforms using DT.Signed-off-by Hao Yu <[email protected]>
Applied.
Thanks,
Guenter