hc
2023-08-30 862c27fc9920c83318c784bfdadf43a65df1ec8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _RGA_DRIVER_H_
#define _RGA_DRIVER_H_
 
#include <linux/mutex.h>
#include <linux/scatterlist.h>
#include <linux/dma-buf.h>
 
 
#define RGA_BLIT_SYNC    0x5017
#define RGA_BLIT_ASYNC  0x5018
#define RGA_FLUSH       0x5019
#define RGA_GET_RESULT  0x501a
#define RGA_GET_VERSION 0x501b
#define RGA_CACHE_FLUSH 0x501c
 
#define RGA2_BLIT_SYNC     0x6017
#define RGA2_BLIT_ASYNC  0x6018
#define RGA2_FLUSH       0x6019
#define RGA2_GET_RESULT  0x601a
#define RGA2_GET_VERSION 0x601b
 
 
#define RGA2_REG_CTRL_LEN    0x8    /* 8  */
#define RGA2_REG_CMD_LEN     0x20   /* 32 */
#define RGA2_CMD_BUF_SIZE    0x700  /* 16*28*4 */
 
#define RGA2_OUT_OF_RESOURCES    -10
#define RGA2_MALLOC_ERROR        -11
 
#define SCALE_DOWN_LARGE 1
 
#define rgaIS_ERROR(status)            (status < 0)
#define rgaNO_ERROR(status)            (status >= 0)
#define rgaIS_SUCCESS(status)        (status == 0)
 
#define RGA_BUF_GEM_TYPE_MASK      0xC0
#define RGA_BUF_GEM_TYPE_DMA       0x80
#define RGA2_MAJOR_VERSION_MASK     (0xFF000000)
#define RGA2_MINOR_VERSION_MASK     (0x00F00000)
#define RGA2_SVN_VERSION_MASK       (0x000FFFFF)
 
/* RGA2 process mode enum */
enum
{
    bitblt_mode               = 0x0,
    color_palette_mode        = 0x1,
    color_fill_mode           = 0x2,
    update_palette_table_mode = 0x3,
    update_patten_buff_mode   = 0x4,
};  /*render mode*/
 
enum
{
    A_B_B =0x0,
    A_B_C =0x1,
};  //bitblt_mode select
 
enum
{
    rop_enable_mask          = 0x2,
    dither_enable_mask       = 0x8,
    fading_enable_mask       = 0x10,
    PD_enbale_mask           = 0x20,
};
 
 
 
/*
//          Alpha    Red     Green   Blue
{  4, 32, {{32,24,   8, 0,  16, 8,  24,16 }}, GGL_RGBA },   // RK_FORMAT_RGBA_8888
{  4, 24, {{ 0, 0,   8, 0,  16, 8,  24,16 }}, GGL_RGB  },   // RK_FORMAT_RGBX_8888
{  3, 24, {{ 0, 0,   8, 0,  16, 8,  24,16 }}, GGL_RGB  },   // RK_FORMAT_RGB_888
{  4, 32, {{32,24,  24,16,  16, 8,   8, 0 }}, GGL_BGRA },   // RK_FORMAT_BGRA_8888
{  2, 16, {{ 0, 0,  16,11,  11, 5,   5, 0 }}, GGL_RGB  },   // RK_FORMAT_RGB_565
{  2, 16, {{ 1, 0,  16,11,  11, 6,   6, 1 }}, GGL_RGBA },   // RK_FORMAT_RGBA_5551
{  2, 16, {{ 4, 0,  16,12,  12, 8,   8, 4 }}, GGL_RGBA },   // RK_FORMAT_RGBA_4444
{  2, 16, {{ 0, 0,   5, 0   11, 5,   16,11}}, GGL_BGR  },   // RK_FORMAT_BGR_565
{  2, 16, {{ 1, 0,   6, 1,  11, 6,   16,11}}, GGL_BGRA },   // RK_FORMAT_BGRA_5551
{  2, 16, {{ 4, 0,   8, 4,  12, 8,   16,12}}, GGL_BGRA },   // RK_FORMAT_BGRA_4444
 
*/
enum
{
   RGA2_FORMAT_RGBA_8888    = 0x0,
    RGA2_FORMAT_RGBX_8888    = 0x1,
    RGA2_FORMAT_RGB_888      = 0x2,
    RGA2_FORMAT_BGRA_8888    = 0x3,
    RGA2_FORMAT_BGRX_8888    = 0x4,
    RGA2_FORMAT_BGR_888      = 0x5,
    RGA2_FORMAT_RGB_565      = 0x6,
    RGA2_FORMAT_RGBA_5551    = 0x7,
    RGA2_FORMAT_RGBA_4444    = 0x8,
    RGA2_FORMAT_BGR_565      = 0x9,
    RGA2_FORMAT_BGRA_5551    = 0xa,
    RGA2_FORMAT_BGRA_4444    = 0xb,
 
