Re: [PATCH v3 3/3] iio: light: isl29018: support cover-glass gain compensation via DT
From: Andy Shevchenko
Date: Thu Jun 04 2026 - 16:51:54 EST
On Thu, Jun 04, 2026 at 12:06:17PM +0200, Herman van Hazendonk wrote:
> 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.
...
> struct iio_dev *indio_dev;
> const void *ddata = NULL;
> const char *name;
> + struct device *dev;
> int dev_id;
> int err;
>
> + dev = &client->dev;
Make this go together with the definition.
struct device *dev = &client->dev;
...
Use something like
const char *propname;
...
propname = "isil,cover-comp-gain";
> + 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");
And make these three one-liners.
> + } else {
> + chip->calibscale = 1;
> + }
--
With Best Regards,
Andy Shevchenko