Skip to content

Commit c9e235a

Browse files
committed
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: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20190218193137.22914-6-ville.syrjala@linux.intel.com Reviewed-by: Uma Shankar <uma.shankar@intel.com>
1 parent d2c19b0 commit c9e235a

File tree

1 file changed

+53
-44
lines changed

1 file changed

+53
-44
lines changed

drivers/gpu/drm/i915/intel_color.c

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,58 @@ static bool ilk_csc_limited_range(const struct intel_crtc_state *crtc_state)
188188
IS_GEN_RANGE(dev_priv, 9, 10));
189189
}
190190

191+
static void ilk_csc_convert_ctm(const struct intel_crtc_state *crtc_state,
192+
u16 coeffs[9])
193+
{
194+
const struct drm_color_ctm *ctm = crtc_state->base.ctm->data;
195+
const u64 *input;
196+
u64 temp[9];
197+
int i;
198+
199+
if (ilk_csc_limited_range(crtc_state))
200+
input = ctm_mult_by_limited(temp, ctm->matrix);
201+
else
202+
input = ctm->matrix;
203+
204+
/*
205+
* Convert fixed point S31.32 input to format supported by the
206+
* hardware.
207+
*/
208+
for (i = 0; i < 9; i++) {
209+
u64 abs_coeff = ((1ULL << 63) - 1) & input[i];
210+
211+
/*
212+
* Clamp input value to min/max supported by
213+
* hardware.
214+
*/
215+
abs_coeff = clamp_val(abs_coeff, 0, CTM_COEFF_4_0 - 1);
216+
217+
coeffs[i] = 0;
218+
219+
/* sign bit */
220+
if (CTM_COEFF_NEGATIVE(input[i]))
221+
coeffs[i] |= 1 << 15;
222+
223+
if (abs_coeff < CTM_COEFF_0_125)
224+
coeffs[i] |= (3 << 12) |
225+
ILK_CSC_COEFF_FP(abs_coeff, 12);
226+
else if (abs_coeff < CTM_COEFF_0_25)
227+
coeffs[i] |= (2 << 12) |
228+
ILK_CSC_COEFF_FP(abs_coeff, 11);
229+
else if (abs_coeff < CTM_COEFF_0_5)
230+
coeffs[i] |= (1 << 12) |
231+
ILK_CSC_COEFF_FP(abs_coeff, 10);
232+
else if (abs_coeff < CTM_COEFF_1_0)
233+
coeffs[i] |= ILK_CSC_COEFF_FP(abs_coeff, 9);
234+
else if (abs_coeff < CTM_COEFF_2_0)
235+
coeffs[i] |= (7 << 12) |
236+
ILK_CSC_COEFF_FP(abs_coeff, 8);
237+
else
238+
coeffs[i] |= (6 << 12) |
239+
ILK_CSC_COEFF_FP(abs_coeff, 7);
240+
}
241+
}
242+
191243
static void ilk_load_csc_matrix(const struct intel_crtc_state *crtc_state)
192244
{
193245
struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
@@ -218,50 +270,7 @@ static void ilk_load_csc_matrix(const struct intel_crtc_state *crtc_state)
218270
}
219271

220272
if (crtc_state->base.ctm) {
221-
struct drm_color_ctm *ctm = crtc_state->base.ctm->data;
222-
const u64 *input;
223-
u64 temp[9];
224-
225-
if (limited_color_range)
226-
input = ctm_mult_by_limited(temp, ctm->matrix);
227-
else
228-
input = ctm->matrix;
229-
230-
/*
231-
* Convert fixed point S31.32 input to format supported by the
232-
* hardware.
233-
*/
234-
for (i = 0; i < ARRAY_SIZE(coeffs); i++) {
235-
u64 abs_coeff = ((1ULL << 63) - 1) & input[i];
236-
237-
/*
238-
* Clamp input value to min/max supported by
239-
* hardware.
240-
*/
241-
abs_coeff = clamp_val(abs_coeff, 0, CTM_COEFF_4_0 - 1);
242-
243-
/* sign bit */
244-
if (CTM_COEFF_NEGATIVE(input[i]))
245-
coeffs[i] |= 1 << 15;
246-
247-
if (abs_coeff < CTM_COEFF_0_125)
248-
coeffs[i] |= (3 << 12) |
249-
ILK_CSC_COEFF_FP(abs_coeff, 12);
250-
else if (abs_coeff < CTM_COEFF_0_25)
251-
coeffs[i] |= (2 << 12) |
252-
ILK_CSC_COEFF_FP(abs_coeff, 11);
253-
else if (abs_coeff < CTM_COEFF_0_5)
254-
coeffs[i] |= (1 << 12) |
255-
ILK_CSC_COEFF_FP(abs_coeff, 10);
256-
else if (abs_coeff < CTM_COEFF_1_0)
257-
coeffs[i] |= ILK_CSC_COEFF_FP(abs_coeff, 9);
258-
else if (abs_coeff < CTM_COEFF_2_0)
259-
coeffs[i] |= (7 << 12) |
260-
ILK_CSC_COEFF_FP(abs_coeff, 8);
261-
else
262-
coeffs[i] |= (6 << 12) |
263-
ILK_CSC_COEFF_FP(abs_coeff, 7);
264-
}
273+
ilk_csc_convert_ctm(crtc_state, coeffs);
265274
} else {
266275
/*
267276
* Load an identity matrix if no coefficients are provided.

0 commit comments

Comments
 (0)