    RGA2_FORMAT_Y4           = 0xe,
    RGA2_FORMAT_YCbCr_400    = 0xf,
 
    RGA2_FORMAT_YCbCr_422_SP = 0x10,
    RGA2_FORMAT_YCbCr_422_P  = 0x11,
    RGA2_FORMAT_YCbCr_420_SP = 0x12,
    RGA2_FORMAT_YCbCr_420_P  = 0x13,
    RGA2_FORMAT_YCrCb_422_SP = 0x14,
    RGA2_FORMAT_YCrCb_422_P  = 0x15,
    RGA2_FORMAT_YCrCb_420_SP = 0x16,
    RGA2_FORMAT_YCrCb_420_P  = 0x17,
 
   RGA2_FORMAT_YVYU_422 = 0x18,
   RGA2_FORMAT_YVYU_420 = 0x19,
   RGA2_FORMAT_VYUY_422 = 0x1a,
   RGA2_FORMAT_VYUY_420 = 0x1b,
   RGA2_FORMAT_YUYV_422 = 0x1c,
   RGA2_FORMAT_YUYV_420 = 0x1d,
   RGA2_FORMAT_UYVY_422 = 0x1e,
   RGA2_FORMAT_UYVY_420 = 0x1f,
 
    RGA2_FORMAT_YCbCr_420_SP_10B = 0x20,
    RGA2_FORMAT_YCrCb_420_SP_10B = 0x21,
    RGA2_FORMAT_YCbCr_422_SP_10B = 0x22,
    RGA2_FORMAT_YCrCb_422_SP_10B = 0x23,
 
   RGA2_FORMAT_BPP_1            = 0x24,
   RGA2_FORMAT_BPP_2            = 0x25,
   RGA2_FORMAT_BPP_4            = 0x26,
   RGA2_FORMAT_BPP_8            = 0x27,
 
   RGA2_FORMAT_ARGB_8888    = 0x28,
   RGA2_FORMAT_XRGB_8888    = 0x29,
   RGA2_FORMAT_ARGB_5551    = 0x2a,
   RGA2_FORMAT_ARGB_4444    = 0x2b,
   RGA2_FORMAT_ABGR_8888    = 0x2c,
   RGA2_FORMAT_XBGR_8888    = 0x2d,
   RGA2_FORMAT_ABGR_5551    = 0x2e,
   RGA2_FORMAT_ABGR_4444    = 0x2f,
};
 
typedef struct mdp_img
{
    u16 width;
    u16 height;
    u32 format;
    u32 mem_addr;
}
mdp_img;
 
typedef struct mdp_img_act
{
    u16 width;     // width
    u16 height;    // height
    s16 x_off;     // x offset for the vir
    s16 y_off;     // y offset for the vir
    s16 uv_x_off;
    s16 uv_y_off;
}
mdp_img_act;
 
typedef struct mdp_img_vir
{
    u16 width;
    u16 height;
    u32 format;
    u32 mem_addr;
    u32 uv_addr;
    u32 v_addr;
}
mdp_img_vir;
 
 
typedef struct MMU_INFO
{
    unsigned long src0_base_addr;
    unsigned long src1_base_addr;
    unsigned long dst_base_addr;
    unsigned long els_base_addr;
 
    u8 src0_mmu_flag;     /* [0] src0 mmu enable [1] src0_flush [2] src0_prefetch_en [3] src0_prefetch dir */
    u8 src1_mmu_flag;     /* [0] src1 mmu enable [1] src1_flush [2] src1_prefetch_en [3] src1_prefetch dir */
    u8 dst_mmu_flag;      /* [0] dst  mmu enable [1] dst_flush  [2] dst_prefetch_en  [3] dst_prefetch dir  */
    u8 els_mmu_flag;      /* [0] els  mmu enable [1] els_flush  [2] els_prefetch_en  [3] els_prefetch dir  */
} MMU_INFO;
 
 
enum
{
   MMU_DIS = 0x0,
   MMU_EN  = 0x1
};
enum
{
   MMU_FLUSH_DIS = 0x0,
   MMU_FLUSH_EN  = 0x2
};
enum
{
   MMU_PRE_DIS = 0x0,
   MMU_PRE_EN  = 0x4
};
enum
{
   MMU_PRE_DIR_FORW  = 0x0,
   MMU_PRE_DIR_BACK  = 0x8
};
typedef struct COLOR_FILL
{
    s16 gr_x_a;
    s16 gr_y_a;
    s16 gr_x_b;
    s16 gr_y_b;
    s16 gr_x_g;
    s16 gr_y_g;
    s16 gr_x_r;
    s16 gr_y_r;
}
COLOR_FILL;
 
