From: Ray Wu <ray.wu@amd.com>
To: Hugo Sales <hugo@hsal.es>,
alexander.deucher@amd.com, sunpeng.li@amd.com,
harry.wentland@amd.com, siqueira@igalia.com,
amd-gfx@lists.freedesktop.org
Cc: simona@ffwll.ch, alex.hung@amd.com, mario.limonciello@amd.com,
linux-kernel@vger.kernel.org, lohita.mudimela@amd.com,
bhawanpreet.lakha@amd.com, dri-devel@lists.freedesktop.org,
roman.li@amd.com, airlied@gmail.com, christian.koenig@amd.com
Subject: Re: [PATCH RFC RFT 3/8] drm/amd/display: Interpolate when reading PWM back as a percentage
Date: Wed, 11 Nov 2026 15:50:59 +0800 [thread overview]
Message-ID: <f718f5ef-fe3f-464c-9472-e0f9af1ee0a7@amd.com> (raw)
In-Reply-To: <20261103-backlight-curve-rfc-v1-3-6e4813a8f2eb@hsal.es>
Reviewed-by: Ray Wu <ray.wu@amd.com>
On 11/4/2026 5:55 PM, Hugo Sales wrote:
> backlight_pwm_to_millipercent_legacy() finds the closest backlight_lut
> entry and returns its whole percent. That was the exact inverse while
> backlight_millipercent_to_pwm_legacy() only returned LUT entries. Now
> that it interpolates, a request of 1.5% programs a PWM halfway between
> two entries, which reads back as 1% or 2%, and setting the value read
> back moves the backlight by up to half a LUT step
>
> Interpolate between the two entries around the PWM instead. A PWM equal
> to a LUT entry still reads back as that entry's whole percent
>
> Signed-off-by: Hugo Sales <hugo@hsal.es>
> ---
> Converting a percentage to PWM, back, and to PWM again now moves the
> PWM by about a two-thousandth of the LUT step around it, plus rounding.
> On the GV301QH LUT, whose steps are at most 1799, that keeps every PWM
> within 1 of where it started. A curve with much wider steps can move
> further, but by far less than the half step it could before
>
> KUnit: dm_test_pwm_lut_readback from patch 6 fails without this patch
> and passes with it
> ---
> .../gpu/drm/amd/display/modules/power/power_abm.c | 33 ++++++++--------------
> 1 file changed, 11 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/modules/power/power_abm.c b/drivers/gpu/drm/amd/display/modules/power/power_abm.c
> index d9c1f1401b604..83d79c20281ec 100644
> --- a/drivers/gpu/drm/amd/display/modules/power/power_abm.c
> +++ b/drivers/gpu/drm/amd/display/modules/power/power_abm.c
> @@ -409,34 +409,23 @@ static unsigned int backlight_pwm_to_millipercent_legacy(
> break;
> }
>
> - /* In this case, exact match is not found. Check if mid/min/max
> - * value is actually closer.
> - */
> + /* No exact match, so on a sorted LUT lut[max] < pwm < lut[min] */
> if (max < min) {
> - unsigned int min_delta;
> - unsigned int mid_delta;
> - unsigned int max_delta;
> -
> - min_delta = (core_power->bl_prop[inst].backlight_lut[min] > pwm) ?
> - core_power->bl_prop[inst].backlight_lut[min] - pwm :
> - pwm - core_power->bl_prop[inst].backlight_lut[min];
> -
> - mid_delta = (core_power->bl_prop[inst].backlight_lut[mid] > pwm) ?
> - core_power->bl_prop[inst].backlight_lut[mid] - pwm :
> - pwm - core_power->bl_prop[inst].backlight_lut[mid];
> + unsigned int lower = core_power->bl_prop[inst].backlight_lut[max];
> + unsigned int upper = core_power->bl_prop[inst].backlight_lut[min];
> + unsigned long long span, den;
>
> - max_delta = (core_power->bl_prop[inst].backlight_lut[max] > pwm) ?
> - core_power->bl_prop[inst].backlight_lut[max] - pwm :
> - pwm - core_power->bl_prop[inst].backlight_lut[max];
> + if (pwm <= lower || pwm >= upper)
> + return BACKLIGHT_MILLIPERCENT_MAX * mid / max_index;
>
> - if ((min_delta < mid_delta) && (min_delta < max_delta))
> - mid = min;
> + span = upper - lower;
> + den = span * max_index;
>
> - if ((max_delta < mid_delta) && (max_delta < min_delta))
> - mid = max;
> + /* LUT entries fit in 16 bits, so this stays far below 2^64 */
> + return (unsigned int)div64_u64((max * span + pwm - lower) *
> + BACKLIGHT_MILLIPERCENT_MAX + den / 2, den);
> }
>
> - /* No interpolation, just take closest index */
> millipercent = BACKLIGHT_MILLIPERCENT_MAX * mid / max_index;
>
> return millipercent;
>
next prev parent reply other threads:[~2026-11-11 7:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 9:55 [PATCH RFC RFT 0/8] drm/amd/display: Stop rounding backlight levels to whole percents Hugo Sales
2026-11-04 9:55 ` [PATCH RFC RFT 1/8] drm/amd/display: Rename the user brightness range to user_min and user_max Hugo Sales
2026-11-04 9:55 ` [PATCH RFC RFT 2/8] drm/amd/display: Interpolate between backlight LUT entries Hugo Sales
2026-11-11 7:49 ` Ray Wu
2026-11-04 9:55 ` [PATCH RFC RFT 3/8] drm/amd/display: Interpolate when reading PWM back as a percentage Hugo Sales
2026-11-11 7:50 ` Ray Wu [this message]
2026-11-04 9:55 ` [PATCH RFC RFT 4/8] drm/amd/display: Stop rounding PWM brightness to whole percents Hugo Sales
2026-11-04 9:55 ` [PATCH RFC RFT 5/8] drm/amd/display: Add KUnit tests for the custom brightness curve Hugo Sales
2026-11-04 9:55 ` [PATCH RFC RFT 6/8] drm/amd/display: Add KUnit tests for backlight LUT interpolation Hugo Sales
2026-11-04 9:55 ` [PATCH RFC RFT 7/8] drm/amd/display: Map AUX brightness through the custom curve like PWM Hugo Sales
2026-11-04 9:55 ` [PATCH RFC RFT 8/8] drm/amd/display: Add KUnit tests for the AUX custom brightness curve Hugo Sales
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f718f5ef-fe3f-464c-9472-e0f9af1ee0a7@amd.com \
--to=ray.wu@amd.com \
--cc=airlied@gmail.com \
--cc=alex.hung@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=bhawanpreet.lakha@amd.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=harry.wentland@amd.com \
--cc=hugo@hsal.es \
--cc=linux-kernel@vger.kernel.org \
--cc=lohita.mudimela@amd.com \
--cc=mario.limonciello@amd.com \
--cc=roman.li@amd.com \
--cc=simona@ffwll.ch \
--cc=siqueira@igalia.com \
--cc=sunpeng.li@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®