From: Ray Wu <[email protected]> [Why & How] Add mod_power_set_brightness() so DM can pass a percentage for every panel type and let the power module pick the unit:
- VESA AUX takes nits, mapped linearly over the panel range. - AMD AUX takes nits on OLED and in HDR, and follows PWM otherwise. - PWM goes through the backlight LUT built from ATIF. The AUX brightness mask is ORed into the nits. Cc: ChiaHsuan Chung <[email protected]> Signed-off-by: Ray Wu <[email protected]> Signed-off-by: James Lin <[email protected]> --- .../drm/amd/display/modules/inc/mod_power.h | 7 ++ .../drm/amd/display/modules/power/power_abm.c | 65 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/drivers/gpu/drm/amd/display/modules/inc/mod_power.h b/drivers/gpu/drm/amd/display/modules/inc/mod_power.h index 25a0c96ac754..3b6eb2116636 100644 --- a/drivers/gpu/drm/amd/display/modules/inc/mod_power.h +++ b/drivers/gpu/drm/amd/display/modules/inc/mod_power.h @@ -221,6 +221,13 @@ bool mod_power_set_backlight_percent(struct mod_power *mod_power, unsigned int transition_time_millisec, bool is_hdr); +bool mod_power_set_brightness(struct mod_power *mod_power, + struct dc_stream_state *stream, + unsigned int backlight_millipercent, + unsigned int transition_time_millisec, + unsigned int aux_brightness_mask, + bool is_hdr); + void mod_power_update_backlight(struct mod_power *mod_power, struct dc_stream_state *stream, unsigned int backlight_millipercent); diff --git a/drivers/gpu/drm/amd/display/modules/power/power_abm.c b/drivers/gpu/drm/amd/display/modules/power/power_abm.c index 60930d969b9b..a5077b43837f 100644 --- a/drivers/gpu/drm/amd/display/modules/power/power_abm.c +++ b/drivers/gpu/drm/amd/display/modules/power/power_abm.c @@ -1166,6 +1166,71 @@ bool mod_power_set_backlight_percent(struct mod_power *mod_power, &backlight_level_params, panel_inst); } +/* AMD AUX takes nits only when the panel's AUX backlight control is on, + * which DC turns on for OLED and for HDR. Otherwise the panel follows PWM. + */ +static bool backlight_takes_nits(const struct dc_link *link, bool is_hdr) +{ + switch (link->backlight_control_type) { + case BACKLIGHT_CONTROL_VESA_AUX: + return true; + case BACKLIGHT_CONTROL_AMD_AUX: + return link->dpcd_sink_ext_caps.bits.oled || is_hdr; + default: + return false; + } +} + +/* Sets the brightness as a percentage, whatever the backlight control type. + * When the panel takes nits, the percentage maps linearly to + * [min_brightness_millinits, max_brightness_millinits] with + * aux_brightness_mask ORed in. Otherwise it maps to PWM through the + * backlight LUT. + */ +bool mod_power_set_brightness(struct mod_power *mod_power, + struct dc_stream_state *stream, + unsigned int backlight_millipercent, + unsigned int transition_time_millisec, + unsigned int aux_brightness_mask, + bool is_hdr) +{ + struct core_power *core_power = NULL; + const struct dc_link *link = NULL; + unsigned int backlight_millinit; + unsigned int panel_inst = 0; + + if (mod_power == NULL || stream == NULL) + return false; + + core_power = MOD_POWER_TO_CORE(mod_power); + link = dc_stream_get_link(stream); + + if (!dc_get_edp_link_panel_inst(core_power->dc, link, &panel_inst)) + return false; + + if (backlight_millipercent > BACKLIGHT_MILLIPERCENT_MAX) + backlight_millipercent = BACKLIGHT_MILLIPERCENT_MAX; + + core_power->bl_state[panel_inst].isHDR = is_hdr; + + if (!backlight_takes_nits(link, is_hdr)) + return mod_power_set_backlight_percent(mod_power, stream, + backlight_millipercent, transition_time_millisec, is_hdr); + + backlight_millinit = backlight_millipercent_to_millinit_legacy( + core_power, backlight_millipercent, panel_inst) | + aux_brightness_mask; + + if (!mod_power_set_backlight_nits(mod_power, stream, backlight_millinit, + transition_time_millisec, false, is_hdr)) + return false; + + /* mod_power_set_backlight_nits() caches the percent read back from nits */ + core_power->bl_state[panel_inst].backlight_millipercent = backlight_millipercent; + + return true; +} + void mod_power_update_backlight(struct mod_power *mod_power, struct dc_stream_state *stream, unsigned int backlight_millipercent) -- 2.43.0