enum
{
   ALPHA_ORIGINAL = 0x0,
   ALPHA_NO_128   = 0x1
};
 
enum
{
   R2_BLACK       = 0x00,
   R2_COPYPEN     = 0xf0,
   R2_MASKNOTPEN  = 0x0a,
   R2_MASKPEN     = 0xa0,
   R2_MASKPENNOT  = 0x50,
   R2_MERGENOTPEN = 0xaf,
   R2_MERGEPEN    = 0xfa,
   R2_MERGEPENNOT = 0xf5,
   R2_NOP         = 0xaa,
   R2_NOT         = 0x55,
   R2_NOTCOPYPEN  = 0x0f,
   R2_NOTMASKPEN  = 0x5f,
   R2_NOTMERGEPEN = 0x05,
   R2_NOTXORPEN   = 0xa5,
   R2_WHITE       = 0xff,
   R2_XORPEN      = 0x5a
};
 
 
/***************************************/
/* porting from rga.h for msg convert  */
/***************************************/
 
typedef struct FADING
{
    uint8_t b;
    uint8_t g;
    uint8_t r;
    uint8_t res;
}
FADING;
 
typedef struct MMU
{
    unsigned char mmu_en;
    unsigned long base_addr;
    uint32_t mmu_flag;     /* [0] mmu enable [1] src_flush [2] dst_flush [3] CMD_flush [4~5] page size*/
} MMU;
 
typedef struct MMU_32
{
    unsigned char mmu_en;
    uint32_t base_addr;
    uint32_t mmu_flag;     /* [0] mmu enable [1] src_flush [2] dst_flush [3] CMD_flush [4~5] page size*/
} MMU_32;
 
typedef struct RECT
{
    unsigned short xmin;
    unsigned short xmax; // width - 1
    unsigned short ymin;
    unsigned short ymax; // height - 1
} RECT;
 
typedef struct POINT
{
    unsigned short x;
    unsigned short y;
}
POINT;
 
typedef struct line_draw_t
{
    POINT start_point;              /* LineDraw_start_point                */
    POINT end_point;                /* LineDraw_end_point                  */
    uint32_t   color;               /* LineDraw_color                      */
    uint32_t   flag;                /* (enum) LineDrawing mode sel         */
    uint32_t   line_width;          /* range 1~16 */
}
line_draw_t;
 
/* color space convert coefficient. */
typedef struct csc_coe_t {
    int16_t r_v;
    int16_t g_y;
    int16_t b_u;
    int32_t off;
} csc_coe_t;
 
typedef struct full_csc_t {
    unsigned char flag;
    csc_coe_t coe_y;
    csc_coe_t coe_u;
    csc_coe_t coe_v;
} full_csc_t;
 
typedef struct rga_img_info_t
{
    unsigned long yrgb_addr;      /* yrgb    mem addr         */
    unsigned long uv_addr;        /* cb/cr   mem addr         */
    unsigned long v_addr;         /* cr      mem addr         */
    unsigned int format;         //definition by RK_FORMAT
 
    unsigned short act_w;
    unsigned short act_h;
    unsigned short x_offset;
    unsigned short y_offset;
 
    unsigned short vir_w;
    unsigned short vir_h;
 
    unsigned short endian_mode; //for BPP
    unsigned short alpha_swap;    /* not use */
}
rga_img_info_t;
 
