Devicetree
 help / color / mirror / Atom feed
From: Herman van Hazendonk <github.com@herrie.org>
To: jic23@kernel.org
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	tomasborquez13@gmail.com, masneyb@onstation.org,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Herman van Hazendonk <github.com@herrie.org>
Subject: [PATCH v3 3/3] iio: light: isl29018: support cover-glass gain compensation via DT
Date: Thu,  4 Jun 2026 12:06:17 +0200	[thread overview]
Message-ID: <20260604100617.3486541-4-github.com@herrie.org> (raw)
In-Reply-To: <20260604100617.3486541-1-github.com@herrie.org>

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@herrie.org>
---
 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


      parent reply	other threads:[~2026-06-04 10:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04 10:06 [PATCH v3 0/3] iio: light: isl29018: overflow/precision fix + cover-glass gain via DT Herman van Hazendonk
2026-06-04 10:06 ` [PATCH v3 1/3] iio: light: isl29018: fix overflow and precision in isl29018_read_lux() Herman van Hazendonk
2026-06-04 10:06 ` [PATCH v3 2/3] dt-bindings: iio: light: isl29018: add isil,cover-comp-gain Herman van Hazendonk
2026-06-04 17:01   ` Conor Dooley
2026-06-04 10:06 ` Herman van Hazendonk [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260604100617.3486541-4-github.com@herrie.org \
    --to=github.com@herrie.org \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masneyb@onstation.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    --cc=tomasborquez13@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox