mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: proximity: sx9324: Correct proximity channel resolution
@ 2026-08-18  7:28 Zhang Jie
  2026-08-18  8:26 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang Jie @ 2026-08-18  7:28 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy
  Cc: gwendal, swboyd, linux-iio, linux-kernel, Zhang Jie, stable

The proximity channels were previously defined with 12 realbits.
However, PROXDIFF is read from RegDiffMsb (0x65) and RegDiffLsb
(0x66). The SX9324 datasheet assigns bits 7:0 of each register to
PROXDIFF and documents it as a signed two's-complement value
(Revision 3, Section 8, Table 8, page 43). In contrast, RegOffsetMsb
explicitly marks bits 7:6 as reserved. Thus, PROXDIFF is a 16-bit
signed value.

With realbits = 12, sx_common_read_proximity() uses bit 11 as the
sign bit in sign_extend32(), causing samples outside the 12-bit
signed range to wrap into the [-2048, 2047] range.

Correct the realbits value to 16 to accurately reflect the hardware.

Tested on an SX9324-based device: a phase 0 DIFF readback of 0x7fff
was reported as -1 before this change and as 32767 afterward.

Fixes: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support")
Cc: stable@vger.kernel.org
Signed-off-by: Zhang Jie <zhangjie14@huaqin.corp-partner.google.com>
---
 drivers/iio/proximity/sx9324.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
