• 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 #ifndef __HIFB_H__
20 #define __HIFB_H__
21 
22 #ifdef __HuaweiLite__
23 #include <fb.h>
24 #include <linux/wait.h>
25 #include "stdlib.h"
26 #include <linux/workqueue.h>
27 #include <linux/kernel.h>
28 #include <linux/device.h>
29 #include "liteos/fb.h"
30 #else
31 #include <linux/fb.h>
32 #endif
33 
34 #include "hi_type.h"
35 #include "hi_common.h"
36 
37 #ifdef __cplusplus
38 #if __cplusplus
39 extern "C" {
40 #endif
41 #endif /* __cplusplus */
42 
43 #define IOC_TYPE_HIFB 'F'
44 /* To obtain the colorkey of an overlay layer */
45 #define FBIOGET_COLORKEY_HIFB _IOR(IOC_TYPE_HIFB, 90, HIFB_COLORKEY_S)
46 /* To set the colorkey of an overlay layer */
47 #define FBIOPUT_COLORKEY_HIFB _IOW(IOC_TYPE_HIFB, 91, HIFB_COLORKEY_S)
48 /* To get the alpha of an overlay layer */
49 #define FBIOGET_ALPHA_HIFB _IOR(IOC_TYPE_HIFB, 92, HIFB_ALPHA_S)
50 /* To set the alpha of an overlay layer */
51 #define FBIOPUT_ALPHA_HIFB _IOW(IOC_TYPE_HIFB, 93, HIFB_ALPHA_S)
52 /* To get the origin of an overlay layer on the screen */
53 #define FBIOGET_SCREEN_ORIGIN_HIFB _IOR(IOC_TYPE_HIFB, 94, HIFB_POINT_S)
54 /* To set the origin of an overlay layer on the screen */
55 #define FBIOPUT_SCREEN_ORIGIN_HIFB _IOW(IOC_TYPE_HIFB, 95, HIFB_POINT_S)
56 /* To obtain the anti-flicker setting of an overlay layer */
57 #define FBIOGET_DEFLICKER_HIFB _IOR(IOC_TYPE_HIFB, 98, HIFB_DEFLICKER_S)
58 /* To set the anti-flicker setting of an overlay layer */
59 #define FBIOPUT_DEFLICKER_HIFB _IOW(IOC_TYPE_HIFB, 99, HIFB_DEFLICKER_S)
60 /* To wait for the vertical blanking region of an overlay layer */
61 #define FBIOGET_VBLANK_HIFB _IO(IOC_TYPE_HIFB, 100)
62 /* To set the display state of an overlay layer */
63 #define FBIOPUT_SHOW_HIFB _IOW(IOC_TYPE_HIFB, 101, HI_BOOL)
64 /* To obtain the display state of an overlay layer */
65 #define FBIOGET_SHOW_HIFB _IOR(IOC_TYPE_HIFB, 102, HI_BOOL)
66 /* to obtain the capability of an overlay layer */
67 #define FBIOGET_CAPABILITY_HIFB _IOR(IOC_TYPE_HIFB, 103, HIFB_CAPABILITY_S)
68 /* set the screen output size */
69 #define FBIOPUT_SCREENSIZE _IOW(IOC_TYPE_HIFB, 130, HIFB_SIZE_S)
70 /* get the screen output size */
71 #define FBIOGET_SCREENSIZE _IOR(IOC_TYPE_HIFB, 131, HIFB_SIZE_S)
72 
73 /* To display multiple surfaces in turn and set the alpha and colorkey attributes */
74 #define FBIOFLIP_SURFACE _IOW(IOC_TYPE_HIFB, 132, HIFB_SURFACEEX_S)
75 
76 /* To set the compression function status of an overlay layer */
77 #define FBIOPUT_COMPRESSION_HIFB _IOW(IOC_TYPE_HIFB, 133, HI_BOOL)
78 /* To obtain the compression function status of an overlay layer */
79 #define FBIOGET_COMPRESSION_HIFB _IOR(IOC_TYPE_HIFB, 134, HI_BOOL)
80 
81 /* To set the hdr function status of an overlay layer */
82 #define FBIOPUT_DYNAMIC_RANGE_HIFB _IOW(IOC_TYPE_HIFB, 139, HIFB_DYNAMIC_RANGE_E)
83 /* To get the hdr function status of an overlay layer */
84 #define FBIOGET_DYNAMIC_RANGE_HIFB _IOR(IOC_TYPE_HIFB, 140, HIFB_DYNAMIC_RANGE_E)
85 
86 /* To create the layer */
87 #define FBIO_CREATE_LAYER _IO(IOC_TYPE_HIFB, 149)
88 /* To destroy the layer */
89 #define FBIO_DESTROY_LAYER _IO(IOC_TYPE_HIFB, 150)
90 
91 #ifdef CONFIG_DRIVERS_HDF_DISP
92 #define FBIO_PANEL_SET_POWERSTATUS         _IOW(IOC_TYPE_HIFB, 151, HI_U32)
93 #define FBIO_PANEL_SET_BACKLIGHT           _IOW(IOC_TYPE_HIFB, 152, HI_U32)
94 
95 enum PowerStatus {
96     POWER_STATUS_ON,              /* The power status is on */
97     POWER_STATUS_STANDBY,         /* The power status is standby */
98     POWER_STATUS_SUSPEND,         /* The power status is suspend */
99     POWER_STATUS_OFF,             /* The power status is off */
100     POWER_STATUS_BUTT
101 };
102 
103 extern int32_t DispOn(uint32_t devId);
104 extern int32_t DispOff(uint32_t devId);
105 extern int32_t SetDispBacklight(uint32_t devId, uint32_t level);
106 #endif
107 
108 typedef struct {
109     HI_U32 u32Width;
110     HI_U32 u32Height;
111 } HIFB_SIZE_S;
112 
113 #ifndef __HuaweiLite__
hifb_rgb(const struct fb_bitfield * pBit,HI_S32 color)114 static inline HI_U8 hifb_rgb(const struct fb_bitfield *pBit, HI_S32 color)
115 {
116     return ((HI_U8)((((HI_U32)color) >> pBit->offset) << (8 - pBit->length)) + /* 8 Digits to flip */
117             ((HI_U8)(((HI_U32)(color) >> pBit->offset) << (8 - pBit->length)) >> pBit->length)); /* 8 Digits to flip */
118 }
119 
hifb_color2key(const struct fb_var_screeninfo * pVar,HI_S32 color)120 static inline HI_S32 hifb_color2key(const struct fb_var_screeninfo *pVar, HI_S32 color)
121 {
122     if (pVar->bits_per_pixel <= 8) { /* 8 left shift */
123         return color;
124     } else {
125         HI_U8 r, g, b;
126         r = hifb_rgb(&pVar->red, color);
127         g = hifb_rgb(&pVar->green, color);
128         b = hifb_rgb(&pVar->blue, color);
129         return (r << 16) + (g << 8) + b; /* left shift altitude 16 8 */
130     }
131 }
132 #endif
133 
134 typedef enum {
135     HIFB_DYNAMIC_RANGE_SDR8 = 0,
136     HIFB_DYNAMIC_RANGE_SDR10,
137     HIFB_DYNAMIC_RANGE_HDR10,
138     HIFB_DYNAMIC_RANGE_HLG,
139     HIFB_DYNAMIC_RANGE_SLF,
140     HIFB_DYNAMIC_RANGE_BUTT
141 } HIFB_DYNAMIC_RANGE_E;
142 
143 typedef struct {
144     HI_BOOL bKeyEnable; /* colorkey enable flag */
145     HI_U32 u32Key;      /* colorkey value, maybe contains alpha */
146 } HIFB_COLORKEY_S;
147 
148 typedef struct {
149     HI_S32 x;
150     HI_S32 y;
151     HI_S32 w;
152     HI_S32 h;
153 } HIFB_RECT;
154 
155 typedef struct {
156     HI_S32 s32XPos; /* horizontal position */
157     HI_S32 s32YPos; /* vertical position */
158 } HIFB_POINT_S;
159 
160 typedef struct {
161     HI_U32 u32HDfLevel;          /* horizontal deflicker level */
162     HI_U32 u32VDfLevel;          /* vertical deflicker level */
163     HI_U8 ATTRIBUTE *pu8HDfCoef; /* horizontal deflicker coefficient */
164     HI_U8 ATTRIBUTE *pu8VDfCoef; /* vertical deflicker coefficient */
165 } HIFB_DEFLICKER_S;
166 
167 /* Alpha info */
168 typedef struct {
169     HI_BOOL bAlphaEnable;  /* alpha enable flag */
170     HI_BOOL bAlphaChannel; /* alpha channel enable flag */
171     HI_U8 u8Alpha0;        /* alpha0 value, used in ARGB1555 */
172     HI_U8 u8Alpha1;        /* alpha1 value, used in ARGB1555 */
173     HI_U8 u8GlobalAlpha;   /* global alpha value */
174     HI_U8 u8Reserved;
175 } HIFB_ALPHA_S;
176 
177 typedef enum {
178     HIFB_FMT_RGB565 = 0,
179     HIFB_FMT_RGB888, /* RGB888 24bpp */
180 
181     HIFB_FMT_KRGB444, /* RGB444 16bpp */
182     HIFB_FMT_KRGB555, /* RGB555 16bpp */
183     HIFB_FMT_KRGB888, /* RGB888 32bpp */
184 
185     HIFB_FMT_ARGB4444, /* ARGB4444 */
186     HIFB_FMT_ARGB1555, /* ARGB1555 */
187     HIFB_FMT_ARGB8888, /* ARGB8888 */
188     HIFB_FMT_ARGB8565, /* ARGB8565 */
189 
190     HIFB_FMT_RGBA4444, /* ARGB4444 */
191     HIFB_FMT_RGBA5551, /* RGBA5551 */
192     HIFB_FMT_RGBA5658, /* RGBA5658 */
193     HIFB_FMT_RGBA8888, /* RGBA8888 */
194 
195     HIFB_FMT_BGR565,   /* BGR565 */
196     HIFB_FMT_BGR888,   /* BGR888 */
197     HIFB_FMT_ABGR4444, /* ABGR4444 */
198     HIFB_FMT_ABGR1555, /* ABGR1555 */
199     HIFB_FMT_ABGR8888, /* ABGR8888 */
200     HIFB_FMT_ABGR8565, /* ABGR8565 */
201     HIFB_FMT_KBGR444,  /* BGR444 16bpp */
202     HIFB_FMT_KBGR555,  /* BGR555 16bpp */
203     HIFB_FMT_KBGR888,  /* BGR888 32bpp */
204 
205     HIFB_FMT_1BPP,     /* clut1 */
206     HIFB_FMT_2BPP,     /* clut2 */
207     HIFB_FMT_4BPP,     /* clut4 */
208     HIFB_FMT_8BPP,     /* clut8 */
209     HIFB_FMT_ACLUT44,  /* AClUT44 */
210     HIFB_FMT_ACLUT88,  /* ACLUT88 */
211     HIFB_FMT_PUYVY,    /* UYVY */
212     HIFB_FMT_PYUYV,    /* YUYV */
213     HIFB_FMT_PYVYU,    /* YVYU */
214     HIFB_FMT_YUV888,   /* YUV888 */
215     HIFB_FMT_AYUV8888, /* AYUV8888 */
216     HIFB_FMT_YUVA8888, /* YUVA8888 */
217     HIFB_FMT_BUTT
218 } HIFB_COLOR_FMT_E;
219 
220 typedef struct {
221     HI_BOOL bKeyRgb;
222     HI_BOOL bKeyAlpha;              /* whether support colorkey alpha */
223     HI_BOOL bGlobalAlpha;           /* whether support global alpha */
224     HI_BOOL bCmap;                  /* whether support color map */
225     HI_BOOL bHasCmapReg;            /* whether has color map register */
226     HI_BOOL bColFmt[HIFB_FMT_BUTT]; /* support which color format */
227     HI_BOOL bVoScale;               /* support vo scale */
228     /* whether support a certain layer, for example:x5 HD support HIFB_SD_0 not support HIFB_SD_1 */
229     HI_BOOL bLayerSupported;
230     HI_U32 u32MaxWidth;     /* the max pixels per line */
231     HI_U32 u32MaxHeight;    /* the max lines */
232     HI_U32 u32MinWidth;     /* the min pixels per line */
233     HI_U32 u32MinHeight;    /* the min lines */
234     HI_U32 u32VDefLevel;    /* vertical deflicker level, 0 means vertical deflicker is unsupported */
235     HI_U32 u32HDefLevel;    /* horizontal deflicker level, 0 means horizontal deflicker is unsupported */
236     HI_BOOL bDcmp;
237     HI_BOOL bPreMul;
238     HI_BOOL bGHDR; /* NEW Feature. Is GHDR supported. */
239 } HIFB_CAPABILITY_S;
240 
241 /* refresh mode */
242 typedef enum {
243     HIFB_LAYER_BUF_DOUBLE = 0x0, /* 2 display buf in fb */
244     HIFB_LAYER_BUF_ONE = 0x1,    /* 1 display buf in fb */
245     HIFB_LAYER_BUF_NONE = 0x2,   /* no display buf in fb,the buf user refreshed will be directly set to VO */
246     HIFB_LAYER_BUF_DOUBLE_IMMEDIATE = 0x3, /* 2 display buf in fb, each refresh will be displayed */
247     HIFB_LAYER_BUF_FENCE = 0x4,            /* 2 display buf in fb with fence */
248     HIFB_LAYER_BUF_BUTT
249 } HIFB_LAYER_BUF_E;
250 
251 /* surface info */
252 typedef struct {
253     HI_U64 u64PhyAddr;                   /* start physical address */
254     HI_U64 u64GBPhyAddr;
255     HI_U32 u32Width;                     /* width pixels */
256     HI_U32 u32Height;                    /* height pixels */
257     HI_U32 u32Pitch;                     /* line pixels */
258     HIFB_COLOR_FMT_E enFmt;              /* color format */
259     HIFB_DYNAMIC_RANGE_E enDynamicRange; /* NEW dynamic range. */
260 } HIFB_SURFACE_S;
261 
262 typedef struct {
263     HI_U64 u64PhyAddr;
264     HIFB_ALPHA_S stAlpha;
265     HIFB_COLORKEY_S stColorkey;
266 } HIFB_SURFACEEX_S;
267 
268 /* refresh surface info */
269 typedef struct {
270     HIFB_SURFACE_S stCanvas;
271     HIFB_RECT UpdateRect; /* refresh region */
272 } HIFB_BUFFER_S;
273 
274 /* cursor info */
275 typedef struct {
276     HIFB_SURFACE_S stCursor;
277     HIFB_POINT_S stHotPos;
278 } HIFB_CURSOR_S;
279 
280 /* DDR detect zone info */
281 typedef struct {
282     HI_U32 u32StartSection;
283     HI_U32 u32ZoneNums;
284 } HIFB_DDRZONE_S;
285 
286 /* cursor handle */
287 /* Attention:surface in cursor will be released by user */
288 #define FBIOPUT_CURSOR_INFO _IOW(IOC_TYPE_HIFB, 104, HIFB_CURSOR_S)
289 #define FBIOGET_CURSOR_INFO _IOW(IOC_TYPE_HIFB, 105, HIFB_CURSOR_S)
290 
291 #define FBIOPUT_CURSOR_STATE _IOW(IOC_TYPE_HIFB, 106, HI_BOOL)
292 #define FBIOGET_CURSOR_STATE _IOW(IOC_TYPE_HIFB, 107, HI_BOOL)
293 
294 #define FBIOPUT_CURSOR_POS _IOW(IOC_TYPE_HIFB, 108, HIFB_POINT_S)
295 #define FBIOGET_CURSOR_POS _IOR(IOC_TYPE_HIFB, 109, HIFB_POINT_S)
296 
297 #define FBIOPUT_CURSOR_COLORKEY _IOR(IOC_TYPE_HIFB, 110, HIFB_COLORKEY_S)
298 #define FBIOGET_CURSOR_COLORKEY _IOW(IOC_TYPE_HIFB, 111, HIFB_COLORKEY_S)
299 #define FBIOPUT_CURSOR_ALPHA _IOR(IOC_TYPE_HIFB, 112, HIFB_ALPHA_S)
300 #define FBIOGET_CURSOR_ALPHA _IOW(IOC_TYPE_HIFB, 113, HIFB_ALPHA_S)
301 
302 /*
303  * cursor will be separated from attached layer automatically if you attach cursor to another layer,that means
304  * cursor can be attached to only one layer at any time
305  */
306 #define FBIOPUT_CURSOR_ATTCHCURSOR _IOW(IOC_TYPE_HIFB, 114, HI_U32)
307 #define FBIOPUT_CURSOR_DETACHCURSOR _IOW(IOC_TYPE_HIFB, 115, HI_U32)
308 
309 /* Auto means fb will choose a appropriate antiflicker level automatically according to the color info of map */
310 typedef enum {
311     HIFB_LAYER_ANTIFLICKER_NONE = 0x0,   /* no antiflicker */
312     HIFB_LAYER_ANTIFLICKER_LOW = 0x1,    /* low level */
313     HIFB_LAYER_ANTIFLICKER_MIDDLE = 0x2, /* middle level */
314     HIFB_LAYER_ANTIFLICKER_HIGH = 0x3,   /* high level */
315     HIFB_LAYER_ANTIFLICKER_AUTO = 0x4,   /* auto */
316     HIFB_LAYER_ANTIFLICKER_BUTT
317 } HIFB_LAYER_ANTIFLICKER_LEVEL_E;
318 
319 /* MIRROR mode */
320 typedef enum {
321     HIFB_MIRROR_NONE = 0x0,
322     HIFB_MIRROR_HORIZONTAL = 0x1,
323     HIFB_MIRROR_VERTICAL = 0x2,
324     HIFB_MIRROR_BOTH = 0x3,
325     HIFB_MIRROR_BUTT
326 } HIFB_MIRROR_MODE_E;
327 
328 /* ROTATE mode */
329 typedef enum {
330     HIFB_ROTATE_NONE = 0x0,
331     HIFB_ROTATE_90 = 0x1,
332     HIFB_ROTATE_180 = 0x2,
333     HIFB_ROTATE_270 = 0x3,
334     HIFB_ROTATE_BUTT
335 } HIFB_ROTATE_MODE_E;
336 
337 /* layer info maskbit */
338 typedef enum {
339     HIFB_LAYERMASK_BUFMODE = 0x1,          /* BUFMODE bitmask */
340     HIFB_LAYERMASK_ANTIFLICKER_MODE = 0x2, /* ANTIFLICKER_MODE bitmask */
341     HIFB_LAYERMASK_POS = 0x4,              /* the position bitmask */
342     HIFB_LAYERMASK_CANVASSIZE = 0x8,       /* canvassize bitmask */
343     HIFB_LAYERMASK_DISPSIZE = 0x10,        /* displaysize bitmask */
344     HIFB_LAYERMASK_SCREENSIZE = 0x20,      /* screensize bitmask */
345     HIFB_LAYERMASK_BMUL = 0x40,            /* pre-mult bitmask */
346     HIFB_LAYERMASK_BUTT
347 } HIFB_LAYER_INFO_MASKBIT;
348 
349 /* layer info */
350 typedef struct {
351     HIFB_LAYER_BUF_E BufMode;
352     HIFB_LAYER_ANTIFLICKER_LEVEL_E eAntiflickerLevel;
353     HI_S32 s32XPos;          /* the x pos of origin point in screen */
354     HI_S32 s32YPos;          /* the y pos of origin point in screen */
355     HI_U32 u32CanvasWidth;   /* the width of canvas buffer */
356     HI_U32 u32CanvasHeight;  /* the height of canvas buffer */
357     /* the width of display buf in fb.for 0 buf ,there is no display buf in fb, so it's effectless */
358     HI_U32 u32DisplayWidth;
359     HI_U32 u32DisplayHeight; /* the height of display buf in fb. */
360     HI_U32 u32ScreenWidth;   /* the width of screen */
361     HI_U32 u32ScreenHeight;  /* the height of screen */
362     HI_BOOL bPreMul;         /* The data drawn in buf is premul data or not */
363     HI_U32 u32Mask;          /* param modify mask bit */
364 } HIFB_LAYER_INFO_S;
365 
366 /* To set the layer information */
367 #define FBIOPUT_LAYER_INFO _IOW(IOC_TYPE_HIFB, 120, HIFB_LAYER_INFO_S)
368 /* To get the layer information */
369 #define FBIOGET_LAYER_INFO _IOR(IOC_TYPE_HIFB, 121, HIFB_LAYER_INFO_S)
370 /* To get canvas buf */
371 #define FBIOGET_CANVAS_BUFFER _IOR(IOC_TYPE_HIFB, 123, HIFB_BUFFER_S)
372 /* To refresh the displayed contents in extended mode */
373 #define FBIO_REFRESH _IOW(IOC_TYPE_HIFB, 124, HIFB_BUFFER_S)
374 
375 /* sync refresh */
376 #define FBIO_WAITFOR_FREFRESH_DONE _IO(IOC_TYPE_HIFB, 125)
377 
378 /* To set the mirror mode */
379 #define FBIOPUT_MIRROR_MODE _IOW(IOC_TYPE_HIFB, 126, HIFB_MIRROR_MODE_E)
380 /* To get the mirror mode */
381 #define FBIOGET_MIRROR_MODE _IOW(IOC_TYPE_HIFB, 127, HIFB_MIRROR_MODE_E)
382 
383 /* To set the rotate mode */
384 #define FBIOPUT_ROTATE_MODE _IOW(IOC_TYPE_HIFB, 128, HIFB_ROTATE_MODE_E)
385 /* To get the rotate mode */
386 #define FBIOGET_ROTATE_MODE _IOW(IOC_TYPE_HIFB, 129, HIFB_ROTATE_MODE_E)
387 
388 /* To set the DDR detect zone of an overlay layer */
389 #define FBIOPUT_MDDRDETECT_HIFB _IOW(IOC_TYPE_HIFB, 135, HIFB_DDRZONE_S)
390 /* To get the DDR detect zone of an overlay layer */
391 #define FBIOGET_MDDRDETECT_HIFB _IOW(IOC_TYPE_HIFB, 136, HIFB_DDRZONE_S)
392 
393 #ifdef __HuaweiLite__
394 #define FBIOGET_SCREENINFO_HIFB 0x4600
395 #define FBIOPUT_SCREENINFO_HIFB 0x4601
396 #define FBIOPAN_DISPLAY_HIFB 0x4606
397 
398 struct hifb_info {
399     struct fb_vtable_s vtable;     /* FB interfaces */
400     struct fb_videoinfo_s vinfo;   /* This structure descrides the overall video controller */
401     struct fb_overlayinfo_s oinfo; /* This structure descrides one overlay */
402 #ifdef CONFIG_FB_CMAP
403     struct fb_cmap_s cmap; /* Current camp */
404 #endif
405     int activate;
406     void *par; /* Private data */
407 };
408 
409 HI_S32 hifb_init(hi_void *pArgs);
410 #endif
411 
412 #ifdef __cplusplus
413 #if __cplusplus
414 }
415 #endif
416 #endif /* __cplusplus */
417 
418 #endif /* __HIFB_H__ */
419