[PATCH v1 09/10] drm/i915/casf: abstract scaler searching loop

Michał Grzelak
2026-03-28T14:33:25Z

Add a helper function hiding the search for scaler_id.

Cc: Nemesa Garg <nemesa.garg@intel.com>
Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Michał Grzelak <michal.grzelak@intel.com>
---
drivers/gpu/drm/i915/display/skl_scaler.c | 28 +++++++++++++++--------
1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/skl_scaler.c b/drivers/gpu/drm/i915/display/skl_scaler.c
index 9318fd1bcc45..1bd42ef36d07 100644
--- a/drivers/gpu/drm/i915/display/skl_scaler.c
+++ b/drivers/gpu/drm/i915/display/skl_scaler.c
@@ -858,6 +858,21 @@ void skl_pfit_enable(const struct intel_crtc_state *crtc_state)
PS_WIN_XSIZE(width) | PS_WIN_YSIZE(height));
}

+static int skl_pipe_scaler_get_hw_state(struct intel_crtc_state *crtc_state)
+{
+ struct intel_display *display = to_intel_display(crtc_state);
+ struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
+ u32 ctl;
+
+ for (int scaler_id = 0; scaler_id < crtc->num_scalers; scaler_id++) {
+ ctl = intel_de_read(display, SKL_PS_CTRL(crtc->pipe, scaler_id));
+ if ((ctl & (PS_SCALER_EN | PS_BINDING_MASK)) == (PS_SCALER_EN | PS_BINDING_PIPE))
+ return scaler_id;
+ }
+
+ return -1;
+}
+
void
skl_program_plane_scaler(struct intel_dsb *dsb,
struct intel_plane *plane,
@@ -969,17 +984,12 @@ void skl_scaler_get_config(struct intel_crtc_state *crtc_state)
struct intel_display *display = to_intel_display(crtc_state);
struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
- int scaler_id;
- u32 pos, size;
-
/* find scaler attached to this pipe */
- for (scaler_id = 0; scaler_id < crtc->num_scalers; scaler_id++) {
- u32 ctl;
+ int scaler_id = skl_pipe_scaler_get_hw_state(crtc_state);
+ u32 pos, size;

- ctl = intel_de_read(display, SKL_PS_CTRL(crtc->pipe, scaler_id));
- if ((ctl & (PS_SCALER_EN | PS_BINDING_MASK)) == (PS_SCALER_EN | PS_BINDING_PIPE))
- break;
- }
+ if (scaler_id < 0)
+ return;

/* Read CASF regs for second scaler */
if (HAS_CASF(display) && scaler_id == 1)
--
2.45.2