index 36c45d101336..de6176fd8d47 100644
--- a/drivers/iio/proximity/sx9324.c
+++ b/drivers/iio/proximity/sx9324.c
@@ -223,7 +223,7 @@ static const struct iio_chan_spec_ext_info sx9324_channel_ext_info[] = {
 	.scan_index = idx,					 \
 	.scan_type = {						 \
 		.sign = 's',					 \
-		.realbits = 12,					 \
+		.realbits = 16,					 \
 		.storagebits = 16,				 \
 		.endianness = IIO_BE,				 \
 	},							 \
-- 
2.53.0


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

* Re: [PATCH] iio: proximity: sx9324: Correct proximity channel resolution
  2026-08-18  7:28 [PATCH] iio: proximity: sx9324: Correct proximity channel resolution Zhang Jie
@ 2026-08-18  8:26 ` Andy Shevchenko
  2026-08-19  1:18   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-08-18  8:26 UTC (permalink / raw)
  To: Zhang Jie, Hans de Goede
  Cc: jic23, dlechner, nuno.sa, andy, gwendal, swboyd, linux-iio,
	linux-kernel, stable

On Tue, Aug 18, 2026 at 03:28:03PM +0800, Zhang Jie wrote:
> The proximity channels were previously defined with 12 realbits.
> However, PROXDIFF is read from RegDiffMsb (0x65) and RegDiffLsb
> (0x66). The SX9324 datasheet assigns bits 7:0 of each register to
> PROXDIFF and documents it as a signed two's-complement value
> (Revision 3, Section 8, Table 8, page 43). In contrast, RegOffsetMsb
> explicitly marks bits 7:6 as reserved. Thus, PROXDIFF is a 16-bit
> signed value.
> 
> With realbits = 12, sx_common_read_proximity() uses bit 11 as the
> sign bit in sign_extend32(), causing samples outside the 12-bit
> signed range to wrap into the [-2048, 2047] range.
> 
> Correct the realbits value to 16 to accurately reflect the hardware.

> Tested on an SX9324-based device: a phase 0 DIFF readback of 0x7fff
> was reported as -1 before this change and as 32767 afterward.

Yeah, there seems only Chromebook devices (in ACPI world), MediaTek and
Qualcomm (in DT world). Do we have anybody from Qualcomm to test this?

Hans, I think you (or somebody you might know at QCOMM) might be interested
in this fix.

From the datasheet shared I see the same as described in this commit
and since it was tested on real devices I'm quite sure this is the case.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

> Fixes: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zhang Jie <zhangjie14@huaqin.corp-partner.google.com>
> ---
>  drivers/iio/proximity/sx9324.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
> index 36c45d101336..de6176fd8d47 100644
> --- a/drivers/iio/proximity/sx9324.c
> +++ b/drivers/iio/proximity/sx9324.c
> @@ -223,7 +223,7 @@ static const struct iio_chan_spec_ext_info sx9324_channel_ext_info[] = {
>  	.scan_index = idx,					 \
>  	.scan_type = {						 \
>  		.sign = 's',					 \
> -		.realbits = 12,					 \
> +		.realbits = 16,					 \
>  		.storagebits = 16,				 \
>  		.endianness = IIO_BE,				 \
>  	},							 \

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] iio: proximity: sx9324: Correct proximity channel resolution
  2026-08-18  8:26 ` Andy Shevchenko
@ 2026-08-19  1:18   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-08-19  1:18 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Zhang Jie, Hans de Goede, dlechner, nuno.sa, andy, gwendal,
	swboyd, linux-iio, linux-kernel, stable, Joseph S. Barrera III

On Tue, 18 Aug 2026 11:26:39 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Tue, Aug 18, 2026 at 03:28:03PM +0800, Zhang Jie wrote:
> > The proximity channels were previously defined with 12 realbits.
> > However, PROXDIFF is read from RegDiffMsb (0x65) and RegDiffLsb
> > (0x66). The SX9324 datasheet assigns bits 7:0 of each register to
> > PROXDIFF and documents it as a signed two's-complement value
> > (Revision 3, Section 8, Table 8, page 43). In contrast, RegOffsetMsb
> > explicitly marks bits 7:6 as reserved. Thus, PROXDIFF is a 16-bit
> > signed value.
> > 
> > With realbits = 12, sx_common_read_proximity() uses bit 11 as the
> > sign bit in sign_extend32(), causing samples outside the 12-bit
> > signed range to wrap into the [-2048, 2047] range.
> > 
> > Correct the realbits value to 16 to accurately reflect the hardware.  
> 
> > Tested on an SX9324-based device: a phase 0 DIFF readback of 0x7fff
> > was reported as -1 before this change and as 32767 afterward.  
> 
> Yeah, there seems only Chromebook devices (in ACPI world), MediaTek and
> Qualcomm (in DT world). Do we have anybody from Qualcomm to test this?
> 
> Hans, I think you (or somebody you might know at QCOMM) might be interested
> in this fix.

Looks like the actual dtsi blobs were all from google.
+CC Joseph on off chance still involved.

Applied the patch to the fixes-togreg branch of iio.git.
Note I'll rebase that on rc1 once available.

Jonathan

> 
> From the datasheet shared I see the same as described in this commit
> and since it was tested on real devices I'm quite sure this is the case.
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
> > Fixes: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Zhang Jie <zhangjie14@huaqin.corp-partner.google.com>
> > ---
> >  drivers/iio/proximity/sx9324.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
> > index 36c45d101336..de6176fd8d47 100644
> > --- a/drivers/iio/proximity/sx9324.c
> > +++ b/drivers/iio/proximity/sx9324.c
> > @@ -223,7 +223,7 @@ static const struct iio_chan_spec_ext_info sx9324_channel_ext_info[] = {
> >  	.scan_index = idx,					 \
> >  	.scan_type = {						 \
> >  		.sign = 's',					 \
> > -		.realbits = 12,					 \
> > +		.realbits = 16,					 \
> >  		.storagebits = 16,				 \
> >  		.endianness = IIO_BE,				 \
> >  	},							 \  
> 


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

end of thread, other threads:[~2026-08-19  1:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-18  7:28 [PATCH] iio: proximity: sx9324: Correct proximity channel resolution Zhang Jie
2026-08-18  8:26 ` Andy Shevchenko
2026-08-19  1:18   ` Jonathan Cameron

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

all inboxes | Powered by JetHome®