Re: [PATCH] iio: sx9310: Fix semtech,avg-pos-strength setting when > 16

From: Stephen Boyd
Date: Fri Nov 20 2020 - 13:21:08 EST


Quoting Doug Anderson (2020-11-20 10:16:28)
>
> Checking the math for the documented possible values of pos. What we want:
>
> 0 => 0
> 16 => 1
> 64 => 2
> 128 => 3
> 256 => 4
> 512 => 5
> 1024 => 6
> 4294967295 => 7
>
> So looks OK. Do we care about anything other than the documented
> numbers? If my understanding of ilog2 is correct, then you'll get the
> wrong answer for 17. I think you could fix it with:
>
> pos = min(max(ilog2(pos), 3), 11) - (pos >= 32 ? 4 : 3);
>

I don't think we really care about the rounding but to be consistent
with the first two it is better to do that. I'll send a fix.