Re: [PATCH] iio: proximity: sx9310: report a hysteresis of 0 when it is disabled
From: Andy Shevchenko
Date: Mon Oct 26 2026 - 06:42:14 EST
On Mon, Oct 26, 2026 at 03:30:32PM +0530, Arnav Kapoor wrote:
> sx9310_read_hysteresis() turns a PROXHYST value of 0 (no hysteresis)
> into a shift of 0 and reports the full threshold, which writing back
> then usually fails with -EINVAL. Report 0, as sx9324 and sx9360 do.
...
> regval = FIELD_GET(SX9310_REG_PROX_CTRL10_HYST_MASK, regval);
> if (!regval)
> - regval = 5;
> -
> - /* regval is at most 5 */
> - *val = pthresh >> (5 - regval);
> + *val = 0;
> + else
> + *val = pthresh >> (5 - regval);
While at it, invert the conditional.
if (regval)
*val = pthresh >> (5 - regval);
else
*val = 0;
--
With Best Regards,
Andy Shevchenko