Commit c9e235aa authored by Ville Syrjälä's avatar Ville Syrjälä
Browse files

drm/i915: Extract ilk_csc_convert_ctm()



Start splitting low level nuts and bolts stuff from
ilk_load_csc_matrix(). The goal is to leave only the clear
high level logic in place.

Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190218193137.22914-6-ville.syrjala@linux.intel.com


Reviewed-by: default avatarUma Shankar <uma.shankar@intel.com>
parent d2c19b06
Loading
Loading
Loading
Loading
+53 −44
Original line number Diff line number Diff line
@@ -188,41 +188,15 @@ static bool ilk_csc_limited_range(const struct intel_crtc_state *crtc_state)
		 IS_GEN_RANGE(dev_priv, 9, 10));
}

static void ilk_load_csc_matrix(const struct intel_crtc_state *crtc_state)
static void ilk_csc_convert_ctm(const struct intel_crtc_state *crtc_state,
				u16 coeffs[9])
{
	struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
	bool limited_color_range = ilk_csc_limited_range(crtc_state);
	enum pipe pipe = crtc->pipe;
	u16 coeffs[9] = {};
	int i;

	if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
	    crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) {
		if (INTEL_GEN(dev_priv) >= 11)
			icl_update_output_csc(crtc, ilk_csc_off_zero,
					      ilk_csc_coeff_rgb_to_ycbcr,
					      ilk_csc_postoff_rgb_to_ycbcr);
		else
			ilk_update_pipe_csc(crtc, ilk_csc_off_zero,
					    ilk_csc_coeff_rgb_to_ycbcr,
					    ilk_csc_postoff_rgb_to_ycbcr);

		I915_WRITE(PIPE_CSC_MODE(pipe), crtc_state->csc_mode);
		/*
		 * On pre GEN11 output CSC is not there, so with 1 pipe CSC
		 * RGB to YUV conversion can be done. No need to go further
		 */
		if (INTEL_GEN(dev_priv) < 11)
			return;
	}

	if (crtc_state->base.ctm) {
		struct drm_color_ctm *ctm = crtc_state->base.ctm->data;
	const struct drm_color_ctm *ctm = crtc_state->base.ctm->data;
	const u64 *input;
	u64 temp[9];
	int i;

		if (limited_color_range)
	if (ilk_csc_limited_range(crtc_state))
		input = ctm_mult_by_limited(temp, ctm->matrix);
	else
		input = ctm->matrix;
@@ -231,7 +205,7 @@ static void ilk_load_csc_matrix(const struct intel_crtc_state *crtc_state)
	 * Convert fixed point S31.32 input to format supported by the
	 * hardware.
	 */
		for (i = 0; i < ARRAY_SIZE(coeffs); i++) {
	for (i = 0; i < 9; i++) {
		u64 abs_coeff = ((1ULL << 63) - 1) & input[i];

		/*
@@ -240,6 +214,8 @@ static void ilk_load_csc_matrix(const struct intel_crtc_state *crtc_state)
		 */
		abs_coeff = clamp_val(abs_coeff, 0, CTM_COEFF_4_0 - 1);

		coeffs[i] = 0;

		/* sign bit */
		if (CTM_COEFF_NEGATIVE(input[i]))
			coeffs[i] |= 1 << 15;
@@ -262,6 +238,39 @@ static void ilk_load_csc_matrix(const struct intel_crtc_state *crtc_state)
			coeffs[i] |= (6 << 12) |
				ILK_CSC_COEFF_FP(abs_coeff, 7);
	}
}

static void ilk_load_csc_matrix(const struct intel_crtc_state *crtc_state)
{
	struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
	bool limited_color_range = ilk_csc_limited_range(crtc_state);
	enum pipe pipe = crtc->pipe;
	u16 coeffs[9] = {};
	int i;

	if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
	    crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) {
		if (INTEL_GEN(dev_priv) >= 11)
			icl_update_output_csc(crtc, ilk_csc_off_zero,
					      ilk_csc_coeff_rgb_to_ycbcr,
					      ilk_csc_postoff_rgb_to_ycbcr);
		else
			ilk_update_pipe_csc(crtc, ilk_csc_off_zero,
					    ilk_csc_coeff_rgb_to_ycbcr,
					    ilk_csc_postoff_rgb_to_ycbcr);

		I915_WRITE(PIPE_CSC_MODE(pipe), crtc_state->csc_mode);
		/*
		 * On pre GEN11 output CSC is not there, so with 1 pipe CSC
		 * RGB to YUV conversion can be done. No need to go further
		 */
		if (INTEL_GEN(dev_priv) < 11)
			return;
	}

	if (crtc_state->base.ctm) {
		ilk_csc_convert_ctm(crtc_state, coeffs);
	} else {
		/*
		 * Load an identity matrix if no coefficients are provided.