Skip to contentSkip to conversation

IIO: hid-sensor-prox: add missing scale attribute

PATCH In review Philipp Jungkamp 3 participants 11 messages Aug 6, 2023 – Oct 28, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IIO: hid-sensor-prox: add missing scale attribute

The hid-sensor-prox returned an empty string on sysfs in_proximity_scale read. This is due to the the driver's scale never being initialized.

Try to query the scale of the HID sensor using hid_sensor_format_scale.

---
Hello,

up until now I've used the sensor directly through the buffered IIO interface, ignoring the in_proximity_scale attribute. But while integrating it with iio-sensor-proxy I noticed that a read on scale return an empty string, breaking the code there.

Looking at the code in hid-sensor-prox.c it is fairly obvious that the scale just wasn't being initialized. I now added the hid_sensor_format_scale call similar to the ones found in e.g. hid-sensor-als.c.

Regards,
Philipp Jungkamp

 drivers/iio/light/hid-sensor-prox.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iio/light/hid-sensor-prox.c +3 -0
index a47591e1bad9..aaf2ce6ed52c 100644
@@ -227,6 +227,9 @@ static int prox_parse_report(struct platform_device *pdev,
 	dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr.index,
 			st->prox_attr.report_id);
 
+	st->scale_precision = hid_sensor_format_scale(usage_id, &st->prox_attr,
+				&st->scale_pre_decml, &st->scale_post_decml);
+
 	return ret;
 }
 

--
2.41.0

#1 lore raw
Quoted 3 lines · Philipp Jungkamp

The hid-sensor-prox returned an empty string on sysfs in_proximity_scale
read. This is due to the the driver's scale never being initialized.

What is scale value reporting here? Is it 1.

Thanks,
Srinivas

Quoted 49 lines

Try to query the scale of the HID sensor using
hid_sensor_format_scale.

---
Hello,

up until now I've used the sensor directly through the buffered IIO interface,
ignoring the in_proximity_scale attribute. But while integrating it with
iio-sensor-proxy I noticed that a read on scale return an empty string,
breaking the code there.

Looking at the code in hid-sensor-prox.c it is fairly obvious that the scale
just wasn't being initialized. I now added the hid_sensor_format_scale call
similar to the ones found in e.g. hid-sensor-als.c.

Regards,
Philipp Jungkamp

 drivers/iio/light/hid-sensor-prox.c | 3 +++

 1 file changed, 3 insertions(+)
drivers/iio/light/hid-sensor-prox.c +3 -0
index a47591e1bad9..aaf2ce6ed52c 100644
@@ -227,6 +227,9 @@ static int prox_parse_report(struct
 platform_device *pdev,
         dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr.index,
                         st->prox_attr.report_id);
 
+       st->scale_precision = hid_sensor_format_scale(usage_id, &st-
 >prox_attr,
+                               &st->scale_pre_decml, &st-
 >scale_post_decml);
+

        return ret;
 }

--
2.41.0

#2 lore raw
Quoted 8 lines
Quoted 3 lines

The hid-sensor-prox returned an empty string on sysfs in_proximity_scale
read. This is due to the the driver's scale never being initialized.

What is scale value reporting here? Is it 1.

Thanks,
Srinivas

Calling read on the sysfs file in_proximity_scale returns 0, thus an empty string. Adding the hid_format_scale call makes that a '1.000000'.

Regards,
Philipp

maintainer
#3 lore raw
Quoted 6 lines · On Tue, 8 Aug 2023 14:22:10 +0200 Philipp Jungkamp <[email protected]> wrote:
Quoted 6 lines
Quoted 3 lines

The hid-sensor-prox returned an empty string on sysfs in_proximity_scale
read. This is due to the the driver's scale never being initialized.

What is scale value reporting here? Is it 1.

Quoted 8 lines
Quoted 2 lines

Thanks,
Srinivas

Calling read on the sysfs file in_proximity_scale returns 0, thus an empty string. Adding the hid_format_scale call makes that a '1.000000'.

Regards,
Philipp

Srinivas - I was kind of waiting for a reply to say if you are happy with the explanation. All good?

Phillipp - this sounds like a fix to me. Fixes tag?

Thanks,

Jonathan

maintainer Acked-by
#4 lore raw
Quoted 17 lines · Jonathan Cameron
Quoted 14 lines · On Tue, 8 Aug 2023 14:22:10 +0200 Philipp Jungkamp <[email protected]> wrote:
Quoted 9 lines
Quoted 4 lines

