[PATCH v2 2/2] iio: light: max44009: Report the integration time via read_avail()
From: Arka Mondal
Date: Mon Nov 09 2026 - 00:09:28 EST
The integration times the light channel accepts are listed by a custom
attribute named illuminance_integration_time_available. That name has
no in_ prefix, so it is registered at the device level instead of
beside in_illuminance_integration_time, and userspace looking for
in_illuminance_integration_time_available finds nothing.
Report the list through read_avail() and drop the custom attribute.
All eight values are a whole number of microseconds, so they go in as
IIO_VAL_INT_PLUS_MICRO pairs with nothing rounded. The values do not
change; the core prints them with six decimals, so the attribute reads
0.800000 down to 0.006250 instead of 0.8 down to 0.00625. read_raw()
still reports the time itself as IIO_VAL_INT_PLUS_NANO.
Fixes: 6aef699a7d7e ("iio: light: add driver for MAX44009")
Signed-off-by: Arka Mondal <arka@xxxxxxxxxxxxxx>
---
Notes:
No hardware available. Loaded against CONFIG_I2C_STUB under qemu:
in_illuminance_integration_time_available reads 0.800000 0.400000
0.200000 0.100000 0.050000 0.025000 0.012500 0.006250, and the
unprefixed name is gone.
drivers/iio/light/max44009.c | 48 ++++++++++++++++++++----------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/drivers/iio/light/max44009.c b/drivers/iio/light/max44009.c
index 82b8a806c5fa..8a57b9812f7f 100644
--- a/drivers/iio/light/max44009.c
+++ b/drivers/iio/light/max44009.c
@@ -66,15 +66,16 @@ static const u32 max44009_int_time_ns_array[] = {
6250000, /* Manual mode only */
};
-static const char max44009_int_time_str[] =
- "0.8 "
- "0.4 "
- "0.2 "
- "0.1 "
- "0.05 "
- "0.025 "
- "0.0125 "
- "0.00625";
+static const int max44009_int_time_avail[] = {
+ 0, 800000,
+ 0, 400000,
+ 0, 200000,
+ 0, 100000,
+ 0, 50000,
+ 0, 25000,
+ 0, 12500,
+ 0, 6250,
+};
struct max44009_data {
struct i2c_client *client;
@@ -101,6 +102,7 @@ static const struct iio_chan_spec max44009_channels[] = {
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
BIT(IIO_CHAN_INFO_INT_TIME),
+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME),
.event_spec = max44009_event_spec,
.num_event_specs = ARRAY_SIZE(max44009_event_spec),
},
@@ -284,17 +286,21 @@ static int max44009_read_raw(struct iio_dev *indio_dev,
}
}
-static IIO_CONST_ATTR(illuminance_integration_time_available,
- max44009_int_time_str);
-
-static struct attribute *max44009_attributes[] = {
- &iio_const_attr_illuminance_integration_time_available.dev_attr.attr,
- NULL,
-};
-
-static const struct attribute_group max44009_attribute_group = {
- .attrs = max44009_attributes,
-};
+static int max44009_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_INT_TIME:
+ *vals = max44009_int_time_avail;
+ *type = IIO_VAL_INT_PLUS_MICRO;
+ *length = ARRAY_SIZE(max44009_int_time_avail);
+ return IIO_AVAIL_LIST;
+ default:
+ return -EINVAL;
+ }
+}
static int max44009_threshold_byte_from_fraction(int integral, int fractional)
{
@@ -464,7 +470,7 @@ static const struct iio_info max44009_info = {
.read_event_config = max44009_read_event_config,
.write_event_value = max44009_write_event_value,
.write_event_config = max44009_write_event_config,
- .attrs = &max44009_attribute_group,
+ .read_avail = max44009_read_avail,
};
static irqreturn_t max44009_threaded_irq_handler(int irq, void *p)
--
2.56.0