/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */ /* * Copyright (c) 2025 Amlogic, Inc. All rights reserved. */ #ifndef _DI_H #define _DI_H #include #include #include #include #include #include #include #include "deinterlace_hw.h" #include "nr_drv.h" #include "../di_local/di_local.h" /*trigger_pre_di_process param*/ #define TRIGGER_PRE_BY_PUT 'p' #define TRIGGER_PRE_BY_DE_IRQ 'i' #define TRIGGER_PRE_BY_UNREG 'u' /*di_timer_handle*/ #define TRIGGER_PRE_BY_TIMER 't' #define TRIGGER_PRE_BY_FORCE_UNREG 'f' #define TRIGGER_PRE_BY_VFRAME_READY 'r' #define TRIGGER_PRE_BY_PROVIDER_UNREG 'n' #define TRIGGER_PRE_BY_DEBUG_DISABLE 'd' #define TRIGGER_PRE_BY_PROVIDER_REG 'R' #define DI_RUN_FLAG_RUN 0 #define DI_RUN_FLAG_PAUSE 1 #define DI_RUN_FLAG_STEP 2 #define DI_RUN_FLAG_STEP_DONE 3 #define USED_LOCAL_BUF_MAX 3 #define BYPASS_GET_MAX_BUF_NUM 9 /* buffer management related */ #define MAX_IN_BUF_NUM 20 #define MAX_LOCAL_BUF_NUM 10 #define MAX_POST_BUF_NUM 16 #define VFRAME_TYPE_IN 1 #define VFRAME_TYPE_LOCAL 2 #define VFRAME_TYPE_POST 3 #define VFRAME_TYPE_NUM 3 /*vframe define*/ #define vframe_t struct vframe_s /* canvas defination */ #define DI_USE_FIXED_CANVAS_IDX //#define DET3D #undef SUPPORT_MPEG_TO_VDIN #define CLK_TREE_SUPPORT #ifndef CONFIG_AMLOGIC_MEDIA_RDMA #ifndef VSYNC_WR_MPEG_REG #define VSYNC_WR_MPEG_REG(adr, val) aml_write_vcbus(adr, val) #define VSYNC_WR_MPEG_REG_BITS(adr, val, start, len) \ aml_vcbus_update_bits(adr, ((1<nr0, * 1 (f1,nr0,f1)->nr1_cnt, * 2 (f2,nr1_cnt,nr0)->nr2_cnt * 3 (f3,nr2_cnt,nr1_cnt)->nr3_cnt */ struct DI_MC_MIF_s di_mcinford_mif; struct DI_MC_MIF_s di_mcvecwr_mif; struct DI_MC_MIF_s di_mcinfowr_mif; /* pre state */ int in_seq; int recycle_seq; int pre_ready_seq; int pre_de_busy; /* 1 if pre_de is not done */ int pre_de_busy_timer_count; int pre_de_process_done; /* flag when irq done */ int pre_de_process_flag; /* flag when pre_de_process done */ int pre_de_clear_flag; /* flag is set when VFRAME_EVENT_PROVIDER_UNREG*/ int unreg_req_flag; int unreg_req_flag_irq; int unreg_req_flag_cnt; int reg_req_flag; /*int reg_req_flag_irq;*/ int reg_req_flag_cnt; int reg_irq_busy; int force_unreg_req_flag; int disable_req_flag; /* current source info */ int cur_width; int cur_height; int cur_inp_type; int cur_source_type; int cur_sig_fmt; unsigned int orientation; int cur_prog_flag; /* 1 for progressive source */ /* valid only when prog_proc_type is 0, for * progressive source: top field 1, bot field 0 */ int source_change_flag; /* input size change flag, 1: need reconfig pre/nr/dnr size */ /* 0: not need config pre/nr/dnr size*/ bool input_size_change_flag; /* true: bypass di all logic, false: not bypass */ bool bypass_flag; unsigned char prog_proc_type; /* set by prog_proc_config when source is vdin,0:use 2 i * serial buffer,1:use 1 p buffer,3:use 2 i paralleling buffer */ unsigned char buf_alloc_mode; /* alloc di buf as p or i;0: alloc buf as i; * 1: alloc buf as p; */ unsigned char madi_enable; unsigned char mcdi_enable; unsigned int pps_dstw; unsigned int pps_dsth; int left_right;/*1,left eye; 0,right eye in field alternative*/ /*input2pre*/ int bypass_start_count; /* need discard some vframe when input2pre => bypass */ unsigned char vdin2nr; enum tvin_trans_fmt source_trans_fmt; enum tvin_trans_fmt det3d_trans_fmt; unsigned int det_lr; unsigned int det_tp; unsigned int det_la; unsigned int det_null; /*unsigned int width_bk;*/ #ifdef DET3D int vframe_interleave_flag; #endif /**/ int pre_de_irq_timeout_count; int pre_throw_flag; int bad_frame_throw_count; /*for static pic*/ int static_frame_count; bool force_interlace; bool by_pass_pre; bool invert_flag; bool vdin_source; int nr_size; int count_size; int mcinfo_size; int mv_size; int mtn_size; int cma_alloc_req; int cma_alloc_done; int cma_release_req; /* for performance debug */ unsigned long irq_time[2]; /* combing adaptive */ struct combing_status_s *mtn_status; u64 afbc_rls_time; bool wait_afbc; /*****************/ bool retry_en; unsigned int retry_index; unsigned int retry_cnt; /*****************/ bool combing_fix_en; unsigned int comb_mode; /*struct di_patch_mov_s mov;*/ }; struct di_post_stru_s { struct DI_MIF_s di_buf0_mif; struct DI_MIF_s di_buf1_mif; struct DI_MIF_s di_buf2_mif; struct DI_SIM_MIF_s di_diwr_mif; struct DI_SIM_MIF_s di_mtnprd_mif; struct DI_MC_MIF_s di_mcvecrd_mif; struct di_buf_s *cur_post_buf; struct di_buf_s *keep_buf; int update_post_reg_flag; int run_early_proc_fun_flag; int cur_disp_index; int canvas_id; int next_canvas_id; bool toggle_flag; bool vscale_skip_flag; uint start_pts; int buf_type; int de_post_process_done; int post_de_busy; int di_post_num; unsigned int post_peek_underflow; unsigned int di_post_process_cnt; unsigned int check_recycle_buf_cnt; /* performance debug */ unsigned int post_wr_cnt; unsigned long irq_time; }; #define MAX_QUEUE_POOL_SIZE 256 struct queue_s { unsigned int num; unsigned int in_idx; unsigned int out_idx; unsigned int type; /* 0, first in first out; * 1, general;2, fix position for di buf */ unsigned int pool[MAX_QUEUE_POOL_SIZE]; }; struct di_buf_pool_s { struct di_buf_s *di_buf_ptr; unsigned int size; }; struct di_mm_s { struct page *ppage; unsigned long addr; }; extern bool di_mm_alloc(int cma_mode, size_t count, struct di_mm_s *o); extern bool di_mm_release(int cma_mode, struct page *pages, int count, unsigned long addr); unsigned char is_bypass(vframe_t *vf_in); /*---get di state parameter---*/ struct di_dev_s *get_di_de_devp(void); struct di_pre_stru_s *get_di_pre_stru(void); struct di_post_stru_s *get_di_post_stru(void); const char *get_di_version_s(void); int get_di_dump_state_flag(void); uint get_di_init_flag(void); unsigned char get_di_recovery_flag(void); unsigned int get_di_recovery_log_reason(void); int get_di_di_blocking(void); unsigned int get_di_recovery_log_queue_idx(void); struct di_buf_s *get_di_recovery_log_di_buf(void); int get_di_video_peek_cnt(void); unsigned long get_di_reg_unreg_timeout_cnt(void); struct vframe_s **get_di_vframe_in(void); extern s32 di_request_afbc_hw(u8 id, bool on); u32 di_request_afbc(u32 onoff); unsigned int is_need_stop_reg(unsigned int addr); /***********************/ extern bool di_wr_cue_int(void); extern int reg_cue_int_show(struct seq_file *seq, void *v); bool dil_attach_ext_api(const struct di_ext_ops *di_api); /*--Different DI versions flag---*/ void dil_set_diff_ver_flag(unsigned int para); unsigned int dil_get_diff_ver_flag(void); /*-------------------------*/ struct di_buf_s *get_di_buf(int queue_idx, int *start_pos); #define queue_for_each_entry(di_buf, ptm, queue_idx, list) \ for (itmp = 0; ((di_buf = get_di_buf(queue_idx, &itmp)) != NULL); ) #define di_dev_t struct di_dev_s #define di_pr_info(fmt, args ...) pr_info("DI: " fmt, ## args) #define pr_dbg(fmt, args ...) pr_debug("DI: " fmt, ## args) #define pr_error(fmt, args ...) pr_err("DI: " fmt, ## args) /******************************************/ /*#define DI_KEEP_HIS 0*/ #endif