• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * include/linux/amlogic/media/vfm/vframe.h
3  *
4  * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  */
17 
18 #ifndef VFRAME_H
19 #define VFRAME_H
20 
21 #include <linux/types.h>
22 #include <linux/amlogic/media/frame_provider/tvin/tvin.h>
23 #include <linux/amlogic/media/canvas/canvas.h>
24 #include <linux/atomic.h>
25 #include <linux/amlogic/iomap.h>
26 
27 #define VIDTYPE_PROGRESSIVE             0x0
28 #define VIDTYPE_INTERLACE_TOP           0x1
29 #define VIDTYPE_INTERLACE_BOTTOM        0x3
30 #define VIDTYPE_TYPEMASK                0x7
31 #define VIDTYPE_INTERLACE               0x1
32 #define VIDTYPE_INTERLACE_FIRST         0x8
33 #define VIDTYPE_MVC                     0x10
34 #define VIDTYPE_NO_VIDEO_ENABLE         0x20
35 #define VIDTYPE_VIU_NV12                0x80
36 #define VIDTYPE_VIU_422                 0x800
37 #define VIDTYPE_VIU_FIELD               0x1000
38 #define VIDTYPE_VIU_SINGLE_PLANE        0x2000
39 #define VIDTYPE_VIU_444                 0x4000
40 #define VIDTYPE_VIU_NV21                0x8000
41 #define VIDTYPE_VSCALE_DISABLE          0x10000
42 #define VIDTYPE_CANVAS_TOGGLE           0x20000
43 #define VIDTYPE_PRE_INTERLACE           0x40000
44 #define VIDTYPE_HIGHRUN                 0x80000
45 #define VIDTYPE_COMPRESS                0x100000
46 #define VIDTYPE_PIC		        0x200000
47 #define VIDTYPE_SCATTER                 0x400000
48 #define VIDTYPE_VD2			0x800000
49 #define VIDTYPE_COMPRESS_LOSS		0x1000000
50 #define VIDTYPE_COMB_MODE		0x2000000
51 #define VIDTYPE_NO_DW			0x4000000
52 #define VIDTYPE_SUPPORT_COMPRESS	0x8000000
53 #define VIDTYPE_PRE_DI_AFBC		0x10000000
54 #define VIDTYPE_RGB_444			0x20000000
55 #define VIDTYPE_V4L_EOS			0x80000000
56 
57 /* 2019-04-22 Suggestions from brian.zhu*/
58 #define VIDTYPE_DI_PW			0x40000000
59 #define DISP_RATIO_FORCECONFIG          0x80000000
60 #define DISP_RATIO_FORCE_NORMALWIDE     0x40000000
61 #define DISP_RATIO_FORCE_FULL_STRETCH   0x20000000
62 #define DISP_RATIO_ADAPTED_PICMODE   0x10000000
63 #define DISP_RATIO_INFOFRAME_AVAIL   0x08000000
64 #define DISP_RATIO_CTRL_MASK            0x00000003
65 #define DISP_RATIO_NO_KEEPRATIO         0x00000000
66 #define DISP_RATIO_KEEPRATIO            0x00000001
67 #define DISP_RATIO_PORTRAIT_MODE        0x00000004
68 
69 #define DISP_RATIO_ASPECT_RATIO_MASK    0x0003ff00
70 #define DISP_RATIO_ASPECT_RATIO_BIT     8
71 #define DISP_RATIO_ASPECT_RATIO_MAX     0x3ff
72 
73 #define TB_DETECT_MASK    0x00000040
74 #define TB_DETECT_MASK_BIT     6
75 #define TB_DETECT_NONE          0
76 #define TB_DETECT_INVERT       1
77 #define TB_DETECT_NC               0
78 #define TB_DETECT_TFF             1
79 #define TB_DETECT_BFF             2
80 #define TB_DETECT_TBF             3
81 
82 #define VFRAME_FLAG_NO_DISCONTINUE		1
83 #define VFRAME_FLAG_SWITCHING_FENSE		2
84 #define VFRAME_FLAG_HIGH_BANDWIDTH		4
85 #define VFRAME_FLAG_ERROR_RECOVERY		8
86 #define VFRAME_FLAG_SYNCFRAME			0x10
87 #define VFRAME_FLAG_GAME_MODE			0x20
88 #define VFRAME_FLAG_VIDEO_COMPOSER		0x40
89 #define VFRAME_FLAG_VIDEO_COMPOSER_BYPASS	0x80
90 #define VFRAME_FLAG_COMPOSER_DONE		0x100
91 #define VFRAME_FLAG_VIDEO_COMPOSER_DMA		0x200
92 #define VFRAME_FLAG_VIDEO_LINEAR		0x400
93 #define VFRAME_FLAG_EMPTY_FRAME_V4L		0x800
94 #define VFRAME_FLAG_FAKE_FRAME			0x1000
95 #define VFRAME_FLAG_DOUBLE_FRAM		0x2000
96 #define VFRAME_FLAG_VIDEO_DRM			0x4000
97 #define VFRAME_FLAG_VIDEO_VDETECT		0x8000
98 #define VFRAME_FLAG_VIDEO_VDETECT_PUT		0x10000
99 
100 
101 enum pixel_aspect_ratio_e {
102 	PIXEL_ASPECT_RATIO_1_1,
103 	PIXEL_ASPECT_RATIO_8_9,
104 	PIXEL_ASPECT_RATIO_16_15,
105 };
106 
107 /*
108  * If pixel_sum[21:0] == 0, then all Histogram information are invalid
109  */
110 struct vframe_hist_s {
111 	unsigned int hist_pow;
112 	unsigned int luma_sum;
113 	unsigned int chroma_sum;
114 	unsigned int pixel_sum;	/* [31:30] POW [21:0] PIXEL_SUM */
115 	unsigned int height;
116 	unsigned int width;
117 	unsigned char luma_max;
118 	unsigned char luma_min;
119 	unsigned short gamma[64];
120 	unsigned int vpp_luma_sum;	/*vpp hist info */
121 	unsigned int vpp_chroma_sum;
122 	unsigned int vpp_pixel_sum;
123 	unsigned int vpp_height;
124 	unsigned int vpp_width;
125 	unsigned char vpp_luma_max;
126 	unsigned char vpp_luma_min;
127 	unsigned short vpp_gamma[64];
128 	unsigned int vpp_hue_gamma[32];
129 	unsigned int vpp_sat_gamma[32];
130 #ifdef AML_LOCAL_DIMMING
131 	unsigned int ldim_max[100];
132 #endif
133 } /*vframe_hist_t */;
134 
135 struct tvin_hdr10p_data_s {
136 	uint32_t vsif_hb;
137 	uint32_t vsif_ieee_code;
138 	struct pb4_st {
139 		uint8_t rvd:1;
140 		uint8_t max_lumin:5;
141 		uint8_t app_ver:2;
142 	} __packed pb4_st;
143 	uint8_t average_maxrgb;
144 	uint8_t distrib_valus0;
145 	uint8_t distrib_valus1;
146 	uint8_t distrib_valus2;
147 	uint8_t distrib_valus3;
148 	uint8_t distrib_valus4;
149 	uint8_t distrib_valus5;
150 	uint8_t distrib_valus6;
151 	uint8_t distrib_valus7;
152 	uint8_t distrib_valus8;
153 	struct pb15_18_st {
154 		uint32_t knee_point_x_9_6:4;
155 		uint32_t num_bezier_curve_anchors:4;
156 		uint32_t knee_point_y_9_8:2;
157 		uint32_t knee_point_x_5_0:6;
158 		uint32_t knee_point_y_7_0:8;
159 		uint32_t bezier_curve_anchors0:8;
160 	} __packed pb15_18_st;
161 	uint8_t bezier_curve_anchors1;
162 	uint8_t bezier_curve_anchors2;
163 	uint8_t bezier_curve_anchors3;
164 	uint8_t bezier_curve_anchors4;
165 	uint8_t bezier_curve_anchors5;
166 	uint8_t bezier_curve_anchors6;
167 	uint8_t bezier_curve_anchors7;
168 	uint8_t bezier_curve_anchors8;
169 	struct pb27_st {
170 		uint8_t rvd:6;
171 		uint8_t no_delay_flag:1;
172 		uint8_t overlay_flag:1;
173 	} __packed pb27_st;
174 } __packed;
175 
176 /*vdin dolby vsi info param*/
177 struct tvin_dv_vsif_s {
178 	uint8_t dobly_vision_signal:1;
179 	uint8_t backlt_ctrl_MD_present:1;
180 	uint8_t auxiliary_MD_present:1;
181 	uint8_t eff_tmax_PQ_hi;
182 	uint8_t eff_tmax_PQ_low;
183 	uint8_t auxiliary_runmode;
184 	uint8_t auxiliary_runversion;
185 	uint8_t auxiliary_debug0;
186 };
187 
188 /*
189  * If bottom == 0 or right == 0, then all Blackbar information are invalid
190  */
191 struct vframe_bbar_s {
192 	unsigned short top;
193 	unsigned short bottom;
194 	unsigned short left;
195 	unsigned short right;
196 } /*vfame_bbar_t */;
197 
198 /*
199  * If vsin == 0, then all Measurement information are invalid
200  */
201 struct vframe_meas_s {
202 	/* float frin; frame Rate of Video Input in the unit of Hz */
203 	unsigned int vs_span_cnt;
204 	unsigned long long vs_cnt;
205 	unsigned int hs_cnt0;
206 	unsigned int hs_cnt1;
207 	unsigned int hs_cnt2;
208 	unsigned int hs_cnt3;
209 	unsigned int vs_cycle;
210 	unsigned int vs_stamp;
211 } /*vframe_meas_t */;
212 
213 struct vframe_view_s {
214 	int start_x;
215 	int start_y;
216 	unsigned int width;
217 	unsigned int height;
218 } /*vframe_view_t */;
219 
220 #define SEI_PicTiming         1
221 #define SEI_MasteringDisplayColorVolume 137
222 #define SEI_ContentLightLevel 144
223 struct vframe_content_light_level_s {
224 	u32 present_flag;
225 	u32 max_content;
226 	u32 max_pic_average;
227 }; /* content_light_level from SEI */
228 
229 struct vframe_master_display_colour_s {
230 	u32 present_flag;
231 	u32 primaries[3][2];
232 	u32 white_point[2];
233 	u32 luminance[2];
234 	struct vframe_content_light_level_s
235 		content_light_level;
236 }; /* master_display_colour_info_volume from SEI */
237 
238 /* vframe properties */
239 struct vframe_prop_s {
240 	struct vframe_hist_s hist;
241 	struct vframe_bbar_s bbar;
242 	struct vframe_meas_s meas;
243 	struct vframe_master_display_colour_s
244 	 master_display_colour;
245 	struct tvin_hdr10p_data_s hdr10p_data;
246 } /*vframe_prop_t */;
247 
248 struct vdisplay_info_s {
249 	u32 frame_hd_start_lines_;
250 	u32 frame_hd_end_lines_;
251 	u32 frame_vd_start_lines_;
252 	u32 frame_vd_end_lines_;
253 	u32 display_vsc_startp;
254 	u32 display_vsc_endp;
255 	u32 display_hsc_startp;
256 	u32 display_hsc_endp;
257 	u32 screen_vd_v_start_;
258 	u32 screen_vd_v_end_;
259 	u32 screen_vd_h_start_;
260 	u32 screen_vd_h_end_;
261 };
262 
263 enum vframe_source_type_e {
264 	VFRAME_SOURCE_TYPE_OTHERS = 0,
265 	VFRAME_SOURCE_TYPE_TUNER,
266 	VFRAME_SOURCE_TYPE_CVBS,
267 	VFRAME_SOURCE_TYPE_COMP,
268 	VFRAME_SOURCE_TYPE_HDMI,
269 	VFRAME_SOURCE_TYPE_PPMGR,
270 	VFRAME_SOURCE_TYPE_OSD,
271 };
272 
273 enum vframe_source_mode_e {
274 	VFRAME_SOURCE_MODE_OTHERS = 0,
275 	VFRAME_SOURCE_MODE_PAL,
276 	VFRAME_SOURCE_MODE_NTSC,
277 	VFRAME_SOURCE_MODE_SECAM,
278 };
279 enum vframe_secam_phase_e {
280 	VFRAME_PHASE_DB = 0,
281 	VFRAME_PHASE_DR,
282 };
283 enum vframe_disp_mode_e {
284 	VFRAME_DISP_MODE_NULL = 0,
285 	VFRAME_DISP_MODE_UNKNOWN,
286 	VFRAME_DISP_MODE_SKIP,
287 	VFRAME_DISP_MODE_OK,
288 };
289 
290 enum vframe_signal_fmt_e {
291 	VFRAME_SIGNAL_FMT_INVALID = -1,
292 	VFRAME_SIGNAL_FMT_SDR = 0,
293 	VFRAME_SIGNAL_FMT_HDR10 = 1,
294 	VFRAME_SIGNAL_FMT_HDR10PLUS = 2,
295 	VFRAME_SIGNAL_FMT_HDR10PRIME = 3,
296 	VFRAME_SIGNAL_FMT_HLG = 4,
297 	VFRAME_SIGNAL_FMT_DOVI = 5,
298 	VFRAME_SIGNAL_FMT_DOVI_LL = 6,
299 	VFRAME_SIGNAL_FMT_MVC = 7
300 };
301 
302 #define SEI_MAGIC_CODE 0x53656920 /* SEI */
303 
304 /* signal format and sei data */
305 struct vframe_src_fmt_s {
306 	enum vframe_signal_fmt_e fmt;
307 	u32 sei_magic_code;
308 	void *sei_ptr;
309 	u32 sei_size;
310 	bool dual_layer;
311 };
312 
313 enum pic_mode_provider_e {
314 	PIC_MODE_PROVIDER_DB = 0,
315 	PIC_MODE_PROVIDER_WSS,
316 	PIC_MODE_UNKNOWN,
317 };
318 
319 struct vframe_pic_mode_s {
320 	int hs;
321 	int he;
322 	int vs;
323 	int ve;
324 	u32 screen_mode;
325 	u32 custom_ar;
326 	u32 AFD_enable;
327 	enum pic_mode_provider_e provider;
328 };
329 
330 #define BITDEPTH_Y_SHIFT 8
331 #define BITDEPTH_Y8    (0 << BITDEPTH_Y_SHIFT)
332 #define BITDEPTH_Y9    (1 << BITDEPTH_Y_SHIFT)
333 #define BITDEPTH_Y10   (2 << BITDEPTH_Y_SHIFT)
334 #define BITDEPTH_Y12   (3 << BITDEPTH_Y_SHIFT)
335 #define BITDEPTH_YMASK (3 << BITDEPTH_Y_SHIFT)
336 
337 #define BITDEPTH_U_SHIFT 10
338 #define BITDEPTH_U8    (0 << BITDEPTH_U_SHIFT)
339 #define BITDEPTH_U9    (1 << BITDEPTH_U_SHIFT)
340 #define BITDEPTH_U10   (2 << BITDEPTH_U_SHIFT)
341 #define BITDEPTH_U12   (3 << BITDEPTH_U_SHIFT)
342 #define BITDEPTH_UMASK (3 << BITDEPTH_U_SHIFT)
343 
344 #define BITDEPTH_V_SHIFT 12
345 #define BITDEPTH_V8    (0 << BITDEPTH_V_SHIFT)
346 #define BITDEPTH_V9    (1 << BITDEPTH_V_SHIFT)
347 #define BITDEPTH_V10   (2 << BITDEPTH_V_SHIFT)
348 #define BITDEPTH_V12   (3 << BITDEPTH_V_SHIFT)
349 #define BITDEPTH_VMASK (3 << BITDEPTH_V_SHIFT)
350 
351 #define BITDEPTH_MASK (BITDEPTH_YMASK | BITDEPTH_UMASK | BITDEPTH_VMASK)
352 #define BITDEPTH_SAVING_MODE	0x1
353 #define FULL_PACK_422_MODE		0x2
354 
355 struct codec_mm_box_s {
356 	void    *mmu_box;
357 	int     mmu_idx;
358 	void    *bmmu_box;
359 	int     bmmu_idx;
360 };
361 
362 struct vsif_info {
363 	void *addr;
364 	unsigned int size;
365 };
366 
367 struct emp_info {
368 	void *addr;
369 	unsigned int size;
370 };
371 
372 struct nn_value_t {
373 	int maxclass;
374 	int maxprob;
375 };
376 
377 #define AI_PQ_TOP 5
378 
379 struct vframe_s {
380 	u32 index;
381 	u32 index_disp;
382 	u32 omx_index;
383 	u32 type;
384 	u32 type_backup;
385 	u32 type_original;
386 	u32 blend_mode;
387 	u32 duration;
388 	u32 duration_pulldown;
389 	u32 pts;
390 	u64 pts_us64;
391 	bool next_vf_pts_valid;
392 	u32 next_vf_pts;
393 	u32 disp_pts;
394 	u64 disp_pts_us64;
395 	u64 timestamp;
396 	u32 flag;
397 
398 	u32 canvas0Addr;
399 	u32 canvas1Addr;
400 	u32 compHeadAddr;
401 	u32 compBodyAddr;
402 
403 	u32 plane_num;
404 	struct canvas_config_s canvas0_config[3];
405 	struct canvas_config_s canvas1_config[3];
406 
407 	u32 bufWidth;
408 	u32 width;
409 	u32 height;
410 	u32 compWidth;
411 	u32 compHeight;
412 	u32 ratio_control;
413 	u32 bitdepth;
414 
415 	/*
416 	 * bit 30: is_dv
417 	 * bit 29: present_flag
418 	 * bit 28-26: video_format
419 	 *	"component", "PAL", "NTSC", "SECAM", "MAC", "unspecified"
420 	 * bit 25: range "limited", "full_range"
421 	 * bit 24: color_description_present_flag
422 	 * bit 23-16: color_primaries
423 	 *	"unknown", "bt709", "undef", "bt601", "bt470m", "bt470bg",
424 	 *	"smpte170m", "smpte240m", "film", "bt2020"
425 	 * bit 15-8: transfer_characteristic
426 	 *	"unknown", "bt709", "undef", "bt601", "bt470m", "bt470bg",
427 	 *	"smpte170m", "smpte240m", "linear", "log100", "log316",
428 	 *	"iec61966-2-4", "bt1361e", "iec61966-2-1", "bt2020-10",
429 	 *	"bt2020-12", "smpte-st-2084", "smpte-st-428"
430 	 * bit 7-0: matrix_coefficient
431 	 *	"GBR", "bt709", "undef", "bt601", "fcc", "bt470bg",
432 	 *	"smpte170m", "smpte240m", "YCgCo", "bt2020nc", "bt2020c"
433 	 */
434 	u32 signal_type;
435 	u32 orientation;
436 	u32 video_angle;
437 	enum vframe_source_type_e source_type;
438 	enum vframe_secam_phase_e phase;
439 	enum vframe_source_mode_e source_mode;
440 	enum tvin_sig_fmt_e sig_fmt;
441 
442 	enum tvin_trans_fmt trans_fmt;
443 	struct vframe_view_s left_eye;
444 	struct vframe_view_s right_eye;
445 	u32 mode_3d_enable;
446 
447 	/* vframe extension */
448 	int (*early_process_fun)(void *arg, struct vframe_s *vf);
449 	int (*process_fun)(void *arg, unsigned int zoom_start_x_lines,
450 		unsigned int zoom_end_x_lines,
451 		unsigned int zoom_start_y_lines,
452 		unsigned int zoom_end_y_lines, struct vframe_s *vf);
453 	void *private_data;
454 #if 1
455 	/* vframe properties */
456 	struct vframe_prop_s prop;
457 #endif
458 	struct list_head list;
459 	struct tvafe_vga_parm_s vga_parm;
460 	/* pixel aspect ratio */
461 	enum pixel_aspect_ratio_e pixel_ratio;
462 	u64 ready_jiffies64;	/* ready from decode on  jiffies_64 */
463 	long long ready_clock[5];/*ns*/
464 	long long ready_clock_hist[2];/*ns*/
465 	atomic_t use_cnt;
466 	u32 frame_dirty;
467 	/*
468 	 *prog_proc_config:
469 	 *1: process p from decoder as filed;
470 	 *0: process p from decoder as frame
471 	 */
472 	u32 prog_proc_config;
473 	/* used for indicate current video is motion or static */
474 	int combing_cur_lev;
475 
476 	/*
477 	 *for vframe's memory,
478 	 * used by memory owner.
479 	 */
480 	void *mem_handle;
481 	/*for MMU H265/VP9 compress header*/
482 	void *mem_head_handle;
483 	struct vframe_pic_mode_s pic_mode;
484 
485 	unsigned long v4l_mem_handle;
486 
487 	u32 sar_width;
488 	u32 sar_height;
489 	/*****************
490 	 * di pulldown info
491 	 * bit 3: interlace
492 	 * bit 2: flmxx
493 	 * bit 1: flm22
494 	 * bit 0: flm32
495 	 *****************/
496 	u32 di_pulldown;
497 	u32 di_gmv;
498 	u32 axis[4];
499 	u32 crop[4];
500 
501 	struct codec_mm_box_s mm_box;
502 	struct vsif_info vsif;
503 	struct emp_info emp;
504 	u32 di_cm_cnt;
505 
506 	u32 dwHeadAddr;
507 	u32 dwBodyAddr;
508 	bool fgs_valid;
509 	u32 fgs_table_adr;
510 
511 	u32 sidebind_type;
512 	u32 sidebind_channel_id;
513 
514 	/*for double write VP9/AV1 vf*/
515 	void *mem_dw_handle;
516 	struct nn_value_t nn_value[AI_PQ_TOP];
517 
518 	/* signal format and sei data */
519 	struct vframe_src_fmt_s src_fmt;
520 } /*vframe_t */;
521 
522 #if 0
523 struct vframe_prop_s *vdin_get_vframe_prop(u32 index);
524 #endif
525 int get_curren_frame_para(int *top, int *left, int *bottom, int *right);
526 
527 u8 is_vpp_postblend(void);
528 
529 void pause_video(unsigned char pause_flag);
530 
531 s32 update_vframe_src_fmt(
532 	struct vframe_s *vf, void *sei,
533 	u32 size, bool dual_layer,
534 	char *recv_name);
535 void *get_sei_from_src_fmt(struct vframe_s *vf, u32 *sei_size);
536 enum vframe_signal_fmt_e get_vframe_src_fmt(struct vframe_s *vf);
537 s32 clear_vframe_src_fmt(struct vframe_s *vf);
538 
539 #endif /* VFRAME_H */
540