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 4/6] iio: light: max44000: Report the available lists via read_avail()
Date: Mon, 2 Nov 2026 16:46:58 +0900 [thread overview]
Message-ID: <20261102074700.63075-5-arka@arkamondal.net> (raw)
In-Reply-To: <20261102074700.63075-1-arka@arkamondal.net>
The light channel keeps IIO_CHAN_INFO_SCALE and IIO_CHAN_INFO_INT_TIME
in info_mask_shared_by_type, so userspace sees in_illuminance_scale
and in_illuminance_integration_time. Two custom attributes list the
values those accept, but they are named illuminance_scale_available and
illuminance_integration_time_available, without the in_ prefix the core
gives the attribute a list belongs to. Both land at the device level,
paired with nothing, so userspace that asks for either prefixed name
finds no such file.
Report both lists through read_avail() and delete the two attributes
along with the strings they printed.
Each list uses the format the write path accepts, which
max44000_write_raw_get_fmt() gives as IIO_VAL_INT_PLUS_MICRO for
scale and IIO_VAL_INT_PLUS_NANO for integration time. The scale
is read back as IIO_VAL_FRACTIONAL_LOG2, the same number written
another way. max44000_write_raw() still rounds a request against
the ulux table with find_closest() and against the ns table with
find_closest_descending(), so both tables stay and the lists are
separate arrays of value pairs.
No value changes, but the core prints each one to the full precision
of its format. The scale now reads 0.031250 0.125000 0.500000 4.000000
where it read 0.03125 0.125 0.5 4, and the integration time reads
0.100000000 0.025000000 0.006250000 0.001562500 where it read 0.100
0.025 0.00625 0.0015625.
Fixes: d5d8f49b6345 ("max44000: Expose ambient sensor scaling")
Signed-off-by: Arka Mondal <arka@arkamondal.net>
---
Notes:
Compile tested only; no relevant hardware available.
drivers/iio/light/max44000.c | 60 ++++++++++++++++++++++--------------
1 file changed, 37 insertions(+), 23 deletions(-)
diff --git a/drivers/iio/light/max44000.c b/drivers/iio/light/max44000.c
index 8c344f1b3fe2..9f9046e127c0 100644
--- a/drivers/iio/light/max44000.c
+++ b/drivers/iio/light/max44000.c
@@ -104,11 +104,20 @@ static const int max44000_int_time_avail_ns_array[] = {
6250000,
1562500,
};
-static const char max44000_int_time_avail_str[] =
- "0.100 "
- "0.025 "
- "0.00625 "
- "0.0015625";
+
+static const int max44000_int_time_avail[] = {
+ 0, 100000000,
+ 0, 25000000,
+ 0, 6250000,
+ 0, 1562500,
+};
+
+static const int max44000_scale_avail[] = {
+ 0, 31250,
+ 0, 125000,
+ 0, 500000,
+ 4, 0,
+};
/* Available scales (internal to ulux) with pretty manual alignment: */
static const int max44000_scale_avail_ulux_array[] = {
@@ -117,11 +126,6 @@ static const int max44000_scale_avail_ulux_array[] = {
500000,
4000000,
};
-static const char max44000_scale_avail_str[] =
- "0.03125 "
- "0.125 "
- "0.5 "
- "4";
#define MAX44000_SCAN_INDEX_ALS 0
#define MAX44000_SCAN_INDEX_PRX 1
@@ -132,6 +136,8 @@ static const struct iio_chan_spec max44000_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),
.scan_index = MAX44000_SCAN_INDEX_ALS,
.scan_type = {
.sign = 'u',
@@ -383,24 +389,32 @@ static int max44000_write_raw_get_fmt(struct iio_dev *indio_dev,
return IIO_VAL_INT;
}
-static IIO_CONST_ATTR(illuminance_integration_time_available, max44000_int_time_avail_str);
-static IIO_CONST_ATTR(illuminance_scale_available, max44000_scale_avail_str);
-
-static struct attribute *max44000_attributes[] = {
- &iio_const_attr_illuminance_integration_time_available.dev_attr.attr,
- &iio_const_attr_illuminance_scale_available.dev_attr.attr,
- NULL
-};
-
-static const struct attribute_group max44000_attribute_group = {
- .attrs = max44000_attributes,
-};
+static int max44000_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:
+ *vals = max44000_scale_avail;
+ *type = IIO_VAL_INT_PLUS_MICRO;
+ *length = ARRAY_SIZE(max44000_scale_avail);
+ return IIO_AVAIL_LIST;
+ case IIO_CHAN_INFO_INT_TIME:
+ *vals = max44000_int_time_avail;
+ *type = IIO_VAL_INT_PLUS_NANO;
+ *length = ARRAY_SIZE(max44000_int_time_avail);
+ return IIO_AVAIL_LIST;
+ default:
+ return -EINVAL;
+ }
+}
static const struct iio_info max44000_info = {
.read_raw = max44000_read_raw,
.write_raw = max44000_write_raw,
.write_raw_get_fmt = max44000_write_raw_get_fmt,
- .attrs = &max44000_attribute_group,
+ .read_avail = max44000_read_avail,
};
static bool max44000_readable_reg(struct device *dev, unsigned int reg)
--
2.56.0
next prev 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 ` [PATCH 2/6] iio: light: apds9960: Report the available lists " Arka Mondal
2026-11-02 7:46 ` [PATCH 3/6] iio: light: max44009: Report the integration time " Arka Mondal
2026-11-02 7:46 ` Arka Mondal [this message]
2026-11-02 7:46 ` [PATCH 5/6] iio: humidity: hdc100x: Report the available lists " 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-5-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®