Skip to contentSkip to conversation

iio: light: add support for Broadcom APDS9999

PATCH Superseded Jose A. Perez de Azpillaga 4 participants 8 messages May 19 – May 20

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jose A. Perez de Azpillaga

author maintainer
#0 lore raw

v3 cover iio: light: add support for Broadcom APDS9999

Add IIO driver and DT binding for the Broadcom APDS9999 ambient light and proximity sensor. The green channel uses optical coating technology to approximate the human eye spectral response for ALS/lux measurements. IIO_INTENSITY channels are also provided for red, green, blue, and IR so userspace can compute its own weighted lux.

v3:
- Dropped RFC
- Fixed MAINTAINERS entry alphabetical order (B section)
- Changed IIO_MOD_LIGHT_CLEAR to IIO_MOD_LIGHT_IR
- Unified RAW read path via chan->address for all channels
- Switched enum gains/rates to #define (hardware field values)
- Used USEC_PER_MSEC for integration time table
- Removed redundant comments from resolution enum
- Added default rationale comment in _init()
- Added ALS rationale comment on IIO_LIGHT channel
- s/reg/regval/, fixed indent in poll loop, C99 .name for id table
- Moved iio_info right after read_raw function
- DT binding: expanded VCSEL acronym, explained separate binding
- Commit messages wrapped at 75 chars, clarified RGB vs raw status

v2:
- Added IIO_INTENSITY channels for R, G, B, clear
- Switched to guard(mutex)(), devm_mutex_init(), dev_err_probe()
- Replaced remove() with devm_add_action_or_reset()
- Don't fail probe on PART_ID mismatch (fallback compatibles)
- Replaced manual shifts with FIELD_PREP() / GENMASK
- Used get_unaligned_le24(), sizeof(buf), NSEC_PER_SEC, fsleep()
- Named gain register values, explicit resolution enum values
- Removed section comments, grouped bit defines under registers
- Squashed Kconfig/Makefile into driver patch
- Split MAINTAINERS entry across patches
- DT binding: added vled-supply, interrupts, required vdd-supply
- DT binding: fixed title, added blank lines, full description
- Dropped "DT binding" duplication from binding commit subject

Link to v2: https://lore.kernel.org/linux-iio/[email protected]/
Link to v1: https://lore.kernel.org/linux-iio/[email protected]/

Jose A. Perez de Azpillaga (2):
dt-bindings: iio: light: add Broadcom APDS9999
iio: light: add support for APDS9999 sensor

 .../bindings/iio/light/brcm,apds9999.yaml     |  54 +++
 MAINTAINERS                                   |   7 +
 drivers/iio/light/Kconfig                     |  10 +
 drivers/iio/light/Makefile                    |   1 +
 drivers/iio/light/apds9999.c                  | 337 ++++++++++++++++++
 5 files changed, 409 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
 create mode 100644 drivers/iio/light/apds9999.c
author maintainer
#1 lore raw

PATCH v3 1/2 dt-bindings: iio: light: add Broadcom APDS9999

Add Device Tree binding for the Broadcom APDS9999 ambient light and proximity sensor. A separate binding file is used rather than merging with avago,apds9300.yaml because the APDS9999 has an additional vled-supply for the VCSEL.

The APDS9999 features individual R, G, B, and IR channels with a green channel that uses optical coating to approximate the human eye spectral response for ALS/lux measurements. Calibrated RGB color sensing is not yet implemented in the driver.

---
 .../bindings/iio/light/brcm,apds9999.yaml     | 54 +++++++++++++++++++
 MAINTAINERS                                   |  6 +++
 2 files changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +54 -0
new file mode 100644
index 000000000000..4d9e9aff8894
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/brcm,apds9999.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+title: Broadcom APDS-9999 Digital Proximity and RGB Sensor
+
+maintainers:
+  - Jose A. Perez de Azpillaga <[email protected]>
+
+description: |
+  Broadcom APDS-9999 is a digital proximity and RGB sensor with
+  ambient light sensing (ALS) capability. The device uses individual
+  R, G, B, and IR channels plus a Vertical Cavity Surface Emitting
+  Laser (VCSEL) for proximity detection.
+
+  Datasheet: https://docs.broadcom.com/docs/APDS-9999-DS
+
+properties:
+  compatible:
+    enum:
+      - brcm,apds9999
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+  vled-supply:
+    description: VCSEL power supply
+
+  interrupts:
+    maxItems: 1
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        light-sensor@52 {
+            compatible = "brcm,apds9999";
+            reg = <0x52>;
+            vdd-supply = <&vdd_reg>;
+            vled-supply = <&vled_reg>;
+        };
+    };
MAINTAINERS +6 -0
index 1aa9c989973f..2d8d4e2eab6e 100644
@@ -5000,6 +5000,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/light/brcm,apds9160.yaml
 F:	drivers/iio/light/apds9160.c
 
