mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-23 05:56:14 -04:00
drm/amd/display: Add support for custom brightness curve
Some systems specify in the firmware a brightness curve that better reflects the characteristics of the panel used. This is done in the form of data points and matching luminance percentage. When converting a userspace requested brightness value use that curve to convert to a firmware intended brightness value. Reviewed-by: Alex Hung <alex.hung@amd.com> Link: https://lore.kernel.org/r/20250228185145.186319-5-mario.limonciello@amd.com Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
committed by
Alex Deucher
parent
f25c0f0d4f
commit
578df37b1b
@@ -4750,10 +4750,35 @@ static u32 convert_brightness_from_user(const struct amdgpu_dm_backlight_caps *c
|
||||
uint32_t brightness)
|
||||
{
|
||||
unsigned int min, max;
|
||||
u8 prev_signal = 0, prev_lum = 0;
|
||||
|
||||
if (!get_brightness_range(caps, &min, &max))
|
||||
return brightness;
|
||||
|
||||
for (int i = 0; i < caps->data_points; i++) {
|
||||
u8 signal, lum;
|
||||
|
||||
signal = caps->luminance_data[i].input_signal;
|
||||
lum = caps->luminance_data[i].luminance;
|
||||
|
||||
/*
|
||||
* brightness == signal: luminance is percent numerator
|
||||
* brightness < signal: interpolate between previous and current luminance numerator
|
||||
* brightness > signal: find next data point
|
||||
*/
|
||||
if (brightness < signal)
|
||||
lum = prev_lum + DIV_ROUND_CLOSEST((lum - prev_lum) *
|
||||
(brightness - prev_signal),
|
||||
signal - prev_signal);
|
||||
else if (brightness > signal) {
|
||||
prev_signal = signal;
|
||||
prev_lum = lum;
|
||||
continue;
|
||||
}
|
||||
brightness = DIV_ROUND_CLOSEST(lum * brightness, 101);
|
||||
break;
|
||||
}
|
||||
|
||||
// Rescale 0..255 to min..max
|
||||
return min + DIV_ROUND_CLOSEST((max - min) * brightness,
|
||||
AMDGPU_MAX_BL_LEVEL);
|
||||
|
||||
Reference in New Issue
Block a user