Move legacy CRTC CTM color mgmt handlers to AMD atomic check helper to
centralize legacy properties in a single place, so that we can reuse the
callers to these helpers for colorop setup.

Signed-off-by: Melissa Wen <[email protected]>
---
 .../amd/display/amdgpu_dm/amdgpu_dm_color.c   | 66 +++++++++----------
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
index 67a9ec48836d..9e5da58f26f8 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
@@ -1385,6 +1385,7 @@ int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state 
*crtc,
        uint32_t degamma_size, regamma_size;
        bool has_regamma, has_degamma;
        enum dc_transfer_func_predefined tf = TRANSFER_FUNCTION_LINEAR;
+       struct drm_color_ctm *ctm = NULL;
        bool is_legacy;
        int r;
 
@@ -1454,10 +1455,38 @@ int amdgpu_dm_check_crtc_color_mgmt(struct 
dm_crtc_state *crtc,
         * have to place the CTM in the OCSC in that case.
         */
        crtc->cm_has_degamma = has_degamma;
-       if (check_only)
+       if (check_only) {
                kvfree(out_tf);
+               return r;
+       }
 
-       return r;
+       if (r)
+               return r;
+
+       /* Setup CRTC CTM. */
+       if (crtc->base.ctm) {
+               ctm = (struct drm_color_ctm *)crtc->base.ctm->data;
+
+               /*
+                * Gamut remapping must be used for gamma correction
+                * since it comes before the regamma correction.
+                *
+                * OCSC could be used for gamma correction, but we'd need to
+                * blend the adjustments together with the required output
+                * conversion matrix - so just use the gamut remap block
+                * for now.
+                */
+               __drm_ctm_to_dc_matrix(ctm, stream->gamut_remap_matrix.matrix);
+
+               stream->gamut_remap_matrix.enable_remap = true;
+               stream->csc_color_matrix.enable_adjustment = false;
+       } else {
+               /* Bypass CTM. */
+               stream->gamut_remap_matrix.enable_remap = false;
+               stream->csc_color_matrix.enable_adjustment = false;
+       }
+
+       return 0;
 }
 
 /**
@@ -1484,38 +1513,7 @@ int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state 
*crtc,
  */
 int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)
 {
-       struct dc_stream_state *stream = crtc->stream;
-       struct drm_color_ctm *ctm = NULL;
-       int ret;
-
-       ret = amdgpu_dm_check_crtc_color_mgmt(crtc, false);
-       if (ret)
-               return ret;
-
-       /* Setup CRTC CTM. */
-       if (crtc->base.ctm) {
-               ctm = (struct drm_color_ctm *)crtc->base.ctm->data;
-
-               /*
-                * Gamut remapping must be used for gamma correction
-                * since it comes before the regamma correction.
-                *
-                * OCSC could be used for gamma correction, but we'd need to
-                * blend the adjustments together with the required output
-                * conversion matrix - so just use the gamut remap block
-                * for now.
-                */
-               __drm_ctm_to_dc_matrix(ctm, stream->gamut_remap_matrix.matrix);
-
-               stream->gamut_remap_matrix.enable_remap = true;
-               stream->csc_color_matrix.enable_adjustment = false;
-       } else {
-               /* Bypass CTM. */
-               stream->gamut_remap_matrix.enable_remap = false;
-               stream->csc_color_matrix.enable_adjustment = false;
-       }
-
-       return 0;
+       return amdgpu_dm_check_crtc_color_mgmt(crtc, false);
 }
 
 static int
-- 
2.53.0

Reply via email to