Thread (35 messages) 35 messages, 7 authors, 2022-07-14

Re: [PATCH v4 13/13] video: backlight: mt6370: Add Mediatek MT6370 support

From: Andy Shevchenko <hidden>
Date: 2022-07-14 10:16:40
Also in: dri-devel, linux-arm-kernel, linux-devicetree, linux-iio, linux-leds, linux-mediatek, linux-pm, linux-usb, lkml

On Thu, Jul 14, 2022 at 11:43 AM Andy Shevchenko
[off-list ref] wrote:
On Thu, Jul 14, 2022 at 11:27 AM Andy Shevchenko
[off-list ref] wrote:
quoted
On Thu, Jul 14, 2022 at 9:13 AM ChiaEn Wu [off-list ref] wrote:
quoted
Andy Shevchenko [off-list ref] 於 2022年7月13日 週三 晚上8:07寫道:
...
quoted
quoted
 * prop_val =  1      -->  1 steps --> b'00
 * prop_val =  2 ~  4 -->  4 steps --> b'01
 * prop_val =  5 ~ 16 --> 16 steps --> b'10
 * prop_val = 17 ~ 64 --> 64 steps --> b'11
So, for 1 --> 0, for 2 --> 1, for 5 --> 2, and for 17 --> 3.
Now, consider x - 1:
0  ( 0 ) --> 0
1  (2^0) --> 1
4  (2^2) --> 2
16 (2^4) --> 3
64 (2^6) --> ? (but let's consider that the range has been checked already)

Since we take the lower limit, it means ffs():

  y = (ffs(x - 1) + 1) / 2;

Does it work for you?
It wouldn't, because we need to use fls() against it actually.

So,
0..1   (-1..0)   --> 0
2..4   (1..3)   --> 1
5..16  (4..15)  --> 2
17..64 (16..63) --> 3

y = x ? ((fls(x - 1) + 1) / 2 : 0;
Okay, I nailed it down, but Daniel is right, it's simpler to have just
conditionals.

y = x >=2 ? __fls(x - 1) / 2 + 1 : 0;


--
With Best Regards,
Andy Shevchenko
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help