Add support for AS7343 multi-spectral sensor
Subsystems (2)
v7 cover Add support for AS7343 multi-spectral sensor
This series adds initial support for the AMS AS7343 14-channel multi-spectral sensor.
The sensor has 14 optical channels (11 visible + NIR + clear + flicker) in total. This initial driver supports reading raw counts from all 12 spectral channels (11 visible + NIR) via sysfs and basic power management.
Not yet supported:
- Configurable integration time and gain
- Interrupt support
- Clear (VIS) channel and flicker detection
Patch 1 adds device tree bindings.
Patch 2 adds the driver.
Testing was performed on a Raspberry Pi 4.
Datasheet: https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf
Changes in v7:
- Specify reg as a const.
- Move additionalProperties after allOf block.
- Clear/set PON during suspend/resume.
- Check for digital saturation before reading spectral data.
Changes in v6:
- Add a ref to leds/common.yaml for the LDR pin in dt bindings.
- Convert ATIME and ASTEP range checks to runtime checks.
- Check for digital saturation before reading spectral data.
Changes in v5:
- Remove the GPIO pin from dt bindings.
- Add autosuspend.
- Start measurements before setting up runtime PM.
Changes in v4:
- Fix led-max-microamp property in dt bindings.
- Use REGCACHE_MAPLE and add volatile table.
- Use PM_RUNTIME_ACQUIRE* when resuming.
Changes in v3:
- Fix gpio description and example in dt.
- Only start measurements after suspend action has been registered.
- Add a mutex and pm_runtime_resume_and_get before reading measurements.
Changes in v2:
- Add the LDR, the interrupt pin, and the GPIO pin to the dt bindings.
- Adjust the default gain to x256 and integration time to 50.1ms as recommended by the datasheet.
- Use read_label instead of .extend
- Remove all unused scan_index related constants.
Chang Yu (2):
dt-bindings: iio: light: add as7343
iio: light: add AS7343 multi-spectral sensor driver
.../bindings/iio/light/ams,as7343.yaml | 64 +++ MAINTAINERS | 7 + drivers/iio/light/Kconfig | 11 + drivers/iio/light/Makefile | 1 + drivers/iio/light/as7343.c | 491 ++++++++++++++++++ 5 files changed, 574 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/ams,as7343.yaml create mode 100644 drivers/iio/light/as7343.c
Signature · 1 line
2.56.0
PATCH v7 1/2 dt-bindings: iio: light: add as7343
Add binding for AMS AS7343 which is a 14-channel multi-spectral sensor with i2c address of 0x39.
The GPIO pin is not described because the datasheet does not document how to use it for hardware synchronization at all. The GPIO register also has no mode-select bit to isolate the pin from the chip's internal control logic. Exposing it as a generic GPIO could result in kernel writes being overwritten by internal logic.
Datasheet: https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf
---
Changes in v7:
- Specify reg as a const.
- Move additionalProperties after allOf block.
Changes in v6:
- Add a ref to leds/common.yaml for the LDR pin.
Changes in v5:
- Remove the GPIO pin.
Changes in v4:
- Fix led-max-microamp property name.
Changes in v3:
- Add missing include for gpio.
- Expand GPIO descrption to include hardware synchronization.
- Use led-max-microamp instead of led-current-microamp for the LDR pin.
Changes in v2:
- Add the LDR, the interrupt pin, and the GPIO pin to the bindings.
- Fix node name and unit address mismatch.
- Include MAINTAINERS changes.
.../bindings/iio/light/ams,as7343.yaml | 64 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/ams,as7343.yaml
Documentation/devicetree/bindings/iio/light/ams,as7343.yaml new file +64 -0
@@ -0,0 +1,64 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/ams,as7343.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: AMS AS7343 14-Channel Multi-Spectral Sensor + +maintainers: + - Chang Yu <[email protected]> + +description: | + The AMS AS7343 is a 14-channel multi-spectral sensor with i2c address of 0x39. + https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf + +properties: + compatible: + enum: + - ams,as7343 + + reg: + const: 0x39 + + interrupts: + description: + Open drain output active low interrupt pin. + maxItems: 1 + + vdd-supply: true + + led-max-microamp: + description: + The maximum current for the external LED connected to the LDR pin. + minimum: 4000 + maximum: 258000 + multipleOf: 2000 + default: 12000 + +required: + - compatible + - reg + - vdd-supply + +allOf: + - $ref: /schemas/leds/common.yaml# + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + multispectral-sensor@39 { + compatible = "ams,as7343"; + reg = <0x39>; + interrupts = <7 IRQ_TYPE_LEVEL_LOW>; + vdd-supply = <&vdd_regulator>; + led-max-microamp = <14000>; + }; + };
MAINTAINERS +6 -0
@@ -1430,6 +1430,12 @@ S: Maintained F: Documentation/devicetree/bindings/iio/light/ams,as73211.yaml F: drivers/iio/light/as73211.c +AMS AS7343 DRIVER +M: Chang Yu <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/iio/light/ams,as7343.yaml + AMT (Automatic Multicast Tunneling) M: Taehee Yoo <[email protected]> L: [email protected]
Signature · 1 line
2.56.0
Re: [PATCH v7 1/2] dt-bindings: iio: light: add as7343
Quoted 9 lines · Chang Yu
Add binding for AMS AS7343 which is a 14-channel multi-spectral sensor with i2c address of
0x39.The GPIO pin is not described because the datasheet does not document how to use it for hardware synchronization at all. The GPIO register also has no mode-select bit to isolate the pin from the chip's internal control logic. Exposing it as a generic GPIO could result in kernel writes being overwritten by internal logic.
Quoted 3 lines
Datasheet: https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf
Reviewed-by Krzysztof Kozlowski <[email protected]>Signed-off-by Chang Yu <[email protected]>
LGTM so:
Signature · 2 lines
cheers, jose a. p-a
PATCH v7 2/2 iio: light: add AS7343 multi-spectral sensor driver
In reply to Chang YuAdd a driver for the AMS AS7343 14-channel multi-spectral sensor.
The AS7343 is a 14-channel spectral sensor featuring 11 visible channels, 1 near-infrared channel, 1 clear channel (VIS), and 1 flicker detection channel.
The driver exposes 12 spectral channels (11 visible light and 1 near-infrared) via sysfs. Runtime PM is implemented to stop measurements and enter SLEEP state when the device is suspended or torn down.
Future patches will add configurable gain and integration time, interrupt support, buffered reads, VIS channel, and flicker detection.
Datasheet: https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf
---
Changes in v7:
- Clear/set PON during suspend/resume.
- Check for digital saturation before reading spectral data.
- Reduce gain from x256 to x64 to avoid frequent saturation.
Changes in v6:
- Convert ASTEP and ATIME range checks to runtime checks.
- Move adding suspend action to before setting autosuspend delay.
Changes in v5:
- Add autosuspend support.
- Start measurements before configuring runtime PM.
- Add functions for computing ASTEP and ATIME.
- Sort registers by addresses.
Changes in v4:
- Use REGCACHE_MAPLE and add volatile register table.
- Use PM_RUNTIME_ACQUIRE* when resuming.
- Use a static array for labels.
- Various code style fixes.
Changes in v3:
- Hold a mutex before reading measurements.
- Add pm_runtime_resume_and_get before reading measurements.
- Only start measurements after suspend action has been successfully registered
- Check the return value of regmap_read when verifying device ID.
Changes in v2:
- Adjust the default gain to x256 and integration time to 50.1ms as recommended by the datasheet.
- Use read_label instead of .extend
- Remove all unused scan_index related constants.
- Add missing calls to pm_runtime_* methods in probe.
- Fix various code style issues
MAINTAINERS | 1 + drivers/iio/light/Kconfig | 11 + drivers/iio/light/Makefile | 1 + drivers/iio/light/as7343.c | 491 +++++++++++++++++++++++++++++++++++++ 4 files changed, 504 insertions(+) create mode 100644 drivers/iio/light/as7343.c
MAINTAINERS +1 -0
@@ -1435,6 +1435,7 @@ M: Chang Yu <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/iio/light/ams,as7343.yaml +F: drivers/iio/light/as7343.c AMT (Automatic Multicast Tunneling) M: Taehee Yoo <[email protected]>
drivers/iio/light/Kconfig +11 -0
@@ -149,6 +149,17 @@ config AS73211 This driver can also be built as a module. If so, the module will be called as73211. +config AS7343 + tristate "AMS AS7343 14-Channel Multi-Spectral Sensor" + depends on I2C + select REGMAP_I2C + help + Say Y here to build support for the AMS AS7343 14-channel + multi-spectral sensor. + + To compile this driver as a module, choose M here: the module will + be called as7343. + config BH1745 tristate "ROHM BH1745 colour sensor" depends on I2C
drivers/iio/light/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_APDS9306) += apds9306.o obj-$(CONFIG_APDS9960) += apds9960.o obj-$(CONFIG_APDS9999) += apds9999.o obj-$(CONFIG_AS73211) += as73211.o +obj-$(CONFIG_AS7343) += as7343.o obj-$(CONFIG_BH1745) += bh1745.o obj-$(CONFIG_BH1750) += bh1750.o obj-$(CONFIG_BH1780) += bh1780.o
drivers/iio/light/as7343.c new file +491 -0
491 lines not on this page · raw message
Signature · 1 line
2.56.0
Re: [PATCH v7 2/2] iio: light: add AS7343 multi-spectral sensor driver
Quoted 19 lines · Chang Yu
Add a driver for the AMS AS7343 14-channel multi-spectral sensor.
The AS7343 is a 14-channel spectral sensor featuring 11 visible channels, 1 near-infrared channel, 1 clear channel (VIS), and 1 flicker detection channel.
The driver exposes 12 spectral channels (11 visible light and 1 near-infrared) via sysfs. Runtime PM is implemented to stop measurements and enter SLEEP state when the device is suspended or torn down.
Future patches will add configurable gain and integration time, interrupt support, buffered reads, VIS channel, and flicker detection.
Datasheet: https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf
Reviewed-by Joshua Crofts <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Chang Yu <[email protected]>
[snip]
drivers/iio/light/as7343.c line 204
Quoted 7 lines
drivers/iio/light/as7343.c new file +7
-0+/* Check for digital saturation. */ +if (status &AS7343_ASTATUS_ASAT_STATUS ) { +/* +* Per the datasheet, ASTATUS is self-clearing: writing +* the value back clears the entire register. +*/ + ret =regmap_write (map,AS7343_ASTATUS_REG , status);
isn't that the STATUS (0x93) text? the datasheet says ASTATUS is read only and ASAT_STATUS clears on access, so the write shouldn't be needed. it also covers analog saturation, not only digital
drivers/iio/light/as7343.c line 205
Quoted 1 line
drivers/iio/light/as7343.c new file +1
-0+return ret ? ret : -EIO ;
-EIO reads like a bus error. as73211 returns -EOVERFLOW for this, wouldn't that fit better?
if (status & AS7343_ASTATUS_ASAT_STATUS) return -EOVERFLOW;
Signature · 2 lines
cheers, jose a. p-a
Re: [PATCH v7 2/2] iio: light: add AS7343 multi-spectral sensor driver
Quoted 24 lines · Jose A. Perez de Azpillaga
Quoted 19 lines · Chang Yu
Add a driver for the AMS AS7343 14-channel multi-spectral sensor.
The AS7343 is a 14-channel spectral sensor featuring 11 visible channels, 1 near-infrared channel, 1 clear channel (VIS), and 1 flicker detection channel.
The driver exposes 12 spectral channels (11 visible light and 1 near-infrared) via sysfs. Runtime PM is implemented to stop measurements and enter SLEEP state when the device is suspended or torn down.
Future patches will add configurable gain and integration time, interrupt support, buffered reads, VIS channel, and flicker detection.
Datasheet: https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf
Reviewed-by Joshua Crofts <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Chang Yu <[email protected]>[snip]
Quoted 13 lines
drivers/iio/light/as7343.c line 204
Quoted 7 lines
drivers/iio/light/as7343.c new file +7
-0+/* Check for digital saturation. */ +if (status &AS7343_ASTATUS_ASAT_STATUS ) { +/* +* Per the datasheet, ASTATUS is self-clearing: writing +* the value back clears the entire register. +*/ + ret =regmap_write (map,AS7343_ASTATUS_REG , status);isn't that the STATUS (
0x93) text? the datasheet says ASTATUS is read only andASAT_STATUSclears on access, so the write shouldn't be needed. it also covers analog saturation, not only digital
Aw man, how did I not notice that?
Quoted 4 lines
drivers/iio/light/as7343.c line 205
Quoted 1 line
drivers/iio/light/as7343.c new file +1
-0+return ret ? ret : -EIO ;
-EIOreads like a bus error. as73211 returns-EOVERFLOWfor this, wouldn't that fit better?
Sounds good to me. Jonathan, if v7 goes in, can you replace this if block with:
/* Check for saturation. */ if (status & AS7343_ASTATUS_ASAT_STATUS) return -EOVERFLOW;
I've tested the change on hardware and everything works fine. Or do you prefer me sending over a v8 instead?
Jose A. Perez de Azpillaga
Reviewed-byRe: [PATCH v7 2/2] iio: light: add AS7343 multi-spectral sensor driver
Quoted 38 lines · Chang Yu
Quoted 24 lines · Jose A. Perez de Azpillaga
Quoted 19 lines · Chang Yu
Add a driver for the AMS AS7343 14-channel multi-spectral sensor.
The AS7343 is a 14-channel spectral sensor featuring 11 visible channels, 1 near-infrared channel, 1 clear channel (VIS), and 1 flicker detection channel.
The driver exposes 12 spectral channels (11 visible light and 1 near-infrared) via sysfs. Runtime PM is implemented to stop measurements and enter SLEEP state when the device is suspended or torn down.
Future patches will add configurable gain and integration time, interrupt support, buffered reads, VIS channel, and flicker detection.
Datasheet: https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf
Reviewed-by Joshua Crofts <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Chang Yu <[email protected]>[snip]
Quoted 13 lines
drivers/iio/light/as7343.c line 204
Quoted 7 lines
drivers/iio/light/as7343.c new file +7
-0+/* Check for digital saturation. */ +if (status &AS7343_ASTATUS_ASAT_STATUS ) { +/* +* Per the datasheet, ASTATUS is self-clearing: writing +* the value back clears the entire register. +*/ + ret =regmap_write (map,AS7343_ASTATUS_REG , status);isn't that the STATUS (
0x93) text? the datasheet says ASTATUS is read only andASAT_STATUSclears on access, so the write shouldn't be needed. it also covers analog saturation, not only digital
Quoted 1 line
Aw man, how did I not notice that?
easy to mix up, STATUS and ASTATUS are one letter apart :)
Quoted 9 lines
Quoted 5 lines
drivers/iio/light/as7343.c line 205
Quoted 2 lines
drivers/iio/light/as7343.c new file +1
-0+return ret ? ret : -EIO ;
-EIOreads like a bus error. as73211 returns-EOVERFLOWfor this, wouldn't that fit better?Sounds good to me. Jonathan, if v7 goes in, can you replace this if block with:
Quoted 6 lines
/* Check for saturation. */ if (status & AS7343_ASTATUS_ASAT_STATUS) return -EOVERFLOW;I've tested the change on hardware and everything works fine. Or do you prefer me sending over a v8 instead?
with that fixup, LGTM so:
Signature · 2 lines
cheers, jose a. p-a
Jonathan Cameron
maintainerRe: [PATCH v7 2/2] iio: light: add AS7343 multi-spectral sensor driver
Quoted 39 lines · On Thu, 29 Oct 2026 21:59:28 +0100 "Jose A. Perez de Azpillaga"…
Quoted 38 lines · Chang Yu
Quoted 37 lines · Jose A. Perez de Azpillaga
Quoted 19 lines · Chang Yu
Add a driver for the AMS AS7343 14-channel multi-spectral sensor.
The AS7343 is a 14-channel spectral sensor featuring 11 visible channels, 1 near-infrared channel, 1 clear channel (VIS), and 1 flicker detection channel.
The driver exposes 12 spectral channels (11 visible light and 1 near-infrared) via sysfs. Runtime PM is implemented to stop measurements and enter SLEEP state when the device is suspended or torn down.
Future patches will add configurable gain and integration time, interrupt support, buffered reads, VIS channel, and flicker detection.
Datasheet: https://look.ams-osram.com/m/5f2d27fff9a874d2/original/AS7343-14-Channel-Multi-Spectral-Sensor.pdf
Reviewed-by Joshua Crofts <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Chang Yu <[email protected]>[snip]
Review
Quoted 7 lines
(quoted diff) +7
-0+ /* Check for digital saturation. */ + if (status & AS7343_ASTATUS_ASAT_STATUS) { + /* + * Per the datasheet, ASTATUS is self-clearing: writing + * the value back clears the entire register. + */ + ret = regmap_write(map, AS7343_ASTATUS_REG, status);isn't that the STATUS (
0x93) text? the datasheet says ASTATUS is read only andASAT_STATUSclears on access, so the write shouldn't be needed. it also covers analog saturation, not only digital
Quoted 16 lines
Quoted 1 line
Aw man, how did I not notice that?
easy to mix up, STATUS and ASTATUS are one letter apart :)
Quoted 12 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ return ret ? ret : -EIO;
-EIOreads like a bus error. as73211 returns-EOVERFLOWfor this, wouldn't that fit better?Sounds good to me. Jonathan, if v7 goes in, can you replace this if block with:
/* Check for saturation. */ if (status & AS7343_ASTATUS_ASAT_STATUS) return -EOVERFLOW;
Diff I applied is:
drivers/iio/light/as7343.c +3 -9
@@ -195,15 +195,9 @@ static int as7343_read_raw(struct iio_dev *indio_dev,if (ret)return ret; -/* Check for digital saturation. */ -if (status &AS7343_ASTATUS_ASAT_STATUS ) { -/* -* Per the datasheet, ASTATUS is self-clearing: writing -* the value back clears the entire register. -*/ - ret =regmap_write (map,AS7343_ASTATUS_REG , status); -return ret ? ret : -EIO ; - } +/* Check for saturation. */ +if (status &AS7343_ASTATUS_ASAT_STATUS ) +return -EOVERFLOW ; ret =regmap_bulk_read (map, chan->address, &result,sizeof (result));
With that applied to the testing branch of iio.git.
Shout if I misunderstood this discussion.
Thanks,
Jonathan
Quoted 8 lines
Quoted 3 lines
I've tested the change on hardware and everything works fine. Or do you prefer me sending over a v8 instead?
with that fixup, LGTM so:
Reviewed-by Jose A. Perez de Azpillaga <[email protected]>