[PATCH] iio: hid-sensor: als: scale each channel individually
Daniel Schaefer via B4 Relay <[email protected]>
| Newsgroups | org.kernel.vger.linux-iio,org.kernel.feeds.b4-sent,org.kernel.vger.linux-input,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
From: Daniel Schaefer <[email protected]> Some sensors have multiple channels (not just brightness but color ALS sensors) with different scaling factors. Tested on Asus ProArt PX13 laptop by Sven. Signed-off-by: Daniel Schaefer <[email protected]> Link: https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/merge_requests/413 Cc: Sven Vainküla <[email protected]> Cc: Jiri Kosina <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Srinivas Pandruvada <[email protected]> Cc: David Lechner <[email protected]> Cc: Nuno Sá <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] --- drivers/iio/light/hid-sensor-als.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 384572844162..232cb58e0a9f 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -33,9 +33,9 @@ struct als_state { u32 illum[CHANNEL_SCAN_INDEX_MAX]; aligned_s64 timestamp; } scan; - int scale_pre_decml; - int scale_post_decml; - int scale_precision; + int scale_pre_decml[CHANNEL_SCAN_INDEX_MAX]; + int scale_post_decml[CHANNEL_SCAN_INDEX_MAX]; + int scale_precision[CHANNEL_SCAN_INDEX_MAX]; int value_offset; int num_channels; s64 timestamp; @@ -186,9 +186,11 @@ static int als_read_raw(struct iio_dev *indio_dev, ret_type = IIO_VAL_INT; break; case IIO_CHAN_INFO_SCALE: - *val = als_state->scale_pre_decml; - *val2 = als_state->scale_post_decml; - ret_type = als_state->scale_precision; + if (chan->scan_index >= CHANNEL_SCAN_INDEX_MAX) + return -EINVAL; + *val = als_state->scale_pre_decml[chan->scan_index]; + *val2 = als_state->scale_post_decml[chan->scan_index]; + ret_type = als_state->scale_precision[chan->scan_index]; break; case IIO_CHAN_INFO_OFFSET: *val = als_state->value_offset; @@ -338,6 +340,10 @@ static int als_parse_report(struct platform_device *pdev, als_adjust_channel_bit_mask(channels, index, st->als[i].size); ++index; + st->scale_precision[i] = hid_sensor_format_scale(usage_id, + &st->als[i], &st->scale_pre_decml[i], + &st->scale_post_decml[i]); + dev_dbg(&pdev->dev, "als %x:%x\n", st->als[i].index, st->als[i].report_id); } @@ -347,10 +353,6 @@ static int als_parse_report(struct platform_device *pdev, if (index) ret = 0; - st->scale_precision = hid_sensor_format_scale(usage_id, - &st->als[CHANNEL_SCAN_INDEX_INTENSITY], - &st->scale_pre_decml, &st->scale_post_decml); - return ret; } --- base-commit: 194a48576843858afcd9c00ed4f105ec2b398e6c change-id: 20260723-chromaticity-88fec417f00c Best regards, -- Daniel Schaefer <[email protected]>