Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: hid-sensor: als: scale each channel individually
@ 2026-07-22 17:18 Daniel Schaefer via B4 Relay
  2026-07-25 23:18 ` Jonathan Cameron
  2026-07-27 15:18 ` srinivas pandruvada
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Schaefer via B4 Relay @ 2026-07-22 17:18 UTC (permalink / raw)
  To: Jiri Kosina, Jonathan Cameron, Srinivas Pandruvada, David Lechner,
	Nuno Sá, Andy Shevchenko
  Cc: linux-input, linux-iio, linux-kernel, Daniel Schaefer,
	Sven Vainküla, linux

From: Daniel Schaefer <dhs@frame.work>

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 <dhs@frame.work>
Link: https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/merge_requests/413
Cc: Sven Vainküla <sven@xn--vainkla-r2a.ee>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Nuno Sá <nuno.sa@analog.com>
Cc: Andy Shevchenko <andy@kernel.org>
Cc: linux-input@vger.kernel.org
Cc: linux-iio@vger.kernel.org
Cc: linux@frame.work
---
 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 <dhs@frame.work>



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: hid-sensor: als: scale each channel individually
  2026-07-22 17:18 [PATCH] iio: hid-sensor: als: scale each channel individually Daniel Schaefer via B4 Relay
@ 2026-07-25 23:18 ` Jonathan Cameron
  2026-07-27 15:18 ` srinivas pandruvada
  1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2026-07-25 23:18 UTC (permalink / raw)
  To: Daniel Schaefer via B4 Relay
  Cc: dhs, Jiri Kosina, Srinivas Pandruvada, David Lechner,
	Nuno Sá, Andy Shevchenko, linux-input, linux-iio,
	linux-kernel, Sven Vainküla, linux

On Thu, 23 Jul 2026 01:18:58 +0800
Daniel Schaefer via B4 Relay <devnull+dhs.frame.work@kernel.org> wrote:

> From: Daniel Schaefer <dhs@frame.work>
> 
> Some sensors have multiple channels (not just brightness but color ALS
> sensors) with different scaling factors.
> 
> Tested on Asus ProArt PX13 laptop by Sven.

The channels in this driver report IIO_CHAN_INFO_SCALE as shared by type.
That doesn't matter unless we get different scales on the two parts
of chromaticity and I'm assuming that isn't eh issue Sven has run into?

Assuming it is illuminance vs color temp (or both chromaticity channels together)
then the change here looks fine to me.

I'll queue it up on the testing branch of iio.git but more eyes welcome if
anyone has time to take a look.

A few little tweaks to the commit message.  There was a bit of fuzz as well
whilst applying but all seemed like line changes due to other updates.

Thanks

Jonathan

> 
> Signed-off-by: Daniel Schaefer <dhs@frame.work>
> Link: https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/merge_requests/413
> Cc: Sven Vainküla <sven@xn--vainkla-r2a.ee>
Given you say Sven tested it, I've upgraded this to a Tested-by
and included a comment after that to say what it was tested on.

> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Cc: David Lechner <dlechner@baylibre.com>
> Cc: Nuno Sá <nuno.sa@analog.com>
> Cc: Andy Shevchenko <andy@kernel.org>
> Cc: linux-input@vger.kernel.org
> Cc: linux-iio@vger.kernel.org
> Cc: linux@frame.work
We don't really want to end up with all this list in the git log, so good
practice is to put a --- above them, so they end up in the region that is
cut out.

> ---
>  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,


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: hid-sensor: als: scale each channel individually
  2026-07-22 17:18 [PATCH] iio: hid-sensor: als: scale each channel individually Daniel Schaefer via B4 Relay
  2026-07-25 23:18 ` Jonathan Cameron
@ 2026-07-27 15:18 ` srinivas pandruvada
  2026-07-27 21:13   ` Jonathan Cameron
  1 sibling, 1 reply; 7+ messages in thread
From: srinivas pandruvada @ 2026-07-27 15:18 UTC (permalink / raw)
  To: dhs, Jiri Kosina, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko
  Cc: linux-input, linux-iio, linux-kernel, Sven Vainküla, linux

On Thu, 2026-07-23 at 01:18 +0800, Daniel Schaefer via B4 Relay wrote:
> From: Daniel Schaefer <dhs@frame.work>
> 
> 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 <dhs@frame.work>
> Link:
> https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/merge_requests/413
> Cc: Sven Vainküla <sven@xn--vainkla-r2a.ee>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Cc: David Lechner <dlechner@baylibre.com>
> Cc: Nuno Sá <nuno.sa@analog.com>
> Cc: Andy Shevchenko <andy@kernel.org>
> Cc: linux-input@vger.kernel.org
> Cc: linux-iio@vger.kernel.org
> Cc: linux@frame.work

Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

> ---
>  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,

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: hid-sensor: als: scale each channel individually
  2026-07-27 15:18 ` srinivas pandruvada
