2024-01-03 12:09:18

by Javier Carrasco

[permalink] [raw]
Subject: [PATCH v2 0/3] iio: light: add support for AMS AS7331

The AMS AS7331 UV light sensor measures three ultraviolet bands (UVA,
UVB and UVC, also known as deep UV or DUV) as well as temperature.

This device is practically identical to the AMS AS73211 XYZ True Color
sensor that is already supported by the iio subsystem, except for the
photodiodes used to aquire the desired light wavelengths.

In order to reuse code and reduce maintenance load, this series extends
the AS73211 driver to support the AS7331 as well.

Note that the UVA and UVB light modifiers have not been merged into the
mainline kernel yet, but they are already available in Greg's char-misc
git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
in the char-misc-next branch.

The original device AS73211 supported by the driver could only be tested
briefly due to the lack of hardware. Instead, the i2c-stub module has
been used to make sure that the driver registers the iio device properly
and the attributes exported to sysfs are correct. Some basic register
assignments reported the expected intensity scales and in principle
nothing else should have been affected by the modifications in the code.

Signed-off-by: Javier Carrasco <[email protected]>
---
Changes in v2:
- as73211.c: Use IIO_VAL_FRACTIONAL to retrieve scales of AS73211.
- as73211.c: simplify device-specific data retrieval in probe function.
- as73211.c: minor coding-style fix (shorter line).
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Javier Carrasco (3):
iio: light: as73211: use IIO_VAL_FRACTIONAL for intensity scales
dt-bindings: iio: light: as73211: add support for as7331
iio: light: as73211: add support for as7331

.../devicetree/bindings/iio/light/ams,as73211.yaml | 7 +-
drivers/iio/light/Kconfig | 5 +-
drivers/iio/light/as73211.c | 142 +++++++++++++++++----
3 files changed, 123 insertions(+), 31 deletions(-)
---
base-commit: e9215fcca2561b208c78359110ee4009b454f761
change-id: 20231220-as7331-88a25ceeb66d

Best regards,
--
Javier Carrasco <[email protected]>



2024-01-03 12:09:29

by Javier Carrasco

[permalink] [raw]
Subject: [PATCH v2 1/3] iio: light: as73211: use IIO_VAL_FRACTIONAL for intensity scales

The scale values associated to the light channels are calculated as a
division that can be better expressed as an IIO_VAL_FRACTIONAL type
instead of the current IIO_VAL_INT.

Note that the constant values used for the calculation were scaled up to
work with integers, turning the nW/cm^2 units from the datasheet into
nW/m^2, which would not be necessary with the IIO_VAL_FRACTIONAL type.
But to avoid issues from current users of the driver, the units must be
kept.

Signed-off-by: Javier Carrasco <[email protected]>
---
drivers/iio/light/as73211.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c
index ec97a3a46839..b4c6f389a292 100644
--- a/drivers/iio/light/as73211.c
+++ b/drivers/iio/light/as73211.c
@@ -356,25 +356,24 @@ static int as73211_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec cons
return IIO_VAL_INT_PLUS_MICRO;

case IIO_INTENSITY: {
- unsigned int scale;

switch (chan->channel2) {
case IIO_MOD_X:
- scale = AS73211_SCALE_X;
+ *val = AS73211_SCALE_X;
break;
case IIO_MOD_Y:
- scale = AS73211_SCALE_Y;
+ *val = AS73211_SCALE_Y;
break;
case IIO_MOD_Z:
- scale = AS73211_SCALE_Z;
+ *val = AS73211_SCALE_Z;
break;
default:
return -EINVAL;
}
- scale /= as73211_gain(data);
- scale /= as73211_integration_time_1024cyc(data);
- *val = scale;
- return IIO_VAL_INT;
+ *val2 = as73211_integration_time_1024cyc(data) *
+ as73211_gain(data);
+
+ return IIO_VAL_FRACTIONAL;

default:
return -EINVAL;

--
2.39.2


2024-01-03 12:10:04

by Javier Carrasco

[permalink] [raw]
Subject: [PATCH v2 2/3] dt-bindings: iio: light: as73211: add support for as7331

This device has the same properties and I2C addresses as the as73211.
The only difference between them is the photodiodes they use internally,
which in this case is irrelevant for the bindings.

Acked-by: Conor Dooley <[email protected]>
Signed-off-by: Javier Carrasco <[email protected]>
---
Documentation/devicetree/bindings/iio/light/ams,as73211.yaml | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/light/ams,as73211.yaml b/Documentation/devicetree/bindings/iio/light/ams,as73211.yaml
index 0e8cd02759b3..062a038aa0ff 100644
--- a/Documentation/devicetree/bindings/iio/light/ams,as73211.yaml
+++ b/Documentation/devicetree/bindings/iio/light/ams,as73211.yaml
@@ -4,19 +4,22 @@
$id: http://devicetree.org/schemas/iio/light/ams,as73211.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

-title: AMS AS73211 JENCOLOR(R) Digital XYZ Sensor
+title: AMS AS73211 JENCOLOR(R) Digital XYZ Sensor and AMS AS7331 UV Sensor

maintainers:
- Christian Eggers <[email protected]>

description: |
- XYZ True Color Sensor with I2C Interface
+ AMS AS73211 XYZ True Color Sensor with I2C Interface
https://ams.com/documents/20143/36005/AS73211_DS000556_3-01.pdf/a65474c0-b302-c2fd-e30a-c98df87616df
+ AMS AS7331 UVA, UVB and UVC Sensor with I2C Interface
+ https://ams.com/documents/20143/9106314/AS7331_DS001047_4-00.pdf

properties:
compatible:
enum:
- ams,as73211
+ - ams,as7331

reg:
description:

--
2.39.2


2024-01-07 15:58:57

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] iio: light: add support for AMS AS7331

