1 /* g2d_driver.h
2  *
3  * Copyright (c)	2011 xxxx Electronics
4  *					2011 Yupu Tang
5  *
6  * @ F23 G2D driver
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
16  * GNU General Public License for more details.
17  */
18 
19 #ifndef __G2D_DRIVER_H
20 #define __G2D_DRIVER_H
21 #include <typedef.h>
22 #include <errno.h>
23 
24 
25 
26 /* data format */
27 typedef enum {
28 	G2D_FORMAT_ARGB8888,
29 	G2D_FORMAT_ABGR8888,
30 	G2D_FORMAT_RGBA8888,
31 	G2D_FORMAT_BGRA8888,
32 	G2D_FORMAT_XRGB8888,
33 	G2D_FORMAT_XBGR8888,
34 	G2D_FORMAT_RGBX8888,
35 	G2D_FORMAT_BGRX8888,
36 	G2D_FORMAT_RGB888,
37 	G2D_FORMAT_BGR888,
38 	G2D_FORMAT_RGB565,
39 	G2D_FORMAT_BGR565,
40 	G2D_FORMAT_ARGB4444,
41 	G2D_FORMAT_ABGR4444,
42 	G2D_FORMAT_RGBA4444,
43 	G2D_FORMAT_BGRA4444,
44 	G2D_FORMAT_ARGB1555,
45 	G2D_FORMAT_ABGR1555,
46 	G2D_FORMAT_RGBA5551,
47 	G2D_FORMAT_BGRA5551,
48 	G2D_FORMAT_ARGB2101010,
49 	G2D_FORMAT_ABGR2101010,
50 	G2D_FORMAT_RGBA1010102,
51 	G2D_FORMAT_BGRA1010102,
52 
53 	/* invailed for UI channel */
54 	G2D_FORMAT_IYUV422_V0Y1U0Y0 = 0x20,
55 	G2D_FORMAT_IYUV422_Y1V0Y0U0,
56 	G2D_FORMAT_IYUV422_U0Y1V0Y0,
57 	G2D_FORMAT_IYUV422_Y1U0Y0V0,
58 
59 	G2D_FORMAT_YUV422UVC_V1U1V0U0,
60 	G2D_FORMAT_YUV422UVC_U1V1U0V0,
61 	G2D_FORMAT_YUV422_PLANAR,
62 
63 	G2D_FORMAT_YUV420UVC_V1U1V0U0 = 0x28,
64 	G2D_FORMAT_YUV420UVC_U1V1U0V0,
65 	G2D_FORMAT_YUV420_PLANAR,
66 
67 	G2D_FORMAT_YUV411UVC_V1U1V0U0 = 0x2c,
68 	G2D_FORMAT_YUV411UVC_U1V1U0V0,
69 	G2D_FORMAT_YUV411_PLANAR,
70 
71 	G2D_FORMAT_Y8 = 0x30,
72 
73 	/* YUV 10bit format */
74 	G2D_FORMAT_YVU10_P010 = 0x34,
75 
76 	G2D_FORMAT_YVU10_P210 = 0x36,
77 
78 	G2D_FORMAT_YVU10_444 = 0x38,
79 	G2D_FORMAT_YUV10_444 = 0x39,
80 	G2D_FORMAT_MAX,
81 } g2d_fmt_enh;
82 /* mixer data format */
83 typedef enum {
84 	/* share data format */
85 	G2D_FMT_ARGB_AYUV8888	= (0x0),
86 	G2D_FMT_BGRA_VUYA8888	= (0x1),
87 	G2D_FMT_ABGR_AVUY8888	= (0x2),
88 	G2D_FMT_RGBA_YUVA8888	= (0x3),
89 
90 	G2D_FMT_XRGB8888		= (0x4),
91 	G2D_FMT_BGRX8888		= (0x5),
92 	G2D_FMT_XBGR8888		= (0x6),
93 	G2D_FMT_RGBX8888		= (0x7),
94 
95 	G2D_FMT_ARGB4444		= (0x8),
96 	G2D_FMT_ABGR4444		= (0x9),
97 	G2D_FMT_RGBA4444		= (0xA),
98 	G2D_FMT_BGRA4444		= (0xB),
99 
100 	G2D_FMT_ARGB1555		= (0xC),
101 	G2D_FMT_ABGR1555		= (0xD),
102 	G2D_FMT_RGBA5551		= (0xE),
103 	G2D_FMT_BGRA5551		= (0xF),
104 
105 	G2D_FMT_RGB565			= (0x10),
106 	G2D_FMT_BGR565			= (0x11),
107 
108 	G2D_FMT_IYUV422			= (0x12),
109 
110 	G2D_FMT_8BPP_MONO		= (0x13),
111 	G2D_FMT_4BPP_MONO		= (0x14),
112 	G2D_FMT_2BPP_MONO		= (0x15),
113 	G2D_FMT_1BPP_MONO		= (0x16),
114 
115 	G2D_FMT_PYUV422UVC		= (0x17),
116 	G2D_FMT_PYUV420UVC		= (0x18),
117 	G2D_FMT_PYUV411UVC		= (0x19),
118 
119 	/* just for output format */
120 	G2D_FMT_PYUV422			= (0x1A),
121 	G2D_FMT_PYUV420			= (0x1B),
122 	G2D_FMT_PYUV411			= (0x1C),
123 
124 	/* just for input format */
125 	G2D_FMT_8BPP_PALETTE	= (0x1D),
126 	G2D_FMT_4BPP_PALETTE	= (0x1E),
127 	G2D_FMT_2BPP_PALETTE	= (0x1F),
128 	G2D_FMT_1BPP_PALETTE	= (0x20),
129 
130 	G2D_FMT_PYUV422UVC_MB16	= (0x21),
131 	G2D_FMT_PYUV420UVC_MB16	= (0x22),
132 	G2D_FMT_PYUV411UVC_MB16	= (0x23),
133 	G2D_FMT_PYUV422UVC_MB32	= (0x24),
134 	G2D_FMT_PYUV420UVC_MB32	= (0x25),
135 	G2D_FMT_PYUV411UVC_MB32	= (0x26),
136 	G2D_FMT_PYUV422UVC_MB64	= (0x27),
137 	G2D_FMT_PYUV420UVC_MB64	= (0x28),
138 	G2D_FMT_PYUV411UVC_MB64	= (0x29),
139 	G2D_FMT_PYUV422UVC_MB128 = (0x2A),
140 	G2D_FMT_PYUV420UVC_MB128 = (0x2B),
141 	G2D_FMT_PYUV411UVC_MB128 = (0x2C),
142 
143 } g2d_data_fmt;
144 
145 /* pixel sequence in double word */
146 typedef enum {
147 	G2D_SEQ_NORMAL = 0x0,
148 
149 	/* for interleaved yuv422 */
150 	G2D_SEQ_VYUY   = 0x1,			/* pixel 0在16位 */
151 	G2D_SEQ_YVYU   = 0x2,			/* pixel 1在16位 */
152 
153 	/* for uv_combined yuv420 */
154 	G2D_SEQ_VUVU   = 0x3,
155 
156 	/* for 16bpp rgb */
157 	G2D_SEQ_P10    = 0x4,			/* pixel 0在16位 */
158 	G2D_SEQ_P01    = 0x5,			/* pixel 1在16位 */
159 
160 	/* planar format or 8bpp rgb */
161 	G2D_SEQ_P3210  = 0x6,			/* pixel 0在8位 */
162 	G2D_SEQ_P0123  = 0x7,			/* pixel 3在8位 */
163 
164 	/* for 4bpp rgb */
165 	G2D_SEQ_P76543210  = 0x8,			/* 7,6,5,4,3,2,1,0 */
166 	G2D_SEQ_P67452301  = 0x9,			/* 6,7,4,5,2,3,0,1 */
167 	G2D_SEQ_P10325476  = 0xA,			/* 1,0,3,2,5,4,7,6 */
168 	G2D_SEQ_P01234567  = 0xB,			/* 0,1,2,3,4,5,6,7 */
169 
170 	/* for 2bpp rgb */
171 	/* 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 */
172 	G2D_SEQ_2BPP_BIG_BIG       = 0xC,
173 	/* 12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3 */
174 	G2D_SEQ_2BPP_BIG_LITTER    = 0xD,
175 	/* 3,2,1,0,7,6,5,4,11,10,9,8,15,14,13,12 */
176 	G2D_SEQ_2BPP_LITTER_BIG    = 0xE,
177 	/* 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 */
178 	G2D_SEQ_2BPP_LITTER_LITTER = 0xF,
179 
180 	/* for 1bpp rgb */
181 	/* 31,30,29,28,27,26,25,24,23,22,21,20,
182 	 * 19,18,17,16,15,14,13,12,11,10,9,8,7,
183 	 * 6,5,4,3,2,1,0
184 	 */
185 	G2D_SEQ_1BPP_BIG_BIG       = 0x10,
186 	/* 24,25,26,27,28,29,30,31,16,17,
187 	 * 18,19,20,21,22,23,8,9,10,11,12,
188 	 * 13,14,15,0,1,2,3,4,5,6,7
189 	 */
190 	G2D_SEQ_1BPP_BIG_LITTER    = 0x11,
191 	/* 7,6,5,4,3,2,1,0,15,14,13,12,11,
192 	 * 10,9,8,23,22,21,20,19,18,17,16,
193 	 * 31,30,29,28,27,26,25,24
194 	 */
195 	G2D_SEQ_1BPP_LITTER_BIG    = 0x12,
196 	/* 0,1,2,3,4,5,6,7,8,9,10,11,12,13,
197 	 * 14,15,16,17,18,19,20,21,22,23,24,
198 	 * 25,26,27,28,29,30,31
199 	 */
200 	G2D_SEQ_1BPP_LITTER_LITTER = 0x13,
201 } g2d_pixel_seq;
202 
203 /*  */
204 typedef enum {
205 	G2D_BLT_NONE_H = 0x0,
206 	G2D_BLT_BLACKNESS,
207 	G2D_BLT_NOTMERGEPEN,
208 	G2D_BLT_MASKNOTPEN,
209 	G2D_BLT_NOTCOPYPEN,
210 	G2D_BLT_MASKPENNOT,
211 	G2D_BLT_NOT,
212 	G2D_BLT_XORPEN,
213 	G2D_BLT_NOTMASKPEN,
214 	G2D_BLT_MASKPEN,
215 	G2D_BLT_NOTXORPEN,
216 	G2D_BLT_NOP,
217 	G2D_BLT_MERGENOTPEN,
218 	G2D_BLT_COPYPEN,
219 	G2D_BLT_MERGEPENNOT,
220 	G2D_BLT_MERGEPEN,
221 	G2D_BLT_WHITENESS = 0x000000ff,
222 
223 	G2D_ROT_90  = 0x00000100,
224 	G2D_ROT_180 = 0x00000200,
225 	G2D_ROT_270 = 0x00000300,
226 	G2D_ROT_0   = 0x00000400,
227 	G2D_ROT_H = 0x00001000,
228 	G2D_ROT_V = 0x00002000,
229 
230 /*	G2D_SM_TDLR_1  =    0x10000000, */
231 	G2D_SM_DTLR_1 = 0x10000000,
232 /*	G2D_SM_TDRL_1  =    0x20000000, */
233 /*	G2D_SM_DTRL_1  =    0x30000000, */
234 } g2d_blt_flags_h;
235 
236 /* ROP3 command */
237 typedef enum {
238 	G2D_ROP3_BLACKNESS = 0x00,
239 	G2D_ROP3_NOTSRCERASE = 0x11,
240 	G2D_ROP3_NOTSRCCOPY = 0x33,
241 	G2D_ROP3_SRCERASE = 0x44,
242 	G2D_ROP3_DSTINVERT = 0x55,
243 	G2D_ROP3_PATINVERT = 0x5A,
244 	G2D_ROP3_SRCINVERT = 0x66,
245 	G2D_ROP3_SRCAND = 0x88,
246 	G2D_ROP3_MERGEPAINT = 0xBB,
247 	G2D_ROP3_MERGECOPY = 0xC0,
248 	G2D_ROP3_SRCCOPY = 0xCC,
249 	G2D_ROP3_SRCPAINT = 0xEE,
250 	G2D_ROP3_PATCOPY = 0xF0,
251 	G2D_ROP3_PATPAINT = 0xFB,
252 	G2D_ROP3_WHITENESS = 0xFF,
253 } g2d_rop3_cmd_flag;
254 
255 typedef enum {
256 	G2D_FIL_NONE			= 0x00000000,
257 	G2D_FIL_PIXEL_ALPHA		= 0x00000001,
258 	G2D_FIL_PLANE_ALPHA		= 0x00000002,
259 	G2D_FIL_MULTI_ALPHA		= 0x00000004,
260 } g2d_fillrect_flags;
261 
262 typedef enum {
263 	G2D_BLT_NONE			= 0x00000000,
264 	G2D_BLT_PIXEL_ALPHA		= 0x00000001,
265 	G2D_BLT_PLANE_ALPHA		= 0x00000002,
266 	G2D_BLT_MULTI_ALPHA		= 0x00000004,
267 	G2D_BLT_SRC_COLORKEY	= 0x00000008,
268 	G2D_BLT_DST_COLORKEY	= 0x00000010,
269 	G2D_BLT_FLIP_HORIZONTAL	= 0x00000020,
270 	G2D_BLT_FLIP_VERTICAL	= 0x00000040,
271 	G2D_BLT_ROTATE90		= 0x00000080,
272 	G2D_BLT_ROTATE180		= 0x00000100,
273 	G2D_BLT_ROTATE270		= 0x00000200,
274 	G2D_BLT_MIRROR45		= 0x00000400,
275 	G2D_BLT_MIRROR135		= 0x00000800,
276 	G2D_BLT_SRC_PREMULTIPLY	= 0x00001000,
277 	G2D_BLT_DST_PREMULTIPLY	= 0x00002000,
278 } g2d_blt_flags;
279 
280 /* BLD LAYER ALPHA MODE*/
281 typedef enum {
282 	G2D_PIXEL_ALPHA,
283 	G2D_GLOBAL_ALPHA,
284 	G2D_MIXER_ALPHA,
285 } g2d_alpha_mode_enh;
286 
287 /* flip rectangle struct */
288 typedef struct {
289 	__s32		x;		/* left top point coordinate x */
290 	__s32		y;		/* left top point coordinate y */
291 	__u32		w;		/* rectangle width */
292 	__u32		h;		/* rectangle height */
293 } g2d_rect;
294 
295 /* g2d color gamut */
296 typedef enum {
297 	G2D_BT601,
298 	G2D_BT709,
299 	G2D_BT2020,
300 } g2d_color_gmt;
301 
302 /* image struct */
303 typedef struct {
304 	__u32		addr[3];/* base addr of image frame buffer in byte */
305 	__u32		w;	/* width of image frame buffer in pixel */
306 	__u32		h;	/* height of image frame buffer in pixel */
307 	g2d_data_fmt	format;	/* pixel format of image frame buffer */
308 	g2d_pixel_seq	pixel_seq;/* pixel sequence of image frame buffer */
309 } g2d_image;
310 
311 typedef struct {
312 	/* left point coordinate x of dst rect */
313 	unsigned int x;
314 	/* top point coordinate y of dst rect */
315 	unsigned int y;
316 } g2d_coor;
317 
318 /* image struct */
319 typedef struct {
320 	int		 bbuff;
321 	__u32		 color;
322 	g2d_fmt_enh	 format;
323 	__u32		 laddr[3];
324 	__u32		 haddr[3];
325 	__u32		 width;
326 	__u32		 height;
327 	__u32		 align[3];
328 
329 	g2d_rect	 clip_rect;
330 	g2d_coor	 coor;
331 
332 	__u32		 gamut;
333 	int		 bpremul;
334 	__u8		 alpha;
335 	g2d_alpha_mode_enh mode;
336 	int		 fd;
337 	__u32 use_phy_addr;
338 } g2d_image_enh;
339 
340 /*
341  * 0:Top to down, Left to right
342  * 1:Top to down, Right to left
343  * 2:Down to top, Left to right
344  * 3:Down to top, Right to left
345  */
346 enum g2d_scan_order {
347 	G2D_SM_TDLR = 0x00000000,
348 	G2D_SM_TDRL = 0x00000001,
349 	G2D_SM_DTLR = 0x00000002,
350 	G2D_SM_DTRL = 0x00000003,
351 };
352 
353 typedef struct {
354 	g2d_fillrect_flags	 flag;
355 	g2d_image			 dst_image;
356 	g2d_rect			 dst_rect;
357 
358 	__u32				 color;		/* fill color */
359 	__u32				 alpha;		/* plane alpha value */
360 
361 } g2d_fillrect;
362 
363 typedef struct {
364 	g2d_image_enh dst_image_h;
365 } g2d_fillrect_h;
366 
367 typedef struct {
368 	g2d_blt_flags		flag;
369 	g2d_image		src_image;
370 	g2d_rect		src_rect;
371 
372 	g2d_image		dst_image;
373 	/* left top point coordinate x of dst rect */
374 	__s32			dst_x;
375 	/* left top point coordinate y of dst rect */
376 	__s32			dst_y;
377 
378 	__u32			color;		/* colorkey color */
379 	__u32			alpha;		/* plane alpha value */
380 
381 } g2d_blt;
382 
383 typedef struct {
384 	g2d_blt_flags_h flag_h;
385 	g2d_image_enh src_image_h;
386 	g2d_image_enh dst_image_h;
387 } g2d_blt_h;
388 
389 typedef struct {
390 	g2d_blt_h blt;
391 	__u32	lbc_cmp_ratio;
392 	__u8	enc_is_lossy;
393 	__u8	dec_is_lossy;
394 } g2d_lbc_rot;
395 typedef struct {
396 	g2d_blt_flags			 flag;
397 	g2d_image			 src_image;
398 	g2d_rect			 src_rect;
399 
400 	g2d_image			 dst_image;
401 	g2d_rect			 dst_rect;
402 
403 	__u32				 color;		/* colorkey color */
404 	__u32				 alpha;		/* plane alpha value */
405 
406 
407 } g2d_stretchblt;
408 
409 typedef struct {
410 	g2d_rop3_cmd_flag back_flag;
411 	g2d_rop3_cmd_flag fore_flag;
412 
413 	g2d_image_enh dst_image_h;
414 	g2d_image_enh src_image_h;
415 	g2d_image_enh ptn_image_h;
416 	g2d_image_enh mask_image_h;
417 
418 } g2d_maskblt;
419 
420 /* Porter Duff BLD command*/
421 typedef enum {
422 	G2D_BLD_CLEAR = 0x00000001,
423 	G2D_BLD_COPY = 0x00000002,
424 	G2D_BLD_DST = 0x00000003,
425 	G2D_BLD_SRCOVER = 0x00000004,
426 	G2D_BLD_DSTOVER = 0x00000005,
427 	G2D_BLD_SRCIN = 0x00000006,
428 	G2D_BLD_DSTIN = 0x00000007,
429 	G2D_BLD_SRCOUT = 0x00000008,
430 	G2D_BLD_DSTOUT = 0x00000009,
431 	G2D_BLD_SRCATOP = 0x0000000a,
432 	G2D_BLD_DSTATOP = 0x0000000b,
433 	G2D_BLD_XOR = 0x0000000c,
434 	G2D_CK_SRC = 0x00010000,
435 	G2D_CK_DST = 0x00020000,
436 } g2d_bld_cmd_flag;
437 
438 typedef struct {
439 	__u32		*pbuffer;
440 	__u32		 size;
441 
442 } g2d_palette;
443 
444 
445 
446 typedef struct {
447 	long	start;
448 	long	end;
449 } g2d_cache_range;
450 
451 /* CK PARA struct */
452 typedef struct {
453 	int match_rule;
454 	__u32 max_color;
455 	__u32 min_color;
456 } g2d_ck;
457 
458 typedef struct {
459 	g2d_bld_cmd_flag bld_cmd;
460 	g2d_image_enh dst_image;
461 	g2d_image_enh src_image[4];/*now only ch0 and ch3*/
462 	g2d_ck ck_para;
463 } g2d_bld;			/* blending enhance */
464 
465 typedef enum {
466 	OP_FILLRECT = 0x1,
467 	OP_BITBLT = 0x2,
468 	OP_BLEND = 0x4,
469 	OP_MASK = 0x8,
470 	OP_SPLIT_MEM = 0x10,
471 } g2d_operation_flag;
472 
473 /**
474  * mixer_para
475  */
476 struct mixer_para {
477 	g2d_operation_flag op_flag;
478 	g2d_blt_flags_h flag_h;
479 	g2d_rop3_cmd_flag back_flag;
480 	g2d_rop3_cmd_flag fore_flag;
481 	g2d_bld_cmd_flag bld_cmd;
482 	g2d_image_enh src_image_h;
483 	g2d_image_enh dst_image_h;
484 	g2d_image_enh ptn_image_h;
485 	g2d_image_enh mask_image_h;
486 	g2d_ck ck_para;
487 };
488 /*
489 #define SUNXI_G2D_IOC_MAGIC 'G'
490 #define SUNXI_G2D_IO(nr)          _IO(SUNXI_G2D_IOC_MAGIC, nr)
491 #define SUNXI_G2D_IOR(nr, size)   _IOR(SUNXI_G2D_IOC_MAGIC, nr, size)
492 #define SUNXI_G2D_IOW(nr, size)   _IOW(SUNXI_G2D_IOC_MAGIC, nr, size)
493 #define SUNXI_G2D_IOWR(nr, size)  _IOWR(SUNXI_G2D_IOC_MAGIC, nr, size)
494 */
495 typedef enum {
496 	G2D_CMD_BITBLT			=	0x50,
497 	G2D_CMD_FILLRECT		=	0x51,
498 	G2D_CMD_STRETCHBLT		=	0x52,
499 	G2D_CMD_PALETTE_TBL		=	0x53,
500 	G2D_CMD_QUEUE			=	0x54,
501 	G2D_CMD_BITBLT_H		=	0x55,
502 	G2D_CMD_FILLRECT_H		=	0x56,
503 	G2D_CMD_BLD_H			=	0x57,
504 	G2D_CMD_MASK_H			=	0x58,
505 
506 	G2D_CMD_MEM_REQUEST		=	0x59,
507 	G2D_CMD_MEM_RELEASE		=	0x5A,
508 	G2D_CMD_MEM_GETADR		=	0x5B,
509 	G2D_CMD_MEM_SELIDX		=	0x5C,
510 	G2D_CMD_MEM_FLUSH_CACHE		=	0x5D,
511 	G2D_CMD_INVERTED_ORDER		=	0x5E,
512 	G2D_CMD_MIXER_TASK		=	0x5F,
513 	/*G2D_CMD_CREATE_TASK = SUNXI_G2D_IOW(0x1, struct mixer_para),
514 	G2D_CMD_TASK_APPLY = SUNXI_G2D_IOW(0x2, struct mixer_para),
515 	G2D_CMD_TASK_DESTROY = SUNXI_G2D_IOW(0x3, unsigned int),
516 	G2D_CMD_TASK_GET_PARA = SUNXI_G2D_IOR(0x4, struct mixer_para),  */
517 	G2D_CMD_CREATE_TASK		=	0x60,
518 	G2D_CMD_TASK_APPLY		=	0x61,
519 	G2D_CMD_TASK_DESTROY		=	0x62,
520 	G2D_CMD_TASK_GET_PARA		=	0x63,
521 	G2D_CMD_LBC_ROT			=	0x64,
522 
523 } g2d_cmd;
524 
525 #endif	/* __G2D_DRIVER_H */
526 
527