• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include "hifb_vou_drv.h"
20 #include "hifb_vou_graphics.h"
21 #include "hi_tde_ext.h"
22 #include "mod_ext.h"
23 
24 #define HIFB_MAX_LAYER_WIDTH_G0  1920
25 #define HIFB_MAX_LAYER_HEIGHT_G0 1080
26 #define HIFB_MIN_LAYER_WIDTH_G0  32
27 #define HIFB_MIN_LAYER_HEIGH_G0  32
28 
29 #define GRAPHIC_ALPHA_OPACITY 0xff
30 
31 /*
32  * Prototype       : Variable Definition
33  * Description     : hifb: a definition of the graphics layer capability set.
34  */
35 const HIFB_CAPABILITY_S g_hifb_gfx_cap[HIFB_MAX_LAYER_NUM] = {
36     /* G0 */
37     {
38         .bKeyRgb = 1,
39         .bKeyAlpha = 0,
40         .bGlobalAlpha = 1,
41         .bCmap = 0,
42         .bColFmt = {
43             0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
45         }, /* 25 */
46         .u32MaxWidth = HIFB_MAX_LAYER_WIDTH_G0,
47         .u32MaxHeight = HIFB_MAX_LAYER_HEIGHT_G0,
48         .u32MinWidth = HIFB_MIN_LAYER_WIDTH_G0,
49         .u32MinHeight = HIFB_MIN_LAYER_HEIGH_G0,
50         .u32VDefLevel = 0,
51         .u32HDefLevel = 0,
52         .bLayerSupported = HI_TRUE,
53         .bVoScale = HI_TRUE,
54         .bHasCmapReg = 0,
55         .bDcmp = 0,
56         .bPreMul = 1,
57         .bGHDR = 0,
58     },
59 };
60 
61 /*
62  * the index of array means the number of framebuffer layer, and the value of the array means the mapping
63  * hardware graphic layer
64  * the index number of fb and the actual graphics layer
65  * 0 - HAL_DISP_LAYER_GFX0
66  * 1 - HAL_DISP_LAYER_GFX1
67  * 2 - HAL_DISP_LAYER_GFX3
68  */
69 static hal_disp_layer g_hifblayer_to_hwlayer[HIFB_MAX_LAYER_NUM] = {
70     HAL_DISP_LAYER_GFX0,
71 };
72 
hifb_drv_support_rotate(hi_void)73 hi_bool hifb_drv_support_rotate(hi_void)
74 {
75     return HI_TRUE;
76 }
77 
is_hd_layer(hi_u32 layer_id)78 hi_bool is_hd_layer(hi_u32 layer_id)
79 {
80     return (layer_id == 0);
81 }
82 
is_sd_layer(hi_u32 layer_id)83 hi_bool is_sd_layer(hi_u32 layer_id)
84 {
85     hi_unused(layer_id);
86     return HI_FALSE;
87 }
88 
is_ad_layer(hi_u32 layer_id)89 hi_bool is_ad_layer(hi_u32 layer_id)
90 {
91     hi_unused(layer_id);
92     return HI_FALSE;
93 }
94 
is_cursor_layer(hi_u32 layer_id)95 hi_bool is_cursor_layer(hi_u32 layer_id)
96 {
97     return (layer_id == 2); /* 2 is cursor layer */
98 }
99 
hifb_drv_convert_pixel_format(HIFB_COLOR_FMT_E color_format)100 fb_vo_disp_pixel_format hifb_drv_convert_pixel_format(HIFB_COLOR_FMT_E color_format)
101 {
102     switch (color_format) {
103         case HIFB_FMT_ARGB8888:
104             return HAL_INPUTFMT_ARGB_8888;
105         case HIFB_FMT_ARGB1555:
106             return HAL_INPUTFMT_ARGB_1555;
107         default:
108             return HAL_DISP_PIXELFORMAT_BUTT;
109     }
110 }
111 
112 /*
113  * Frame decompression needs to be offset by 16 bytes;
114  * line decompression does not need
115  */
hifb_drv_get_dcmp_offset_addr(hi_u64 dcmp_addr)116 hi_u64 hifb_drv_get_dcmp_offset_addr(hi_u64 dcmp_addr)
117 {
118     return dcmp_addr;
119 }
120 
hifb_drv_enable_layer(hi_u32 layer_id,hi_bool enable)121 hi_s32 hifb_drv_enable_layer(hi_u32 layer_id, hi_bool enable)
122 {
123     return vou_graphics_enable_layer(g_hifblayer_to_hwlayer[layer_id], enable);
124 }
125 
126 /*
127  * Name : hifb_drv_layer_default_setting
128  * Desc : The default settings for the layer, including the following:
129  *          1.Color key mode
130  *          2.Bit extension mode
131  *          3.alpha, global alpha,CSC,CSC enable, get interface type
132  */
hifb_drv_layer_default_setting(hi_u32 layer_id)133 hi_s32 hifb_drv_layer_default_setting(hi_u32 layer_id)
134 {
135     hal_disp_layer disp_layer = g_hifblayer_to_hwlayer[layer_id];
136 
137     if (g_hifb_gfx_cap[layer_id].bKeyRgb || g_hifb_gfx_cap[layer_id].bKeyAlpha) {
138         vou_graphics_set_gfx_key_mode(disp_layer, FB_VOU_COLORKEY_IN);
139     }
140 
141     vou_graphics_set_gfx_ext(disp_layer, FB_VOU_BITEXT_LOW_HIGHBITS);
142 
143     vou_graphics_set_gfx_palpha(disp_layer, HI_TRUE, HI_TRUE, GRAPHIC_ALPHA_OPACITY, GRAPHIC_ALPHA_OPACITY);
144 
145     vou_graphics_set_layer_galpha(disp_layer, GRAPHIC_ALPHA_OPACITY);
146 
147     vou_graphics_set_csc_coef(disp_layer);
148 
149     vou_graphics_set_csc_en(disp_layer, HI_TRUE);
150 
151     return HI_SUCCESS;
152 }
153 
hifb_drv_set_layer_addr(hi_u32 layer_id,hi_u64 addr)154 hi_s32 hifb_drv_set_layer_addr(hi_u32 layer_id, hi_u64 addr)
155 {
156     hi_bool status = vou_graphics_set_gfx_addr(g_hifblayer_to_hwlayer[layer_id], addr);
157     if (status == HI_FALSE) {
158         return HI_FAILURE;
159     }
160 
161     return HI_SUCCESS;
162 }
163 
hifb_drv_get_layer_addr(hi_u32 layer_id,hi_u64 * phys_addr)164 hi_s32 hifb_drv_get_layer_addr(hi_u32 layer_id, hi_u64 *phys_addr)
165 {
166     hi_bool status = vou_graphics_get_gfx_addr(g_hifblayer_to_hwlayer[layer_id], phys_addr);
167     if (status == HI_FALSE) {
168         return HI_FAILURE;
169     }
170 
171     return HI_SUCCESS;
172 }
173 
hifb_drv_set_layer_stride(hi_u32 layer_id,hi_u32 stride)174 hi_s32 hifb_drv_set_layer_stride(hi_u32 layer_id, hi_u32 stride)
175 {
176     hi_bool status = vou_graphics_set_gfx_stride(g_hifblayer_to_hwlayer[layer_id], stride);
177     if (status == HI_FALSE) {
178         return HI_FAILURE;
179     }
180     return HI_SUCCESS;
181 }
182 
hifb_drv_get_layer_stride_align(hi_u32 layer_id,hi_u32 * stride_align)183 hi_s32 hifb_drv_get_layer_stride_align(hi_u32 layer_id, hi_u32 *stride_align)
184 {
185     hi_unused(layer_id);
186     if (stride_align != HI_NULL) {
187         *stride_align = 16; /* 16 is stride align */
188     }
189     return HI_SUCCESS;
190 }
191 
hifb_drv_set_layer_alpha(hi_u32 layer_id,HIFB_ALPHA_S alpha)192 hi_s32 hifb_drv_set_layer_alpha(hi_u32 layer_id, HIFB_ALPHA_S alpha)
193 {
194     hi_u32 pre_mult_mode = 0;
195     hal_disp_layer disp_layer;
196 
197     if (layer_id >= HIFB_MAX_LAYER_NUM) {
198         return HI_FAILURE;
199     }
200     disp_layer = g_hifblayer_to_hwlayer[layer_id];
201     /* When the premultiply is enabled, the global alpha cannot be 1 */
202     if (alpha.u8GlobalAlpha == 1) {
203         if (vou_graphics_get_gfx_pre_mult(disp_layer, &pre_mult_mode) == HI_FALSE) {
204             return HI_FAILURE;
205         }
206         if (pre_mult_mode == 1) {
207             hi_trace_fb(HI_DBG_ERR, "the global alpha can not set to 1 when the pre-mult mode is enable\n");
208             return HI_FAILURE;
209         }
210     }
211     if (alpha.bAlphaChannel) {
212         vou_graphics_set_layer_galpha(g_hifblayer_to_hwlayer[layer_id], alpha.u8GlobalAlpha);
213     } else {
214         vou_graphics_set_layer_galpha(g_hifblayer_to_hwlayer[layer_id], GRAPHIC_ALPHA_OPACITY);
215     }
216 
217     vou_graphics_set_gfx_palpha(g_hifblayer_to_hwlayer[layer_id], alpha.bAlphaEnable, HI_TRUE, alpha.u8Alpha0,
218                                 alpha.u8Alpha1);
219 
220     return HI_SUCCESS;
221 }
222 
hifb_drv_set_layer_data_fmt(hi_u32 layer_id,HIFB_COLOR_FMT_E data_fmt)223 hi_s32 hifb_drv_set_layer_data_fmt(hi_u32 layer_id, HIFB_COLOR_FMT_E data_fmt)
224 {
225     fb_vo_disp_pixel_format pixel_format_for_hal;
226     hal_disp_layer disp_layer = g_hifblayer_to_hwlayer[layer_id];
227 
228     switch (data_fmt) {
229         case HIFB_FMT_ARGB1555:
230             pixel_format_for_hal = HAL_INPUTFMT_ARGB_1555;
231             /* Pre-multiply enable is not supported when the data format is ARGB1555 */
232             vou_graphics_set_gfx_pre_mult(disp_layer, HI_FALSE);
233             break;
234         case HIFB_FMT_ARGB8888:
235             pixel_format_for_hal = HAL_INPUTFMT_ARGB_8888;
236             break;
237         case HIFB_FMT_ARGB4444:
238             pixel_format_for_hal = HAL_INPUTFMT_ARGB_4444;
239             break;
240         default:
241             hi_trace_fb(HI_DBG_ERR, "HiFB does not support this color format");
242             return HI_FAILURE;
243     }
244 
245     if (vou_graphics_set_layer_data_fmt(disp_layer, pixel_format_for_hal) == HI_FALSE) {
246         return HI_FAILURE;
247     }
248     return HI_SUCCESS;
249 }
250 
hifb_drv_set_layer_src_image_reso(hi_u32 disp_layer,const HIFB_RECT * hifb_rect)251 hi_s32 hifb_drv_set_layer_src_image_reso(hi_u32 disp_layer, const HIFB_RECT *hifb_rect)
252 {
253     HIFB_RECT rect = { 0 };
254     rect.x = hifb_rect->x;
255     rect.y = hifb_rect->y;
256     rect.w = hifb_rect->w;
257     rect.h = hifb_rect->h;
258     if (vou_graphics_set_layer_src_image_reso(g_hifblayer_to_hwlayer[disp_layer], &rect) == HI_FALSE) {
259         return HI_FAILURE;
260     }
261     return HI_SUCCESS;
262 }
263 
hifb_drv_set_layer_rect(hi_u32 layer_id,const HIFB_RECT * input_rect,const HIFB_RECT * output_rect)264 hi_s32 hifb_drv_set_layer_rect(hi_u32 layer_id, const HIFB_RECT *input_rect, const HIFB_RECT *output_rect)
265 {
266     HIFB_RECT rect;
267     fb_vou_scan_mode scan_mode = 0;
268     hi_bool field_update = HI_FALSE;
269     hi_unused(input_rect);
270     rect.x = output_rect->x;
271     rect.y = output_rect->y;
272     rect.w = output_rect->w;
273     rect.h = output_rect->h;
274 
275     if (vou_graphics_get_dev_mode(g_hifblayer_to_hwlayer[layer_id], &scan_mode, &field_update) != HI_SUCCESS) {
276         return HI_FAILURE;
277     }
278 
279     if (scan_mode == FB_VOU_SCAN_MODE_INTERLACE) {
280         /* When interlaced display, the ordinate and height are required to be even */
281         if ((((hi_u32)rect.y & 0x1) == 1) || (((hi_u32)rect.h & 0x1) == 1)) {
282             hi_trace_fb(HI_DBG_ERR, "the height must be even for interlaced device\n");
283             return HI_FAILURE;
284         }
285     }
286 
287     vou_graphics_set_layer_out_rect(g_hifblayer_to_hwlayer[layer_id], &rect);
288 
289     vou_graphics_set_layer_in_rect(g_hifblayer_to_hwlayer[layer_id], &rect);
290 
291     return HI_SUCCESS;
292 }
293 
hifb_drv_set_lay_key_mask(hi_u32 layer_id,const hifb_colorkeyex * colorkey)294 hi_s32 hifb_drv_set_lay_key_mask(hi_u32 layer_id, const hifb_colorkeyex *colorkey)
295 {
296     fb_vo_gfx_key_max key_max_rgb;
297     fb_vo_gfx_key_min key_min_rgb;
298     fb_vo_gfx_mask key_mask_rgb;
299     hal_disp_layer disp_layer = g_hifblayer_to_hwlayer[layer_id];
300 
301     if (colorkey->key_enable) {
302         if (vou_graphics_set_gfx_key_mode(disp_layer, colorkey->key_mode) == HI_FALSE) {
303             return HI_FAILURE;
304         }
305 
306         key_max_rgb.key_max_r = colorkey->red_max;
307         key_max_rgb.key_max_g = colorkey->green_max;
308         key_max_rgb.key_max_b = colorkey->blue_max;
309 
310         key_min_rgb.key_min_r = colorkey->red_min;
311         key_min_rgb.key_min_g = colorkey->green_min;
312         key_min_rgb.key_min_b = colorkey->blue_min;
313 
314         vou_graphics_set_color_key_value(disp_layer, key_max_rgb, key_min_rgb);
315         if (colorkey->mask_enable) {
316             key_mask_rgb.mask_r = colorkey->red_mask;
317             key_mask_rgb.mask_g = colorkey->green_mask;
318             key_mask_rgb.mask_b = colorkey->blue_mask;
319         } else {
320             key_mask_rgb.mask_r = 0;
321             key_mask_rgb.mask_g = 0;
322             key_mask_rgb.mask_b = 0;
323         }
324         vou_graphics_set_color_key_mask(disp_layer, key_mask_rgb);
325     }
326 
327     if (vou_graphics_set_gfx_key_en(disp_layer, colorkey->key_enable) == HI_FALSE) {
328         return HI_FAILURE;
329     }
330 
331     return HI_FAILURE;
332 }
333 
334 #ifdef __HuaweiLite__
hifb_drv_color_convert(const struct hifb_info * info,hifb_colorkeyex * ckey)335 hi_s32 hifb_drv_color_convert(const struct hifb_info *info, hifb_colorkeyex *ckey)
336 {
337     return HI_SUCCESS;
338 }
339 #else
hifb_drv_color_convert(const struct fb_var_screeninfo * var,hifb_colorkeyex * ckey)340 hi_s32 hifb_drv_color_convert(const struct fb_var_screeninfo *var, hifb_colorkeyex *ckey)
341 {
342     hi_u8 r, g, b;
343     hi_u32 key = ckey->key;
344     hi_u8 r_mask, g_mask, b_mask;
345 
346     r = (key >> var->red.offset) << (8 - var->red.length);     /* 8 flip data */
347     g = (key >> var->green.offset) << (8 - var->green.length); /* 8 flip data */
348     b = (key >> var->blue.offset) << (8 - var->blue.length);   /* 8 flip data */
349 
350     r_mask = (0xff >> var->red.length);   /* 0xff bit */
351     g_mask = (0xff >> var->green.length); /* 0xff bit */
352     b_mask = (0xff >> var->blue.length);  /* 0xff bit */
353 
354     ckey->blue_min = b;
355     ckey->green_min = g;
356     ckey->red_min = r;
357 
358     ckey->blue_max = b | b_mask;
359     ckey->green_max = g | b_mask;
360     ckey->red_max = r | b_mask;
361 
362     /* low bits not using when do compare, after extend bits */
363     ckey->red_mask = ~r_mask;
364     ckey->green_mask = ~g_mask;
365     ckey->blue_mask = ~b_mask;
366 
367     ckey->key_mode = 0;
368 
369     ckey->mask_enable = HI_TRUE;
370 
371     return HI_SUCCESS;
372 }
373 #endif
374 
hifb_drv_updata_layer_reg(hi_u32 layer_id)375 hi_s32 hifb_drv_updata_layer_reg(hi_u32 layer_id)
376 {
377     hi_bool status = vou_graphics_set_reg_up(g_hifblayer_to_hwlayer[layer_id]);
378     if (status != HI_TRUE) {
379         return HI_FAILURE;
380     }
381     return HI_SUCCESS;
382 }
383 
hifb_drv_gamma_enable(hi_u32 layer_id,hi_bool enable)384 hi_s32 hifb_drv_gamma_enable(hi_u32 layer_id, hi_bool enable)
385 {
386     hi_unused(layer_id);
387     hi_unused(enable);
388     return HI_FAILURE;
389 }
390 
hifb_drv_set_layer_de_flicker(hi_u32 layer_id,HIFB_DEFLICKER_S de_flicker)391 hi_s32 hifb_drv_set_layer_de_flicker(hi_u32 layer_id, HIFB_DEFLICKER_S de_flicker)
392 {
393     hi_unused(layer_id);
394     hi_unused(de_flicker);
395     return HI_FAILURE;
396 }
397 
hifb_drv_set_color_reg(hi_u32 layer_id,hi_u32 off_set,hi_u32 color,hi_s32 up_flag)398 hi_s32 hifb_drv_set_color_reg(hi_u32 layer_id, hi_u32 off_set, hi_u32 color, hi_s32 up_flag)
399 {
400     hi_unused(layer_id);
401     hi_unused(off_set);
402     hi_unused(color);
403     hi_unused(up_flag);
404     return HI_FAILURE;
405 }
406 
hifb_drv_init(hi_void)407 hi_s32 hifb_drv_init(hi_void)
408 {
409     hi_s32 ret;
410     hi_tde_export_func *tde_export_func = HI_NULL;
411 
412     tde_export_func = func_entry(hi_tde_export_func, HI_ID_TDE);
413     if ((tde_export_func == HI_NULL) || (tde_export_func->drv_tde_module_open == HI_NULL)) {
414         hi_trace_fb(HI_DBG_ERR, "TDE pTdeExportFunc is HI_NULL!\n");
415     } else {
416         ret = tde_export_func->drv_tde_module_open();
417         if (ret) {
418             hi_trace_fb(HI_DBG_ERR, "TDE open failed\n");
419             return ret;
420         }
421     }
422 
423     ret = vou_graphics_resource_init();
424     if (ret) {
425         hi_trace_fb(HI_DBG_ERR, "resource init failed\n");
426         return ret;
427     }
428 
429     return HI_SUCCESS;
430 }
431 
hifb_drv_deinit(hi_void)432 hi_s32 hifb_drv_deinit(hi_void)
433 {
434     hi_tde_export_func *tde_export_func = HI_NULL;
435 
436     vou_graphics_resource_deinit();
437 
438     tde_export_func = func_entry(hi_tde_export_func, HI_ID_TDE);
439     if ((tde_export_func == HI_NULL) || (tde_export_func->drv_tde_module_close == HI_NULL)) {
440         hi_trace_fb(HI_DBG_ERR, "TDE pTdeExportFunc is HI_NULL!\n");
441         return HI_FAILURE;
442     }
443     tde_export_func->drv_tde_module_close();
444 
445     return HI_SUCCESS;
446 }
447 
448 /* set premul data */
hifb_drv_set_pre_mul(hi_u32 layer_id,hi_bool premul)449 hi_s32 hifb_drv_set_pre_mul(hi_u32 layer_id, hi_bool premul)
450 {
451     hal_disp_pixel_format pixel_format = HAL_INPUTFMT_ARGB_1555;
452     hal_disp_layer layer = g_hifblayer_to_hwlayer[layer_id];
453     hi_u8 global_alpha;
454 
455     if (premul == HI_TRUE) {
456         /* When the global alpha configuration is 1, pre-multiplication cannot be enabled. */
457         if (vou_graphics_get_layer_galpha(layer, &global_alpha) != HI_TRUE) {
458             return HI_FAILURE;
459         }
460         if (global_alpha == 1) {
461             hi_trace_fb(HI_DBG_ERR, "not allow to set pre-mult mode when the GlobalAlpha is 1\n");
462             return HI_FAILURE;
463         }
464 
465         /* Pre-multiply enable is not supported when the data format is ARGB1555 */
466         if (vou_graphics_get_layer_data_fmt(layer, &pixel_format) != HI_TRUE) {
467             return HI_FAILURE;
468         }
469         if ((pixel_format == HAL_INPUTFMT_ARGB_1555) || (HAL_INPUTFMT_ARGB_4444 == pixel_format)) {
470             hi_trace_fb(HI_DBG_ERR, "not allow to set pre-mult mode when the color format is ARGB1555 or ARGB4444\n");
471             return HI_FAILURE;
472         }
473     }
474 
475     if (vou_graphics_set_gfx_pre_mult(layer, premul) != HI_TRUE) {
476         return HI_FAILURE;
477     }
478     return HI_SUCCESS;
479 }
480 
hifb_drv_set_clut_addr(hi_u32 layer_id,hi_u32 phy_addr)481 hi_s32 hifb_drv_set_clut_addr(hi_u32 layer_id, hi_u32 phy_addr)
482 {
483     hi_unused(layer_id);
484     hi_unused(phy_addr);
485     return HI_FAILURE;
486 }
487 
hifb_drv_set_int_callback(fb_vo_int_type int_type,int_callback call_back,hi_u32 layer_id,hi_void * call_back_arg)488 hi_s32 hifb_drv_set_int_callback(fb_vo_int_type int_type, int_callback call_back, hi_u32 layer_id,
489                                  hi_void *call_back_arg)
490 {
491     if (layer_id >= HIFB_MAX_LAYER_NUM) {
492         return HI_FAILURE;
493     }
494 
495     return vou_graphics_set_callback(g_hifblayer_to_hwlayer[layer_id], int_type, call_back, call_back_arg);
496 }
497 
498 /*
499  * The premise is that the VO device is enabled and an error is returned when the VO device is not enabled.
500  * For X5HD, the current configuration content of the graphics layer is obtained for the boot screen;
501  * for the 3531, since the boot screen is not required, only the device resolution and scan information
502  * can be obtained.
503  */
hifb_drv_get_osd_data(hi_u32 layer_id,hifb_osd_data * layer_data)504 hi_s32 hifb_drv_get_osd_data(hi_u32 layer_id, hifb_osd_data *layer_data)
505 {
506     hi_u32 width = 0;
507     hi_u32 height = 0;
508     hi_s32 ret;
509     hal_disp_layer layer = g_hifblayer_to_hwlayer[layer_id];
510     fb_vou_scan_mode scan_mode = 0;
511 
512     ret = vou_graphics_get_intf_size(layer, &width, &height);
513     if (ret != HI_SUCCESS) {
514         hi_trace_fb(HI_DBG_ERR, "Failed to get screen width and height!\n");
515         return HI_FAILURE;
516     }
517 
518     ret = vou_graphics_get_gfx_addr(layer, &layer_data->buffer_phy_addr);
519     if (ret != HI_TRUE) {
520         return HI_FAILURE;
521     }
522 
523     ret = vou_graphics_get_gfx_stride(layer, &layer_data->stride);
524     if (ret != HI_TRUE) {
525         return HI_FAILURE;
526     }
527 
528     ret = vou_graphics_get_dev_mode(layer, &scan_mode, &layer_data->feild_update);
529     if (ret != HI_SUCCESS) {
530         return HI_FAILURE;
531     }
532     if (scan_mode == FB_VOU_SCAN_MODE_INTERLACE) {
533         layer_data->scan_mode = HIFB_SCANMODE_I;
534     } else {
535         layer_data->scan_mode = HIFB_SCANMODE_P;
536     }
537 
538     layer_data->screen_height = height;
539     layer_data->screen_width = width;
540 
541     return HI_SUCCESS;
542 }
543 
hifb_open_layer(hi_u32 layer_id)544 hi_s32 hifb_open_layer(hi_u32 layer_id)
545 {
546     return vou_graphics_open_layer(g_hifblayer_to_hwlayer[layer_id]);
547 }
548 
hifb_close_layer(hi_u32 layer_id)549 hi_s32 hifb_close_layer(hi_u32 layer_id)
550 {
551     return vou_graphics_close_layer(g_hifblayer_to_hwlayer[layer_id]);
552 }
553 
554 /*
555  * open vo & close vo -- For internal debugging only
556  * (for the API that does not adjust VO, the device can display the graphics layer)
557  */
hifb_drv_open_display(hi_void)558 hi_s32 hifb_drv_open_display(hi_void)
559 {
560     return HI_SUCCESS;
561 }
562 
563 /* close vou */
hifb_drv_close_display(hi_void)564 hi_s32 hifb_drv_close_display(hi_void)
565 {
566     return HI_SUCCESS;
567 }
568 
tde_cal_scale_rect_hifb(const hi_tde_rect * src_rect,const hi_tde_rect * dst_rect,hi_tde_rect * rect_in_src,hi_tde_rect * rect_in_dst)569 hi_s32 tde_cal_scale_rect_hifb(const hi_tde_rect *src_rect, const hi_tde_rect *dst_rect, hi_tde_rect *rect_in_src,
570                                hi_tde_rect *rect_in_dst)
571 {
572     if ((rect_in_dst == HI_NULL) || (src_rect == HI_NULL) || (src_rect->width == 0) || (src_rect->height == 0)) {
573         hi_trace_fb(HI_DBG_ERR, "invalid arguments!\n");
574         return HI_FALSE;
575     }
576 
577     rect_in_dst->pos_x = rect_in_src->pos_x * dst_rect->width / src_rect->width;
578     rect_in_dst->pos_y = rect_in_src->pos_y * dst_rect->height / src_rect->height;
579     rect_in_dst->height = dst_rect->height;
580     rect_in_dst->width = dst_rect->width;
581 
582     return HI_SUCCESS;
583 }
584 
hifb_drv_enable_dcmp(hi_u32 layer_id,hi_bool enable)585 hi_bool hifb_drv_enable_dcmp(hi_u32 layer_id, hi_bool enable)
586 {
587     hi_unused(layer_id);
588     hi_unused(enable);
589     return HI_TRUE;
590 }
591 
hifb_drv_get_dcmp_enable_state(hi_u32 layer_id,hi_bool * enable)592 hi_bool hifb_drv_get_dcmp_enable_state(hi_u32 layer_id, hi_bool *enable)
593 {
594     hi_unused(layer_id);
595     hi_unused(enable);
596     return HI_TRUE;
597 }
598 
hifb_drv_set_dcmp_info(hi_u32 layer_id,fb_vo_graphic_dcmp_info * dcmp_info)599 hi_bool hifb_drv_set_dcmp_info(hi_u32 layer_id, fb_vo_graphic_dcmp_info *dcmp_info)
600 {
601     hi_unused(layer_id);
602     hi_unused(dcmp_info);
603     return HI_TRUE;
604 }
605 
hifb_drv_enable_ghdr(hi_u32 layer_id,hi_bool enable)606 hi_bool hifb_drv_enable_ghdr(hi_u32 layer_id, hi_bool enable)
607 {
608     hi_unused(layer_id);
609     hi_unused(enable);
610     return HI_SUCCESS;
611 }
612 
hifb_drv_enable_zme(hi_u32 layer_id,HIFB_RECT * in_rect,HIFB_RECT * out_rect,hi_bool enable)613 hi_bool hifb_drv_enable_zme(hi_u32 layer_id, HIFB_RECT *in_rect, HIFB_RECT *out_rect, hi_bool enable)
614 {
615     RECT_S in;
616     RECT_S out;
617 
618     if (layer_id >= HIFB_MAX_LAYER_NUM) {
619         hi_trace_fb(HI_DBG_ERR, "Invalid layer ID %u.\n", layer_id);
620         return HI_FALSE;
621     }
622     in.u32Width = in_rect->w;
623     in.u32Height = in_rect->h;
624     out.u32Width = out_rect->w;
625     out.u32Height = out_rect->h;
626 
627     if (g_hifblayer_to_hwlayer[layer_id] == HAL_DISP_LAYER_GFX0) {
628         return vou_graphics_enable_zme(g_hifblayer_to_hwlayer[layer_id], &in, &out, enable);
629     } else {
630         if (enable) {
631             hi_trace_fb(HI_DBG_ERR, "G%u does not support zme.\n", layer_id);
632         }
633         return HI_TRUE;
634     }
635 }
636 
hifb_drv_is_layer_support_zoom_out(hi_u32 layer_id)637 hi_bool hifb_drv_is_layer_support_zoom_out(hi_u32 layer_id)
638 {
639     hi_unused(layer_id);
640     return HI_FALSE;
641 }
642 
hifb_drv_enable_wbc_int(hi_u32 layer_id,hi_bool enable)643 hi_void hifb_drv_enable_wbc_int(hi_u32 layer_id, hi_bool enable)
644 {
645     hi_unused(layer_id);
646     hi_unused(enable);
647     return;
648 }
649 
hifb_drv_set_wbc_info(hi_u32 layer_id,fb_vo_graphic_wbc_info * wbc_info)650 hi_void hifb_drv_set_wbc_info(hi_u32 layer_id, fb_vo_graphic_wbc_info *wbc_info)
651 {
652     hi_unused(layer_id);
653     hi_unused(wbc_info);
654     return;
655 }
656 
hifb_drv_enable_wbc(hi_u32 layer_id,hi_bool enable)657 hi_void hifb_drv_enable_wbc(hi_u32 layer_id, hi_bool enable)
658 {
659     hi_unused(layer_id);
660     hi_unused(enable);
661     return;
662 }
663 
hifb_drv_get_wbc_en_state(hi_u32 layer_id,hi_bool * wbc_en)664 hi_void hifb_drv_get_wbc_en_state(hi_u32 layer_id, hi_bool *wbc_en)
665 {
666     hi_unused(layer_id);
667     hi_unused(wbc_en);
668     return;
669 }
670 
hifb_drv_get_wbc_stop_state(hi_u32 layer_id,hi_bool * wbc_stop)671 hi_void hifb_drv_get_wbc_stop_state(hi_u32 layer_id, hi_bool *wbc_stop)
672 {
673     hi_unused(layer_id);
674     hi_unused(wbc_stop);
675     return;
676 }
677 
678 #ifdef MDDRDETECT
hifb_drv_is_layer_support_ddrdetect(hi_u32 layer_id)679 static hi_bool hifb_drv_is_layer_support_ddrdetect(hi_u32 layer_id)
680 {
681     hi_unused(layer_id);
682     return HI_FALSE;
683 }
684 
hifb_drv_set_ddr_detect_zone(hi_u32 start_id,hi_u32 cnt,fb_vo_mddrc_zone_addr * zone_addr)685 static hi_void hifb_drv_set_ddr_detect_zone(hi_u32 start_id, hi_u32 cnt, fb_vo_mddrc_zone_addr *zone_addr)
686 {
687     hi_unused(start_id);
688     hi_unused(cnt);
689     hi_unused(zone_addr);
690     return;
691 }
692 
hifb_drv_get_mddr_status(hi_u32 start_id,hi_u32 cnt,hi_u32 * status)693 static hi_void hifb_drv_get_mddr_status(hi_u32 start_id, hi_u32 cnt, hi_u32 *status)
694 {
695     hi_unused(start_id);
696     hi_unused(cnt);
697     hi_unused(status);
698     return;
699 }
700 
hifb_drv_clear_ddrdectect_zone(hi_u32 start_id,hi_u32 cnt)701 hi_void hifb_drv_clear_ddrdectect_zone(hi_u32 start_id, hi_u32 cnt)
702 {
703     hi_unused(start_id);
704     hi_unused(cnt);
705     return;
706 }
707 
hifb_drv_check_ddr_dectect_zone(hi_u32 layer_id,hi_u32 new_start_id,hi_u32 new_cnt,hi_u32 pre_start_id,hi_u32 pre_cnt)708 hi_s32 hifb_drv_check_ddr_dectect_zone(hi_u32 layer_id, hi_u32 new_start_id, hi_u32 new_cnt, hi_u32 pre_start_id,
709                                        hi_u32 pre_cnt)
710 {
711     hi_unused(layer_id);
712     hi_unused(new_start_id);
713     hi_unused(new_cnt);
714     hi_unused(pre_start_id);
715     hi_unused(pre_cnt);
716     return HI_FAILURE;
717 }
718 
hifb_drv_get_ddr_zone_cfg(hi_u32 layer_id,hi_u32 * start_id,hi_u32 * cnt)719 hi_void hifb_drv_get_ddr_zone_cfg(hi_u32 layer_id, hi_u32 *start_id, hi_u32 *cnt)
720 {
721     hi_unused(layer_id);
722     hi_unused(start_id);
723     hi_unused(cnt);
724     return;
725 }
726 #endif
727 
hifb_drv_graphics_enable_int(hi_u32 layer_id,hi_bool enable)728 hi_bool hifb_drv_graphics_enable_int(hi_u32 layer_id, hi_bool enable)
729 {
730     return (vou_graphics_enable_int(layer_id, enable) == HI_SUCCESS ? HI_TRUE : HI_FALSE);
731 }
732 
hifb_drv_graphics_clear_int(hi_u32 int_clear,hi_s32 irq)733 hi_bool hifb_drv_graphics_clear_int(hi_u32 int_clear, hi_s32 irq)
734 {
735     return vou_graphics_clear_int(int_clear, irq);
736 }
737 
hifb_drv_graphics_get_int(hi_u32 * int_status)738 hi_bool hifb_drv_graphics_get_int(hi_u32 *int_status)
739 {
740     return vou_graphics_get_int(int_status);
741 }
742 
hifb_drv_graphics_clear_int_status(hi_u32 int_status)743 hi_bool hifb_drv_graphics_clear_int_status(hi_u32 int_status)
744 {
745     return vou_graphics_clear_int_status(int_status);
746 }
747 
hifb_drv_graphics_get_interrupt_dev(hi_u32 int_status,hifb_vo_dev * vo_dev)748 hi_s32 hifb_drv_graphics_get_interrupt_dev(hi_u32 int_status, hifb_vo_dev *vo_dev)
749 {
750     return vou_graphics_get_interrupt_dev(int_status, vo_dev);
751 }
752 
753 #ifdef MDDRDETECT
get_ddr_detect_ops(hifb_drv_ops * ops)754 static hi_void get_ddr_detect_ops(hifb_drv_ops *ops)
755 {
756     ops->hifb_drv_is_layer_support_ddr_detect = hifb_drv_is_layer_support_ddrdetect;
757     ops->hifb_drv_get_mddr_status = hifb_drv_get_mddr_status;
758     ops->hifb_drv_set_mddr_detect_zone = hifb_drv_set_ddr_detect_zone;
759     ops->hifb_drv_clear_ddr_dectect_zone = hifb_drv_clear_ddrdectect_zone;
760     ops->hifb_drv_check_ddr_dectect_zone = hifb_drv_check_ddr_dectect_zone;
761     ops->hifb_drv_get_ddr_zone_cfg = hifb_drv_get_ddr_zone_cfg;
762     ops->hifb_drv_init_mddr = vou_graphics_init_mddr_detect;
763     return;
764 }
765 #endif
766 
get_implement_ops(hifb_drv_ops * ops)767 static hi_void get_implement_ops(hifb_drv_ops *ops)
768 {
769     ops->hifb_drv_init = hifb_drv_init;
770     ops->hifb_drv_deinit = hifb_drv_deinit;
771     ops->hifb_drv_enable_layer = hifb_drv_enable_layer;
772     ops->hifb_drv_layer_default_setting = hifb_drv_layer_default_setting;
773     ops->hifb_drv_set_layer_addr = hifb_drv_set_layer_addr;
774     ops->hifb_drv_get_layer_addr = hifb_drv_get_layer_addr;
775     ops->hifb_drv_set_layer_stride = hifb_drv_set_layer_stride;
776     ops->hifb_drv_set_layer_alpha = hifb_drv_set_layer_alpha;
777     ops->hifb_drv_set_layer_data_fmt = hifb_drv_set_layer_data_fmt;
778     ops->hifb_drv_set_layer_rect = hifb_drv_set_layer_rect;
779     ops->hifb_drv_set_layer_src_image_reso = hifb_drv_set_layer_src_image_reso;
780     ops->hifb_drv_set_layer_key_mask = hifb_drv_set_lay_key_mask;
781     ops->hifb_drv_color_convert = hifb_drv_color_convert;
782     ops->hifb_drv_updata_layer_reg = hifb_drv_updata_layer_reg;
783     ops->hifb_drv_set_int_callback = hifb_drv_set_int_callback;
784     ops->hifb_drv_set_layer_de_flicker = hifb_drv_set_layer_de_flicker;
785     ops->hifb_drv_set_color_reg = hifb_drv_set_color_reg;
786     ops->hifb_drv_set_pre_mul = hifb_drv_set_pre_mul;
787     ops->hifb_drv_set_clut_addr = hifb_drv_set_clut_addr;
788     ops->hifb_drv_get_osd_data = hifb_drv_get_osd_data;
789     ops->hifb_drv_open_display = hifb_drv_open_display;
790     ops->hifb_drv_close_display = hifb_drv_close_display;
791     ops->hifb_open_layer = hifb_open_layer;
792     ops->hifb_close_layer = hifb_close_layer;
793 
794     ops->hifb_drv_enable_wbc_int = hifb_drv_enable_wbc_int;
795     ops->hifb_drv_get_wbc_stop_state = hifb_drv_get_wbc_stop_state;
796     ops->hifb_drv_enable_wbc = hifb_drv_enable_wbc;
797     ops->hifb_drv_set_wbc_info = hifb_drv_set_wbc_info;
798     ops->hifb_drv_get_wbc_en_state = hifb_drv_get_wbc_en_state;
799     ops->hifb_drv_set_dcmp_info = hifb_drv_set_dcmp_info;
800     ops->hifb_drv_enable_dcmp = hifb_drv_enable_dcmp;
801     ops->hifb_drv_get_dcmp_enable_state = hifb_drv_get_dcmp_enable_state;
802     return;
803 }
804 
hifb_drv_get_ops(hifb_drv_ops * ops)805 hi_void hifb_drv_get_ops(hifb_drv_ops *ops)
806 {
807     ops->layer_count = HIFB_MAX_LAYER_NUM;
808     ops->capability = (HIFB_CAPABILITY_S *)g_hifb_gfx_cap;
809 
810     /* implement */
811     get_implement_ops(ops);
812 #ifdef MDDRDETECT
813     get_ddr_detect_ops(ops);
814 #endif
815     /* For GHDR */
816     ops->hifb_drv_enable_ghdr = hifb_drv_enable_ghdr;
817     /* for zme */
818     ops->hifb_drv_enable_zme = hifb_drv_enable_zme;
819     ops->hifb_drv_is_layer_support_zoom_out = hifb_drv_is_layer_support_zoom_out;
820     /* for int */
821     ops->hifb_drv_graphics_enable_int = hifb_drv_graphics_enable_int;
822     ops->hifb_drv_graphics_clear_int = hifb_drv_graphics_clear_int;
823     ops->hifb_drv_graphics_get_int = hifb_drv_graphics_get_int;
824     ops->hifb_drv_graphics_clear_int_status = hifb_drv_graphics_clear_int_status;
825     ops->hifb_drv_graphics_get_int_dev = hifb_drv_graphics_get_interrupt_dev;
826 }
827