Skip to content

Commit b8653af

Browse files
bebarinojic23
authored andcommitted
iio: sx9310: Fix semtech,avg-pos-strength setting when > 16
This DT property can be 0, 16, and then 64, but not 32. The math here doesn't recognize this slight bump in the power of 2 numbers and translates a DT property of 64 into the register value '3' when it really should be '2'. Fix it by subtracting one more if the number being translated is larger than 31. Also use clamp() because we're here. Cc: Daniel Campello <[email protected]> Cc: Lars-Peter Clausen <[email protected]> Cc: Peter Meerwald-Stadler <[email protected]> Cc: Douglas Anderson <[email protected]> Cc: Gwendal Grignou <[email protected]> Cc: Evan Green <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 40c48fb commit b8653af

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/iio/proximity/sx9310.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,8 @@ sx9310_get_default_reg(struct sx9310_data *data, int i,
13051305
if (ret)
13061306
break;
13071307

1308-
pos = min(max(ilog2(pos), 3), 10) - 3;
1308+
/* Powers of 2, except for a gap between 16 and 64 */
1309+
pos = clamp(ilog2(pos), 3, 11) - (pos >= 32 ? 4 : 3);
13091310
reg_def->def &= ~SX9310_REG_PROX_CTRL7_AVGPOSFILT_MASK;
13101311
reg_def->def |= FIELD_PREP(SX9310_REG_PROX_CTRL7_AVGPOSFILT_MASK,
13111312
pos);

0 commit comments

Comments
 (0)