public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation
@ 2025-03-31  5:50 Zhang Lixu
  2025-03-31  5:50 ` [PATCH 1/3] iio: hid-sensor-prox: Restore lost scale assignments Zhang Lixu
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Zhang Lixu @ 2025-03-31  5:50 UTC (permalink / raw)
  To: linux-iio, jic23, lars, jikos, srinivas.pandruvada, peterz,
	gregkh, ribalda, archana.patni, linux-kernel, linux-input
  Cc: lixu.zhang, even.xu

This patch series addresses issues in the hid-sensor-prox driver related to
SCALE and OFFSET calculations. The changes include restoring lost scale
assignments, supporting multi-channel SCALE calculation, and fixing incorrect
OFFSET calculation.


Zhang Lixu (3):
  iio: hid-sensor-prox: Restore lost scale assignments
  iio: hid-sensor-prox: support multi-channel SCALE calculation
  iio: hid-sensor-prox: Fix incorrect OFFSET calculation

 .../hid-sensors/hid-sensor-attributes.c       |  4 ++++
 drivers/iio/light/hid-sensor-prox.c           | 22 ++++++++++++-------
 2 files changed, 18 insertions(+), 8 deletions(-)


base-commit: e21edb1638e82460f126a6e49bcdd958d452929c
-- 
2.43.0


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

* [PATCH 1/3] iio: hid-sensor-prox: Restore lost scale assignments
  2025-03-31  5:50 [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation Zhang Lixu
@ 2025-03-31  5:50 ` Zhang Lixu
  2025-03-31  5:50 ` [PATCH 2/3] iio: hid-sensor-prox: support multi-channel SCALE calculation Zhang Lixu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Zhang Lixu @ 2025-03-31  5:50 UTC (permalink / raw)
  To: linux-iio, jic23, lars, jikos, srinivas.pandruvada, peterz,
	gregkh, ribalda, archana.patni, linux-kernel, linux-input
  Cc: lixu.zhang, even.xu

The variables `scale_pre_decml`, `scale_post_decml`, and `scale_precision`
were assigned in commit d68c592e02f6 ("iio: hid-sensor-prox: Fix scale not
correct issue"), but due to a merge conflict in
commit 9c15db92a8e5 ("Merge tag 'iio-for-5.13a' of
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next"),
these assignments were lost.

Add back lost assignments and replace `st->prox_attr` with
`st->prox_attr[0]` because commit 596ef5cf654b ("iio: hid-sensor-prox: Add
support for more channels") changed `prox_attr` to an array.

Cc: stable@vger.kernel.org # 5.13+
Fixes: 9c15db92a8e5 ("Merge tag 'iio-for-5.13a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next")
Signed-off-by: Zhang Lixu <lixu.zhang@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/light/hid-sensor-prox.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 76b76d12b388..1dc6fb7cf614 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -257,6 +257,11 @@ static int prox_parse_report(struct platform_device *pdev,
 
 	st->num_channels = index;
 
+	st->scale_precision = hid_sensor_format_scale(hsdev->usage,
+						      &st->prox_attr[0],
+						      &st->scale_pre_decml,
+						      &st->scale_post_decml);
+
 	return 0;
 }
 
-- 
2.43.0


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

* [PATCH 2/3] iio: hid-sensor-prox: support multi-channel SCALE calculation
  2025-03-31  5:50 [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation Zhang Lixu
  2025-03-31  5:50 ` [PATCH 1/3] iio: hid-sensor-prox: Restore lost scale assignments Zhang Lixu