typedef struct rga_img_info_32_t
{
    uint32_t yrgb_addr;      /* yrgb    mem addr         */
    uint32_t uv_addr;        /* cb/cr   mem addr         */
    uint32_t v_addr;         /* cr      mem addr         */
    unsigned int format;         //definition by RK_FORMAT
    unsigned short act_w;
    unsigned short act_h;
    unsigned short x_offset;
    unsigned short y_offset;
    unsigned short vir_w;
    unsigned short vir_h;
    unsigned short endian_mode; //for BPP
    unsigned short alpha_swap;
}
rga_img_info_32_t;
 
struct rga_dma_buffer_t {
   /* DMABUF information */
   struct dma_buf *dma_buf;
   struct dma_buf_attachment *attach;
   struct sg_table *sgt;
 
   dma_addr_t iova;
   unsigned long size;
   void *vaddr;
   enum dma_data_direction dir;
};
 
struct rga_req {
    uint8_t render_mode;            /* (enum) process mode sel */
 
    rga_img_info_t src;             /* src image info */
    rga_img_info_t dst;             /* dst image info */
    rga_img_info_t pat;             /* patten image info */
 
    unsigned long rop_mask_addr;         /* rop4 mask addr */
    unsigned long LUT_addr;              /* LUT addr */
 
    RECT clip;                      /* dst clip window default value is dst_vir */
                                    /* value from [0, w-1] / [0, h-1]*/
 
    int32_t sina;                   /* dst angle  default value 0  16.16 scan from table */
    int32_t cosa;                   /* dst angle  default value 0  16.16 scan from table */
 
    uint16_t alpha_rop_flag;        /* alpha rop process flag           */
                                    /* ([0] = 1 alpha_rop_enable)       */
                                    /* ([1] = 1 rop enable)             */
                                    /* ([2] = 1 fading_enable)          */
                                    /* ([3] = 1 PD_enable)              */
                                    /* ([4] = 1 alpha cal_mode_sel)     */
                                    /* ([5] = 1 dither_enable)          */
                                    /* ([6] = 1 gradient fill mode sel) */
                                    /* ([7] = 1 AA_enable)              */
 
    uint8_t  scale_mode;            /* 0 nearst / 1 bilnear / 2 bicubic */
 
    uint32_t color_key_max;         /* color key max */
    uint32_t color_key_min;         /* color key min */
 
    uint32_t fg_color;              /* foreground color */
    uint32_t bg_color;              /* background color */
 
    COLOR_FILL gr_color;            /* color fill use gradient */
 
    line_draw_t line_draw_info;
 
    FADING fading;
 
    uint8_t PD_mode;                /* porter duff alpha mode sel */
 
    uint8_t alpha_global_value;     /* global alpha value */
 
    uint16_t rop_code;              /* rop2/3/4 code  scan from rop code table*/
 
    uint8_t bsfilter_flag;          /* [2] 0 blur 1 sharp / [1:0] filter_type*/
 
    uint8_t palette_mode;           /* (enum) color palatte  0/1bpp, 1/2bpp 2/4bpp 3/8bpp*/
 
    uint8_t yuv2rgb_mode;           /* (enum) BT.601 MPEG / BT.601 JPEG / BT.709  */
 
    uint8_t endian_mode;            /* 0/big endian 1/little endian*/
 
    uint8_t rotate_mode;            /* (enum) rotate mode  */
                                    /* 0x0,     no rotate  */
                                    /* 0x1,     rotate     */
                                    /* 0x2,     x_mirror   */
                                    /* 0x3,     y_mirror   */
 
    uint8_t color_fill_mode;        /* 0 solid color / 1 patten color */
 
    MMU mmu_info;                   /* mmu information */
 
    uint8_t  alpha_rop_mode;        /* ([0~1] alpha mode)            */
                                    /* ([2~3] rop   mode)            */
                                    /* ([4]   zero  mode en)         */
                                    /* ([5]   dst   alpha mode)      */
                                    /* ([6]   alpha output mode sel) 0 src / 1 dst*/
 
    uint8_t  src_trans_mode;
 
    uint8_t dither_mode;
 
