Skip to contentSkip to conversation

Add AHT20 sensor bindings and fix driver initialization

PATCH Applied Hao Yu 3 participants 6 messages Feb 22 – Feb 23

Subsystems (2)
lore
Share & tools
lore

Hao Yu

author
#0 lore raw

v2 cover Add AHT20 sensor bindings and fix driver initialization

This patch series adds device tree binding documentation for Aosong AHT10/AHT20 series sensors, fixes the initialization command sequence for AHT20, and adds Device Tree support to the driver.

The AHT20 sensor was tested on a rk3566_lckfb board with the I2C-2 port. Temperature and humidity readings are now accurate after fixing the initialization command.

Changes in v2:
- Split the driver patch into two separate commits:
- Patch 2/3: A fix for the initialization bug (includes Fixes tag).
- Patch 3/3: A feature patch for adding Device Tree support.
- Improved the commit message for the initialization fix with a detailed explanation as requested by Guenter Roeck.
- Fixed indentation in aht10.c (ensured tab usage after macro definition).

Hao Yu (3):
dt-bindings: hwmon: add aosong,aht10 family
hwmon: (aht10) Fix initialization commands for AHT20
hwmon: (aht10) Add Device Tree 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
author
#1 lore raw

PATCH v2 1/3 dt-bindings: hwmon: add aosong,aht10 family

Add device tree bindings for Aosong AHT10, AHT20 and DHT20 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
new file mode 100644
index 000000000000..6eb3944ae3da
@@ -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
#2 lore raw

Re: [PATCH v2 1/3] dt-bindings: hwmon: add aosong,aht10 family

Quoted 5 lines · Hao Yu

Add device tree bindings for Aosong AHT10, AHT20 and DHT20 sensors.

---
 .../bindings/hwmon/aosong,aht10.yaml          | 41 +++++++++++++++++++

This should go to trivial-devices schema.

Best regards,
Krzysztof

author
#3 lore raw

PATCH v2 2/3 hwmon: (aht10) Fix initialization commands for AHT20

In reply to Hao Yu

According to the AHT20 datasheet (updated to V1.0 after the 2023.09 version), the initialization command for AHT20 is 0b10111110 (0xBE). The previous sequence (0xE1) used in earlier versions is no longer compatible with newer AHT20 sensors. Update the initialization command to ensure the sensor is properly initialized.

Fixes d2abcb5cc885 ("hwmon: (aht10) Add support for compatible aht20")
---
 drivers/hwmon/aht10.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hwmon/aht10.c +4 -2
index 007befdba977..4ce019d2cc80 100644
@@ -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
@@ -341,7 +343,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;
Signature · 1 line
2.34.1
maintainer Applied
#4 lore raw

Re: [PATCH v2 2/3] hwmon: (aht10) Fix initialization commands for AHT20

Quoted 8 lines · Hao Yu

According to the AHT20 datasheet (updated to V1.0 after the 2023.09 version), the initialization command for AHT20 is 0b10111110 (0xBE). The previous sequence (0xE1) used in earlier versions is no longer compatible with newer AHT20 sensors. Update the initialization command to ensure the sensor is properly initialized.

Fixes d2abcb5cc885 ("hwmon: (aht10) Add support for compatible aht20")

Applied, since htis is a fix which doewsn't depend on the devicetree patches.

Thanks,
Guenter

Quoted 28 lines
---
 drivers/hwmon/aht10.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hwmon/aht10.c +4 -2
index 007befdba977..4ce019d2cc80 100644
@@ -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
@@ -341,7 +343,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;
author
#5 lore raw

PATCH v2 3/3 hwmon: (aht10) Add Device Tree support

In reply to Hao Yu

Add support for Device Tree probing by adding an of_match_table. This allows the driver to be used with aosong,aht10, aosong,aht20, and aosong,dht20 compatible strings in device tree files.

---
 drivers/hwmon/aht10.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/hwmon/aht10.c +10 -0
index 4ce019d2cc80..66955395d058 100644
@@ -62,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
@@ -377,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