drm/amd/display: Fix AMDGPU_MAX_BL_LEVEL value
Subsystems (5)
PATCH v2 1/2 drm/amd/display: Fix AMDGPU_MAX_BL_LEVEL value
[Why]
commit 16dc8bc27c2aa ("drm/amd/display: Export full brightness range to userspace") adjusted the brightness range to scale to larger values, but missed updating AMDGPU_MAX_BL_LEVEL which is needed to make sure that scaling works properly with custom brightness curves.
[How]
As the change for max brightness of 0xFFFF only applies to devices supporting DC, use existing DC define MAX_BACKLIGHT_LEVEL.
---
v2:
* Use DC define instead
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6 -6
@@ -4689,7 +4689,7 @@ static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev) }#define AMDGPU_DM_DEFAULT_MIN_BACKLIGHT 12 -#define AMDGPU_DM_DEFAULT_MAX_BACKLIGHT 255 +#define AMDGPU_DM_DEFAULT_MAX_BACKLIGHT MAX_BACKLIGHT_LEVEL#define AMDGPU_DM_MIN_SPREAD ((AMDGPU_DM_DEFAULT_MAX_BACKLIGHT - AMDGPU_DM_DEFAULT_MIN_BACKLIGHT) / 2)#define AUX_BL_DEFAULT_TRANSITION_TIME_MS 50
@@ -4751,16 +4751,16 @@ static int get_brightness_range(const struct amdgpu_dm_backlight_caps *caps,return 1 ; } -/* Rescale from [min..max] to [0..AMDGPU_MAX_BL_LEVEL] */ +/* Rescale from [min..max] to [0..MAX_BACKLIGHT_LEVEL] */ static inline u32 scale_input_to_fw (int min,int max,u64 input) { -return DIV_ROUND_CLOSEST_ULL (input *AMDGPU_MAX_BL_LEVEL , max - min); +return DIV_ROUND_CLOSEST_ULL (input *MAX_BACKLIGHT_LEVEL , max - min); } -/* Rescale from [0..AMDGPU_MAX_BL_LEVEL] to [min..max] */ +/* Rescale from [0..MAX_BACKLIGHT_LEVEL] to [min..max] */ static inline u32 scale_fw_to_input (int min,int max,u64 input) { -return min +DIV_ROUND_CLOSEST_ULL (input * (max - min),AMDGPU_MAX_BL_LEVEL ); +return min +DIV_ROUND_CLOSEST_ULL (input * (max - min),MAX_BACKLIGHT_LEVEL ); } static void convert_custom_brightness(const struct amdgpu_dm_backlight_caps *caps,
@@ -4980,7 +4980,7 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)drm_dbg (drm,"Backlight caps: min: %d, max: %d, ac %d, dc %d\n" , min, max, caps->ac_level, caps->dc_level); }else - props.brightness = props.max_brightness =AMDGPU_MAX_BL_LEVEL ; + props.brightness = props.max_brightness =MAX_BACKLIGHT_LEVEL ;if (caps->data_points && !(amdgpu_dc_debug_mask &DC_DISABLE_CUSTOM_BRIGHTNESS_CURVE ))drm_info (drm,"Using custom brightness curve\n" );
Signature · 1 line
2.49.0
PATCH v2 2/2 drm/amd/display: Add a trace event for brightness programming
[Why]
Brightness programming may involve a conversion of a user requested brightness against what was in a custom brightness curve. The values might not match what a user programmed.
[How]
Add a new trace event to show specific converted brightness values.
--- Documentation/gpu/amdgpu/debugging.rst | 18 +++++++++++++ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 ++++++ .../amd/display/amdgpu_dm/amdgpu_dm_trace.h | 26 +++++++++++++++++++ 3 files changed, 52 insertions(+)
Documentation/gpu/amdgpu/debugging.rst +18 -0
@@ -85,3 +85,21 @@ UMR GPU debugging and diagnostics tool. Please see the umr `documentation <https://umr.readthedocs.io/en/main/>`_ for more information about its capabilities. + +Debugging backlight brightness +============================== +Default backlight brightness is intended to be set via the policy advertised +by the firmware. Firmware will often provide different defaults for AC or DC. +Furthermore, some userspace software will save backlight brightness during +the previous boot and attempt to restore it. + +Some firmware also has support for a feature called "Custom Backlight Curves" +where an input value for brightness is mapped along a linearly interpolated +curve of brightness values that better match display characteristics. + +In the event of problems happening with backlight, there is a trace event +that can be enabled at bootup to log every brightness change request. +This can help isolate where the problem is. To enable the trace event add +the following to the kernel command line: + + tp_printk trace_event=amdgpu_dm:amdgpu_dm_brightness:mod:amdgpu trace_buf_size=1M
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -0
@@ -4860,6 +4860,14 @@ static void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm, reallow_idle = true; } +if (trace_amdgpu_dm_brightness_enabled ()) { +trace_amdgpu_dm_brightness (__builtin_return_address (0 ), + user_brightness, + brightness, + caps->aux_support, +power_supply_is_system_supplied () >0 ); + } +if (caps->aux_support) { rc =dc_link_set_backlight_level_nits (link, true, brightness,AUX_BL_DEFAULT_TRANSITION_TIME_MS );
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h +26 -0
@@ -726,6 +726,32 @@ TRACE_EVENT(dcn_optc_lock_unlock_state, ) ); +TRACE_EVENT (amdgpu_dm_brightness, + TP_PROTO(void *function, u32 user_brightness, u32 converted_brightness, bool aux, bool ac), +TP_ARGS (function, user_brightness, converted_brightness, aux, ac), +TP_STRUCT__entry ( + __field(void *, function) + __field(u32, user_brightness) + __field(u32, converted_brightness) + __field(bool, aux) +__field (bool, ac) + ), +TP_fast_assign ( + __entry->function = function; + __entry->user_brightness = user_brightness; + __entry->converted_brightness = converted_brightness; + __entry->aux = aux; + __entry->ac = ac; + ), +TP_printk ("%ps: brightness requested=%u converted=%u aux=%s power=%s" , + (void *)__entry->function, + (u32 )__entry->user_brightness, + (u32 )__entry->converted_brightness, + (__entry->aux) ?"true" :"false" , + (__entry->ac) ?"AC" :"DC" + ) +); +#endif /* _AMDGPU_DM_TRACE_H_ */ #undef TRACE_INCLUDE_PATH
Signature · 1 line
2.49.0
Re: [PATCH v2 2/2] drm/amd/display: Add a trace event for brightness programming
Quoted 97 lines · Mario Limonciello
[Why]
Brightness programming may involve a conversion of a user requested brightness against what was in a custom brightness curve. The values might not match what a user programmed.[How]
Add a new trace event to show specific converted brightness values.Signed-off-by Mario Limonciello <[email protected]>--- Documentation/gpu/amdgpu/debugging.rst | 18 +++++++++++++ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 ++++++ .../amd/display/amdgpu_dm/amdgpu_dm_trace.h | 26 +++++++++++++++++++ 3 files changed, 52 insertions(+)Documentation/gpu/amdgpu/debugging.rst +18
-0@@ -85,3 +85,21 @@ UMR GPU debugging and diagnostics tool. Please see the umr `documentation <https://umr.readthedocs.io/en/main/>`_ for more information about its capabilities. + +Debugging backlight brightness +============================== +Default backlight brightness is intended to be set via the policy advertised +by the firmware. Firmware will often provide different defaults for AC or DC. +Furthermore, some userspace software will save backlight brightness during +the previous boot and attempt to restore it. + +Some firmware also has support for a feature called "Custom Backlight Curves" +where an input value for brightness is mapped along a linearly interpolated +curve of brightness values that better match display characteristics. + +In the event of problems happening with backlight, there is a trace event +that can be enabled at bootup to log every brightness change request. +This can help isolate where the problem is. To enable the trace event add +the following to the kernel command line: + + tp_printk trace_event=amdgpu_dm:amdgpu_dm_brightness:mod:amdgpu trace_buf_size=1Mdrivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8
-0@@ -4860,6 +4860,14 @@ static void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm, reallow_idle = true; } +if (trace_amdgpu_dm_brightness_enabled ()) { +trace_amdgpu_dm_brightness (__builtin_return_address (0 ), + user_brightness, + brightness, + caps->aux_support, +power_supply_is_system_supplied () >0 ); + } +if (caps->aux_support) { rc =dc_link_set_backlight_level_nits (link, true, brightness,AUX_BL_DEFAULT_TRANSITION_TIME_MS );drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h +26
-0@@ -726,6 +726,32 @@ TRACE_EVENT(dcn_optc_lock_unlock_state, ) ); +TRACE_EVENT (amdgpu_dm_brightness, + TP_PROTO(void *function, u32 user_brightness, u32 converted_brightness, bool aux, bool ac), +TP_ARGS (function, user_brightness, converted_brightness, aux, ac), +TP_STRUCT__entry ( + __field(void *, function) + __field(u32, user_brightness) + __field(u32, converted_brightness) + __field(bool, aux) +__field (bool, ac) + ), +TP_fast_assign ( + __entry->function = function; + __entry->user_brightness = user_brightness; + __entry->converted_brightness = converted_brightness; + __entry->aux = aux; + __entry->ac = ac; + ), +TP_printk ("%ps: brightness requested=%u converted=%u aux=%s power=%s" , + (void *)__entry->function, + (u32 )__entry->user_brightness, + (u32 )__entry->converted_brightness, + (__entry->aux) ?"true" :"false" , + (__entry->ac) ?"AC" :"DC" + ) +); +#endif /* _AMDGPU_DM_TRACE_H_ */ #undef TRACE_INCLUDE_PATH
Quoted 7 lines · Mario Limonciello
[Why]
commit16dc8bc27c2aa("drm/amd/display: Export full brightness range to userspace") adjusted the brightness range to scale to larger values, but missed updatingAMDGPU_MAX_BL_LEVELwhich is needed to make sure that scaling works properly with custom brightness curves.
Quoted 6 lines
[How]
As the change for max brightness of0xFFFFonly applies to devices supporting DC, use existing DC defineMAX_BACKLIGHT_LEVEL.Fixes 16dc8bc27c2aa ("drm/amd/display: Export full brightness range to userspace")Signed-off-by Mario Limonciello <[email protected]>
Quoted 53 lines
---
v2:
* Use DC define instead--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6
-7@@ -4689,7 +4689,7 @@ static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev) }#define AMDGPU_DM_DEFAULT_MIN_BACKLIGHT 12 -#define AMDGPU_DM_DEFAULT_MAX_BACKLIGHT 255 +#define AMDGPU_DM_DEFAULT_MAX_BACKLIGHT MAX_BACKLIGHT_LEVEL#define AMDGPU_DM_MIN_SPREAD ((AMDGPU_DM_DEFAULT_MAX_BACKLIGHT - AMDGPU_DM_DEFAULT_MIN_BACKLIGHT) / 2)#define AUX_BL_DEFAULT_TRANSITION_TIME_MS 50@@ -4751,16 +4751,16 @@ static int get_brightness_range(const struct amdgpu_dm_backlight_caps *caps,return 1 ; } -/* Rescale from [min..max] to [0..AMDGPU_MAX_BL_LEVEL] */ +/* Rescale from [min..max] to [0..MAX_BACKLIGHT_LEVEL] */ static inline u32 scale_input_to_fw (int min,int max,u64 input) { -return DIV_ROUND_CLOSEST_ULL (input *AMDGPU_MAX_BL_LEVEL , max - min); +return DIV_ROUND_CLOSEST_ULL (input *MAX_BACKLIGHT_LEVEL , max - min); } -/* Rescale from [0..AMDGPU_MAX_BL_LEVEL] to [min..max] */ +/* Rescale from [0..MAX_BACKLIGHT_LEVEL] to [min..max] */ static inline u32 scale_fw_to_input (int min,int max,u64 input) { -return min +DIV_ROUND_CLOSEST_ULL (input * (max - min),AMDGPU_MAX_BL_LEVEL ); +return min +DIV_ROUND_CLOSEST_ULL (input * (max - min),MAX_BACKLIGHT_LEVEL ); } static void convert_custom_brightness(const struct amdgpu_dm_backlight_caps *caps,@@ -4980,7 +4980,7 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)drm_dbg (drm,"Backlight caps: min: %d, max: %d, ac %d, dc %d\n" , min, max, caps->ac_level, caps->dc_level); }else - props.brightness = props.max_brightness =AMDGPU_MAX_BL_LEVEL ; + props.brightness = props.max_brightness =MAX_BACKLIGHT_LEVEL ;if (caps->data_points && !(amdgpu_dc_debug_mask &DC_DISABLE_CUSTOM_BRIGHTNESS_CURVE ))drm_info (drm,"Using custom brightness curve\n" ); --2.49.0