On Wed, 03 Jan 2024 13:08:50 +0100
Javier Carrasco <[email protected]> wrote:

> The AMS AS7331 UV light sensor measures three ultraviolet bands (UVA,
> UVB and UVC, also known as deep UV or DUV) as well as temperature.
>
> This device is practically identical to the AMS AS73211 XYZ True Color
> sensor that is already supported by the iio subsystem, except for the
> photodiodes used to aquire the desired light wavelengths.
>
> In order to reuse code and reduce maintenance load, this series extends
> the AS73211 driver to support the AS7331 as well.
>
> Note that the UVA and UVB light modifiers have not been merged into the
> mainline kernel yet, but they are already available in Greg's char-misc
> git tree which can be found at
> git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
> in the char-misc-next branch.
>
> The original device AS73211 supported by the driver could only be tested
> briefly due to the lack of hardware. Instead, the i2c-stub module has
> been used to make sure that the driver registers the iio device properly
> and the attributes exported to sysfs are correct. Some basic register
> assignments reported the expected intensity scales and in principle
> nothing else should have been affected by the modifications in the code.
>
> Signed-off-by: Javier Carrasco <[email protected]>
Hi Javier,

Series applied - but given timing I'll only push this out as testing for
now as I'll want to rebase the IIO tree on rc1 once available in a couple of
weeks time.

Thanks,

Jonathan

> ---
> Changes in v2:
> - as73211.c: Use IIO_VAL_FRACTIONAL to retrieve scales of AS73211.
> - as73211.c: simplify device-specific data retrieval in probe function.
> - as73211.c: minor coding-style fix (shorter line).
> - Link to v1: https://lore.kernel.org/r/[email protected]
>
> ---
> Javier Carrasco (3):
> iio: light: as73211: use IIO_VAL_FRACTIONAL for intensity scales
> dt-bindings: iio: light: as73211: add support for as7331
> iio: light: as73211: add support for as7331
>
> .../devicetree/bindings/iio/light/ams,as73211.yaml | 7 +-
> drivers/iio/light/Kconfig | 5 +-
> drivers/iio/light/as73211.c | 142 +++++++++++++++++----
> 3 files changed, 123 insertions(+), 31 deletions(-)
> ---
> base-commit: e9215fcca2561b208c78359110ee4009b454f761
> change-id: 20231220-as7331-88a25ceeb66d
>
> Best regards,


2024-01-07 17:34:55

by Javier Carrasco

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] iio: light: add support for AMS AS7331

On 07.01.24 16:58, Jonathan Cameron wrote:
> On Wed, 03 Jan 2024 13:08:50 +0100
> Javier Carrasco <[email protected]> wrote:
>
>> The AMS AS7331 UV light sensor measures three ultraviolet bands (UVA,
>> UVB and UVC, also known as deep UV or DUV) as well as temperature.
>>
>> This device is practically identical to the AMS AS73211 XYZ True Color
>> sensor that is already supported by the iio subsystem, except for the
>> photodiodes used to aquire the desired light wavelengths.
>>
>> In order to reuse code and reduce maintenance load, this series extends
>> the AS73211 driver to support the AS7331 as well.
>>
>> Note that the UVA and UVB light modifiers have not been merged into the
>> mainline kernel yet, but they are already available in Greg's char-misc
>> git tree which can be found at
>> git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
>> in the char-misc-next branch.
>>
>> The original device AS73211 supported by the driver could only be tested
>> briefly due to the lack of hardware. Instead, the i2c-stub module has
>> been used to make sure that the driver registers the iio device properly
>> and the attributes exported to sysfs are correct. Some basic register
>> assignments reported the expected intensity scales and in principle
>> nothing else should have been affected by the modifications in the code.
>>
>> Signed-off-by: Javier Carrasco <[email protected]>
> Hi Javier,
>
> Series applied - but given timing I'll only push this out as testing for
> now as I'll want to rebase the IIO tree on rc1 once available in a couple of
> weeks time.
>
> Thanks,
>
> Jonathan
>
Hi Jonathan,

I am happy with that approach. Some extra time to catch issues before
going live is a good thing anyway.

Thank you and best regards,

Javier Carrasco