Re: [PATCH 1/1] iio: light: isl29018: support cover-glass gain compensation via DT
From: Andy Shevchenko
Date: Thu Jun 04 2026 - 03:25:56 EST
On Thu, Jun 04, 2026 at 07:47:23AM +0200, Herman van Hazendonk wrote:
> Boards that mount the sensor under a tinted or coated cover glass need
> to compensate for the optical loss before downstream consumers can map
> the reading onto a useful lux range. The driver already exposes a
> runtime knob through in_illuminance0_calibscale, but every user has to
> re-apply it after every reboot (or rely on a board-specific udev rule),
> and a power-of-two cover gain like 100x is a hardware constant of the
> board rather than a policy choice that belongs in userspace.
>
> Add an "isil,cover-comp-gain" device-tree property that seeds calibscale
> at probe, mirroring the pattern tsl2563.c already uses for the same
> class of problem (amstaos,cover-comp-gain). The default stays 1 so
> existing systems are unaffected, and userspace can still re-tune via
> the sysfs attribute afterwards.
Haven't DT schema patches needed to go separately?
...
> + /*
> + * Allow boards that mount the sensor behind tinted / coated cover
> + * glass to bake the optical-loss compensation into firmware via
> + * "isil,cover-comp-gain", following the precedent set by
> + * tsl2563.c. The value seeds calibscale (default 1), so userspace
> + * can still retune through in_illuminance0_calibscale.
> + */
> chip->calibscale = 1;
> + device_property_read_u32(&client->dev, "isil,cover-comp-gain",
> + &chip->calibscale);
With
struct device *dev = &client->dev;
at the top of the function this will be made shorter.
Additionally the above approach won't be accurate when property is present in
DT but by some reason can't be retrieved. It will puzzle the user. That's why
the robust approach is
struct device *dev = &client->dev;
const char *propname;
...
propname = "isil,cover-comp-gain";
if (device_property_present(dev, &chip->calibscale)) {
ret = device_property_read_u32(dev, propname, &chip->calibscale);
if (ret)
return ret; // optionally dev_err_probe()
} else {
chip->calibscale = 1;
}
Taking the expansion of this pattern we might need to actually introduce a full
set of device_property_read_*_optional() to make this churn less required.
Perhaps for v7.3.
--
With Best Regards,
Andy Shevchenko