1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
3  */
4 
5 #ifndef _DPU_HW_SSPP_H
6 #define _DPU_HW_SSPP_H
7 
8 #include "dpu_hw_catalog.h"
9 #include "dpu_hw_mdss.h"
10 #include "dpu_hw_util.h"
11 #include "dpu_hw_blk.h"
12 #include "dpu_formats.h"
13 
14 struct dpu_hw_pipe;
15 
16 /**
17  * Flags
18  */
19 #define DPU_SSPP_FLIP_LR		BIT(0)
20 #define DPU_SSPP_FLIP_UD		BIT(1)
21 #define DPU_SSPP_SOURCE_ROTATED_90	BIT(2)
22 #define DPU_SSPP_ROT_90			BIT(3)
23 #define DPU_SSPP_SOLID_FILL		BIT(4)
24 
25 /**
26  * Define all scaler feature bits in catalog
27  */
28 #define DPU_SSPP_SCALER (BIT(DPU_SSPP_SCALER_RGB) | \
29 			 BIT(DPU_SSPP_SCALER_QSEED2) | \
30 			 BIT(DPU_SSPP_SCALER_QSEED3) | \
31 			 BIT(DPU_SSPP_SCALER_QSEED3LITE) | \
32 			 BIT(DPU_SSPP_SCALER_QSEED4))
33 
34 /*
35  * Define all CSC feature bits in catalog
36  */
37 #define DPU_SSPP_CSC_ANY (BIT(DPU_SSPP_CSC) | \
38 			  BIT(DPU_SSPP_CSC_10BIT))
39 
40 /**
41  * Component indices
42  */
43 enum {
44 	DPU_SSPP_COMP_0,
45 	DPU_SSPP_COMP_1_2,
46 	DPU_SSPP_COMP_2,
47 	DPU_SSPP_COMP_3,
48 
49 	DPU_SSPP_COMP_MAX
50 };
51 
52 /**
53  * DPU_SSPP_RECT_SOLO - multirect disabled
54  * DPU_SSPP_RECT_0 - rect0 of a multirect pipe
55  * DPU_SSPP_RECT_1 - rect1 of a multirect pipe
56  *
57  * Note: HW supports multirect with either RECT0 or
58  * RECT1. Considering no benefit of such configs over
59  * SOLO mode and to keep the plane management simple,
60  * we dont support single rect multirect configs.
61  */
62 enum dpu_sspp_multirect_index {
63 	DPU_SSPP_RECT_SOLO = 0,
64 	DPU_SSPP_RECT_0,
65 	DPU_SSPP_RECT_1,
66 };
67 
68 enum dpu_sspp_multirect_mode {
69 	DPU_SSPP_MULTIRECT_NONE = 0,
70 	DPU_SSPP_MULTIRECT_PARALLEL,
71 	DPU_SSPP_MULTIRECT_TIME_MX,
72 };
73 
74 enum {
75 	DPU_FRAME_LINEAR,
76 	DPU_FRAME_TILE_A4X,
77 	DPU_FRAME_TILE_A5X,
78 };
79 
80 enum dpu_hw_filter {
81 	DPU_SCALE_FILTER_NEAREST = 0,
82 	DPU_SCALE_FILTER_BIL,
83 	DPU_SCALE_FILTER_PCMN,
84 	DPU_SCALE_FILTER_CA,
85 	DPU_SCALE_FILTER_MAX
86 };
87 
88 enum dpu_hw_filter_alpa {
89 	DPU_SCALE_ALPHA_PIXEL_REP,
90 	DPU_SCALE_ALPHA_BIL
91 };
92 
93 enum dpu_hw_filter_yuv {
94 	DPU_SCALE_2D_4X4,
95 	DPU_SCALE_2D_CIR,
96 	DPU_SCALE_1D_SEP,
97 	DPU_SCALE_BIL
98 };
99 
100 struct dpu_hw_sharp_cfg {
101 	u32 strength;
102 	u32 edge_thr;
103 	u32 smooth_thr;
104 	u32 noise_thr;
105 };
106 
107 struct dpu_hw_pixel_ext {
108 	/* scaling factors are enabled for this input layer */
109 	uint8_t enable_pxl_ext;
110 
111 	int init_phase_x[DPU_MAX_PLANES];
112 	int phase_step_x[DPU_MAX_PLANES];
113 	int init_phase_y[DPU_MAX_PLANES];
114 	int phase_step_y[DPU_MAX_PLANES];
115 
116 	/*
117 	 * Number of pixels extension in left, right, top and bottom direction
118 	 * for all color components. This pixel value for each color component
119 	 * should be sum of fetch + repeat pixels.
120 	 */
121 	int num_ext_pxls_left[DPU_MAX_PLANES];
122 	int num_ext_pxls_right[DPU_MAX_PLANES];
123 	int num_ext_pxls_top[DPU_MAX_PLANES];
124 	int num_ext_pxls_btm[DPU_MAX_PLANES];
125 
126 	/*
127 	 * Number of pixels needs to be overfetched in left, right, top and
128 	 * bottom directions from source image for scaling.
129 	 */
130 	int left_ftch[DPU_MAX_PLANES];
131 	int right_ftch[DPU_MAX_PLANES];
132 	int top_ftch[DPU_MAX_PLANES];
133 	int btm_ftch[DPU_MAX_PLANES];
134 
135 	/*
136 	 * Number of pixels needs to be repeated in left, right, top and
137 	 * bottom directions for scaling.
138 	 */
139 	int left_rpt[DPU_MAX_PLANES];
140 	int right_rpt[DPU_MAX_PLANES];
141 	int top_rpt[DPU_MAX_PLANES];
142 	int btm_rpt[DPU_MAX_PLANES];
143 
144 	uint32_t roi_w[DPU_MAX_PLANES];
145 	uint32_t roi_h[DPU_MAX_PLANES];
146 
147 	/*
148 	 * Filter type to be used for scaling in horizontal and vertical
149 	 * directions
150 	 */
151 	enum dpu_hw_filter horz_filter[DPU_MAX_PLANES];
152 	enum dpu_hw_filter vert_filter[DPU_MAX_PLANES];
153 
154 };
155 
156 /**
157  * struct dpu_hw_pipe_cfg : Pipe description
158  * @layout:    format layout information for programming buffer to hardware
159  * @src_rect:  src ROI, caller takes into account the different operations
160  *             such as decimation, flip etc to program this field
161  * @dest_rect: destination ROI.
162  * @index:     index of the rectangle of SSPP
163  * @mode:      parallel or time multiplex multirect mode
164  */
165 struct dpu_hw_pipe_cfg {
166 	struct dpu_hw_fmt_layout layout;
167 	struct drm_rect src_rect;
168 	struct drm_rect dst_rect;
169 	enum dpu_sspp_multirect_index index;
170 	enum dpu_sspp_multirect_mode mode;
171 };
172 
173 /**
174  * struct dpu_hw_pipe_qos_cfg : Source pipe QoS configuration
175  * @creq_vblank: creq value generated to vbif during vertical blanking
176  * @danger_vblank: danger value generated during vertical blanking
177  * @vblank_en: enable creq_vblank and danger_vblank during vblank
178  * @danger_safe_en: enable danger safe generation
179  */
180 struct dpu_hw_pipe_qos_cfg {
181 	u32 creq_vblank;
182 	u32 danger_vblank;
183 	bool vblank_en;
184 	bool danger_safe_en;
185 };
186 
187 /**
188  * enum CDP preload ahead address size
189  */
190 enum {
191 	DPU_SSPP_CDP_PRELOAD_AHEAD_32,
192 	DPU_SSPP_CDP_PRELOAD_AHEAD_64
193 };
194 
195 /**
196  * struct dpu_hw_pipe_cdp_cfg : CDP configuration
197  * @enable: true to enable CDP
198  * @ubwc_meta_enable: true to enable ubwc metadata preload
199  * @tile_amortize_enable: true to enable amortization control for tile format
200  * @preload_ahead: number of request to preload ahead
201  *	DPU_SSPP_CDP_PRELOAD_AHEAD_32,
202  *	DPU_SSPP_CDP_PRELOAD_AHEAD_64
203  */
204 struct dpu_hw_pipe_cdp_cfg {
205 	bool enable;
206 	bool ubwc_meta_enable;
207 	bool tile_amortize_enable;
208 	u32 preload_ahead;
209 };
210 
211 /**
212  * struct dpu_hw_pipe_ts_cfg - traffic shaper configuration
213  * @size: size to prefill in bytes, or zero to disable
214  * @time: time to prefill in usec, or zero to disable
215  */
216 struct dpu_hw_pipe_ts_cfg {
217 	u64 size;
218 	u64 time;
219 };
220 
221 /**
222  * struct dpu_hw_sspp_ops - interface to the SSPP Hw driver functions
223  * Caller must call the init function to get the pipe context for each pipe
224  * Assumption is these functions will be called after clocks are enabled
225  */
226 struct dpu_hw_sspp_ops {
227 	/**
228 	 * setup_format - setup pixel format cropping rectangle, flip
229 	 * @ctx: Pointer to pipe context
230 	 * @cfg: Pointer to pipe config structure
231 	 * @flags: Extra flags for format config
232 	 * @index: rectangle index in multirect
233 	 */
234 	void (*setup_format)(struct dpu_hw_pipe *ctx,
235 			const struct dpu_format *fmt, u32 flags,
236 			enum dpu_sspp_multirect_index index);
237 
238 	/**
239 	 * setup_rects - setup pipe ROI rectangles
240 	 * @ctx: Pointer to pipe context
241 	 * @cfg: Pointer to pipe config structure
242 	 * @index: rectangle index in multirect
243 	 */
244 	void (*setup_rects)(struct dpu_hw_pipe *ctx,
245 			struct dpu_hw_pipe_cfg *cfg,
246 			enum dpu_sspp_multirect_index index);
247 
248 	/**
249 	 * setup_pe - setup pipe pixel extension
250 	 * @ctx: Pointer to pipe context
251 	 * @pe_ext: Pointer to pixel ext settings
252 	 */
253 	void (*setup_pe)(struct dpu_hw_pipe *ctx,
254 			struct dpu_hw_pixel_ext *pe_ext);
255 
256 	/**
257 	 * setup_sourceaddress - setup pipe source addresses
258 	 * @ctx: Pointer to pipe context
259 	 * @cfg: Pointer to pipe config structure
260 	 * @index: rectangle index in multirect
261 	 */
262 	void (*setup_sourceaddress)(struct dpu_hw_pipe *ctx,
263 			struct dpu_hw_pipe_cfg *cfg,
264 			enum dpu_sspp_multirect_index index);
265 
266 	/**
267 	 * setup_csc - setup color space coversion
268 	 * @ctx: Pointer to pipe context
269 	 * @data: Pointer to config structure
270 	 */
271 	void (*setup_csc)(struct dpu_hw_pipe *ctx, const struct dpu_csc_cfg *data);
272 
273 	/**
274 	 * setup_solidfill - enable/disable colorfill
275 	 * @ctx: Pointer to pipe context
276 	 * @const_color: Fill color value
277 	 * @flags: Pipe flags
278 	 * @index: rectangle index in multirect
279 	 */
280 	void (*setup_solidfill)(struct dpu_hw_pipe *ctx, u32 color,
281 			enum dpu_sspp_multirect_index index);
282 
283 	/**
284 	 * setup_multirect - setup multirect configuration
285 	 * @ctx: Pointer to pipe context
286 	 * @index: rectangle index in multirect
287 	 * @mode: parallel fetch / time multiplex multirect mode
288 	 */
289 
290 	void (*setup_multirect)(struct dpu_hw_pipe *ctx,
291 			enum dpu_sspp_multirect_index index,
292 			enum dpu_sspp_multirect_mode mode);
293 
294 	/**
295 	 * setup_sharpening - setup sharpening
296 	 * @ctx: Pointer to pipe context
297 	 * @cfg: Pointer to config structure
298 	 */
299 	void (*setup_sharpening)(struct dpu_hw_pipe *ctx,
300 			struct dpu_hw_sharp_cfg *cfg);
301 
302 	/**
303 	 * setup_danger_safe_lut - setup danger safe LUTs
304 	 * @ctx: Pointer to pipe context
305 	 * @danger_lut: LUT for generate danger level based on fill level
306 	 * @safe_lut: LUT for generate safe level based on fill level
307 	 *
308 	 */
309 	void (*setup_danger_safe_lut)(struct dpu_hw_pipe *ctx,
310 			u32 danger_lut,
311 			u32 safe_lut);
312 
313 	/**
314 	 * setup_creq_lut - setup CREQ LUT
315 	 * @ctx: Pointer to pipe context
316 	 * @creq_lut: LUT for generate creq level based on fill level
317 	 *
318 	 */
319 	void (*setup_creq_lut)(struct dpu_hw_pipe *ctx,
320 			u64 creq_lut);
321 
322 	/**
323 	 * setup_qos_ctrl - setup QoS control
324 	 * @ctx: Pointer to pipe context
325 	 * @cfg: Pointer to pipe QoS configuration
326 	 *
327 	 */
328 	void (*setup_qos_ctrl)(struct dpu_hw_pipe *ctx,
329 			struct dpu_hw_pipe_qos_cfg *cfg);
330 
331 	/**
332 	 * setup_histogram - setup histograms
333 	 * @ctx: Pointer to pipe context
334 	 * @cfg: Pointer to histogram configuration
335 	 */
336 	void (*setup_histogram)(struct dpu_hw_pipe *ctx,
337 			void *cfg);
338 
339 	/**
340 	 * setup_scaler - setup scaler
341 	 * @ctx: Pointer to pipe context
342 	 * @pipe_cfg: Pointer to pipe configuration
343 	 * @scaler_cfg: Pointer to scaler configuration
344 	 */
345 	void (*setup_scaler)(struct dpu_hw_pipe *ctx,
346 		struct dpu_hw_pipe_cfg *pipe_cfg,
347 		void *scaler_cfg);
348 
349 	/**
350 	 * get_scaler_ver - get scaler h/w version
351 	 * @ctx: Pointer to pipe context
352 	 */
353 	u32 (*get_scaler_ver)(struct dpu_hw_pipe *ctx);
354 
355 	/**
356 	 * setup_cdp - setup client driven prefetch
357 	 * @ctx: Pointer to pipe context
358 	 * @cfg: Pointer to cdp configuration
359 	 * @index: rectangle index in multirect
360 	 */
361 	void (*setup_cdp)(struct dpu_hw_pipe *ctx,
362 			struct dpu_hw_pipe_cdp_cfg *cfg,
363 			enum dpu_sspp_multirect_index index);
364 };
365 
366 /**
367  * struct dpu_hw_pipe - pipe description
368  * @base: hardware block base structure
369  * @hw: block hardware details
370  * @catalog: back pointer to catalog
371  * @mdp: pointer to associated mdp portion of the catalog
372  * @idx: pipe index
373  * @cap: pointer to layer_cfg
374  * @ops: pointer to operations possible for this pipe
375  */
376 struct dpu_hw_pipe {
377 	struct dpu_hw_blk base;
378 	struct dpu_hw_blk_reg_map hw;
379 	struct dpu_mdss_cfg *catalog;
380 	const struct dpu_mdp_cfg *mdp;
381 
382 	/* Pipe */
383 	enum dpu_sspp idx;
384 	const struct dpu_sspp_cfg *cap;
385 
386 	/* Ops */
387 	struct dpu_hw_sspp_ops ops;
388 };
389 
390 struct dpu_kms;
391 /**
392  * dpu_hw_sspp_init - initializes the sspp hw driver object.
393  * Should be called once before accessing every pipe.
394  * @idx:  Pipe index for which driver object is required
395  * @addr: Mapped register io address of MDP
396  * @catalog : Pointer to mdss catalog data
397  * @is_virtual_pipe: is this pipe virtual pipe
398  */
399 struct dpu_hw_pipe *dpu_hw_sspp_init(enum dpu_sspp idx,
400 		void __iomem *addr, struct dpu_mdss_cfg *catalog,
401 		bool is_virtual_pipe);
402 
403 /**
404  * dpu_hw_sspp_destroy(): Destroys SSPP driver context
405  * should be called during Hw pipe cleanup.
406  * @ctx:  Pointer to SSPP driver context returned by dpu_hw_sspp_init
407  */
408 void dpu_hw_sspp_destroy(struct dpu_hw_pipe *ctx);
409 
410 void dpu_debugfs_sspp_init(struct dpu_kms *dpu_kms, struct dentry *debugfs_root);
411 int _dpu_hw_sspp_init_debugfs(struct dpu_hw_pipe *hw_pipe, struct dpu_kms *kms, struct dentry *entry);
412 
413 #endif /*_DPU_HW_SSPP_H */
414 
415