Skip to contentSkip to conversation

add support for Aosong AM2320

PATCH In review Nicolás Antinori 2 participants 4 messages Aug 20 – Aug 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover add support for Aosong AM2320

The AM2320 is fully compatible with the AM2315 sensor in terms of I2C communication protocol and measurement conversions.

This patch series adds am2320 to the i2c_device_id table, creates of_device_id table and adds both am2315 and am2320 to trivial-devices.yml dt bindings.

v4:
- Addressed minor styling issues in driver's C code pointed by Andy Shevchenko (carried "Reviewed-by: Andy Shevchenko <...> from v3)
- Adapted commit message pointed by Marcelo Schmitt (carried "Reviewed-by: Marcelo Schmitt <...>" from v3)
- Carried Acked-by: "Krzysztof Kozlowski <...>: from v3 dt-bindings patch since bindings patch did not change.

Note: I carried tags from v3 because reviewers declared the tag after pointing things that were resolved in v4 (and the dt-bindings one because the patch did not change from v3 to v4). If this is a mistake please let me know.

v3: [3]
- Added "aosong,am2315" and "aosong,am2320" to trivial-devices.yml.
- Added of_device_id table.
- Replaced using a constant for driver's name with chip_info struct.
- Separated code changes and dt-bindings changes in two commits.

v2: [2]
- Generalized KConfig description text.

v1: [1]

[1] https://lore.kernel.org/all/[email protected]/T/#u
[2] https://lore.kernel.org/all/[email protected]/T/#u
[3] https://lore.kernel.org/all/[email protected]/

Nicolás Antinori (2):
dt-bindings: trivial-devices: add Aosong AM2315 and AM2320 chips
iio: humidity: am2315: add support for am2320

 .../devicetree/bindings/trivial-devices.yaml  |  2 ++
 drivers/iio/humidity/Kconfig                  |  8 +++--
 drivers/iio/humidity/am2315.c                 | 34 ++++++++++++++++---
 3 files changed, 36 insertions(+), 8 deletions(-)

--
2.47.3

#1 lore raw

PATCH v4 1/2 dt-bindings: trivial-devices: add Aosong AM2315 and AM2320 chips

Aosong AM2315 and AM2320 are temperature and humidity sensors that do not require configuration.

---
 Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/trivial-devices.yaml +2 -0
index 435c4baab436..92b757579eef 100644
@@ -62,6 +62,8 @@ properties:
             # Aosong temperature & humidity sensors with I2C interface
           - aosong,aht10
           - aosong,aht20
+          - aosong,am2315
+          - aosong,am2320
           - aosong,dht20
             # Arduino microcontroller interface over SPI on UnoQ board
           - arduino,unoq-mcu

--
2.47.3

#2 lore raw

PATCH v4 2/2 iio: humidity: am2315: add support for am2320

In reply to Nicolás Antinori

The AM2320 design is fully compatible with AM2315 in terms of I2C communication protocol and measurement conversions.

Add the "am2320" entry to the i2c_device_id table and register a of_device_id table to match against devices declared in device tree.

---
 drivers/iio/humidity/Kconfig  |  8 +++++---
 drivers/iio/humidity/am2315.c | 34 +++++++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 8 deletions(-)
drivers/iio/humidity/Kconfig +5 -3
index 54f11f000b6f..13e267943f67 100644
@@ -5,13 +5,15 @@
 menu "Humidity sensors"
 
 config AM2315
-	tristate "Aosong AM2315 relative humidity and temperature sensor"
+	tristate "Aosong AM2315 and similar relative humidity and temperature sensor"
 	depends on I2C
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	help
-	  If you say yes here you get support for the Aosong AM2315
-	  relative humidity and ambient temperature sensor.
+	  If you say yes here you get support for the Aosong relative
+	  humidity and ambient temperature sensors:
+	  - AM2315
+	  - AM2320
 
 	  This driver can also be built as a module. If so, the module will
 	  be called am2315.
drivers/iio/humidity/am2315.c +29 -5
index f29baa251f9f..5c7582f3a4f9 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Aosong AM2315 relative humidity and temperature
+ * Aosong AM2315 and similar relative humidity and temperature
  *
  * Copyright (c) 2016, Intel Corporation.
  *
@@ -27,7 +27,17 @@
 #define AM2315_TEMP_OFFSET			4
 #define AM2315_ALL_CHANNEL_MASK			GENMASK(1, 0)
 
