f0787342fd7436eca14e3a7da15419d371065ddd
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / iep / iep_drv.h
1 #ifndef IEP_DRV_H_
2 #define IEP_DRV_H_
3
4 #include <linux/device.h>
5 #include <linux/miscdevice.h>
6 #include <linux/mutex.h>
7
8 #if defined(CONFIG_RK_IOMMU) && defined(CONFIG_ION_ROCKCHIP)
9 #define CONFIG_IEP_IOMMU
10 #endif
11
12 #ifdef CONFIG_IEP_IOMMU
13 #include <linux/rockchip_ion.h>
14 #include <linux/rockchip-iovmm.h>
15 #include <linux/dma-buf.h>
16 #endif
17 #include "iep.h"
18
19 #define IEP_REG_LEN         0x100
20 #define IEP_CMD_REG_LEN     0xE
21 #define IEP_ADD_REG_LEN     0xE0
22 #define IEP_RAW_REG_LEN     0xA
23 #define IEP_SYS_REG_LEN     0x6
24 #define IEP_CNF_REG_LEN     0x2
25
26 #define IEP_CNF_REG_BASE    0x0
27 #define IEP_SYS_REG_BASE    0x2
28 #define IEP_CMD_REG_BASE    0x8
29 #define IEP_ADD_REG_BASE    0x20
30 #define IEP_RAW_REG_BASE    0x16
31
32 #if defined(CONFIG_IEP_MMU)
33 #define IEP_MMU_REG_BASE    0x200
34 #define IEP_MMU_REG_LEN     0xA
35 #endif
36
37 struct iep_parameter_req {
38         struct iep_img src;
39         struct iep_img dst;
40 };
41
42 struct iep_parameter_deinterlace {
43         struct iep_img src1;
44         struct iep_img dst1;
45
46         struct iep_img src_itemp;
47         struct iep_img src_ftemp;
48
49         struct iep_img dst_itemp;
50         struct iep_img dst_ftemp;
51
52         u8 dein_mode;
53
54         // deinterlace high frequency
55         u8 dein_high_fre_en;
56         u8 dein_high_fre_fct;
57
58         // deinterlace edge interpolation
59         u8 dein_ei_mode;
60         u8 dein_ei_smooth;
61         u8 dein_ei_sel;
62         u8 dein_ei_radius;
63 };
64
65 struct iep_parameter_enhance {
66         u8 yuv_3D_denoise_en;
67
68         u8 yuv_enhance_en;
69         float yuv_enh_saturation; //0-1.992
70         float yuv_enh_contrast; //0-1.992
71         s8 yuv_enh_brightness; //-32<brightness<31
72         s8 yuv_enh_hue_angle; //0-30,value is 0 - 30
73
74         u8 video_mode; //0-3
75         u8 color_bar_y; //0-127
76         u8 color_bar_u; //0-127
77         u8 color_bar_v; //0-127
78
79         u8 rgb_enhance_en;
80
81         u8 rgb_cg_en; //sw_rgb_con_gam_en
82         double cg_rr;
83         double cg_rg;
84         double cg_rb;
85         u8 rgb_color_enhance_en; //sw_rgb_color_enh_en
86         float rgb_enh_coe; //0-3.96875
87 };
88
89 struct iep_parameter_scale {
90         u8 scale_up_mode;
91 };
92
93 struct iep_parameter_convert {
94         u8 dither_up_en;
95         u8 dither_down_en; //not to be used
96
97         u8 yuv2rgb_mode;
98         u8 rgb2yuv_mode;
99
100         u8 global_alpha_value;
101
102         u8 rgb2yuv_clip_en;
103         u8 yuv2rgb_clip_en;
104 };
105
106 typedef struct iep_session {
107         /* a linked list of data so we can access them for debugging */
108         struct list_head    list_session;
109         /* a linked list of register data waiting for process */
110         struct list_head    waiting;
111         /* a linked list of register data in ready */
112         struct list_head    ready;
113         /* a linked list of register data in processing */
114         struct list_head    running;
115         /* all coommand this thread done */
116         atomic_t            done;
117         wait_queue_head_t   wait;
118         pid_t               pid;
119         atomic_t            task_running;
120         atomic_t            num_done;
121
122 #if defined(CONFIG_IEP_MMU)
123         uint32_t *dte_table;
124         struct list_head    pte_list;
125         struct task_struct *tsk;
126 #endif
127 } iep_session;
128
129 typedef struct iep_service_info {
130         struct mutex        lock;
131         struct timer_list       timer;          /* timer for power off */
132         struct list_head        waiting;        /* link to link_reg in struct iep_reg */
133         atomic_t            waitcnt;
134         struct list_head    ready;          /* link to link_reg in struct iep_reg */
135         struct list_head        running;        /* link to link_reg in struct iep_reg */
136         struct list_head        done;           /* link to link_reg in struct iep_reg */
137         struct list_head        session;        /* link to list_session in struct vpu_session */
138         atomic_t                    total_running;
139
140         struct iep_reg      *reg;
141         bool                enable;
142
143         struct mutex        mutex;  // mutex
144
145 #ifdef CONFIG_IEP_IOMMU
146         struct ion_client *ion_client;
147 #endif
148         struct device *iommu_dev;
149 } iep_service_info;
150
151 struct iep_reg {
152         iep_session *session;
153         struct list_head        session_link;      /* link to rga service session */
154         struct list_head        status_link;       /* link to register set list */
155         uint32_t                        reg[0x300];
156         bool                dpi_en;
157         int                 off_x;
158         int                 off_y;
159         int                 act_width;
160         int                 act_height;
161         int                 vir_width;
162         int                 vir_height;
163         int                 layer;
164         unsigned int        format;
165 #if defined(CONFIG_IEP_IOMMU)
166         struct list_head    mem_region_list;
167 #endif
168 };
169
170 #if defined(CONFIG_IEP_IOMMU)
171 struct iep_mem_region {
172         struct list_head srv_lnk;
173         struct list_head reg_lnk;
174         struct list_head session_lnk;
175         unsigned long iova;              /* virtual address for iommu */
176         unsigned long len;
177         struct ion_handle *hdl;
178 };
179 #endif
180
181 #endif
182