From: James Lin <[email protected]>

[why]
On DCN 4.2 the global alpha is reported using 12 bits
(MPCC_GLOBAL_ALPHA spans bits [0:11]), whereas other ASICs such as
DCN 3.1.4 use an 8-bit field (MPCC_GLOBAL_ALPHA spans bits
[16:23]). The DRM plane alpha property is 16-bit and amdgpu_dm
unconditionally scaled it down by >> 8, which only matches the 8-bit
hardware field. On DCN 4.2 this fed a value that was 4 bits too small
into the 12-bit field, so the hardware applied the wrong global alpha
and the resulting blended output did not match the expected hw * alpha
value.

[how]
Detect DCN 4.2 via amdgpu_ip_version(adev, DCE_HWIP, 0) and scale the
16-bit plane alpha by >> 4 to fill the 12-bit MPCC_GLOBAL_ALPHA field.
All other ASICs keep the existing >> 8 behavior for their 8-bit field.

Reviewed-by: ChiaHsuan (Tom) Chung <[email protected]>
Signed-off-by: James Lin <[email protected]>
Signed-off-by: George Zhang <[email protected]>
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c  | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
index 20bac36be335..458b3dcdbfa3 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
@@ -137,8 +137,18 @@ void amdgpu_dm_plane_fill_blending_from_plane_state(const 
struct drm_plane_state
        }
 
        if (plane_state->alpha < 0xffff) {
+               struct amdgpu_device *adev = 
drm_to_adev(plane_state->plane->dev);
                *global_alpha = true;
-               *global_alpha_value = plane_state->alpha >> 8;
+               /*
+                * DCN 4.2 uses a 12-bit MPCC_GLOBAL_ALPHA field, while
+                * other ASICs use an 8-bit field. The DRM plane alpha is
+                * 16-bit, so scale it down to the width the hardware expects.
+                */
+               if (amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(4, 2, 0))
+                       *global_alpha_value = plane_state->alpha >> 4;
+               else
+                       *global_alpha_value = plane_state->alpha >> 8;
+
        }
 }
 EXPORT_IF_KUNIT(amdgpu_dm_plane_fill_blending_from_plane_state);
-- 
2.53.0

Reply via email to