    full_csc_t full_csc;            /* full color space convert */
};
struct rga_req_32
{
    uint8_t render_mode;            /* (enum) process mode sel */
    rga_img_info_32_t src;             /* src image info */
    rga_img_info_32_t dst;             /* dst image info */
    rga_img_info_32_t pat;             /* patten image info */
    uint32_t rop_mask_addr;         /* rop4 mask addr */
    uint32_t LUT_addr;              /* LUT addr */
    RECT clip;                      /* dst clip window default value is dst_vir */
                                    /* value from [0, w-1] / [0, h-1]*/
    int32_t sina;                   /* dst angle  default value 0  16.16 scan from table */
    int32_t cosa;                   /* dst angle  default value 0  16.16 scan from table */
    uint16_t alpha_rop_flag;        /* alpha rop process flag           */
                                    /* ([0] = 1 alpha_rop_enable)       */
                                    /* ([1] = 1 rop enable)             */
                                    /* ([2] = 1 fading_enable)          */
                                    /* ([3] = 1 PD_enable)              */
                                    /* ([4] = 1 alpha cal_mode_sel)     */
                                    /* ([5] = 1 dither_enable)          */
                                    /* ([6] = 1 gradient fill mode sel) */
                                    /* ([7] = 1 AA_enable)              */
    uint8_t  scale_mode;            /* 0 nearst / 1 bilnear / 2 bicubic */
    uint32_t color_key_max;         /* color key max */
    uint32_t color_key_min;         /* color key min */
    uint32_t fg_color;              /* foreground color */
    uint32_t bg_color;              /* background color */
    COLOR_FILL gr_color;            /* color fill use gradient */
    line_draw_t line_draw_info;
    FADING fading;
    uint8_t PD_mode;                /* porter duff alpha mode sel */
    uint8_t alpha_global_value;     /* global alpha value */
    uint16_t rop_code;              /* rop2/3/4 code  scan from rop code table*/
    uint8_t bsfilter_flag;          /* [2] 0 blur 1 sharp / [1:0] filter_type*/
    uint8_t palette_mode;           /* (enum) color palatte  0/1bpp, 1/2bpp 2/4bpp 3/8bpp*/
    uint8_t yuv2rgb_mode;           /* (enum) BT.601 MPEG / BT.601 JPEG / BT.709  */
    uint8_t endian_mode;            /* 0/big endian 1/little endian*/
    uint8_t rotate_mode;            /* (enum) rotate mode  */
                                    /* 0x0,     no rotate  */
                                    /* 0x1,     rotate     */
                                    /* 0x2,     x_mirror   */
                                    /* 0x3,     y_mirror   */
    uint8_t color_fill_mode;        /* 0 solid color / 1 patten color */
    MMU_32 mmu_info;                   /* mmu information */
    uint8_t  alpha_rop_mode;        /* ([0~1] alpha mode)            */
                                    /* ([2~3] rop   mode)            */
                                    /* ([4]   zero  mode en)         */
                                    /* ([5]   dst   alpha mode)      */
                                    /* ([6]   alpha output mode sel) 0 src / 1 dst*/
    uint8_t  src_trans_mode;
 
    uint8_t dither_mode;
 
    full_csc_t full_csc;            /* full color space convert */
};
 
 
 
struct rga2_req
{
    u8 render_mode;          /* (enum) process mode sel */
 
    rga_img_info_t src;    // src  active window
    rga_img_info_t src1;   // src1 active window
    rga_img_info_t dst;    // dst  active window
    rga_img_info_t pat;    // patten active window
 
    unsigned long rop_mask_addr;       // rop4 mask addr
    unsigned long LUT_addr;            // LUT addr
 
    u32 rop_mask_stride;
 
    u8 bitblt_mode;          /* 0: SRC + DST  => DST     */
                             /* 1: SRC + SRC1 => DST     */
 
    u8 rotate_mode;          /* [1:0]                           */
                             /* 0   degree 0x0                  */
                             /* 90  degree 0x1                  */
                             /* 180 degree 0x2                  */
                             /* 270 degree 0x3                  */
                             /* [5:4]                           */
                             /* none                0x0         */
                             /* x_mirror            0x1         */
                             /* y_mirror            0x2         */
                             /* x_mirror + y_mirror 0x3         */
 
    u16 alpha_rop_flag;         /* alpha rop process flag           */
                                /* ([0] = 1 alpha_rop_enable)       */
                                /* ([1] = 1 rop enable)             */
                                /* ([2] = 1 fading_enable)          */
                                /* ([3] = 1 alpha cal_mode_sel)     */
                                /* ([4] = 1 src_dither_up_enable)   */
                                /* ([5] = 1 dst_dither_up_enable)   */
                                /* ([6] = 1 dither_down_enable)     */
                                /* ([7] = 1 gradient fill mode sel) */
 
 
    u16 alpha_mode_0;           /* [0]     SrcAlphaMode0          */
                                /* [2:1]   SrcGlobalAlphaMode0    */
                                /* [3]     SrcAlphaSelectMode0    */
                                /* [6:4]   SrcFactorMode0         */
                                /* [7]     SrcColorMode           */
 
