-
Notifications
You must be signed in to change notification settings - Fork 22
/
cedar_ve.c
1772 lines (1526 loc) · 49.2 KB
/
cedar_ve.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\media\cedar_ve
* (C) Copyright 2010-2016
* Reuuimlla Technology Co., Ltd. <www.allwinnertech.com>
* fangning<[email protected]>
*
* some simple description for this code
*
* 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.
*
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/ioctl.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/list.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/preempt.h>
#include <linux/cdev.h>
#include <linux/platform_device.h>
#include <linux/interrupt.h>
#include <linux/clk.h>
#include <linux/rmap.h>
#include <linux/wait.h>
#include <linux/semaphore.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/version.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/dma.h>
#include <linux/mm.h>
#include <asm/siginfo.h>
#include <asm/signal.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
#include <linux/reset.h>
#include <linux/sched/signal.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
#else /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
#include <linux/clk/sunxi.h>
#endif /*LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)*/
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include "cedar_ve.h"
#include <linux/regulator/consumer.h>
struct regulator *regu;
#define DRV_VERSION "0.01alpha"
#undef USE_CEDAR_ENGINE
#ifndef CEDARDEV_MAJOR
#define CEDARDEV_MAJOR (150)
#endif
#ifndef CEDARDEV_MINOR
#define CEDARDEV_MINOR (0)
#endif
#define MACC_REGS_BASE (0x01C0E000) // Media ACCelerate
#ifndef CONFIG_OF
//H3: arch/arm/mach-sunxi/include/mach/sun8i/irqs-sun8iw7p1.h
//#define SUNXI_IRQ_VE (90)
#endif
//#define CEDAR_DEBUG
#define cedar_ve_printk(level, msg...) printk(level "cedar_ve: " msg)
#define VE_CLK_HIGH_WATER (700)//400MHz
#define VE_CLK_LOW_WATER (100) //160MHz
static int g_dev_major = CEDARDEV_MAJOR;
static int g_dev_minor = CEDARDEV_MINOR;
module_param(g_dev_major, int, S_IRUGO);//S_IRUGO represent that g_dev_major can be read,but canot be write
module_param(g_dev_minor, int, S_IRUGO);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
#define SYSCON_SRAM_CTRL_REG0 0x0
#define SYSCON_SRAM_C1_MAP_VE 0x7fffffff
#else /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
struct clk *ve_moduleclk = NULL;
struct clk *ve_parent_pll_clk = NULL;
struct clk *ve_power_gating = NULL;
static u32 ve_parent_clk_rate = 300000000;
#endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
struct iomap_para{
volatile char* regs_macc;
volatile char* regs_avs;
};
static DECLARE_WAIT_QUEUE_HEAD(wait_ve);
struct cedar_dev {
struct cdev cdev; /* char device struct */
struct platform_device *pdev;
struct device *dev;
struct device *odev; /* ptr to class device struct */
struct class *class; /* class for auto create device node */
struct semaphore sem; /* mutual exclusion semaphore */
wait_queue_head_t wq; /* wait queue for poll ops */
struct iomap_para iomap_addrs; /* io remap addrs */
struct timer_list cedar_engine_timer;
struct timer_list cedar_engine_timer_rel;
u32 irq; /* cedar video engine irq number */
u32 de_irq_flag; /* flag of video decoder engine irq generated */
u32 de_irq_value; /* value of video decoder engine irq */
u32 en_irq_flag; /* flag of video encoder engine irq generated */
u32 en_irq_value; /* value of video encoder engine irq */
u32 irq_has_enable;
u32 ref_count;
u32 jpeg_irq_flag; /* flag of video jpeg dec irq generated */
u32 jpeg_irq_value; /* value of video jpeg dec irq */
volatile u32* sram_bass_vir ;
volatile u32* clk_bass_vir;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
struct clk *mod_clk;
struct clk *ahb_clk;
struct clk *ram_clk;
struct reset_control *rstc;
struct regmap *syscon;
#endif /*LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)*/
};
struct ve_info {
u32 set_vol_flag;
};
struct cedar_dev *cedar_devp;
struct file *ve_file;
u32 int_sta=0,int_value;
/*
* Video engine interrupt service routine
* To wake up ve wait queue
*/
#if defined(CONFIG_OF)
static struct of_device_id sunxi_cedar_ve_match[] = {
{ .compatible = "allwinner,sunxi-cedar-ve", },
//{ .compatible = "allwinner,sun8i-h3-video-engine", },
{}
};
MODULE_DEVICE_TABLE(of, sunxi_cedar_ve_match);
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0) || ((defined CONFIG_ARCH_SUN8IW7P1) || (defined CONFIG_ARCH_SUN8IW8P1) || (defined CONFIG_ARCH_SUN8IW9P1))
#if defined(CONFIG_SUNXI_TRUSTZONE)
static inline u32 sunxi_smc_readl(void __iomem *addr)
{
if (sunxi_soc_is_secure()) {
return call_firmware_op(read_reg, addr);
} else {
return readl(addr);
}
}
static inline void sunxi_smc_writel(u32 val, void __iomem *addr)
{
if (sunxi_soc_is_secure()) {
call_firmware_op(write_reg, val, addr);
} else {
writel(val, addr);
}
}
#else
static inline u32 sunxi_smc_readl(void __iomem *addr)
{
return readl(addr);
}
static inline void sunxi_smc_writel(u32 val, void __iomem *addr)
{
writel(val, addr);
}
#endif
#endif /*((defined CONFIG_ARCH_SUN8IW7P1) || (defined CONFIG_ARCH_SUN8IW8P1) || (defined CONFIG_ARCH_SUN8IW9P1))*/
static irqreturn_t VideoEngineInterupt(int irq, void *dev)
{
ulong ve_int_status_reg;
ulong ve_int_ctrl_reg;
u32 status;
volatile int val;
int modual_sel;
u32 interrupt_enable;
struct iomap_para addrs = cedar_devp->iomap_addrs;
modual_sel = readl(addrs.regs_macc + 0);
if (modual_sel&(3<<6)) {
if (modual_sel&(1<<7)) {
/*avc enc*/
ve_int_status_reg = (ulong)(addrs.regs_macc + 0xb00 + 0x1c);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0xb00 + 0x14);
interrupt_enable = readl((void*)ve_int_ctrl_reg) &(0x7);
status = readl((void*)ve_int_status_reg);
status &= 0xf;
} else {
/*isp*/
ve_int_status_reg = (ulong)(addrs.regs_macc + 0xa00 + 0x10);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0xa00 + 0x08);
interrupt_enable = readl((void*)ve_int_ctrl_reg) &(0x1);
status = readl((void*)ve_int_status_reg);
status &= 0x1;
}
/*modify by fangning 2013-05-22*/
if (status && interrupt_enable) {
/*disable interrupt*/
/*avc enc*/
if (modual_sel&(1<<7)) {
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0xb00 + 0x14);
val = readl((void*)ve_int_ctrl_reg);
writel(val & (~0x7), (void*)ve_int_ctrl_reg);
} else {
/*isp*/
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0xa00 + 0x08);
val = readl((void*)ve_int_ctrl_reg);
writel(val & (~0x1), (void*)ve_int_ctrl_reg);
}
/*hx modify 2011-8-1 16:08:47*/
cedar_devp->en_irq_value = 1;
cedar_devp->en_irq_flag = 1;
/*any interrupt will wake up wait queue*/
wake_up_interruptible(&wait_ve);
}
}
#if ((defined CONFIG_ARCH_SUN8IW8P1) || (defined CONFIG_ARCH_SUN50I))
if (modual_sel&(0x20)) {
ve_int_status_reg = (ulong)(addrs.regs_macc + 0xe00 + 0x1c);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0xe00 + 0x14);
interrupt_enable = readl((void*)ve_int_ctrl_reg) & (0x38);
status = readl((void*)ve_int_status_reg);
if ((status&0x7) && interrupt_enable) {
/*disable interrupt*/
val = readl((void*)ve_int_ctrl_reg);
writel(val & (~0x38), (void*)ve_int_ctrl_reg);
cedar_devp->jpeg_irq_value = 1;
cedar_devp->jpeg_irq_flag = 1;
/*any interrupt will wake up wait queue*/
wake_up_interruptible(&wait_ve);
}
}
#endif
modual_sel &= 0xf;
if (modual_sel <= 4) {
/*estimate Which video format*/
switch (modual_sel)
{
case 0: /*mpeg124*/
ve_int_status_reg = (ulong)
(addrs.regs_macc + 0x100 + 0x1c);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0x100 + 0x14);
interrupt_enable = readl((void*)ve_int_ctrl_reg) & (0x7c);
break;
case 1: /*h264*/
ve_int_status_reg = (ulong)
(addrs.regs_macc + 0x200 + 0x28);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0x200 + 0x20);
interrupt_enable = readl((void*)ve_int_ctrl_reg) & (0xf);
break;
case 2: /*vc1*/
ve_int_status_reg = (ulong)(addrs.regs_macc +
0x300 + 0x2c);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0x300 + 0x24);
interrupt_enable = readl((void*)ve_int_ctrl_reg) & (0xf);
break;
case 3: /*rmvb*/
ve_int_status_reg = (ulong)
(addrs.regs_macc + 0x400 + 0x1c);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0x400 + 0x14);
interrupt_enable = readl((void*)ve_int_ctrl_reg) & (0xf);
break;
case 4: /*hevc*/
ve_int_status_reg = (ulong)
(addrs.regs_macc + 0x500 + 0x38);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0x500 + 0x30);
interrupt_enable = readl((void*)ve_int_ctrl_reg) & (0xf);
break;
default:
ve_int_status_reg = (ulong)(addrs.regs_macc + 0x100 + 0x1c);
ve_int_ctrl_reg = (ulong)(addrs.regs_macc + 0x100 + 0x14);
interrupt_enable = readl((void*)ve_int_ctrl_reg) & (0xf);
cedar_ve_printk(KERN_WARNING, "ve mode :%x "
"not defined!\n", modual_sel);
break;
}
status = readl((void*)ve_int_status_reg);
/*modify by fangning 2013-05-22*/
if ((status&0xf) && interrupt_enable) {
/*disable interrupt*/
if (modual_sel == 0) {
val = readl((void*)ve_int_ctrl_reg);
writel(val & (~0x7c), (void*)ve_int_ctrl_reg);
} else {
val = readl((void*)ve_int_ctrl_reg);
writel(val & (~0xf), (void*)ve_int_ctrl_reg);
}
cedar_devp->de_irq_value = 1;
cedar_devp->de_irq_flag = 1;
/*any interrupt will wake up wait queue*/
wake_up_interruptible(&wait_ve);
}
}
return IRQ_HANDLED;
}
static int clk_status = 0;
static LIST_HEAD(run_task_list);
static LIST_HEAD(del_task_list);
static spinlock_t cedar_spin_lock;
#define CEDAR_RUN_LIST_NONULL -1
#define CEDAR_NONBLOCK_TASK 0
#define CEDAR_BLOCK_TASK 1
#define CLK_REL_TIME 10000
#define TIMER_CIRCLE 50
#define TASK_INIT 0x00
#define TASK_TIMEOUT 0x55
#define TASK_RELEASE 0xaa
#define SIG_CEDAR 35
static int enable_cedar_hw_clk(void)
{
ulong flags;
int res = -EFAULT;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (clk_status == 1)
goto out;
clk_status = 1;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
reset_control_deassert(cedar_devp->rstc);
if (clk_enable(cedar_devp->mod_clk)) { cedar_ve_printk(KERN_WARNING, "try to enable ve_moduleclk failed! (%d=\n", __LINE__); goto out; }
res = 0;
#else /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
sunxi_periph_reset_deassert(ve_moduleclk);
if (clk_enable(ve_moduleclk)) {
cedar_ve_printk(KERN_WARNING, "enable ve_moduleclk failed;\n");
goto out;
}else {
res = 0;
}
#endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
#ifdef CEDAR_DEBUG
printk("%s,%d\n",__func__,__LINE__);
#endif
out:
spin_unlock_irqrestore(&cedar_spin_lock, flags);
return res;
}
int disable_cedar_hw_clk(void)
{
ulong flags;
int res = -EFAULT;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (clk_status == 0) {
res = 0;
goto out;
}
clk_status = 0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
if ((NULL == cedar_devp->mod_clk)||(IS_ERR(cedar_devp->mod_clk))) {
cedar_ve_printk(KERN_WARNING, "ve_moduleclk is invalid\n");
} else {
clk_disable(cedar_devp->mod_clk);
reset_control_assert(cedar_devp->rstc);
res = 0;
}
#else /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
if ((NULL == ve_moduleclk)||(IS_ERR(ve_moduleclk))) {
cedar_ve_printk(KERN_WARNING, "ve_moduleclk is invalid\n");
} else {
clk_disable(ve_moduleclk);
sunxi_periph_reset_assert(ve_moduleclk);
res = 0;
}
#endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
#ifdef CEDAR_DEBUG
printk("%s,%d\n",__func__,__LINE__);
#endif
out:
spin_unlock_irqrestore(&cedar_spin_lock, flags);
return res;
}
void cedardev_insert_task(struct cedarv_engine_task* new_task)
{
struct cedarv_engine_task *task_entry;
ulong flags;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (list_empty(&run_task_list))
new_task->is_first_task = 1;
list_for_each_entry(task_entry, &run_task_list, list) {
if ((task_entry->is_first_task == 0) && (task_entry->running == 0) && (task_entry->t.task_prio < new_task->t.task_prio)) {
break;
}
}
list_add(&new_task->list, task_entry->list.prev);
#ifdef CEDAR_DEBUG
printk("%s,%d, TASK_ID:",__func__,__LINE__);
list_for_each_entry(task_entry, &run_task_list, list) {
printk("%d!", task_entry->t.ID);
}
printk("\n");
#endif
mod_timer(&cedar_devp->cedar_engine_timer, jiffies + 0);
spin_unlock_irqrestore(&cedar_spin_lock, flags);
}
int cedardev_del_task(int task_id)
{
struct cedarv_engine_task *task_entry;
ulong flags;
spin_lock_irqsave(&cedar_spin_lock, flags);
list_for_each_entry(task_entry, &run_task_list, list) {
if (task_entry->t.ID == task_id && task_entry->status != TASK_RELEASE) {
task_entry->status = TASK_RELEASE;
spin_unlock_irqrestore(&cedar_spin_lock, flags);
mod_timer(&cedar_devp->cedar_engine_timer, jiffies + 0);
return 0;
}
}
spin_unlock_irqrestore(&cedar_spin_lock, flags);
return -1;
}
int cedardev_check_delay(int check_prio)
{
struct cedarv_engine_task *task_entry;
int timeout_total = 0;
ulong flags;
spin_lock_irqsave(&cedar_spin_lock, flags);
list_for_each_entry(task_entry, &run_task_list, list) {
if ((task_entry->t.task_prio >= check_prio) || (task_entry->running == 1) || (task_entry->is_first_task == 1))
timeout_total = timeout_total + task_entry->t.frametime;
}
spin_unlock_irqrestore(&cedar_spin_lock, flags);
#ifdef CEDAR_DEBUG
printk("%s,%d,%d\n", __func__, __LINE__, timeout_total);
#endif
return timeout_total;
}
static void cedar_engine_for_timer_rel(unsigned long arg)
{
ulong flags;
int ret = 0;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (list_empty(&run_task_list)) {
ret = disable_cedar_hw_clk();
if (ret < 0) {
cedar_ve_printk(KERN_WARNING, "clk disable error!\n");
}
} else {
cedar_ve_printk(KERN_WARNING, "clk disable time out "
"but task left\n");
mod_timer( &cedar_devp->cedar_engine_timer, jiffies + msecs_to_jiffies(TIMER_CIRCLE));
}
spin_unlock_irqrestore(&cedar_spin_lock, flags);
}
static void cedar_engine_for_events(unsigned long arg)
{
struct cedarv_engine_task *task_entry, *task_entry_tmp;
struct siginfo info;
ulong flags;
spin_lock_irqsave(&cedar_spin_lock, flags);
list_for_each_entry_safe(task_entry, task_entry_tmp, &run_task_list, list) {
mod_timer(&cedar_devp->cedar_engine_timer_rel, jiffies + msecs_to_jiffies(CLK_REL_TIME));
if (task_entry->status == TASK_RELEASE ||
time_after(jiffies, task_entry->t.timeout)) {
if (task_entry->status == TASK_INIT)
task_entry->status = TASK_TIMEOUT;
list_move(&task_entry->list, &del_task_list);
}
}
list_for_each_entry_safe(task_entry, task_entry_tmp, &del_task_list, list) {
info.si_signo = SIG_CEDAR;
info.si_code = task_entry->t.ID;
if (task_entry->status == TASK_TIMEOUT) {
info.si_errno = TASK_TIMEOUT;
send_sig_info(SIG_CEDAR, &info, task_entry->task_handle);
} else if (task_entry->status == TASK_RELEASE) {
info.si_errno = TASK_RELEASE;
send_sig_info(SIG_CEDAR, &info, task_entry->task_handle);
}
list_del(&task_entry->list);
kfree(task_entry);
}
if (!list_empty(&run_task_list)) {
task_entry = list_entry(run_task_list.next, struct cedarv_engine_task, list);
if (task_entry->running == 0) {
task_entry->running = 1;
info.si_signo = SIG_CEDAR;
info.si_code = task_entry->t.ID;
info.si_errno = TASK_INIT;
send_sig_info(SIG_CEDAR, &info, task_entry->task_handle);
}
mod_timer( &cedar_devp->cedar_engine_timer, jiffies + msecs_to_jiffies(TIMER_CIRCLE));
}
spin_unlock_irqrestore(&cedar_spin_lock, flags);
}
#ifdef CONFIG_COMPAT
static long compat_cedardev_ioctl(struct file *filp, u32 cmd, unsigned long arg)
{
int ret = 0;
int ve_timeout = 0;
/*struct cedar_dev *devp;*/
#ifdef USE_CEDAR_ENGINE
int rel_taskid = 0;
struct __cedarv_task task_ret;
struct cedarv_engine_task *task_ptr = NULL;
#endif
ulong flags;
struct ve_info *info;
info = filp->private_data;
switch (cmd)
{
case IOCTL_ENGINE_REQ:
#ifdef USE_CEDAR_ENGINE
if (copy_from_user(&task_ret, (void __user *)arg,
sizeof(struct __cedarv_task))) {
cedar_ve_printk(KERN_WARNING, "USE_CEDAR_ENGINE "
"copy_from_user fail\n");
return -EFAULT;
}
spin_lock_irqsave(&cedar_spin_lock, flags);
if (!list_empty(&run_task_list) &&
(task_ret.block_mode == CEDAR_NONBLOCK_TASK)) {
spin_unlock_irqrestore(&cedar_spin_lock, flags);
return CEDAR_RUN_LIST_NONULL;
}
spin_unlock_irqrestore(&cedar_spin_lock, flags);
task_ptr = kmalloc(sizeof(struct cedarv_engine_task), GFP_KERNEL);
if (!task_ptr) {
cedar_ve_printk(KERN_WARNING, "get "
"task_ptr error\n");
return PTR_ERR(task_ptr);
}
task_ptr->task_handle = current;
task_ptr->t.ID = task_ret.ID;
/*ms to jiffies*/
task_ptr->t.timeout = jiffies +
msecs_to_jiffies(1000*task_ret.timeout);
task_ptr->t.frametime = task_ret.frametime;
task_ptr->t.task_prio = task_ret.task_prio;
task_ptr->running = 0;
task_ptr->is_first_task = 0;
task_ptr->status = TASK_INIT;
cedardev_insert_task(task_ptr);
ret = enable_cedar_hw_clk();
if (ret < 0) {
cedar_ve_printk(KERN_WARNING, "IOCTL_ENGINE_REQ "
"clk enable error!\n");
return -EFAULT;
}
return task_ptr->is_first_task;
#else
cedar_devp->ref_count++;
if (1 == cedar_devp->ref_count)
enable_cedar_hw_clk();
break;
#endif
case IOCTL_ENGINE_REL:
#ifdef USE_CEDAR_ENGINE
rel_taskid = (int)arg;
ret = cedardev_del_task(rel_taskid);
#else
cedar_devp->ref_count--;
if (0 == cedar_devp->ref_count) {
ret = disable_cedar_hw_clk();
if (ret < 0) {
cedar_ve_printk(KERN_WARNING, "IOCTL_ENGINE_REL "
"clk disable error!\n");
return -EFAULT;
}
}
#endif
return ret;
case IOCTL_ENGINE_CHECK_DELAY:
{
struct cedarv_engine_task_info task_info;
if (copy_from_user(&task_info, (void __user *)arg,
sizeof(struct cedarv_engine_task_info))) {
cedar_ve_printk(KERN_WARNING, "%d "
"copy_from_user fail\n",
IOCTL_ENGINE_CHECK_DELAY);
return -EFAULT;
}
task_info.total_time = cedardev_check_delay(task_info.task_prio);
#ifdef CEDAR_DEBUG
printk("%s,%d,%d\n", __func__, __LINE__, task_info.total_time);
#endif
task_info.frametime = 0;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (!list_empty(&run_task_list)) {
struct cedarv_engine_task *task_entry;
#ifdef CEDAR_DEBUG
printk("%s,%d\n",__func__,__LINE__);
#endif
task_entry = list_entry(run_task_list.next, struct cedarv_engine_task, list);
if (task_entry->running == 1)
task_info.frametime = task_entry->t.frametime;
#ifdef CEDAR_DEBUG
printk("%s,%d,%d\n",__func__,__LINE__,task_info.frametime);
#endif
}
spin_unlock_irqrestore(&cedar_spin_lock, flags);
if (copy_to_user((void *)arg, &task_info, sizeof(struct cedarv_engine_task_info))){
cedar_ve_printk(KERN_WARNING, "%d "
"copy_to_user fail\n",
IOCTL_ENGINE_CHECK_DELAY);
return -EFAULT;
}
}
break;
case IOCTL_WAIT_VE_DE:
ve_timeout = (int)arg;
cedar_devp->de_irq_value = 0;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (cedar_devp->de_irq_flag)
cedar_devp->de_irq_value = 1;
spin_unlock_irqrestore(&cedar_spin_lock, flags);
wait_event_interruptible_timeout(wait_ve, cedar_devp->de_irq_flag, ve_timeout*HZ);
cedar_devp->de_irq_flag = 0;
return cedar_devp->de_irq_value;
case IOCTL_WAIT_VE_EN:
ve_timeout = (int)arg;
cedar_devp->en_irq_value = 0;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (cedar_devp->en_irq_flag)
cedar_devp->en_irq_value = 1;
spin_unlock_irqrestore(&cedar_spin_lock, flags);
wait_event_interruptible_timeout(wait_ve, cedar_devp->en_irq_flag, ve_timeout*HZ);
cedar_devp->en_irq_flag = 0;
return cedar_devp->en_irq_value;
#if ((defined CONFIG_ARCH_SUN8IW8P1) || (defined CONFIG_ARCH_SUN50I))
case IOCTL_WAIT_JPEG_DEC:
ve_timeout = (int)arg;
cedar_devp->jpeg_irq_value = 0;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (cedar_devp->jpeg_irq_flag)
cedar_devp->jpeg_irq_value = 1;
spin_unlock_irqrestore(&cedar_spin_lock, flags);
wait_event_interruptible_timeout(wait_ve, cedar_devp->jpeg_irq_flag, ve_timeout*HZ);
cedar_devp->jpeg_irq_flag = 0;
return cedar_devp->jpeg_irq_value;
#endif
case IOCTL_ENABLE_VE:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
if (clk_prepare_enable(cedar_devp->mod_clk)) {
cedar_ve_printk(KERN_WARNING, "IOCTL_ENABLE_VE enable ve_moduleclk failed! (%d)\n", __LINE__);
}
#else /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
if (clk_prepare_enable(ve_moduleclk)) {
cedar_ve_printk(KERN_WARNING, "IOCTL_ENABLE_VE "
"enable ve_moduleclk failed!\n");
}
#endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
break;
case IOCTL_DISABLE_VE:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
if ((NULL == cedar_devp->mod_clk)||IS_ERR(cedar_devp->mod_clk)) {
cedar_ve_printk(KERN_WARNING, "IOCTL_DISABLE_VE ve_moduleclk is invalid (%d)\n", __LINE__);
return -EFAULT;
} else {
clk_disable_unprepare(cedar_devp->mod_clk);
}
#else /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
if ((NULL == ve_moduleclk)||IS_ERR(ve_moduleclk)) {
cedar_ve_printk(KERN_WARNING, "IOCTL_DISABLE_VE "
"ve_moduleclk is invalid\n");
return -EFAULT;
} else {
clk_disable_unprepare(ve_moduleclk);
}
#endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
break;
case IOCTL_RESET_VE:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
reset_control_assert(cedar_devp->rstc);
reset_control_deassert(cedar_devp->rstc);
#else /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
sunxi_periph_reset_assert(ve_moduleclk);
sunxi_periph_reset_deassert(ve_moduleclk);
#endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
break;
case IOCTL_SET_VE_FREQ:
{
int arg_rate = (int)arg;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
struct clk *const ve_moduleclk=cedar_devp->mod_clk;
struct clk *const ve_parent_pll_clk=cedar_devp->ahb_clk;
u32 ve_parent_clk_rate;
#endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)*/
#if 0
int v_div = 0;
v_div = (ve_parent_clk_rate/1000000 + (arg_rate-1))/arg_rate;
if (v_div <= 8 && v_div >= 1) {
if (clk_set_rate(ve_moduleclk, ve_parent_clk_rate/v_div)) {
/*
* while set the rate fail, don't return the fail value,
* we can still set the other rate of ve module clk.
*/
printk("try to set ve_rate fail\n");
}
}
#else
if (arg_rate >= VE_CLK_LOW_WATER &&
arg_rate <= VE_CLK_HIGH_WATER &&
clk_get_rate(ve_moduleclk)/1000000 != arg_rate) {
if (!clk_set_rate(ve_parent_pll_clk, arg_rate*1000000)) {
ve_parent_clk_rate = clk_get_rate(ve_parent_pll_clk);
if (clk_set_rate(ve_moduleclk, ve_parent_clk_rate)) {
cedar_ve_printk(KERN_WARNING, "set ve clock failed\n");
}
} else {
cedar_ve_printk(KERN_WARNING, "set pll4 clock failed\n");
}
}
ret = clk_get_rate(ve_moduleclk);
#endif
break;
}
case IOCTL_GETVALUE_AVS2:
case IOCTL_ADJUST_AVS2:
case IOCTL_ADJUST_AVS2_ABS:
case IOCTL_CONFIG_AVS2:
case IOCTL_RESET_AVS2:
case IOCTL_PAUSE_AVS2:
case IOCTL_START_AVS2:
cedar_ve_printk(KERN_WARNING, "do not supprot this ioctrl now\n");
break;
case IOCTL_GET_ENV_INFO:
{
struct cedarv_env_infomation_compat env_info;
env_info.phymem_start = 0; // do not use this interface ,ve get phy mem form ion now
env_info.phymem_total_size = 0;//ve_size = 0x04000000
env_info.address_macc = 0;
if (copy_to_user((char *)arg, &env_info,
sizeof(struct cedarv_env_infomation_compat)))
return -EFAULT;
}
break;
case IOCTL_GET_IC_VER:
{
return 0;
}
case IOCTL_SET_REFCOUNT:
cedar_devp->ref_count = (int)arg;
break;
case IOCTL_SET_VOL:
{
#if defined CONFIG_ARCH_SUN9IW1P1
int ret;
int vol = (int)arg;
if (down_interruptible(&cedar_devp->sem)) {
return -ERESTARTSYS;
}
info->set_vol_flag = 1;
//set output voltage to arg mV
ret = regulator_set_voltage(regu,vol*1000,3300000);
if (IS_ERR(regu)) {
cedar_ve_printk(KERN_WARNING, \
"fail to set axp15_dcdc4 regulator voltage!\n");
}
up(&cedar_devp->sem);
#endif
break;
}
default:
return -1;
}
return ret;
}
#endif /* CONFIG_COMPAT */
/*
* ioctl function
* including : wait video engine done,
* AVS Counter control,
* Physical memory control,
* module clock/freq control.
* cedar engine
*/
static long cedardev_ioctl(struct file *filp, u32 cmd, unsigned long arg)
{
int ret = 0;
int ve_timeout = 0;
//struct cedar_dev *devp;
#ifdef USE_CEDAR_ENGINE
int rel_taskid = 0;
struct __cedarv_task task_ret;
struct cedarv_engine_task *task_ptr = NULL;
#endif
ulong flags;
struct ve_info *info;
info = filp->private_data;
switch (cmd)
{
case IOCTL_ENGINE_REQ:
#ifdef USE_CEDAR_ENGINE
if (copy_from_user(&task_ret, (void __user *)arg, sizeof(struct __cedarv_task))) {
cedar_ve_printk(KERN_WARNING, \
"IOCTL_ENGINE_REQ copy_from_user fail\n");
return -EFAULT;
}
spin_lock_irqsave(&cedar_spin_lock, flags);
if (!list_empty(&run_task_list) && (task_ret.block_mode == CEDAR_NONBLOCK_TASK)) {
spin_unlock_irqrestore(&cedar_spin_lock, flags);
return CEDAR_RUN_LIST_NONULL;
}
spin_unlock_irqrestore(&cedar_spin_lock, flags);
task_ptr = kmalloc(sizeof(struct cedarv_engine_task), GFP_KERNEL);
if (!task_ptr) {
cedar_ve_printk(KERN_WARNING, "get mem for IOCTL_ENGINE_REQ\n");
return PTR_ERR(task_ptr);
}
task_ptr->task_handle = current;
task_ptr->t.ID = task_ret.ID;
task_ptr->t.timeout = jiffies + msecs_to_jiffies(1000*task_ret.timeout);//ms to jiffies
task_ptr->t.frametime = task_ret.frametime;
task_ptr->t.task_prio = task_ret.task_prio;
task_ptr->running = 0;
task_ptr->is_first_task = 0;
task_ptr->status = TASK_INIT;
cedardev_insert_task(task_ptr);
ret = enable_cedar_hw_clk();
if (ret < 0) {
cedar_ve_printk(KERN_WARNING, \
"cedar clk enable somewhere error!\n");
return -EFAULT;
}
return task_ptr->is_first_task;
#else
cedar_devp->ref_count++;
if (1 == cedar_devp->ref_count)
enable_cedar_hw_clk();
break;
#endif
case IOCTL_ENGINE_REL:
#ifdef USE_CEDAR_ENGINE
rel_taskid = (int)arg;
ret = cedardev_del_task(rel_taskid);
#else
cedar_devp->ref_count--;
if (0 == cedar_devp->ref_count) {
ret = disable_cedar_hw_clk();
if (ret < 0) {
cedar_ve_printk(KERN_WARNING, "IOCTL_ENGINE_REL "
"clk disable error!\n");
return -EFAULT;
}
}
#endif
return ret;
case IOCTL_ENGINE_CHECK_DELAY:
{
struct cedarv_engine_task_info task_info;
if (copy_from_user(&task_info,
(void __user *)arg,
sizeof(struct cedarv_engine_task_info))) {
cedar_ve_printk(KERN_WARNING, \
"IOCTL_ENGINE_CHECK_DELAY copy_from_user fail\n");
return -EFAULT;
}
task_info.total_time = cedardev_check_delay(task_info.task_prio);
#ifdef CEDAR_DEBUG
printk("%s,%d,%d\n", __func__, __LINE__, task_info.total_time);
#endif
task_info.frametime = 0;
spin_lock_irqsave(&cedar_spin_lock, flags);
if (!list_empty(&run_task_list)) {
struct cedarv_engine_task *task_entry;
#ifdef CEDAR_DEBUG
printk("%s,%d\n",__func__,__LINE__);
#endif
task_entry = list_entry(run_task_list.next, struct cedarv_engine_task, list);
if (task_entry->running == 1)
task_info.frametime = task_entry->t.frametime;
#ifdef CEDAR_DEBUG
printk("%s,%d,%d\n",__func__,__LINE__,task_info.frametime);
#endif
}
spin_unlock_irqrestore(&cedar_spin_lock, flags);
if (copy_to_user((void *)arg, &task_info, sizeof(struct cedarv_engine_task_info))){
cedar_ve_printk(KERN_WARNING, \
"IOCTL_ENGINE_CHECK_DELAY copy_to_user fail\n");
return -EFAULT;