Message ID | 20200422065114.22164-5-tomi.valkeinen@ti.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | led-backlight cleanups & fixes | expand |
On Wed, Apr 22, 2020 at 09:51:14AM +0300, Tomi Valkeinen wrote: > The code that maps the LED default brightness to backlight levels has > two issues: 1) if the default brightness is the first backlight level > (usually 0), the code fails to find it, and 2) when the code fails to > find a backlight level, it ends up using max_brightness + 1 as the > default brightness. > > Fix these two issues. > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com> Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org> Daniel.
diff --git a/drivers/video/backlight/led_bl.c b/drivers/video/backlight/led_bl.c index 63693c4f0883..699424b111ec 100644 --- a/drivers/video/backlight/led_bl.c +++ b/drivers/video/backlight/led_bl.c @@ -139,7 +139,6 @@ static int led_bl_parse_levels(struct device *dev, num_levels = of_property_count_u32_elems(node, "brightness-levels"); if (num_levels > 1) { int i; - unsigned int db; u32 *levels; levels = devm_kzalloc(dev, sizeof(u32) * num_levels, @@ -153,15 +152,11 @@ static int led_bl_parse_levels(struct device *dev, if (ret < 0) return ret; - /* - * Try to map actual LED brightness to backlight brightness - * level - */ - db = priv->default_brightness; - for (i = 0 ; i < num_levels; i++) { - if ((i && db > levels[i - 1]) && db <= levels[i]) + /* Map LED brightness to backlight brightness level */ + for (i = 0; i < num_levels - 1; i++) + if (levels[i] >= priv->default_brightness) break; - } + priv->default_brightness = i; priv->max_brightness = num_levels - 1; priv->levels = levels;
The code that maps the LED default brightness to backlight levels has two issues: 1) if the default brightness is the first backlight level (usually 0), the code fails to find it, and 2) when the code fails to find a backlight level, it ends up using max_brightness + 1 as the default brightness. Fix these two issues. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com> --- drivers/video/backlight/led_bl.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)