The hid-sensor-prox returned an empty string on sysfs in_proximity_scale
read. This is due to the the driver's scale never being initialized.

What is scale value reporting here? Is it 1.

Thanks,
Srinivas

Calling read on the sysfs file in_proximity_scale returns 0, thus an empty string.
Adding the hid_format_scale call makes that a '1.000000'.

Quoted 6 lines
Quoted 2 lines

Regards,
Philipp

Srinivas - I was kind of waiting for a reply to say if you are happy with the explanation.
All good?

All good.

Quoted 6 lines

Phillipp - this sounds like a fix to me.  Fixes tag?

Thanks,

Jonathan

maintainer
#5 lore raw
Quoted 21 lines · On Sat, 14 Oct 2023 19:56:26 -0700 srinivas pandruvada…
Quoted 20 lines · Jonathan Cameron
Quoted 16 lines · On Tue, 8 Aug 2023 14:22:10 +0200 Philipp Jungkamp <[email protected]> wrote:
Quoted 9 lines
Quoted 4 lines

The hid-sensor-prox returned an empty string on sysfs in_proximity_scale
read. This is due to the the driver's scale never being initialized.

What is scale value reporting here? Is it 1.

Thanks,
Srinivas

Calling read on the sysfs file in_proximity_scale returns 0, thus an empty string.
Adding the hid_format_scale call makes that a '1.000000'.

Regards,
Philipp

Quoted 7 lines
Quoted 3 lines

Srinivas - I was kind of waiting for a reply to say if you are happy with the explanation.
All good?

All good.

Given we are late in the cycle and my next fixes pull will probably end up going in during the merge window anyway, I've applied this to the togreg branch of iio.git (so the slow path).

Phillipp, if a backport makes sense you can request that after this goes upstream.

Thanks,

Jonathan

Quoted 7 lines
Quoted 6 lines

Phillipp - this sounds like a fix to me.  Fixes tag?

Thanks,

Jonathan

maintainer
#6 lore raw
Quoted 29 lines · On Sun, 15 Oct 2023 12:04:48 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 26 lines · On Sat, 14 Oct 2023 19:56:26 -0700 srinivas pandruvada…
Quoted 17 lines · Jonathan Cameron
Quoted 14 lines · On Tue, 8 Aug 2023 14:22:10 +0200 Philipp Jungkamp <[email protected]> wrote:
Quoted 9 lines
Quoted 4 lines

The hid-sensor-prox returned an empty string on sysfs in_proximity_scale
read. This is due to the the driver's scale never being initialized.

What is scale value reporting here? Is it 1.

Thanks,
Srinivas

Calling read on the sysfs file in_proximity_scale returns 0, thus an empty string.
Adding the hid_format_scale call makes that a '1.000000'.

Quoted 6 lines
Quoted 2 lines

Regards,
Philipp

Srinivas - I was kind of waiting for a reply to say if you are happy with the explanation.
All good?

All good.

Quoted 8 lines
Quoted 2 lines

Given we are late in the cycle and my next fixes pull will probably end up going in during the merge window anyway, I've applied this to the togreg branch of iio.git (so the slow path).

Phillipp, if a backport makes sense you can request that after this goes upstream.

Whilst typing up a pull request I saw this again and thought a bit more on it.

This fix is probably wrong approach. Proximity sensors are often scale free because they depend on reflectance off something or a capacitance changing etc so we don't know the scaling. So the right response then is not to return a scale value of 1.0 but to not provide the attribute at all. Is that something that could be easily done here?

For now I'm dropping the patch. Sorry I wasn't paying enough attention to notice this was a proximity sensor.

Jonathan

Quoted 13 lines

Thanks,

Jonathan

Quoted 7 lines
Quoted 6 lines

Phillipp - this sounds like a fix to me.  Fixes tag?

Thanks,

Jonathan

#7 lore raw
Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Sun, 15 Oct 2023 12:04:48 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 2 lines · On Sat, 14 Oct 2023 19:56:26 -0700 srinivas pandruvada…

On Sat, 2023-10-14 at 17:52 +0100, Jonathan Cameron wrote:

[...]

Quoted 5 lines
Quoted 2 lines

Phillipp, if a backport makes sense you can request that after this goes upstream.

Whilst typing up a pull request I saw this again and thought a bit more on it.

