drm/amd/display: use correct scale for actual_brightness
authorAlexander Monakov <amonakov@ispras.ru>
Tue, 4 Aug 2020 20:13:13 +0000 (23:13 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 18 Aug 2020 22:22:59 +0000 (18:22 -0400)
commit37d0474542850e6bb70b226487b4202d21bfe7cc
tree297f60abd243f3ae43e3fcad7fd54ddeac1dd7c1
parent16697cf39ed8c5948b44f786bf9bf749dc67692e
drm/amd/display: use correct scale for actual_brightness

Documentation for sysfs backlight level interface requires that
values in both 'brightness' and 'actual_brightness' files are
interpreted to be in range from 0 to the value given in the
'max_brightness' file.

With amdgpu, max_brightness gives 255, and values written by the user
into 'brightness' are internally rescaled to a wider range. However,
reading from 'actual_brightness' gives the raw register value without
inverse rescaling. This causes issues for various userspace tools such
as PowerTop and systemd that expect the value to be in the correct
range.

Introduce a helper to retrieve internal backlight range. Use it to
reimplement 'convert_brightness' as 'convert_brightness_from_user' and
introduce 'convert_brightness_to_user'.

Bug: https://bugzilla.kernel.org/show_bug.cgi?id=203905
Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1242
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alexander Monakov <amonakov@ispras.ru>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c