@ 2026-07-27 21:13   ` Jonathan Cameron
  2026-07-28  0:38     ` Daniel Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2026-07-27 21:13 UTC (permalink / raw)
  To: srinivas pandruvada
  Cc: dhs, Jiri Kosina, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-input, linux-iio, linux-kernel, Sven Vainküla, linux

On Mon, 27 Jul 2026 08:18:47 -0700
srinivas pandruvada <srinivas.pandruvada@linux.intel.com> wrote:

> On Thu, 2026-07-23 at 01:18 +0800, Daniel Schaefer via B4 Relay wrote:
> > From: Daniel Schaefer <dhs@frame.work>
> > 
> > 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 <dhs@frame.work>
> > Link:
> > https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/merge_requests/413
> > Cc: Sven Vainküla <sven@xn--vainkla-r2a.ee>
> > Cc: Jiri Kosina <jikos@kernel.org>
> > Cc: Jonathan Cameron <jic23@kernel.org>
> > Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> > Cc: David Lechner <dlechner@baylibre.com>
> > Cc: Nuno Sá <nuno.sa@analog.com>
> > Cc: Andy Shevchenko <andy@kernel.org>
> > Cc: linux-input@vger.kernel.org
> > Cc: linux-iio@vger.kernel.org
> > Cc: linux@frame.work  
> 
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Added.  Thanks Srinivas!
J
> 
> > ---
> >  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,  
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: hid-sensor: als: scale each channel individually
  2026-07-27 21:13   ` Jonathan Cameron
@ 2026-07-28  0:38     ` Daniel Schaefer
  2026-08-05  1:23       ` Daniel Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Schaefer @ 2026-07-28  0:38 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: srinivas pandruvada, Jiri Kosina, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-input, linux-iio, linux-kernel,
	Sven Vainküla, linux

> The channels in this driver report IIO_CHAN_INFO_SCALE as shared by type.
> That doesn't matter unless we get different scales on the two parts
> of chromaticity and I'm assuming that isn't eh issue Sven has run into?

Yes, in practice it's probably not needed and the patch works as is.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: hid-sensor: als: scale each channel individually
  2026-07-28  0:38     ` Daniel Schaefer
@ 2026-08-05  1:23       ` Daniel Schaefer
  2026-08-05 12:53         ` David Lechner
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Schaefer @ 2026-08-05  1:23 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: srinivas pandruvada, Jiri Kosina, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-input, linux-iio, linux-kernel,
	Sven Vainküla, linux

>  I'll queue it up on the testing branch of iio.git but more eyes welcome if
anyone has time to take a look.

Sorry I'm not sure what that means. Is the patch applied or
should I send another one with commit message update?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: hid-sensor: als: scale each channel individually
  2026-08-05  1:23       ` Daniel Schaefer
@ 2026-08-05 12:53         ` David Lechner
  0 siblings, 0 replies; 7+ messages in thread
From: David Lechner @ 2026-08-05 12:53 UTC (permalink / raw)
  To: Daniel Schaefer, Jonathan Cameron
  Cc: srinivas pandruvada, Jiri Kosina, Nuno Sá, Andy Shevchenko,
	linux-input, linux-iio, linux-kernel, Sven Vainküla, linux

On 8/4/26 8:23 PM, Daniel Schaefer wrote:
>>  I'll queue it up on the testing branch of iio.git but more eyes welcome if
> anyone has time to take a look.
> 
> Sorry I'm not sure what that means. Is the patch applied or
> should I send another one with commit message update?

It means that it is accepted/applied.

The iio/testing branch is the first step where various CI bots
will do some automatic checks. If they find something, you will
be notified. Otherwise nothing more for you to do (unless a serious
concern is raised later).

And it means there is still time for further review too in case
anyone wants to add their e.g. reviewed-by tag.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-08-05 12:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 17:18 [PATCH] iio: hid-sensor: als: scale each channel individually Daniel Schaefer via B4 Relay
2026-07-25 23:18 ` Jonathan Cameron
2026-07-27 15:18 ` srinivas pandruvada
2026-07-27 21:13   ` Jonathan Cameron
2026-07-28  0:38     ` Daniel Schaefer
2026-08-05  1:23       ` Daniel Schaefer
2026-08-05 12:53         ` David Lechner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox