forked from torvalds/linux
/
dev_disp.c
2001 lines (1657 loc) · 46.4 KB
/
dev_disp.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
/*
* Copyright (C) 2007-2012 Allwinner Technology Co., Ltd.
* Copyright (C) 2012 Luc Verhaegen <libv@skynet.be>
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#ifdef CONFIG_FB_SUNXI_UMP
#include <ump/ump_kernel_interface.h>
#endif
#include <linux/console.h>
#include "drv_disp_i.h"
#include "dev_disp.h"
#include "disp_lcd.h"
#include "dev_fb.h"
#include "disp_display.h"
struct info_mm {
void *info_base; /* Virtual address */
unsigned long mem_start; /* Start of frame buffer mem */
/* (physical address) */
__u32 mem_len; /* Length of frame buffer mem */
};
struct __disp_drv_t {
__u32 mid;
__u32 used;
__u32 status;
__u32 exit_mode; /* 0:clean all 1:disable interrupt */
__bool b_cache[2];
__bool b_lcd_open[2];
} ;
struct alloc_struct_t {
__u32 address; /* Application memory address */
__u32 size; /* The size of the allocated memory */
__u32 o_size; /* User application memory size */
struct alloc_struct_t *next;
};
static struct __disp_drv_t g_disp_drv;
/* alloc based on 4K byte */
#define MY_BYTE_ALIGN(x) (((x + (4*1024-1)) >> 12) << 12)
static struct alloc_struct_t boot_heap_head, boot_heap_tail;
static unsigned int gbuffer[4096];
static __u32 suspend_output_type[2];
/*
* 0:normal;
* suspend_status&1 != 0:in early_suspend;
* suspend_status&2 != 0:in suspend;
*/
static __u32 suspend_status;
static struct info_mm g_disp_mm[10];
static int g_disp_mm_sel;
static struct cdev *my_cdev;
static dev_t devid;
static struct class *disp_class;
static struct resource disp_resource[DISP_IO_NUM] = {
[DISP_IO_SCALER0] = {
.start = 0x01e00000,
.end = 0x01e0077f,
.flags = IORESOURCE_MEM,
},
[DISP_IO_SCALER1] = {
.start = 0x01e20000,
.end = 0x01e2077f,
.flags = IORESOURCE_MEM,
},
[DISP_IO_IMAGE0] = {
.start = 0x01e60000,
.end = 0x01e657ff,
.flags = IORESOURCE_MEM,
},
[DISP_IO_IMAGE1] = {
.start = 0x01e40000,
.end = 0x01e457ff,
.flags = IORESOURCE_MEM,
},
[DISP_IO_LCDC0] = {
.start = 0x01c0c000,
.end = 0x01c0cfff,
.flags = IORESOURCE_MEM,
},
[DISP_IO_LCDC1] = {
.start = 0x01c0d000,
.end = 0x01c0dfff,
.flags = IORESOURCE_MEM,
},
[DISP_IO_TVEC0] = {
.start = 0x01c0a000,
.end = 0x01c0afff,
.flags = IORESOURCE_MEM,
},
[DISP_IO_TVEC1] = {
.start = 0x01c1b000,
.end = 0x01c1bfff,
.flags = IORESOURCE_MEM,
},
#ifdef CONFIG_ARCH_SUN5I
[DISP_IO_IEP] = {
.start = 0x01e70000,
.end = 0x01e703ff,
.flags = IORESOURCE_MEM,
},
#endif
};
__s32 disp_create_heap(__u32 pHeapHead, __u32 nHeapSize)
{
boot_heap_head.size = boot_heap_tail.size = 0;
boot_heap_head.address = pHeapHead;
boot_heap_tail.address = pHeapHead + nHeapSize;
boot_heap_head.next = &boot_heap_tail;
boot_heap_tail.next = NULL;
__inf("head:%x,tail:%x\n", boot_heap_head.address,
boot_heap_tail.address);
return 0;
}
void *disp_malloc(__u32 num_bytes)
{
struct alloc_struct_t *ptr, *newptr;
__u32 actual_bytes;
if (!num_bytes)
return NULL;
/* translate the byte count to size of long type */
actual_bytes = MY_BYTE_ALIGN(num_bytes);
/* scan from the boot_heap_head of the heap */
ptr = &boot_heap_head;
/* look for enough memory for alloc */
while (ptr && ptr->next) {
if (ptr->next->address >=
(ptr->address + ptr->size + (8 * 1024) + actual_bytes)) {
break;
}
/* find enough memory to alloc */
ptr = ptr->next;
}
if (!ptr->next) {
__wrn(" it has reached the boot_heap_tail of the heap now\n");
return NULL;
}
newptr = (struct alloc_struct_t *)(ptr->address + ptr->size);
/* create a new node for the memory block */
if (!newptr) {
__wrn(" create the node failed, can't manage the block\n");
return NULL;
}
/* set the memory block chain, insert the node to the chain */
newptr->address = ptr->address + ptr->size + 4 * 1024;
newptr->size = actual_bytes;
newptr->o_size = num_bytes;
newptr->next = ptr->next;
ptr->next = newptr;
return (void *)newptr->address;
}
void disp_free(void *p)
{
struct alloc_struct_t *ptr, *prev;
if (p == NULL)
return;
/* look for the node which po__s32 this memory block */
ptr = &boot_heap_head;
while (ptr && ptr->next) {
if (((void *) ptr->next->address) == p)
break; /* find the node which need to be release */
ptr = ptr->next;
}
prev = ptr;
ptr = ptr->next;
if (!ptr)
return; /* the node is heap boot_heap_tail */
/*
* delete the node which need be released from the memory block chain
*/
prev->next = ptr->next;
return;
}
int sunxi_is_version_A(void)
{
#ifdef CONFIG_ARCH_SUN4I
if (sw_get_ic_ver() == MAGIC_VER_A)
return 1;
#endif
return 0;
}
__s32 DRV_lcd_open(__u32 sel)
{
__u32 i = 0;
__lcd_flow_t *flow;
if (g_disp_drv.b_lcd_open[sel] == 0) {
BSP_disp_lcd_open_before(sel);
flow = BSP_disp_lcd_get_open_flow(sel);
for (i = 0; i < flow->func_num; i++) {
__u32 timeout = flow->func[i].delay * HZ / 1000;
flow->func[i].func(sel);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(timeout);
}
BSP_disp_lcd_open_after(sel);
g_disp_drv.b_lcd_open[sel] = 1;
}
return 0;
}
__s32 DRV_lcd_close(__u32 sel)
{
__u32 i = 0;
__lcd_flow_t *flow;
if (g_disp_drv.b_lcd_open[sel] == 1) {
BSP_disp_lcd_close_befor(sel);
flow = BSP_disp_lcd_get_close_flow(sel);
for (i = 0; i < flow->func_num; i++) {
__u32 timeout = flow->func[i].delay * HZ / 1000;
flow->func[i].func(sel);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(timeout);
}
BSP_disp_lcd_close_after(sel);
g_disp_drv.b_lcd_open[sel] = 0;
}
return 0;
}
__s32 disp_set_hdmi_func(__disp_hdmi_func *func)
{
BSP_disp_set_hdmi_func(func);
return 0;
}
EXPORT_SYMBOL(disp_set_hdmi_func);
__s32 DRV_DISP_Init(void)
{
__disp_bsp_init_para para;
init_waitqueue_head(&g_fbi.wait[0]);
init_waitqueue_head(&g_fbi.wait[1]);
g_fbi.wait_count[0] = 0;
g_fbi.wait_count[1] = 0;
memset(¶, 0, sizeof(__disp_bsp_init_para));
para.base_image0 = (__u32) g_fbi.base_image0;
para.base_image1 = (__u32) g_fbi.base_image1;
para.base_scaler0 = (__u32) g_fbi.base_scaler0;
para.base_scaler1 = (__u32) g_fbi.base_scaler1;
para.base_lcdc0 = (__u32) g_fbi.base_lcdc0;
para.base_lcdc1 = (__u32) g_fbi.base_lcdc1;
para.base_tvec0 = (__u32) g_fbi.base_tvec0;
para.base_tvec1 = (__u32) g_fbi.base_tvec1;
#ifdef CONFIG_ARCH_SUN5I
para.base_iep = (__u32) g_fbi.base_iep;
#endif
para.base_ccmu = (__u32) g_fbi.base_ccmu;
para.base_sdram = (__u32) g_fbi.base_sdram;
para.base_pioc = (__u32) g_fbi.base_pioc;
para.base_pwm = (__u32) g_fbi.base_pwm;
para.disp_int_process = DRV_disp_int_process;
memset(&g_disp_drv, 0, sizeof(struct __disp_drv_t));
BSP_disp_init(¶);
BSP_disp_open();
return 0;
}
__s32 DRV_DISP_Exit(void)
{
Fb_Exit();
BSP_disp_close();
BSP_disp_exit(g_disp_drv.exit_mode);
return 0;
}
static int
disp_mem_request(int sel, __u32 size)
{
unsigned map_size = 0;
struct page *page;
if (g_disp_mm[sel].info_base != NULL)
return -EINVAL;
#ifdef CONFIG_FB_SUNXI_RESERVED_MEM
if (fb_size) {
void *ret = disp_malloc(size);
if (ret) {
g_disp_mm[sel].info_base = ret;
g_disp_mm[sel].mem_start =
virt_to_phys(g_disp_mm[sel].info_base);
memset(g_disp_mm[sel].info_base, 0, size);
__inf("pa=0x%08lx va=0x%p size:0x%x\n",
g_disp_mm[sel].mem_start,
g_disp_mm[sel].info_base, size);
return 0;
} else {
__wrn("disp_malloc fail!\n");
return -ENOMEM;
}
}
#endif
g_disp_mm[sel].mem_len = size;
map_size = PAGE_ALIGN(g_disp_mm[sel].mem_len);
page = alloc_pages(GFP_KERNEL, get_order(map_size));
if (page != NULL) {
g_disp_mm[sel].info_base = page_address(page);
if (g_disp_mm[sel].info_base == NULL) {
free_pages((unsigned long)(page), get_order(map_size));
__wrn("page_address fail!\n");
return -ENOMEM;
}
g_disp_mm[sel].mem_start =
virt_to_phys(g_disp_mm[sel].info_base);
memset(g_disp_mm[sel].info_base, 0, size);
__inf("pa=0x%08lx va=0x%p size:0x%x\n",
g_disp_mm[sel].mem_start, g_disp_mm[sel].info_base, size);
return 0;
} else {
__wrn("alloc_pages fail!\n");
return -ENOMEM;
}
}
static int
disp_mem_release(int sel)
{
unsigned map_size = PAGE_ALIGN(g_disp_mm[sel].mem_len);
if (g_disp_mm[sel].info_base == NULL)
return -EINVAL;
#ifdef CONFIG_FB_SUNXI_RESERVED_MEM
if (fb_size)
disp_free((void *)g_disp_mm[sel].info_base);
else
#endif
free_pages((unsigned long)(g_disp_mm[sel].info_base),
get_order(map_size));
memset(&g_disp_mm[sel], 0, sizeof(struct info_mm));
return 0;
}
static int disp_mmap(struct file *filp, struct vm_area_struct *vma)
{
// - PAGE_OFFSET;
unsigned long physics = g_disp_mm[g_disp_mm_sel].mem_start;
unsigned long mypfn = physics >> PAGE_SHIFT;
unsigned long vmsize = vma->vm_end - vma->vm_start;
if (remap_pfn_range(vma, vma->vm_start, mypfn, vmsize,
vma->vm_page_prot))
return -EAGAIN;
return 0;
}
/*
*
*/
struct dev_disp_data {
/* Version of the user of /dev/disp */
#define SUNXI_DISP_VERSION_PENDING -1
#define SUNXI_DISP_VERSION_SKIPPED -2
int version;
struct {
__u32 layer[SUNXI_DISP_MAX_LAYERS];
} layers[2];
};
static int disp_open(struct inode *inode, struct file *filp)
{
struct dev_disp_data *data =
kzalloc(sizeof(struct dev_disp_data), GFP_KERNEL);
static bool warned;
if (!data)
return -ENOMEM;
data->version = SUNXI_DISP_VERSION_PENDING;
filp->private_data = data;
if (!warned) {
pr_warn("Warning: this sunxi disp driver will see significant "
"redesign.\n");
pr_warn("Applications using /dev/disp directly will break.\n");
pr_warn("For more information visit: "
"http://linux-sunxi.org/Sunxi_disp_driver\n");
warned = true;
}
return 0;
}
static int disp_release(struct inode *inode, struct file *filp)
{
struct dev_disp_data *data = filp->private_data;
int i,j;
for (j = 0; j < 2; j++)
for (i = 0; i < SUNXI_DISP_MAX_LAYERS ; i++)
if (data->layers[j].layer[i]) {
__wrn("layer allocated at close: %i,%u\n", j, data->layers[j].layer[i]);
BSP_disp_layer_release(j,data->layers[j].layer[i]);
}
kfree(data);
filp->private_data = NULL;
return 0;
}
static ssize_t disp_read(struct file *filp,
char __user *buf, size_t count, loff_t *ppos)
{
return 0;
}
static ssize_t disp_write(struct file *filp,
const char __user *buf, size_t count, loff_t *ppos)
{
return 0;
}
/*
* called when platform_driver_register
*/
static int __devinit disp_probe(struct platform_device *pdev)
{
fb_info_t *info = NULL;
__inf("disp_probe call\n");
info = &g_fbi;
info->dev = &pdev->dev;
platform_set_drvdata(pdev, info);
info->base_image0 = 0xf1e60000;
info->base_image1 = 0xf1e40000;
info->base_scaler0 = 0xf1e00000;
info->base_scaler1 = 0xf1e20000;
info->base_lcdc0 = 0xf1c0c000;
info->base_lcdc1 = 0xf1c0d000;
info->base_tvec0 = 0xf1c0a000;
info->base_tvec1 = 0xf1c1b000;
info->base_ccmu = 0xf1c20000;
info->base_sdram = 0xf1c01000;
info->base_pioc = 0xf1c20800;
info->base_pwm = 0xf1c20c00;
#ifdef CONFIG_ARCH_SUN5I
info->base_iep = 0xf1e70000;
#endif
__inf("SCALER0 base 0x%08x\n", info->base_scaler0);
__inf("SCALER1 base 0x%08x\n", info->base_scaler1);
__inf("IMAGE0 base 0x%08x\n", info->base_image0 + 0x800);
__inf("IMAGE1 base 0x%08x\n", info->base_image1 + 0x800);
__inf("LCDC0 base 0x%08x\n", info->base_lcdc0);
__inf("LCDC1 base 0x%08x\n", info->base_lcdc1);
__inf("TVEC0 base 0x%08x\n", info->base_tvec0);
__inf("TVEC1 base 0x%08x\n", info->base_tvec1);
#ifdef CONFIG_ARCH_SUN5I
__inf("IEP base 0x%08x\n", info->base_iep);
#endif
__inf("CCMU base 0x%08x\n", info->base_ccmu);
__inf("SDRAM base 0x%08x\n", info->base_sdram);
__inf("PIO base 0x%08x\n", info->base_pioc);
__inf("PWM base 0x%08x\n", info->base_pwm);
pr_info("sunxi disp driver loaded (/dev/disp api %d.%d)\n",
SUNXI_DISP_VERSION_MAJOR, SUNXI_DISP_VERSION_MINOR);
return 0;
}
static int disp_remove(struct platform_device *pdev)
{
__inf("disp_remove call\n");
platform_set_drvdata(pdev, NULL);
return 0;
}
int disp_suspend(int clk, int status)
{
int i = 0;
__inf("disp_suspend clk %d status %d call\n", clk, status);
if (clk != 1)
for (i = 0; i < 2; i++) {
suspend_output_type[i] = BSP_disp_get_output_type(i);
if (suspend_output_type[i] == DISP_OUTPUT_TYPE_LCD)
DRV_lcd_close(i);
else if (suspend_output_type[i] == DISP_OUTPUT_TYPE_TV)
BSP_disp_tv_close(i);
else if (suspend_output_type[i] == DISP_OUTPUT_TYPE_VGA)
BSP_disp_vga_close(i);
else if (suspend_output_type[i] == DISP_OUTPUT_TYPE_HDMI)
BSP_disp_hdmi_close(i);
}
BSP_disp_clk_off(clk);
suspend_status |= status;
return 0;
}
int disp_resume(int clk, int status)
{
int i = 0;
__inf("disp_resume clk %d status %d call\n", clk, status);
BSP_disp_clk_on(clk);
if (clk != 1)
for (i = 0; i < 2; i++) {
if (suspend_output_type[i] == DISP_OUTPUT_TYPE_LCD)
DRV_lcd_open(i);
else if (suspend_output_type[i] == DISP_OUTPUT_TYPE_TV)
BSP_disp_tv_open(i);
else if (suspend_output_type[i] == DISP_OUTPUT_TYPE_VGA)
BSP_disp_vga_open(i);
else if (suspend_output_type[i] == DISP_OUTPUT_TYPE_HDMI)
BSP_disp_hdmi_open(i, 0);
}
suspend_status &= ~status;
return 0;
}
#ifdef CONFIG_HAS_EARLYSUSPEND
static void backlight_early_suspend(struct early_suspend *h)
{
disp_suspend(2, 1);
}
static void backlight_late_resume(struct early_suspend *h)
{
disp_resume(2, 1);
}
static struct early_suspend backlight_early_suspend_handler = {
.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
.suspend = backlight_early_suspend,
.resume = backlight_late_resume,
};
#endif
static int
disp_normal_suspend(struct platform_device *pdev, pm_message_t state)
{
int i;
console_lock();
for(i = 0; i < SUNXI_MAX_FB; i++)
fb_set_suspend(g_fbi.fbinfo[i], 1);
console_unlock();
#ifndef CONFIG_HAS_EARLYSUSPEND
disp_suspend(3, 3);
#else
disp_suspend(1, 2);
#endif
return 0;
}
static int
disp_normal_resume(struct platform_device *pdev)
{
int i;
#ifndef CONFIG_HAS_EARLYSUSPEND
disp_resume(3, 3);
#else
disp_resume(1, 2);
#endif
console_lock();
for(i = 0; i < SUNXI_MAX_FB; i++)
fb_set_suspend(g_fbi.fbinfo[i], 0);
console_unlock();
return 0;
}
static void
disp_shutdown(struct platform_device *pdev)
{
__u32 type = 0, i = 0;
for (i = 0; i < 2; i++) {
type = BSP_disp_get_output_type(i);
if (type == DISP_OUTPUT_TYPE_LCD)
DRV_lcd_close(i);
}
}
static long disp_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
struct dev_disp_data *filp_data = filp->private_data;
unsigned long karg[4];
unsigned long ubuffer[4] = { 0 };
__s32 ret = 0;
if (copy_from_user
((void *)karg, (void __user *)arg, 4 * sizeof(unsigned long))) {
__wrn("copy_from_user fail\n");
return -EFAULT;
}
ubuffer[0] = *(unsigned long *)karg;
ubuffer[1] = (*(unsigned long *)(karg + 1));
ubuffer[2] = (*(unsigned long *)(karg + 2));
ubuffer[3] = (*(unsigned long *)(karg + 3));
/* Verify version handshake first. */
if (filp_data->version == SUNXI_DISP_VERSION_PENDING) {
if (cmd == DISP_CMD_VERSION) {
int version = *((int *) karg);
if (version < 0) {
pr_err("disp: process %d (%s) provided an "
"invalid version.\n",
current->pid, current->comm);
filp_data->version = SUNXI_DISP_VERSION_SKIPPED;
return -EINVAL;
}
if (version != SUNXI_DISP_VERSION)
pr_warn("disp: process %d (%s) has a different "
"version: %d.%d (vs. %d.%d)\n",
current->pid, current->comm,
SUNXI_DISP_VERSION_MAJOR_GET(version),
SUNXI_DISP_VERSION_MINOR_GET(version),
SUNXI_DISP_VERSION_MAJOR,
SUNXI_DISP_VERSION_MINOR);
/* Add compatibility checks here */
filp_data->version = version;
return SUNXI_DISP_VERSION;
} else {
pr_err("disp: process %d (%s) has skipped the version "
"handshake.\n", current->pid, current->comm);
filp_data->version = SUNXI_DISP_VERSION_SKIPPED;
}
}
if (cmd < DISP_CMD_FB_REQUEST) {
if ((ubuffer[0] != 0) && (ubuffer[0] != 1)) {
__wrn("para err in disp_ioctl, cmd = 0x%x,"
"screen id = %d\n", cmd, (int)ubuffer[0]);
return -1;
}
}
if (suspend_status & 2) {
__wrn("ioctl:%x fail when in suspend!\n", cmd);
return -1;
}
#if 0
if (cmd != DISP_CMD_TV_GET_INTERFACE &&
cmd != DISP_CMD_HDMI_GET_HPD_STATUS &&
cmd != DISP_CMD_GET_OUTPUT_TYPE && cmd != DISP_CMD_SCN_GET_WIDTH &&
cmd != DISP_CMD_SCN_GET_HEIGHT && cmd != DISP_CMD_VIDEO_SET_FB &&
cmd != DISP_CMD_VIDEO_GET_FRAME_ID)
DE_WRN("cmd:0x%x,%ld,%ld\n", cmd, ubuffer[0], ubuffer[1]);
#endif
switch (cmd) {
/* ----disp global---- */
case DISP_CMD_SET_BKCOLOR:
{
__disp_color_t para;
if (copy_from_user(¶, (void __user *)ubuffer[1],
sizeof(__disp_color_t))) {
__wrn("copy_from_user fail\n");
return -EFAULT;
}
ret = BSP_disp_set_bk_color(ubuffer[0], ¶);
break;
}
case DISP_CMD_SET_COLORKEY:
{
__disp_colorkey_t para;
if (copy_from_user(¶, (void __user *)ubuffer[1],
sizeof(__disp_colorkey_t))) {
__wrn("copy_from_user fail\n");
return -EFAULT;
}
ret = BSP_disp_set_color_key(ubuffer[0], ¶);
break;
}
case DISP_CMD_SET_PALETTE_TBL:
if ((ubuffer[1] == 0) || ((int)ubuffer[3] <= 0)) {
__wrn("para invalid in disp ioctrl "
"DISP_CMD_SET_PALETTE_TBL,buffer:0x%x, "
"size:0x%x\n", (unsigned int) ubuffer[1],
(unsigned int) ubuffer[3]);
return -1;
}
if (copy_from_user(gbuffer, (void __user *) ubuffer[1],
ubuffer[3])) {
__wrn("copy_from_user fail\n");
return -EFAULT;
}
ret = BSP_disp_set_palette_table(ubuffer[0], (__u32 *) gbuffer,
ubuffer[2], ubuffer[3]);
break;
case DISP_CMD_GET_PALETTE_TBL:
if ((ubuffer[1] == 0) || ((int)ubuffer[3] <= 0)) {
__wrn("para invalid in disp ioctrl "
"DISP_CMD_GET_PALETTE_TBL,buffer:0x%x, "
"size:0x%x\n", (unsigned int) ubuffer[1],
(unsigned int) ubuffer[3]);
return -1;
}
ret =
BSP_disp_get_palette_table(ubuffer[0], (__u32 *) gbuffer,
ubuffer[2], ubuffer[3]);
if (copy_to_user((void __user *) ubuffer[1], gbuffer,
ubuffer[3])) {
__wrn("copy_to_user fail\n");
return -EFAULT;
}
break;
case DISP_CMD_START_CMD_CACHE:
ret = BSP_disp_cmd_cache(ubuffer[0]);
break;
case DISP_CMD_EXECUTE_CMD_AND_STOP_CACHE:
ret = BSP_disp_cmd_submit(ubuffer[0]);
break;
case DISP_CMD_GET_OUTPUT_TYPE:
ret = BSP_disp_get_output_type(ubuffer[0]);
break;
case DISP_CMD_SCN_GET_WIDTH:
ret = BSP_disp_get_screen_width(ubuffer[0]);
break;
case DISP_CMD_SCN_GET_HEIGHT:
ret = BSP_disp_get_screen_height(ubuffer[0]);
break;
case DISP_CMD_SET_GAMMA_TABLE:
if ((ubuffer[1] == 0) || ((int)ubuffer[2] <= 0)) {
__wrn("para invalid in disp ioctrl "
"DISP_CMD_SET_GAMMA_TABLE,buffer:0x%x, "
"size:0x%x\n", (unsigned int) ubuffer[1],
(unsigned int) ubuffer[2]);
return -1;
}
if (copy_from_user(gbuffer, (void __user *) ubuffer[1],
ubuffer[2])) {
__wrn("copy_from_user fail\n");
return -EFAULT;
}
ret = BSP_disp_set_gamma_table(ubuffer[0], (__u32 *) gbuffer,
ubuffer[2]);
break;
case DISP_CMD_GAMMA_CORRECTION_ON:
ret = BSP_disp_gamma_correction_enable(ubuffer[0]);
break;
case DISP_CMD_GAMMA_CORRECTION_OFF:
ret = BSP_disp_gamma_correction_disable(ubuffer[0]);
break;
case DISP_CMD_SET_BRIGHT:
ret = BSP_disp_set_bright(ubuffer[0], ubuffer[1]);
break;
case DISP_CMD_GET_BRIGHT:
ret = BSP_disp_get_bright(ubuffer[0]);
break;
case DISP_CMD_SET_CONTRAST:
ret = BSP_disp_set_contrast(ubuffer[0], ubuffer[1]);
break;
case DISP_CMD_GET_CONTRAST:
ret = BSP_disp_get_contrast(ubuffer[0]);
break;
case DISP_CMD_SET_SATURATION:
ret = BSP_disp_set_saturation(ubuffer[0], ubuffer[1]);
break;
case DISP_CMD_GET_SATURATION:
ret = BSP_disp_get_saturation(ubuffer[0]);
break;
case DISP_CMD_SET_HUE:
ret = BSP_disp_set_hue(ubuffer[0], ubuffer[1]);
break;
case DISP_CMD_GET_HUE:
ret = BSP_disp_get_hue(ubuffer[0]);
break;
#ifdef CONFIG_ARCH_SUN4I
case DISP_CMD_ENHANCE_ON:
ret = BSP_disp_enhance_enable(ubuffer[0], 1);
break;
case DISP_CMD_ENHANCE_OFF:
ret = BSP_disp_enhance_enable(ubuffer[0], 0);
break;
case DISP_CMD_GET_ENHANCE_EN:
ret = BSP_disp_get_enhance_enable(ubuffer[0]);
break;
#endif
case DISP_CMD_CAPTURE_SCREEN:
ret = BSP_disp_capture_screen(ubuffer[0],
(__disp_capture_screen_para_t *)
ubuffer[1]);
break;
case DISP_CMD_SET_SCREEN_SIZE:
ret = BSP_disp_set_screen_size(ubuffer[0],
(__disp_rectsz_t *) ubuffer[1]);
break;
/* ----iep---- */
case DISP_CMD_DE_FLICKER_ON:
#ifdef CONFIG_ARCH_SUN4I
ret = BSP_disp_de_flicker_enable(ubuffer[0], 1);
#else
ret = BSP_disp_iep_deflicker_enable(ubuffer[0], 1);
#endif
break;
case DISP_CMD_DE_FLICKER_OFF:
#ifdef CONFIG_ARCH_SUN4I
ret = BSP_disp_de_flicker_enable(ubuffer[0], 0);
#else
ret = BSP_disp_iep_deflicker_enable(ubuffer[0], 0);
#endif
break;
#ifdef CONFIG_ARCH_SUN5I
case DISP_CMD_GET_DE_FLICKER_EN:
ret = BSP_disp_iep_get_deflicker_enable(ubuffer[0]);
break;
case DISP_CMD_DRC_ON:
ret = BSP_disp_iep_drc_enable(ubuffer[0], 1);
break;
case DISP_CMD_DRC_OFF:
ret = BSP_disp_iep_drc_enable(ubuffer[0], 0);
break;
case DISP_CMD_GET_DRC_EN:
ret = BSP_disp_iep_get_drc_enable(ubuffer[0]);
break;
case DISP_CMD_DE_FLICKER_SET_WINDOW:
{
__disp_rect_t para;
if (copy_from_user(¶, (void __user *)ubuffer[1],
sizeof(__disp_rect_t))) {
__wrn("copy_from_user fail\n");
return -EFAULT;
}
ret = BSP_disp_iep_set_demo_win(ubuffer[0], 1, ¶);
break;
}
case DISP_CMD_DRC_SET_WINDOW:
{
__disp_rect_t para;
if (copy_from_user(¶, (void __user *)ubuffer[1],
sizeof(__disp_rect_t))) {
__wrn("copy_from_user fail\n");
return -EFAULT;
}
ret = BSP_disp_iep_set_demo_win(ubuffer[0], 2, ¶);
break;
}
#endif
/* ----layer---- */
case DISP_CMD_LAYER_REQUEST:
ret = BSP_disp_layer_request(ubuffer[0],
(__disp_layer_work_mode_t)
ubuffer[1]);
if (ret != DIS_NULL) {
int i;
__wrn("layer allocated: %lu,%i\n", ubuffer[0], ret);
for (i = 0; i < SUNXI_DISP_MAX_LAYERS ; i++)
if (! filp_data->layers[ubuffer[0]].layer[i]) {
filp_data->layers[ubuffer[0]].layer[i] = ret;
break;
}
BUG_ON (i == SUNXI_DISP_MAX_LAYERS);
}
break;
case DISP_CMD_LAYER_RELEASE:
ret = BSP_disp_layer_release(ubuffer[0], ubuffer[1]);
if (ret == DIS_SUCCESS) {
int i;
__wrn("layer released: %lu,%lu\n", ubuffer[0], ubuffer[1]);
for (i = 0; i < SUNXI_DISP_MAX_LAYERS ; i++)
if (filp_data->layers[ubuffer[0]].layer[i] == ubuffer[1]) {
filp_data->layers[ubuffer[0]].layer[i] = 0;
break;
}
if (i == SUNXI_DISP_MAX_LAYERS)
__wrn("released layer not allocated in this session: %lu,%lu\n", ubuffer[0], ubuffer[1]);
}
break;
case DISP_CMD_LAYER_OPEN:
ret = BSP_disp_layer_open(ubuffer[0], ubuffer[1]);
break;
case DISP_CMD_LAYER_CLOSE:
ret = BSP_disp_layer_close(ubuffer[0], ubuffer[1]);
break;
case DISP_CMD_LAYER_SET_FB:
{
__disp_fb_t para;
if (copy_from_user(¶, (void __user *)ubuffer[2],