                                /* [8]     DstAlphaMode0          */
                                /* [10:9]  DstGlobalAlphaMode0    */
                                /* [11]    DstAlphaSelectMode0    */
                                /* [14:12] DstFactorMode0         */
                                /* [15]    DstColorMode0          */
 
    u16 alpha_mode_1;           /* [0]     SrcAlphaMode1          */
                                /* [2:1]   SrcGlobalAlphaMode1    */
                                /* [3]     SrcAlphaSelectMode1    */
                                /* [6:4]   SrcFactorMode1         */
 
                                /* [8]     DstAlphaMode1          */
                                /* [10:9]  DstGlobalAlphaMode1    */
                                /* [11]    DstAlphaSelectMode1    */
                                /* [14:12] DstFactorMode1         */
 
    u8  scale_bicu_mode;    /* 0   1   2  3 */
 
    u32 color_key_max;      /* color key max */
    u32 color_key_min;      /* color key min */
 
    u32 fg_color;           /* foreground color */
    u32 bg_color;           /* background color */
 
    u8 color_fill_mode;
    COLOR_FILL gr_color;    /* color fill use gradient */
 
    u8 fading_alpha_value;  /* Fading value */
    u8 fading_r_value;
    u8 fading_g_value;
    u8 fading_b_value;
 
    u8 src_a_global_val;    /* src global alpha value        */
    u8 dst_a_global_val;    /* dst global alpha value        */
 
    u8  rop_mode;        /* rop mode select 0 : rop2 1 : rop3 2 : rop4 */
    u16 rop_code;           /* rop2/3/4 code */
 
    u8 palette_mode;        /* (enum) color palatte  0/1bpp, 1/2bpp 2/4bpp 3/8bpp*/
 
    u8 yuv2rgb_mode;        /* (enum) BT.601 MPEG / BT.601 JPEG / BT.709  */
                            /* [1:0]   src0 csc mode        */
                            /* [3:2]   dst csc mode         */
                            /* [4]     dst csc clip enable  */
                            /* [6:5]   src1 csc mdoe        */
                            /* [7]     src1 csc clip enable */
    full_csc_t full_csc;    /* full color space convert */
 
    u8 endian_mode;         /* 0/little endian 1/big endian */
 
    u8 CMD_fin_int_enable;
 
    MMU_INFO mmu_info;               /* mmu infomation */
 
    u8 alpha_zero_key;
    u8 src_trans_mode;
 
    u8 alpha_swp;           /* not use */
    u8 dither_mode;
 
    u8 rgb2yuv_mode;
 
   u8 buf_type;
};
 
struct rga2_mmu_buf_t {
    int32_t front;
    int32_t back;
    int32_t size;
    int32_t curr;
    unsigned int *buf;
    unsigned int *buf_virtual;
 
    struct page **pages;
 
    u8 buf_order;
    u8 pages_order;
};
 
enum
{
    BB_ROTATE_OFF   = 0x0,     /* no rotate  */
    BB_ROTATE_90    = 0x1,     /* rotate 90  */
    BB_ROTATE_180   = 0x2,     /* rotate 180 */
    BB_ROTATE_270   = 0x3,     /* rotate 270 */
};  /*rotate mode*/
 
enum
{
    BB_MIRROR_OFF   = (0x0 << 4),     /* no mirror  */
    BB_MIRROR_X     = (0x1 << 4),     /* x  mirror  */
    BB_MIRROR_Y     = (0x2 << 4),     /* y  mirror  */
    BB_MIRROR_XY    = (0x3 << 4),     /* xy mirror  */
};  /*mirror mode*/
 
enum
{
    BB_COPY_USE_TILE = (0x1 << 6),    /* bitblt mode copy but use Tile mode */
};
 
enum
{
   //BYPASS        = 0x0,
    BT_601_RANGE0   = 0x1,
    BT_601_RANGE1   = 0x2,
    BT_709_RANGE0   = 0x3,
}; /*yuv2rgb_mode*/
 
enum
{
    BPP1        = 0x0,     /* BPP1 */
    BPP2        = 0x1,     /* BPP2 */
    BPP4        = 0x2,     /* BPP4 */
    BPP8        = 0x3      /* BPP8 */
}; /*palette_mode*/
 
