Skip to content

Commit

Permalink
drm/msm: fix brightness level mapping
Browse files Browse the repository at this point in the history
The current brightness level mapping does not correctly map the
brightness level range from user space to the range supported by the
panel.

For example if the max user brightness reported is 4095, and panel
backlight range is 0-255. Then user is expected to be able to set
brightness in range from 0-4095, but current logic truncates at
bl-max (255). Moreover it doesn't take into account bl-min.

Fix logic such that the brightness range set by user correctly scales to
the backlight level from panel.

Bug: 139263611
Change-Id: Ic70909af63fb5b66ebc1434477f2fc41a785ce1f
Signed-off-by: Adrian Salido <[email protected]>
Signed-off-by: Carlos Ayrton Lopez Arroyo <[email protected]>
  • Loading branch information
adriansm authored and HELLBOY017 committed Sep 17, 2022
1 parent 9c5cda5 commit 983828d
Showing 1 changed file with 10 additions and 44 deletions.
54 changes: 10 additions & 44 deletions techpack/display/msm/sde/sde_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,53 +107,19 @@ static int sde_backlight_device_update_status(struct backlight_device *bd)

c_conn = bl_get_data(bd);
display = (struct dsi_display *) c_conn->display;
if (brightness > display->panel->bl_config.bl_max_level)
brightness = display->panel->bl_config.bl_max_level;
if (brightness > display->panel->bl_config.brightness_max_level)
brightness = display->panel->bl_config.brightness_max_level;

#ifndef OPLUS_BUG_STABILITY
/* map UI brightness into driver backlight level with rounding */
bl_lvl = mult_frac(brightness, display->panel->bl_config.bl_max_level,
display->panel->bl_config.brightness_max_level);
#else
if (oplus_debug_max_brightness) {
bl_lvl = mult_frac(brightness, oplus_debug_max_brightness,
display->panel->bl_config.brightness_max_level);
} else if (brightness == 0) {
bl_lvl = 0;
} else {
if (display->panel->oplus_priv.bl_remap && display->panel->oplus_priv.bl_remap_count) {
int i = 0;
int count = display->panel->oplus_priv.bl_remap_count;
struct oplus_brightness_alpha *lut = display->panel->oplus_priv.bl_remap;

for (i = 0; i < display->panel->oplus_priv.bl_remap_count; i++){
if (display->panel->oplus_priv.bl_remap[i].brightness >= brightness)
break;
}
if (brightness) {
int bl_min = display->panel->bl_config.bl_min_level ? : 1;
int bl_range = display->panel->bl_config.bl_max_level - bl_min;

if (i == 0)
bl_lvl = lut[0].alpha;
else if (i == count)
bl_lvl = lut[count - 1].alpha;
else
bl_lvl = interpolate(brightness, lut[i-1].brightness,
lut[i].brightness, lut[i-1].alpha,
lut[i].alpha, display->panel->oplus_priv.bl_interpolate_nosub);
} else if (brightness > display->panel->bl_config.brightness_normal_max_level) {
bl_lvl = interpolate(brightness,
display->panel->bl_config.brightness_normal_max_level,
display->panel->bl_config.brightness_max_level,
display->panel->bl_config.bl_normal_max_level,
display->panel->bl_config.bl_max_level, false);
} else {
bl_lvl = mult_frac(brightness, display->panel->bl_config.bl_normal_max_level,
display->panel->bl_config.brightness_normal_max_level);
}
/* map UI brightness into driver backlight level rounding it */
bl_lvl = bl_min + DIV_ROUND_CLOSEST((brightness - 1) * bl_range,
display->panel->bl_config.brightness_max_level - 1);
} else {
bl_lvl = 0;
}
#endif

if (!bl_lvl && brightness)
bl_lvl = 1;

if (!c_conn->allow_bl_update) {
c_conn->unset_bl_level = bl_lvl;
Expand Down

0 comments on commit 983828d

Please sign in to comment.