Skip to content

Commit 26a3ca7

Browse files
committed
drm/amd/display: Export full brightness range to userspace
JIRA: https://issues.redhat.com/browse/RHEL-75958 commit 889906e6eb5fab990c9b6b5fe8f1122b2416fc22 Author: Mario Limonciello <mario.limonciello@amd.com> Date: Thu May 29 09:46:32 2025 -0500 drm/amd/display: Export full brightness range to userspace commit 16dc8bc upstream. [WHY] Userspace currently is offered a range from 0-0xFF but the PWM is programmed from 0-0xFFFF. This can be limiting to some software that wants to apply greater granularity. [HOW] Convert internally to firmware values only when mapping custom brightness curves because these are in 0-0xFF range. Advertise full PWM range to userspace. Cc: Mario Limonciello <mario.limonciello@amd.com> Cc: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Roman Li <roman.li@amd.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Alex Hung <alex.hung@amd.com> Tested-by: Daniel Wheeler <daniel.wheeler@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 8dbd72c) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: José Expósito <jexposit@redhat.com>
1 parent c6a29aa commit 26a3ca7

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4655,9 +4655,23 @@ static int get_brightness_range(const struct amdgpu_dm_backlight_caps *caps,
46554655
return 1;
46564656
}
46574657

4658+
/* Rescale from [min..max] to [0..AMDGPU_MAX_BL_LEVEL] */
4659+
static inline u32 scale_input_to_fw(int min, int max, u64 input)
4660+
{
4661+
return DIV_ROUND_CLOSEST_ULL(input * AMDGPU_MAX_BL_LEVEL, max - min);
4662+
}
4663+
4664+
/* Rescale from [0..AMDGPU_MAX_BL_LEVEL] to [min..max] */
4665+
static inline u32 scale_fw_to_input(int min, int max, u64 input)
4666+
{
4667+
return min + DIV_ROUND_CLOSEST_ULL(input * (max - min), AMDGPU_MAX_BL_LEVEL);
4668+
}
4669+
46584670
static void convert_custom_brightness(const struct amdgpu_dm_backlight_caps *caps,
4659-
uint32_t *brightness)
4671+
unsigned int min, unsigned int max,
4672+
uint32_t *user_brightness)
46604673
{
4674+
u32 brightness = scale_input_to_fw(min, max, *user_brightness);
46614675
u8 prev_signal = 0, prev_lum = 0;
46624676
int i = 0;
46634677

@@ -4668,7 +4682,7 @@ static void convert_custom_brightness(const struct amdgpu_dm_backlight_caps *cap
46684682
return;
46694683

46704684
/* choose start to run less interpolation steps */
4671-
if (caps->luminance_data[caps->data_points/2].input_signal > *brightness)
4685+
if (caps->luminance_data[caps->data_points/2].input_signal > brightness)
46724686
i = caps->data_points/2;
46734687
do {
46744688
u8 signal = caps->luminance_data[i].input_signal;
@@ -4679,17 +4693,18 @@ static void convert_custom_brightness(const struct amdgpu_dm_backlight_caps *cap
46794693
* brightness < signal: interpolate between previous and current luminance numerator
46804694
* brightness > signal: find next data point
46814695
*/
4682-
if (*brightness > signal) {
4696+
if (brightness > signal) {
46834697
prev_signal = signal;
46844698
prev_lum = lum;
46854699
i++;
46864700
continue;
46874701
}
4688-
if (*brightness < signal)
4702+
if (brightness < signal)
46894703
lum = prev_lum + DIV_ROUND_CLOSEST((lum - prev_lum) *
4690-
(*brightness - prev_signal),
4704+
(brightness - prev_signal),
46914705
signal - prev_signal);
4692-
*brightness = DIV_ROUND_CLOSEST(lum * *brightness, 101);
4706+
*user_brightness = scale_fw_to_input(min, max,
4707+
DIV_ROUND_CLOSEST(lum * brightness, 101));
46934708
return;
46944709
} while (i < caps->data_points);
46954710
}
@@ -4702,11 +4717,10 @@ static u32 convert_brightness_from_user(const struct amdgpu_dm_backlight_caps *c
47024717
if (!get_brightness_range(caps, &min, &max))
47034718
return brightness;
47044719

4705-
convert_custom_brightness(caps, &brightness);
4720+
convert_custom_brightness(caps, min, max, &brightness);
47064721

4707-
// Rescale 0..255 to min..max
4708-
return min + DIV_ROUND_CLOSEST((max - min) * brightness,
4709-
AMDGPU_MAX_BL_LEVEL);
4722+
// Rescale 0..max to min..max
4723+
return min + DIV_ROUND_CLOSEST_ULL((u64)(max - min) * brightness, max);
47104724
}
47114725

47124726
static u32 convert_brightness_to_user(const struct amdgpu_dm_backlight_caps *caps,
@@ -4719,8 +4733,8 @@ static u32 convert_brightness_to_user(const struct amdgpu_dm_backlight_caps *cap
47194733

47204734
if (brightness < min)
47214735
return 0;
4722-
// Rescale min..max to 0..255
4723-
return DIV_ROUND_CLOSEST(AMDGPU_MAX_BL_LEVEL * (brightness - min),
4736+
// Rescale min..max to 0..max
4737+
return DIV_ROUND_CLOSEST_ULL((u64)max * (brightness - min),
47244738
max - min);
47254739
}
47264740

@@ -4870,11 +4884,10 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
48704884
drm_dbg(drm, "Backlight caps: min: %d, max: %d, ac %d, dc %d\n", min, max,
48714885
caps->ac_level, caps->dc_level);
48724886
} else
4873-
props.brightness = AMDGPU_MAX_BL_LEVEL;
4887+
props.brightness = props.max_brightness = AMDGPU_MAX_BL_LEVEL;
48744888

48754889
if (caps->data_points && !(amdgpu_dc_debug_mask & DC_DISABLE_CUSTOM_BRIGHTNESS_CURVE))
48764890
drm_info(drm, "Using custom brightness curve\n");
4877-
props.max_brightness = AMDGPU_MAX_BL_LEVEL;
48784891
props.type = BACKLIGHT_RAW;
48794892

48804893
snprintf(bl_name, sizeof(bl_name), "amdgpu_bl%d",

0 commit comments

Comments
 (0)