2 * Copyright 2016 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include "dm_services.h"
28 #include "core_types.h"
30 #include "reg_helper.h"
31 #include "dcn10_dpp.h"
32 #include "basics/conversion.h"
36 #define HORZ_MAX_TAPS 8
37 #define VERT_MAX_TAPS 8
39 #define BLACK_OFFSET_RGB_Y 0x0
40 #define BLACK_OFFSET_CBCR 0x8000
49 #define FN(reg_name, field_name) \
50 dpp->tf_shift->field_name, dpp->tf_mask->field_name
52 enum dcn10_coef_filter_type_sel
{
53 SCL_COEF_LUMA_VERT_FILTER
= 0,
54 SCL_COEF_LUMA_HORZ_FILTER
= 1,
55 SCL_COEF_CHROMA_VERT_FILTER
= 2,
56 SCL_COEF_CHROMA_HORZ_FILTER
= 3,
57 SCL_COEF_ALPHA_VERT_FILTER
= 4,
58 SCL_COEF_ALPHA_HORZ_FILTER
= 5
61 enum dscl_autocal_mode
{
64 /* Autocal calculate the scaling ratio and initial phase and the
65 * DSCL_MODE_SEL must be set to 1
67 AUTOCAL_MODE_AUTOSCALE
= 1,
68 /* Autocal perform auto centering without replication and the
69 * DSCL_MODE_SEL must be set to 0
71 AUTOCAL_MODE_AUTOCENTER
= 2,
72 /* Autocal perform auto centering and auto replication and the
73 * DSCL_MODE_SEL must be set to 0
75 AUTOCAL_MODE_AUTOREPLICATE
= 3
79 DSCL_MODE_SCALING_444_BYPASS
= 0,
80 DSCL_MODE_SCALING_444_RGB_ENABLE
= 1,
81 DSCL_MODE_SCALING_444_YCBCR_ENABLE
= 2,
82 DSCL_MODE_SCALING_420_YCBCR_ENABLE
= 3,
83 DSCL_MODE_SCALING_420_LUMA_BYPASS
= 4,
84 DSCL_MODE_SCALING_420_CHROMA_BYPASS
= 5,
85 DSCL_MODE_DSCL_BYPASS
= 6
88 static void dpp1_dscl_set_overscan(
89 struct dcn10_dpp
*dpp
,
90 const struct scaler_data
*data
)
92 uint32_t left
= data
->recout
.x
;
93 uint32_t top
= data
->recout
.y
;
95 int right
= data
->h_active
- data
->recout
.x
- data
->recout
.width
;
96 int bottom
= data
->v_active
- data
->recout
.y
- data
->recout
.height
;
107 REG_SET_2(DSCL_EXT_OVERSCAN_LEFT_RIGHT
, 0,
108 EXT_OVERSCAN_LEFT
, left
,
109 EXT_OVERSCAN_RIGHT
, right
);
111 REG_SET_2(DSCL_EXT_OVERSCAN_TOP_BOTTOM
, 0,
112 EXT_OVERSCAN_BOTTOM
, bottom
,
113 EXT_OVERSCAN_TOP
, top
);
116 static void dpp1_dscl_set_otg_blank(
117 struct dcn10_dpp
*dpp
, const struct scaler_data
*data
)
119 uint32_t h_blank_start
= data
->h_active
;
120 uint32_t h_blank_end
= 0;
121 uint32_t v_blank_start
= data
->v_active
;
122 uint32_t v_blank_end
= 0;
124 REG_SET_2(OTG_H_BLANK
, 0,
125 OTG_H_BLANK_START
, h_blank_start
,
126 OTG_H_BLANK_END
, h_blank_end
);
128 REG_SET_2(OTG_V_BLANK
, 0,
129 OTG_V_BLANK_START
, v_blank_start
,
130 OTG_V_BLANK_END
, v_blank_end
);
133 static int dpp1_dscl_get_pixel_depth_val(enum lb_pixel_depth depth
)
135 if (depth
== LB_PIXEL_DEPTH_30BPP
)
136 return 0; /* 10 bpc */
137 else if (depth
== LB_PIXEL_DEPTH_24BPP
)
138 return 1; /* 8 bpc */
139 else if (depth
== LB_PIXEL_DEPTH_18BPP
)
140 return 2; /* 6 bpc */
141 else if (depth
== LB_PIXEL_DEPTH_36BPP
)
142 return 3; /* 12 bpc */
145 return -1; /* Unsupported */
149 static bool dpp1_dscl_is_video_format(enum pixel_format format
)
151 if (format
>= PIXEL_FORMAT_VIDEO_BEGIN
152 && format
<= PIXEL_FORMAT_VIDEO_END
)
158 static bool dpp1_dscl_is_420_format(enum pixel_format format
)
160 if (format
== PIXEL_FORMAT_420BPP8
||
161 format
== PIXEL_FORMAT_420BPP10
)
167 static enum dscl_mode_sel
dpp1_dscl_get_dscl_mode(
168 struct dpp
*dpp_base
,
169 const struct scaler_data
*data
,
170 bool dbg_always_scale
)
172 const long long one
= dc_fixpt_one
.value
;
174 if (dpp_base
->caps
->dscl_data_proc_format
== DSCL_DATA_PRCESSING_FIXED_FORMAT
) {
175 /* DSCL is processing data in fixed format */
176 if (data
->format
== PIXEL_FORMAT_FP16
)
177 return DSCL_MODE_DSCL_BYPASS
;
180 if (data
->ratios
.horz
.value
== one
181 && data
->ratios
.vert
.value
== one
182 && data
->ratios
.horz_c
.value
== one
183 && data
->ratios
.vert_c
.value
== one
184 && !dbg_always_scale
)
185 return DSCL_MODE_SCALING_444_BYPASS
;
187 if (!dpp1_dscl_is_420_format(data
->format
)) {
188 if (dpp1_dscl_is_video_format(data
->format
))
189 return DSCL_MODE_SCALING_444_YCBCR_ENABLE
;
191 return DSCL_MODE_SCALING_444_RGB_ENABLE
;
193 if (data
->ratios
.horz
.value
== one
&& data
->ratios
.vert
.value
== one
)
194 return DSCL_MODE_SCALING_420_LUMA_BYPASS
;
195 if (data
->ratios
.horz_c
.value
== one
&& data
->ratios
.vert_c
.value
== one
)
196 return DSCL_MODE_SCALING_420_CHROMA_BYPASS
;
198 return DSCL_MODE_SCALING_420_YCBCR_ENABLE
;
201 static void dpp1_dscl_set_lb(
202 struct dcn10_dpp
*dpp
,
203 const struct line_buffer_params
*lb_params
,
204 enum lb_memory_config mem_size_config
)
207 if (dpp
->base
.caps
->dscl_data_proc_format
== DSCL_DATA_PRCESSING_FIXED_FORMAT
) {
208 /* DSCL caps: pixel data processed in fixed format */
209 uint32_t pixel_depth
= dpp1_dscl_get_pixel_depth_val(lb_params
->depth
);
210 uint32_t dyn_pix_depth
= lb_params
->dynamic_pixel_depth
;
212 REG_SET_7(LB_DATA_FORMAT
, 0,
213 PIXEL_DEPTH
, pixel_depth
, /* Pixel depth stored in LB */
214 PIXEL_EXPAN_MODE
, lb_params
->pixel_expan_mode
, /* Pixel expansion mode */
215 PIXEL_REDUCE_MODE
, 1, /* Pixel reduction mode: Rounding */
216 DYNAMIC_PIXEL_DEPTH
, dyn_pix_depth
, /* Dynamic expansion pixel depth */
217 DITHER_EN
, 0, /* Dithering enable: Disabled */
218 INTERLEAVE_EN
, lb_params
->interleave_en
, /* Interleave source enable */
219 LB_DATA_FORMAT__ALPHA_EN
, lb_params
->alpha_en
); /* Alpha enable */
222 /* DSCL caps: pixel data processed in float format */
223 REG_SET_2(LB_DATA_FORMAT
, 0,
224 INTERLEAVE_EN
, lb_params
->interleave_en
, /* Interleave source enable */
225 LB_DATA_FORMAT__ALPHA_EN
, lb_params
->alpha_en
); /* Alpha enable */
228 REG_SET_2(LB_MEMORY_CTRL
, 0,
229 MEMORY_CONFIG
, mem_size_config
,
230 LB_MAX_PARTITIONS
, 63);
233 static const uint16_t *dpp1_dscl_get_filter_coeffs_64p(int taps
, struct fixed31_32 ratio
)
236 return get_filter_8tap_64p(ratio
);
238 return get_filter_7tap_64p(ratio
);
240 return get_filter_6tap_64p(ratio
);
242 return get_filter_5tap_64p(ratio
);
244 return get_filter_4tap_64p(ratio
);
246 return get_filter_3tap_64p(ratio
);
248 return get_filter_2tap_64p();
252 /* should never happen, bug */
258 static void dpp1_dscl_set_scaler_filter(
259 struct dcn10_dpp
*dpp
,
261 enum dcn10_coef_filter_type_sel filter_type
,
262 const uint16_t *filter
)
264 const int tap_pairs
= (taps
+ 1) / 2;
267 uint16_t odd_coef
, even_coef
;
269 REG_SET_3(SCL_COEF_RAM_TAP_SELECT
, 0,
270 SCL_COEF_RAM_TAP_PAIR_IDX
, 0,
271 SCL_COEF_RAM_PHASE
, 0,
272 SCL_COEF_RAM_FILTER_TYPE
, filter_type
);
274 for (phase
= 0; phase
< (NUM_PHASES
/ 2 + 1); phase
++) {
275 for (pair
= 0; pair
< tap_pairs
; pair
++) {
276 even_coef
= filter
[phase
* taps
+ 2 * pair
];
277 if ((pair
* 2 + 1) < taps
)
278 odd_coef
= filter
[phase
* taps
+ 2 * pair
+ 1];
282 REG_SET_4(SCL_COEF_RAM_TAP_DATA
, 0,
283 /* Even tap coefficient (bits 1:0 fixed to 0) */
284 SCL_COEF_RAM_EVEN_TAP_COEF
, even_coef
,
285 /* Write/read control for even coefficient */
286 SCL_COEF_RAM_EVEN_TAP_COEF_EN
, 1,
287 /* Odd tap coefficient (bits 1:0 fixed to 0) */
288 SCL_COEF_RAM_ODD_TAP_COEF
, odd_coef
,
289 /* Write/read control for odd coefficient */
290 SCL_COEF_RAM_ODD_TAP_COEF_EN
, 1);
296 static void dpp1_dscl_set_scl_filter(
297 struct dcn10_dpp
*dpp
,
298 const struct scaler_data
*scl_data
,
299 bool chroma_coef_mode
)
301 bool h_2tap_hardcode_coef_en
= false;
302 bool v_2tap_hardcode_coef_en
= false;
303 bool h_2tap_sharp_en
= false;
304 bool v_2tap_sharp_en
= false;
305 uint32_t h_2tap_sharp_factor
= scl_data
->sharpness
.horz
;
306 uint32_t v_2tap_sharp_factor
= scl_data
->sharpness
.vert
;
307 bool coef_ram_current
;
308 const uint16_t *filter_h
= NULL
;
309 const uint16_t *filter_v
= NULL
;
310 const uint16_t *filter_h_c
= NULL
;
311 const uint16_t *filter_v_c
= NULL
;
313 h_2tap_hardcode_coef_en
= scl_data
->taps
.h_taps
< 3
314 && scl_data
->taps
.h_taps_c
< 3
315 && (scl_data
->taps
.h_taps
> 1 && scl_data
->taps
.h_taps_c
> 1);
316 v_2tap_hardcode_coef_en
= scl_data
->taps
.v_taps
< 3
317 && scl_data
->taps
.v_taps_c
< 3
318 && (scl_data
->taps
.v_taps
> 1 && scl_data
->taps
.v_taps_c
> 1);
320 h_2tap_sharp_en
= h_2tap_hardcode_coef_en
&& h_2tap_sharp_factor
!= 0;
321 v_2tap_sharp_en
= v_2tap_hardcode_coef_en
&& v_2tap_sharp_factor
!= 0;
323 REG_UPDATE_6(DSCL_2TAP_CONTROL
,
324 SCL_H_2TAP_HARDCODE_COEF_EN
, h_2tap_hardcode_coef_en
,
325 SCL_H_2TAP_SHARP_EN
, h_2tap_sharp_en
,
326 SCL_H_2TAP_SHARP_FACTOR
, h_2tap_sharp_factor
,
327 SCL_V_2TAP_HARDCODE_COEF_EN
, v_2tap_hardcode_coef_en
,
328 SCL_V_2TAP_SHARP_EN
, v_2tap_sharp_en
,
329 SCL_V_2TAP_SHARP_FACTOR
, v_2tap_sharp_factor
);
331 if (!v_2tap_hardcode_coef_en
|| !h_2tap_hardcode_coef_en
) {
332 bool filter_updated
= false;
334 filter_h
= dpp1_dscl_get_filter_coeffs_64p(
335 scl_data
->taps
.h_taps
, scl_data
->ratios
.horz
);
336 filter_v
= dpp1_dscl_get_filter_coeffs_64p(
337 scl_data
->taps
.v_taps
, scl_data
->ratios
.vert
);
339 filter_updated
= (filter_h
&& (filter_h
!= dpp
->filter_h
))
340 || (filter_v
&& (filter_v
!= dpp
->filter_v
));
342 if (chroma_coef_mode
) {
343 filter_h_c
= dpp1_dscl_get_filter_coeffs_64p(
344 scl_data
->taps
.h_taps_c
, scl_data
->ratios
.horz_c
);
345 filter_v_c
= dpp1_dscl_get_filter_coeffs_64p(
346 scl_data
->taps
.v_taps_c
, scl_data
->ratios
.vert_c
);
347 filter_updated
= filter_updated
|| (filter_h_c
&& (filter_h_c
!= dpp
->filter_h_c
))
348 || (filter_v_c
&& (filter_v_c
!= dpp
->filter_v_c
));
351 if (filter_updated
) {
352 uint32_t scl_mode
= REG_READ(SCL_MODE
);
354 if (!h_2tap_hardcode_coef_en
&& filter_h
) {
355 dpp1_dscl_set_scaler_filter(
356 dpp
, scl_data
->taps
.h_taps
,
357 SCL_COEF_LUMA_HORZ_FILTER
, filter_h
);
359 dpp
->filter_h
= filter_h
;
360 if (!v_2tap_hardcode_coef_en
&& filter_v
) {
361 dpp1_dscl_set_scaler_filter(
362 dpp
, scl_data
->taps
.v_taps
,
363 SCL_COEF_LUMA_VERT_FILTER
, filter_v
);
365 dpp
->filter_v
= filter_v
;
366 if (chroma_coef_mode
) {
367 if (!h_2tap_hardcode_coef_en
&& filter_h_c
) {
368 dpp1_dscl_set_scaler_filter(
369 dpp
, scl_data
->taps
.h_taps_c
,
370 SCL_COEF_CHROMA_HORZ_FILTER
, filter_h_c
);
372 if (!v_2tap_hardcode_coef_en
&& filter_v_c
) {
373 dpp1_dscl_set_scaler_filter(
374 dpp
, scl_data
->taps
.v_taps_c
,
375 SCL_COEF_CHROMA_VERT_FILTER
, filter_v_c
);
378 dpp
->filter_h_c
= filter_h_c
;
379 dpp
->filter_v_c
= filter_v_c
;
381 coef_ram_current
= get_reg_field_value_ex(
382 scl_mode
, dpp
->tf_mask
->SCL_COEF_RAM_SELECT_CURRENT
,
383 dpp
->tf_shift
->SCL_COEF_RAM_SELECT_CURRENT
);
385 /* Swap coefficient RAM and set chroma coefficient mode */
386 REG_SET_2(SCL_MODE
, scl_mode
,
387 SCL_COEF_RAM_SELECT
, !coef_ram_current
,
388 SCL_CHROMA_COEF_MODE
, chroma_coef_mode
);
393 static int dpp1_dscl_get_lb_depth_bpc(enum lb_pixel_depth depth
)
395 if (depth
== LB_PIXEL_DEPTH_30BPP
)
397 else if (depth
== LB_PIXEL_DEPTH_24BPP
)
399 else if (depth
== LB_PIXEL_DEPTH_18BPP
)
401 else if (depth
== LB_PIXEL_DEPTH_36BPP
)
405 return -1; /* Unsupported */
409 void dpp1_dscl_calc_lb_num_partitions(
410 const struct scaler_data
*scl_data
,
411 enum lb_memory_config lb_config
,
415 int lb_memory_size
, lb_memory_size_c
, lb_memory_size_a
, num_partitions_a
,
416 lb_bpc
, memory_line_size_y
, memory_line_size_c
, memory_line_size_a
;
418 int line_size
= scl_data
->viewport
.width
< scl_data
->recout
.width
?
419 scl_data
->viewport
.width
: scl_data
->recout
.width
;
420 int line_size_c
= scl_data
->viewport_c
.width
< scl_data
->recout
.width
?
421 scl_data
->viewport_c
.width
: scl_data
->recout
.width
;
426 if (line_size_c
== 0)
430 lb_bpc
= dpp1_dscl_get_lb_depth_bpc(scl_data
->lb_params
.depth
);
431 memory_line_size_y
= (line_size
* lb_bpc
+ 71) / 72; /* +71 to ceil */
432 memory_line_size_c
= (line_size_c
* lb_bpc
+ 71) / 72; /* +71 to ceil */
433 memory_line_size_a
= (line_size
+ 5) / 6; /* +5 to ceil */
435 if (lb_config
== LB_MEMORY_CONFIG_1
) {
436 lb_memory_size
= 816;
437 lb_memory_size_c
= 816;
438 lb_memory_size_a
= 984;
439 } else if (lb_config
== LB_MEMORY_CONFIG_2
) {
440 lb_memory_size
= 1088;
441 lb_memory_size_c
= 1088;
442 lb_memory_size_a
= 1312;
443 } else if (lb_config
== LB_MEMORY_CONFIG_3
) {
444 /* 420 mode: using 3rd mem from Y, Cr and Cb */
445 lb_memory_size
= 816 + 1088 + 848 + 848 + 848;
446 lb_memory_size_c
= 816 + 1088;
447 lb_memory_size_a
= 984 + 1312 + 456;
449 lb_memory_size
= 816 + 1088 + 848;
450 lb_memory_size_c
= 816 + 1088 + 848;
451 lb_memory_size_a
= 984 + 1312 + 456;
453 *num_part_y
= lb_memory_size
/ memory_line_size_y
;
454 *num_part_c
= lb_memory_size_c
/ memory_line_size_c
;
455 num_partitions_a
= lb_memory_size_a
/ memory_line_size_a
;
457 if (scl_data
->lb_params
.alpha_en
458 && (num_partitions_a
< *num_part_y
))
459 *num_part_y
= num_partitions_a
;
461 if (*num_part_y
> 64)
463 if (*num_part_c
> 64)
468 bool dpp1_dscl_is_lb_conf_valid(int ceil_vratio
, int num_partitions
, int vtaps
)
471 return vtaps
<= (num_partitions
- ceil_vratio
+ 2);
473 return vtaps
<= num_partitions
;
476 /*find first match configuration which meets the min required lb size*/
477 static enum lb_memory_config
dpp1_dscl_find_lb_memory_config(struct dcn10_dpp
*dpp
,
478 const struct scaler_data
*scl_data
)
480 int num_part_y
, num_part_c
;
481 int vtaps
= scl_data
->taps
.v_taps
;
482 int vtaps_c
= scl_data
->taps
.v_taps_c
;
483 int ceil_vratio
= dc_fixpt_ceil(scl_data
->ratios
.vert
);
484 int ceil_vratio_c
= dc_fixpt_ceil(scl_data
->ratios
.vert_c
);
485 enum lb_memory_config mem_cfg
= LB_MEMORY_CONFIG_0
;
487 if (dpp
->base
.ctx
->dc
->debug
.use_max_lb
)
490 dpp
->base
.caps
->dscl_calc_lb_num_partitions(
491 scl_data
, LB_MEMORY_CONFIG_1
, &num_part_y
, &num_part_c
);
493 if (dpp1_dscl_is_lb_conf_valid(ceil_vratio
, num_part_y
, vtaps
)
494 && dpp1_dscl_is_lb_conf_valid(ceil_vratio_c
, num_part_c
, vtaps_c
))
495 return LB_MEMORY_CONFIG_1
;
497 dpp
->base
.caps
->dscl_calc_lb_num_partitions(
498 scl_data
, LB_MEMORY_CONFIG_2
, &num_part_y
, &num_part_c
);
500 if (dpp1_dscl_is_lb_conf_valid(ceil_vratio
, num_part_y
, vtaps
)
501 && dpp1_dscl_is_lb_conf_valid(ceil_vratio_c
, num_part_c
, vtaps_c
))
502 return LB_MEMORY_CONFIG_2
;
504 if (scl_data
->format
== PIXEL_FORMAT_420BPP8
505 || scl_data
->format
== PIXEL_FORMAT_420BPP10
) {
506 dpp
->base
.caps
->dscl_calc_lb_num_partitions(
507 scl_data
, LB_MEMORY_CONFIG_3
, &num_part_y
, &num_part_c
);
509 if (dpp1_dscl_is_lb_conf_valid(ceil_vratio
, num_part_y
, vtaps
)
510 && dpp1_dscl_is_lb_conf_valid(ceil_vratio_c
, num_part_c
, vtaps_c
))
511 return LB_MEMORY_CONFIG_3
;
514 dpp
->base
.caps
->dscl_calc_lb_num_partitions(
515 scl_data
, LB_MEMORY_CONFIG_0
, &num_part_y
, &num_part_c
);
517 /*Ensure we can support the requested number of vtaps*/
518 ASSERT(dpp1_dscl_is_lb_conf_valid(ceil_vratio
, num_part_y
, vtaps
)
519 && dpp1_dscl_is_lb_conf_valid(ceil_vratio_c
, num_part_c
, vtaps_c
));
521 return LB_MEMORY_CONFIG_0
;
524 void dpp1_dscl_set_scaler_auto_scale(
525 struct dpp
*dpp_base
,
526 const struct scaler_data
*scl_data
)
528 enum lb_memory_config lb_config
;
529 struct dcn10_dpp
*dpp
= TO_DCN10_DPP(dpp_base
);
530 enum dscl_mode_sel dscl_mode
= dpp1_dscl_get_dscl_mode(
531 dpp_base
, scl_data
, dpp_base
->ctx
->dc
->debug
.always_scale
);
532 bool ycbcr
= scl_data
->format
>= PIXEL_FORMAT_VIDEO_BEGIN
533 && scl_data
->format
<= PIXEL_FORMAT_VIDEO_END
;
535 dpp1_dscl_set_overscan(dpp
, scl_data
);
537 dpp1_dscl_set_otg_blank(dpp
, scl_data
);
539 REG_UPDATE(SCL_MODE
, DSCL_MODE
, dscl_mode
);
541 if (dscl_mode
== DSCL_MODE_DSCL_BYPASS
)
544 lb_config
= dpp1_dscl_find_lb_memory_config(dpp
, scl_data
);
545 dpp1_dscl_set_lb(dpp
, &scl_data
->lb_params
, lb_config
);
547 if (dscl_mode
== DSCL_MODE_SCALING_444_BYPASS
)
551 REG_SET_3(DSCL_AUTOCAL
, 0,
552 AUTOCAL_MODE
, AUTOCAL_MODE_AUTOSCALE
,
558 REG_SET_2(SCL_BLACK_OFFSET
, 0,
559 SCL_BLACK_OFFSET_RGB_Y
, BLACK_OFFSET_RGB_Y
,
560 SCL_BLACK_OFFSET_CBCR
, BLACK_OFFSET_CBCR
);
563 REG_SET_2(SCL_BLACK_OFFSET
, 0,
564 SCL_BLACK_OFFSET_RGB_Y
, BLACK_OFFSET_RGB_Y
,
565 SCL_BLACK_OFFSET_CBCR
, BLACK_OFFSET_RGB_Y
);
567 REG_SET_4(SCL_TAP_CONTROL
, 0,
568 SCL_V_NUM_TAPS
, scl_data
->taps
.v_taps
- 1,
569 SCL_H_NUM_TAPS
, scl_data
->taps
.h_taps
- 1,
570 SCL_V_NUM_TAPS_C
, scl_data
->taps
.v_taps_c
- 1,
571 SCL_H_NUM_TAPS_C
, scl_data
->taps
.h_taps_c
- 1);
573 dpp1_dscl_set_scl_filter(dpp
, scl_data
, ycbcr
);
577 static void dpp1_dscl_set_manual_ratio_init(
578 struct dcn10_dpp
*dpp
, const struct scaler_data
*data
)
580 uint32_t init_frac
= 0;
581 uint32_t init_int
= 0;
583 REG_SET(SCL_HORZ_FILTER_SCALE_RATIO
, 0,
584 SCL_H_SCALE_RATIO
, dc_fixpt_u3d19(data
->ratios
.horz
) << 5);
586 REG_SET(SCL_VERT_FILTER_SCALE_RATIO
, 0,
587 SCL_V_SCALE_RATIO
, dc_fixpt_u3d19(data
->ratios
.vert
) << 5);
589 REG_SET(SCL_HORZ_FILTER_SCALE_RATIO_C
, 0,
590 SCL_H_SCALE_RATIO_C
, dc_fixpt_u3d19(data
->ratios
.horz_c
) << 5);
592 REG_SET(SCL_VERT_FILTER_SCALE_RATIO_C
, 0,
593 SCL_V_SCALE_RATIO_C
, dc_fixpt_u3d19(data
->ratios
.vert_c
) << 5);
596 * 0.24 format for fraction, first five bits zeroed
598 init_frac
= dc_fixpt_u0d19(data
->inits
.h
) << 5;
599 init_int
= dc_fixpt_floor(data
->inits
.h
);
600 REG_SET_2(SCL_HORZ_FILTER_INIT
, 0,
601 SCL_H_INIT_FRAC
, init_frac
,
602 SCL_H_INIT_INT
, init_int
);
604 init_frac
= dc_fixpt_u0d19(data
->inits
.h_c
) << 5;
605 init_int
= dc_fixpt_floor(data
->inits
.h_c
);
606 REG_SET_2(SCL_HORZ_FILTER_INIT_C
, 0,
607 SCL_H_INIT_FRAC_C
, init_frac
,
608 SCL_H_INIT_INT_C
, init_int
);
610 init_frac
= dc_fixpt_u0d19(data
->inits
.v
) << 5;
611 init_int
= dc_fixpt_floor(data
->inits
.v
);
612 REG_SET_2(SCL_VERT_FILTER_INIT
, 0,
613 SCL_V_INIT_FRAC
, init_frac
,
614 SCL_V_INIT_INT
, init_int
);
616 if (REG(SCL_VERT_FILTER_INIT_BOT
)) {
617 init_frac
= dc_fixpt_u0d19(data
->inits
.v_bot
) << 5;
618 init_int
= dc_fixpt_floor(data
->inits
.v_bot
);
619 REG_SET_2(SCL_VERT_FILTER_INIT_BOT
, 0,
620 SCL_V_INIT_FRAC_BOT
, init_frac
,
621 SCL_V_INIT_INT_BOT
, init_int
);
624 init_frac
= dc_fixpt_u0d19(data
->inits
.v_c
) << 5;
625 init_int
= dc_fixpt_floor(data
->inits
.v_c
);
626 REG_SET_2(SCL_VERT_FILTER_INIT_C
, 0,
627 SCL_V_INIT_FRAC_C
, init_frac
,
628 SCL_V_INIT_INT_C
, init_int
);
630 if (REG(SCL_VERT_FILTER_INIT_BOT_C
)) {
631 init_frac
= dc_fixpt_u0d19(data
->inits
.v_c_bot
) << 5;
632 init_int
= dc_fixpt_floor(data
->inits
.v_c_bot
);
633 REG_SET_2(SCL_VERT_FILTER_INIT_BOT_C
, 0,
634 SCL_V_INIT_FRAC_BOT_C
, init_frac
,
635 SCL_V_INIT_INT_BOT_C
, init_int
);
641 static void dpp1_dscl_set_recout(
642 struct dcn10_dpp
*dpp
, const struct rect
*recout
)
644 int visual_confirm_on
= 0;
645 if (dpp
->base
.ctx
->dc
->debug
.visual_confirm
!= VISUAL_CONFIRM_DISABLE
)
646 visual_confirm_on
= 1;
648 REG_SET_2(RECOUT_START
, 0,
649 /* First pixel of RECOUT */
650 RECOUT_START_X
, recout
->x
,
651 /* First line of RECOUT */
652 RECOUT_START_Y
, recout
->y
);
654 REG_SET_2(RECOUT_SIZE
, 0,
655 /* Number of RECOUT horizontal pixels */
656 RECOUT_WIDTH
, recout
->width
,
657 /* Number of RECOUT vertical lines */
658 RECOUT_HEIGHT
, recout
->height
659 - visual_confirm_on
* 4 * (dpp
->base
.inst
+ 1));
662 /* Main function to program scaler and line buffer in manual scaling mode */
663 void dpp1_dscl_set_scaler_manual_scale(
664 struct dpp
*dpp_base
,
665 const struct scaler_data
*scl_data
)
667 enum lb_memory_config lb_config
;
668 struct dcn10_dpp
*dpp
= TO_DCN10_DPP(dpp_base
);
669 enum dscl_mode_sel dscl_mode
= dpp1_dscl_get_dscl_mode(
670 dpp_base
, scl_data
, dpp_base
->ctx
->dc
->debug
.always_scale
);
671 bool ycbcr
= scl_data
->format
>= PIXEL_FORMAT_VIDEO_BEGIN
672 && scl_data
->format
<= PIXEL_FORMAT_VIDEO_END
;
674 if (memcmp(&dpp
->scl_data
, scl_data
, sizeof(*scl_data
)) == 0)
679 dpp
->scl_data
= *scl_data
;
682 REG_SET_3(DSCL_AUTOCAL
, 0,
683 AUTOCAL_MODE
, AUTOCAL_MODE_OFF
,
688 dpp1_dscl_set_recout(dpp
, &scl_data
->recout
);
691 REG_SET_2(MPC_SIZE
, 0,
692 /* Number of horizontal pixels of MPC */
693 MPC_WIDTH
, scl_data
->h_active
,
694 /* Number of vertical lines of MPC */
695 MPC_HEIGHT
, scl_data
->v_active
);
698 REG_UPDATE(SCL_MODE
, DSCL_MODE
, dscl_mode
);
700 if (dscl_mode
== DSCL_MODE_DSCL_BYPASS
)
704 lb_config
= dpp1_dscl_find_lb_memory_config(dpp
, scl_data
);
705 dpp1_dscl_set_lb(dpp
, &scl_data
->lb_params
, lb_config
);
707 if (dscl_mode
== DSCL_MODE_SCALING_444_BYPASS
)
711 if (REG(SCL_BLACK_OFFSET
)) {
713 REG_SET_2(SCL_BLACK_OFFSET
, 0,
714 SCL_BLACK_OFFSET_RGB_Y
, BLACK_OFFSET_RGB_Y
,
715 SCL_BLACK_OFFSET_CBCR
, BLACK_OFFSET_CBCR
);
718 REG_SET_2(SCL_BLACK_OFFSET
, 0,
719 SCL_BLACK_OFFSET_RGB_Y
, BLACK_OFFSET_RGB_Y
,
720 SCL_BLACK_OFFSET_CBCR
, BLACK_OFFSET_RGB_Y
);
723 /* Manually calculate scale ratio and init values */
724 dpp1_dscl_set_manual_ratio_init(dpp
, scl_data
);
727 REG_SET_4(SCL_TAP_CONTROL
, 0,
728 SCL_V_NUM_TAPS
, scl_data
->taps
.v_taps
- 1,
729 SCL_H_NUM_TAPS
, scl_data
->taps
.h_taps
- 1,
730 SCL_V_NUM_TAPS_C
, scl_data
->taps
.v_taps_c
- 1,
731 SCL_H_NUM_TAPS_C
, scl_data
->taps
.h_taps_c
- 1);
733 dpp1_dscl_set_scl_filter(dpp
, scl_data
, ycbcr
);