+BROADCOM APDS9999 AMBIENT LIGHT SENSOR DRIVER
+M:	Jose A. Perez de Azpillaga <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
+
 BROADCOM ASP 2.0 ETHERNET DRIVER
 M:	Justin Chen <[email protected]>
 M:	Florian Fainelli <[email protected]>
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: light: add Broadcom APDS9999

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Unnecessary schema split and contradiction regarding the vled-supply property. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unnecessary schema split and contradiction regarding the vled-supply property. --

commit 16ae176ed1deb8d1509cb369a4821fa40c4b1e66
Author: Jose A. Perez de Azpillaga <[email protected]>

dt-bindings: iio: light: add Broadcom APDS9999

This commit adds a new device tree binding for the Broadcom APDS9999 ambient light and proximity sensor. The commit message states that a separate binding file is used rather than merging with the existing APDS9300 binding due to the addition of a vled-supply property.

Quoted 3 lines

A separate binding file is used rather
than merging with avago,apds9300.yaml because the APDS9999 has an additional vled-supply for the VCSEL.

Does the implementation match this justification?

Quoted 4 lines
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +0 -0
new file mode 100644

[ ... ]

Quoted 1 line

+properties:

[ ... ]

Quoted 4 lines
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +4 -0
+  vled-supply:
+    description: VCSEL power supply
+
+  interrupts:

Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml line 42

Quoted 10 lines
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +10 -0
+    maxItems: 1
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+examples:

If the vled-supply property is the primary hardware difference that warrants a separate schema file, should it be included in the required properties list?

Alternatively, if the supply is genuinely optional, could this have been handled with a simple conditional in the existing avago,apds9300.yaml schema instead of splitting into a new file? The device tree binding guidelines recommend splitting bindings into separate files only when the conditionals become too unwieldy.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: light: add Broadcom APDS9999

In reply to Jose A. Perez de Azpillaga
Quoted 43 lines · Jose A. Perez de Azpillaga

Add Device Tree binding for the Broadcom APDS9999 ambient light and proximity sensor. A separate binding file is used rather than merging with avago,apds9300.yaml because the APDS9999 has an additional vled-supply for the VCSEL.

The APDS9999 features individual R, G, B, and IR channels with a green channel that uses optical coating to approximate the human eye spectral response for ALS/lux measurements. Calibrated RGB color sensing is not yet implemented in the driver.

---
 .../bindings/iio/light/brcm,apds9999.yaml     | 54 +++++++++++++++++++
 MAINTAINERS                                   |  6 +++
 2 files changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +20 -0
new file mode 100644
index 000000000000..4d9e9aff8894
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/brcm,apds9999.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+title: Broadcom APDS-9999 Digital Proximity and RGB Sensor
+
+maintainers:
+  - Jose A. Perez de Azpillaga <[email protected]>
+
+description: |
+  Broadcom APDS-9999 is a digital proximity and RGB sensor with
+  ambient light sensing (ALS) capability. The device uses individual
+  R, G, B, and IR channels plus a Vertical Cavity Surface Emitting
+  Laser (VCSEL) for proximity detection.
+
+  Datasheet: https://docs.broadcom.com/docs/APDS-9999-DS
+
+properties:
+  compatible:

Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml line 30

Quoted 10 lines
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +10 -0
+    enum:
+      - brcm,apds9999
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+  vled-supply:
+    description: VCSEL power supply

Why does the name in the description disagree with the name in the property? If the pin is called vcsel, please call the property that.

Cheers,
Conor.

Quoted 33 lines
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +24 -0
+
+  interrupts:
+    maxItems: 1
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        light-sensor@52 {
+            compatible = "brcm,apds9999";
+            reg = <0x52>;
+            vdd-supply = <&vdd_reg>;
+            vled-supply = <&vled_reg>;
+        };
+    };
MAINTAINERS +0 -0
index 1aa9c989973f..2d8d4e2eab6e 100644
@@ -5000,6 +5000,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/light/brcm,apds9160.yaml
 F:	drivers/iio/light/apds9160.c

MAINTAINERS S: Maintained · line 5011

Quoted 10 lines
MAINTAINERS +6 -0
 
