[PATCH v3 3/3] iio: light: isl29018: support cover-glass gain compensation via DT

From: Herman van Hazendonk

Date: Thu Jun 04 2026 - 06:20:18 EST


Boards that mount the ISL29018 behind tinted or coated cover glass
experience optical loss that effectively reduces the sensor's apparent
sensitivity. The existing in_illuminance0_calibscale sysfs attribute
can correct for this at runtime, but firmware knows the loss factor at
design time and there is no way to seed it without a userspace helper.

Add support for an optional "isil,cover-comp-gain" device-tree property
that initialises calibscale at probe time. If the property is present
but cannot be read, probe returns an error via dev_err_probe() so the
root cause is visible in the log. If absent, calibscale defaults to 1
(unity gain, matching the previous behaviour). Userspace can still
override the value at runtime through the sysfs attribute.

The approach follows the precedent set by the TSL2563 driver.

Signed-off-by: Herman van Hazendonk <github.com@xxxxxxxxxx>
---
drivers/iio/light/isl29018.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/light/isl29018.c b/drivers/iio/light/isl29018.c
index f3312ad670d9..9daacb9b02bc 100644
--- a/drivers/iio/light/isl29018.c
+++ b/drivers/iio/light/isl29018.c
@@ -711,10 +711,13 @@ static int isl29018_probe(struct i2c_client *client)
struct iio_dev *indio_dev;
const void *ddata = NULL;
const char *name;
+ struct device *dev;
int dev_id;
int err;

- indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
+ dev = &client->dev;
+
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*chip));
if (!indio_dev)
return -ENOMEM;

@@ -733,8 +736,16 @@ static int isl29018_probe(struct i2c_client *client)
mutex_init(&chip->lock);

chip->type = dev_id;
- chip->calibscale = 1;
chip->ucalibscale = 0;
+ if (device_property_present(dev, "isil,cover-comp-gain")) {
+ err = device_property_read_u32(dev, "isil,cover-comp-gain",
+ &chip->calibscale);
+ if (err)
+ return dev_err_probe(dev, err,
+ "invalid isil,cover-comp-gain\n");
+ } else {
+ chip->calibscale = 1;
+ }
chip->int_time = ISL29018_INT_TIME_16;
chip->scale = isl29018_scales[chip->int_time][0];
chip->suspended = false;
--
2.43.0