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