mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arka Mondal <arka@arkamondal.net>
To: Jonathan Cameron <jic23@kernel.org>, Linus Walleij <linusw@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Peter Meerwald" <pmeerw@pmeerw.net>,
	"Matt Ranostay" <mranostay@gmail.com>,
	"Robert Eshleman" <bobbyeshleman@gmail.com>,
	"Leonard Crestez" <cdleonard@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Arka Mondal" <arka@arkamondal.net>
Subject: [PATCH 2/6] iio: light: apds9960: Report the available lists via read_avail()
Date: Mon,  2 Nov 2026 16:46:56 +0900	[thread overview]
Message-ID: <20261102074700.63075-3-arka@arkamondal.net> (raw)
In-Reply-To: <20261102074700.63075-1-arka@arkamondal.net>

The proximity and intensity channels put IIO_CHAN_INFO_SCALE in
info_mask_shared_by_type, and the intensity channels put
IIO_CHAN_INFO_INT_TIME there too. The values those attributes accept
are listed by three custom attributes: proximity_scale_available,
intensity_scale_available and integration_time_available. None of the
three carries the in_ prefix that the core gives the attribute it
describes, so all three are registered at the device level, and
userspace looking for in_proximity_scale_available,
in_intensity_scale_available or in_intensity_integration_time_available
finds nothing.

Report all three through read_avail() and drop the custom attribute
group. The two gain lists keep their exact text. The integration time
list becomes 0.028000 0.100000 0.200000 0.700000 instead of 0.028 0.1
0.2 0.7, because the core prints IIO_VAL_INT_PLUS_MICRO with six
decimals. The values are unchanged.

Fixes: aff268cd532e ("iio: light: add APDS9960 ALS + promixity driver")
Signed-off-by: Arka Mondal <arka@arkamondal.net>
---

Notes:
    Compile tested only; no relevant hardware available.

 drivers/iio/light/apds9960.c | 56 +++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/light/apds9960.c b/drivers/iio/light/apds9960.c
index afe520de60e2..496678c4d338 100644
--- a/drivers/iio/light/apds9960.c
+++ b/drivers/iio/light/apds9960.c
@@ -289,6 +289,8 @@ static const struct iio_event_spec apds9960_als_event_spec[] = {
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
 	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
 			BIT(IIO_CHAN_INFO_INT_TIME), \
+	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE) | \
+			BIT(IIO_CHAN_INFO_INT_TIME), \
 	.channel2 = IIO_MOD_LIGHT_##_colour, \
 	.address = APDS9960_REG_ALS_CHANNEL(_colour), \
 	.modified = 1, \
@@ -304,6 +306,7 @@ static const struct iio_chan_spec apds9960_channels[] = {
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 			BIT(IIO_CHAN_INFO_CALIBBIAS),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+		.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE),
 		.channel = 0,
 		.indexed = 0,
 		.scan_index = -1,
@@ -322,6 +325,8 @@ static const struct iio_chan_spec apds9960_channels[] = {
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
 			BIT(IIO_CHAN_INFO_INT_TIME),
+		.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE) |
+			BIT(IIO_CHAN_INFO_INT_TIME),
 		.channel2 = IIO_MOD_LIGHT_CLEAR,
 		.address = APDS9960_REG_ALS_CHANNEL(CLEAR),
 		.modified = 1,
@@ -370,19 +375,11 @@ static const int apds9960_int_time[][2] = {
 static const int apds9960_pxs_gain_map[] = {1, 2, 4, 8};
 static const int apds9960_als_gain_map[] = {1, 4, 16, 64};
 
-static IIO_CONST_ATTR(proximity_scale_available, "1 2 4 8");
-static IIO_CONST_ATTR(intensity_scale_available, "1 4 16 64");
-static IIO_CONST_ATTR_INT_TIME_AVAIL("0.028 0.1 0.2 0.7");
-
-static struct attribute *apds9960_attributes[] = {
-	&iio_const_attr_proximity_scale_available.dev_attr.attr,
-	&iio_const_attr_intensity_scale_available.dev_attr.attr,
-	&iio_const_attr_integration_time_available.dev_attr.attr,
-	NULL,
-};
-
-static const struct attribute_group apds9960_attribute_group = {
-	.attrs = apds9960_attributes,
+static const int apds9960_int_time_avail[] = {
+	0, 28000,
+	0, 100000,
+	0, 200000,
+	0, 700000,
 };
 
 static const struct reg_field apds9960_reg_field_int_als =
@@ -786,8 +783,39 @@ static int apds9960_write_event_config(struct iio_dev *indio_dev,
 	return 0;
 }
 
+static int apds9960_read_avail(struct iio_dev *indio_dev,
+			       struct iio_chan_spec const *chan,
+			       const int **vals, int *type, int *length,
+			       long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		switch (chan->type) {
+		case IIO_PROXIMITY:
+			*vals = apds9960_pxs_gain_map;
+			*length = ARRAY_SIZE(apds9960_pxs_gain_map);
+			break;
+		case IIO_INTENSITY:
+			*vals = apds9960_als_gain_map;
+			*length = ARRAY_SIZE(apds9960_als_gain_map);
+			break;
+		default:
+			return -EINVAL;
+		}
+		*type = IIO_VAL_INT;
+		return IIO_AVAIL_LIST;
+	case IIO_CHAN_INFO_INT_TIME:
+		*vals = apds9960_int_time_avail;
+		*type = IIO_VAL_INT_PLUS_MICRO;
+		*length = ARRAY_SIZE(apds9960_int_time_avail);
+		return IIO_AVAIL_LIST;
+	default:
+		return -EINVAL;
+	}
+}
+
 static const struct iio_info apds9960_info = {
-	.attrs = &apds9960_attribute_group,
+	.read_avail = apds9960_read_avail,
 	.read_raw = apds9960_read_raw,
 	.write_raw = apds9960_write_raw,
 	.read_event_value = apds9960_read_event,
-- 
2.56.0


  parent reply	other threads:[~2026-11-02  7:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  7:46 [PATCH 0/6] iio: Give the *_available attributes the names the core generates Arka Mondal
2026-11-02  7:46 ` [PATCH 1/6] iio: light: isl29125: Report the scale list via read_avail() Arka Mondal
2026-11-02 22:26   ` Jonathan Cameron
2026-11-02  7:46 ` Arka Mondal [this message]
2026-11-02  7:46 ` [PATCH 3/6] iio: light: max44009: Report the integration time " Arka Mondal
2026-11-02  7:46 ` [PATCH 4/6] iio: light: max44000: Report the available lists " Arka Mondal
2026-11-02  7:46 ` [PATCH 5/6] iio: humidity: hdc100x: " Arka Mondal
2026-11-02  7:47 ` [PATCH 6/6] iio: gyro: mpu3050: Fix the scale list and report it " Arka Mondal

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=20261102074700.63075-3-arka@arkamondal.net \
    --to=arka@arkamondal.net \
    --cc=andy@kernel.org \
    --cc=bobbyeshleman@gmail.com \
    --cc=cdleonard@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=pmeerw@pmeerw.net \
    /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

all inboxes | Powered by JetHome®