add support for Aosong AM2320
Subsystems (2)
v3 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.
v3:
- 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: Link [2]
- Generalized KConfig description text.
v1: Link [1]
[1] https://lore.kernel.org/all/[email protected]/T/#u
[2] https://lore.kernel.org/all/[email protected]/T/#u
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
PATCH v3 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
@@ -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
Re: [PATCH v3 1/2] dt-bindings: trivial-devices: add Aosong AM2315 and AM2320 chips
Quoted 7 lines · Nicolás Antinori
Aosong AM2315 and AM2320 are temperature and humidity sensors that do not require configuration.
Signed-off-by Nicolás Antinori <[email protected]>--- Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ 1 file changed, 2 insertions(+)
Best regards,
Krzysztof
PATCH v3 2/2 iio: humidity: am2315: add support for am2320
In reply to Nicolás AntinoriThe AM2320 is fully compatible with the AM2315 sensor in terms of I2C communication protocol and measurement conversions.
Add the "am2320" entry to the i2c_device_id table and create of_device_id table.
--- drivers/iio/humidity/Kconfig | 8 +++++--- drivers/iio/humidity/am2315.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-)
drivers/iio/humidity/Kconfig +5 -3
@@ -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
@@ -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 -EINVAL ; + 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
Re: [PATCH v3 2/2] iio: humidity: am2315: add support for am2320
Quoted 5 lines · Nicolás Antinori
The AM2320 is fully compatible with the AM2315 sensor in terms of I2C communication protocol and measurement conversions.
Add the "am2320" entry to the
i2c_device_idtable and createof_device_idtable.
...
drivers/iio/humidity/am2315.c static const struct iio_info am2315_info = { · line 239
Quoted 3 lines
drivers/iio/humidity/am2315.c +3
-0+ chip_info =i2c_get_match_data (client); +if (!chip_info) +return -EINVAL ;
-ENODATA
...
drivers/iio/humidity/am2315.c static int am2315_probe(struct i2c_client *client) · line 270
Quoted 4 lines
drivers/iio/humidity/am2315.c +4
-0+static const struct of_device_id am2315_of_match[] = { + { .compatible ="aosong,am2315" , .data = &am2315_chip_info }, + { .compatible ="aosong,am2320" , .data = &am2320_chip_info }, + {}
Same style as elsewhere, id est
{ }Quoted 1 line
+};
With the above being addressed,
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/2] iio: humidity: am2315: add support for am2320
In reply to Nicolás AntinoriQuoted 8 lines · Nicolás Antinori
The AM2320 is fully compatible with the AM2315 sensor in terms of I2C communication protocol and measurement conversions.
Add the "am2320" entry to the
i2c_device_idtable and createof_device_idtable.Signed-off-by Nicolás Antinori <[email protected]>---
Some optional suggestions for the commit message:
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.
I see nothing else to improve besides what Andy already mentioned. With those sorted out,