Skip to contentSkip to conversation

drm/amd/display: Use linear backlight curve in power module

PATCH RESEND In review Matthew Schwartz 2 participants 4 messages Sep 16 – Sep 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/2 drm/amd/display: Use linear backlight curve in power module

amdgpu_dm already applies the ATIF custom brightness curve in convert_custom_brightness() before handing the level to the power module. The power module then builds its own percent to PWM LUT from the same ATIF data in initialize_backlight_caps() and applies the curve a second time. On the Lenovo Legion Go S this maps the bottom 40% of the brightness range to under 12% PWM, where the panel no longer visibly changes.

Tell the power module to use its linear curve so the PWM is a straight rescale of the level DM computed, matching the behavior before the power module took over backlight programming.

Fixes 3c108046e1d6 ("drm/amd/display: Add power module on Linux")
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
index ca795cda8084..63acefc0acfb 100644
@@ -455,7 +455,7 @@ STATIC_IFN_KUNIT int amdgpu_dm_init_power_module(struct amdgpu_display_manager *
 			!(amdgpu_dc_feature_mask & DC_DISABLE_FRACTIONAL_PWM_MASK);
 		init_data[i].use_custom_backlight_caps = false;
 		init_data[i].custom_backlight_caps_config_no = 0;
-		init_data[i].use_linear_backlight_curve = false;
+		init_data[i].use_linear_backlight_curve = true;
 		init_data[i].def_varibright_enable = 0;
 		init_data[i].varibright_level = 0;
 		/*
Signature · 1 line
2.55.0
#1 lore raw

PATCH RESEND 2/2 drm/amd/display: Keep backlight precision in millipercent

The power module takes the backlight level in millipercent, but DM rounds the 16-bit level to a whole percent before multiplying by 1000, collapsing the range to 101 steps. It also divides the absolute level, which already includes the panel minimum, by the min to max span, so panels with a nonzero minimum PWM overshoot the top of the range.

Scale the offset from the minimum to millipercent directly so the full resolution reaches the power module and the minimum is only added once.

Fixes 3c108046e1d6 ("drm/amd/display: Add power module on Linux")
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c +2 -1
index 45e1732a5b04..079277d47b3f 100644
@@ -326,7 +326,8 @@ void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
 	} else {
 		/* power module uses millipercent */
 		get_brightness_range(caps, &min, &max);
-		brightness = DIV_ROUND_CLOSEST(brightness * 100, (max - min)) * 1000;
+		brightness = DIV_ROUND_CLOSEST_ULL((u64)(brightness - min) * 100000,
+						   max - min);
 		rc = mod_power_set_backlight_percent(dm->power_module, stream,
 						     brightness, 0, false);
 	}
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH RESEND 2/2] drm/amd/display: Keep backlight precision in millipercent

Hi Mathew,

Same as your other patch, a similar change has already been merged into asdn DC 3.2.400 release.
    commit: drm/amd/display: map PWM brightness through custom backlight curve

Please give it a try, and if you still see any other issues, feel free to send an updated patch.

Thanks,
Ray

Quoted 29 lines · Matthew Schwartz

The power module takes the backlight level in millipercent, but DM rounds the 16-bit level to a whole percent before multiplying by 1000, collapsing the range to 101 steps. It also divides the absolute level, which already includes the panel minimum, by the min to max span, so panels with a nonzero minimum PWM overshoot the top of the range.

Scale the offset from the minimum to millipercent directly so the full resolution reaches the power module and the minimum is only added once.

Fixes 3c108046e1d6 ("drm/amd/display: Add power module on Linux")
---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c +2 -1
index 45e1732a5b04..079277d47b3f 100644
@@ -326,7 +326,8 @@ void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
  	} else {
  		/* power module uses millipercent */
  		get_brightness_range(caps, &min, &max);
-		brightness = DIV_ROUND_CLOSEST(brightness * 100, (max - min)) * 1000;
+		brightness = DIV_ROUND_CLOSEST_ULL((u64)(brightness - min) * 100000,
+						   max - min);
  		rc = mod_power_set_backlight_percent(dm->power_module, stream,
  						     brightness, 0, false);
  	}
#3 lore raw
In reply to Matthew Schwartz

Hi Mathew,

We have a similar change has already been merged into asdn DC 3.2.400 release.
    commit: drm/amd/display: map PWM brightness through custom backlight curve

Could you give it a try? If you still see any other issues, please feel free to send an updated patch. Thanks!

Quoted 31 lines · Matthew Schwartz

amdgpu_dm already applies the ATIF custom brightness curve in convert_custom_brightness() before handing the level to the power module. The power module then builds its own percent to PWM LUT from the same ATIF data in initialize_backlight_caps() and applies the curve a second time. On the Lenovo Legion Go S this maps the bottom 40% of the brightness range to under 12% PWM, where the panel no longer visibly changes.

Tell the power module to use its linear curve so the PWM is a straight rescale of the level DM computed, matching the behavior before the power module took over backlight programming.

Fixes 3c108046e1d6 ("drm/amd/display: Add power module on Linux")
---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
index ca795cda8084..63acefc0acfb 100644
@@ -455,7 +455,7 @@ STATIC_IFN_KUNIT int amdgpu_dm_init_power_module(struct amdgpu_display_manager *
  			!(amdgpu_dc_feature_mask & DC_DISABLE_FRACTIONAL_PWM_MASK);
  		init_data[i].use_custom_backlight_caps = false;
  		init_data[i].custom_backlight_caps_config_no = 0;
-		init_data[i].use_linear_backlight_curve = false;
+		init_data[i].use_linear_backlight_curve = true;
  		init_data[i].def_varibright_enable = 0;
  		init_data[i].varibright_level = 0;
  		/*