+BROADCOM APDS9999 AMBIENT LIGHT SENSOR DRIVER
+M:	Jose A. Perez de Azpillaga <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
+
 BROADCOM ASP 2.0 ETHERNET DRIVER
 M:	Justin Chen <[email protected]>
 M:	Florian Fainelli <[email protected]>

pw-bot: changes-requested

author maintainer
#4 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: light: add Broadcom APDS9999

Quoted 49 lines · Conor Dooley
Quoted 48 lines · Jose A. Perez de Azpillaga

Add Device Tree binding for the Broadcom APDS9999 ambient light and proximity sensor. A separate binding file is used rather than merging with avago,apds9300.yaml because the APDS9999 has an additional vled-supply for the VCSEL.

The APDS9999 features individual R, G, B, and IR channels with a green channel that uses optical coating to approximate the human eye spectral response for ALS/lux measurements. Calibrated RGB color sensing is not yet implemented in the driver.

---
 .../bindings/iio/light/brcm,apds9999.yaml     | 54 +++++++++++++++++++
 MAINTAINERS                                   |  6 +++
 2 files changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +25 -0
new file mode 100644
index 000000000000..4d9e9aff8894
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/brcm,apds9999.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+title: Broadcom APDS-9999 Digital Proximity and RGB Sensor
+
+maintainers:
+  - Jose A. Perez de Azpillaga <[email protected]>
+
+description: |
+  Broadcom APDS-9999 is a digital proximity and RGB sensor with
+  ambient light sensing (ALS) capability. The device uses individual
+  R, G, B, and IR channels plus a Vertical Cavity Surface Emitting
+  Laser (VCSEL) for proximity detection.
+
+  Datasheet: https://docs.broadcom.com/docs/APDS-9999-DS
+
+properties:
+  compatible:
+    enum:
+      - brcm,apds9999
+
+  reg:
+    maxItems: 1
Quoted 9 lines

Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml line 30

Quoted 5 lines
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +5 -0
+
+  vdd-supply: true
+
+  vled-supply:
+    description: VCSEL power supply

Why does the name in the description disagree with the name in the property? If the pin is called vcsel, please call the property that.

will rename to vcsel-supply in v4.

Quoted 35 lines

Cheers,
Conor.

Quoted 32 lines
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +24 -0
+
+  interrupts:
+    maxItems: 1
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        light-sensor@52 {
+            compatible = "brcm,apds9999";
+            reg = <0x52>;
+            vdd-supply = <&vdd_reg>;
+            vled-supply = <&vled_reg>;
+        };
+    };
MAINTAINERS +0 -0
index 1aa9c989973f..2d8d4e2eab6e 100644
@@ -5000,6 +5000,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/light/brcm,apds9160.yaml
 F:	drivers/iio/light/apds9160.c
 
Quoted 13 lines

MAINTAINERS S: Maintained · line 5011

Quoted 11 lines
MAINTAINERS +6 -0
+BROADCOM APDS9999 AMBIENT LIGHT SENSOR DRIVER
+M:	Jose A. Perez de Azpillaga <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
+
 BROADCOM ASP 2.0 ETHERNET DRIVER
 M:	Justin Chen <[email protected]>
 M:	Florian Fainelli <[email protected]>

pw-bot: changes-requested

--
jose a. p-a

#5 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: light: add Broadcom APDS9999

Quoted 60 lines · Jose A. Perez de Azpillaga
Quoted 49 lines · Conor Dooley
Quoted 48 lines · Jose A. Perez de Azpillaga

Add Device Tree binding for the Broadcom APDS9999 ambient light and proximity sensor. A separate binding file is used rather than merging with avago,apds9300.yaml because the APDS9999 has an additional vled-supply for the VCSEL.

The APDS9999 features individual R, G, B, and IR channels with a green channel that uses optical coating to approximate the human eye spectral response for ALS/lux measurements. Calibrated RGB color sensing is not yet implemented in the driver.

---
 .../bindings/iio/light/brcm,apds9999.yaml     | 54 +++++++++++++++++++
 MAINTAINERS                                   |  6 +++
 2 files changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +25 -0
new file mode 100644
index 000000000000..4d9e9aff8894
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/brcm,apds9999.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+title: Broadcom APDS-9999 Digital Proximity and RGB Sensor
+
+maintainers:
+  - Jose A. Perez de Azpillaga <[email protected]>
+
+description: |
+  Broadcom APDS-9999 is a digital proximity and RGB sensor with
+  ambient light sensing (ALS) capability. The device uses individual
+  R, G, B, and IR channels plus a Vertical Cavity Surface Emitting
+  Laser (VCSEL) for proximity detection.
+
+  Datasheet: https://docs.broadcom.com/docs/APDS-9999-DS
+
+properties:
+  compatible:
+    enum:
+      - brcm,apds9999
+
+  reg:
+    maxItems: 1
Quoted 9 lines

Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml line 30

Quoted 5 lines
Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml new file +5 -0
+
+  vdd-supply: true
+
+  vled-supply:
+    description: VCSEL power supply

Why does the name in the description disagree with the name in the property? If the pin is called vcsel, please call the property that.

Quoted 1 line

will rename to vcsel-supply in v4.

Sounds good.

pw-bot: changes-requested

Thanks,
Conor.

author maintainer
#6 lore raw

PATCH v3 2/2 iio: light: add support for APDS9999 sensor

In reply to Jose A. Perez de Azpillaga

Add IIO driver for Broadcom APDS9999 ambient light sensor.

The APDS9999 is a digital proximity and RGB sensor with ALS capability. The driver implements the ALS/Lux functionality using the green channel, which uses optical coating technology to approximate the human eye spectral response.

Raw IIO_INTENSITY channels are exposed for red, green, blue, and IR so userspace can compute its own weighted lux. Proximity (PS) and calibrated RGB color sensing are not yet implemented.

---
 MAINTAINERS                  |   1 +
 drivers/iio/light/Kconfig    |  10 ++
 drivers/iio/light/Makefile   |   1 +
 drivers/iio/light/apds9999.c | 337 +++++++++++++++++++++++++++++++++++
 4 files changed, 349 insertions(+)
 create mode 100644 drivers/iio/light/apds9999.c
MAINTAINERS +1 -0
index 2d8d4e2eab6e..d36ab614aa53 100644
@@ -5005,6 +5005,7 @@ M:	Jose A. Perez de Azpillaga <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
+F:	drivers/iio/light/apds9999.c
 
 BROADCOM ASP 2.0 ETHERNET DRIVER
 M:	Justin Chen <[email protected]>
drivers/iio/light/Kconfig +10 -0
index eff33e456c70..c7256ffb972d 100644
@@ -119,6 +119,16 @@ config APDS9960
 	  To compile this driver as a module, choose M here: the
 	  module will be called apds9960
 
+config APDS9999
+	tristate "APDS9999 ambient light sensor"
+	depends on I2C
+	help
+	  Say Y here if you want to build support for the Broadcom APDS9999
+	  ambient light sensor (ALS/Lux).
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called apds9999.
+
 config AS73211
 	tristate "AMS AS73211 XYZ color sensor and AMS AS7331 UV sensor"
 	depends on I2C
drivers/iio/light/Makefile +1 -0
index c0048e0d5ca8..39e62dfc10c7 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_APDS9160)		+= apds9160.o
 obj-$(CONFIG_APDS9300)		+= apds9300.o
 obj-$(CONFIG_APDS9306)		+= apds9306.o
 obj-$(CONFIG_APDS9960)		+= apds9960.o
+obj-$(CONFIG_APDS9999)		+= apds9999.o
 obj-$(CONFIG_AS73211)		+= as73211.o
 obj-$(CONFIG_BH1745)		+= bh1745.o
 obj-$(CONFIG_BH1750)		+= bh1750.o
drivers/iio/light/apds9999.c new file +337 -0

337 lines not on this page · raw message

maintainer
#7 lore raw

Re: [PATCH v3 2/2] iio: light: add support for APDS9999 sensor

Quoted 7 lines · On Tue, 19 May 2026 11:23:40 +0200 "Jose A. Perez de Azpillaga"…

Add IIO driver for Broadcom APDS9999 ambient light sensor.

The APDS9999 is a digital proximity and RGB sensor with ALS capability. The driver implements the ALS/Lux functionality using the green channel, which uses optical coating technology to approximate the human eye spectral response.

Quoted 6 lines

Raw IIO_INTENSITY channels are exposed for red, green, blue, and IR so userspace can compute its own weighted lux. Proximity (PS) and calibrated RGB color sensing are not yet implemented.

Hi Jose,

A few minor comments inline

Looking good.

Jonathan

Quoted 25 lines
---
 MAINTAINERS                  |   1 +
 drivers/iio/light/Kconfig    |  10 ++
 drivers/iio/light/Makefile   |   1 +
 drivers/iio/light/apds9999.c | 337 +++++++++++++++++++++++++++++++++++
 4 files changed, 349 insertions(+)
 create mode 100644 drivers/iio/light/apds9999.c
