• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 #include <linux/types.h>
23 #include <linux/ioctl.h>
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 enum color_range {
319 	COLOR_RANGE_0_255 = 0,
320 	COLOR_RANGE_16_235 = 1,
321 };
322 
323 /* image struct */
324 typedef struct {
325 	int		 bbuff;
326 	__u32		 color;
327 	g2d_fmt_enh	 format;
328 	__u32		 laddr[3];
329 	__u32		 haddr[3];
330 	__u32		 width;
331 	__u32		 height;
332 	__u32		 align[3];
333 
334 	g2d_rect	 clip_rect;
335 	g2d_coor	 coor;
336 
337 	g2d_color_gmt	 gamut;
338 	int		 bpremul;
339 	__u8		 alpha;
340 	g2d_alpha_mode_enh mode;
341 	int		 fd;
342 	__u32 use_phy_addr;
343 	enum color_range color_range;
344 } g2d_image_enh;
345 
346 /*
347  * 0:Top to down, Left to right
348  * 1:Top to down, Right to left
349  * 2:Down to top, Left to right
350  * 3:Down to top, Right to left
351  */
352 enum g2d_scan_order {
353 	G2D_SM_TDLR = 0x00000000,
354 	G2D_SM_TDRL = 0x00000001,
355 	G2D_SM_DTLR = 0x00000002,
356 	G2D_SM_DTRL = 0x00000003,
357 };
358 
359 typedef struct {
360 	g2d_fillrect_flags	 flag;
361 	g2d_image			 dst_image;
362 	g2d_rect			 dst_rect;
363 
364 	__u32				 color;		/* fill color */
365 	__u32				 alpha;		/* plane alpha value */
366 
367 } g2d_fillrect;
368 
369 typedef struct {
370 	g2d_image_enh dst_image_h;
371 } g2d_fillrect_h;
372 
373 typedef struct {
374 	g2d_blt_flags		flag;
375 	g2d_image		src_image;
376 	g2d_rect		src_rect;
377 
378 	g2d_image		dst_image;
379 	/* left top point coordinate x of dst rect */
380 	__s32			dst_x;
381 	/* left top point coordinate y of dst rect */
382 	__s32			dst_y;
383 
384 	__u32			color;		/* colorkey color */
385 	__u32			alpha;		/* plane alpha value */
386 
387 } g2d_blt;
388 
389 typedef struct {
390 	g2d_blt_flags_h flag_h;
391 	g2d_image_enh src_image_h;
392 	g2d_image_enh dst_image_h;
393 } g2d_blt_h;
394 
395 typedef struct {
396 	g2d_blt_h blt;
397 	__u32	lbc_cmp_ratio;
398 	bool	enc_is_lossy;
399 	bool	dec_is_lossy;
400 } g2d_lbc_rot;
401 
402 typedef struct {
403 	g2d_blt_flags			 flag;
404 	g2d_image			 src_image;
405 	g2d_rect			 src_rect;
406 
407 	g2d_image			 dst_image;
408 	g2d_rect			 dst_rect;
409 
410 	__u32				 color;		/* colorkey color */
411 	__u32				 alpha;		/* plane alpha value */
412 
413 
414 } g2d_stretchblt;
415 
416 typedef struct {
417 	g2d_rop3_cmd_flag back_flag;
418 	g2d_rop3_cmd_flag fore_flag;
419 
420 	g2d_image_enh dst_image_h;
421 	g2d_image_enh src_image_h;
422 	g2d_image_enh ptn_image_h;
423 	g2d_image_enh mask_image_h;
424 
425 } g2d_maskblt;
426 
427 /* Porter Duff BLD command*/
428 typedef enum {
429 	G2D_BLD_CLEAR = 0x00000001,
430 	G2D_BLD_COPY = 0x00000002,
431 	G2D_BLD_DST = 0x00000003,
432 	G2D_BLD_SRCOVER = 0x00000004,
433 	G2D_BLD_DSTOVER = 0x00000005,
434 	G2D_BLD_SRCIN = 0x00000006,
435 	G2D_BLD_DSTIN = 0x00000007,
436 	G2D_BLD_SRCOUT = 0x00000008,
437 	G2D_BLD_DSTOUT = 0x00000009,
438 	G2D_BLD_SRCATOP = 0x0000000a,
439 	G2D_BLD_DSTATOP = 0x0000000b,
440 	G2D_BLD_XOR = 0x0000000c,
441 	G2D_CK_SRC = 0x00010000,
442 	G2D_CK_DST = 0x00020000,
443 } g2d_bld_cmd_flag;
444 
445 typedef struct {
446 	__u32		*pbuffer;
447 	__u32		 size;
448 
449 } g2d_palette;
450 
451 
452 
453 typedef struct {
454 	long	start;
455 	long	end;
456 } g2d_cache_range;
457 
458 /* CK PARA struct */
459 typedef struct {
460 	bool match_rule;
461 /*	int match_rule; */
462 	__u32 max_color;
463 	__u32 min_color;
464 } g2d_ck;
465 
466 typedef struct {
467 	g2d_bld_cmd_flag bld_cmd;
468 	g2d_image_enh dst_image;
469 	g2d_image_enh src_image[4];/*now only ch0 and ch3*/
470 	g2d_ck ck_para;
471 } g2d_bld;			/* blending enhance */
472 
473 typedef enum {
474 	OP_FILLRECT = 0x1,
475 	OP_BITBLT = 0x2,
476 	OP_BLEND = 0x4,
477 	OP_MASK = 0x8,
478 	OP_SPLIT_MEM = 0x10,
479 } g2d_operation_flag;
480 
481 /**
482  * mixer_para
483  */
484 struct mixer_para {
485 	g2d_operation_flag op_flag;
486 	g2d_blt_flags_h flag_h;
487 	g2d_rop3_cmd_flag back_flag;
488 	g2d_rop3_cmd_flag fore_flag;
489 	g2d_bld_cmd_flag bld_cmd;
490 	g2d_image_enh src_image_h;
491 	g2d_image_enh dst_image_h;
492 	g2d_image_enh ptn_image_h;
493 	g2d_image_enh mask_image_h;
494 	g2d_ck ck_para;
495 };
496 
497 #define SUNXI_G2D_IOC_MAGIC 'G'
498 #define SUNXI_G2D_IO(nr)          _IO(SUNXI_G2D_IOC_MAGIC, nr)
499 #define SUNXI_G2D_IOR(nr, size)   _IOR(SUNXI_G2D_IOC_MAGIC, nr, size)
500 #define SUNXI_G2D_IOW(nr, size)   _IOW(SUNXI_G2D_IOC_MAGIC, nr, size)
501 #define SUNXI_G2D_IOWR(nr, size)  _IOWR(SUNXI_G2D_IOC_MAGIC, nr, size)
502 
503 typedef enum {
504 	G2D_CMD_BITBLT			=	0x50,
505 	G2D_CMD_FILLRECT		=	0x51,
506 	G2D_CMD_STRETCHBLT		=	0x52,
507 	G2D_CMD_PALETTE_TBL		=	0x53,
508 	G2D_CMD_QUEUE			=	0x54,
509 	G2D_CMD_BITBLT_H		=	0x55,
510 	G2D_CMD_FILLRECT_H		=	0x56,
511 	G2D_CMD_BLD_H			=	0x57,
512 	G2D_CMD_MASK_H			=	0x58,
513 
514 	G2D_CMD_MEM_REQUEST		=	0x59,
515 	G2D_CMD_MEM_RELEASE		=	0x5A,
516 	G2D_CMD_MEM_GETADR		=	0x5B,
517 	G2D_CMD_MEM_SELIDX		=	0x5C,
518 	G2D_CMD_MEM_FLUSH_CACHE		=	0x5D,
519 	G2D_CMD_INVERTED_ORDER		=	0x5E,
520 	G2D_CMD_MIXER_TASK		=	0x5F,
521 	G2D_CMD_LBC_ROT			=	0x60,
522 	G2D_CMD_CREATE_TASK = SUNXI_G2D_IOW(0x1, struct mixer_para),
523 	G2D_CMD_TASK_APPLY = SUNXI_G2D_IOW(0x2, struct mixer_para),
524 	G2D_CMD_TASK_DESTROY = SUNXI_G2D_IOW(0x3, unsigned int),
525 	G2D_CMD_TASK_GET_PARA = SUNXI_G2D_IOR(0x4, struct mixer_para),
526 
527 } g2d_cmd;
528 
529 #endif	/* __G2D_DRIVER_H */
530 
531