1 // SPDX-License-Identifier: MIT 2 // 3 // Copyright 2024 Advanced Micro Devices, Inc. 4 5 #include "dc_spl.h" 6 #include "dc_spl_scl_filters.h" 7 #include "dc_spl_scl_easf_filters.h" 8 #include "dc_spl_isharp_filters.h" 9 #include "spl_debug.h" 10 11 #define IDENTITY_RATIO(ratio) (spl_fixpt_u2d19(ratio) == (1 << 19)) 12 #define MIN_VIEWPORT_SIZE 12 13 14 static struct spl_rect intersect_rec(const struct spl_rect *r0, const struct spl_rect *r1) 15 { 16 struct spl_rect rec; 17 int r0_x_end = r0->x + r0->width; 18 int r1_x_end = r1->x + r1->width; 19 int r0_y_end = r0->y + r0->height; 20 int r1_y_end = r1->y + r1->height; 21 22 rec.x = r0->x > r1->x ? r0->x : r1->x; 23 rec.width = r0_x_end > r1_x_end ? r1_x_end - rec.x : r0_x_end - rec.x; 24 rec.y = r0->y > r1->y ? r0->y : r1->y; 25 rec.height = r0_y_end > r1_y_end ? r1_y_end - rec.y : r0_y_end - rec.y; 26 27 /* in case that there is no intersection */ 28 if (rec.width < 0 || rec.height < 0) 29 memset(&rec, 0, sizeof(rec)); 30 31 return rec; 32 } 33 34 static struct spl_rect shift_rec(const struct spl_rect *rec_in, int x, int y) 35 { 36 struct spl_rect rec_out = *rec_in; 37 38 rec_out.x += x; 39 rec_out.y += y; 40 41 return rec_out; 42 } 43 44 static struct spl_rect calculate_plane_rec_in_timing_active( 45 struct spl_in *spl_in, 46 const struct spl_rect *rec_in) 47 { 48 /* 49 * The following diagram shows an example where we map a 1920x1200 50 * desktop to a 2560x1440 timing with a plane rect in the middle 51 * of the screen. To map a plane rect from Stream Source to Timing 52 * Active space, we first multiply stream scaling ratios (i.e 2304/1920 53 * horizontal and 1440/1200 vertical) to the plane's x and y, then 54 * we add stream destination offsets (i.e 128 horizontal, 0 vertical). 55 * This will give us a plane rect's position in Timing Active. However 56 * we have to remove the fractional. The rule is that we find left/right 57 * and top/bottom positions and round the value to the adjacent integer. 58 * 59 * Stream Source Space 60 * ------------ 61 * __________________________________________________ 62 * |Stream Source (1920 x 1200) ^ | 63 * | y | 64 * | <------- w --------|> | 65 * | __________________V | 66 * |<-- x -->|Plane//////////////| ^ | 67 * | |(pre scale)////////| | | 68 * | |///////////////////| | | 69 * | |///////////////////| h | 70 * | |///////////////////| | | 71 * | |///////////////////| | | 72 * | |///////////////////| V | 73 * | | 74 * | | 75 * |__________________________________________________| 76 * 77 * 78 * Timing Active Space 79 * --------------------------------- 80 * 81 * Timing Active (2560 x 1440) 82 * __________________________________________________ 83 * |*****| Stteam Destination (2304 x 1440) |*****| 84 * |*****| |*****| 85 * |<128>| |*****| 86 * |*****| __________________ |*****| 87 * |*****| |Plane/////////////| |*****| 88 * |*****| |(post scale)//////| |*****| 89 * |*****| |//////////////////| |*****| 90 * |*****| |//////////////////| |*****| 91 * |*****| |//////////////////| |*****| 92 * |*****| |//////////////////| |*****| 93 * |*****| |*****| 94 * |*****| |*****| 95 * |*****| |*****| 96 * |*****|______________________________________|*****| 97 * 98 * So the resulting formulas are shown below: 99 * 100 * recout_x = 128 + round(plane_x * 2304 / 1920) 101 * recout_w = 128 + round((plane_x + plane_w) * 2304 / 1920) - recout_x 102 * recout_y = 0 + round(plane_y * 1440 / 1280) 103 * recout_h = 0 + round((plane_y + plane_h) * 1440 / 1200) - recout_y 104 * 105 * NOTE: fixed point division is not error free. To reduce errors 106 * introduced by fixed point division, we divide only after 107 * multiplication is complete. 108 */ 109 const struct spl_rect *stream_src = &spl_in->basic_out.src_rect; 110 const struct spl_rect *stream_dst = &spl_in->basic_out.dst_rect; 111 struct spl_rect rec_out = {0}; 112 struct spl_fixed31_32 temp; 113 114 115 temp = spl_fixpt_from_fraction(rec_in->x * (long long)stream_dst->width, 116 stream_src->width); 117 rec_out.x = stream_dst->x + spl_fixpt_round(temp); 118 119 temp = spl_fixpt_from_fraction( 120 (rec_in->x + rec_in->width) * (long long)stream_dst->width, 121 stream_src->width); 122 rec_out.width = stream_dst->x + spl_fixpt_round(temp) - rec_out.x; 123 124 temp = spl_fixpt_from_fraction(rec_in->y * (long long)stream_dst->height, 125 stream_src->height); 126 rec_out.y = stream_dst->y + spl_fixpt_round(temp); 127 128 temp = spl_fixpt_from_fraction( 129 (rec_in->y + rec_in->height) * (long long)stream_dst->height, 130 stream_src->height); 131 rec_out.height = stream_dst->y + spl_fixpt_round(temp) - rec_out.y; 132 133 return rec_out; 134 } 135 136 static struct spl_rect calculate_mpc_slice_in_timing_active( 137 struct spl_in *spl_in, 138 struct spl_rect *plane_clip_rec) 139 { 140 int mpc_slice_count = spl_in->basic_in.mpc_combine_h; 141 int mpc_slice_idx = spl_in->basic_in.mpc_combine_v; 142 int epimo = mpc_slice_count - plane_clip_rec->width % mpc_slice_count - 1; 143 struct spl_rect mpc_rec; 144 145 mpc_rec.width = plane_clip_rec->width / mpc_slice_count; 146 mpc_rec.x = plane_clip_rec->x + mpc_rec.width * mpc_slice_idx; 147 mpc_rec.height = plane_clip_rec->height; 148 mpc_rec.y = plane_clip_rec->y; 149 SPL_ASSERT(mpc_slice_count == 1 || 150 spl_in->basic_out.view_format != SPL_VIEW_3D_SIDE_BY_SIDE || 151 mpc_rec.width % 2 == 0); 152 153 /* extra pixels in the division remainder need to go to pipes after 154 * the extra pixel index minus one(epimo) defined here as: 155 */ 156 if (mpc_slice_idx > epimo) { 157 mpc_rec.x += mpc_slice_idx - epimo - 1; 158 mpc_rec.width += 1; 159 } 160 161 if (spl_in->basic_out.view_format == SPL_VIEW_3D_TOP_AND_BOTTOM) { 162 SPL_ASSERT(mpc_rec.height % 2 == 0); 163 mpc_rec.height /= 2; 164 } 165 return mpc_rec; 166 } 167 168 static struct spl_rect calculate_odm_slice_in_timing_active(struct spl_in *spl_in) 169 { 170 int odm_slice_count = spl_in->basic_out.odm_combine_factor; 171 int odm_slice_idx = spl_in->odm_slice_index; 172 bool is_last_odm_slice = (odm_slice_idx + 1) == odm_slice_count; 173 int h_active = spl_in->basic_out.output_size.width; 174 int v_active = spl_in->basic_out.output_size.height; 175 int odm_slice_width; 176 struct spl_rect odm_rec; 177 178 if (spl_in->basic_out.odm_combine_factor > 0) { 179 odm_slice_width = h_active / odm_slice_count; 180 /* 181 * deprecated, caller must pass in odm slice rect i.e OPP input 182 * rect in timing active for the new interface. 183 */ 184 if (spl_in->basic_out.use_two_pixels_per_container && (odm_slice_width % 2)) 185 odm_slice_width++; 186 187 odm_rec.x = odm_slice_width * odm_slice_idx; 188 odm_rec.width = is_last_odm_slice ? 189 /* last slice width is the reminder of h_active */ 190 h_active - odm_slice_width * (odm_slice_count - 1) : 191 /* odm slice width is the floor of h_active / count */ 192 odm_slice_width; 193 odm_rec.y = 0; 194 odm_rec.height = v_active; 195 196 return odm_rec; 197 } 198 199 return spl_in->basic_out.odm_slice_rect; 200 } 201 202 static void spl_calculate_recout(struct spl_in *spl_in, struct spl_scratch *spl_scratch, struct spl_out *spl_out) 203 { 204 /* 205 * A plane clip represents the desired plane size and position in Stream 206 * Source Space. Stream Source is the destination where all planes are 207 * blended (i.e. positioned, scaled and overlaid). It is a canvas where 208 * all planes associated with the current stream are drawn together. 209 * After Stream Source is completed, we will further scale and 210 * reposition the entire canvas of the stream source to Stream 211 * Destination in Timing Active Space. This could be due to display 212 * overscan adjustment where we will need to rescale and reposition all 213 * the planes so they can fit into a TV with overscan or downscale 214 * upscale features such as GPU scaling or VSR. 215 * 216 * This two step blending is a virtual procedure in software. In 217 * hardware there is no such thing as Stream Source. all planes are 218 * blended once in Timing Active Space. Software virtualizes a Stream 219 * Source space to decouple the math complicity so scaling param 220 * calculation focuses on one step at a time. 221 * 222 * In the following two diagrams, user applied 10% overscan adjustment 223 * so the Stream Source needs to be scaled down a little before mapping 224 * to Timing Active Space. As a result the Plane Clip is also scaled 225 * down by the same ratio, Plane Clip position (i.e. x and y) with 226 * respect to Stream Source is also scaled down. To map it in Timing 227 * Active Space additional x and y offsets from Stream Destination are 228 * added to Plane Clip as well. 229 * 230 * Stream Source Space 231 * ------------ 232 * __________________________________________________ 233 * |Stream Source (3840 x 2160) ^ | 234 * | y | 235 * | | | 236 * | __________________V | 237 * |<-- x -->|Plane Clip/////////| | 238 * | |(pre scale)////////| | 239 * | |///////////////////| | 240 * | |///////////////////| | 241 * | |///////////////////| | 242 * | |///////////////////| | 243 * | |///////////////////| | 244 * | | 245 * | | 246 * |__________________________________________________| 247 * 248 * 249 * Timing Active Space (3840 x 2160) 250 * --------------------------------- 251 * 252 * Timing Active 253 * __________________________________________________ 254 * | y_____________________________________________ | 255 * |x |Stream Destination (3456 x 1944) | | 256 * | | | | 257 * | | __________________ | | 258 * | | |Plane Clip////////| | | 259 * | | |(post scale)//////| | | 260 * | | |//////////////////| | | 261 * | | |//////////////////| | | 262 * | | |//////////////////| | | 263 * | | |//////////////////| | | 264 * | | | | 265 * | | | | 266 * | |____________________________________________| | 267 * |__________________________________________________| 268 * 269 * 270 * In Timing Active Space a plane clip could be further sliced into 271 * pieces called MPC slices. Each Pipe Context is responsible for 272 * processing only one MPC slice so the plane processing workload can be 273 * distributed to multiple DPP Pipes. MPC slices could be blended 274 * together to a single ODM slice. Each ODM slice is responsible for 275 * processing a portion of Timing Active divided horizontally so the 276 * output pixel processing workload can be distributed to multiple OPP 277 * pipes. All ODM slices are mapped together in ODM block so all MPC 278 * slices belong to different ODM slices could be pieced together to 279 * form a single image in Timing Active. MPC slices must belong to 280 * single ODM slice. If an MPC slice goes across ODM slice boundary, it 281 * needs to be divided into two MPC slices one for each ODM slice. 282 * 283 * In the following diagram the output pixel processing workload is 284 * divided horizontally into two ODM slices one for each OPP blend tree. 285 * OPP0 blend tree is responsible for processing left half of Timing 286 * Active, while OPP2 blend tree is responsible for processing right 287 * half. 288 * 289 * The plane has two MPC slices. However since the right MPC slice goes 290 * across ODM boundary, two DPP pipes are needed one for each OPP blend 291 * tree. (i.e. DPP1 for OPP0 blend tree and DPP2 for OPP2 blend tree). 292 * 293 * Assuming that we have a Pipe Context associated with OPP0 and DPP1 294 * working on processing the plane in the diagram. We want to know the 295 * width and height of the shaded rectangle and its relative position 296 * with respect to the ODM slice0. This is called the recout of the pipe 297 * context. 298 * 299 * Planes can be at arbitrary size and position and there could be an 300 * arbitrary number of MPC and ODM slices. The algorithm needs to take 301 * all scenarios into account. 302 * 303 * Timing Active Space (3840 x 2160) 304 * --------------------------------- 305 * 306 * Timing Active 307 * __________________________________________________ 308 * |OPP0(ODM slice0)^ |OPP2(ODM slice1) | 309 * | y | | 310 * | | <- w -> | 311 * | _____V________|____ | 312 * | |DPP0 ^ |DPP1 |DPP2| | 313 * |<------ x |-----|->|/////| | | 314 * | | | |/////| | | 315 * | | h |/////| | | 316 * | | | |/////| | | 317 * | |_____V__|/////|____| | 318 * | | | 319 * | | | 320 * | | | 321 * |_________________________|________________________| 322 * 323 * 324 */ 325 struct spl_rect plane_clip; 326 struct spl_rect mpc_slice_of_plane_clip; 327 struct spl_rect odm_slice; 328 struct spl_rect overlapping_area; 329 330 plane_clip = calculate_plane_rec_in_timing_active(spl_in, 331 &spl_in->basic_in.clip_rect); 332 /* guard plane clip from drawing beyond stream dst here */ 333 plane_clip = intersect_rec(&plane_clip, 334 &spl_in->basic_out.dst_rect); 335 mpc_slice_of_plane_clip = calculate_mpc_slice_in_timing_active( 336 spl_in, &plane_clip); 337 odm_slice = calculate_odm_slice_in_timing_active(spl_in); 338 overlapping_area = intersect_rec(&mpc_slice_of_plane_clip, &odm_slice); 339 340 if (overlapping_area.height > 0 && 341 overlapping_area.width > 0) { 342 /* shift the overlapping area so it is with respect to current 343 * ODM slice's position 344 */ 345 spl_scratch->scl_data.recout = shift_rec( 346 &overlapping_area, 347 -odm_slice.x, -odm_slice.y); 348 spl_scratch->scl_data.recout.height -= 349 spl_in->debug.visual_confirm_base_offset; 350 spl_scratch->scl_data.recout.height -= 351 spl_in->debug.visual_confirm_dpp_offset; 352 } else 353 /* if there is no overlap, zero recout */ 354 memset(&spl_scratch->scl_data.recout, 0, 355 sizeof(struct spl_rect)); 356 } 357 358 /* Calculate scaling ratios */ 359 static void spl_calculate_scaling_ratios(struct spl_in *spl_in, 360 struct spl_scratch *spl_scratch, 361 struct spl_out *spl_out) 362 { 363 const int in_w = spl_in->basic_out.src_rect.width; 364 const int in_h = spl_in->basic_out.src_rect.height; 365 const int out_w = spl_in->basic_out.dst_rect.width; 366 const int out_h = spl_in->basic_out.dst_rect.height; 367 struct spl_rect surf_src = spl_in->basic_in.src_rect; 368 369 /*Swap surf_src height and width since scaling ratios are in recout rotation*/ 370 if (spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_90 || 371 spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_270) 372 spl_swap(surf_src.height, surf_src.width); 373 374 spl_scratch->scl_data.ratios.horz = spl_fixpt_from_fraction( 375 surf_src.width, 376 spl_in->basic_in.dst_rect.width); 377 spl_scratch->scl_data.ratios.vert = spl_fixpt_from_fraction( 378 surf_src.height, 379 spl_in->basic_in.dst_rect.height); 380 381 if (spl_in->basic_out.view_format == SPL_VIEW_3D_SIDE_BY_SIDE) 382 spl_scratch->scl_data.ratios.horz.value *= 2; 383 else if (spl_in->basic_out.view_format == SPL_VIEW_3D_TOP_AND_BOTTOM) 384 spl_scratch->scl_data.ratios.vert.value *= 2; 385 386 spl_scratch->scl_data.ratios.vert.value = spl_div64_s64( 387 spl_scratch->scl_data.ratios.vert.value * in_h, out_h); 388 spl_scratch->scl_data.ratios.horz.value = spl_div64_s64( 389 spl_scratch->scl_data.ratios.horz.value * in_w, out_w); 390 391 spl_scratch->scl_data.ratios.horz_c = spl_scratch->scl_data.ratios.horz; 392 spl_scratch->scl_data.ratios.vert_c = spl_scratch->scl_data.ratios.vert; 393 394 if (spl_in->basic_in.format == SPL_PIXEL_FORMAT_420BPP8 395 || spl_in->basic_in.format == SPL_PIXEL_FORMAT_420BPP10) { 396 spl_scratch->scl_data.ratios.horz_c.value /= 2; 397 spl_scratch->scl_data.ratios.vert_c.value /= 2; 398 } 399 spl_scratch->scl_data.ratios.horz = spl_fixpt_truncate( 400 spl_scratch->scl_data.ratios.horz, 19); 401 spl_scratch->scl_data.ratios.vert = spl_fixpt_truncate( 402 spl_scratch->scl_data.ratios.vert, 19); 403 spl_scratch->scl_data.ratios.horz_c = spl_fixpt_truncate( 404 spl_scratch->scl_data.ratios.horz_c, 19); 405 spl_scratch->scl_data.ratios.vert_c = spl_fixpt_truncate( 406 spl_scratch->scl_data.ratios.vert_c, 19); 407 408 /* 409 * Coefficient table and some registers are different based on ratio 410 * that is output/input. Currently we calculate input/output 411 * Store 1/ratio in recip_ratio for those lookups 412 */ 413 spl_scratch->scl_data.recip_ratios.horz = spl_fixpt_recip( 414 spl_scratch->scl_data.ratios.horz); 415 spl_scratch->scl_data.recip_ratios.vert = spl_fixpt_recip( 416 spl_scratch->scl_data.ratios.vert); 417 spl_scratch->scl_data.recip_ratios.horz_c = spl_fixpt_recip( 418 spl_scratch->scl_data.ratios.horz_c); 419 spl_scratch->scl_data.recip_ratios.vert_c = spl_fixpt_recip( 420 spl_scratch->scl_data.ratios.vert_c); 421 } 422 423 /* Calculate Viewport size */ 424 static void spl_calculate_viewport_size(struct spl_in *spl_in, struct spl_scratch *spl_scratch) 425 { 426 spl_scratch->scl_data.viewport.width = spl_fixpt_ceil(spl_fixpt_mul_int(spl_scratch->scl_data.ratios.horz, 427 spl_scratch->scl_data.recout.width)); 428 spl_scratch->scl_data.viewport.height = spl_fixpt_ceil(spl_fixpt_mul_int(spl_scratch->scl_data.ratios.vert, 429 spl_scratch->scl_data.recout.height)); 430 spl_scratch->scl_data.viewport_c.width = spl_fixpt_ceil(spl_fixpt_mul_int(spl_scratch->scl_data.ratios.horz_c, 431 spl_scratch->scl_data.recout.width)); 432 spl_scratch->scl_data.viewport_c.height = spl_fixpt_ceil(spl_fixpt_mul_int(spl_scratch->scl_data.ratios.vert_c, 433 spl_scratch->scl_data.recout.height)); 434 if (spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_90 || 435 spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_270) { 436 spl_swap(spl_scratch->scl_data.viewport.width, spl_scratch->scl_data.viewport.height); 437 spl_swap(spl_scratch->scl_data.viewport_c.width, spl_scratch->scl_data.viewport_c.height); 438 } 439 } 440 441 static void spl_get_vp_scan_direction(enum spl_rotation_angle rotation, 442 bool horizontal_mirror, 443 bool *orthogonal_rotation, 444 bool *flip_vert_scan_dir, 445 bool *flip_horz_scan_dir) 446 { 447 *orthogonal_rotation = false; 448 *flip_vert_scan_dir = false; 449 *flip_horz_scan_dir = false; 450 if (rotation == SPL_ROTATION_ANGLE_180) { 451 *flip_vert_scan_dir = true; 452 *flip_horz_scan_dir = true; 453 } else if (rotation == SPL_ROTATION_ANGLE_90) { 454 *orthogonal_rotation = true; 455 *flip_horz_scan_dir = true; 456 } else if (rotation == SPL_ROTATION_ANGLE_270) { 457 *orthogonal_rotation = true; 458 *flip_vert_scan_dir = true; 459 } 460 461 if (horizontal_mirror) 462 *flip_horz_scan_dir = !*flip_horz_scan_dir; 463 } 464 465 /* 466 * We completely calculate vp offset, size and inits here based entirely on scaling 467 * ratios and recout for pixel perfect pipe combine. 468 */ 469 static void spl_calculate_init_and_vp(bool flip_scan_dir, 470 int recout_offset_within_recout_full, 471 int recout_size, 472 int src_size, 473 int taps, 474 struct spl_fixed31_32 ratio, 475 struct spl_fixed31_32 init_adj, 476 struct spl_fixed31_32 *init, 477 int *vp_offset, 478 int *vp_size) 479 { 480 struct spl_fixed31_32 temp; 481 int int_part; 482 483 /* 484 * First of the taps starts sampling pixel number <init_int_part> corresponding to recout 485 * pixel 1. Next recout pixel samples int part of <init + scaling ratio> and so on. 486 * All following calculations are based on this logic. 487 * 488 * Init calculated according to formula: 489 * init = (scaling_ratio + number_of_taps + 1) / 2 490 * init_bot = init + scaling_ratio 491 * to get pixel perfect combine add the fraction from calculating vp offset 492 */ 493 temp = spl_fixpt_mul_int(ratio, recout_offset_within_recout_full); 494 *vp_offset = spl_fixpt_floor(temp); 495 temp.value &= 0xffffffff; 496 *init = spl_fixpt_add(spl_fixpt_div_int(spl_fixpt_add_int(ratio, taps + 1), 2), temp); 497 *init = spl_fixpt_add(*init, init_adj); 498 *init = spl_fixpt_truncate(*init, 19); 499 500 /* 501 * If viewport has non 0 offset and there are more taps than covered by init then 502 * we should decrease the offset and increase init so we are never sampling 503 * outside of viewport. 504 */ 505 int_part = spl_fixpt_floor(*init); 506 if (int_part < taps) { 507 int_part = taps - int_part; 508 if (int_part > *vp_offset) 509 int_part = *vp_offset; 510 *vp_offset -= int_part; 511 *init = spl_fixpt_add_int(*init, int_part); 512 } 513 /* 514 * If taps are sampling outside of viewport at end of recout and there are more pixels 515 * available in the surface we should increase the viewport size, regardless set vp to 516 * only what is used. 517 */ 518 temp = spl_fixpt_add(*init, spl_fixpt_mul_int(ratio, recout_size - 1)); 519 *vp_size = spl_fixpt_floor(temp); 520 if (*vp_size + *vp_offset > src_size) 521 *vp_size = src_size - *vp_offset; 522 523 /* We did all the math assuming we are scanning same direction as display does, 524 * however mirror/rotation changes how vp scans vs how it is offset. If scan direction 525 * is flipped we simply need to calculate offset from the other side of plane. 526 * Note that outside of viewport all scaling hardware works in recout space. 527 */ 528 if (flip_scan_dir) 529 *vp_offset = src_size - *vp_offset - *vp_size; 530 } 531 532 static bool spl_is_yuv420(enum spl_pixel_format format) 533 { 534 if ((format >= SPL_PIXEL_FORMAT_420BPP8) && 535 (format <= SPL_PIXEL_FORMAT_420BPP10)) 536 return true; 537 538 return false; 539 } 540 541 /*Calculate inits and viewport */ 542 static void spl_calculate_inits_and_viewports(struct spl_in *spl_in, 543 struct spl_scratch *spl_scratch) 544 { 545 struct spl_rect src = spl_in->basic_in.src_rect; 546 struct spl_rect recout_dst_in_active_timing; 547 struct spl_rect recout_clip_in_active_timing; 548 struct spl_rect recout_clip_in_recout_dst; 549 struct spl_rect overlap_in_active_timing; 550 struct spl_rect odm_slice = calculate_odm_slice_in_timing_active(spl_in); 551 int vpc_div = (spl_in->basic_in.format == SPL_PIXEL_FORMAT_420BPP8 552 || spl_in->basic_in.format == SPL_PIXEL_FORMAT_420BPP10) ? 2 : 1; 553 bool orthogonal_rotation, flip_vert_scan_dir, flip_horz_scan_dir; 554 struct spl_fixed31_32 init_adj_h = spl_fixpt_zero; 555 struct spl_fixed31_32 init_adj_v = spl_fixpt_zero; 556 557 recout_clip_in_active_timing = shift_rec( 558 &spl_scratch->scl_data.recout, odm_slice.x, odm_slice.y); 559 recout_dst_in_active_timing = calculate_plane_rec_in_timing_active( 560 spl_in, &spl_in->basic_in.dst_rect); 561 overlap_in_active_timing = intersect_rec(&recout_clip_in_active_timing, 562 &recout_dst_in_active_timing); 563 if (overlap_in_active_timing.width > 0 && 564 overlap_in_active_timing.height > 0) 565 recout_clip_in_recout_dst = shift_rec(&overlap_in_active_timing, 566 -recout_dst_in_active_timing.x, 567 -recout_dst_in_active_timing.y); 568 else 569 memset(&recout_clip_in_recout_dst, 0, sizeof(struct spl_rect)); 570 /* 571 * Work in recout rotation since that requires less transformations 572 */ 573 spl_get_vp_scan_direction( 574 spl_in->basic_in.rotation, 575 spl_in->basic_in.horizontal_mirror, 576 &orthogonal_rotation, 577 &flip_vert_scan_dir, 578 &flip_horz_scan_dir); 579 580 if (orthogonal_rotation) { 581 spl_swap(src.width, src.height); 582 spl_swap(flip_vert_scan_dir, flip_horz_scan_dir); 583 } 584 585 if (spl_is_yuv420(spl_in->basic_in.format)) { 586 /* this gives the direction of the cositing (negative will move 587 * left, right otherwise) 588 */ 589 int sign = 1; 590 591 switch (spl_in->basic_in.cositing) { 592 593 case CHROMA_COSITING_LEFT: 594 init_adj_h = spl_fixpt_zero; 595 init_adj_v = spl_fixpt_from_fraction(sign, 4); 596 break; 597 case CHROMA_COSITING_NONE: 598 init_adj_h = spl_fixpt_from_fraction(sign, 4); 599 init_adj_v = spl_fixpt_from_fraction(sign, 4); 600 break; 601 case CHROMA_COSITING_TOPLEFT: 602 default: 603 init_adj_h = spl_fixpt_zero; 604 init_adj_v = spl_fixpt_zero; 605 break; 606 } 607 } 608 609 spl_calculate_init_and_vp( 610 flip_horz_scan_dir, 611 recout_clip_in_recout_dst.x, 612 spl_scratch->scl_data.recout.width, 613 src.width, 614 spl_scratch->scl_data.taps.h_taps, 615 spl_scratch->scl_data.ratios.horz, 616 spl_fixpt_zero, 617 &spl_scratch->scl_data.inits.h, 618 &spl_scratch->scl_data.viewport.x, 619 &spl_scratch->scl_data.viewport.width); 620 spl_calculate_init_and_vp( 621 flip_horz_scan_dir, 622 recout_clip_in_recout_dst.x, 623 spl_scratch->scl_data.recout.width, 624 src.width / vpc_div, 625 spl_scratch->scl_data.taps.h_taps_c, 626 spl_scratch->scl_data.ratios.horz_c, 627 init_adj_h, 628 &spl_scratch->scl_data.inits.h_c, 629 &spl_scratch->scl_data.viewport_c.x, 630 &spl_scratch->scl_data.viewport_c.width); 631 spl_calculate_init_and_vp( 632 flip_vert_scan_dir, 633 recout_clip_in_recout_dst.y, 634 spl_scratch->scl_data.recout.height, 635 src.height, 636 spl_scratch->scl_data.taps.v_taps, 637 spl_scratch->scl_data.ratios.vert, 638 spl_fixpt_zero, 639 &spl_scratch->scl_data.inits.v, 640 &spl_scratch->scl_data.viewport.y, 641 &spl_scratch->scl_data.viewport.height); 642 spl_calculate_init_and_vp( 643 flip_vert_scan_dir, 644 recout_clip_in_recout_dst.y, 645 spl_scratch->scl_data.recout.height, 646 src.height / vpc_div, 647 spl_scratch->scl_data.taps.v_taps_c, 648 spl_scratch->scl_data.ratios.vert_c, 649 init_adj_v, 650 &spl_scratch->scl_data.inits.v_c, 651 &spl_scratch->scl_data.viewport_c.y, 652 &spl_scratch->scl_data.viewport_c.height); 653 if (orthogonal_rotation) { 654 spl_swap(spl_scratch->scl_data.viewport.x, spl_scratch->scl_data.viewport.y); 655 spl_swap(spl_scratch->scl_data.viewport.width, spl_scratch->scl_data.viewport.height); 656 spl_swap(spl_scratch->scl_data.viewport_c.x, spl_scratch->scl_data.viewport_c.y); 657 spl_swap(spl_scratch->scl_data.viewport_c.width, spl_scratch->scl_data.viewport_c.height); 658 } 659 spl_scratch->scl_data.viewport.x += src.x; 660 spl_scratch->scl_data.viewport.y += src.y; 661 SPL_ASSERT(src.x % vpc_div == 0 && src.y % vpc_div == 0); 662 spl_scratch->scl_data.viewport_c.x += src.x / vpc_div; 663 spl_scratch->scl_data.viewport_c.y += src.y / vpc_div; 664 } 665 666 static void spl_handle_3d_recout(struct spl_in *spl_in, struct spl_rect *recout) 667 { 668 /* 669 * Handle side by side and top bottom 3d recout offsets after vp calculation 670 * since 3d is special and needs to calculate vp as if there is no recout offset 671 * This may break with rotation, good thing we aren't mixing hw rotation and 3d 672 */ 673 if (spl_in->basic_in.mpc_combine_v) { 674 SPL_ASSERT(spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_0 || 675 (spl_in->basic_out.view_format != SPL_VIEW_3D_TOP_AND_BOTTOM && 676 spl_in->basic_out.view_format != SPL_VIEW_3D_SIDE_BY_SIDE)); 677 if (spl_in->basic_out.view_format == SPL_VIEW_3D_TOP_AND_BOTTOM) 678 recout->y += recout->height; 679 else if (spl_in->basic_out.view_format == SPL_VIEW_3D_SIDE_BY_SIDE) 680 recout->x += recout->width; 681 } 682 } 683 684 static void spl_clamp_viewport(struct spl_rect *viewport) 685 { 686 /* Clamp minimum viewport size */ 687 if (viewport->height < MIN_VIEWPORT_SIZE) 688 viewport->height = MIN_VIEWPORT_SIZE; 689 if (viewport->width < MIN_VIEWPORT_SIZE) 690 viewport->width = MIN_VIEWPORT_SIZE; 691 } 692 693 static bool spl_dscl_is_420_format(enum spl_pixel_format format) 694 { 695 if (format == SPL_PIXEL_FORMAT_420BPP8 || 696 format == SPL_PIXEL_FORMAT_420BPP10) 697 return true; 698 else 699 return false; 700 } 701 702 static bool spl_dscl_is_video_format(enum spl_pixel_format format) 703 { 704 if (format >= SPL_PIXEL_FORMAT_VIDEO_BEGIN 705 && format <= SPL_PIXEL_FORMAT_VIDEO_END) 706 return true; 707 else 708 return false; 709 } 710 711 static enum scl_mode spl_get_dscl_mode(const struct spl_in *spl_in, 712 const struct spl_scaler_data *data, 713 bool enable_isharp, bool enable_easf) 714 { 715 const long long one = spl_fixpt_one.value; 716 enum spl_pixel_format pixel_format = spl_in->basic_in.format; 717 718 /* Bypass if ratio is 1:1 with no ISHARP or force scale on */ 719 if (data->ratios.horz.value == one 720 && data->ratios.vert.value == one 721 && data->ratios.horz_c.value == one 722 && data->ratios.vert_c.value == one 723 && !spl_in->basic_out.always_scale 724 && !enable_isharp) 725 return SCL_MODE_SCALING_444_BYPASS; 726 727 if (!spl_dscl_is_420_format(pixel_format)) { 728 if (spl_dscl_is_video_format(pixel_format)) 729 return SCL_MODE_SCALING_444_YCBCR_ENABLE; 730 else 731 return SCL_MODE_SCALING_444_RGB_ENABLE; 732 } 733 734 /* Bypass YUV if at 1:1 with no ISHARP or if doing 2:1 YUV 735 * downscale without EASF 736 */ 737 if ((!enable_isharp) && (!enable_easf)) { 738 if (data->ratios.horz.value == one && data->ratios.vert.value == one) 739 return SCL_MODE_SCALING_420_LUMA_BYPASS; 740 if (data->ratios.horz_c.value == one && data->ratios.vert_c.value == one) 741 return SCL_MODE_SCALING_420_CHROMA_BYPASS; 742 } 743 744 return SCL_MODE_SCALING_420_YCBCR_ENABLE; 745 } 746 747 static bool spl_choose_lls_policy(enum spl_pixel_format format, 748 enum spl_transfer_func_type tf_type, 749 enum spl_transfer_func_predefined tf_predefined_type, 750 enum linear_light_scaling *lls_pref) 751 { 752 if (spl_is_yuv420(format)) { 753 *lls_pref = LLS_PREF_NO; 754 if ((tf_type == SPL_TF_TYPE_PREDEFINED) || 755 (tf_type == SPL_TF_TYPE_DISTRIBUTED_POINTS)) 756 return true; 757 } else { /* RGB or YUV444 */ 758 if ((tf_type == SPL_TF_TYPE_PREDEFINED) || 759 (tf_type == SPL_TF_TYPE_BYPASS)) { 760 *lls_pref = LLS_PREF_YES; 761 return true; 762 } 763 } 764 *lls_pref = LLS_PREF_NO; 765 return false; 766 } 767 768 /* Enable EASF ?*/ 769 static bool enable_easf(struct spl_in *spl_in, struct spl_scratch *spl_scratch) 770 { 771 int vratio = 0; 772 int hratio = 0; 773 bool skip_easf = false; 774 bool lls_enable_easf = true; 775 776 /* 777 * If lls_pref is LLS_PREF_DONT_CARE, then use pixel format and transfer 778 * function to determine whether to use LINEAR or NONLINEAR scaling 779 */ 780 if (spl_in->lls_pref == LLS_PREF_DONT_CARE) 781 lls_enable_easf = spl_choose_lls_policy(spl_in->basic_in.format, 782 spl_in->basic_in.tf_type, spl_in->basic_in.tf_predefined_type, 783 &spl_in->lls_pref); 784 785 vratio = spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert); 786 hratio = spl_fixpt_ceil(spl_scratch->scl_data.ratios.horz); 787 788 if (!lls_enable_easf || spl_in->disable_easf) 789 skip_easf = true; 790 791 /* 792 * No EASF support for downscaling > 2:1 793 * EASF support for upscaling or downscaling up to 2:1 794 */ 795 if ((vratio > 2) || (hratio > 2)) 796 skip_easf = true; 797 798 /* Check for linear scaling or EASF preferred */ 799 if (spl_in->lls_pref != LLS_PREF_YES && !spl_in->prefer_easf) 800 skip_easf = true; 801 802 return skip_easf; 803 } 804 805 /* Check if video is in fullscreen mode */ 806 static bool spl_is_video_fullscreen(struct spl_in *spl_in) 807 { 808 if (spl_is_yuv420(spl_in->basic_in.format) && spl_in->is_fullscreen) 809 return true; 810 return false; 811 } 812 813 static bool spl_get_isharp_en(struct spl_in *spl_in, 814 struct spl_scratch *spl_scratch) 815 { 816 bool enable_isharp = false; 817 int vratio = 0; 818 int hratio = 0; 819 struct spl_taps taps = spl_scratch->scl_data.taps; 820 bool fullscreen = spl_is_video_fullscreen(spl_in); 821 822 vratio = spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert); 823 hratio = spl_fixpt_ceil(spl_scratch->scl_data.ratios.horz); 824 825 /* Return if adaptive sharpness is disabled */ 826 if (spl_in->adaptive_sharpness.enable == false) 827 return enable_isharp; 828 829 /* No iSHARP support for downscaling */ 830 if (vratio > 1 || hratio > 1) 831 return enable_isharp; 832 833 // Scaling is up to 1:1 (no scaling) or upscaling 834 835 /* 836 * Apply sharpness to all RGB surfaces and to 837 * NV12/P010 surfaces if in fullscreen 838 */ 839 if (spl_is_yuv420(spl_in->basic_in.format) && !fullscreen) 840 return enable_isharp; 841 842 /* 843 * Apply sharpness if supports horizontal taps 4,6 AND 844 * vertical taps 3, 4, 6 845 */ 846 if ((taps.h_taps == 4 || taps.h_taps == 6) && 847 (taps.v_taps == 3 || taps.v_taps == 4 || taps.v_taps == 6)) 848 enable_isharp = true; 849 850 return enable_isharp; 851 } 852 853 /* Calculate optimal number of taps */ 854 static bool spl_get_optimal_number_of_taps( 855 int max_downscale_src_width, struct spl_in *spl_in, struct spl_scratch *spl_scratch, 856 const struct spl_taps *in_taps, bool *enable_easf_v, bool *enable_easf_h, 857 bool *enable_isharp) 858 { 859 int num_part_y, num_part_c; 860 int max_taps_y, max_taps_c; 861 int min_taps_y, min_taps_c; 862 enum lb_memory_config lb_config; 863 bool skip_easf = false; 864 865 if (spl_scratch->scl_data.viewport.width > spl_scratch->scl_data.h_active && 866 max_downscale_src_width != 0 && 867 spl_scratch->scl_data.viewport.width > max_downscale_src_width) 868 return false; 869 870 /* Check if we are using EASF or not */ 871 skip_easf = enable_easf(spl_in, spl_scratch); 872 873 /* 874 * Set default taps if none are provided 875 * From programming guide: taps = min{ ceil(2*H_RATIO,1), 8} for downscaling 876 * taps = 4 for upscaling 877 */ 878 if (skip_easf) { 879 if (in_taps->h_taps == 0) { 880 if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.horz) > 1) 881 spl_scratch->scl_data.taps.h_taps = spl_min(2 * spl_fixpt_ceil( 882 spl_scratch->scl_data.ratios.horz), 8); 883 else 884 spl_scratch->scl_data.taps.h_taps = 4; 885 } else 886 spl_scratch->scl_data.taps.h_taps = in_taps->h_taps; 887 if (in_taps->v_taps == 0) { 888 if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert) > 1) 889 spl_scratch->scl_data.taps.v_taps = spl_min(spl_fixpt_ceil(spl_fixpt_mul_int( 890 spl_scratch->scl_data.ratios.vert, 2)), 8); 891 else 892 spl_scratch->scl_data.taps.v_taps = 4; 893 } else 894 spl_scratch->scl_data.taps.v_taps = in_taps->v_taps; 895 if (in_taps->v_taps_c == 0) { 896 if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c) > 1) 897 spl_scratch->scl_data.taps.v_taps_c = spl_min(spl_fixpt_ceil(spl_fixpt_mul_int( 898 spl_scratch->scl_data.ratios.vert_c, 2)), 8); 899 else 900 spl_scratch->scl_data.taps.v_taps_c = 4; 901 } else 902 spl_scratch->scl_data.taps.v_taps_c = in_taps->v_taps_c; 903 if (in_taps->h_taps_c == 0) { 904 if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.horz_c) > 1) 905 spl_scratch->scl_data.taps.h_taps_c = spl_min(2 * spl_fixpt_ceil( 906 spl_scratch->scl_data.ratios.horz_c), 8); 907 else 908 spl_scratch->scl_data.taps.h_taps_c = 4; 909 } else if ((in_taps->h_taps_c % 2) != 0 && in_taps->h_taps_c != 1) 910 /* Only 1 and even h_taps_c are supported by hw */ 911 spl_scratch->scl_data.taps.h_taps_c = in_taps->h_taps_c - 1; 912 else 913 spl_scratch->scl_data.taps.h_taps_c = in_taps->h_taps_c; 914 } else { 915 if (spl_is_yuv420(spl_in->basic_in.format)) { 916 spl_scratch->scl_data.taps.h_taps = 6; 917 spl_scratch->scl_data.taps.v_taps = 6; 918 spl_scratch->scl_data.taps.h_taps_c = 4; 919 spl_scratch->scl_data.taps.v_taps_c = 4; 920 } else { /* RGB */ 921 spl_scratch->scl_data.taps.h_taps = 6; 922 spl_scratch->scl_data.taps.v_taps = 6; 923 spl_scratch->scl_data.taps.h_taps_c = 6; 924 spl_scratch->scl_data.taps.v_taps_c = 6; 925 } 926 } 927 928 /*Ensure we can support the requested number of vtaps*/ 929 min_taps_y = spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert); 930 min_taps_c = spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c); 931 932 /* Use LB_MEMORY_CONFIG_3 for 4:2:0 */ 933 if ((spl_in->basic_in.format == SPL_PIXEL_FORMAT_420BPP8) 934 || (spl_in->basic_in.format == SPL_PIXEL_FORMAT_420BPP10)) 935 lb_config = LB_MEMORY_CONFIG_3; 936 else 937 lb_config = LB_MEMORY_CONFIG_0; 938 // Determine max vtap support by calculating how much line buffer can fit 939 spl_in->funcs->spl_calc_lb_num_partitions(spl_in->basic_out.alpha_en, &spl_scratch->scl_data, 940 lb_config, &num_part_y, &num_part_c); 941 /* MAX_V_TAPS = MIN (NUM_LINES - MAX(CEILING(V_RATIO,1)-2, 0), 8) */ 942 if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert) > 2) 943 max_taps_y = num_part_y - (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert) - 2); 944 else 945 max_taps_y = num_part_y; 946 947 if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c) > 2) 948 max_taps_c = num_part_c - (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c) - 2); 949 else 950 max_taps_c = num_part_c; 951 952 if (max_taps_y < min_taps_y) 953 return false; 954 else if (max_taps_c < min_taps_c) 955 return false; 956 957 if (spl_scratch->scl_data.taps.v_taps > max_taps_y) 958 spl_scratch->scl_data.taps.v_taps = max_taps_y; 959 960 if (spl_scratch->scl_data.taps.v_taps_c > max_taps_c) 961 spl_scratch->scl_data.taps.v_taps_c = max_taps_c; 962 963 if (!skip_easf) { 964 /* 965 * RGB ( L + NL ) and Linear HDR support 6x6, 6x4, 6x3, 4x4, 4x3 966 * NL YUV420 only supports 6x6, 6x4 for Y and 4x4 for UV 967 * 968 * If LB does not support 3, 4, or 6 taps, then disable EASF_V 969 * and only enable EASF_H. So for RGB, support 6x2, 4x2 970 * and for NL YUV420, support 6x2 for Y and 4x2 for UV 971 * 972 * All other cases, have to disable EASF_V and EASF_H 973 * 974 * If optimal no of taps is 5, then set it to 4 975 * If optimal no of taps is 7 or 8, then fine since max tap is 6 976 * 977 */ 978 if (spl_scratch->scl_data.taps.v_taps == 5) 979 spl_scratch->scl_data.taps.v_taps = 4; 980 981 if (spl_scratch->scl_data.taps.v_taps_c == 5) 982 spl_scratch->scl_data.taps.v_taps_c = 4; 983 984 if (spl_scratch->scl_data.taps.h_taps == 5) 985 spl_scratch->scl_data.taps.h_taps = 4; 986 987 if (spl_scratch->scl_data.taps.h_taps_c == 5) 988 spl_scratch->scl_data.taps.h_taps_c = 4; 989 990 if (spl_is_yuv420(spl_in->basic_in.format)) { 991 if ((spl_scratch->scl_data.taps.h_taps <= 4) || 992 (spl_scratch->scl_data.taps.h_taps_c <= 3)) { 993 *enable_easf_v = false; 994 *enable_easf_h = false; 995 } else if ((spl_scratch->scl_data.taps.v_taps <= 3) || 996 (spl_scratch->scl_data.taps.v_taps_c <= 3)) { 997 *enable_easf_v = false; 998 *enable_easf_h = true; 999 } else { 1000 *enable_easf_v = true; 1001 *enable_easf_h = true; 1002 } 1003 SPL_ASSERT((spl_scratch->scl_data.taps.v_taps > 1) && 1004 (spl_scratch->scl_data.taps.v_taps_c > 1)); 1005 } else { /* RGB */ 1006 if (spl_scratch->scl_data.taps.h_taps <= 3) { 1007 *enable_easf_v = false; 1008 *enable_easf_h = false; 1009 } else if (spl_scratch->scl_data.taps.v_taps < 3) { 1010 *enable_easf_v = false; 1011 *enable_easf_h = true; 1012 } else { 1013 *enable_easf_v = true; 1014 *enable_easf_h = true; 1015 } 1016 SPL_ASSERT(spl_scratch->scl_data.taps.v_taps > 1); 1017 } 1018 } else { 1019 *enable_easf_v = false; 1020 *enable_easf_h = false; 1021 } // end of if prefer_easf 1022 1023 /* Sharpener requires scaler to be enabled, including for 1:1 1024 * Check if ISHARP can be enabled 1025 * If ISHARP is not enabled, for 1:1, set taps to 1 and disable 1026 * EASF 1027 * For case of 2:1 YUV where chroma is 1:1, set taps to 1 if 1028 * EASF is not enabled 1029 */ 1030 1031 *enable_isharp = spl_get_isharp_en(spl_in, spl_scratch); 1032 if (!*enable_isharp && !spl_in->basic_out.always_scale) { 1033 if ((IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz)) && 1034 (IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert))) { 1035 spl_scratch->scl_data.taps.h_taps = 1; 1036 spl_scratch->scl_data.taps.v_taps = 1; 1037 1038 if (IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz_c)) 1039 spl_scratch->scl_data.taps.h_taps_c = 1; 1040 1041 if (IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert_c)) 1042 spl_scratch->scl_data.taps.v_taps_c = 1; 1043 1044 *enable_easf_v = false; 1045 *enable_easf_h = false; 1046 } else { 1047 if ((!*enable_easf_h) && 1048 (IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz_c))) 1049 spl_scratch->scl_data.taps.h_taps_c = 1; 1050 1051 if ((!*enable_easf_v) && 1052 (IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert_c))) 1053 spl_scratch->scl_data.taps.v_taps_c = 1; 1054 } 1055 } 1056 return true; 1057 } 1058 1059 static void spl_set_black_color_data(enum spl_pixel_format format, 1060 struct scl_black_color *scl_black_color) 1061 { 1062 bool ycbcr = format >= SPL_PIXEL_FORMAT_VIDEO_BEGIN 1063 && format <= SPL_PIXEL_FORMAT_VIDEO_END; 1064 if (ycbcr) { 1065 scl_black_color->offset_rgb_y = BLACK_OFFSET_RGB_Y; 1066 scl_black_color->offset_rgb_cbcr = BLACK_OFFSET_CBCR; 1067 } else { 1068 scl_black_color->offset_rgb_y = 0x0; 1069 scl_black_color->offset_rgb_cbcr = 0x0; 1070 } 1071 } 1072 1073 static void spl_set_manual_ratio_init_data(struct dscl_prog_data *dscl_prog_data, 1074 const struct spl_scaler_data *scl_data) 1075 { 1076 struct spl_fixed31_32 bot; 1077 1078 dscl_prog_data->ratios.h_scale_ratio = spl_fixpt_u3d19(scl_data->ratios.horz) << 5; 1079 dscl_prog_data->ratios.v_scale_ratio = spl_fixpt_u3d19(scl_data->ratios.vert) << 5; 1080 dscl_prog_data->ratios.h_scale_ratio_c = spl_fixpt_u3d19(scl_data->ratios.horz_c) << 5; 1081 dscl_prog_data->ratios.v_scale_ratio_c = spl_fixpt_u3d19(scl_data->ratios.vert_c) << 5; 1082 /* 1083 * 0.24 format for fraction, first five bits zeroed 1084 */ 1085 dscl_prog_data->init.h_filter_init_frac = 1086 spl_fixpt_u0d19(scl_data->inits.h) << 5; 1087 dscl_prog_data->init.h_filter_init_int = 1088 spl_fixpt_floor(scl_data->inits.h); 1089 dscl_prog_data->init.h_filter_init_frac_c = 1090 spl_fixpt_u0d19(scl_data->inits.h_c) << 5; 1091 dscl_prog_data->init.h_filter_init_int_c = 1092 spl_fixpt_floor(scl_data->inits.h_c); 1093 dscl_prog_data->init.v_filter_init_frac = 1094 spl_fixpt_u0d19(scl_data->inits.v) << 5; 1095 dscl_prog_data->init.v_filter_init_int = 1096 spl_fixpt_floor(scl_data->inits.v); 1097 dscl_prog_data->init.v_filter_init_frac_c = 1098 spl_fixpt_u0d19(scl_data->inits.v_c) << 5; 1099 dscl_prog_data->init.v_filter_init_int_c = 1100 spl_fixpt_floor(scl_data->inits.v_c); 1101 1102 bot = spl_fixpt_add(scl_data->inits.v, scl_data->ratios.vert); 1103 dscl_prog_data->init.v_filter_init_bot_frac = spl_fixpt_u0d19(bot) << 5; 1104 dscl_prog_data->init.v_filter_init_bot_int = spl_fixpt_floor(bot); 1105 bot = spl_fixpt_add(scl_data->inits.v_c, scl_data->ratios.vert_c); 1106 dscl_prog_data->init.v_filter_init_bot_frac_c = spl_fixpt_u0d19(bot) << 5; 1107 dscl_prog_data->init.v_filter_init_bot_int_c = spl_fixpt_floor(bot); 1108 } 1109 1110 static void spl_set_taps_data(struct dscl_prog_data *dscl_prog_data, 1111 const struct spl_scaler_data *scl_data) 1112 { 1113 dscl_prog_data->taps.v_taps = scl_data->taps.v_taps - 1; 1114 dscl_prog_data->taps.h_taps = scl_data->taps.h_taps - 1; 1115 dscl_prog_data->taps.v_taps_c = scl_data->taps.v_taps_c - 1; 1116 dscl_prog_data->taps.h_taps_c = scl_data->taps.h_taps_c - 1; 1117 } 1118 1119 /* Populate dscl prog data structure from scaler data calculated by SPL */ 1120 static void spl_set_dscl_prog_data(struct spl_in *spl_in, struct spl_scratch *spl_scratch, 1121 struct spl_out *spl_out, bool enable_easf_v, bool enable_easf_h, bool enable_isharp) 1122 { 1123 struct dscl_prog_data *dscl_prog_data = spl_out->dscl_prog_data; 1124 1125 const struct spl_scaler_data *data = &spl_scratch->scl_data; 1126 1127 struct scl_black_color *scl_black_color = &dscl_prog_data->scl_black_color; 1128 1129 bool enable_easf = enable_easf_v || enable_easf_h; 1130 1131 // Set values for recout 1132 dscl_prog_data->recout = spl_scratch->scl_data.recout; 1133 // Set values for MPC Size 1134 dscl_prog_data->mpc_size.width = spl_scratch->scl_data.h_active; 1135 dscl_prog_data->mpc_size.height = spl_scratch->scl_data.v_active; 1136 1137 // SCL_MODE - Set SCL_MODE data 1138 dscl_prog_data->dscl_mode = spl_get_dscl_mode(spl_in, data, enable_isharp, 1139 enable_easf); 1140 1141 // SCL_BLACK_COLOR 1142 spl_set_black_color_data(spl_in->basic_in.format, scl_black_color); 1143 1144 /* Manually calculate scale ratio and init values */ 1145 spl_set_manual_ratio_init_data(dscl_prog_data, data); 1146 1147 // Set HTaps/VTaps 1148 spl_set_taps_data(dscl_prog_data, data); 1149 // Set viewport 1150 dscl_prog_data->viewport = spl_scratch->scl_data.viewport; 1151 // Set viewport_c 1152 dscl_prog_data->viewport_c = spl_scratch->scl_data.viewport_c; 1153 // Set filters data 1154 spl_set_filters_data(dscl_prog_data, data, enable_easf_v, enable_easf_h); 1155 } 1156 1157 /* Set EASF data */ 1158 static void spl_set_easf_data(struct spl_scratch *spl_scratch, struct spl_out *spl_out, bool enable_easf_v, 1159 bool enable_easf_h, enum linear_light_scaling lls_pref, 1160 enum spl_pixel_format format, enum system_setup setup) 1161 { 1162 struct dscl_prog_data *dscl_prog_data = spl_out->dscl_prog_data; 1163 if (enable_easf_v) { 1164 dscl_prog_data->easf_v_en = true; 1165 dscl_prog_data->easf_v_ring = 0; 1166 dscl_prog_data->easf_v_sharp_factor = 0; 1167 dscl_prog_data->easf_v_bf1_en = 1; // 1-bit, BF1 calculation enable, 0=disable, 1=enable 1168 dscl_prog_data->easf_v_bf2_mode = 0xF; // 4-bit, BF2 calculation mode 1169 /* 2-bit, BF3 chroma mode correction calculation mode */ 1170 dscl_prog_data->easf_v_bf3_mode = spl_get_v_bf3_mode( 1171 spl_scratch->scl_data.recip_ratios.vert); 1172 /* FP1.5.10 [ minCoef ]*/ 1173 dscl_prog_data->easf_v_ringest_3tap_dntilt_uptilt = 1174 spl_get_3tap_dntilt_uptilt_offset(spl_scratch->scl_data.taps.v_taps, 1175 spl_scratch->scl_data.recip_ratios.vert); 1176 /* FP1.5.10 [ upTiltMaxVal ]*/ 1177 dscl_prog_data->easf_v_ringest_3tap_uptilt_max = 1178 spl_get_3tap_uptilt_maxval(spl_scratch->scl_data.taps.v_taps, 1179 spl_scratch->scl_data.recip_ratios.vert); 1180 /* FP1.5.10 [ dnTiltSlope ]*/ 1181 dscl_prog_data->easf_v_ringest_3tap_dntilt_slope = 1182 spl_get_3tap_dntilt_slope(spl_scratch->scl_data.taps.v_taps, 1183 spl_scratch->scl_data.recip_ratios.vert); 1184 /* FP1.5.10 [ upTilt1Slope ]*/ 1185 dscl_prog_data->easf_v_ringest_3tap_uptilt1_slope = 1186 spl_get_3tap_uptilt1_slope(spl_scratch->scl_data.taps.v_taps, 1187 spl_scratch->scl_data.recip_ratios.vert); 1188 /* FP1.5.10 [ upTilt2Slope ]*/ 1189 dscl_prog_data->easf_v_ringest_3tap_uptilt2_slope = 1190 spl_get_3tap_uptilt2_slope(spl_scratch->scl_data.taps.v_taps, 1191 spl_scratch->scl_data.recip_ratios.vert); 1192 /* FP1.5.10 [ upTilt2Offset ]*/ 1193 dscl_prog_data->easf_v_ringest_3tap_uptilt2_offset = 1194 spl_get_3tap_uptilt2_offset(spl_scratch->scl_data.taps.v_taps, 1195 spl_scratch->scl_data.recip_ratios.vert); 1196 /* FP1.5.10; (2.0) Ring reducer gain for 4 or 6-tap mode [H_REDUCER_GAIN4] */ 1197 dscl_prog_data->easf_v_ringest_eventap_reduceg1 = 1198 spl_get_reducer_gain4(spl_scratch->scl_data.taps.v_taps, 1199 spl_scratch->scl_data.recip_ratios.vert); 1200 /* FP1.5.10; (2.5) Ring reducer gain for 6-tap mode [V_REDUCER_GAIN6] */ 1201 dscl_prog_data->easf_v_ringest_eventap_reduceg2 = 1202 spl_get_reducer_gain6(spl_scratch->scl_data.taps.v_taps, 1203 spl_scratch->scl_data.recip_ratios.vert); 1204 /* FP1.5.10; (-0.135742) Ring gain for 6-tap set to -139/1024 */ 1205 dscl_prog_data->easf_v_ringest_eventap_gain1 = 1206 spl_get_gainRing4(spl_scratch->scl_data.taps.v_taps, 1207 spl_scratch->scl_data.recip_ratios.vert); 1208 /* FP1.5.10; (-0.024414) Ring gain for 6-tap set to -25/1024 */ 1209 dscl_prog_data->easf_v_ringest_eventap_gain2 = 1210 spl_get_gainRing6(spl_scratch->scl_data.taps.v_taps, 1211 spl_scratch->scl_data.recip_ratios.vert); 1212 dscl_prog_data->easf_v_bf_maxa = 63; //Vertical Max BF value A in U0.6 format.Selected if V_FCNTL == 0 1213 dscl_prog_data->easf_v_bf_maxb = 63; //Vertical Max BF value A in U0.6 format.Selected if V_FCNTL == 1 1214 dscl_prog_data->easf_v_bf_mina = 0; //Vertical Min BF value A in U0.6 format.Selected if V_FCNTL == 0 1215 dscl_prog_data->easf_v_bf_minb = 0; //Vertical Min BF value A in U0.6 format.Selected if V_FCNTL == 1 1216 if (lls_pref == LLS_PREF_YES) { 1217 dscl_prog_data->easf_v_bf2_flat1_gain = 4; // U1.3, BF2 Flat1 Gain control 1218 dscl_prog_data->easf_v_bf2_flat2_gain = 8; // U4.0, BF2 Flat2 Gain control 1219 dscl_prog_data->easf_v_bf2_roc_gain = 4; // U2.2, Rate Of Change control 1220 1221 dscl_prog_data->easf_v_bf1_pwl_in_seg0 = 0x600; // S0.10, BF1 PWL Segment 0 = -512 1222 dscl_prog_data->easf_v_bf1_pwl_base_seg0 = 0; // U0.6, BF1 Base PWL Segment 0 1223 dscl_prog_data->easf_v_bf1_pwl_slope_seg0 = 3; // S7.3, BF1 Slope PWL Segment 0 1224 dscl_prog_data->easf_v_bf1_pwl_in_seg1 = 0x7EC; // S0.10, BF1 PWL Segment 1 = -20 1225 dscl_prog_data->easf_v_bf1_pwl_base_seg1 = 12; // U0.6, BF1 Base PWL Segment 1 1226 dscl_prog_data->easf_v_bf1_pwl_slope_seg1 = 326; // S7.3, BF1 Slope PWL Segment 1 1227 dscl_prog_data->easf_v_bf1_pwl_in_seg2 = 0; // S0.10, BF1 PWL Segment 2 1228 dscl_prog_data->easf_v_bf1_pwl_base_seg2 = 63; // U0.6, BF1 Base PWL Segment 2 1229 dscl_prog_data->easf_v_bf1_pwl_slope_seg2 = 0; // S7.3, BF1 Slope PWL Segment 2 1230 dscl_prog_data->easf_v_bf1_pwl_in_seg3 = 16; // S0.10, BF1 PWL Segment 3 1231 dscl_prog_data->easf_v_bf1_pwl_base_seg3 = 63; // U0.6, BF1 Base PWL Segment 3 1232 dscl_prog_data->easf_v_bf1_pwl_slope_seg3 = 0x7C8; // S7.3, BF1 Slope PWL Segment 3 = -56 1233 dscl_prog_data->easf_v_bf1_pwl_in_seg4 = 32; // S0.10, BF1 PWL Segment 4 1234 dscl_prog_data->easf_v_bf1_pwl_base_seg4 = 56; // U0.6, BF1 Base PWL Segment 4 1235 dscl_prog_data->easf_v_bf1_pwl_slope_seg4 = 0x7D0; // S7.3, BF1 Slope PWL Segment 4 = -48 1236 dscl_prog_data->easf_v_bf1_pwl_in_seg5 = 48; // S0.10, BF1 PWL Segment 5 1237 dscl_prog_data->easf_v_bf1_pwl_base_seg5 = 50; // U0.6, BF1 Base PWL Segment 5 1238 dscl_prog_data->easf_v_bf1_pwl_slope_seg5 = 0x710; // S7.3, BF1 Slope PWL Segment 5 = -240 1239 dscl_prog_data->easf_v_bf1_pwl_in_seg6 = 64; // S0.10, BF1 PWL Segment 6 1240 dscl_prog_data->easf_v_bf1_pwl_base_seg6 = 20; // U0.6, BF1 Base PWL Segment 6 1241 dscl_prog_data->easf_v_bf1_pwl_slope_seg6 = 0x760; // S7.3, BF1 Slope PWL Segment 6 = -160 1242 dscl_prog_data->easf_v_bf1_pwl_in_seg7 = 80; // S0.10, BF1 PWL Segment 7 1243 dscl_prog_data->easf_v_bf1_pwl_base_seg7 = 0; // U0.6, BF1 Base PWL Segment 7 1244 1245 dscl_prog_data->easf_v_bf3_pwl_in_set0 = 0x000; // FP0.6.6, BF3 Input value PWL Segment 0 1246 dscl_prog_data->easf_v_bf3_pwl_base_set0 = 63; // S0.6, BF3 Base PWL Segment 0 1247 dscl_prog_data->easf_v_bf3_pwl_slope_set0 = 0x12C5; // FP1.6.6, BF3 Slope PWL Segment 0 1248 dscl_prog_data->easf_v_bf3_pwl_in_set1 = 1249 0x0B37; // FP0.6.6, BF3 Input value PWL Segment 1 (0.0078125 * 125^3) 1250 dscl_prog_data->easf_v_bf3_pwl_base_set1 = 62; // S0.6, BF3 Base PWL Segment 1 1251 dscl_prog_data->easf_v_bf3_pwl_slope_set1 = 1252 0x13B8; // FP1.6.6, BF3 Slope PWL Segment 1 1253 dscl_prog_data->easf_v_bf3_pwl_in_set2 = 1254 0x0BB7; // FP0.6.6, BF3 Input value PWL Segment 2 (0.03125 * 125^3) 1255 dscl_prog_data->easf_v_bf3_pwl_base_set2 = 20; // S0.6, BF3 Base PWL Segment 2 1256 dscl_prog_data->easf_v_bf3_pwl_slope_set2 = 1257 0x1356; // FP1.6.6, BF3 Slope PWL Segment 2 1258 dscl_prog_data->easf_v_bf3_pwl_in_set3 = 1259 0x0BF7; // FP0.6.6, BF3 Input value PWL Segment 3 (0.0625 * 125^3) 1260 dscl_prog_data->easf_v_bf3_pwl_base_set3 = 0; // S0.6, BF3 Base PWL Segment 3 1261 dscl_prog_data->easf_v_bf3_pwl_slope_set3 = 1262 0x136B; // FP1.6.6, BF3 Slope PWL Segment 3 1263 dscl_prog_data->easf_v_bf3_pwl_in_set4 = 1264 0x0C37; // FP0.6.6, BF3 Input value PWL Segment 4 (0.125 * 125^3) 1265 dscl_prog_data->easf_v_bf3_pwl_base_set4 = 0x4E; // S0.6, BF3 Base PWL Segment 4 = -50 1266 dscl_prog_data->easf_v_bf3_pwl_slope_set4 = 1267 0x1200; // FP1.6.6, BF3 Slope PWL Segment 4 1268 dscl_prog_data->easf_v_bf3_pwl_in_set5 = 1269 0x0CF7; // FP0.6.6, BF3 Input value PWL Segment 5 (1.0 * 125^3) 1270 dscl_prog_data->easf_v_bf3_pwl_base_set5 = 0x41; // S0.6, BF3 Base PWL Segment 5 = -63 1271 } else { 1272 dscl_prog_data->easf_v_bf2_flat1_gain = 13; // U1.3, BF2 Flat1 Gain control 1273 dscl_prog_data->easf_v_bf2_flat2_gain = 15; // U4.0, BF2 Flat2 Gain control 1274 dscl_prog_data->easf_v_bf2_roc_gain = 14; // U2.2, Rate Of Change control 1275 1276 dscl_prog_data->easf_v_bf1_pwl_in_seg0 = 0x440; // S0.10, BF1 PWL Segment 0 = -960 1277 dscl_prog_data->easf_v_bf1_pwl_base_seg0 = 0; // U0.6, BF1 Base PWL Segment 0 1278 dscl_prog_data->easf_v_bf1_pwl_slope_seg0 = 2; // S7.3, BF1 Slope PWL Segment 0 1279 dscl_prog_data->easf_v_bf1_pwl_in_seg1 = 0x7C4; // S0.10, BF1 PWL Segment 1 = -60 1280 dscl_prog_data->easf_v_bf1_pwl_base_seg1 = 12; // U0.6, BF1 Base PWL Segment 1 1281 dscl_prog_data->easf_v_bf1_pwl_slope_seg1 = 109; // S7.3, BF1 Slope PWL Segment 1 1282 dscl_prog_data->easf_v_bf1_pwl_in_seg2 = 0; // S0.10, BF1 PWL Segment 2 1283 dscl_prog_data->easf_v_bf1_pwl_base_seg2 = 63; // U0.6, BF1 Base PWL Segment 2 1284 dscl_prog_data->easf_v_bf1_pwl_slope_seg2 = 0; // S7.3, BF1 Slope PWL Segment 2 1285 dscl_prog_data->easf_v_bf1_pwl_in_seg3 = 48; // S0.10, BF1 PWL Segment 3 1286 dscl_prog_data->easf_v_bf1_pwl_base_seg3 = 63; // U0.6, BF1 Base PWL Segment 3 1287 dscl_prog_data->easf_v_bf1_pwl_slope_seg3 = 0x7ED; // S7.3, BF1 Slope PWL Segment 3 = -19 1288 dscl_prog_data->easf_v_bf1_pwl_in_seg4 = 96; // S0.10, BF1 PWL Segment 4 1289 dscl_prog_data->easf_v_bf1_pwl_base_seg4 = 56; // U0.6, BF1 Base PWL Segment 4 1290 dscl_prog_data->easf_v_bf1_pwl_slope_seg4 = 0x7F0; // S7.3, BF1 Slope PWL Segment 4 = -16 1291 dscl_prog_data->easf_v_bf1_pwl_in_seg5 = 144; // S0.10, BF1 PWL Segment 5 1292 dscl_prog_data->easf_v_bf1_pwl_base_seg5 = 50; // U0.6, BF1 Base PWL Segment 5 1293 dscl_prog_data->easf_v_bf1_pwl_slope_seg5 = 0x7B0; // S7.3, BF1 Slope PWL Segment 5 = -80 1294 dscl_prog_data->easf_v_bf1_pwl_in_seg6 = 192; // S0.10, BF1 PWL Segment 6 1295 dscl_prog_data->easf_v_bf1_pwl_base_seg6 = 20; // U0.6, BF1 Base PWL Segment 6 1296 dscl_prog_data->easf_v_bf1_pwl_slope_seg6 = 0x7CB; // S7.3, BF1 Slope PWL Segment 6 = -53 1297 dscl_prog_data->easf_v_bf1_pwl_in_seg7 = 240; // S0.10, BF1 PWL Segment 7 1298 dscl_prog_data->easf_v_bf1_pwl_base_seg7 = 0; // U0.6, BF1 Base PWL Segment 7 1299 1300 dscl_prog_data->easf_v_bf3_pwl_in_set0 = 0x000; // FP0.6.6, BF3 Input value PWL Segment 0 1301 dscl_prog_data->easf_v_bf3_pwl_base_set0 = 63; // S0.6, BF3 Base PWL Segment 0 1302 dscl_prog_data->easf_v_bf3_pwl_slope_set0 = 0x0000; // FP1.6.6, BF3 Slope PWL Segment 0 1303 dscl_prog_data->easf_v_bf3_pwl_in_set1 = 1304 0x06C0; // FP0.6.6, BF3 Input value PWL Segment 1 (0.0625) 1305 dscl_prog_data->easf_v_bf3_pwl_base_set1 = 63; // S0.6, BF3 Base PWL Segment 1 1306 dscl_prog_data->easf_v_bf3_pwl_slope_set1 = 0x1896; // FP1.6.6, BF3 Slope PWL Segment 1 1307 dscl_prog_data->easf_v_bf3_pwl_in_set2 = 1308 0x0700; // FP0.6.6, BF3 Input value PWL Segment 2 (0.125) 1309 dscl_prog_data->easf_v_bf3_pwl_base_set2 = 20; // S0.6, BF3 Base PWL Segment 2 1310 dscl_prog_data->easf_v_bf3_pwl_slope_set2 = 0x1810; // FP1.6.6, BF3 Slope PWL Segment 2 1311 dscl_prog_data->easf_v_bf3_pwl_in_set3 = 1312 0x0740; // FP0.6.6, BF3 Input value PWL Segment 3 (0.25) 1313 dscl_prog_data->easf_v_bf3_pwl_base_set3 = 0; // S0.6, BF3 Base PWL Segment 3 1314 dscl_prog_data->easf_v_bf3_pwl_slope_set3 = 1315 0x1878; // FP1.6.6, BF3 Slope PWL Segment 3 1316 dscl_prog_data->easf_v_bf3_pwl_in_set4 = 1317 0x0761; // FP0.6.6, BF3 Input value PWL Segment 4 (0.375) 1318 dscl_prog_data->easf_v_bf3_pwl_base_set4 = 0x44; // S0.6, BF3 Base PWL Segment 4 = -60 1319 dscl_prog_data->easf_v_bf3_pwl_slope_set4 = 0x1760; // FP1.6.6, BF3 Slope PWL Segment 4 1320 dscl_prog_data->easf_v_bf3_pwl_in_set5 = 1321 0x0780; // FP0.6.6, BF3 Input value PWL Segment 5 (0.5) 1322 dscl_prog_data->easf_v_bf3_pwl_base_set5 = 0x41; // S0.6, BF3 Base PWL Segment 5 = -63 1323 } 1324 } else 1325 dscl_prog_data->easf_v_en = false; 1326 1327 if (enable_easf_h) { 1328 dscl_prog_data->easf_h_en = true; 1329 dscl_prog_data->easf_h_ring = 0; 1330 dscl_prog_data->easf_h_sharp_factor = 0; 1331 dscl_prog_data->easf_h_bf1_en = 1332 1; // 1-bit, BF1 calculation enable, 0=disable, 1=enable 1333 dscl_prog_data->easf_h_bf2_mode = 1334 0xF; // 4-bit, BF2 calculation mode 1335 /* 2-bit, BF3 chroma mode correction calculation mode */ 1336 dscl_prog_data->easf_h_bf3_mode = spl_get_h_bf3_mode( 1337 spl_scratch->scl_data.recip_ratios.horz); 1338 /* FP1.5.10; (2.0) Ring reducer gain for 4 or 6-tap mode [H_REDUCER_GAIN4] */ 1339 dscl_prog_data->easf_h_ringest_eventap_reduceg1 = 1340 spl_get_reducer_gain4(spl_scratch->scl_data.taps.h_taps, 1341 spl_scratch->scl_data.recip_ratios.horz); 1342 /* FP1.5.10; (2.5) Ring reducer gain for 6-tap mode [V_REDUCER_GAIN6] */ 1343 dscl_prog_data->easf_h_ringest_eventap_reduceg2 = 1344 spl_get_reducer_gain6(spl_scratch->scl_data.taps.h_taps, 1345 spl_scratch->scl_data.recip_ratios.horz); 1346 /* FP1.5.10; (-0.135742) Ring gain for 6-tap set to -139/1024 */ 1347 dscl_prog_data->easf_h_ringest_eventap_gain1 = 1348 spl_get_gainRing4(spl_scratch->scl_data.taps.h_taps, 1349 spl_scratch->scl_data.recip_ratios.horz); 1350 /* FP1.5.10; (-0.024414) Ring gain for 6-tap set to -25/1024 */ 1351 dscl_prog_data->easf_h_ringest_eventap_gain2 = 1352 spl_get_gainRing6(spl_scratch->scl_data.taps.h_taps, 1353 spl_scratch->scl_data.recip_ratios.horz); 1354 dscl_prog_data->easf_h_bf_maxa = 63; //Horz Max BF value A in U0.6 format.Selected if H_FCNTL==0 1355 dscl_prog_data->easf_h_bf_maxb = 63; //Horz Max BF value B in U0.6 format.Selected if H_FCNTL==1 1356 dscl_prog_data->easf_h_bf_mina = 0; //Horz Min BF value B in U0.6 format.Selected if H_FCNTL==0 1357 dscl_prog_data->easf_h_bf_minb = 0; //Horz Min BF value B in U0.6 format.Selected if H_FCNTL==1 1358 if (lls_pref == LLS_PREF_YES) { 1359 dscl_prog_data->easf_h_bf2_flat1_gain = 4; // U1.3, BF2 Flat1 Gain control 1360 dscl_prog_data->easf_h_bf2_flat2_gain = 8; // U4.0, BF2 Flat2 Gain control 1361 dscl_prog_data->easf_h_bf2_roc_gain = 4; // U2.2, Rate Of Change control 1362 1363 dscl_prog_data->easf_h_bf1_pwl_in_seg0 = 0x600; // S0.10, BF1 PWL Segment 0 = -512 1364 dscl_prog_data->easf_h_bf1_pwl_base_seg0 = 0; // U0.6, BF1 Base PWL Segment 0 1365 dscl_prog_data->easf_h_bf1_pwl_slope_seg0 = 3; // S7.3, BF1 Slope PWL Segment 0 1366 dscl_prog_data->easf_h_bf1_pwl_in_seg1 = 0x7EC; // S0.10, BF1 PWL Segment 1 = -20 1367 dscl_prog_data->easf_h_bf1_pwl_base_seg1 = 12; // U0.6, BF1 Base PWL Segment 1 1368 dscl_prog_data->easf_h_bf1_pwl_slope_seg1 = 326; // S7.3, BF1 Slope PWL Segment 1 1369 dscl_prog_data->easf_h_bf1_pwl_in_seg2 = 0; // S0.10, BF1 PWL Segment 2 1370 dscl_prog_data->easf_h_bf1_pwl_base_seg2 = 63; // U0.6, BF1 Base PWL Segment 2 1371 dscl_prog_data->easf_h_bf1_pwl_slope_seg2 = 0; // S7.3, BF1 Slope PWL Segment 2 1372 dscl_prog_data->easf_h_bf1_pwl_in_seg3 = 16; // S0.10, BF1 PWL Segment 3 1373 dscl_prog_data->easf_h_bf1_pwl_base_seg3 = 63; // U0.6, BF1 Base PWL Segment 3 1374 dscl_prog_data->easf_h_bf1_pwl_slope_seg3 = 0x7C8; // S7.3, BF1 Slope PWL Segment 3 = -56 1375 dscl_prog_data->easf_h_bf1_pwl_in_seg4 = 32; // S0.10, BF1 PWL Segment 4 1376 dscl_prog_data->easf_h_bf1_pwl_base_seg4 = 56; // U0.6, BF1 Base PWL Segment 4 1377 dscl_prog_data->easf_h_bf1_pwl_slope_seg4 = 0x7D0; // S7.3, BF1 Slope PWL Segment 4 = -48 1378 dscl_prog_data->easf_h_bf1_pwl_in_seg5 = 48; // S0.10, BF1 PWL Segment 5 1379 dscl_prog_data->easf_h_bf1_pwl_base_seg5 = 50; // U0.6, BF1 Base PWL Segment 5 1380 dscl_prog_data->easf_h_bf1_pwl_slope_seg5 = 0x710; // S7.3, BF1 Slope PWL Segment 5 = -240 1381 dscl_prog_data->easf_h_bf1_pwl_in_seg6 = 64; // S0.10, BF1 PWL Segment 6 1382 dscl_prog_data->easf_h_bf1_pwl_base_seg6 = 20; // U0.6, BF1 Base PWL Segment 6 1383 dscl_prog_data->easf_h_bf1_pwl_slope_seg6 = 0x760; // S7.3, BF1 Slope PWL Segment 6 = -160 1384 dscl_prog_data->easf_h_bf1_pwl_in_seg7 = 80; // S0.10, BF1 PWL Segment 7 1385 dscl_prog_data->easf_h_bf1_pwl_base_seg7 = 0; // U0.6, BF1 Base PWL Segment 7 1386 1387 dscl_prog_data->easf_h_bf3_pwl_in_set0 = 0x000; // FP0.6.6, BF3 Input value PWL Segment 0 1388 dscl_prog_data->easf_h_bf3_pwl_base_set0 = 63; // S0.6, BF3 Base PWL Segment 0 1389 dscl_prog_data->easf_h_bf3_pwl_slope_set0 = 0x12C5; // FP1.6.6, BF3 Slope PWL Segment 0 1390 dscl_prog_data->easf_h_bf3_pwl_in_set1 = 1391 0x0B37; // FP0.6.6, BF3 Input value PWL Segment 1 (0.0078125 * 125^3) 1392 dscl_prog_data->easf_h_bf3_pwl_base_set1 = 62; // S0.6, BF3 Base PWL Segment 1 1393 dscl_prog_data->easf_h_bf3_pwl_slope_set1 = 0x13B8; // FP1.6.6, BF3 Slope PWL Segment 1 1394 dscl_prog_data->easf_h_bf3_pwl_in_set2 = 1395 0x0BB7; // FP0.6.6, BF3 Input value PWL Segment 2 (0.03125 * 125^3) 1396 dscl_prog_data->easf_h_bf3_pwl_base_set2 = 20; // S0.6, BF3 Base PWL Segment 2 1397 dscl_prog_data->easf_h_bf3_pwl_slope_set2 = 0x1356; // FP1.6.6, BF3 Slope PWL Segment 2 1398 dscl_prog_data->easf_h_bf3_pwl_in_set3 = 1399 0x0BF7; // FP0.6.6, BF3 Input value PWL Segment 3 (0.0625 * 125^3) 1400 dscl_prog_data->easf_h_bf3_pwl_base_set3 = 0; // S0.6, BF3 Base PWL Segment 3 1401 dscl_prog_data->easf_h_bf3_pwl_slope_set3 = 0x136B; // FP1.6.6, BF3 Slope PWL Segment 3 1402 dscl_prog_data->easf_h_bf3_pwl_in_set4 = 1403 0x0C37; // FP0.6.6, BF3 Input value PWL Segment 4 (0.125 * 125^3) 1404 dscl_prog_data->easf_h_bf3_pwl_base_set4 = 0x4E; // S0.6, BF3 Base PWL Segment 4 = -50 1405 dscl_prog_data->easf_h_bf3_pwl_slope_set4 = 0x1200; // FP1.6.6, BF3 Slope PWL Segment 4 1406 dscl_prog_data->easf_h_bf3_pwl_in_set5 = 1407 0x0CF7; // FP0.6.6, BF3 Input value PWL Segment 5 (1.0 * 125^3) 1408 dscl_prog_data->easf_h_bf3_pwl_base_set5 = 0x41; // S0.6, BF3 Base PWL Segment 5 = -63 1409 } else { 1410 dscl_prog_data->easf_h_bf2_flat1_gain = 13; // U1.3, BF2 Flat1 Gain control 1411 dscl_prog_data->easf_h_bf2_flat2_gain = 15; // U4.0, BF2 Flat2 Gain control 1412 dscl_prog_data->easf_h_bf2_roc_gain = 14; // U2.2, Rate Of Change control 1413 1414 dscl_prog_data->easf_h_bf1_pwl_in_seg0 = 0x440; // S0.10, BF1 PWL Segment 0 = -960 1415 dscl_prog_data->easf_h_bf1_pwl_base_seg0 = 0; // U0.6, BF1 Base PWL Segment 0 1416 dscl_prog_data->easf_h_bf1_pwl_slope_seg0 = 2; // S7.3, BF1 Slope PWL Segment 0 1417 dscl_prog_data->easf_h_bf1_pwl_in_seg1 = 0x7C4; // S0.10, BF1 PWL Segment 1 = -60 1418 dscl_prog_data->easf_h_bf1_pwl_base_seg1 = 12; // U0.6, BF1 Base PWL Segment 1 1419 dscl_prog_data->easf_h_bf1_pwl_slope_seg1 = 109; // S7.3, BF1 Slope PWL Segment 1 1420 dscl_prog_data->easf_h_bf1_pwl_in_seg2 = 0; // S0.10, BF1 PWL Segment 2 1421 dscl_prog_data->easf_h_bf1_pwl_base_seg2 = 63; // U0.6, BF1 Base PWL Segment 2 1422 dscl_prog_data->easf_h_bf1_pwl_slope_seg2 = 0; // S7.3, BF1 Slope PWL Segment 2 1423 dscl_prog_data->easf_h_bf1_pwl_in_seg3 = 48; // S0.10, BF1 PWL Segment 3 1424 dscl_prog_data->easf_h_bf1_pwl_base_seg3 = 63; // U0.6, BF1 Base PWL Segment 3 1425 dscl_prog_data->easf_h_bf1_pwl_slope_seg3 = 0x7ED; // S7.3, BF1 Slope PWL Segment 3 = -19 1426 dscl_prog_data->easf_h_bf1_pwl_in_seg4 = 96; // S0.10, BF1 PWL Segment 4 1427 dscl_prog_data->easf_h_bf1_pwl_base_seg4 = 56; // U0.6, BF1 Base PWL Segment 4 1428 dscl_prog_data->easf_h_bf1_pwl_slope_seg4 = 0x7F0; // S7.3, BF1 Slope PWL Segment 4 = -16 1429 dscl_prog_data->easf_h_bf1_pwl_in_seg5 = 144; // S0.10, BF1 PWL Segment 5 1430 dscl_prog_data->easf_h_bf1_pwl_base_seg5 = 50; // U0.6, BF1 Base PWL Segment 5 1431 dscl_prog_data->easf_h_bf1_pwl_slope_seg5 = 0x7B0; // S7.3, BF1 Slope PWL Segment 5 = -80 1432 dscl_prog_data->easf_h_bf1_pwl_in_seg6 = 192; // S0.10, BF1 PWL Segment 6 1433 dscl_prog_data->easf_h_bf1_pwl_base_seg6 = 20; // U0.6, BF1 Base PWL Segment 6 1434 dscl_prog_data->easf_h_bf1_pwl_slope_seg6 = 0x7CB; // S7.3, BF1 Slope PWL Segment 6 = -53 1435 dscl_prog_data->easf_h_bf1_pwl_in_seg7 = 240; // S0.10, BF1 PWL Segment 7 1436 dscl_prog_data->easf_h_bf1_pwl_base_seg7 = 0; // U0.6, BF1 Base PWL Segment 7 1437 1438 dscl_prog_data->easf_h_bf3_pwl_in_set0 = 0x000; // FP0.6.6, BF3 Input value PWL Segment 0 1439 dscl_prog_data->easf_h_bf3_pwl_base_set0 = 63; // S0.6, BF3 Base PWL Segment 0 1440 dscl_prog_data->easf_h_bf3_pwl_slope_set0 = 0x0000; // FP1.6.6, BF3 Slope PWL Segment 0 1441 dscl_prog_data->easf_h_bf3_pwl_in_set1 = 1442 0x06C0; // FP0.6.6, BF3 Input value PWL Segment 1 (0.0625) 1443 dscl_prog_data->easf_h_bf3_pwl_base_set1 = 63; // S0.6, BF3 Base PWL Segment 1 1444 dscl_prog_data->easf_h_bf3_pwl_slope_set1 = 0x1896; // FP1.6.6, BF3 Slope PWL Segment 1 1445 dscl_prog_data->easf_h_bf3_pwl_in_set2 = 1446 0x0700; // FP0.6.6, BF3 Input value PWL Segment 2 (0.125) 1447 dscl_prog_data->easf_h_bf3_pwl_base_set2 = 20; // S0.6, BF3 Base PWL Segment 2 1448 dscl_prog_data->easf_h_bf3_pwl_slope_set2 = 0x1810; // FP1.6.6, BF3 Slope PWL Segment 2 1449 dscl_prog_data->easf_h_bf3_pwl_in_set3 = 1450 0x0740; // FP0.6.6, BF3 Input value PWL Segment 3 (0.25) 1451 dscl_prog_data->easf_h_bf3_pwl_base_set3 = 0; // S0.6, BF3 Base PWL Segment 3 1452 dscl_prog_data->easf_h_bf3_pwl_slope_set3 = 0x1878; // FP1.6.6, BF3 Slope PWL Segment 3 1453 dscl_prog_data->easf_h_bf3_pwl_in_set4 = 1454 0x0761; // FP0.6.6, BF3 Input value PWL Segment 4 (0.375) 1455 dscl_prog_data->easf_h_bf3_pwl_base_set4 = 0x44; // S0.6, BF3 Base PWL Segment 4 = -60 1456 dscl_prog_data->easf_h_bf3_pwl_slope_set4 = 0x1760; // FP1.6.6, BF3 Slope PWL Segment 4 1457 dscl_prog_data->easf_h_bf3_pwl_in_set5 = 1458 0x0780; // FP0.6.6, BF3 Input value PWL Segment 5 (0.5) 1459 dscl_prog_data->easf_h_bf3_pwl_base_set5 = 0x41; // S0.6, BF3 Base PWL Segment 5 = -63 1460 } // if (lls_pref == LLS_PREF_YES) 1461 } else 1462 dscl_prog_data->easf_h_en = false; 1463 1464 if (lls_pref == LLS_PREF_YES) { 1465 dscl_prog_data->easf_ltonl_en = 1; // Linear input 1466 if (setup == HDR_L) { 1467 dscl_prog_data->easf_matrix_c0 = 1468 0x504E; // fp1.5.10, C0 coefficient (LN_BT2020: 0.2627 * (2^14)/125 = 34.43750000) 1469 dscl_prog_data->easf_matrix_c1 = 1470 0x558E; // fp1.5.10, C1 coefficient (LN_BT2020: 0.6780 * (2^14)/125 = 88.87500000) 1471 dscl_prog_data->easf_matrix_c2 = 1472 0x47C6; // fp1.5.10, C2 coefficient (LN_BT2020: 0.0593 * (2^14)/125 = 7.77343750) 1473 dscl_prog_data->easf_matrix_c3 = 1474 0x0; // fp1.5.10, C3 coefficient 1475 } else { // SDR_L 1476 dscl_prog_data->easf_matrix_c0 = 1477 0x4EF7; // fp1.5.10, C0 coefficient (LN_rec709: 0.2126 * (2^14)/125 = 27.86590720) 1478 dscl_prog_data->easf_matrix_c1 = 1479 0x55DC; // fp1.5.10, C1 coefficient (LN_rec709: 0.7152 * (2^14)/125 = 93.74269440) 1480 dscl_prog_data->easf_matrix_c2 = 1481 0x48BB; // fp1.5.10, C2 coefficient (LN_rec709: 0.0722 * (2^14)/125 = 9.46339840) 1482 dscl_prog_data->easf_matrix_c3 = 1483 0x0; // fp1.5.10, C3 coefficient 1484 } 1485 } else { 1486 dscl_prog_data->easf_ltonl_en = 0; // Non-Linear input 1487 dscl_prog_data->easf_matrix_c0 = 1488 0x3434; // fp1.5.10, C0 coefficient (LN_BT2020: 0.262695312500000) 1489 dscl_prog_data->easf_matrix_c1 = 1490 0x396D; // fp1.5.10, C1 coefficient (LN_BT2020: 0.678222656250000) 1491 dscl_prog_data->easf_matrix_c2 = 1492 0x2B97; // fp1.5.10, C2 coefficient (LN_BT2020: 0.059295654296875) 1493 dscl_prog_data->easf_matrix_c3 = 1494 0x0; // fp1.5.10, C3 coefficient 1495 } 1496 1497 if (spl_is_yuv420(format)) { /* TODO: 0 = RGB, 1 = YUV */ 1498 dscl_prog_data->easf_matrix_mode = 1; 1499 /* 1500 * 2-bit, BF3 chroma mode correction calculation mode 1501 * Needs to be disabled for YUV420 mode 1502 * Override lookup value 1503 */ 1504 dscl_prog_data->easf_v_bf3_mode = 0; 1505 dscl_prog_data->easf_h_bf3_mode = 0; 1506 } else 1507 dscl_prog_data->easf_matrix_mode = 0; 1508 1509 } 1510 1511 /*Set isharp noise detection */ 1512 static void spl_set_isharp_noise_det_mode(struct dscl_prog_data *dscl_prog_data, 1513 const struct spl_scaler_data *data) 1514 { 1515 // ISHARP_NOISEDET_MODE 1516 // 0: 3x5 as VxH 1517 // 1: 4x5 as VxH 1518 // 2: 1519 // 3: 5x5 as VxH 1520 if (data->taps.v_taps == 6) 1521 dscl_prog_data->isharp_noise_det.mode = 3; 1522 else if (data->taps.v_taps == 4) 1523 dscl_prog_data->isharp_noise_det.mode = 1; 1524 else if (data->taps.v_taps == 3) 1525 dscl_prog_data->isharp_noise_det.mode = 0; 1526 }; 1527 /* Set Sharpener data */ 1528 static void spl_set_isharp_data(struct dscl_prog_data *dscl_prog_data, 1529 struct adaptive_sharpness adp_sharpness, bool enable_isharp, 1530 enum linear_light_scaling lls_pref, enum spl_pixel_format format, 1531 const struct spl_scaler_data *data, struct spl_fixed31_32 ratio, 1532 enum system_setup setup) 1533 { 1534 /* Turn off sharpener if not required */ 1535 if (!enable_isharp) { 1536 dscl_prog_data->isharp_en = 0; 1537 return; 1538 } 1539 1540 dscl_prog_data->isharp_en = 1; // ISHARP_EN 1541 // Set ISHARP_NOISEDET_MODE if htaps = 6-tap 1542 if (data->taps.h_taps == 6) { 1543 dscl_prog_data->isharp_noise_det.enable = 1; /* ISHARP_NOISEDET_EN */ 1544 spl_set_isharp_noise_det_mode(dscl_prog_data, data); /* ISHARP_NOISEDET_MODE */ 1545 } else 1546 dscl_prog_data->isharp_noise_det.enable = 0; // ISHARP_NOISEDET_EN 1547 // Program noise detection threshold 1548 dscl_prog_data->isharp_noise_det.uthreshold = 24; // ISHARP_NOISEDET_UTHRE 1549 dscl_prog_data->isharp_noise_det.dthreshold = 4; // ISHARP_NOISEDET_DTHRE 1550 // Program noise detection gain 1551 dscl_prog_data->isharp_noise_det.pwl_start_in = 3; // ISHARP_NOISEDET_PWL_START_IN 1552 dscl_prog_data->isharp_noise_det.pwl_end_in = 13; // ISHARP_NOISEDET_PWL_END_IN 1553 dscl_prog_data->isharp_noise_det.pwl_slope = 1623; // ISHARP_NOISEDET_PWL_SLOPE 1554 1555 if (lls_pref == LLS_PREF_NO) /* ISHARP_FMT_MODE */ 1556 dscl_prog_data->isharp_fmt.mode = 1; 1557 else 1558 dscl_prog_data->isharp_fmt.mode = 0; 1559 1560 dscl_prog_data->isharp_fmt.norm = 0x3C00; // ISHARP_FMT_NORM 1561 dscl_prog_data->isharp_lba.mode = 0; // ISHARP_LBA_MODE 1562 if (setup == SDR_L) { 1563 // ISHARP_LBA_PWL_SEG0: ISHARP Local Brightness Adjustment PWL Segment 0 1564 dscl_prog_data->isharp_lba.in_seg[0] = 0; // ISHARP LBA PWL for Seg 0. INPUT value in U0.10 format 1565 dscl_prog_data->isharp_lba.base_seg[0] = 0; // ISHARP LBA PWL for Seg 0. BASE value in U0.6 format 1566 dscl_prog_data->isharp_lba.slope_seg[0] = 62; // ISHARP LBA for Seg 0. SLOPE value in S5.3 format 1567 // ISHARP_LBA_PWL_SEG1: ISHARP LBA PWL Segment 1 1568 dscl_prog_data->isharp_lba.in_seg[1] = 130; // ISHARP LBA PWL for Seg 1. INPUT value in U0.10 format 1569 dscl_prog_data->isharp_lba.base_seg[1] = 63; // ISHARP LBA PWL for Seg 1. BASE value in U0.6 format 1570 dscl_prog_data->isharp_lba.slope_seg[1] = 0; // ISHARP LBA for Seg 1. SLOPE value in S5.3 format 1571 // ISHARP_LBA_PWL_SEG2: ISHARP LBA PWL Segment 2 1572 dscl_prog_data->isharp_lba.in_seg[2] = 312; // ISHARP LBA PWL for Seg 2. INPUT value in U0.10 format 1573 dscl_prog_data->isharp_lba.base_seg[2] = 63; // ISHARP LBA PWL for Seg 2. BASE value in U0.6 format 1574 dscl_prog_data->isharp_lba.slope_seg[2] = 0x1D9; // ISHARP LBA for Seg 2. SLOPE value in S5.3 format = -39 1575 // ISHARP_LBA_PWL_SEG3: ISHARP LBA PWL Segment 3 1576 dscl_prog_data->isharp_lba.in_seg[3] = 520; // ISHARP LBA PWL for Seg 3.INPUT value in U0.10 format 1577 dscl_prog_data->isharp_lba.base_seg[3] = 0; // ISHARP LBA PWL for Seg 3. BASE value in U0.6 format 1578 dscl_prog_data->isharp_lba.slope_seg[3] = 0; // ISHARP LBA for Seg 3. SLOPE value in S5.3 format 1579 // ISHARP_LBA_PWL_SEG4: ISHARP LBA PWL Segment 4 1580 dscl_prog_data->isharp_lba.in_seg[4] = 520; // ISHARP LBA PWL for Seg 4.INPUT value in U0.10 format 1581 dscl_prog_data->isharp_lba.base_seg[4] = 0; // ISHARP LBA PWL for Seg 4. BASE value in U0.6 format 1582 dscl_prog_data->isharp_lba.slope_seg[4] = 0; // ISHARP LBA for Seg 4. SLOPE value in S5.3 format 1583 // ISHARP_LBA_PWL_SEG5: ISHARP LBA PWL Segment 5 1584 dscl_prog_data->isharp_lba.in_seg[5] = 520; // ISHARP LBA PWL for Seg 5.INPUT value in U0.10 format 1585 dscl_prog_data->isharp_lba.base_seg[5] = 0; // ISHARP LBA PWL for Seg 5. BASE value in U0.6 format 1586 } else { 1587 // ISHARP_LBA_PWL_SEG0: ISHARP Local Brightness Adjustment PWL Segment 0 1588 dscl_prog_data->isharp_lba.in_seg[0] = 0; // ISHARP LBA PWL for Seg 0. INPUT value in U0.10 format 1589 dscl_prog_data->isharp_lba.base_seg[0] = 0; // ISHARP LBA PWL for Seg 0. BASE value in U0.6 format 1590 dscl_prog_data->isharp_lba.slope_seg[0] = 32; // ISHARP LBA for Seg 0. SLOPE value in S5.3 format 1591 // ISHARP_LBA_PWL_SEG1: ISHARP LBA PWL Segment 1 1592 dscl_prog_data->isharp_lba.in_seg[1] = 256; // ISHARP LBA PWL for Seg 1. INPUT value in U0.10 format 1593 dscl_prog_data->isharp_lba.base_seg[1] = 63; // ISHARP LBA PWL for Seg 1. BASE value in U0.6 format 1594 dscl_prog_data->isharp_lba.slope_seg[1] = 0; // ISHARP LBA for Seg 1. SLOPE value in S5.3 format 1595 // ISHARP_LBA_PWL_SEG2: ISHARP LBA PWL Segment 2 1596 dscl_prog_data->isharp_lba.in_seg[2] = 614; // ISHARP LBA PWL for Seg 2. INPUT value in U0.10 format 1597 dscl_prog_data->isharp_lba.base_seg[2] = 63; // ISHARP LBA PWL for Seg 2. BASE value in U0.6 format 1598 dscl_prog_data->isharp_lba.slope_seg[2] = 0x1EC; // ISHARP LBA for Seg 2. SLOPE value in S5.3 format = -20 1599 // ISHARP_LBA_PWL_SEG3: ISHARP LBA PWL Segment 3 1600 dscl_prog_data->isharp_lba.in_seg[3] = 1023; // ISHARP LBA PWL for Seg 3.INPUT value in U0.10 format 1601 dscl_prog_data->isharp_lba.base_seg[3] = 0; // ISHARP LBA PWL for Seg 3. BASE value in U0.6 format 1602 dscl_prog_data->isharp_lba.slope_seg[3] = 0; // ISHARP LBA for Seg 3. SLOPE value in S5.3 format 1603 // ISHARP_LBA_PWL_SEG4: ISHARP LBA PWL Segment 4 1604 dscl_prog_data->isharp_lba.in_seg[4] = 1023; // ISHARP LBA PWL for Seg 4.INPUT value in U0.10 format 1605 dscl_prog_data->isharp_lba.base_seg[4] = 0; // ISHARP LBA PWL for Seg 4. BASE value in U0.6 format 1606 dscl_prog_data->isharp_lba.slope_seg[4] = 0; // ISHARP LBA for Seg 4. SLOPE value in S5.3 format 1607 // ISHARP_LBA_PWL_SEG5: ISHARP LBA PWL Segment 5 1608 dscl_prog_data->isharp_lba.in_seg[5] = 1023; // ISHARP LBA PWL for Seg 5.INPUT value in U0.10 format 1609 dscl_prog_data->isharp_lba.base_seg[5] = 0; // ISHARP LBA PWL for Seg 5. BASE value in U0.6 format 1610 } 1611 1612 spl_build_isharp_1dlut_from_reference_curve(ratio, setup); 1613 dscl_prog_data->isharp_delta = spl_get_pregen_filter_isharp_1D_lut( 1614 adp_sharpness.sharpness); 1615 1616 // Program the nldelta soft clip values 1617 if (lls_pref == LLS_PREF_YES) { 1618 dscl_prog_data->isharp_nldelta_sclip.enable_p = 0; /* ISHARP_NLDELTA_SCLIP_EN_P */ 1619 dscl_prog_data->isharp_nldelta_sclip.pivot_p = 0; /* ISHARP_NLDELTA_SCLIP_PIVOT_P */ 1620 dscl_prog_data->isharp_nldelta_sclip.slope_p = 0; /* ISHARP_NLDELTA_SCLIP_SLOPE_P */ 1621 dscl_prog_data->isharp_nldelta_sclip.enable_n = 1; /* ISHARP_NLDELTA_SCLIP_EN_N */ 1622 dscl_prog_data->isharp_nldelta_sclip.pivot_n = 71; /* ISHARP_NLDELTA_SCLIP_PIVOT_N */ 1623 dscl_prog_data->isharp_nldelta_sclip.slope_n = 16; /* ISHARP_NLDELTA_SCLIP_SLOPE_N */ 1624 } else { 1625 dscl_prog_data->isharp_nldelta_sclip.enable_p = 1; /* ISHARP_NLDELTA_SCLIP_EN_P */ 1626 dscl_prog_data->isharp_nldelta_sclip.pivot_p = 70; /* ISHARP_NLDELTA_SCLIP_PIVOT_P */ 1627 dscl_prog_data->isharp_nldelta_sclip.slope_p = 24; /* ISHARP_NLDELTA_SCLIP_SLOPE_P */ 1628 dscl_prog_data->isharp_nldelta_sclip.enable_n = 1; /* ISHARP_NLDELTA_SCLIP_EN_N */ 1629 dscl_prog_data->isharp_nldelta_sclip.pivot_n = 70; /* ISHARP_NLDELTA_SCLIP_PIVOT_N */ 1630 dscl_prog_data->isharp_nldelta_sclip.slope_n = 24; /* ISHARP_NLDELTA_SCLIP_SLOPE_N */ 1631 } 1632 1633 // Set the values as per lookup table 1634 spl_set_blur_scale_data(dscl_prog_data, data); 1635 } 1636 1637 /* Calculate scaler parameters */ 1638 bool spl_calculate_scaler_params(struct spl_in *spl_in, struct spl_out *spl_out) 1639 { 1640 bool res = false; 1641 bool enable_easf_v = false; 1642 bool enable_easf_h = false; 1643 int vratio = 0; 1644 int hratio = 0; 1645 struct spl_scratch spl_scratch; 1646 struct spl_fixed31_32 isharp_scale_ratio; 1647 enum system_setup setup; 1648 bool enable_isharp = false; 1649 const struct spl_scaler_data *data = &spl_scratch.scl_data; 1650 1651 memset(&spl_scratch, 0, sizeof(struct spl_scratch)); 1652 spl_scratch.scl_data.h_active = spl_in->h_active; 1653 spl_scratch.scl_data.v_active = spl_in->v_active; 1654 // All SPL calls 1655 /* recout calculation */ 1656 /* depends on h_active */ 1657 spl_calculate_recout(spl_in, &spl_scratch, spl_out); 1658 /* depends on pixel format */ 1659 spl_calculate_scaling_ratios(spl_in, &spl_scratch, spl_out); 1660 /* depends on scaling ratios and recout, does not calculate offset yet */ 1661 spl_calculate_viewport_size(spl_in, &spl_scratch); 1662 1663 res = spl_get_optimal_number_of_taps( 1664 spl_in->basic_out.max_downscale_src_width, spl_in, 1665 &spl_scratch, &spl_in->scaling_quality, &enable_easf_v, 1666 &enable_easf_h, &enable_isharp); 1667 /* 1668 * Depends on recout, scaling ratios, h_active and taps 1669 * May need to re-check lb size after this in some obscure scenario 1670 */ 1671 if (res) 1672 spl_calculate_inits_and_viewports(spl_in, &spl_scratch); 1673 // Handle 3d recout 1674 spl_handle_3d_recout(spl_in, &spl_scratch.scl_data.recout); 1675 // Clamp 1676 spl_clamp_viewport(&spl_scratch.scl_data.viewport); 1677 1678 if (!res) 1679 return res; 1680 1681 // Save all calculated parameters in dscl_prog_data structure to program hw registers 1682 spl_set_dscl_prog_data(spl_in, &spl_scratch, spl_out, enable_easf_v, enable_easf_h, enable_isharp); 1683 1684 if (spl_in->lls_pref == LLS_PREF_YES) { 1685 if (spl_in->is_hdr_on) 1686 setup = HDR_L; 1687 else 1688 setup = SDR_L; 1689 } else { 1690 if (spl_in->is_hdr_on) 1691 setup = HDR_NL; 1692 else 1693 setup = SDR_NL; 1694 } 1695 // Set EASF 1696 spl_set_easf_data(&spl_scratch, spl_out, enable_easf_v, enable_easf_h, spl_in->lls_pref, 1697 spl_in->basic_in.format, setup); 1698 // Set iSHARP 1699 vratio = spl_fixpt_ceil(spl_scratch.scl_data.ratios.vert); 1700 hratio = spl_fixpt_ceil(spl_scratch.scl_data.ratios.horz); 1701 if (vratio <= hratio) 1702 isharp_scale_ratio = spl_scratch.scl_data.recip_ratios.vert; 1703 else 1704 isharp_scale_ratio = spl_scratch.scl_data.recip_ratios.horz; 1705 1706 spl_set_isharp_data(spl_out->dscl_prog_data, spl_in->adaptive_sharpness, enable_isharp, 1707 spl_in->lls_pref, spl_in->basic_in.format, data, isharp_scale_ratio, setup); 1708 1709 return res; 1710 } 1711