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