enum
{
   SOLID_COLOR   = 0x0, //color fill mode; ROP4: SOLID_rop4_mask_addr COLOR
   PATTERN_COLOR = 0x1  //pattern_fill_mode;ROP4:PATTERN_COLOR
};  /*color fill mode*/
 
enum
{
   COLOR_FILL_CLIP     = 0x0,
   COLOR_FILL_NOT_CLIP = 0x1
};
 
enum
{
    CATROM    = 0x0,
    MITCHELL  = 0x1,
    HERMITE   = 0x2,
    B_SPLINE  = 0x3,
};  /*bicubic coefficient*/
 
enum
{
   ROP2 = 0x0,
   ROP3 = 0x1,
   ROP4 = 0x2
};  /*ROP mode*/
 
enum
{
   BIG_ENDIAN    = 0x0,
   LITTLE_ENDIAN = 0x1
};  /*endian mode*/
 
enum
{
   MMU_TABLE_4KB  = 0x0,
   MMU_TABLE_64KB = 0x1,
};  /*MMU table size*/
 
enum
{
    RGB_2_666 = 0x0,
    RGB_2_565 = 0x1,
    RGB_2_555 = 0x2,
    RGB_2_444 = 0x3,
};  /*dither down mode*/
 
 
 
/**
 * struct for process session which connect to rga
 *
 * @author ZhangShengqin (2012-2-15)
 */
typedef struct rga2_session {
   /* a linked list of data so we can access them for debugging */
   struct list_head    list_session;
   /* a linked list of register data waiting for process */
   struct list_head    waiting;
   /* a linked list of register data in processing */
   struct list_head    running;
   /* all coommand this thread done */
    atomic_t            done;
   wait_queue_head_t   wait;
   pid_t           pid;
   atomic_t        task_running;
    atomic_t        num_done;
} rga2_session;
 
struct rga2_reg {
   rga2_session        *session;
   struct list_head    session_link;
   struct list_head    status_link;
   uint32_t  sys_reg[8];
   uint32_t  csc_reg[12];
   uint32_t  cmd_reg[32];
 
   uint32_t *MMU_src0_base;
   uint32_t *MMU_src1_base;
   uint32_t *MMU_dst_base;
   uint32_t MMU_src0_count;
   uint32_t MMU_src1_count;
   uint32_t MMU_dst_count;
 
   uint32_t MMU_len;
   bool MMU_map;
 
   struct rga_dma_buffer_t dma_buffer_src0;
   struct rga_dma_buffer_t dma_buffer_src1;
   struct rga_dma_buffer_t dma_buffer_dst;
   struct rga_dma_buffer_t dma_buffer_els;
};
 
struct rga2_service_info {
    struct mutex    lock;
    struct timer_list    timer;            /* timer for power off */
    struct list_head    waiting;        /* link to link_reg in struct vpu_reg */
    struct list_head    running;        /* link to link_reg in struct vpu_reg */
    struct list_head    done;            /* link to link_reg in struct vpu_reg */
    struct list_head    session;        /* link to list_session in struct vpu_session */
    atomic_t        total_running;
 
    struct rga2_reg        *reg;
 
    uint32_t            cmd_buff[32*8];/* cmd_buff for rga */
    uint32_t            *pre_scale_buf;
    atomic_t            int_disable;     /* 0 int enable 1 int disable  */
    atomic_t            cmd_num;
    atomic_t            src_format_swt;
    int                 last_prc_src_format;
    atomic_t            rga_working;
    bool                enable;
    uint32_t            dev_mode;
 
    //struct rga_req      req[10];
 
    struct mutex    mutex;    // mutex
};
 
#define RGA2_TEST_CASE 0
 
//General Registers
#define RGA2_SYS_CTRL             0x000
#define RGA2_CMD_CTRL             0x004
#define RGA2_CMD_BASE             0x008
#define RGA2_STATUS               0x00c
#define RGA2_INT                  0x010
#define RGA2_MMU_CTRL0            0x018
#define RGA2_MMU_CMD_BASE         0x01c
 
//Full Csc Coefficient
#define RGA2_CSC_COE_BASE         0x60
 
//Command code start
#define RGA2_MODE_CTRL            0x100
#define RGA_BLIT_COMPLETE_EVENT 1
 
#endif /*_RK29_IPP_DRIVER_H_*/