]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (aht10) Add support for dht20
authorAkhilesh Patil <akhilesh@ee.iitb.ac.in>
Sun, 2 Nov 2025 09:43:20 +0000 (15:13 +0530)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 2 Nov 2025 19:07:16 +0000 (11:07 -0800)
Add support for dht20 temperature and humidity sensor from Aosong.
Modify aht10 driver to handle different init command for dht20 sensor by
adding init_cmd entry in the driver data. dht20 sensor is compatible with
aht10 hwmon driver with this change.

Tested on TI am62x SK board with dht20 sensor connected at i2c-2 port.

Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
Link: https://lore.kernel.org/r/2025112-94320-906858@bhairav-test.ee.iitb.ac.in
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Documentation/hwmon/aht10.rst
drivers/hwmon/Kconfig
drivers/hwmon/aht10.c

index 213644b4ecba6e5828eb2630eeb2d2190715825c..7903b6434326d0304b5c2004dcb66c61a60a59a1 100644 (file)
@@ -20,6 +20,14 @@ Supported chips:
 
       English: http://www.aosong.com/userfiles/files/media/Data%20Sheet%20AHT20.pdf
 
+  * Aosong DHT20
+
+    Prefix: 'dht20'
+
+    Addresses scanned: None
+
+    Datasheet: https://www.digikey.co.nz/en/htmldatasheets/production/9184855/0/0/1/101020932
+
 Author: Johannes Cornelis Draaijer <jcdra1@gmail.com>
 
 
@@ -33,7 +41,7 @@ The address of this i2c device may only be 0x38
 Special Features
 ----------------
 
-AHT20 has additional CRC8 support which is sent as the last byte of the sensor
+AHT20, DHT20 has additional CRC8 support which is sent as the last byte of the sensor
 values.
 
 Usage Notes
index aa783be9b73d20283d4ca72c61fd35568ade5b05..adf9575400506c50d4731a1259628a5995bcaa1d 100644 (file)
@@ -245,12 +245,12 @@ config SENSORS_ADT7475
          will be called adt7475.
 
 config SENSORS_AHT10
-       tristate "Aosong AHT10, AHT20"
+       tristate "Aosong AHT10, AHT20, DHT20"
        depends on I2C
        select CRC8
        help
-         If you say yes here, you get support for the Aosong AHT10 and AHT20
-         temperature and humidity sensors
+         If you say yes here, you get support for the Aosong AHT10, AHT20 and
+         DHT20 temperature and humidity sensors
 
          This driver can also be built as a module. If so, the module
          will be called aht10.
index 8b90b661c393e5788e9e1da27ef43453705e91e3..007befdba9776fa308908f10a45ad537b4b1bd26 100644 (file)
@@ -37,6 +37,8 @@
 #define AHT10_CMD_MEAS 0b10101100
 #define AHT10_CMD_RST  0b10111010
 
+#define DHT20_CMD_INIT 0x71
+
 /*
  * Flags in the answer byte/command
  */
 
 #define AHT10_MAX_POLL_INTERVAL_LEN    30
 
-enum aht10_variant { aht10, aht20 };
+enum aht10_variant { aht10, aht20, dht20};
 
 static const struct i2c_device_id aht10_id[] = {
        { "aht10", aht10 },
        { "aht20", aht20 },
+       { "dht20", dht20 },
        { },
 };
 MODULE_DEVICE_TABLE(i2c, aht10_id);
@@ -75,6 +78,7 @@ MODULE_DEVICE_TABLE(i2c, aht10_id);
  *              AHT10/AHT20
  *   @crc8: crc8 support flag
  *   @meas_size: measurements data size
+ *   @init_cmd: Initialization command
  */
 
 struct aht10_data {
@@ -85,6 +89,7 @@ struct aht10_data {
        int humidity;
        bool crc8;
        unsigned int meas_size;
+       u8 init_cmd;
 };
 
 /*
@@ -94,13 +99,13 @@ struct aht10_data {
  */
 static int aht10_init(struct aht10_data *data)
 {
-       const u8 cmd_init[] = {AHT10_CMD_INIT, AHT10_CAL_ENABLED | AHT10_MODE_CYC,
+       const u8 cmd_init[] = {data->init_cmd, AHT10_CAL_ENABLED | AHT10_MODE_CYC,
                               0x00};
        int res;
        u8 status;
        struct i2c_client *client = data->client;
 
-       res = i2c_master_send(client, cmd_init, 3);
+       res = i2c_master_send(client, cmd_init, sizeof(cmd_init));
        if (res < 0)
                return res;
 
@@ -336,9 +341,17 @@ 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;
+               break;
+       case dht20:
+               data->meas_size = AHT20_MEAS_SIZE;
+               data->crc8 = true;
+               crc8_populate_msb(crc8_table, AHT20_CRC8_POLY);
+               data->init_cmd = DHT20_CMD_INIT;
                break;
        default:
                data->meas_size = AHT10_MEAS_SIZE;
+               data->init_cmd = AHT10_CMD_INIT;
                break;
        }