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: UtsavBalar1231 <[email protected]>
  • Loading branch information
adriansm authored and HELLBOY017 committed Oct 7, 2022
1 parent b6e4ff0 commit bd7e70b
Showing 1 changed file with 23 additions and 94 deletions.
117 changes: 23 additions & 94 deletions techpack/display/msm/sde/sde_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ static int sde_backlight_device_update_status(struct backlight_device *bd)
int bl_lvl;
struct drm_event event;
int rc = 0;
#ifdef OPLUS_BUG_STABILITY
SDE_ATRACE_BEGIN("debug_io_issue_for_backlight_smooth");
#endif

brightness = bd->props.brightness;

Expand All @@ -107,106 +104,37 @@ 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;
return 0;
}

#ifndef OPLUS_BUG_STABILITY
if (c_conn->ops.set_backlight) {
/* skip notifying user space if bl is 0 */
if (brightness != 0) {
event.type = DRM_EVENT_SYS_BACKLIGHT;
event.length = sizeof(u32);
msm_mode_object_event_notify(&c_conn->base.base,
c_conn->base.dev, &event, (u8 *)&brightness);
}
rc = c_conn->ops.set_backlight(&c_conn->base,
c_conn->display, bl_lvl);
c_conn->unset_bl_level = 0;
}
#else
if (c_conn->ops.set_backlight) {
/* skip notifying user space if bl is 0 */
if (brightness != 0) {
event.type = DRM_EVENT_SYS_BACKLIGHT;
event.length = sizeof(u32);
msm_mode_object_event_notify(&c_conn->base.base,
c_conn->base.dev, &event, (u8 *)&brightness);
}

if (is_support_panel_backlight_smooths(display->panel->oplus_priv.vendor_name)) {
if ((bl_lvl >= 2) && (bl_lvl <= 200)) {
spin_lock(&g_bk_lock);
g_new_bk_level = bl_lvl;
spin_unlock(&g_bk_lock);
} else {
spin_lock(&g_bk_lock);
g_new_bk_level = bl_lvl;
spin_unlock(&g_bk_lock);
rc = c_conn->ops.set_backlight(&c_conn->base,
c_conn->display, bl_lvl);
c_conn->unset_bl_level = 0;
}
} else {
rc = c_conn->ops.set_backlight(&c_conn->base,
c_conn->display, bl_lvl);
c_conn->unset_bl_level = 0;
}
if (c_conn->ops.set_backlight) {
/* skip notifying user space if bl is 0 */
if (brightness != 0) {
event.type = DRM_EVENT_SYS_BACKLIGHT;
event.length = sizeof(u32);
msm_mode_object_event_notify(&c_conn->base.base,
c_conn->base.dev, &event, (u8 *)&brightness);
}
#endif

#ifdef OPLUS_BUG_STABILITY
SDE_ATRACE_END("debug_io_issue_for_backlight_smooth");
#endif
rc = c_conn->ops.set_backlight(&c_conn->base,
c_conn->display, bl_lvl);
c_conn->unset_bl_level = 0;
}

return rc;
}
Expand Down Expand Up @@ -249,6 +177,7 @@ static int sde_backlight_setup(struct sde_connector *c_conn,
#else
props.brightness = bl_config->brightness_default_level;
#endif
SDE_ERROR("props.brightness = %d\n",props.brightness);
snprintf(bl_node_name, BL_NODE_NAME_SIZE, "panel%u-backlight",
display_count);
c_conn->bl_device = backlight_device_register(bl_node_name, dev->dev,
Expand Down

0 comments on commit bd7e70b

Please sign in to comment.