iio: light: ltr501: Add LTR-659PS-01 prox sensor support
Subsystems (2)
v2 cover iio: light: ltr501: Add LTR-659PS-01 prox sensor support
Add support for the Lite-On LTR-659PS-01 proximity sensor. This device is nearly identical to the LTR-559ALS-01, but omits all elements related to ambient light sensing.
---
Changes in v2:
- set IIO_PROXIMITY channel to scan_index 2 since driver will not handle other id properly
- add IIO_CHAN_INFO_SAMP_FREQ for IIO_PROXIMITY channel
- isolate missed ALS register calls
- add commit to use read_avail operation
- convert to use modern chip info match
---
Svyatoslav Ryhel (4):
iio: light: ltr501: Switch to read_avail() op from manual attribute
registration
iio: light: ltr501: Switch to modern match mechanism
dt-bindings: iio: light: ltr501: Document LTR659 proximity sensor
iio: light: ltr501: Add support for the LTR-659PS-01 proximity sensor
.../bindings/iio/light/liteon,ltr501.yaml | 1 + drivers/iio/light/ltr501.c | 383 +++++++++--------- 2 files changed, 184 insertions(+), 200 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/4 iio: light: ltr501: Switch to read_avail() op from manual attribute registration
Switch to the read_avail() operation from manual attribute group registration. This eliminates the need for per-chip attribute_group structures and related ltr501_chip_info iio_info entries.
--- drivers/iio/light/ltr501.c | 153 +++++++++++++------------------------ 1 file changed, 52 insertions(+), 101 deletions(-)
drivers/iio/light/ltr501.c +52 -101
@@ -133,6 +133,22 @@ static const struct ltr501_gain ltr559_ps_gain_tbl[] = { {0, 15624}, }; +static const int int_time_avail[] = { +0 ,50000 , +0 ,100000 , +0 ,200000 , +0 ,400000 +}; + +static const int samp_freq_avail[] = { +20 ,0 , +10 ,0 , +5 ,0 , +2 ,0 , +1 ,0 , +0 ,500000 +}; + struct ltr501_chip_info { u8 partid; const struct ltr501_gain *als_gain;
@@ -145,8 +161,6 @@ struct ltr501_chip_info {bool no_irq_support;struct iio_chan_spec const *channels;const int no_channels; -const struct iio_info *info; -const struct iio_info *info_no_irq; };struct ltr501_data {
@@ -590,6 +604,7 @@ static const struct iio_event_spec ltr501_pxs_event_spec[] = { .channel2 = (_mod), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = (_shared), \ + .info_mask_shared_by_all_available = (_shared), \ .scan_index = (_idx), \ .scan_type = { \ .sign = 'u', \
@@ -1111,111 +1126,56 @@ static int ltr501_write_event_config(struct iio_dev *indio_dev,return -EINVAL ; } -static ssize_t ltr501_show_proximity_scale_avail (struct device *dev, -struct device_attribute *attr, -char *buf) +static int ltr501_read_avail (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +const int **vals,int *type,int *length,long mask) { -struct ltr501_data *data =iio_priv (dev_to_iio_dev (dev)); +struct ltr501_data *data =iio_priv (indio_dev);const struct ltr501_chip_info *info = data->chip_info; -ssize_t len =0 ; -int i; - -for (i =0 ; i < info->ps_gain_tbl_size; i++) { -if (info->ps_gain[i].scale ==LTR501_RESERVED_GAIN ) -continue ; - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d.%06d " , - info->ps_gain[i].scale, - info->ps_gain[i].uscale); - } - buf[len -1 ] ='\n' ; +switch (mask) { +case IIO_CHAN_INFO_SCALE : +if (chan->type ==IIO_INTENSITY ) { + *length = info->als_gain_tbl_size *2 ; + *vals = (const int *)info->als_gain; + }else { + *length = info->ps_gain_tbl_size *2 ; + *vals = (const int *)info->ps_gain; + } + *type =IIO_VAL_INT_PLUS_MICRO ; +return IIO_AVAIL_LIST ; -return len; -} +case IIO_CHAN_INFO_INT_TIME : + *vals = int_time_avail; + *type =IIO_VAL_INT_PLUS_MICRO ; + *length =ARRAY_SIZE (int_time_avail); +return IIO_AVAIL_LIST ; -static ssize_t ltr501_show_intensity_scale_avail (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -struct ltr501_data *data =iio_priv (dev_to_iio_dev (dev)); -const struct ltr501_chip_info *info = data->chip_info; -ssize_t len =0 ; -int i; +case IIO_CHAN_INFO_SAMP_FREQ : + *vals = samp_freq_avail; + *type =IIO_VAL_INT_PLUS_MICRO ; + *length =ARRAY_SIZE (samp_freq_avail); +return IIO_AVAIL_LIST ; -for (i =0 ; i < info->als_gain_tbl_size; i++) { -if (info->als_gain[i].scale ==LTR501_RESERVED_GAIN ) -continue ; - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d.%06d " , - info->als_gain[i].scale, - info->als_gain[i].uscale); +default : +return -EINVAL ; } - - buf[len -1 ] ='\n' ; - -return len; } -static IIO_CONST_ATTR_INT_TIME_AVAIL("0.05 0.1 0.2 0.4"); -static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("20 10 5 2 1 0.5"); - -static IIO_DEVICE_ATTR(in_proximity_scale_available, S_IRUGO, - ltr501_show_proximity_scale_avail, NULL, 0); -static IIO_DEVICE_ATTR(in_intensity_scale_available, S_IRUGO, - ltr501_show_intensity_scale_avail, NULL, 0); - -static struct attribute *ltr501_attributes[] = { - &iio_dev_attr_in_proximity_scale_available.dev_attr.attr, - &iio_dev_attr_in_intensity_scale_available.dev_attr.attr, - &iio_const_attr_integration_time_available.dev_attr.attr, - &iio_const_attr_sampling_frequency_available.dev_attr.attr, -NULL -}; - -static struct attribute *ltr301_attributes[] = { - &iio_dev_attr_in_intensity_scale_available.dev_attr.attr, - &iio_const_attr_integration_time_available.dev_attr.attr, - &iio_const_attr_sampling_frequency_available.dev_attr.attr, -NULL -}; - -static const struct attribute_group ltr501_attribute_group = { - .attrs = ltr501_attributes, -}; - -static const struct attribute_group ltr301_attribute_group = { - .attrs = ltr301_attributes, -}; -static const struct iio_info ltr501_info_no_irq = { .read_raw = ltr501_read_raw, .write_raw = ltr501_write_raw, - .attrs = <r501_attribute_group, + .read_avail = ltr501_read_avail, };static const struct iio_info ltr501_info = { .read_raw = ltr501_read_raw, .write_raw = ltr501_write_raw, - .attrs = <r501_attribute_group, - .read_event_value = <r501_read_event, - .write_event_value = <r501_write_event, - .read_event_config = <r501_read_event_config, - .write_event_config = <r501_write_event_config, -}; - -static const struct iio_info ltr301_info_no_irq = { - .read_raw = ltr501_read_raw, - .write_raw = ltr501_write_raw, - .attrs = <r301_attribute_group, -}; - -static const struct iio_info ltr301_info = { - .read_raw = ltr501_read_raw, - .write_raw = ltr501_write_raw, - .attrs = <r301_attribute_group, - .read_event_value = <r501_read_event, - .write_event_value = <r501_write_event, - .read_event_config = <r501_read_event_config, - .write_event_config = <r501_write_event_config, + .read_avail = ltr501_read_avail, + .read_event_value = <r501_read_event, + .write_event_value = <r501_write_event, + .read_event_config = <r501_read_event_config, + .write_event_config = <r501_write_event_config, };static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
@@ -1226,8 +1186,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_mode_active = BIT(0) | BIT(1), .als_gain_mask = BIT(3), .als_gain_shift = 3, - .info = <r301_info, - .info_no_irq = <r301_info_no_irq, .channels = ltr301_channels, .no_channels = ARRAY_SIZE(ltr301_channels), },
@@ -1238,8 +1196,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_mode_active = BIT(0), .als_gain_mask = BIT(2) | BIT(3) | BIT(4), .als_gain_shift = 2, - .info = <r301_info, - .info_no_irq = <r301_info_no_irq, .channels = ltr301_channels, .no_channels = ARRAY_SIZE(ltr301_channels), },
@@ -1251,7 +1207,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_gain_mask = BIT(2) | BIT(3) | BIT(4), .als_gain_shift = 2, .no_irq_support = true, - .info_no_irq = <r301_info_no_irq, .channels = ltr301_channels, .no_channels = ARRAY_SIZE(ltr301_channels), },
@@ -1264,8 +1219,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_mode_active = BIT(0) | BIT(1), .als_gain_mask = BIT(3), .als_gain_shift = 3, - .info = <r501_info, - .info_no_irq = <r501_info_no_irq, .channels = ltr501_channels, .no_channels = ARRAY_SIZE(ltr501_channels), },
@@ -1278,8 +1231,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_mode_active = BIT(0), .als_gain_mask = BIT(2) | BIT(3) | BIT(4), .als_gain_shift = 2, - .info = <r501_info, - .info_no_irq = <r501_info_no_irq, .channels = ltr501_channels, .no_channels = ARRAY_SIZE(ltr501_channels), },
@@ -1548,7 +1499,7 @@ static int ltr501_probe(struct i2c_client *client) &data->near_level)) data->near_level =0 ; - indio_dev->info = data->chip_info->info; + indio_dev->info = <r501_info; indio_dev->channels = data->chip_info->channels; indio_dev->num_channels = data->chip_info->no_channels; indio_dev->name = name;
@@ -1573,7 +1524,7 @@ static int ltr501_probe(struct i2c_client *client)if (ret) goto powerdown_on_error; }else { - indio_dev->info = data->chip_info->info_no_irq; + indio_dev->info = <r501_info_no_irq; } ret = iio_triggered_buffer_setup(indio_dev, NULL,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 1/4] iio: light: ltr501: Switch to read_avail() op from manual attribute registration
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] iio: light: ltr501: wrong available masks break scale_available sysfs ABI - [Medium] iio: light…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] iio: light: ltr501: wrong available masks break scale_available sysfs ABI
- [Medium] iio: light: ltr501: ltr501_read_avail() exposes reserved gain entries
--
commit 62f3eb145ee7bea38108b1176e688878b094c714
Author: Svyatoslav Ryhel <[email protected]>
iio: light: ltr501: Switch to read_avail() op from manual attribute registration
This commit replaces manual *_available sysfs attribute registration with the IIO read_avail() callback and consolidates the per-chip iio_info structures.
Quoted 4 lines
drivers/iio/light/ltr501.c +0
-0
[ ... ]
drivers/iio/light/ltr501.c static const struct iio_event_spec ltr501_pxs_event_spec[] = { · line 610
Quoted 8 lines
drivers/iio/light/ltr501.c +1
-0@@ -590,6 +604,7 @@ static const struct iio_event_spec ltr501_pxs_event_spec[] = { .channel2 = (_mod), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = (_shared), \ + .info_mask_shared_by_all_available = (_shared), \ .scan_index = (_idx), \ .scan_type = { \ .sign = 'u', \
[Severity: High]
Does setting .info_mask_shared_by_all_available = (_shared) break the sysfs ABI for scale availability?
_shared includes BIT(IIO_CHAN_INFO_SCALE), so placing it in info_mask_shared_by_all_available registers scale_available instead of in_intensity_scale_available (which requires info_mask_shared_by_type_available).
In addition, the IIO_PROXIMITY channel in ltr501_channels sets BIT(IIO_CHAN_INFO_SCALE) in .info_mask_separate without a matching .info_mask_separate_available mask, so in_proximity_scale_available is no longer registered on ltr501 or ltr559 and the proximity scale branch in ltr501_read_avail() is unreachable.
Quoted 14 lines
drivers/iio/light/ltr501.c +4
-4@@ -1111,111 +1126,56 @@ static int ltr501_write_event_config(struct iio_dev *indio_dev,return -EINVAL ; } -static ssize_t ltr501_show_proximity_scale_avail (struct device *dev, -struct device_attribute *attr, -char *buf) +static int ltr501_read_avail (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +const int **vals,int *type,int *length,long mask) { -struct ltr501_data *data =iio_priv (dev_to_iio_dev (dev)); +struct ltr501_data *data =iio_priv (indio_dev);const struct ltr501_chip_info *info = data->chip_info;
[ ... ]
drivers/iio/light/ltr501.c static int ltr501_write_event_config(struct iio_dev *indio_dev, · line 1146
Quoted 11 lines
drivers/iio/light/ltr501.c +11
-0+switch (mask) { +case IIO_CHAN_INFO_SCALE : +if (chan->type ==IIO_INTENSITY ) { + *length = info->als_gain_tbl_size *2 ; + *vals = (const int *)info->als_gain; + }else { + *length = info->ps_gain_tbl_size *2 ; + *vals = (const int *)info->ps_gain; + } + *type =IIO_VAL_INT_PLUS_MICRO ; +return IIO_AVAIL_LIST ;
[Severity: Medium]
Does returning info->als_gain directly as IIO_AVAIL_LIST expose LTR501_RESERVED_GAIN sentinel entries to userspace?
ltr559_als_gain_tbl (used by ltr303, ltr329, and ltr559) is indexed by hardware register value and has two reserved entries:
drivers/iio/light/ltr501.c:
static const struct ltr501_gain ltr559_als_gain_tbl[] = {
...
{LTR501_RESERVED_GAIN, LTR501_RESERVED_GAIN},
{LTR501_RESERVED_GAIN, LTR501_RESERVED_GAIN},
{0, 20000},
{0, 10000},
};ltr501_show_intensity_scale_avail() previously skipped entries equal to LTR501_RESERVED_GAIN (-1), whereas iio_format_avail_list() formats each {-1, -1} pair as "-1.000001" in sysfs.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Jonathan Cameron
maintainerRe: [PATCH v2 1/4] iio: light: ltr501: Switch to read_avail() op from manual attribute registration
In reply to Svyatoslav RyhelQuoted 5 lines · On Fri, 6 Nov 2026 11:19:40 +0200 Svyatoslav Ryhel <[email protected]> wrote:
Switch to the
read_avail()operation from manual attribute group registration. This eliminates the need for per-chipattribute_groupstructures and relatedltr501_chip_infoiio_infoentries.Signed-off-by Svyatoslav Ryhel <[email protected]>
Given you were quick off the mark on sashiko on v1, I guess you already saw:
https://sashiko.dev/#/patchset/20261106091943.35783-1-clamor95%40gmail.com
It seems correct that you'll only get one attribute where there were two before. I suspect it's as simple as the mask should be set of shared_by_type_available not shared_by_all for scale and shared_by_all for only sampling frequency and integration time.
The current code is odd in having per type sampling_freq and integration time as both apply to the light channel as well I think. Not vital to fix that though so I'd just split the mask to make it work for both as it does today.
The current way the two Intensity channels is done is very odd. The .info_mask_shared_by_type should be the same for both of them (only one set of attrs will be created).
Ideally fix that as a precursor patch (don't label it as a fix though as it's just a code consistency thing rather than actually resulting in a change.)
Quoted 24 lines
--- drivers/iio/light/ltr501.c | 153 +++++++++++++------------------------ 1 file changed, 52 insertions(+), 101 deletions(-)static const struct
iio_infoltr501_info= {drivers/iio/light/ltr501.c +0
-16.read_raw = ltr501_read_raw, .write_raw = ltr501_write_raw, - .attrs = <r501_attribute_group, - .read_event_value = <r501_read_event, - .write_event_value = <r501_write_event, - .read_event_config = <r501_read_event_config, - .write_event_config = <r501_write_event_config, -}; - -static const struct iio_info ltr301_info_no_irq = { - .read_raw = ltr501_read_raw, - .write_raw = ltr501_write_raw, - .attrs = <r301_attribute_group, -}; - -static const struct iio_info ltr301_info = { - .read_raw = ltr501_read_raw, - .write_raw = ltr501_write_raw,
drivers/iio/light/ltr501.c static int ltr501_write_event_config(struct iio_dev *indio_dev, · line 1178
Quoted 10 lines
drivers/iio/light/ltr501.c +5
-5- .attrs = <r301_attribute_group, - .read_event_value = <r501_read_event, - .write_event_value = <r501_write_event, - .read_event_config = <r501_read_event_config, - .write_event_config = <r501_write_event_config, + .read_avail = ltr501_read_avail, + .read_event_value = <r501_read_event, + .write_event_value = <r501_write_event, + .read_event_config = <r501_read_event_config, + .write_event_config = <r501_write_event_config,
I'd prefer a precursor patch tidying up the indent as that should make the diff on this patch easier to read.
Quoted 1 line
};
Re: [PATCH v2 1/4] iio: light: ltr501: Switch to read_avail() op from manual attribute registration
сб, 7 лист. 2026 р. о 05:20 Jonathan Cameron <[email protected]> пише:
Quoted 18 lines
Quoted 5 lines · On Fri, 6 Nov 2026 11:19:40 +0200 Svyatoslav Ryhel <[email protected]> wrote:
Switch to the
read_avail()operation from manual attribute group registration. This eliminates the need for per-chipattribute_groupstructures and relatedltr501_chip_infoiio_infoentries.Signed-off-by Svyatoslav Ryhel <[email protected]>Given you were quick off the mark on sashiko on v1, I guess you already saw:
https://sashiko.dev/#/patchset/20261106091943.35783-1-clamor95%40gmail.comIt seems correct that you'll only get one attribute where there were two before. I suspect it's as simple as the mask should be set of
shared_by_type_availablenotshared_by_allfor scale andshared_by_allfor only sampling frequency and integration time.
Quoted 5 lines
The current code is odd in having per type
sampling_freqand integration time as both apply to the light channel as well I think. Not vital to fix that though so I'd just split the mask to make it work for both as it does today.
- .info_mask_shared_by_all_available = (_shared), \ + .info_mask_shared_by_type_available = (_avail_type), \ + .info_mask_shared_by_all_available = (_avail_all), \
...
static const struct iio_chan_spec ltr501_channels[] = {
LTR501_LIGHT_CHANNEL(),
- LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0, IIO_MOD_LIGHT_BOTH, 0,
+ LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0,
IIO_MOD_LIGHT_BOTH, 0, 0, 0,
ltr501_als_event_spec,
ARRAY_SIZE(ltr501_als_event_spec)),
LTR501_INTENSITY_CHANNEL(1, LTR501_ALS_DATA1, IIO_MOD_LIGHT_IR,
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_SAMP_FREQ),
- NULL, 0),
+ BIT(IIO_CHAN_INFO_SCALE),
+ BIT(IIO_CHAN_INFO_INT_TIME) |
+ BIT(IIO_CHAN_INFO_SAMP_FREQ), NULL, 0), {
.type = IIO_PROXIMITY,
.address = LTR501_PS_DATA, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE),
+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),
.scan_index = 2,
.scan_type = {IIO_CHAN_INFO_SCALE is by type and IIO_CHAN_INFO_INT_TIME and IIO_CHAN_INFO_SAMP_FREQ by all
Quoted 7 lines
The current way the two Intensity channels is done is very odd. The .info_mask_shared_by_type should be the same for both of them (only one set of attrs will be created).
Ideally fix that as a precursor patch (don't label it as a fix though as it's just a code consistency thing rather than actually resulting in a change.)
No more precursor patches! I am just a random contributor, not a driver author, not a subsystem maintainer, not even a random code janitor. Stop using me for random unrelated fixes!
Quoted 30 lines
Quoted 30 lines
--- drivers/iio/light/ltr501.c | 153 +++++++++++++------------------------ 1 file changed, 52 insertions(+), 101 deletions(-)static const struct iio_info ltr501_info = { .read_raw = ltr501_read_raw, .write_raw = ltr501_write_raw,drivers/iio/light/ltr501.c +0
-21- .attrs = <r501_attribute_group, - .read_event_value = <r501_read_event, - .write_event_value = <r501_write_event, - .read_event_config = <r501_read_event_config, - .write_event_config = <r501_write_event_config, -}; - -static const struct iio_info ltr301_info_no_irq = { - .read_raw = ltr501_read_raw, - .write_raw = ltr501_write_raw, - .attrs = <r301_attribute_group, -}; - -static const struct iio_info ltr301_info = { - .read_raw = ltr501_read_raw, - .write_raw = ltr501_write_raw, - .attrs = <r301_attribute_group, - .read_event_value = <r501_read_event, - .write_event_value = <r501_write_event, - .read_event_config = <r501_read_event_config, - .write_event_config = <r501_write_event_config,
Quoted 9 lines
drivers/iio/light/ltr501.c static int ltr501_write_event_config(struct iio_dev *indio_dev, · line 1178
Quoted 5 lines
drivers/iio/light/ltr501.c +5
-0+ .read_avail = ltr501_read_avail, + .read_event_value = <r501_read_event, + .write_event_value = <r501_write_event, + .read_event_config = <r501_read_event_config, + .write_event_config = <r501_write_event_config,I'd prefer a precursor patch tidying up the indent as that should make the diff on this patch easier to read.
NO, either this, or I can drop alignment adjustment and you can fix it on your own whenever you like.
Quoted 3 lines
Quoted 2 lines
};
Re: [PATCH v2 1/4] iio: light: ltr501: Switch to read_avail() op from manual attribute registration
On Sat, 7 Nov 2026 12:10:06 +0200
Svyatoslav Ryhel <[email protected]> wrote:
...
Quoted 11 lines
IIO_CHAN_INFO_SCALEis by type andIIO_CHAN_INFO_INT_TIMEandIIO_CHAN_INFO_SAMP_FREQby allQuoted 7 lines
The current way the two Intensity channels is done is very odd. The .info_mask_shared_by_type should be the same for both of them (only one set of attrs will be created).
Ideally fix that as a precursor patch (don't label it as a fix though as it's just a code consistency thing rather than actually resulting in a change.)
Quoted 3 lines
No more precursor patches! I am just a random contributor, not a driver author, not a subsystem maintainer, not even a random code janitor. Stop using me for random unrelated fixes!
It's not an attempt to use you as a janitor; reviewers often suggest cleanups in the adjacent code so that no new patches are built on inconsistent code patterns.
Nevertheless, it's only a suggestion, so it's no problem if you don't have the time or just want to focus on adding new functionality.
Signature · 2 lines
Kind regards, Joshua Crofts
PATCH v2 2/4 iio: light: ltr501: Switch to modern match mechanism
In reply to Svyatoslav RyhelRemove the chip enum, break the chip list structure into individual elements, and pass each element using i2c_get_match_data().
--- drivers/iio/light/ltr501.c | 165 +++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 91 deletions(-)
drivers/iio/light/ltr501.c +74 -91
@@ -90,14 +90,6 @@ struct ltr501_samp_table {#define LTR501_RESERVED_GAIN -1 -enum { - ltr301, - ltr303, - ltr329, - ltr501, - ltr559, -}; -struct ltr501_gain {int scale;int uscale;
@@ -1178,62 +1170,64 @@ static const struct iio_info ltr501_info = { .write_event_config = <r501_write_event_config, }; -static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { - [ltr301] = { - .partid =0x08 , - .als_gain = ltr501_als_gain_tbl, - .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), - .als_mode_active =BIT (0 ) |BIT (1 ), - .als_gain_mask =BIT (3 ), - .als_gain_shift =3 , - .channels = ltr301_channels, - .no_channels =ARRAY_SIZE (ltr301_channels), - }, - [ltr303] = { - .partid =0x0A , - .als_gain = ltr559_als_gain_tbl, - .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), - .als_mode_active =BIT (0 ), - .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), - .als_gain_shift =2 , - .channels = ltr301_channels, - .no_channels =ARRAY_SIZE (ltr301_channels), - }, - [ltr329] = { - .partid =0x0A , - .als_gain = ltr559_als_gain_tbl, - .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), - .als_mode_active =BIT (0 ), - .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), - .als_gain_shift =2 , - .no_irq_support = true, - .channels = ltr301_channels, - .no_channels =ARRAY_SIZE (ltr301_channels), - }, - [ltr501] = { - .partid =0x08 , - .als_gain = ltr501_als_gain_tbl, - .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), - .ps_gain = ltr501_ps_gain_tbl, - .ps_gain_tbl_size =ARRAY_SIZE (ltr501_ps_gain_tbl), - .als_mode_active =BIT (0 ) |BIT (1 ), - .als_gain_mask =BIT (3 ), - .als_gain_shift =3 , - .channels = ltr501_channels, - .no_channels =ARRAY_SIZE (ltr501_channels), - }, - [ltr559] = { - .partid =0x09 , - .als_gain = ltr559_als_gain_tbl, - .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), - .ps_gain = ltr559_ps_gain_tbl, - .ps_gain_tbl_size =ARRAY_SIZE (ltr559_ps_gain_tbl), - .als_mode_active =BIT (0 ), - .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), - .als_gain_shift =2 , - .channels = ltr501_channels, - .no_channels =ARRAY_SIZE (ltr501_channels), - }, +static const struct ltr501_chip_info ltr301_chip_info_tbl = { + .partid =0x08 , + .als_gain = ltr501_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), + .als_mode_active =BIT (0 ) |BIT (1 ), + .als_gain_mask =BIT (3 ), + .als_gain_shift =3 , + .channels = ltr301_channels, + .no_channels =ARRAY_SIZE (ltr301_channels), +}; + +static const struct ltr501_chip_info ltr303_chip_info_tbl = { + .partid =0x0A , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), + .als_gain_shift =2 , + .channels = ltr301_channels, + .no_channels =ARRAY_SIZE (ltr301_channels), +}; + +static const struct ltr501_chip_info ltr329_chip_info_tbl = { + .partid =0x0A , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), + .als_gain_shift =2 , + .no_irq_support = true, + .channels = ltr301_channels, + .no_channels =ARRAY_SIZE (ltr301_channels), +}; + +static const struct ltr501_chip_info ltr501_chip_info_tbl = { + .partid =0x08 , + .als_gain = ltr501_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), + .ps_gain = ltr501_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr501_ps_gain_tbl), + .als_mode_active =BIT (0 ) |BIT (1 ), + .als_gain_mask =BIT (3 ), + .als_gain_shift =3 , + .channels = ltr501_channels, + .no_channels =ARRAY_SIZE (ltr501_channels), +}; + +static const struct ltr501_chip_info ltr559_chip_info_tbl = { + .partid =0x09 , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .ps_gain = ltr559_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr559_ps_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), + .als_gain_shift =2 , + .channels = ltr501_channels, + .no_channels =ARRAY_SIZE (ltr501_channels), };static int ltr501_write_contr (struct ltr501_data *data,u8 als_val,u8 ps_val)
@@ -1393,14 +1387,11 @@ static int ltr501_powerdown(struct ltr501_data *data)static int ltr501_probe (struct i2c_client *client) { -const struct i2c_device_id *id =i2c_client_get_device_id (client);static const char *const regulator_names[] = {"vdd" ,"vddio" };struct ltr501_data *data;struct iio_dev *indio_dev;struct regmap *regmap; -const void *ddata =NULL ; -int partid, chip_idx; -const char *name; +int partid;int ret; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));
@@ -1480,18 +1471,10 @@ static int ltr501_probe(struct i2c_client *client)if (ret <0 )return ret; -if (id) { - name = id->name; - chip_idx = id->driver_data; - }else { - name =iio_get_acpi_device_name_and_data (&client->dev, &ddata); - chip_idx = (intptr_t )ddata; - } -if (!name) + data->chip_info =i2c_get_match_data (client); +if (!data->chip_info)return -ENODEV ; - data->chip_info = <r501_chip_info_tbl[chip_idx]; -if ((partid >>4 ) != data->chip_info->partid)return -ENODEV ;
@@ -1502,7 +1485,7 @@ static int ltr501_probe(struct i2c_client *client) indio_dev->info = <r501_info; indio_dev->channels = data->chip_info->channels; indio_dev->num_channels = data->chip_info->no_channels; - indio_dev->name = name; + indio_dev->name = client->name; indio_dev->modes =INDIO_DIRECT_MODE ; ret =ltr501_init (data);
@@ -1573,29 +1556,29 @@ static int ltr501_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(ltr501_pm_ops, ltr501_suspend, ltr501_resume);static const struct acpi_device_id ltr_acpi_match[] = { - {"LTER0301" , ltr301 }, + {"LTER0301" , .driver_data = (kernel_ulong_t)<r301_chip_info_tbl },/* https://www.catalog.update.microsoft.com/Search.aspx?q=lter0303 */ - {"LTER0303" , ltr303 }, + {"LTER0303" , .driver_data = (kernel_ulong_t)<r303_chip_info_tbl }, { } };MODULE_DEVICE_TABLE (acpi, ltr_acpi_match);static const struct i2c_device_id ltr501_id[] = { - { .name ="ltr301" , .driver_data = ltr301 }, - { .name ="ltr303" , .driver_data = ltr303 }, - { .name ="ltr329" , .driver_data = ltr329 }, - { .name ="ltr501" , .driver_data = ltr501 }, - { .name ="ltr559" , .driver_data = ltr559 }, + { .name ="ltr301" , .driver_data = (kernel_ulong_t)<r301_chip_info_tbl }, + { .name ="ltr303" , .driver_data = (kernel_ulong_t)<r303_chip_info_tbl }, + { .name ="ltr329" , .driver_data = (kernel_ulong_t)<r329_chip_info_tbl }, + { .name ="ltr501" , .driver_data = (kernel_ulong_t)<r501_chip_info_tbl }, + { .name ="ltr559" , .driver_data = (kernel_ulong_t)<r559_chip_info_tbl }, { } };MODULE_DEVICE_TABLE (i2c, ltr501_id);static const struct of_device_id ltr501_of_match[] = { - { .compatible ="liteon,ltr301" , }, - { .compatible ="liteon,ltr303" , }, - { .compatible ="liteon,ltr329" , }, - { .compatible ="liteon,ltr501" , }, - { .compatible ="liteon,ltr559" , }, + { .compatible ="liteon,ltr301" , .data = <r301_chip_info_tbl }, + { .compatible ="liteon,ltr303" , .data = <r303_chip_info_tbl }, + { .compatible ="liteon,ltr329" , .data = <r329_chip_info_tbl }, + { .compatible ="liteon,ltr501" , .data = <r501_chip_info_tbl }, + { .compatible ="liteon,ltr559" , .data = <r559_chip_info_tbl }, { } };MODULE_DEVICE_TABLE (of, ltr501_of_match);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 2/4] iio: light: ltr501: Switch to modern match mechanism
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] iio: light: ltr501: unintended sysfs name change in ltr501_probe() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] iio: light: ltr501: unintended sysfs name change in ltr501_probe()
--
commit 1e03d9253f6f315d8f95ed562a39ab7edc44ec2b
Author: Svyatoslav Ryhel <[email protected]>
iio: light: ltr501: Switch to modern match mechanism
This commit replaces the chip enum and array with per-chip info structs retrieved via i2c_get_match_data().
Quoted 4 lines
drivers/iio/light/ltr501.c +0
-0
[ ... ]
Quoted 22 lines
drivers/iio/light/ltr501.c +2
-10@@ -1480,18 +1471,10 @@ static int ltr501_probe(struct i2c_client *client)if (ret <0 )return ret; -if (id) { - name = id->name; - chip_idx = id->driver_data; - }else { - name =iio_get_acpi_device_name_and_data (&client->dev, &ddata); - chip_idx = (intptr_t )ddata; - } -if (!name) + data->chip_info =i2c_get_match_data (client); +if (!data->chip_info)return -ENODEV ; - data->chip_info = <r501_chip_info_tbl[chip_idx]; -if ((partid >>4 ) != data->chip_info->partid)return -ENODEV ;
drivers/iio/light/ltr501.c static int ltr501_probe(struct i2c_client *client) · line 1489
Quoted 6 lines
drivers/iio/light/ltr501.c +1
-1@@ -1502,7 +1485,7 @@ static int ltr501_probe(struct i2c_client *client) indio_dev->info = <r501_info; indio_dev->channels = data->chip_info->channels; indio_dev->num_channels = data->chip_info->no_channels; - indio_dev->name = name; + indio_dev->name = client->name; indio_dev->modes =INDIO_DIRECT_MODE ;
[Severity: Medium]
Does assigning client->name to indio_dev->name change the exported IIO sysfs device name on ACPI systems?
Previously, iio_get_acpi_device_name_and_data() returned dev_name(&client->dev), which is "i2c-LTER0301:00" or "i2c-LTER0303:00". For ACPI-enumerated I2C clients, i2c_acpi_get_info() populates client->name from the ACPI device name without the "i2c-" prefix ("LTER0301:00" / "LTER0303:00"), altering the user-visible /sys/bus/iio/devices/iio:deviceX/name attribute (neither preserving the legacy ACPI name nor using the canonical chip name from chip_info).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Jonathan Cameron
maintainerRe: [PATCH v2 2/4] iio: light: ltr501: Switch to modern match mechanism
In reply to Svyatoslav RyhelQuoted 2 lines · On Fri, 6 Nov 2026 11:19:41 +0200 Svyatoslav Ryhel <[email protected]> wrote:
Remove the chip enum, break the chip list structure into individual elements, and pass each element using
i2c_get_match_data().
Sashiko calls out that for ACPI this results in an ABI change. The original code did the ABI wrong but that unfortunately doesn't mean we can change this one as it is an artefact of a time when we weren't so careful about those names.
So you'll need to put special handling back in for the ACPI parts and that name. Some other things in the existing code noted inline that would be nice to clean up whilst you are here.
Quoted 29 lines
Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/iio/light/ltr501.c | 165 +++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 91 deletions(-)drivers/iio/light/ltr501.c +18
-0+static const struct ltr501_chip_info ltr301_chip_info_tbl = { + .partid =0x08 , + .als_gain = ltr501_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), + .als_mode_active =BIT (0 ) |BIT (1 ), + .als_gain_mask =BIT (3 ), + .als_gain_shift =3 , + .channels = ltr301_channels, + .no_channels =ARRAY_SIZE (ltr301_channels), +}; + +static const struct ltr501_chip_info ltr303_chip_info_tbl = { + .partid =0x0A , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), + .als_gain_shift =2 ,
drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1200
Quoted 10 lines
drivers/iio/light/ltr501.c +10
-0+ .channels = ltr301_channels, + .no_channels = ARRAY_SIZE(ltr301_channels), +}; + +static const struct ltr501_chip_info ltr329_chip_info_tbl = { + .partid =0x0A , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ),
As below. Same for all the others. That would be a separate cleanup patch though -> perhaps do it with getting rid of the als_gain_shift.
drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1213
Quoted 13 lines
drivers/iio/light/ltr501.c +13
-0+ .als_gain_shift = 2, + .no_irq_support = true, + .channels = ltr301_channels, + .no_channels = ARRAY_SIZE(ltr301_channels), +}; + +static const struct ltr501_chip_info ltr501_chip_info_tbl = { + .partid =0x08 , + .als_gain = ltr501_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), + .ps_gain = ltr501_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr501_ps_gain_tbl), + .als_mode_active =BIT (0 ) |BIT (1 ),
As below
Quoted 4 lines
drivers/iio/light/ltr501.c +4
-0+ .als_gain_mask = BIT(3), + .als_gain_shift = 3, + .channels = ltr501_channels, + .no_channels = ARRAY_SIZE(ltr501_channels),
drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1227
Quoted 10 lines
drivers/iio/light/ltr501.c +10
-0+}; + +static const struct ltr501_chip_info ltr559_chip_info_tbl = { + .partid =0x09 , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .ps_gain = ltr559_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr559_ps_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ),
Is it really 3 separate bits, or GENMASK(4, 2) to
represent a 3 bit shift?
Whilst you are touching the driver can we get rid of the separate shift by using field_prep() field_get() using just the mask?
Quoted 27 lines
drivers/iio/light/ltr501.c +4
-5+ .als_gain_shift = 2, + .channels = ltr501_channels, + .no_channels = ARRAY_SIZE(ltr501_channels), };static int ltr501_write_contr (struct ltr501_data *data,u8 als_val,u8 ps_val)@@ -1393,14 +1387,11 @@ static int ltr501_powerdown(struct ltr501_data *data)static int ltr501_probe (struct i2c_client *client) { -const struct i2c_device_id *id =i2c_client_get_device_id (client);static const char *const regulator_names[] = {"vdd" ,"vddio" };struct ltr501_data *data;struct iio_dev *indio_dev;struct regmap *regmap; -const void *ddata =NULL ; -int partid, chip_idx; -const char *name; +int partid;int ret; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));@@ -1480,18 +1471,10 @@ static int ltr501_probe(struct i2c_client *client)if (ret <0 )return ret; -if (id) {
drivers/iio/light/ltr501.c static int ltr501_probe(struct i2c_client *client) · line 1476
Quoted 10 lines
drivers/iio/light/ltr501.c +2
-7- name = id->name; - chip_idx = id->driver_data; - }else { - name =iio_get_acpi_device_name_and_data (&client->dev, &ddata); - chip_idx = (intptr_t )ddata; - } -if (!name) + data->chip_info =i2c_get_match_data (client); +if (!data->chip_info)return -ENODEV ;
As above. Unfortunately at this point we'll still need to do some special handling to match the existing indio_dev->name.
Quoted 14 lines
drivers/iio/light/ltr501.c +1
-3- data->chip_info = <r501_chip_info_tbl[chip_idx]; -if ((partid >>4 ) != data->chip_info->partid)return -ENODEV ;@@ -1502,7 +1485,7 @@ static int ltr501_probe(struct i2c_client *client) indio_dev->info = <r501_info; indio_dev->channels = data->chip_info->channels; indio_dev->num_channels = data->chip_info->no_channels; - indio_dev->name = name; + indio_dev->name = client->name; indio_dev->modes =INDIO_DIRECT_MODE ;
Re: [PATCH v2 2/4] iio: light: ltr501: Switch to modern match mechanism
сб, 7 лист. 2026 р. о 05:30 Jonathan Cameron <[email protected]> пише:
Quoted 51 lines
Quoted 2 lines · On Fri, 6 Nov 2026 11:19:41 +0200 Svyatoslav Ryhel <[email protected]> wrote:
Remove the chip enum, break the chip list structure into individual elements, and pass each element using
i2c_get_match_data().Sashiko calls out that for ACPI this results in an ABI change. The original code did the ABI wrong but that unfortunately doesn't mean we can change this one as it is an artefact of a time when we weren't so careful about those names.
So you'll need to put special handling back in for the ACPI parts and that name. Some other things in the existing code noted inline that would be nice to clean up whilst you are here.
Quoted 35 lines
Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/iio/light/ltr501.c | 165 +++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 91 deletions(-)drivers/iio/light/ltr501.c +24
-0+static const struct ltr501_chip_info ltr301_chip_info_tbl = { + .partid =0x08 , + .als_gain = ltr501_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), + .als_mode_active =BIT (0 ) |BIT (1 ), + .als_gain_mask =BIT (3 ), + .als_gain_shift =3 , + .channels = ltr301_channels, + .no_channels =ARRAY_SIZE (ltr301_channels), +}; + +static const struct ltr501_chip_info ltr303_chip_info_tbl = { + .partid =0x0A , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), + .als_gain_shift =2 , + .channels = ltr301_channels, + .no_channels =ARRAY_SIZE (ltr301_channels), +}; + +static const struct ltr501_chip_info ltr329_chip_info_tbl = { + .partid =0x0A ,
Quoted 9 lines
drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1189
Quoted 4 lines
drivers/iio/light/ltr501.c +4
-0+ .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl), + .als_mode_active = BIT(0), + .als_gain_mask = BIT(2) | BIT(3) | BIT(4),As below. Same for all the others. That would be a separate cleanup patch though -> perhaps do it with getting rid of the
als_gain_shift.
This is all out of scope of my series. I am not a code janitor!
Quoted 61 lines
drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1213
Quoted 13 lines
drivers/iio/light/ltr501.c +13
-0+ .als_gain_shift = 2, + .no_irq_support = true, + .channels = ltr301_channels, + .no_channels = ARRAY_SIZE(ltr301_channels), +}; + +static const struct ltr501_chip_info ltr501_chip_info_tbl = { + .partid =0x08 , + .als_gain = ltr501_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), + .ps_gain = ltr501_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr501_ps_gain_tbl), + .als_mode_active =BIT (0 ) |BIT (1 ),As below
Quoted 4 lines
drivers/iio/light/ltr501.c +4
-0+ .als_gain_mask = BIT(3), + .als_gain_shift = 3, + .channels = ltr501_channels, + .no_channels = ARRAY_SIZE(ltr501_channels),drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1227
Quoted 10 lines
drivers/iio/light/ltr501.c +10
-0+}; + +static const struct ltr501_chip_info ltr559_chip_info_tbl = { + .partid =0x09 , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .ps_gain = ltr559_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr559_ps_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ),Is it really 3 separate bits, or
GENMASK(4, 2)to
represent a 3 bit shift?Whilst you are touching the driver can we get rid of the separate shift by using
field_prep()field_get()using just the mask?Quoted 26 lines
drivers/iio/light/ltr501.c +4
-4+ .als_gain_shift = 2, + .channels = ltr501_channels, + .no_channels = ARRAY_SIZE(ltr501_channels), };static int ltr501_write_contr (struct ltr501_data *data,u8 als_val,u8 ps_val)@@ -1393,14 +1387,11 @@ static int ltr501_powerdown(struct ltr501_data *data)static int ltr501_probe (struct i2c_client *client) { -const struct i2c_device_id *id =i2c_client_get_device_id (client);static const char *const regulator_names[] = {"vdd" ,"vddio" };struct ltr501_data *data;struct iio_dev *indio_dev;struct regmap *regmap; -const void *ddata =NULL ; -int partid, chip_idx; -const char *name; +int partid;int ret; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));@@ -1480,18 +1471,10 @@ static int ltr501_probe(struct i2c_client *client)if (ret <0 )return ret;
Quoted 15 lines
drivers/iio/light/ltr501.c static int ltr501_probe(struct i2c_client *client) · line 1476
Quoted 11 lines
drivers/iio/light/ltr501.c +2
-8-if (id) { - name = id->name; - chip_idx = id->driver_data; - }else { - name =iio_get_acpi_device_name_and_data (&client->dev, &ddata); - chip_idx = (intptr_t )ddata; - } -if (!name) + data->chip_info =i2c_get_match_data (client); +if (!data->chip_info)return -ENODEV ;As above. Unfortunately at this point we'll still need to do some special handling to match the existing
indio_dev->name.
const struct i2c_device_id *id = i2c_client_get_device_id(client);
...
indio_dev->name = id ? id->name :iio_get_acpi_device_name_and_data(&client->dev, NULL);
Will this be acceptible?
Quoted 14 lines
Quoted 14 lines
drivers/iio/light/ltr501.c +1
-3- data->chip_info = <r501_chip_info_tbl[chip_idx]; -if ((partid >>4 ) != data->chip_info->partid)return -ENODEV ;@@ -1502,7 +1485,7 @@ static int ltr501_probe(struct i2c_client *client) indio_dev->info = <r501_info; indio_dev->channels = data->chip_info->channels; indio_dev->num_channels = data->chip_info->no_channels; - indio_dev->name = name; + indio_dev->name = client->name; indio_dev->modes =INDIO_DIRECT_MODE ;
Jonathan Cameron
maintainerRe: [PATCH v2 2/4] iio: light: ltr501: Switch to modern match mechanism
Quoted 62 lines · On Sat, 7 Nov 2026 12:13:44 +0200 Svyatoslav Ryhel <[email protected]> wrote:
сб, 7 лист. 2026 р. о 05:30 Jonathan Cameron <[email protected]> пише:
Quoted 51 lines
Quoted 2 lines · On Fri, 6 Nov 2026 11:19:41 +0200 Svyatoslav Ryhel <[email protected]> wrote:
Remove the chip enum, break the chip list structure into individual elements, and pass each element using
i2c_get_match_data().Sashiko calls out that for ACPI this results in an ABI change. The original code did the ABI wrong but that unfortunately doesn't mean we can change this one as it is an artefact of a time when we weren't so careful about those names.
So you'll need to put special handling back in for the ACPI parts and that name. Some other things in the existing code noted inline that would be nice to clean up whilst you are here.
Quoted 35 lines
Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/iio/light/ltr501.c | 165 +++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 91 deletions(-)drivers/iio/light/ltr501.c +24
-0+static const struct ltr501_chip_info ltr301_chip_info_tbl = { + .partid =0x08 , + .als_gain = ltr501_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), + .als_mode_active =BIT (0 ) |BIT (1 ), + .als_gain_mask =BIT (3 ), + .als_gain_shift =3 , + .channels = ltr301_channels, + .no_channels =ARRAY_SIZE (ltr301_channels), +}; + +static const struct ltr501_chip_info ltr303_chip_info_tbl = { + .partid =0x0A , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ), + .als_gain_shift =2 , + .channels = ltr301_channels, + .no_channels =ARRAY_SIZE (ltr301_channels), +}; + +static const struct ltr501_chip_info ltr329_chip_info_tbl = { + .partid =0x0A ,Quoted 9 lines
drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1189
Quoted 4 lines
drivers/iio/light/ltr501.c +4
-0+ .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl), + .als_mode_active = BIT(0), + .als_gain_mask = BIT(2) | BIT(3) | BIT(4),As below. Same for all the others. That would be a separate cleanup patch though -> perhaps do it with getting rid of the
als_gain_shift.
Quoted 1 line
This is all out of scope of my series. I am not a code janitor!
It is common practice to ask anyone who is modifying the code to tidy up inconsistencies, modernise and make minor general improvements. If nothing else, if someone else makes those improvements within a short window of you working on the driver I'm going ask you to test them anyway.
I very rarely make a request for major refactoring because that burden is unreasonable. This would fall under the scope of what I'd normally consider reasonable.
Leaving that cleanup for future is fine. Just state that in you have chosen to do so in the cover letter for the next version.
Quoted 78 lines
Quoted 62 lines
Quoted 4 lines
drivers/iio/light/ltr501.c +3
-0+ .als_gain_shift = 2, + .no_irq_support = true, + .channels = ltr301_channels,drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1213
Quoted 10 lines
drivers/iio/light/ltr501.c +10
-0+ .no_channels = ARRAY_SIZE(ltr301_channels), +}; + +static const struct ltr501_chip_info ltr501_chip_info_tbl = { + .partid =0x08 , + .als_gain = ltr501_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr501_als_gain_tbl), + .ps_gain = ltr501_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr501_ps_gain_tbl), + .als_mode_active =BIT (0 ) |BIT (1 ),As below
Quoted 4 lines
drivers/iio/light/ltr501.c +4
-0+ .als_gain_mask = BIT(3), + .als_gain_shift = 3, + .channels = ltr501_channels, + .no_channels = ARRAY_SIZE(ltr501_channels),drivers/iio/light/ltr501.c static const struct iio_info ltr501_info = { · line 1227
Quoted 10 lines
drivers/iio/light/ltr501.c +10
-0+}; + +static const struct ltr501_chip_info ltr559_chip_info_tbl = { + .partid =0x09 , + .als_gain = ltr559_als_gain_tbl, + .als_gain_tbl_size =ARRAY_SIZE (ltr559_als_gain_tbl), + .ps_gain = ltr559_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr559_ps_gain_tbl), + .als_mode_active =BIT (0 ), + .als_gain_mask =BIT (2 ) |BIT (3 ) |BIT (4 ),Is it really 3 separate bits, or
GENMASK(4, 2)to
represent a 3 bit shift?Whilst you are touching the driver can we get rid of the separate shift by using
field_prep()field_get()using just the mask?Quoted 26 lines
drivers/iio/light/ltr501.c +4
-4+ .als_gain_shift = 2, + .channels = ltr501_channels, + .no_channels = ARRAY_SIZE(ltr501_channels), };static int ltr501_write_contr (struct ltr501_data *data,u8 als_val,u8 ps_val)@@ -1393,14 +1387,11 @@ static int ltr501_powerdown(struct ltr501_data *data)static int ltr501_probe (struct i2c_client *client) { -const struct i2c_device_id *id =i2c_client_get_device_id (client);static const char *const regulator_names[] = {"vdd" ,"vddio" };struct ltr501_data *data;struct iio_dev *indio_dev;struct regmap *regmap; -const void *ddata =NULL ; -int partid, chip_idx; -const char *name; +int partid;int ret; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));@@ -1480,18 +1471,10 @@ static int ltr501_probe(struct i2c_client *client)if (ret <0 )return ret;Quoted 15 lines
drivers/iio/light/ltr501.c static int ltr501_probe(struct i2c_client *client) · line 1476
Quoted 11 lines
drivers/iio/light/ltr501.c +2
-8-if (id) { - name = id->name; - chip_idx = id->driver_data; - }else { - name =iio_get_acpi_device_name_and_data (&client->dev, &ddata); - chip_idx = (intptr_t )ddata; - } -if (!name) + data->chip_info =i2c_get_match_data (client); +if (!data->chip_info)return -ENODEV ;As above. Unfortunately at this point we'll still need to do some special handling to match the existing
indio_dev->name.
Quoted 8 lines
const struct
i2c_device_id*id =i2c_client_get_device_id(client);...
indio_dev->name= id ?id->name:iio_get_acpi_device_name_and_data(&client->dev, NULL);Will this be acceptible?
Yes. I think that should work.
PATCH v2 3/4 dt-bindings: iio: light: ltr501: Document LTR659 proximity sensor
In reply to Svyatoslav RyhelThe LTR-659PS-01 is a proximity sensor similar to the LTR-559ALS-01, but without ambient light sensing support.
--- Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml +1 -0
@@ -17,6 +17,7 @@ properties: - liteon,ltr329 - liteon,ltr501 - liteon,ltr559 + - liteon,ltr659 reg: maxItems: 1
Signature · 1 line
2.53.0
Re: [PATCH v2 3/4] dt-bindings: iio: light: ltr501: Document LTR659 proximity sensor
pw-bot: not-applicable
PATCH v2 4/4 iio: light: ltr501: Add support for the LTR-659PS-01 proximity sensor
In reply to Svyatoslav RyhelAdd support for the Lite-On LTR-659PS-01 proximity sensor. This device is nearly identical to the LTR-559ALS-01, but omits all elements related to ambient light sensing.
Add a no_als_support flag, similar to how no_irq_support is used, to isolate ALS register access for the LTR-659PS-01, since ALS registers are marked as reserved and interactions with them are discouraged.
The ltr501_trigger_handler relied on the scan index to identify channels. This approach is fragile regarding channel status flags and can break if the index is not strictly set. Switch to checking the channel type instead.
--- drivers/iio/light/ltr501.c | 73 +++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 12 deletions(-)
drivers/iio/light/ltr501.c +61 -12
@@ -151,6 +151,7 @@ struct ltr501_chip_info {u8 als_gain_mask;u8 als_gain_shift;bool no_irq_support; +bool no_als_support;struct iio_chan_spec const *channels;const int no_channels; };
@@ -192,6 +193,11 @@ static bool ltr501_has_irq_support(const struct ltr501_chip_info *info)return !info->no_irq_support; } +static bool ltr501_has_als_support (const struct ltr501_chip_info *info) +{ +return !info->no_als_support; +} +static int ltr501_match_samp_freq (const struct ltr501_samp_table *tab,int len,int val,int val2) {
@@ -656,6 +662,29 @@ static const struct iio_chan_spec ltr301_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(2), }; +static const struct iio_chan_spec ltr659_channels[] = { + { + .type =IIO_PROXIMITY , + .address =LTR501_PS_DATA , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_separate_available =BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .scan_index =0 , + .scan_type = { + .sign ='u' , + .realbits =11 , + .storagebits =16 , + .endianness =IIO_CPU , + }, + .event_spec = ltr501_pxs_event_spec, + .num_event_specs =ARRAY_SIZE (ltr501_pxs_event_spec), + .ext_info = ltr501_ext_info, + }, +IIO_CHAN_SOFT_TIMESTAMP (1 ), +}; +static int ltr501_read_info_raw (struct ltr501_data *data,struct iio_chan_spec const *chan,int *val)
@@ -1230,13 +1259,24 @@ static const struct ltr501_chip_info ltr559_chip_info_tbl = { .no_channels = ARRAY_SIZE(ltr501_channels), }; +static const struct ltr501_chip_info ltr659_chip_info_tbl = { + .partid =0x09 , + .ps_gain = ltr559_ps_gain_tbl, + .ps_gain_tbl_size =ARRAY_SIZE (ltr559_ps_gain_tbl), + .no_als_support = true, + .channels = ltr659_channels, + .no_channels =ARRAY_SIZE (ltr659_channels), +}; +static int ltr501_write_contr (struct ltr501_data *data,u8 als_val,u8 ps_val) {int ret; - ret =regmap_write (data->regmap,LTR501_ALS_CONTR , als_val); -if (ret <0 ) -return ret; +if (ltr501_has_als_support (data->chip_info)) { + ret =regmap_write (data->regmap,LTR501_ALS_CONTR , als_val); +if (ret <0 ) +return ret; + }return regmap_write (data->regmap,LTR501_PS_CONTR , ps_val); }
@@ -1251,16 +1291,21 @@ static irqreturn_t ltr501_trigger_handler(int irq, void *p)aligned_s64 ts; } scan = { };__le16 als_buf[2 ]; +unsigned int i;u8 mask =0 ;int j =0 ;int ret, psdata;/* figure out which data needs to be ready */ -if (test_bit (0 , indio_dev->active_scan_mask) || -test_bit (1 , indio_dev->active_scan_mask)) - mask |=LTR501_STATUS_ALS_RDY ; -if (test_bit (2 , indio_dev->active_scan_mask)) - mask |=LTR501_STATUS_PS_RDY ; +for_each_set_bit (i, indio_dev->active_scan_mask, indio_dev->num_channels) { +const struct iio_chan_spec *chan = &indio_dev->channels[i]; + +if (chan->type ==IIO_INTENSITY ) + mask |=LTR501_STATUS_ALS_RDY ; + +if (chan->type ==IIO_PROXIMITY ) + mask |=LTR501_STATUS_PS_RDY ; + } ret =ltr501_drdy (data, mask);if (ret <0 )
@@ -1328,11 +1373,13 @@ static int ltr501_init(struct ltr501_data *data) {int ret, status; - ret =regmap_read (data->regmap,LTR501_ALS_CONTR , &status); -if (ret <0 ) -return ret; +if (ltr501_has_als_support (data->chip_info)) { + ret =regmap_read (data->regmap,LTR501_ALS_CONTR , &status); +if (ret <0 ) +return ret; - data->als_contr = status | data->chip_info->als_mode_active; + data->als_contr = status | data->chip_info->als_mode_active; + } ret =regmap_read (data->regmap,LTR501_PS_CONTR , &status);if (ret <0 )
@@ -1569,6 +1616,7 @@ static const struct i2c_device_id ltr501_id[] = { { .name = "ltr329", .driver_data = (kernel_ulong_t)<r329_chip_info_tbl }, { .name = "ltr501", .driver_data = (kernel_ulong_t)<r501_chip_info_tbl }, { .name = "ltr559", .driver_data = (kernel_ulong_t)<r559_chip_info_tbl }, + { .name = "ltr659", .driver_data = (kernel_ulong_t)<r659_chip_info_tbl }, { } };MODULE_DEVICE_TABLE (i2c, ltr501_id);
@@ -1579,6 +1627,7 @@ static const struct of_device_id ltr501_of_match[] = { { .compatible = "liteon,ltr329", .data = <r329_chip_info_tbl }, { .compatible = "liteon,ltr501", .data = <r501_chip_info_tbl }, { .compatible = "liteon,ltr559", .data = <r559_chip_info_tbl }, + { .compatible = "liteon,ltr659", .data = <r659_chip_info_tbl }, { } };MODULE_DEVICE_TABLE (of, ltr501_of_match);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 4/4] iio: light: ltr501: Add support for the LTR-659PS-01 proximity sensor
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] iio: light: ltr501: wrong channel lookup in ltr501_trigger_handler() - [Medium] iio: light: ltr501…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] iio: light: ltr501: wrong channel lookup in ltr501_trigger_handler()
- [Medium] iio: light: ltr501: unguarded ALS register read in ltr501_init()
--
commit ee234def6f10d9aedb1149ec4e47b6d46e491495
Author: Svyatoslav Ryhel <[email protected]>
iio: light: ltr501: Add support for the LTR-659PS-01 proximity sensor
This commit adds support for the Lite-On LTR-659PS-01 proximity sensor, gates ALS register accesses behind a no_als_support flag, and updates ltr501_trigger_handler() to check channel types instead of hardcoded scan indices.
Quoted 4 lines
drivers/iio/light/ltr501.c +0
-0
[ ... ]
Quoted 14 lines
drivers/iio/light/ltr501.c +1
-4@@ -1251,16 +1291,21 @@ static irqreturn_t ltr501_trigger_handler(int irq, void *p)aligned_s64 ts; } scan = { };__le16 als_buf[2 ]; +unsigned int i;u8 mask =0 ;int j =0 ;int ret, psdata;/* figure out which data needs to be ready */ -if (test_bit (0 , indio_dev->active_scan_mask) || -test_bit (1 , indio_dev->active_scan_mask)) - mask |=LTR501_STATUS_ALS_RDY ; -if (test_bit (2 , indio_dev->active_scan_mask))
drivers/iio/light/ltr501.c static irqreturn_t ltr501_trigger_handler(int irq, void *p) · line 1308
Quoted 10 lines
drivers/iio/light/ltr501.c +9
-1- mask |=LTR501_STATUS_PS_RDY ; +for_each_set_bit (i, indio_dev->active_scan_mask, indio_dev->num_channels) { +const struct iio_chan_spec *chan = &indio_dev->channels[i]; + +if (chan->type ==IIO_INTENSITY ) + mask |=LTR501_STATUS_ALS_RDY ; + +if (chan->type ==IIO_PROXIMITY ) + mask |=LTR501_STATUS_PS_RDY ; + }
[Severity: High]
Does indexing indio_dev->channels[] with the bit position from active_scan_mask inspect the wrong channel on existing sensors?
Bit positions in active_scan_mask correspond to chan->scan_index, not the array index in indio_dev->channels[]. In ltr501_channels and ltr301_channels, channels[0] is LTR501_LIGHT_CHANNEL() with scan_index -1, which shifts all buffered channels by one slot: channels[1] and channels[2] are IIO_INTENSITY (scan_index 0 and 1), and in ltr501_channels channels[3] is IIO_PROXIMITY (scan_index 2).
As a regression on LTR-501 and LTR-559, enabling buffered proximity sets bit 2 in active_scan_mask, which inspects channels[2] (IIO_INTENSITY) instead of channels[3] (IIO_PROXIMITY). LTR501_STATUS_PS_RDY is never set in mask, LTR501_PS_DATA is never read, and zeroed proximity values are pushed to the IIO buffer. Similarly, enabling only scan_index 0 on any of the existing ALS sensors inspects channels[0] (IIO_LIGHT), leaving mask at 0 and pushing zeroed ALS data.
Quoted 8 lines
drivers/iio/light/ltr501.c +1
-3@@ -1328,11 +1373,13 @@ static int ltr501_init(struct ltr501_data *data) {int ret, status; - ret =regmap_read (data->regmap,LTR501_ALS_CONTR , &status); -if (ret <0 ) -return ret; +if (ltr501_has_als_support (data->chip_info)) {
drivers/iio/light/ltr501.c static int ltr501_init(struct ltr501_data *data) · line 1385
Quoted 10 lines
drivers/iio/light/ltr501.c +5
-1+ ret =regmap_read (data->regmap,LTR501_ALS_CONTR , &status); +if (ret <0 ) +return ret; - data->als_contr = status | data->chip_info->als_mode_active; + data->als_contr = status | data->chip_info->als_mode_active; + } ret =regmap_read (data->regmap,LTR501_PS_CONTR , &status);if (ret <0 )
[Severity: Medium]
Should the IIO_INTENSITY persistence read later in ltr501_init() also be guarded by ltr501_has_als_support()?
drivers/iio/light/ltr501.c:ltr501_init() {
...
if (ltr501_has_irq_support(data->chip_info)) {
ret = ltr501_read_intr_prst(data, IIO_INTENSITY, &data->als_period);
if (ret < 0)
return ret;
...
}Because ltr659_chip_info_tbl has irq support enabled, probing an LTR-659PS-01 calls ltr501_read_intr_prst() for IIO_INTENSITY, which reads reg_als_prst and calls ltr501_als_read_samp_period() to read the reserved LTR501_ALS_MEAS_RATE register.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Jonathan Cameron
maintainerRe: [PATCH v2 4/4] iio: light: ltr501: Add support for the LTR-659PS-01 proximity sensor
In reply to Svyatoslav RyhelQuoted 31 lines · On Fri, 6 Nov 2026 11:19:43 +0200 Svyatoslav Ryhel <[email protected]> wrote:
Add support for the Lite-On LTR-659PS-01 proximity sensor. This device is nearly identical to the LTR-559ALS-01, but omits all elements related to ambient light sensing.
Add a
no_als_supportflag, similar to howno_irq_supportis used, to isolate ALS register access for the LTR-659PS-01, since ALS registers are marked as reserved and interactions with them are discouraged.The
ltr501_trigger_handlerrelied on the scan index to identify channels. This approach is fragile regarding channel status flags and can break if the index is not strictly set. Switch to checking the channel type instead.Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/iio/light/ltr501.c | 73 +++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 12 deletions(-)drivers/iio/light/ltr501.c +1
-0@@ -151,6 +151,7 @@ struct ltr501_chip_info {u8 als_gain_mask;u8 als_gain_shift;bool no_irq_support; +bool no_als_support;struct iio_chan_spec const *channels;const int no_channels; };
drivers/iio/light/ltr501.c static bool ltr501_has_irq_support(const struct ltr501_chip_info *info) · line 196
Quoted 4 lines
drivers/iio/light/ltr501.c +1
-0@@ -192,6 +193,11 @@ static bool ltr501_has_irq_support(const struct ltr501_chip_info *info)return !info->no_irq_support; } +static bool ltr501_has_als_support (const struct ltr501_chip_info *info)
Is the helper bring enough value? The !info->no_als_support where this is used seems clear enough to me.
Quoted 10 lines
drivers/iio/light/ltr501.c +4
-0+{ +return !info->no_als_support; +} +static int ltr501_match_samp_freq (const struct ltr501_samp_table *tab,int len,int val,int val2) {@@ -656,6 +662,29 @@ static const struct iio_chan_spec ltr301_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(2), };
drivers/iio/light/ltr501.c static const struct iio_chan_spec ltr301_channels[] = { · line 673
Quoted 10 lines
drivers/iio/light/ltr501.c +9
-0+static const struct iio_chan_spec ltr659_channels[] = { + { + .type =IIO_PROXIMITY , + .address =LTR501_PS_DATA , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_separate_available =BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ),
The sampling frequency applies to both channels here. I'd just make that info_mask_shared_by_all
Quoted 13 lines
drivers/iio/light/ltr501.c +13
-0+ .scan_index = 0, + .scan_type = { + .sign = 'u', + .realbits = 11, + .storagebits = 16, + .endianness = IIO_CPU, + }, + .event_spec = ltr501_pxs_event_spec, + .num_event_specs = ARRAY_SIZE(ltr501_pxs_event_spec), + .ext_info = ltr501_ext_info, + }, + IIO_CHAN_SOFT_TIMESTAMP(1), +};
Re: [PATCH v2 4/4] iio: light: ltr501: Add support for the LTR-659PS-01 proximity sensor
сб, 7 лист. 2026 р. о 05:33 Jonathan Cameron <[email protected]> пише:
Quoted 38 lines
Quoted 34 lines · On Fri, 6 Nov 2026 11:19:43 +0200 Svyatoslav Ryhel <[email protected]> wrote:
Add support for the Lite-On LTR-659PS-01 proximity sensor. This device is nearly identical to the LTR-559ALS-01, but omits all elements related to ambient light sensing.
Add a
no_als_supportflag, similar to howno_irq_supportis used, to isolate ALS register access for the LTR-659PS-01, since ALS registers are marked as reserved and interactions with them are discouraged.The
ltr501_trigger_handlerrelied on the scan index to identify channels. This approach is fragile regarding channel status flags and can break if the index is not strictly set. Switch to checking the channel type instead.Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/iio/light/ltr501.c | 73 +++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 12 deletions(-)drivers/iio/light/ltr501.c +1
-0@@ -151,6 +151,7 @@ struct ltr501_chip_info {u8 als_gain_mask;u8 als_gain_shift;bool no_irq_support; +bool no_als_support;struct iio_chan_spec const *channels;const int no_channels; };@@ -192,6 +193,11 @@ static bool ltr501_has_irq_support(const struct ltr501_chip_info *info)return !info->no_irq_support; }
Quoted 5 lines
drivers/iio/light/ltr501.c static bool ltr501_has_irq_support(const struct ltr501_chip_info *info) · line 196
Quoted 1 line
drivers/iio/light/ltr501.c +1
-0+static bool ltr501_has_als_support (const struct ltr501_chip_info *info)Is the helper bring enough value? The !info->no_als_support where this is used seems clear enough to me.
Noted, if you are fine with !info->no_als_support I have no objections.
Quoted 11 lines
Quoted 11 lines
drivers/iio/light/ltr501.c +4
-0+{ +return !info->no_als_support; +} +static int ltr501_match_samp_freq (const struct ltr501_samp_table *tab,int len,int val,int val2) {@@ -656,6 +662,29 @@ static const struct iio_chan_spec ltr301_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(2), };
Quoted 13 lines
drivers/iio/light/ltr501.c static const struct iio_chan_spec ltr301_channels[] = { · line 673
Quoted 9 lines
drivers/iio/light/ltr501.c +9
-0+static const struct iio_chan_spec ltr659_channels[] = { + { + .type =IIO_PROXIMITY , + .address =LTR501_PS_DATA , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_separate_available =BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ),The sampling frequency applies to both channels here. I'd just make that
info_mask_shared_by_all
so IIO_CHAN_INFO_SCALE is separate
and IIO_CHAN_INFO_SAMP_FREQ is shared_by_all
Noted.
Quoted 14 lines
Quoted 13 lines
drivers/iio/light/ltr501.c +13
-0+ .scan_index = 0, + .scan_type = { + .sign = 'u', + .realbits = 11, + .storagebits = 16, + .endianness = IIO_CPU, + }, + .event_spec = ltr501_pxs_event_spec, + .num_event_specs = ARRAY_SIZE(ltr501_pxs_event_spec), + .ext_info = ltr501_ext_info, + }, + IIO_CHAN_SOFT_TIMESTAMP(1), +};
Jonathan Cameron
maintainerRe: [PATCH v2 4/4] iio: light: ltr501: Add support for the LTR-659PS-01 proximity sensor
Quoted 72 lines · On Sat, 7 Nov 2026 12:15:07 +0200 Svyatoslav Ryhel <[email protected]> wrote:
сб, 7 лист. 2026 р. о 05:33 Jonathan Cameron <[email protected]> пише:
Quoted 38 lines
Quoted 34 lines · On Fri, 6 Nov 2026 11:19:43 +0200 Svyatoslav Ryhel <[email protected]> wrote:
Add support for the Lite-On LTR-659PS-01 proximity sensor. This device is nearly identical to the LTR-559ALS-01, but omits all elements related to ambient light sensing.
Add a
no_als_supportflag, similar to howno_irq_supportis used, to isolate ALS register access for the LTR-659PS-01, since ALS registers are marked as reserved and interactions with them are discouraged.The
ltr501_trigger_handlerrelied on the scan index to identify channels. This approach is fragile regarding channel status flags and can break if the index is not strictly set. Switch to checking the channel type instead.Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/iio/light/ltr501.c | 73 +++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 12 deletions(-)drivers/iio/light/ltr501.c +1
-0@@ -151,6 +151,7 @@ struct ltr501_chip_info {u8 als_gain_mask;u8 als_gain_shift;bool no_irq_support; +bool no_als_support;struct iio_chan_spec const *channels;const int no_channels; };@@ -192,6 +193,11 @@ static bool ltr501_has_irq_support(const struct ltr501_chip_info *info)return !info->no_irq_support; }Quoted 5 lines
drivers/iio/light/ltr501.c static bool ltr501_has_irq_support(const struct ltr501_chip_info *info) · line 196
Quoted 1 line
drivers/iio/light/ltr501.c +1
-0+static bool ltr501_has_als_support (const struct ltr501_chip_info *info)Is the helper bring enough value? The !info->no_als_support where this is used seems clear enough to me.
Noted, if you are fine with !info->no_als_support I have no objections.
Quoted 11 lines
Quoted 11 lines
drivers/iio/light/ltr501.c +4
-0+{ +return !info->no_als_support; +} +static int ltr501_match_samp_freq (const struct ltr501_samp_table *tab,int len,int val,int val2) {@@ -656,6 +662,29 @@ static const struct iio_chan_spec ltr301_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(2), };Quoted 13 lines
drivers/iio/light/ltr501.c static const struct iio_chan_spec ltr301_channels[] = { · line 673
Quoted 9 lines
drivers/iio/light/ltr501.c +9
-0+static const struct iio_chan_spec ltr659_channels[] = { + { + .type =IIO_PROXIMITY , + .address =LTR501_PS_DATA , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_separate_available =BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ),The sampling frequency applies to both channels here. I'd just make that
info_mask_shared_by_all
Quoted 5 lines
so
IIO_CHAN_INFO_SCALEis separate
andIIO_CHAN_INFO_SAMP_FREQisshared_by_allNoted.
Roughly speaking look at what is being described and consider what it applies to.
Here the timestamp is grabbed for each single channel read, so sampling_frequency it applies to the timestamp as well as the channel. There are messier corners with sampling for devices with more channels where it would be per channel in the case that they are sampled one by one.
That usually indicates the sampling frequency of a scan is 1/(1/sampA + 1/sampB ...) If the sampling of a scan is independent of channels enabled (because we read them all anyway, parallel read out in the hardware or the sampling is clocked at a rate such that they all get sampled in less time than the inter sample frequency then sampling_frequency may still be shared_by_all.
The scale doesn't apply to the timestamp. Now you only have one channel so you could use shared_by_type, but for this I'd just go with most common pattern for related drivers and separate is also a valid ABI choice.
Userspace should always cope with figuring out whether the broader scoped parameters apply to a specific channel - so separate and shared_by_type are equivalent when there is only one channel of the type.
Jonathan
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/iio/light/ltr501.c +13
-0+ .scan_index = 0, + .scan_type = { + .sign = 'u', + .realbits = 11, + .storagebits = 16, + .endianness = IIO_CPU, + }, + .event_spec = ltr501_pxs_event_spec, + .num_event_specs = ARRAY_SIZE(ltr501_pxs_event_spec), + .ext_info = ltr501_ext_info, + }, + IIO_CHAN_SOFT_TIMESTAMP(1), +};