1 /* 2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 #ifndef __HIFB_DRV_H__ 19 #define __HIFB_DRV_H__ 20 #ifdef __HuaweiLite__ 21 #include <fb.h> 22 #endif 23 #include "hifb.h" 24 #include "hi_debug.h" 25 #include "hifb_def.h" 26 #ifdef __cplusplus 27 #if __cplusplus 28 extern "C" { 29 #endif 30 #endif /* End of #ifdef __cplusplus */ 31 32 #ifdef __HuaweiLite__ 33 typedef struct { 34 struct hifb_info *info; 35 hi_ulong layer_size; 36 hi_u32 curosr_buf_size; /* For soft cursor */ 37 } hifb_layer; 38 39 #else 40 typedef struct { 41 struct fb_info *info; 42 hi_ulong layer_size; /* ulLayerSize = fb.smem_len, For display buf, KB */ 43 hi_u32 curosr_buf_size; /* For soft cursor */ 44 } hifb_layer; 45 #endif 46 47 #if (HICHIP == HI3516E_V200) 48 typedef hi_s32 (*intvgscallback)(hi_u32 call_mod_id, hi_u32 call_dev_id, hi_u32 call_chn_id, hi_void *job_data); 49 #endif 50 51 typedef hi_s32 (*int_callback)(const hi_void *paraml, const hi_void *paramr); 52 #define hifb_trace(level, fmt...) \ 53 do { \ 54 HI_TRACE(level, HI_ID_VO, "[Func]:%s [Line]:%d [Info]:", __FUNCTION__, __LINE__); \ 55 HI_TRACE(level, HI_ID_VO, ##fmt); \ 56 } while (0) 57 58 #define hi_trace_fb(level, fmt...) \ 59 do { \ 60 HI_TRACE(level, HI_ID_FB, "[Func]:%s [Line]:%d [Info]:", __FUNCTION__, __LINE__); \ 61 HI_TRACE(level, HI_ID_FB, ##fmt); \ 62 } while (0) 63 64 #define hifb_fatal(fmt...) hi_trace_fb(HI_DBG_EMERG, fmt) 65 #define hifb_error(fmt...) hi_trace_fb(HI_DBG_ERR, fmt) 66 #define hifb_warning(fmt...) hi_trace_fb(HI_DBG_WARN, fmt) 67 #define hifb_dbg_info(fmt...) hi_trace_fb(HI_DBG_INFO, fmt) 68 69 typedef hi_u32 hifb_layer_id; /* start from 0 */ 70 71 hi_bool hifb_drv_support_rotate(void); 72 hi_bool is_hd_layer(hi_u32 layer_id); 73 hi_bool is_sd_layer(hi_u32 layer_id); 74 hi_bool is_ad_layer(hi_u32 layer_id); 75 hi_bool is_cursor_layer(hi_u32 layer_id); 76 77 typedef struct { 78 hi_bool key_enable; /* colorkey */ 79 hi_bool mask_enable; /* key mask */ 80 hi_u32 key; 81 hi_u8 red_mask; /* red mask */ 82 hi_u8 green_mask; /* green mask */ 83 hi_u8 blue_mask; /* blue mask */ 84 hi_u8 reserved; 85 hi_u32 key_mode; /* 0:In region; 1:Out region */ 86 hi_u8 red_max; /* colorkey red max */ 87 hi_u8 green_max; /* colorkey green max */ 88 hi_u8 blue_max; /* colorkey blue max */ 89 hi_u8 reserved1; 90 hi_u8 red_min; /* colorkey red min */ 91 hi_u8 green_min; /* colorkey green min */ 92 hi_u8 blue_min; /* colorkey blue min */ 93 hi_u8 reserved2; 94 } hifb_colorkeyex; 95 96 typedef struct { 97 HIFB_RECT clip_rect; 98 hi_bool in_region_clip; 99 hi_bool clip; 100 } hifb_clip; 101 102 typedef struct { 103 HIFB_ALPHA_S alpha; 104 hifb_colorkeyex ckey; 105 hifb_clip clip; 106 HIFB_LAYER_ANTIFLICKER_LEVEL_E antiflicker_level; 107 hi_bool scale; 108 hi_bool block; 109 hi_bool call_back; 110 hi_bool region_deflicker; 111 hi_void *param; 112 hi_u64 cmap_addr; 113 hi_bool soft_cursor_update; 114 HIFB_MIRROR_MODE_E mirror_mode; 115 hi_bool compress; 116 } hifb_blit_opt; 117 118 /* for graphic rotation. */ 119 typedef struct { 120 hi_bool block; 121 hi_bool call_back; 122 hi_void *param; 123 HIFB_ROTATE_MODE_E rotate_mode; 124 } hifb_rotate_opt; 125 126 typedef enum { 127 HIFB_SCANMODE_P, 128 HIFB_SCANMODE_I, 129 HIFB_SCANMODE_BUTT, 130 } hifb_scan_mode; 131 132 /* layer state */ 133 typedef enum { 134 HIFB_LAYER_STATE_ENABLE = 0x0, 135 136 HIFB_LAYER_STATE_DISABLE, 137 138 HIFB_LAYER_STATE_INVALID, 139 140 HIFB_LAYER_STATE_BUTT 141 } hifb_layer_state; 142 143 typedef struct { 144 hifb_scan_mode scan_mode; 145 hi_u32 screen_width; 146 hi_u32 screen_height; 147 } disp_info; 148 149 typedef struct { 150 hi_u64 buffer_phy_addr; 151 hi_u32 stride; 152 hi_bool feild_update; /* field update mode or not */ 153 hifb_scan_mode scan_mode; 154 hi_u32 screen_width; /* current sync width */ 155 hi_u32 screen_height; /* current sync height */ 156 } hifb_osd_data; 157 158 /* mask bit */ 159 typedef enum { 160 HIFB_LAYER_PARAMODIFY_FMT = 0x1, /* color format */ 161 HIFB_LAYER_PARAMODIFY_STRIDE = 0x2, /* stride, line spacing */ 162 HIFB_LAYER_PARAMODIFY_ALPHA = 0x4, /* alpha */ 163 HIFB_LAYER_PARAMODIFY_COLORKEY = 0x8, /* colorkey */ 164 HIFB_LAYER_PARAMODIFY_INRECT = 0x10, /* input rect */ 165 HIFB_LAYER_PARAMODIFY_OUTRECT = 0x20, /* output rect */ 166 HIFB_LAYER_PARAMODIFY_DISPLAYADDR = 0x40, /* display addr */ 167 HIFB_LAYER_PARAMODIFY_SHOW = 0x80, /* show or hide */ 168 HIFB_LAYER_PARAMODIFY_BMUL = 0x100, /* be pre-multi data */ 169 HIFB_LAYER_PARAMODIFY_ANTIFLICKERLEVEL = 0x200, /* ANTIFLICKERLEVEL */ 170 HIFB_LAYER_PARAMODIFY_DYNAMICRANGE = 0x400, /* DYNAMICRANGE */ 171 HIFB_LAYER_PARAMODIFY_BUTT 172 } hifb_layer_paramodify_maskbit; 173 174 typedef struct { 175 hi_u32 phy_addr; 176 HIFB_COLOR_FMT_E color_fmt; 177 HIFB_SIZE_S resolution; 178 hi_u32 stride; 179 } hifb_vcmp_inbufinfo; 180 181 typedef struct { 182 hi_u32 bank_width; 183 hi_u32 stride; 184 hi_u32 alpha_addr; 185 hi_u32 red_addr; 186 hi_u32 green_addr; 187 hi_u32 blue_addr; 188 } hifb_vcmp_outbufinfo; 189 190 typedef enum { 191 FB_VO_INPUTFMT_ARGB_4444 = 0x48, 192 FB_VO_INPUTFMT_ARGB_1555 = 0x49, 193 FB_VO_INPUTFMT_ARGB_8888 = 0x68, 194 195 FB_VO_DISP_PIXELFORMAT_BUTT 196 } fb_vo_disp_pixel_format; 197 198 typedef struct { 199 fb_vo_disp_pixel_format pixel_fmt; 200 hi_u64 ar_phy_addr; 201 hi_u64 gb_phy_addr; 202 hi_u32 frame_size0; 203 hi_u32 frame_size1; 204 hi_u32 width; 205 hi_u32 height; 206 hi_bool is_lossless_a; 207 hi_bool is_lossless; 208 hi_u32 offset; 209 hi_u32 stride; 210 } fb_vo_graphic_dcmp_info; 211 212 typedef enum { 213 HIFB_VO_INTTYPE_VO, 214 HIFB_VO_INTTYPE_VO_DISP, 215 HIFB_VO_INTTYPE_WBC, 216 HIFB_VO_INTTYPE_BUTT, 217 } fb_vo_int_type; 218 219 typedef struct { 220 hi_s32 x; 221 hi_s32 y; 222 hi_s32 w; 223 hi_s32 h; 224 } fb_vo_rect; 225 226 typedef struct { 227 hi_u64 ar_phy_addr; 228 hi_u64 gb_phy_addr; 229 hi_u32 offset; 230 hi_u32 stride; 231 fb_vo_rect in_rect; 232 fb_vo_rect out_rect; 233 } fb_vo_graphic_wbc_info; 234 235 typedef struct { 236 hi_u32 start_phy_addr; 237 hi_u32 end_phy_addr; 238 } fb_vo_mddrc_zone_addr; 239 240 typedef enum { 241 FB_VO_CSC_MATRIX_IDENTITY = 0, /* Identity CSC matrix. */ 242 243 FB_VO_CSC_MATRIX_BT601_TO_BT709, /* BT601 to BT709 */ 244 FB_VO_CSC_MATRIX_BT709_TO_BT601, /* BT709 to BT601 */ 245 246 FB_VO_CSC_MATRIX_BT601_TO_RGB_PC, /* BT601 to RGB */ 247 FB_VO_CSC_MATRIX_BT709_TO_RGB_PC, /* BT709 to RGB */ 248 249 FB_VO_CSC_MATRIX_RGB_TO_BT601_PC, /* RGB to BT601 FULL */ 250 FB_VO_CSC_MATRIX_RGB_TO_BT709_PC, /* RGB to BT709 FULL */ 251 252 FB_VO_CSC_MATRIX_RGB_TO_BT2020_PC, /* RGB to BT.2020 */ 253 FB_VO_CSC_MATRIX_BT2020_TO_RGB_PC, /* BT.2020 to RGB */ 254 255 FB_VO_CSC_MATRIX_RGB_TO_BT601_TV, /* RGB to BT601 LIMIT */ 256 FB_VO_CSC_MATRIX_RGB_TO_BT709_TV, /* RGB to BT709 LIMIT */ 257 258 FB_VO_CSC_MATRIX_BUTT 259 } fb_vo_csc_matrix; 260 261 typedef struct { 262 fb_vo_csc_matrix csc_matrix; /* CSC matrix */ 263 hi_u32 luma; /* RW range:[0, 100] luminance, default: 50 */ 264 hi_u32 contrast; /* RW range:[0, 100] contrast, default: 50 */ 265 hi_u32 hue; /* RW range:[0, 100] hue, default: 50 */ 266 hi_u32 satuature; /* RW range:[0, 100] satuature, default: 50 */ 267 } fb_vo_csc; 268 269 typedef enum { 270 HIFB_INTTYPE_VO, /* Vertical timing interrupt */ 271 HIFB_INTTYPE_VO_DISP, /* Timing switch notification */ 272 HIFB_INTTYPE_WBC, /* Compression completion interrupt */ 273 HIFB_INTTYPE_BUTT, 274 } fb_int_type; 275 276 typedef struct { 277 const char *chip_name; /* chip name */ 278 hi_u32 layer_count; /* support how many layers */ 279 HIFB_CAPABILITY_S *capability; /* capability */ 280 281 /* init DRV */ 282 hi_s32 (*hifb_drv_init)(hi_void); 283 284 /* De init DRV */ 285 hi_s32 (*hifb_drv_deinit)(hi_void); 286 hi_s32 (*hifb_drv_layer_default_setting)(hi_u32); 287 288 /* enable/disable layer */ 289 hi_s32 (*hifb_drv_enable_layer)(hi_u32, hi_bool); 290 291 /* set layer address */ 292 hi_s32 (*hifb_drv_set_layer_addr)(hi_u32, hi_u64); 293 294 /* get layer address */ 295 hi_s32 (*hifb_drv_get_layer_addr)(hi_u32, hi_u64 *); 296 297 /* set layer stride */ 298 hi_s32 (*hifb_drv_set_layer_stride)(hi_u32, hi_u32); 299 300 /* set layer pixel format */ 301 hi_s32 (*hifb_drv_set_layer_data_fmt)(hi_u32, HIFB_COLOR_FMT_E); 302 303 /* set color registers */ 304 hi_s32 (*hifb_drv_set_color_reg)(hi_u32, hi_u32, hi_u32, hi_s32); 305 306 /* wait until vblank, it's a block interface */ 307 hi_s32 (*hifb_drv_wait_v_blank)(hi_u32); 308 309 /* set layer deflicker */ 310 hi_s32 (*hifb_drv_set_layer_de_flicker)(hi_u32, HIFB_DEFLICKER_S); 311 312 /* set layer alpha */ 313 hi_s32 (*hifb_drv_set_layer_alpha)(hi_u32, HIFB_ALPHA_S); 314 315 /* set layer start position and size */ 316 hi_s32 (*hifb_drv_set_layer_rect)(hi_u32, const HIFB_RECT *, const HIFB_RECT *); 317 318 /* set layer src image resolution */ 319 hi_s32 (*hifb_drv_set_layer_src_image_reso)(hi_u32, const HIFB_RECT *); 320 321 /* other color format convert to RGB888 format */ 322 #ifdef __HuaweiLite__ 323 hi_s32 (*hifb_drv_color_convert)(const struct hifb_info *, hifb_colorkeyex *); 324 #else 325 hi_s32 (*hifb_drv_color_convert)(const struct fb_var_screeninfo *, hifb_colorkeyex *); 326 #endif 327 /* set layer colorkey */ 328 hi_s32 (*hifb_drv_set_layer_key_mask)(hi_u32, const hifb_colorkeyex *); 329 330 /* update layer register */ 331 hi_s32 (*hifb_drv_updata_layer_reg)(hi_u32); 332 333 /* set premul data */ 334 hi_s32 (*hifb_drv_set_pre_mul)(hi_u32, hi_bool); 335 336 hi_s32 (*hifb_drv_set_clut_addr)(hi_u32, hi_u32); 337 /* get osd data */ 338 hi_s32 (*hifb_drv_get_osd_data)(hi_u32, hifb_osd_data *); 339 /* register call back function */ 340 hi_s32 (*hifb_drv_set_int_callback) 341 (fb_vo_int_type, int_callback, hi_u32, hi_void *); 342 /* open vo */ 343 hi_s32 (*hifb_drv_open_display)(hi_void); 344 345 /* close vou */ 346 hi_s32 (*hifb_drv_close_display)(hi_void); 347 348 hi_s32 (*hifb_open_layer)(hi_u32); 349 hi_s32 (*hifb_close_layer)(hi_u32); 350 351 /* for compression */ 352 hi_void (*hifb_drv_get_wbc_en_state)(hi_u32, hi_bool *); 353 hi_void (*hifb_drv_get_wbc_stop_state)(hi_u32, hi_bool *); 354 hi_void (*hifb_drv_set_wbc_info)(hi_u32, fb_vo_graphic_wbc_info *); 355 hi_void (*hifb_drv_enable_wbc_int)(hi_u32, hi_bool); 356 hi_void (*hifb_drv_enable_wbc)(hi_u32, hi_bool); 357 hi_bool (*hifb_drv_enable_dcmp)(hi_u32, hi_bool); 358 hi_bool (*hifb_drv_get_dcmp_enable_state)(hi_u32, hi_bool *); 359 hi_bool (*hifb_drv_set_dcmp_info)(hi_u32, fb_vo_graphic_dcmp_info *); 360 hi_bool (*hifb_drv_is_layer_support_ddr_detect)(hi_u32); 361 hi_void (*hifb_drv_get_mddr_status)(hi_u32, hi_u32, hi_u32 *); 362 hi_void (*hifb_drv_set_mddr_detect_zone)(hi_u32, hi_u32, fb_vo_mddrc_zone_addr *); 363 hi_void (*hifb_drv_clear_ddr_dectect_zone)(hi_u32, hi_u32); 364 hi_s32 (*hifb_drv_check_ddr_dectect_zone) 365 (hi_u32, hi_u32, hi_u32, hi_u32, hi_u32); 366 hi_void (*hifb_drv_get_ddr_zone_cfg)(hi_u32, hi_u32 *, hi_u32 *); 367 hi_void (*hifb_drv_init_mddr)(hi_void); 368 369 /* for GHDR */ 370 hi_bool (*hifb_drv_enable_ghdr)(hi_u32, hi_bool); 371 372 /* for ZME */ 373 hi_bool (*hifb_drv_enable_zme)(hi_u32, HIFB_RECT *, HIFB_RECT *, hi_bool); 374 hi_bool (*hifb_drv_is_layer_support_zoom_out)(hi_u32); 375 /* for int */ 376 hi_bool (*hifb_drv_graphics_enable_int)(hi_u32, hi_bool); 377 hi_bool (*hifb_drv_graphics_clear_int)(hi_u32, hi_s32); 378 hi_bool (*hifb_drv_graphics_get_int)(hi_u32 *); 379 hi_bool (*hifb_drv_graphics_clear_int_status)(hi_u32); 380 hi_s32 (*hifb_drv_graphics_get_int_dev)(hi_u32, hifb_vo_dev *); 381 } hifb_drv_ops; 382 383 hi_void hifb_drv_get_ops(hifb_drv_ops *ops); 384 fb_vo_disp_pixel_format hifb_drv_convert_pixel_format(HIFB_COLOR_FMT_E color_format); 385 hi_u64 hifb_drv_get_dcmp_offset_addr(hi_u64 dcmp_addr); 386 char *hifb_get_layer_mmz_names(hi_u32 layer_id); 387 388 #ifdef __cplusplus 389 #if __cplusplus 390 } 391 #endif /* __HIFB_DRV_H__ */ 392 #endif /* __cplusplus */ 393 394 #endif /* __HIFB_DRV_H__ */ 395