MAINTAINERS +1 -0
index 2d8d4e2eab6e..d36ab614aa53 100644
@@ -5005,6 +5005,7 @@ M:	Jose A. Perez de Azpillaga <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/light/brcm,apds9999.yaml
+F:	drivers/iio/light/apds9999.c
 
 BROADCOM ASP 2.0 ETHERNET DRIVER
 M:	Justin Chen <[email protected]>
drivers/iio/light/Kconfig +0 -0
index eff33e456c70..c7256ffb972d 100644

drivers/iio/light/Kconfig config APDS9960 · line 123

Quoted 5 lines
drivers/iio/light/Kconfig +2 -0
@@ -119,6 +119,16 @@ config APDS9960
 	  To compile this driver as a module, choose M here: the
 	  module will be called apds9960
 
+config APDS9999
+	tristate "APDS9999 ambient light sensor"

For such a capable device ambient light seems insufficient. I'd go with ALS, RGB and proximity sensor

drivers/iio/light/Kconfig config APDS9960 · line 127

Quoted 4 lines
drivers/iio/light/Kconfig +4 -0
+	depends on I2C
+	help
+	  Say Y here if you want to build support for the Broadcom APDS9999
+	  ambient light sensor (ALS/Lux).

Similar here - but provide even more detail.

Quoted 14 lines
drivers/iio/light/Kconfig +4 -0
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called apds9999.
+
 config AS73211
 	tristate "AMS AS73211 XYZ color sensor and AMS AS7331 UV sensor"
 	depends on I2C
drivers/iio/light/apds9999.c new file +0 -0
new file mode 100644
index 000000000000..938e43b39ad5

drivers/iio/light/apds9999.c line 8

Quoted 8 lines
drivers/iio/light/apds9999.c new file +8 -0
@@ -0,0 +1,337 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * IIO driver for Broadcom APDS9999 Lux Light Sensor
+ *
+ * Copyright (C) 2026
+ * Author: Jose A. Perez de Azpillaga <[email protected]>
+ *
+ * TODO: proximity and color sensor

color part of this seems to now be supported.

drivers/iio/light/apds9999.c line 84

Quoted 4 lines
drivers/iio/light/apds9999.c new file +3 -0
+ */
 
+	struct i2c_client *client;
+	/* lock: protects als_gain_idx, als_res, als_rate */

Protect against what? Can we be more specific on whether something must be atomic, or not change during some operation.

Other than during init (where arguably the lock isn't needed) only als_res is accessed with the lock held.

Quoted 29 lines
drivers/iio/light/apds9999.c new file +28 -0
+	struct mutex lock;
+	int als_gain_idx;
+	int als_res;
+	int als_rate;
+};
 
+static int apds9999_read_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int *val, int *val2, long mask)
+{
+	struct apds9999_data *data = iio_priv(indio_dev);
+	int gain, itime_us;
+	u64 scale_nano;
+	u32 counts;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = apds9999_read_channel(data, chan->address, &counts);
+		if (ret)
+			return ret;
+		*val = (int)counts;
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE:
+		/*
+		 * Scale (lux per count) = 54 / (gain * integration_time_ms)
+		 *
+		 * The constant 54 is derived from the datasheet table:

drivers/iio/light/apds9999.c line 202

Quoted 10 lines
drivers/iio/light/apds9999.c new file +10 -0
+		 *   at gain = 3x, itime = 100 ms -> 0.180 lux/count
+		 *   -> C = 0.180 * 3 * 100 = 54
+		 *
+		 * Expressed as IIO_VAL_INT_PLUS_NANO.
+		 */
+		gain = apds9999_gains[data->als_gain_idx];
+		itime_us = apds9999_itimes_us[data->als_res];
+
+		/* scale_nano = 54e12 / (gain * itime_us) nano-lux/count */
+		scale_nano = div_u64(54000000000000ULL, (u32)(gain * itime_us));

That's a lot of zeros. Is it effectively NANO * MICRO / MILLI

(the second part being conversion from msecs to microsecs as used on the bottom) If so use those constants to express it rather than the many zeros.

Quoted 13 lines
drivers/iio/light/apds9999.c new file +13 -0
+		*val = (int)(scale_nano / NSEC_PER_SEC);
+		*val2 = (int)(scale_nano % NSEC_PER_SEC);
+		return IIO_VAL_INT_PLUS_NANO;
+
+	case IIO_CHAN_INFO_INT_TIME:
+		*val = 0;
+		*val2 = apds9999_itimes_us[data->als_res];
+		return IIO_VAL_INT_PLUS_MICRO;
+
+	default:
+		return -EINVAL;
+	}
+}