[PATCH v2 4/5] drm/amd/display: Add support for custom brightness curve
Alex Hung
alex.hung at amd.com
Fri Feb 28 22:04:39 UTC 2025
Reviewed-by: Alex Hung <alex.hung at amd.com>
On 2/28/25 11:51, Mario Limonciello wrote:
> 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.
>
> Signed-off-by: Mario Limonciello <mario.limonciello at amd.com>
> ---
> .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 25 +++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 61d626914590..b252c67f2bc4 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -4759,10 +4759,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);
More information about the amd-gfx
mailing list