Quoted 9 lines

This fix is probably wrong approach.  Proximity sensors are often scale free
because they depend on reflectance off something or a capacitance changing etc
so we don't know the scaling.  So the right response then is not to return a scale
value of 1.0 but to not provide the attribute at all.  Is that something that
could be easily done here?

I think so. But hope that iio-sensor-proxy can handle absence of scale attribute.

git diff drivers/iio/light/hid-sensor-prox.c

(quoted diff) +0 -0

b/drivers/iio/light/hid-sensor-prox.c
index a47591e1bad9..e4b81fa948f5 100644

drivers/iio/light/hid-sensor-prox.c +0 -1
@@ -36,7 +36,6 @@ static const struct iio_chan_spec prox_channels[] = {
                .type = IIO_PROXIMITY,
                .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
-               BIT(IIO_CHAN_INFO_SCALE) |
                BIT(IIO_CHAN_INFO_SAMP_FREQ) |
                BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_PRESENCE,

Thanks,
Srinivas

Quoted 21 lines

For now I'm dropping the patch. Sorry I wasn't paying enough attention to notice
this was a proximity sensor.

Jonathan

Quoted 13 lines

Thanks,

Jonathan

Quoted 7 lines
Quoted 6 lines

Phillipp - this sounds like a fix to me.  Fixes tag?

Thanks,

Jonathan

maintainer
#8 lore raw
Quoted 46 lines · On Mon, 16 Oct 2023 07:28:36 -0700 srinivas pandruvada…
Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Sun, 15 Oct 2023 12:04:48 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 2 lines · On Sat, 14 Oct 2023 19:56:26 -0700 srinivas pandruvada…

On Sat, 2023-10-14 at 17:52 +0100, Jonathan Cameron wrote:

[...]

Quoted 5 lines
Quoted 2 lines

Phillipp, if a backport makes sense you can request that after this goes upstream.

Whilst typing up a pull request I saw this again and thought a bit more on it.

Quoted 9 lines

This fix is probably wrong approach.  Proximity sensors are often scale free
because they depend on reflectance off something or a capacitance changing etc
so we don't know the scaling.  So the right response then is not to return a scale
value of 1.0 but to not provide the attribute at all.  Is that something that
could be easily done here?

I think so. But hope that iio-sensor-proxy can handle absence of scale attribute.

git diff drivers/iio/light/hid-sensor-prox.c

drivers/iio/light/hid-sensor-prox.c +0 -1
index a47591e1bad9..e4b81fa948f5 100644
@@ -36,7 +36,6 @@ static const struct iio_chan_spec prox_channels[] = {
                .type = IIO_PROXIMITY,
                .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
-               BIT(IIO_CHAN_INFO_SCALE) |
                BIT(IIO_CHAN_INFO_SAMP_FREQ) |
                BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_PRESENCE,
Quoted 2 lines

Thanks,
Srinivas

Just to check. Are we guaranteed that there is never a scale parameter? Some proximity sensors do have absolute units (time of flight sensors for example).

Jonathan

Quoted 23 lines
Quoted 22 lines

For now I'm dropping the patch. Sorry I wasn't paying enough attention to notice
this was a proximity sensor.

Jonathan

Quoted 13 lines

Thanks,

Jonathan

Quoted 7 lines
Quoted 6 lines

Phillipp - this sounds like a fix to me.  Fixes tag?

Thanks,

Jonathan

#9 lore raw
Quoted 56 lines · Jonathan Cameron
Quoted 53 lines · On Mon, 16 Oct 2023 07:28:36 -0700 srinivas pandruvada…
Quoted 10 lines · Jonathan Cameron

On Sun, 15 Oct 2023 12:04:48 +0100
Jonathan Cameron <[email protected]> wrote:

Quoted 7 lines

On Sat, 14 Oct 2023 19:56:26 -0700
srinivas pandruvada <[email protected]> wrote:

Quoted 2 lines · Jonathan Cameron

[...]

Quoted 7 lines
Quoted 3 lines

Phillipp, if a backport makes sense you can request that after this
goes upstream.

Whilst typing up a pull request I saw this again and thought a bit
more on it.

Quoted 10 lines

This fix is probably wrong approach.  Proximity sensors are often scale free
because they depend on reflectance off something or a capacitance changing etc
so we don't know the scaling.  So the right response then is not to
return a scale
value of 1.0 but to not provide the attribute at all.  Is that something that
could be easily done here?

I think so. But hope that iio-sensor-proxy can handle absence of scale
attribute.

git diff drivers/iio/light/hid-sensor-prox.c

drivers/iio/light/hid-sensor-prox.c +0 -0
index a47591e1bad9..e4b81fa948f5 100644
@@ -36,7 +36,6 @@ static const struct iio_chan_spec prox_channels[]
 = {
                 .type = IIO_PROXIMITY,
                 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),

                .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
-               BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_HYSTERESIS), .scan_index = CHANNEL_SCAN_INDEX_PRESENCE,

Quoted 8 lines
Quoted 2 lines

Thanks,
Srinivas

Just to check. Are we guaranteed that there is never a scale parameter?
Some proximity sensors do have absolute units (time of flight sensors for example).

This driver is implementing:
Biometric: Human Presence (Usage ID 0x11) from HID sensor hub specification.

"Biometric: Human
PresenceCA,CP – An application-level or physical collection that identifies
a device that detects human presence (Boolean yes or no)."

It is not implementing Biometric: Human Proximity (Usage ID 0x12). This has range of values, then unit will be applicable.

Thanks,
Srinivas

Quoted 26 lines

Jonathan

Quoted 23 lines
Quoted 22 lines

For now I'm dropping the patch. Sorry I wasn't paying enough attention to notice
this was a proximity sensor.

Jonathan

Quoted 6 lines

Thanks,

Jonathan

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

Phillipp - this sounds like a fix to me.  Fixes tag?

Thanks,

Jonathan

maintainer
#10 lore raw
Quoted 69 lines · On Tue, 17 Oct 2023 18:56:38 -0700 srinivas pandruvada…
Quoted 56 lines · Jonathan Cameron
Quoted 53 lines · On Mon, 16 Oct 2023 07:28:36 -0700 srinivas pandruvada…
Quoted 10 lines · Jonathan Cameron

On Sun, 15 Oct 2023 12:04:48 +0100
Jonathan Cameron <[email protected]> wrote:

Quoted 7 lines

On Sat, 14 Oct 2023 19:56:26 -0700
srinivas pandruvada <[email protected]> wrote:

Quoted 2 lines · Jonathan Cameron

[...]

Quoted 7 lines
Quoted 3 lines

Phillipp, if a backport makes sense you can request that after this
goes upstream.

Whilst typing up a pull request I saw this again and thought a bit
more on it.

Quoted 10 lines

This fix is probably wrong approach.  Proximity sensors are often scale free
because they depend on reflectance off something or a capacitance changing etc
so we don't know the scaling.  So the right response then is not to
return a scale
value of 1.0 but to not provide the attribute at all.  Is that something that
could be easily done here?

I think so. But hope that iio-sensor-proxy can handle absence of scale
attribute.

git diff drivers/iio/light/hid-sensor-prox.c

drivers/iio/light/hid-sensor-prox.c +0 -0
index a47591e1bad9..e4b81fa948f5 100644
@@ -36,7 +36,6 @@ static const struct iio_chan_spec prox_channels[]
 = {
                 .type = IIO_PROXIMITY,
                 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),

                .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
-               BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_HYSTERESIS), .scan_index = CHANNEL_SCAN_INDEX_PRESENCE,

Quoted 8 lines
Quoted 2 lines

Thanks,
Srinivas

Just to check. Are we guaranteed that there is never a scale parameter?
Some proximity sensors do have absolute units (time of flight sensors for example).

This driver is implementing:
Biometric: Human Presence (Usage ID 0x11) from HID sensor hub specification.

Quoted 8 lines

"Biometric: Human
PresenceCA,CP – An application-level or physical collection that identifies
a device that detects human presence (Boolean yes or no)."

It is not implementing Biometric: Human Proximity (Usage ID 0x12). This has range of values, then unit will be applicable.

Makes sense. In that case, formal version of the patch above?

Thanks,

Jonathan

Quoted 31 lines

Thanks,
Srinivas

Quoted 26 lines

Jonathan

Quoted 23 lines
Quoted 22 lines

For now I'm dropping the patch. Sorry I wasn't paying enough attention to notice
this was a proximity sensor.

Jonathan

Quoted 6 lines

Thanks,

Jonathan

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

Phillipp - this sounds like a fix to me.  Fixes tag?

Thanks,

Jonathan