@ 2025-03-31  5:50 ` Zhang Lixu
  2025-03-31  5:50 ` [PATCH 3/3] iio: hid-sensor-prox: Fix incorrect OFFSET calculation Zhang Lixu
  2025-03-31 11:00 ` [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and " Jonathan Cameron
  3 siblings, 0 replies; 7+ messages in thread
From: Zhang Lixu @ 2025-03-31  5:50 UTC (permalink / raw)
  To: linux-iio, jic23, lars, jikos, srinivas.pandruvada, peterz,
	gregkh, ribalda, archana.patni, linux-kernel, linux-input
  Cc: lixu.zhang, even.xu

With the introduction of multi-channel support in commit 596ef5cf654b
("iio: hid-sensor-prox: Add support for more channels"), each channel
requires an independent SCALE calculation, but the existing code only
calculates SCALE for a single channel.

Addresses the problem by modifying the driver to perform independent
SCALE calculations for each channel.

Cc: stable@vger.kernel.org
Fixes: 596ef5cf654b ("iio: hid-sensor-prox: Add support for more channels")
Signed-off-by: Zhang Lixu <lixu.zhang@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 .../hid-sensors/hid-sensor-attributes.c       |  4 ++++
 drivers/iio/light/hid-sensor-prox.c           | 24 ++++++++++---------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index ad1882f608c0..2055a03cbeb1 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -66,6 +66,10 @@ static struct {
 	{HID_USAGE_SENSOR_HUMIDITY, 0, 1000, 0},
 	{HID_USAGE_SENSOR_HINGE, 0, 0, 17453293},
 	{HID_USAGE_SENSOR_HINGE, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
+
+	{HID_USAGE_SENSOR_HUMAN_PRESENCE, 0, 1, 0},
+	{HID_USAGE_SENSOR_HUMAN_PROXIMITY, 0, 1, 0},
+	{HID_USAGE_SENSOR_HUMAN_ATTENTION, 0, 1, 0},
 };
 
 static void simple_div(int dividend, int divisor, int *whole,
diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 1dc6fb7cf614..941508e58286 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -34,9 +34,9 @@ struct prox_state {
 	struct iio_chan_spec channels[MAX_CHANNELS];
 	u32 channel2usage[MAX_CHANNELS];
 	u32 human_presence[MAX_CHANNELS];
-	int scale_pre_decml;
-	int scale_post_decml;
-	int scale_precision;
+	int scale_pre_decml[MAX_CHANNELS];
+	int scale_post_decml[MAX_CHANNELS];
+	int scale_precision[MAX_CHANNELS];
 	unsigned long scan_mask[2]; /* One entry plus one terminator. */
 	int num_channels;
 };
@@ -116,9 +116,12 @@ static int prox_read_raw(struct iio_dev *indio_dev,
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		*val = prox_state->scale_pre_decml;
-		*val2 = prox_state->scale_post_decml;
-		ret_type = prox_state->scale_precision;
+		if (chan->scan_index >= prox_state->num_channels)
+			return -EINVAL;
+
+		*val = prox_state->scale_pre_decml[chan->scan_index];
+		*val2 = prox_state->scale_post_decml[chan->scan_index];
+		ret_type = prox_state->scale_precision[chan->scan_index];
 		break;
 	case IIO_CHAN_INFO_OFFSET:
 		*val = hid_sensor_convert_exponent(
@@ -249,6 +252,10 @@ static int prox_parse_report(struct platform_device *pdev,
 					     st->prox_attr[index].size);
 		dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr[index].index,
 			st->prox_attr[index].report_id);
+		st->scale_precision[index] =
+			hid_sensor_format_scale(usage_id, &st->prox_attr[index],
+						&st->scale_pre_decml[index],
+						&st->scale_post_decml[index]);
 		index++;
 	}
 
@@ -257,11 +264,6 @@ static int prox_parse_report(struct platform_device *pdev,
 
 	st->num_channels = index;
 
-	st->scale_precision = hid_sensor_format_scale(hsdev->usage,
-						      &st->prox_attr[0],
-						      &st->scale_pre_decml,
-						      &st->scale_post_decml);
-
 	return 0;
 }
 
-- 
2.43.0


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

* [PATCH 3/3] iio: hid-sensor-prox: Fix incorrect OFFSET calculation
  2025-03-31  5:50 [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation Zhang Lixu
  2025-03-31  5:50 ` [PATCH 1/3] iio: hid-sensor-prox: Restore lost scale assignments Zhang Lixu
  2025-03-31  5:50 ` [PATCH 2/3] iio: hid-sensor-prox: support multi-channel SCALE calculation Zhang Lixu
@ 2025-03-31  5:50 ` Zhang Lixu
  2025-03-31 11:00 ` [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and " Jonathan Cameron
  3 siblings, 0 replies; 7+ messages in thread
From: Zhang Lixu @ 2025-03-31  5:50 UTC (permalink / raw)
  To: linux-iio, jic23, lars, jikos, srinivas.pandruvada, peterz,
	gregkh, ribalda, archana.patni, linux-kernel, linux-input
  Cc: lixu.zhang, even.xu

The OFFSET calculation in the prox_read_raw() was incorrectly using the
unit exponent, which is intended for SCALE calculations.

Remove the incorrect OFFSET calculation and set it to a fixed value of 0.

Cc: stable@vger.kernel.org
Fixes: 39a3a0138f61 ("iio: hid-sensors: Added Proximity Sensor Driver")
Signed-off-by: Zhang Lixu <lixu.zhang@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/light/hid-sensor-prox.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 941508e58286..4c65b32d34ce 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -124,8 +124,7 @@ static int prox_read_raw(struct iio_dev *indio_dev,
 		ret_type = prox_state->scale_precision[chan->scan_index];
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = hid_sensor_convert_exponent(
-			prox_state->prox_attr[chan->scan_index].unit_expo);
+		*val = 0;
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
-- 
2.43.0


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

* Re: [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation
  2025-03-31  5:50 [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation Zhang Lixu
                   ` (2 preceding siblings ...)
  2025-03-31  5:50 ` [PATCH 3/3] iio: hid-sensor-prox: Fix incorrect OFFSET calculation Zhang Lixu
@ 2025-03-31 11:00 ` Jonathan Cameron
  2025-03-31 14:20   ` srinivas pandruvada
  3 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2025-03-31 11:00 UTC (permalink / raw)
  To: Zhang Lixu
  Cc: linux-iio, lars, jikos, srinivas.pandruvada, peterz, gregkh,
	ribalda, archana.patni, linux-kernel, linux-input, even.xu

On Mon, 31 Mar 2025 13:50:19 +0800
Zhang Lixu <lixu.zhang@intel.com> wrote:

> This patch series addresses issues in the hid-sensor-prox driver related to
> SCALE and OFFSET calculations. The changes include restoring lost scale
> assignments, supporting multi-channel SCALE calculation, and fixing incorrect
> OFFSET calculation.
> 
Hi.

Generally I prefer to see review tags (Srinivas' Acks here) given on list
but in I trust Srinivas to have done a thorough review (or to shout when he
sees this!) and the changes look correct to me, applied to the fixes-togreg-testing
branch of iio.git.

Odd point in merge cycle hence the odd temporary branch.

Jonathan

> 
> Zhang Lixu (3):
>   iio: hid-sensor-prox: Restore lost scale assignments
>   iio: hid-sensor-prox: support multi-channel SCALE calculation
>   iio: hid-sensor-prox: Fix incorrect OFFSET calculation
> 
>  .../hid-sensors/hid-sensor-attributes.c       |  4 ++++
>  drivers/iio/light/hid-sensor-prox.c           | 22 ++++++++++++-------
>  2 files changed, 18 insertions(+), 8 deletions(-)
> 
> 
> base-commit: e21edb1638e82460f126a6e49bcdd958d452929c


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

* Re: [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation
  2025-03-31 11:00 ` [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and " Jonathan Cameron
@ 2025-03-31 14:20   ` srinivas pandruvada
  2025-04-01  2:12     ` Zhang, Lixu
  0 siblings, 1 reply; 7+ messages in thread
From: srinivas pandruvada @ 2025-03-31 14:20 UTC (permalink / raw)
  To: Jonathan Cameron, Zhang Lixu
  Cc: linux-iio, lars, jikos, peterz, gregkh, ribalda, archana.patni,
	linux-kernel, linux-input, even.xu

On Mon, 2025-03-31 at 12:00 +0100, Jonathan Cameron wrote:
> On Mon, 31 Mar 2025 13:50:19 +0800
> Zhang Lixu <lixu.zhang@intel.com> wrote:
> 
> > This patch series addresses issues in the hid-sensor-prox driver
> > related to
> > SCALE and OFFSET calculations. The changes include restoring lost
> > scale
> > assignments, supporting multi-channel SCALE calculation, and fixing
> > incorrect
> > OFFSET calculation.
> > 
> Hi.
> 
> Generally I prefer to see review tags (Srinivas' Acks here) given on
> list
> but in I trust Srinivas to have done a thorough review (or to shout
> when he
> sees this!) and the changes look correct to me, applied to the fixes-
> togreg-testing
> branch of iio.git.
Hi Jonathan,

I have reviewed these patches internally. From next time, I will make
sure that I ACK on the public lists.

Thanks,
Srinivas

> 
> Odd point in merge cycle hence the odd temporary branch.
> 
> Jonathan
> 
> > 
> > Zhang Lixu (3):
> >   iio: hid-sensor-prox: Restore lost scale assignments
> >   iio: hid-sensor-prox: support multi-channel SCALE calculation
> >   iio: hid-sensor-prox: Fix incorrect OFFSET calculation
> > 
> >  .../hid-sensors/hid-sensor-attributes.c       |  4 ++++
> >  drivers/iio/light/hid-sensor-prox.c           | 22 ++++++++++++---
> > ----
> >  2 files changed, 18 insertions(+), 8 deletions(-)
> > 
> > 
> > base-commit: e21edb1638e82460f126a6e49bcdd958d452929c
> 


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

* RE: [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation
  2025-03-31 14:20   ` srinivas pandruvada
@ 2025-04-01  2:12     ` Zhang, Lixu
  0 siblings, 0 replies; 7+ messages in thread
From: Zhang, Lixu @ 2025-04-01  2:12 UTC (permalink / raw)
  To: srinivas pandruvada, Jonathan Cameron
  Cc: linux-iio@vger.kernel.org, lars@metafoo.de, jikos@kernel.org,
	peterz@infradead.org, gregkh@linuxfoundation.org,
	ribalda@chromium.org, archana.patni@linux.intel.com,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	Xu, Even

Hi Jonathan and Srinivas,

Noted. Thank you for merging the patches and reviewing the changes.

Thanks,
Lixu

>-----Original Message-----
>From: srinivas pandruvada <srinivas.pandruvada@linux.intel.com>
>Sent: Monday, March 31, 2025 10:20 PM
>To: Jonathan Cameron <jic23@kernel.org>; Zhang, Lixu <lixu.zhang@intel.com>
>Cc: linux-iio@vger.kernel.org; lars@metafoo.de; jikos@kernel.org;
>peterz@infradead.org; gregkh@linuxfoundation.org; ribalda@chromium.org;
>archana.patni@linux.intel.com; linux-kernel@vger.kernel.org; linux-
>input@vger.kernel.org; Xu, Even <even.xu@intel.com>
>Subject: Re: [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation
>
>On Mon, 2025-03-31 at 12:00 +0100, Jonathan Cameron wrote:
>> On Mon, 31 Mar 2025 13:50:19 +0800
>> Zhang Lixu <lixu.zhang@intel.com> wrote:
>>
>> > This patch series addresses issues in the hid-sensor-prox driver
>> > related to SCALE and OFFSET calculations. The changes include
>> > restoring lost scale assignments, supporting multi-channel SCALE
>> > calculation, and fixing incorrect OFFSET calculation.
>> >
>> Hi.
>>
>> Generally I prefer to see review tags (Srinivas' Acks here) given on
>> list but in I trust Srinivas to have done a thorough review (or to
>> shout when he sees this!) and the changes look correct to me, applied
>> to the fixes- togreg-testing branch of iio.git.
>Hi Jonathan,
>
>I have reviewed these patches internally. From next time, I will make sure that I
>ACK on the public lists.
>
>Thanks,
>Srinivas
>
>>
>> Odd point in merge cycle hence the odd temporary branch.
>>
>> Jonathan
>>
>> >
>> > Zhang Lixu (3):
>> >   iio: hid-sensor-prox: Restore lost scale assignments
>> >   iio: hid-sensor-prox: support multi-channel SCALE calculation
>> >   iio: hid-sensor-prox: Fix incorrect OFFSET calculation
>> >
>> >  .../hid-sensors/hid-sensor-attributes.c       |  4 ++++
>> >  drivers/iio/light/hid-sensor-prox.c           | 22 ++++++++++++---
>> > ----
>> >  2 files changed, 18 insertions(+), 8 deletions(-)
>> >
>> >
>> > base-commit: e21edb1638e82460f126a6e49bcdd958d452929c
>>


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

end of thread, other threads:[~2025-04-01  2:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31  5:50 [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and OFFSET calculation Zhang Lixu
2025-03-31  5:50 ` [PATCH 1/3] iio: hid-sensor-prox: Restore lost scale assignments Zhang Lixu
2025-03-31  5:50 ` [PATCH 2/3] iio: hid-sensor-prox: support multi-channel SCALE calculation Zhang Lixu
2025-03-31  5:50 ` [PATCH 3/3] iio: hid-sensor-prox: Fix incorrect OFFSET calculation Zhang Lixu
2025-03-31 11:00 ` [PATCH 0/3] iio: hid-sensor-prox: fix SCALE and " Jonathan Cameron
2025-03-31 14:20   ` srinivas pandruvada
2025-04-01  2:12     ` Zhang, Lixu

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