-#define AM2315_DRIVER_NAME			"am2315"
+struct am2315_chip_info {
+	const char *name;
+};
+
+static const struct am2315_chip_info am2315_chip_info = {
+	.name = "am2315",
+};
+
+static const struct am2315_chip_info am2320_chip_info = {
+	.name = "am2320",
+};
 
 struct am2315_data {
 	struct i2c_client *client;
@@ -220,9 +230,14 @@ static const struct iio_info am2315_info = {
 static int am2315_probe(struct i2c_client *client)
 {
 	int ret;
+	const struct am2315_chip_info *chip_info;
 	struct iio_dev *indio_dev;
 	struct am2315_data *data;
 
+	chip_info = i2c_get_match_data(client);
+	if (!chip_info)
+		return -ENODATA;
+
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
 	if (!indio_dev)
 		return -ENOMEM;
@@ -233,7 +248,7 @@ static int am2315_probe(struct i2c_client *client)
 	mutex_init(&data->lock);
 
 	indio_dev->info = &am2315_info;
-	indio_dev->name = AM2315_DRIVER_NAME;
+	indio_dev->name = chip_info->name;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->channels = am2315_channels;
 	indio_dev->num_channels = ARRAY_SIZE(am2315_channels);
@@ -249,8 +264,16 @@ static int am2315_probe(struct i2c_client *client)
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
+static const struct of_device_id am2315_of_match[] = {
+	{ .compatible = "aosong,am2315", .data = &am2315_chip_info },
+	{ .compatible = "aosong,am2320", .data = &am2320_chip_info },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, am2315_of_match);
+
 static const struct i2c_device_id am2315_i2c_id[] = {
-	{ .name = "am2315" },
+	{ .name = "am2315", .driver_data = (kernel_ulong_t)&am2315_chip_info },
+	{ .name = "am2320", .driver_data = (kernel_ulong_t)&am2320_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, am2315_i2c_id);
@@ -258,6 +281,7 @@ MODULE_DEVICE_TABLE(i2c, am2315_i2c_id);
 static struct i2c_driver am2315_driver = {
 	.driver = {
 		.name = "am2315",
+		.of_match_table = am2315_of_match,
 	},
 	.probe =        am2315_probe,
 	.id_table =         am2315_i2c_id,
@@ -266,5 +290,5 @@ static struct i2c_driver am2315_driver = {
 module_i2c_driver(am2315_driver);
 
 MODULE_AUTHOR("Tiberiu Breana <[email protected]>");
-MODULE_DESCRIPTION("Aosong AM2315 relative humidity and temperature");
+MODULE_DESCRIPTION("Aosong AM2315 and similar relative humidity and temperature");
 MODULE_LICENSE("GPL v2");

--
2.47.3

maintainer
#3 lore raw
In reply to Nicolás Antinori
Quoted 6 lines · On Thu, 20 Aug 2026 11:31:08 -0300 Nicolás Antinori…

The AM2320 is fully compatible with the AM2315 sensor in terms of I2C communication protocol and measurement conversions.

This patch series adds am2320 to the i2c_device_id table, creates of_device_id table and adds both am2315 and am2320 to trivial-devices.yml dt bindings.

Hi Nicolás,

Applied to the testing branch of iio.git. I'll rebase that on rc1 once that is available and push out as the togreg branch that linux-next picks up.

Quoted 9 lines

v4:
- Addressed minor styling issues in driver's C code pointed by Andy Shevchenko (carried "Reviewed-by: Andy Shevchenko <...> from v3)
- Adapted commit message pointed by Marcelo Schmitt (carried "Reviewed-by: Marcelo Schmitt <...>" from v3)
- Carried Acked-by: "Krzysztof Kozlowski <...>: from v3 dt-bindings patch since bindings patch did not change.

Quoted 4 lines

Note: I carried tags from v3 because reviewers declared the tag after pointing things that were resolved in v4 (and the dt-bindings one because the patch did not change from v3 to v4). If this is a mistake please let me know.

You got it right.

Thanks

Jonathan

Quoted 28 lines

v3: [3]
- Added "aosong,am2315" and "aosong,am2320" to trivial-devices.yml.
- Added of_device_id table.
- Replaced using a constant for driver's name with chip_info struct.
- Separated code changes and dt-bindings changes in two commits.

v2: [2]
- Generalized KConfig description text.

v1: [1]

[1] https://lore.kernel.org/all/[email protected]/T/#u
[2] https://lore.kernel.org/all/[email protected]/T/#u
[3] https://lore.kernel.org/all/[email protected]/

Nicolás Antinori (2):
dt-bindings: trivial-devices: add Aosong AM2315 and AM2320 chips
iio: humidity: am2315: add support for am2320

 .../devicetree/bindings/trivial-devices.yaml  |  2 ++
 drivers/iio/humidity/Kconfig                  |  8 +++--
 drivers/iio/humidity/am2315.c                 | 34 ++++++++++++++++---
 3 files changed, 36 insertions(+), 8 deletions(-)

--
2.47.3