iio: humidity: Add driver for ti HDC302x humidity sensors
Subsystems (3)
Li peiyu
maintainerv4 cover iio: humidity: Add driver for ti HDC302x humidity sensors
Add support for HDC302x integrated capacitive based relative humidity (RH) and temperature sensor.
This driver supports reading values, reading the maximum and minimum of values and controlling the integrated heater of the sensor.
---
changes in v4:
iio core:
- Add an IIO_CHAN_INFO_TROUGH modifier for minimum values.
iio ABI:
- Document the new _TROUGH modifier.
sensor driver:
- Add MAINTAINERS.
- Use new IIO_CHAN_INFO_TROUGH modifier.
- Support the complete heater range.
- Remove measurement values from the data structure.
- Use guard(mutex)(...), make the code simpler
- Removed buffer mode and direct mode conversion code
- Minor coding-style fixes.
dt-bindings:
- removed unnecessary example
- add vdd-supply to the example
changes in v3:
sensor driver:
- Removed the custom ABI
- Give up calculating values in the driver
- Use read_avail callback to get available parameters
- Changed the scope of the lock to make the code more concise
- Fixed the code format issue
dt-bindings:
- Use a fallback compatible
changes in v2:
sensor driver:
- Added static modification to global variables
- change the methord to read peak value
dt-bindings:
- change the maintainers to me.
- hdc3020,hdc3021,hdc3022 are compatible,I've changed the dirver.
- change the node name to humidity-sensor.
---
Javier Carrasco (2):
iio: core: introduce trough modifier for minimum values
iio: ABI: document temperature and humidity peak/trough raw attributes
Li peiyu (2):
dt-bindings: iio: humidity: Add TI HDC302x support
iio: humidity: Add driver for TI HDC302x humidity sensors
Documentation/ABI/testing/sysfs-bus-iio | 13 +- .../bindings/iio/humidity/ti,hdc3020.yaml | 55 +++ MAINTAINERS | 8 + drivers/iio/humidity/Kconfig | 12 + drivers/iio/humidity/Makefile | 1 + drivers/iio/humidity/hdc3020.c | 468 +++++++++++++++++++++ drivers/iio/industrialio-core.c | 1 + include/linux/iio/types.h | 1 + 8 files changed, 558 insertions(+), 1 deletion(-)
---
base-commit: 33cc938e65a98f1d29d0a18403dbbee050dcad9a
Best regards,
Li peiyu
maintainerPATCH v4 1/4 iio: core: introduce trough modifier for minimum values
From: Javier Carrasco <[email protected]>
The IIO_CHAN_INFO_PEAK modifier is used for maximum values and currently there is no equivalent for minimum values. Instead of overloading the existing peak modifier, a new modifier can be added.
In principle there is no need to add a _TROUGH_SCALE modifier as the scale will be the same as the one required for the INFO_PEAK modifier, which in turn is sometimes omitted if a single scale for peaks and raw values is required.
Add an IIO_CHAN_INFO_TROUGH modifier for minimum values.
--- drivers/iio/industrialio-core.c | 1 + include/linux/iio/types.h | 1 + 2 files changed, 2 insertions(+)
drivers/iio/industrialio-core.c +1 -0
@@ -182,6 +182,7 @@ static const char * const iio_chan_info_postfix[] = { [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type", [IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient", [IIO_CHAN_INFO_ZEROPOINT] = "zeropoint", + [IIO_CHAN_INFO_TROUGH] = "trough_raw", };/** * iio_device_id() - query the unique ID for the device
include/linux/iio/types.h +1 -0
@@ -68,6 +68,7 @@ enum iio_chan_info_enum {IIO_CHAN_INFO_THERMOCOUPLE_TYPE ,IIO_CHAN_INFO_CALIBAMBIENT ,IIO_CHAN_INFO_ZEROPOINT , + IIO_CHAN_INFO_TROUGH, };#endif /* _IIO_TYPES_H_ */
Signature · 1 line
2.34.1
Li peiyu
maintainerPATCH v4 2/4 iio: ABI: document temperature and humidity peak/trough raw attributes
In reply to Li peiyuFrom: Javier Carrasco <[email protected]>
The in_temp_peak_raw attribute is already in use, but its documentation is still missing. The in_humidityrelative_raw must be documented for a new iio user that supports this attribute. Add temp and humidityrelative use cases.
When at it, remove an extra blank space in the description.
For users that support minimum values, a new in_<type>_trough_raw attribute is required. Add this attribute and document the first uses of it for temp and humidityrelative types.
--- Documentation/ABI/testing/sysfs-bus-iio | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-iio +12 -1
@@ -362,10 +362,21 @@ Description: What: /sys/bus/iio/devices/iio:deviceX/in_accel_x_peak_raw What: /sys/bus/iio/devices/iio:deviceX/in_accel_y_peak_raw What: /sys/bus/iio/devices/iio:deviceX/in_accel_z_peak_raw +What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_peak_raw +What: /sys/bus/iio/devices/iio:deviceX/in_temp_peak_raw KernelVersion: 2.6.36 Contact: [email protected] Description: - Highest value since some reset condition. These + Highest value since some reset condition. These + attributes allow access to this and are otherwise + the direct equivalent of the <type>Y[_name]_raw attributes. + +What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_trough_raw +What: /sys/bus/iio/devices/iio:deviceX/in_temp_trough_raw +KernelVersion: 6.7 +Contact: [email protected] +Description: + Lowest value since some reset condition. These attributes allow access to this and are otherwise the direct equivalent of the <type>Y[_name]_raw attributes.
Signature · 1 line
2.34.1
Li peiyu
maintainerPATCH v4 3/4 iio: humidity: Add driver for ti HDC302x humidity sensors
In reply to Li peiyuAdd support for HDC302x integrated capacitive based relative humidity (RH) and temperature sensor.
This driver supports reading values, reading the maximum and minimum of values and controlling the integrated heater of the sensor.
--- MAINTAINERS | 8 + drivers/iio/humidity/Kconfig | 12 + drivers/iio/humidity/Makefile | 1 + drivers/iio/humidity/hdc3020.c | 468 +++++++++++++++++++++++++++++++++ 4 files changed, 489 insertions(+) create mode 100644 drivers/iio/humidity/hdc3020.c
MAINTAINERS +8 -0
@@ -21795,6 +21795,14 @@ F: Documentation/devicetree/bindings/media/i2c/ti,ds90* F: drivers/media/i2c/ds90* F: include/media/i2c/ds90* +TI HDC302X HUMIDITY DRIVER +M: Javier Carrasco <[email protected]> +M: Li peiyu <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml +F: drivers/iio/humidity/hdc3020.c + TI ICSSG ETHERNET DRIVER (ICSSG) R: MD Danish Anwar <[email protected]> R: Roger Quadros <[email protected]>
drivers/iio/humidity/Kconfig +12 -0
@@ -48,6 +48,18 @@ config HDC2010 To compile this driver as a module, choose M here: the module will be called hdc2010. +config HDC3020 + tristate "TI HDC3020 relative humidity and temperature sensor" + depends on I2C + select CRC8 + help + Say yes here to build support for the Texas Instruments + HDC3020, HDC3021 and HDC3022 relative humidity and temperature + sensors. + + To compile this driver as a module, choose M here: the module + will be called hdc3020. + config HID_SENSOR_HUMIDITY tristate "HID Environmental humidity sensor" depends on HID_SENSOR_HUB
drivers/iio/humidity/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_AM2315) += am2315.o obj-$(CONFIG_DHT11) += dht11.o obj-$(CONFIG_HDC100X) += hdc100x.o obj-$(CONFIG_HDC2010) += hdc2010.o +obj-$(CONFIG_HDC3020) += hdc3020.o obj-$(CONFIG_HID_SENSOR_HUMIDITY) += hid-sensor-humidity.o hts221-y := hts221_core.o \
drivers/iio/humidity/hdc3020.c new file +468 -0
468 lines not on this page · raw message
Signature · 1 line
2.34.1
Li peiyu
maintainerPATCH v4 4/4 iio: humidity: Add TI HDC302x support
In reply to Li peiyuAdd device tree bindings for HDC3020/HDC3021/HDC3022 humidity and temperature sensors.
--- .../bindings/iio/humidity/ti,hdc3020.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml new file +55 -0
@@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/humidity/ti,hdc3020.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HDC3020/HDC3021/HDC3022 humidity and temperature iio sensors + +maintainers: + - Li peiyu <[email protected]> + - Javier Carrasco <[email protected]> + +description: + https://www.ti.com/lit/ds/symlink/hdc3020.pdf + + The HDC302x is an integrated capacitive based relative humidity (RH) + and temperature sensor. + +properties: + compatible: + oneOf: + - items: + - enum: + - ti,hdc3021 + - ti,hdc3022 + - const: ti,hdc3020 + - items: + - const: ti,hdc3020 + + interrupts: + maxItems: 1 + + vdd-supply: true + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + humidity-sensor@47 { + compatible = "ti,hdc3021", "ti,hdc3020"; + reg = <0x47>; + vdd-supply = <&vcc_3v3>; + }; + };
Signature · 1 line
2.34.1
Re: [PATCH v4 4/4] iio: humidity: Add TI HDC302x support
Quoted 4 lines · Li peiyu
Add device tree bindings for HDC3020/HDC3021/HDC3022 humidity and temperature sensors.
Signed-off-by Li peiyu <[email protected]>
If there is a resubmission, please prepend "dt-bindings: " to your commit $subject. Otherwise, I am only with this.
Thanks,
Conor.
Jonathan Cameron
maintainerRe: [PATCH v4 1/4] iio: core: introduce trough modifier for minimum values
In reply to Li peiyuQuoted 11 lines · On Wed, 6 Dec 2023 21:48:19 +0800 Li peiyu <[email protected]> wrote:
From: Javier Carrasco <[email protected]>
The
IIO_CHAN_INFO_PEAKmodifier is used for maximum values and currently there is no equivalent for minimum values. Instead of overloading the existing peak modifier, a new modifier can be added.In principle there is no need to add a
_TROUGH_SCALEmodifier as the scale will be the same as the one required for theINFO_PEAKmodifier, which in turn is sometimes omitted if a single scale for peaks and raw values is required.
Terminology is a bit mixed up in here. Modifiers in IIO are things like the axis or a color for light sensors. This is an info element that applies to a channel (modified or not).
Other than that looks good to me.
Quoted 32 lines
Add an
IIO_CHAN_INFO_TROUGHmodifier for minimum values.Signed-off-by Javier Carrasco <[email protected]>--- drivers/iio/industrialio-core.c | 1 + include/linux/iio/types.h | 1 + 2 files changed, 2 insertions(+)drivers/iio/industrialio-core.c +1
-0@@ -182,6 +182,7 @@ static const char * const iio_chan_info_postfix[] = { [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type", [IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient", [IIO_CHAN_INFO_ZEROPOINT] = "zeropoint", + [IIO_CHAN_INFO_TROUGH] = "trough_raw", };/** * iio_device_id() - query the unique ID for the device include/linux/iio/types.h +1
-0@@ -68,6 +68,7 @@ enum iio_chan_info_enum {IIO_CHAN_INFO_THERMOCOUPLE_TYPE ,IIO_CHAN_INFO_CALIBAMBIENT ,IIO_CHAN_INFO_ZEROPOINT , + IIO_CHAN_INFO_TROUGH, };#endif /* _IIO_TYPES_H_ */
Jonathan Cameron
maintainerQuoted 9 lines · On Wed, 6 Dec 2023 21:51:23 +0800 Li peiyu <[email protected]> wrote:
Add support for HDC302x integrated capacitive based relative humidity (RH) and temperature sensor.
This driver supports reading values, reading the maximum and minimum of values and controlling the integrated heater of the sensor.Co-developed-by Javier Carrasco <[email protected]>Signed-off-by Javier Carrasco <[email protected]>Signed-off-by Li peiyu <[email protected]>
Hi.
A few minor comments inline from a fresh thread through.
Jonathan
Quoted 15 lines
hts221-y := hts221_core.o \
drivers/iio/humidity/hdc3020.c new file +8
-0@@ -0,0 +1,468 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* hdc3020.c - Support for the TI HDC3020,HDC3021 and HDC3022 +* temperature + relative humidity sensors +* +* Copyright (C) 2023 +* +* Datasheet: https://www.ti.com/lit/ds/symlink/hdc3020.pdf
drivers/iio/humidity/hdc3020.c line 18
Quoted 10 lines
drivers/iio/humidity/hdc3020.c new file +10
-0+*/ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/bitops.h> +#include <linux/crc8.h> +#include <linux/delay.h> +#include <linux/mutex.h> +#include <linux/cleanup.h>
This block should be in alphabetical order. (IIO convention, other bits of the kernel use other weird ordering rules!)
J
drivers/iio/humidity/hdc3020.c line 48
Quoted 5 lines
drivers/iio/humidity/hdc3020.c new file +5
-0+struct hdc3020_data { +struct i2c_client *client; +/* +* Ensure that only one operation can communicate with the device +* at the same time.
Why? What is being protected. State changes on device perhaps? Good to give more detail as it makes it easier to check the lock is used correctly in the future.
Quoted 18 lines
drivers/iio/humidity/hdc3020.c new file +18
-0+*/ +struct mutex lock; +}; + +static const int hdc3020_heater_vals[] = {0 ,1 ,0x3FFF }; + +static const struct iio_chan_spec hdc3020_channels[] = { + { + .type =IIO_TEMP , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) |BIT (IIO_CHAN_INFO_PEAK ) | +BIT (IIO_CHAN_INFO_TROUGH ) |BIT (IIO_CHAN_INFO_OFFSET ), + }, + { + .type =IIO_HUMIDITYRELATIVE , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) |BIT (IIO_CHAN_INFO_PEAK ) | +BIT (IIO_CHAN_INFO_TROUGH ) |BIT (IIO_CHAN_INFO_OFFSET ),
drivers/iio/humidity/hdc3020.c line 76
Quoted 10 lines
drivers/iio/humidity/hdc3020.c new file +10
-0+ }, + { +/* +* For setting the internal heater, which can be switched on to +* prevent or remove any condensation that may develop when the +* ambient environment approaches its dew point temperature. +*/ + .type = IIO_CURRENT, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_separate_available = 1,
This takes the same bits as info_mask_separate.
So BIT(IIO_CHAN_INFO_RAW) which is probably 1 but I haven't checked.
drivers/iio/humidity/hdc3020.c line 274
Quoted 13 lines
drivers/iio/humidity/hdc3020.c new file +12
-0+ .output = 1, + }, +}; +static int hdc3020_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val, +int *val2,long mask) +{ +struct hdc3020_data *data =iio_priv (indio_dev); +int ret; + +switch (mask) { +case IIO_CHAN_INFO_RAW : {
Odd indent. One table to many for the following few lines.
Quoted 9 lines
drivers/iio/humidity/hdc3020.c new file +8
-0+guard (mutex)(&data->lock); + ret =hdc3020_read_measurement (data, chan->type, val); +if (ret <0 ) +return ret; + +return IIO_VAL_INT ; + } +case IIO_CHAN_INFO_SCALE :
drivers/iio/humidity/hdc3020.c line 318
Quoted 10 lines
drivers/iio/humidity/hdc3020.c new file +10
-0+ *val2 =65536 ; +if (chan->type ==IIO_TEMP ) + *val =175 ; +else + *val =100 ; +return IIO_VAL_FRACTIONAL ; + +case IIO_CHAN_INFO_OFFSET : +if (chan->type ==IIO_TEMP ) + *val =16852 ;
Seems backwards to check the type, but not deal with it being wrong. Check the inverse and return an error.
if (chan->type != IIO_TEMP) return -EINVAL; *val = ...
Quoted 31 lines
drivers/iio/humidity/hdc3020.c new file +30
-0+return IIO_VAL_INT ; + } + +return -EINVAL ; +} + +static int hdc3020_probe (struct i2c_client *client) +{ +struct iio_dev *indio_dev; +struct hdc3020_data *data; +int ret; + +if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) +return -EOPNOTSUPP ; + + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); +if (!indio_dev) +return -ENOMEM ; + + data =iio_priv (indio_dev); + data->client = client; +mutex_init (&data->lock); + +crc8_populate_msb (hdc3020_crc8_table,HDC3020_CRC8_POLYNOMIAL ); + + indio_dev->name ="hdc3020" ; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = &hdc3020_info; + indio_dev->channels = hdc3020_channels; + indio_dev->num_channels =ARRAY_SIZE (hdc3020_channels);
drivers/iio/humidity/hdc3020.c line 429
Quoted 10 lines
drivers/iio/humidity/hdc3020.c new file +10
-0+ + ret =hdc3020_write_bytes (data,HDC3020_S_AUTO_10HZ_MOD0 ,2 ); +if (ret) +return dev_err_probe (&client->dev, ret, +"Unable to set up measurement\n" ); + + ret =devm_add_action_or_reset (&data->client->dev, hdc3020_stop, data); +if (ret) +return dev_err_probe (&client->dev, ret, +"Failed to add device\n" );
This isn't adding the device... So the error message needs an update. It's vanishingly unlikely to actually happen, so fine to not have a message at all for this one.
Quoted 8 lines
drivers/iio/humidity/hdc3020.c new file +8
-0+ + ret =devm_iio_device_register (&data->client->dev, indio_dev); +if (ret) +return dev_err_probe (&client->dev, ret, +"Failed to add device\n" ); + +return 0 ; +}
Re: [PATCH v4 4/4] iio: humidity: Add TI HDC302x support
In reply to Li peiyuQuoted 2 lines · Li peiyu
Add device tree bindings for HDC3020/HDC3021/HDC3022 humidity and temperature sensors.
Please use subject prefixes matching the subsystem. You can get them for example with git log --oneline -- DIRECTORY_OR_FILE on the directory your patch is touching.
Quoted 3 lines
Signed-off-by Li peiyu <[email protected]>---
Where is the changelog? It was here.
This patch looks worse than it was before.
Quoted 27 lines
.../bindings/iio/humidity/ti,hdc3020.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yamlDocumentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml new file +17
-0@@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/humidity/ti,hdc3020.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HDC3020/HDC3021/HDC3022 humidity and temperature iio sensors + +maintainers: + - Li peiyu <[email protected]> + - Javier Carrasco <[email protected]> + +description: + https://www.ti.com/lit/ds/symlink/hdc3020.pdf + + The HDC302x is an integrated capacitive based relative humidity (RH) + and temperature sensor.
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml line 27
Quoted 10 lines
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml new file +10
-0+ +properties: + compatible: + oneOf: + - items: + - enum: + - ti,hdc3021 + - ti,hdc3022 + - const: ti,hdc3020 + - items:
Drop items
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml line 40
Quoted 13 lines
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml new file +13
-0+ - const: ti,hdc3020 + + interrupts: + maxItems: 1 + + vdd-supply: true + + reg: + maxItems: 1 + +required: + - compatible + - reg
How did you respond to Jonathan's feedback?
Best regards,
Krzysztof
peiyu li
maintainerRe: [PATCH v4 4/4] iio: humidity: Add TI HDC302x support
Quoted 19 lines · Krzysztof Kozlowski
Quoted 19 lines
+---
+$id: http://devicetree.org/schemas/iio/humidity/ti,hdc3020.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml new file +16
-0+ +title: HDC3020/HDC3021/HDC3022 humidity and temperature iio sensors + +maintainers: + - Li peiyu <[email protected]> + - Javier Carrasco <[email protected]> + +description: + https://www.ti.com/lit/ds/symlink/hdc3020.pdf + + The HDC302x is an integrated capacitive based relative humidity (RH) + and temperature sensor. + +properties: + compatible: + oneOf:
Quoted 8 lines
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml line 27
Quoted 6 lines
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml new file +6
-0+ - items: + - enum: + - ti,hdc3021 + - ti,hdc3022 + - const: ti,hdc3020 + - items:Drop items
Does that mean just drop the "items" tag or drop the whole items with "- const: ti,hdc3020"?
Thanks,
Li peiyu
Re: [PATCH v4 4/4] iio: humidity: Add TI HDC302x support
Quoted 30 lines · peiyu li
Quoted 19 lines · Krzysztof Kozlowski
Quoted 19 lines
+---
+$id: http://devicetree.org/schemas/iio/humidity/ti,hdc3020.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml new file +16
-0+ +title: HDC3020/HDC3021/HDC3022 humidity and temperature iio sensors + +maintainers: + - Li peiyu <[email protected]> + - Javier Carrasco <[email protected]> + +description: + https://www.ti.com/lit/ds/symlink/hdc3020.pdf + + The HDC302x is an integrated capacitive based relative humidity (RH) + and temperature sensor. + +properties: + compatible: + oneOf:Quoted 8 lines
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml line 27
Quoted 6 lines
Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml new file +6
-0+ - items: + - enum: + - ti,hdc3021 + - ti,hdc3022 + - const: ti,hdc3020 + - items:Drop items
Quoted 2 lines
Does that mean just drop the "items" tag or drop the whole items with "- const: ti,hdc3020"?
On this one line with "items", and re-indent appropriately.
Best regards,
Krzysztof