forked from LibreELEC/linux-amlogic
/
ge2d_wq.c
1145 lines (1032 loc) · 31.9 KB
/
ge2d_wq.c
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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* drivers/amlogic/display/ge2d/ge2d_wq.c
*
* Copyright (C) 2015 Amlogic, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*/
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/kthread.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/of_fdt.h>
#include <linux/reset.h>
#include <linux/clk.h>
/* Amlogic Headers */
#include <linux/amlogic/vout/color.h>
#include <linux/amlogic/canvas/canvas.h>
#include <linux/amlogic/canvas/canvas_mgr.h>
#include <linux/amlogic/ge2d/ge2d.h>
#include <linux/platform_device.h>
/* Local Headers */
#include "ge2dgen.h"
#include "ge2d_log.h"
#include "ge2d_io.h"
#include "ge2d_reg.h"
#include "ge2d_wq.h"
#define OSD1_CANVAS_INDEX 0x40
#define OSD2_CANVAS_INDEX 0x43
#define OSD3_CANVAS_INDEX 0x41
#define OSD4_CANVAS_INDEX 0x42
#define ALLOC_CANVAS_INDEX 0x44
static struct ge2d_manager_s ge2d_manager;
static int ge2d_irq = -ENXIO;
static struct reset_control *ge2d_rstc;
static struct clk *ge2d_clk;
static const int bpp_type_lut[] = {
/* 16bit */
COLOR_INDEX_16_655, /* 0 */
COLOR_INDEX_16_844, /* 1 */
COLOR_INDEX_16_6442, /* 2 */
COLOR_INDEX_16_4444_R, /* 3 */
COLOR_INDEX_16_565, /* 4 */
COLOR_INDEX_16_4444_A, /* 5 */
COLOR_INDEX_16_1555_A, /* 6 */
COLOR_INDEX_16_4642_R, /* 7 */
/* 24bit */
COLOR_INDEX_24_RGB, /* 0 */
COLOR_INDEX_24_5658, /* 1 */
COLOR_INDEX_24_8565, /* 2 */
COLOR_INDEX_24_6666_R, /* 3 */
COLOR_INDEX_24_6666_A, /* 4 */
COLOR_INDEX_24_888_B, /* 5 */
0,
0,
/* 32bit */
COLOR_INDEX_32_RGBA, /* 0 */
COLOR_INDEX_32_ARGB, /* 1 */
COLOR_INDEX_32_ABGR, /* 2 */
COLOR_INDEX_32_BGRA, /* 3 */
0, 0, 0, 0
};
static const int default_ge2d_color_lut[] = {
0,
0,
0,/* BPP_TYPE_02_PAL4 = 2, */
0,
0,/* BPP_TYPE_04_PAL16 = 4, */
0,
0,
0,
0,/* BPP_TYPE_08_PAL256=8, */
GE2D_FORMAT_S16_RGB_655,/* BPP_TYPE_16_655 =9, */
GE2D_FORMAT_S16_RGB_844,/* BPP_TYPE_16_844 =10, */
GE2D_FORMAT_S16_RGBA_6442,/* BPP_TYPE_16_6442 =11 , */
GE2D_FORMAT_S16_RGBA_4444,/* BPP_TYPE_16_4444_R = 12, */
GE2D_FORMAT_S16_RGBA_4642,/* BPP_TYPE_16_4642_R = 13, */
GE2D_FORMAT_S16_ARGB_1555,/* BPP_TYPE_16_1555_A=14, */
GE2D_FORMAT_S16_ARGB_4444,/* BPP_TYPE_16_4444_A = 15, */
GE2D_FORMAT_S16_RGB_565,/* BPP_TYPE_16_565 =16, */
0,
0,
GE2D_FORMAT_S24_ARGB_6666,/* BPP_TYPE_24_6666_A=19, */
GE2D_FORMAT_S24_RGBA_6666,/* BPP_TYPE_24_6666_R=20, */
GE2D_FORMAT_S24_ARGB_8565,/* BPP_TYPE_24_8565 =21, */
GE2D_FORMAT_S24_RGBA_5658,/* BPP_TYPE_24_5658 = 22, */
GE2D_FORMAT_S24_BGR,/* BPP_TYPE_24_888_B = 23, */
GE2D_FORMAT_S24_RGB,/* BPP_TYPE_24_RGB = 24, */
0,
0,
0,
0,
GE2D_FORMAT_S32_BGRA,/* BPP_TYPE_32_BGRA=29, */
GE2D_FORMAT_S32_ABGR,/* BPP_TYPE_32_ABGR = 30, */
GE2D_FORMAT_S32_RGBA,/* BPP_TYPE_32_RGBA=31, */
GE2D_FORMAT_S32_ARGB,/* BPP_TYPE_32_ARGB=32, */
};
static int ge2d_clk_config(bool enable)
{
if (ge2d_clk == NULL)
return -1;
if (enable) {
if (ge2d_rstc != NULL)
reset_control_deassert(ge2d_rstc);
clk_prepare_enable(ge2d_clk);
} else {
clk_disable_unprepare(ge2d_clk);
if (ge2d_rstc != NULL)
reset_control_assert(ge2d_rstc);
}
return 0;
}
static int get_queue_member_count(struct list_head *head)
{
int member_count = 0;
struct ge2d_queue_item_s *pitem;
list_for_each_entry(pitem, head, list) {
member_count++;
if (member_count > MAX_GE2D_CMD) /* error has occured */
break;
}
return member_count;
}
ssize_t work_queue_status_show(struct class *cla, struct class_attribute *attr,
char *buf)
{
struct ge2d_context_s *wq = ge2d_manager.current_wq;
if (wq == 0)
return 0;
return snprintf(buf, 40, "cmd count in queue:%d\n",
get_queue_member_count(&wq->work_queue));
}
ssize_t free_queue_status_show(struct class *cla, struct class_attribute *attr,
char *buf)
{
struct ge2d_context_s *wq = ge2d_manager.current_wq;
if (wq == 0)
return 0;
return snprintf(buf, 40, "free space :%d\n",
get_queue_member_count(&wq->free_queue));
}
static inline int work_queue_no_space(struct ge2d_context_s *queue)
{
return list_empty(&queue->free_queue);
}
static int ge2d_process_work_queue(struct ge2d_context_s *wq)
{
struct ge2d_config_s *cfg;
struct ge2d_queue_item_s *pitem;
unsigned int mask = 0x1;
struct list_head *head = &wq->work_queue, *pos;
int ret = 0;
unsigned int block_mode;
ge2d_manager.ge2d_state = GE2D_STATE_RUNNING;
pos = head->next;
if (pos != head) { /* current work queue not empty. */
if (wq != ge2d_manager.last_wq) { /* maybe */
/* modify the first item . */
pitem = (struct ge2d_queue_item_s *)pos;
if (pitem)
pitem->config.update_flag = UPDATE_ALL;
else {
ge2d_log_err("can't get pitem\n");
ret = -1;
goto exit;
}
} else
/* modify the first item . */
pitem = (struct ge2d_queue_item_s *)pos;
} else {
ret = -1;
goto exit;
}
do {
cfg = &pitem->config;
mask = 0x1;
while (cfg->update_flag && mask <= UPDATE_SCALE_COEF) {
/* we do not change */
switch (cfg->update_flag & mask) {
case UPDATE_SRC_DATA:
ge2d_set_src1_data(&cfg->src1_data);
break;
case UPDATE_SRC_GEN:
ge2d_set_src1_gen(&cfg->src1_gen);
break;
case UPDATE_DST_DATA:
ge2d_set_src2_dst_data(&cfg->src2_dst_data);
break;
case UPDATE_DST_GEN:
ge2d_set_src2_dst_gen(&cfg->src2_dst_gen);
break;
case UPDATE_DP_GEN:
ge2d_set_dp_gen(&cfg->dp_gen);
break;
case UPDATE_SCALE_COEF:
ge2d_set_src1_scale_coef(cfg->v_scale_coef_type,
cfg->h_scale_coef_type);
break;
}
cfg->update_flag &= ~mask;
mask = mask << 1;
}
ge2d_set_cmd(&pitem->cmd);/* set START_FLAG in this func. */
/* remove item */
block_mode = pitem->cmd.wait_done_flag;
/* spin_lock(&wq->lock); */
/* pos=pos->next; */
/* list_move_tail(&pitem->list,&wq->free_queue); */
/* spin_unlock(&wq->lock); */
while (ge2d_is_busy())
interruptible_sleep_on_timeout(
&ge2d_manager.event.cmd_complete, 1);
/* if block mode (cmd) */
if (block_mode) {
pitem->cmd.wait_done_flag = 0;
wake_up_interruptible(&wq->cmd_complete);
}
spin_lock(&wq->lock);
pos = pos->next;
list_move_tail(&pitem->list, &wq->free_queue);
spin_unlock(&wq->lock);
pitem = (struct ge2d_queue_item_s *)pos;
} while (pos != head);
ge2d_manager.last_wq = wq;
exit:
if (ge2d_manager.ge2d_state == GE2D_STATE_REMOVING_WQ)
complete(&ge2d_manager.event.process_complete);
ge2d_manager.ge2d_state = GE2D_STATE_IDLE;
return ret;
}
static irqreturn_t ge2d_wq_handle(int irq_number, void *para)
{
wake_up(&ge2d_manager.event.cmd_complete);
return IRQ_HANDLED;
}
struct ge2d_src1_data_s *ge2d_wq_get_src_data(struct ge2d_context_s *wq)
{
return &wq->config.src1_data;
}
struct ge2d_src1_gen_s *ge2d_wq_get_src_gen(struct ge2d_context_s *wq)
{
return &wq->config.src1_gen;
}
struct ge2d_src2_dst_data_s *ge2d_wq_get_dst_data(struct ge2d_context_s *wq)
{
return &wq->config.src2_dst_data;
}
struct ge2d_src2_dst_gen_s *ge2d_wq_get_dst_gen(struct ge2d_context_s *wq)
{
return &wq->config.src2_dst_gen;
}
struct ge2d_dp_gen_s *ge2d_wq_get_dp_gen(struct ge2d_context_s *wq)
{
return &wq->config.dp_gen;
}
struct ge2d_cmd_s *ge2d_wq_get_cmd(struct ge2d_context_s *wq)
{
return &wq->cmd;
}
void ge2d_wq_set_scale_coef(struct ge2d_context_s *wq,
unsigned v_scale_coef_type,
unsigned h_scale_coef_type)
{
if (wq) {
wq->config.v_scale_coef_type = v_scale_coef_type;
wq->config.h_scale_coef_type = h_scale_coef_type;
wq->config.update_flag |= UPDATE_SCALE_COEF;
}
}
int ge2d_wq_add_work(struct ge2d_context_s *wq)
{
struct ge2d_queue_item_s *pitem;
ge2d_log_dbg("add new work @@%s:%d\n", __func__, __LINE__);
if (work_queue_no_space(wq)) {
ge2d_log_dbg("work queue no space\n");
/* we should wait for queue empty at this point. */
while (work_queue_no_space(wq))
interruptible_sleep_on_timeout(
&ge2d_manager.event.cmd_complete, 3);
ge2d_log_dbg("got free space\n");
}
pitem = list_entry(wq->free_queue.next, struct ge2d_queue_item_s, list);
if (IS_ERR(pitem))
goto error;
memcpy(&pitem->cmd, &wq->cmd, sizeof(struct ge2d_cmd_s));
memset(&wq->cmd, 0, sizeof(struct ge2d_cmd_s));
memcpy(&pitem->config, &wq->config, sizeof(struct ge2d_config_s));
wq->config.update_flag = 0; /* reset config set flag */
spin_lock(&wq->lock);
list_move_tail(&pitem->list, &wq->work_queue);
spin_unlock(&wq->lock);
ge2d_log_dbg("add new work ok\n");
/* only read not need lock */
if (ge2d_manager.event.cmd_in_sem.count == 0)
up(&ge2d_manager.event.cmd_in_sem);/* new cmd come in */
/* add block mode if() */
if (pitem->cmd.wait_done_flag) {
wait_event_interruptible(wq->cmd_complete,
pitem->cmd.wait_done_flag == 0);
/* interruptible_sleep_on(&wq->cmd_complete); */
}
return 0;
error:
return -1;
}
static inline struct ge2d_context_s *get_next_work_queue(
struct ge2d_manager_s *manager)
{
struct ge2d_context_s *pcontext;
spin_lock(&ge2d_manager.event.sem_lock);
list_for_each_entry(pcontext, &manager->process_queue, list) {
/* not lock maybe delay to next time. */
if (!list_empty(&pcontext->work_queue)) {
/* move head . */
list_move(&manager->process_queue, &pcontext->list);
spin_unlock(&ge2d_manager.event.sem_lock);
return pcontext;
}
}
spin_unlock(&ge2d_manager.event.sem_lock);
return NULL;
}
static int ge2d_monitor_thread(void *data)
{
int ret;
struct ge2d_manager_s *manager = (struct ge2d_manager_s *)data;
ge2d_log_info("ge2d workqueue monitor start\n");
/* setup current_wq here. */
while (ge2d_manager.process_queue_state != GE2D_PROCESS_QUEUE_STOP) {
ret = down_interruptible(&manager->event.cmd_in_sem);
ge2d_clk_config(true);
while ((manager->current_wq =
get_next_work_queue(manager)) != NULL)
ge2d_process_work_queue(manager->current_wq);
ge2d_clk_config(false);
}
ge2d_log_info("exit ge2d_monitor_thread\n");
return 0;
}
static int ge2d_start_monitor(void)
{
int ret = 0;
ge2d_log_info("ge2d start monitor\n");
ge2d_manager.process_queue_state = GE2D_PROCESS_QUEUE_START;
ge2d_manager.ge2d_thread = kthread_run(ge2d_monitor_thread,
&ge2d_manager,
"ge2d_monitor");
if (IS_ERR(ge2d_manager.ge2d_thread)) {
ret = PTR_ERR(ge2d_manager.ge2d_thread);
ge2d_log_err("ge2d failed to start kthread (%d)\n", ret);
}
return ret;
}
static int ge2d_stop_monitor(void)
{
ge2d_log_info("stop ge2d monitor thread\n");
if (ge2d_manager.ge2d_thread) {
ge2d_manager.process_queue_state = GE2D_PROCESS_QUEUE_STOP;
up(&ge2d_manager.event.cmd_in_sem);
kthread_stop(ge2d_manager.ge2d_thread);
ge2d_manager.ge2d_thread = NULL;
}
return 0;
}
static inline int bpp(unsigned format)
{
switch (format & GE2D_BPP_MASK) {
case GE2D_BPP_8BIT:
return 8;
case GE2D_BPP_16BIT:
return 16;
case GE2D_BPP_24BIT:
return 24;
case GE2D_BPP_32BIT:
default:
return 32;
}
}
static void build_ge2d_config(struct config_para_s *cfg,
struct src_dst_para_s *src,
struct src_dst_para_s *dst,
int index)
{
index &= 0xff;
if (src) {
src->xres = cfg->src_planes[0].w;
src->yres = cfg->src_planes[0].h;
src->ge2d_color_index = cfg->src_format;
src->bpp = bpp(cfg->src_format);
if (cfg->src_planes[0].addr) {
src->canvas_index = index;
canvas_config(index++,
cfg->src_planes[0].addr,
cfg->src_planes[0].w * src->bpp / 8,
cfg->src_planes[0].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
/* multi-src_planes */
if (cfg->src_planes[1].addr) {
src->canvas_index |= index << 8;
canvas_config(index++,
cfg->src_planes[1].addr,
cfg->src_planes[1].w * src->bpp / 8,
cfg->src_planes[1].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
if (cfg->src_planes[2].addr) {
src->canvas_index |= index << 16;
canvas_config(index++,
cfg->src_planes[2].addr,
cfg->src_planes[2].w * src->bpp / 8,
cfg->src_planes[2].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
if (cfg->src_planes[3].addr) {
src->canvas_index |= index << 24;
canvas_config(index++,
cfg->src_planes[3].addr,
cfg->src_planes[3].w * src->bpp / 8,
cfg->src_planes[3].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
}
if (dst) {
dst->xres = cfg->dst_planes[0].w;
dst->yres = cfg->dst_planes[0].h;
dst->ge2d_color_index = cfg->dst_format;
dst->bpp = bpp(cfg->dst_format);
if (cfg->dst_planes[0].addr) {
dst->canvas_index = index;
canvas_config(index++ & 0xff,
cfg->dst_planes[0].addr,
cfg->dst_planes[0].w,
cfg->dst_planes[0].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
/* multi-src_planes */
if (cfg->dst_planes[1].addr) {
dst->canvas_index |= index << 8;
canvas_config(index++,
cfg->dst_planes[1].addr,
cfg->dst_planes[1].w,
cfg->dst_planes[1].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
if (cfg->dst_planes[2].addr) {
dst->canvas_index |= index << 16;
canvas_config(index++,
cfg->dst_planes[2].addr,
cfg->dst_planes[2].w,
cfg->dst_planes[2].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
if (cfg->dst_planes[3].addr) {
dst->canvas_index |= index << 24;
canvas_config(index++,
cfg->dst_planes[3].addr,
cfg->dst_planes[3].w,
cfg->dst_planes[3].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
}
}
static int setup_display_property(struct src_dst_para_s *src_dst, int index)
{
#define REG_OFFSET (0x20)
struct canvas_s canvas;
unsigned int data32;
unsigned int bpp;
unsigned int block_mode[] = {2, 4, 8, 16, 16, 32, 0, 24};
src_dst->canvas_index = index;
canvas_read(index, &canvas);
index = (index == OSD1_CANVAS_INDEX ? 0 : 1);
ge2d_log_dbg("osd%d ", index);
data32 = ge2d_vcbus_read(VIU_OSD1_BLK0_CFG_W0 + REG_OFFSET * index);
index = (data32 >> 8) & 0xf;
bpp = block_mode[index]; /* OSD_BLK_MODE[8..11] */
ge2d_log_dbg("%d bpp\n", bpp);
if (bpp < 16)
return -1;
src_dst->bpp = bpp;
src_dst->xres = canvas.width / (bpp >> 3);
src_dst->yres = canvas.height;
if (index == 3) /* yuv422 32bit for two pixel. */
src_dst->ge2d_color_index = GE2D_FORMAT_S16_YUV422;
else { /* for block mode=4,5,7 */
/* color mode [2..5] */
index = bpp - 16 + ((data32 >> 2) & 0xf);
index = bpp_type_lut[index]; /* get color mode */
/* get matched ge2d color mode. */
src_dst->ge2d_color_index = default_ge2d_color_lut[index];
if (src_dst->xres <= 0 ||
src_dst->yres <= 0 ||
src_dst->ge2d_color_index == 0)
return -2;
}
return 0;
}
int ge2d_antiflicker_enable(struct ge2d_context_s *context,
unsigned long enable)
{
/*
* antiflicker used in cvbs mode, if antiflicker is enabled,
* it represent that we want this feature be enabled for all ge2d work
*/
struct ge2d_context_s *pcontext;
spin_lock(&ge2d_manager.event.sem_lock);
list_for_each_entry(pcontext, &ge2d_manager.process_queue, list) {
ge2dgen_antiflicker(pcontext, enable);
}
spin_unlock(&ge2d_manager.event.sem_lock);
return 0;
}
int ge2d_context_config(struct ge2d_context_s *context,
struct config_para_s *ge2d_config)
{
struct src_dst_para_s src, dst, tmp;
int type = ge2d_config->src_dst_type;
ge2d_log_dbg(" ge2d init\n");
/* setup src and dst */
switch (type) {
case OSD0_OSD0:
case OSD0_OSD1:
case OSD1_OSD0:
case ALLOC_OSD0:
if (0 > setup_display_property(&src, OSD1_CANVAS_INDEX))
return -1;
break;
default:
break;
}
switch (type) {
case OSD0_OSD1:
case OSD1_OSD1:
case OSD1_OSD0:
case ALLOC_OSD1:
if (0 > setup_display_property(&dst, OSD2_CANVAS_INDEX))
return -1;
break;
case ALLOC_ALLOC:
default:
break;
}
ge2d_log_dbg("OSD ge2d type %d\n", type);
switch (type) {
case OSD0_OSD0:
dst = src;
break;
case OSD0_OSD1:
break;
case OSD1_OSD1:
src = dst;
break;
case OSD1_OSD0:
tmp = src;
src = dst;
dst = tmp;
break;
case ALLOC_OSD0:
dst = src;
build_ge2d_config(ge2d_config, &src, NULL, ALLOC_CANVAS_INDEX);
break;
case ALLOC_OSD1:
build_ge2d_config(ge2d_config, &src, NULL, ALLOC_CANVAS_INDEX);
break;
case ALLOC_ALLOC:
build_ge2d_config(ge2d_config, &src, &dst, ALLOC_CANVAS_INDEX);
break;
}
if (src.bpp < 16 || dst.bpp < 16)
ge2d_log_dbg("src dst bpp type, src=%d,dst=%d\n",
src.bpp, dst.bpp);
/* next will config regs */
ge2d_log_dbg("ge2d src.xres %d src.yres %d, dst.xres %d dst.yres %d\n",
src.xres, src.yres, dst.xres, dst.yres);
ge2d_log_dbg("src_format: 0x%x, dst_format: 0x%x\n",
src.ge2d_color_index, dst.ge2d_color_index);
ge2dgen_src(context, src.canvas_index, src.ge2d_color_index);
ge2dgen_src_clip(context,
0, 0, src.xres, src.yres);
ge2dgen_src2(context, dst.canvas_index, dst.ge2d_color_index);
ge2dgen_src2_clip(context,
0, 0, dst.xres, dst.yres);
ge2dgen_const_color(context, ge2d_config->alu_const_color);
ge2dgen_dst(context, dst.canvas_index, dst.ge2d_color_index);
ge2dgen_dst_clip(context,
0, 0, dst.xres, dst.yres, DST_CLIP_MODE_INSIDE);
return 0;
}
static int build_ge2d_config_ex(struct config_planes_s *plane,
unsigned format,
unsigned *canvas_index,
int index,
unsigned *r_offset)
{
int bpp_value = bpp(format);
int ret = -1;
bpp_value /= 8;
index &= 0xff;
if (plane) {
if (plane[0].addr) {
*canvas_index = index;
*r_offset += 1;
canvas_config(index++, plane[0].addr,
plane[0].w * bpp_value,
plane[0].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
ret = 0;
}
/* multi-src_planes */
if (plane[1].addr) {
*canvas_index |= index << 8;
*r_offset += 1;
canvas_config(index++, plane[1].addr,
plane[1].w * bpp_value,
plane[1].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
if (plane[2].addr) {
*canvas_index |= index << 16;
*r_offset += 1;
canvas_config(index++, plane[2].addr,
plane[2].w * bpp_value,
plane[2].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
if (plane[3].addr) {
*canvas_index |= index << 24;
*r_offset += 1;
canvas_config(index++, plane[3].addr,
plane[3].w * bpp_value,
plane[3].h,
CANVAS_ADDR_NOWRAP,
CANVAS_BLKMODE_LINEAR);
}
}
return ret;
}
int ge2d_context_config_ex(struct ge2d_context_s *context,
struct config_para_ex_s *ge2d_config)
{
struct src_dst_para_s tmp;
unsigned index = 0;
unsigned alloc_canvas_offset = 0;
struct ge2d_src1_gen_s *src1_gen_cfg;
struct ge2d_src2_dst_data_s *src2_dst_data_cfg;
struct ge2d_src2_dst_gen_s *src2_dst_gen_cfg;
struct ge2d_dp_gen_s *dp_gen_cfg;
struct ge2d_cmd_s *ge2d_cmd_cfg;
int top, left, width, height;
/* setup src and dst */
switch (ge2d_config->src_para.mem_type) {
case CANVAS_OSD0:
case CANVAS_OSD1:
if (setup_display_property(&tmp,
(ge2d_config->src_para.mem_type == CANVAS_OSD0) ?
OSD1_CANVAS_INDEX : OSD2_CANVAS_INDEX) < 0)
return -1;
ge2d_config->src_para.canvas_index = tmp.canvas_index;
ge2d_config->src_para.format = tmp.ge2d_color_index;
ge2d_log_dbg("ge2d: src1-->type: osd%d, format: 0x%x !!\n",
ge2d_config->src_para.mem_type - CANVAS_OSD0,
ge2d_config->src_para.format);
top = ge2d_config->src_para.top;
left = ge2d_config->src_para.left;
width = ge2d_config->src_para.width;
height = ge2d_config->src_para.height;
if ((left + width > tmp.xres) ||
(top + height > tmp.yres)) {
ge2d_log_dbg("ge2d src error: out of range\n");
return -1;
}
break;
case CANVAS_ALLOC:
top = ge2d_config->src_para.top;
left = ge2d_config->src_para.left;
width = ge2d_config->src_para.width;
height = ge2d_config->src_para.height;
if ((left + width > ge2d_config->src_planes[0].w)
|| (top + height > ge2d_config->src_planes[0].h)) {
ge2d_log_dbg("ge2d error: src alloc, out of range\n");
return -1;
}
if (build_ge2d_config_ex(&ge2d_config->src_planes[0],
ge2d_config->src_para.format,
&index,
ALLOC_CANVAS_INDEX + alloc_canvas_offset,
&alloc_canvas_offset) < 0)
return -1;
ge2d_config->src_para.canvas_index = index;
ge2d_log_dbg("ge2d alloc canvas index:0x%x, format:0x%x\n",
index, ge2d_config->src_para.format);
break;
default:
break;
}
switch (ge2d_config->src2_para.mem_type) {
case CANVAS_OSD0:
case CANVAS_OSD1:
if (setup_display_property(&tmp,
(ge2d_config->src2_para.mem_type == CANVAS_OSD0) ?
OSD1_CANVAS_INDEX : OSD2_CANVAS_INDEX) < 0)
return -1;
ge2d_config->src2_para.canvas_index = tmp.canvas_index;
ge2d_config->src2_para.format = tmp.ge2d_color_index;
ge2d_log_dbg("ge2d: src2-->type: osd%d, format: 0x%x !!\n",
ge2d_config->src2_para.mem_type - CANVAS_OSD0,
ge2d_config->src2_para.format);
top = ge2d_config->src2_para.top;
left = ge2d_config->src2_para.left;
width = ge2d_config->src2_para.width;
height = ge2d_config->src2_para.height;
if ((left + width > tmp.xres) || (top + height > tmp.yres)) {
ge2d_log_dbg("ge2d error: src2: osd%d, out of range\n",
ge2d_config->src2_para.mem_type - CANVAS_OSD0);
return -1;
}
break;
case CANVAS_ALLOC:
top = ge2d_config->src2_para.top;
left = ge2d_config->src2_para.left;
width = ge2d_config->src2_para.width;
height = ge2d_config->src2_para.height;
if ((left + width > ge2d_config->src2_planes[0].w)
|| (top + height > ge2d_config->src2_planes[0].h)) {
ge2d_log_dbg("ge2d error: src2: alloc, out of range\n");
return -1;
}
if (ge2d_config->src2_planes[0].addr ==
ge2d_config->src_planes[0].addr)
index = ge2d_config->src_para.canvas_index;
else if (build_ge2d_config_ex(&ge2d_config->src2_planes[0],
ge2d_config->src2_para.format,
&index,
ALLOC_CANVAS_INDEX + alloc_canvas_offset,
&alloc_canvas_offset) < 0)
return -1;
ge2d_config->src2_para.canvas_index = index;
ge2d_log_dbg("ge2d src2 alloc, canvas index:0x%x,format:0x%x\n",
index, ge2d_config->src2_para.format);
break;
default:
break;
}
switch (ge2d_config->dst_para.mem_type) {
case CANVAS_OSD0:
case CANVAS_OSD1:
if (setup_display_property(&tmp,
(ge2d_config->dst_para.mem_type == CANVAS_OSD0) ?
OSD1_CANVAS_INDEX : OSD2_CANVAS_INDEX) < 0)
return -1;
ge2d_config->dst_para.canvas_index = tmp.canvas_index;
ge2d_config->dst_para.format = tmp.ge2d_color_index;
ge2d_log_dbg("ge2d: dst-->type: osd%d, format: 0x%x !!\n",
ge2d_config->dst_para.mem_type - CANVAS_OSD0,
ge2d_config->dst_para.format);
top = ge2d_config->dst_para.top;
left = ge2d_config->dst_para.left;
width = ge2d_config->dst_para.width;
height = ge2d_config->dst_para.height;
if ((left + width > tmp.xres) || (top + height > tmp.yres)) {
ge2d_log_dbg("ge2d error: dst: osd%d, out of range\n",
ge2d_config->dst_para.mem_type - CANVAS_OSD0);
return -1;
}
break;
case CANVAS_ALLOC:
top = ge2d_config->dst_para.top;
left = ge2d_config->dst_para.left;
width = ge2d_config->dst_para.width;
height = ge2d_config->dst_para.height;
if ((left + width > ge2d_config->dst_planes[0].w)
|| (top + height > ge2d_config->dst_planes[0].h)) {
ge2d_log_dbg("ge2d error: dst: alloc, out of range\n");
return -1;
}
if (ge2d_config->dst_planes[0].addr ==
ge2d_config->src_planes[0].addr)
index = ge2d_config->src_para.canvas_index;
else if (ge2d_config->dst_planes[0].addr ==
ge2d_config->src2_planes[0].addr)
index = ge2d_config->src2_para.canvas_index;
else if (build_ge2d_config_ex(&ge2d_config->dst_planes[0],
ge2d_config->dst_para.format,
&index,
ALLOC_CANVAS_INDEX + alloc_canvas_offset,
&alloc_canvas_offset) < 0)
return -1;
ge2d_config->dst_para.canvas_index = index;
ge2d_log_dbg("ge2d: dst alloc, index:0x%x, format:0x%x\n",
index, ge2d_config->dst_para.format);
break;
default:
break;
}
ge2dgen_rendering_dir(context, ge2d_config->src_para.x_rev,
ge2d_config->src_para.y_rev,
ge2d_config->dst_para.x_rev,
ge2d_config->dst_para.y_rev,
ge2d_config->dst_xy_swap);
ge2dgen_const_color(context, ge2d_config->alu_const_color);
ge2dgen_src(context, ge2d_config->src_para.canvas_index,
ge2d_config->src_para.format);
ge2dgen_src_clip(context, ge2d_config->src_para.left,
ge2d_config->src_para.top,
ge2d_config->src_para.width,
ge2d_config->src_para.height);
ge2dgen_src_key(context, ge2d_config->src_key.key_enable,
ge2d_config->src_key.key_color,
ge2d_config->src_key.key_mask,
ge2d_config->src_key.key_mode);
ge2dgent_src_gbalpha(context, ge2d_config->src1_gb_alpha);
ge2dgen_src_color(context, ge2d_config->src_para.color);
ge2dgen_src2(context, ge2d_config->src2_para.canvas_index,
ge2d_config->src2_para.format);
ge2dgen_src2_clip(context, ge2d_config->src2_para.left,
ge2d_config->src2_para.top,
ge2d_config->src2_para.width,
ge2d_config->src2_para.height);
ge2dgen_dst(context, ge2d_config->dst_para.canvas_index,
ge2d_config->dst_para.format);
ge2dgen_dst_clip(context, ge2d_config->dst_para.left,
ge2d_config->dst_para.top,
ge2d_config->dst_para.width,
ge2d_config->dst_para.height,
DST_CLIP_MODE_INSIDE);
src1_gen_cfg = ge2d_wq_get_src_gen(context);
src1_gen_cfg->fill_mode = ge2d_config->src_para.fill_mode;
src1_gen_cfg->chfmt_rpt_pix = 0;
src1_gen_cfg->cvfmt_rpt_pix = 0;
/* src1_gen_cfg->clipx_start_ex = 0; */
/* src1_gen_cfg->clipx_end_ex = 1; */
/* src1_gen_cfg->clipy_start_ex = 1; */
/* src1_gen_cfg->clipy_end_ex = 1; */
src2_dst_data_cfg = ge2d_wq_get_dst_data(context);
src2_dst_data_cfg->src2_def_color = ge2d_config->src2_para.color;
src2_dst_gen_cfg = ge2d_wq_get_dst_gen(context);
src2_dst_gen_cfg->src2_fill_mode = ge2d_config->src2_para.fill_mode;
dp_gen_cfg = ge2d_wq_get_dp_gen(context);
dp_gen_cfg->src1_vsc_phase0_always_en =
ge2d_config->src1_hsc_phase0_always_en;
dp_gen_cfg->src1_hsc_phase0_always_en =
ge2d_config->src1_vsc_phase0_always_en;
/* 1bit, 0: using minus, 1: using repeat data */
dp_gen_cfg->src1_hsc_rpt_ctrl = ge2d_config->src1_hsc_rpt_ctrl;
/* 1bit, 0: using minus 1: using repeat data */
dp_gen_cfg->src1_vsc_rpt_ctrl = ge2d_config->src1_vsc_rpt_ctrl;
dp_gen_cfg->src2_key_en = ge2d_config->src2_key.key_enable;
dp_gen_cfg->src2_key_mode = ge2d_config->src2_key.key_mode;
dp_gen_cfg->src2_key = ge2d_config->src2_key.key_color;
dp_gen_cfg->src2_key_mask = ge2d_config->src2_key.key_mask;
dp_gen_cfg->bitmask_en = ge2d_config->bitmask_en;
dp_gen_cfg->bitmask = ge2d_config->bitmask;
dp_gen_cfg->bytemask_only = ge2d_config->bytemask_only;
ge2d_cmd_cfg = ge2d_wq_get_cmd(context);
ge2d_cmd_cfg->src1_fill_color_en = ge2d_config->src_para.fill_color_en;
ge2d_cmd_cfg->src2_x_rev = ge2d_config->src2_para.x_rev;
ge2d_cmd_cfg->src2_y_rev = ge2d_config->src2_para.y_rev;
ge2d_cmd_cfg->src2_fill_color_en =
ge2d_config->src2_para.fill_color_en;
ge2d_cmd_cfg->vsc_phase_slope = ge2d_config->vsc_phase_slope;
ge2d_cmd_cfg->vsc_ini_phase = ge2d_config->vf_init_phase;
ge2d_cmd_cfg->vsc_phase_step = ge2d_config->vsc_start_phase_step;
ge2d_cmd_cfg->vsc_rpt_l0_num = ge2d_config->vf_rpt_num;
/* let internal decide */
ge2d_cmd_cfg->hsc_phase_slope = ge2d_config->hsc_phase_slope;
ge2d_cmd_cfg->hsc_ini_phase = ge2d_config->hf_init_phase;
ge2d_cmd_cfg->hsc_phase_step = ge2d_config->hsc_start_phase_step;
ge2d_cmd_cfg->hsc_rpt_p0_num = ge2d_config->hf_rpt_num;
ge2d_cmd_cfg->src1_cmult_asel = 0;
ge2d_cmd_cfg->src2_cmult_asel = 0;
context->config.update_flag = UPDATE_ALL;
/* context->config.src1_data.ddr_burst_size_y = 3; */
/* context->config.src1_data.ddr_burst_size_cb = 3; */
/* context->config.src1_data.ddr_burst_size_cr = 3; */
/* context->config.src2_dst_data.ddr_burst_size= 3; */
return 0;
}
struct ge2d_context_s *create_ge2d_work_queue(void)
{