diff mbox series

[RFC,v2,4/6] drm/i915/scaler: Compute scling factors for pipe scaler

Message ID 20241217180710.1048355-5-mitulkumar.ajitkumar.golani@intel.com (mailing list archive)
State New
Headers show
Series Check if is vblank too short | expand

Commit Message

Mitul Golani Dec. 17, 2024, 6:07 p.m. UTC
Compute scaling factors and scaler user for pipe scaler if
perticular scaler user is pipe scaler.

Signed-off-by: Mitul Golani <mitulkumar.ajitkumar.golani@intel.com>
---
 drivers/gpu/drm/i915/display/skl_scaler.c | 37 ++++++++++++++++++++---
 1 file changed, 33 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/skl_scaler.c b/drivers/gpu/drm/i915/display/skl_scaler.c
index 1c65b53b45f0..1a4aba434d8c 100644
--- a/drivers/gpu/drm/i915/display/skl_scaler.c
+++ b/drivers/gpu/drm/i915/display/skl_scaler.c
@@ -319,6 +319,7 @@  static int intel_atomic_setup_scaler(struct intel_crtc_state *crtc_state,
 					&crtc_state->scaler_state;
 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
 	u32 mode;
+	int hscale, vscale, user;
 
 	if (*scaler_id < 0)
 		*scaler_id = intel_allocate_scaler(scaler_state, crtc);
@@ -375,7 +376,7 @@  static int intel_atomic_setup_scaler(struct intel_crtc_state *crtc_state,
 		const struct drm_framebuffer *fb = plane_state->hw.fb;
 		const struct drm_rect *src = &plane_state->uapi.src;
 		const struct drm_rect *dst = &plane_state->uapi.dst;
-		int hscale, vscale, max_vscale, max_hscale;
+		int max_vscale, max_hscale;
 
 		/*
 		 * FIXME: When two scalers are needed, but only one of
@@ -426,11 +427,39 @@  static int intel_atomic_setup_scaler(struct intel_crtc_state *crtc_state,
 			return -EINVAL;
 		}
 
-		scaler_state->scalers[*scaler_id].hscale = hscale;
-		scaler_state->scalers[*scaler_id].vscale = vscale;
-		scaler_state->scalers[*scaler_id].user = SKL_PLANE_SCALER;
+		user = SKL_PLANE_SCALER;
 	}
 
+	if (crtc_state->pch_pfit.enabled) {
+		struct drm_rect src;
+		int hscale, vscale;
+
+		drm_rect_init(&src, 0, 0,
+			      drm_rect_width(&crtc_state->pipe_src) << 16,
+			      drm_rect_height(&crtc_state->pipe_src) << 16);
+
+		hscale = drm_rect_calc_hscale(&src, &crtc_state->pch_pfit.dst,
+					      0, INT_MAX);
+		vscale = drm_rect_calc_vscale(&src, &crtc_state->pch_pfit.dst,
+					      0, INT_MAX);
+
+		if (hscale < 0 || vscale < 0) {
+			drm_dbg_kms(display->drm,
+				    "Scaler %d doesn't support required plane scaling\n",
+				    *scaler_id);
+			drm_rect_debug_print("src: ", &src, true);
+			drm_rect_debug_print("dst: ", &crtc_state->pch_pfit.dst, false);
+
+			return -EINVAL;
+		}
+
+		user = SKL_PIPE_SCALER;
+	}
+
+	scaler_state->scalers[*scaler_id].hscale = hscale;
+	scaler_state->scalers[*scaler_id].vscale = vscale;
+	scaler_state->scalers[*scaler_id].user = user;
+
 	drm_dbg_kms(display->drm, "Attached scaler id %u.%u to %s:%d\n",
 		    crtc->pipe, *scaler_id, name, idx);
 	scaler_state->scalers[*scaler_id].mode = mode;