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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
|
#ifndef CONFIG_ARCH_MT6735M
#define JPEG_DEC_DRIVER
#endif
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/mm_types.h>
#include <linux/module.h>
#include <generated/autoconf.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/cdev.h>
#include <linux/kdev_t.h>
#include <linux/delay.h>
#include <linux/ioport.h>
#include <linux/platform_device.h>
#include <linux/dma-mapping.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/wait.h>
#include <linux/spinlock.h>
#include <linux/param.h>
#include <linux/uaccess.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/xlog.h>
#include <asm/io.h>
#include <cmdq_core.h>
#include "jpeg_cmdq.h"
//============================================================
//#include <linux/uaccess.h>
//#include <linux/module.h>
//#include <linux/fs.h>
//#include <linux/platform_device.h>
//#include <linux/cdev.h>
#include <linux/interrupt.h>
//#include <asm/io.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/spinlock.h>
#include <linux/delay.h>
#include <linux/earlysuspend.h>
//#include <linux/mm.h>
#include <linux/vmalloc.h>
#include <linux/dma-mapping.h>
//#include <linux/slab.h>
//#include <linux/gfp.h>
#include <linux/aee.h>
#include <linux/timer.h>
#include <linux/disp_assert_layer.h>
//#include <linux/xlog.h>
//#include <linux/fs.h>
//Arch dependent files
//#include <asm/mach/map.h>
//#include <mach/mt6577_pll.h>
#include <mach/mt_irq.h>
#include <mach/mt_clkmgr.h>
#include <mach/irqs.h>
// #include <asm/tcm.h>
#include <asm/cacheflush.h>
//#include <asm/system.h>
//#include <linux/mm.h>
#include <linux/pagemap.h>
#ifndef FPGA_VERSION
#include <mach/mt_boot.h>
#endif
#include <cmdq_record.h>
#ifndef JPEG_DEV
#include <linux/proc_fs.h>
#endif
#ifdef CONFIG_OF
/* device tree */
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include <linux/io.h>
#endif
//==========================================================
#include "jpeg_drv.h"
#include "jpeg_drv_6589_common.h"
//#define USE_SYSRAM
#define JPEG_MSG printk
#define JPEG_WRN printk
#define JPEG_ERR printk
#define JPEG_DEVNAME "mtk_jpeg"
#define TABLE_SIZE 4096
#define JPEG_DEC_PROCESS 0x1
#define JPEG_ENC_PROCESS 0x2
//#define FPGA_VERSION
#include "jpeg_drv_6589_reg.h"
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
// global function
extern kal_uint32 _jpeg_enc_int_status;
extern kal_uint32 _jpeg_dec_int_status;
extern kal_uint32 _jpeg_dec_mode ;
#ifdef JPEG_DEV
// device and driver
static dev_t jpeg_devno;
static struct cdev *jpeg_cdev;
static struct class *jpeg_class = NULL;
#endif
#ifdef CONFIG_OF
static struct JpegDeviceStruct gJpegqDev;
static struct JpegDeviceStruct *gJpegqDevs;
static int nrJpegDevs = 0;
static const struct of_device_id jpeg_of_ids[] = {
{ .compatible = "mediatek,JPGENC", },
{}
};
#endif
// decoder
#ifdef JPEG_DEC_DRIVER
static wait_queue_head_t dec_wait_queue;
#endif
static spinlock_t jpeg_dec_lock;
static int dec_status = 0;
// encoder
static wait_queue_head_t enc_wait_queue;
static spinlock_t jpeg_enc_lock;
static int enc_status = 0;
//==========================================
//CMDQ
//static cmdqRecStruct jpegCMDQ_handle;
#ifdef JPEG_DEC_DRIVER
static cmdqRecHandle jpegCMDQ_handle;
#endif
//--------------------------------------------------------------------------
// JPEG Common Function
//--------------------------------------------------------------------------
void jpeg_reg_dump(void);
#ifdef FPGA_VERSION
void jpeg_drv_dec_power_on(void)
{
JPEG_MSG("JPEG Decoder Power On\n");
}
void jpeg_drv_dec_power_off(void)
{
JPEG_MSG("JPEG Decoder Power Off\n");
}
void jpeg_drv_enc_power_on(void)
{
#ifdef FPGA_VERSION
IMG_REG_WRITE( (0), JPEG_EARLY_MM_BASE);
JPEG_MSG("JPEG Encoder RESET_MM_BASE!!\n");
#endif
JPEG_MSG("JPEG Encoder Power On\n");
}
void jpeg_drv_enc_power_off(void)
{
JPEG_MSG("JPEG Encoder Power Off\n");
}
#else
static irqreturn_t jpeg_drv_enc_isr(int irq, void *dev_id)
{
//JPEG_MSG("JPEG Encoder Interrupt\n");
if(irq == gJpegqDev.encIrqId)
{
//mt65xx_irq_mask(MT6575_JPEG_CODEC_IRQ_ID);
#if 0
if(jpeg_isr_dec_lisr() == 0)
{
wake_up_interruptible(&dec_wait_queue);
}
#endif
if(jpeg_isr_enc_lisr() == 0)
{
wake_up_interruptible(&enc_wait_queue);
}
//mt65xx_irq_unmask(MT6575_JPEG_CODEC_IRQ_ID);
}
return IRQ_HANDLED;
}
#ifdef JPEG_DEC_DRIVER
static irqreturn_t jpeg_drv_dec_isr(int irq, void *dev_id)
{
//JPEG_MSG("JPEG Decoder Interrupt\n");
//jpeg_reg_dump();
if(irq == gJpegqDev.decIrqId)
{
//mt65xx_irq_mask(MT6575_JPEG_CODEC_IRQ_ID);
if(jpeg_isr_dec_lisr() == 0)
{
wake_up_interruptible(&dec_wait_queue);
}
#if 0
if(jpeg_isr_enc_lisr() == 0)
{
wake_up_interruptible(&enc_wait_queue);
}
#endif
//mt65xx_irq_unmask(MT6575_JPEG_CODEC_IRQ_ID);
}
return IRQ_HANDLED;
}
void jpeg_drv_dec_power_on(void)
{
//REG_JPEG_MM_REG_MASK = 0;
#ifndef FPGA_VERSION
#ifndef CONFIG_FPGA_EARLY_PORTING
enable_clock(MT_CG_DISP0_SMI_COMMON,"JPEG");
enable_clock(MT_CG_VENC_LARB,"JPEG");
enable_clock(MT_CG_VENC_JPGDEC,"JPEG");
#endif
#endif
#if 0
//MCI
*(volatile kal_uint32 *)(0xF0208100) |= (0x4|0x8|0x10);
dsb();
*(volatile kal_uint32 *)(0xF0208100) |= (0x11);
dsb();
#endif
#ifdef FOR_COMPILE
BOOL ret;
ret = enable_clock(MT65XX_PDN_MM_JPEG_DEC,"JPEG");
NOT_REFERENCED(ret);
#endif
}
void jpeg_drv_dec_power_off(void)
{
#ifndef FPGA_VERSION
#ifndef CONFIG_FPGA_EARLY_PORTING
disable_clock(MT_CG_VENC_JPGDEC,"JPEG");
disable_clock(MT_CG_VENC_LARB,"JPEG");
disable_clock(MT_CG_DISP0_SMI_COMMON,"JPEG");
#endif
#endif
#ifdef FOR_COMPILE
BOOL ret;
ret = disable_clock(MT65XX_PDN_MM_JPEG_DEC,"JPEG");
NOT_REFERENCED(ret);
#endif
}
#endif
void jpeg_drv_enc_power_on(void)
{
#ifndef FPGA_VERSION
#ifndef CONFIG_FPGA_EARLY_PORTING
//REG_JPEG_MM_REG_MASK = 0;
enable_clock(MT_CG_DISP0_SMI_COMMON,"JPEG");
#ifdef CONFIG_ARCH_MT6735M
enable_clock(MT_CG_IMAGE_JPGENC,"JPEG");
#else
enable_clock(MT_CG_VENC_LARB,"JPEG");
enable_clock(MT_CG_VENC_JPGENC,"JPEG");
#endif
#endif
#endif
#if 0
//MCI
*(volatile kal_uint32 *)(0xF0208100) |= (0x4|0x8|0x10);
dsb();
*(volatile kal_uint32 *)(0xF0208100) |= (0x11);
dsb();
#endif
#ifdef FOR_COMPILE
BOOL ret;
ret = enable_clock(MT65XX_PDN_MM_JPEG_ENC,"JPEG");
NOT_REFERENCED(ret);
#endif
}
void jpeg_drv_enc_power_off(void)
{
#ifndef FPGA_VERSION
#ifndef CONFIG_FPGA_EARLY_PORTING
#ifdef CONFIG_ARCH_MT6735M
disable_clock(MT_CG_IMAGE_JPGENC,"JPEG");
#else
disable_clock(MT_CG_VENC_JPGENC,"JPEG");
disable_clock(MT_CG_VENC_LARB,"JPEG");
#endif
disable_clock(MT_CG_DISP0_SMI_COMMON,"JPEG");
#endif
#endif
#ifdef FOR_COMPILE
BOOL ret;
ret = disable_clock(MT65XX_PDN_MM_JPEG_ENC,"JPEG");
NOT_REFERENCED(ret);
#endif
}
#endif
#ifdef JPEG_DEC_DRIVER
static int jpeg_drv_dec_init(void)
{
int retValue;
spin_lock(&jpeg_dec_lock);
if(dec_status != 0)
{
JPEG_WRN("JPEG Decoder is busy\n");
retValue = -EBUSY;
}
else
{
dec_status = 1;
retValue = 0;
}
spin_unlock(&jpeg_dec_lock);
if(retValue == 0)
{
jpeg_drv_dec_power_on();
jpeg_drv_dec_verify_state_and_reset();
}
return retValue;
}
static void jpeg_drv_dec_deinit(void)
{
if(dec_status != 0)
{
spin_lock(&jpeg_dec_lock);
dec_status = 0;
spin_unlock(&jpeg_dec_lock);
jpeg_drv_dec_reset();
jpeg_drv_dec_power_off();
}
}
#endif
static int jpeg_drv_enc_init(void)
{
int retValue;
spin_lock(&jpeg_enc_lock);
if(enc_status != 0)
{
JPEG_WRN("JPEG Encoder is busy\n");
retValue = -EBUSY;
}
else
{
enc_status = 1;
retValue = 0;
}
spin_unlock(&jpeg_enc_lock);
if(retValue == 0)
{
jpeg_drv_enc_power_on();
jpeg_drv_enc_verify_state_and_reset();
}
return retValue;
}
static void jpeg_drv_enc_deinit(void)
{
if(enc_status != 0)
{
spin_lock(&jpeg_enc_lock);
enc_status = 0;
spin_unlock(&jpeg_enc_lock);
jpeg_drv_enc_reset();
jpeg_drv_enc_power_off();
}
}
//--------------------------------------------------------------------------
// JPEG REG DUMP FUNCTION
//--------------------------------------------------------------------------
void jpeg_reg_dump(void)
{
unsigned int reg_value = 0;
unsigned int index = 0;
JPEG_WRN("JPEG REG:\n ********************\n");
for(index = 0 ; index < 0x168 ; index += 4){
//reg_value = ioread32(JPEG_DEC_BASE + index);
IMG_REG_READ(reg_value, JPEG_DEC_BASE + index);
JPEG_WRN("+0x%x 0x%x\n", index, reg_value);
}
}
//--------------------------------------------------------------------------
// JPEG DECODER IOCTRL FUNCTION
//--------------------------------------------------------------------------
#ifdef JPEG_DEC_DRIVER
static int jpeg_dec_ioctl(unsigned int cmd, unsigned long arg, struct file *file)
{
unsigned int* pStatus;
unsigned int decResult;
long timeout_jiff;
JPEG_DEC_DRV_IN dec_params;
JPEG_DEC_CONFIG_ROW dec_row_params ;
JPEG_DEC_CONFIG_CMDQ cfg_cmdq_params ;
unsigned int irq_st = 0;
unsigned int i = 0;
//unsigned int timeout = 0x1FFFFF;
JPEG_DEC_DRV_OUT outParams;
pStatus = (unsigned int*)file->private_data;
if (NULL == pStatus)
{
JPEG_MSG("[JPEGDRV]JPEG Decoder: Private data is null in flush operation. SOME THING WRONG??\n");
return -EFAULT;
}
switch(cmd)
{
// initial and reset JPEG encoder
case JPEG_DEC_IOCTL_INIT: /* OT:OK */
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Init!!\n");
if(jpeg_drv_dec_init() == 0)
{
*pStatus = JPEG_DEC_PROCESS;
}
break;
case JPEG_DEC_IOCTL_RESET: /* OT:OK */
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Reset!!\n");
jpeg_drv_dec_reset();
break;
case JPEG_DEC_IOCTL_CONFIG:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Configration!!\n");
if(*pStatus != JPEG_DEC_PROCESS)
{
JPEG_MSG("[JPEGDRV]Permission Denied! This process can not access decoder\n");
return -EFAULT;
}
if(dec_status == 0)
{
JPEG_MSG("[JPEGDRV]JPEG Decoder is unlocked!!");
*pStatus = 0;
return -EFAULT;
}
if(copy_from_user(&dec_params, (void *)arg, sizeof(JPEG_DEC_DRV_IN)))
{
JPEG_MSG("[JPEGDRV]JPEG Decoder : Copy from user error\n");
return -EFAULT;
}
//_jpeg_dec_dump_reg_en = dec_params.regDecDumpEn;
if(dec_params.decodeMode == JPEG_DEC_MODE_MCU_ROW)
_jpeg_dec_mode = 1;
else
_jpeg_dec_mode = 0;
if (jpeg_drv_dec_set_config_data(&dec_params) < 0)
return -EFAULT;
break;
case JPEG_DEC_IOCTL_FLUSH_CMDQ :
JPEG_MSG("[JPEGDRV]enter JPEG BUILD CMDQ !!\n");
if(*pStatus != JPEG_DEC_PROCESS)
{
JPEG_MSG("[JPEGDRV]Permission Denied! This process can not access decoder\n");
return -EFAULT;
}
if(dec_status == 0)
{
JPEG_MSG("[JPEGDRV]JPEG Decoder is unlocked!!");
*pStatus = 0;
return -EFAULT;
}
if(copy_from_user(&cfg_cmdq_params, (void *)arg, sizeof(JPEG_DEC_CONFIG_CMDQ)))
{
JPEG_MSG("[JPEGDRV]JPEG Decoder : Copy from user error\n");
return -EFAULT;
}
JPEG_MSG("[JPEGDRV]JPEG CREATE CMDQ !!\n");
cmdqRecCreate(CMDQ_SCENARIO_JPEG_DEC, &jpegCMDQ_handle) ;
cmdqRecWait(jpegCMDQ_handle, CMDQ_EVENT_JPEG_DEC_EOF) ;
for( i = 0 ; i < cfg_cmdq_params.goNum ; i++ ){
JPEG_MSG("[JPEGDRV]JPEG gen CMDQ %x %x %x %x !!\n", cfg_cmdq_params.pauseMCUidx[i],
cfg_cmdq_params.decRowBuf0[i], cfg_cmdq_params.decRowBuf1[i], cfg_cmdq_params.decRowBuf2[i]);
cmdqRecWrite(jpegCMDQ_handle, 0x18004170 /*REG_ADDR_JPGDEC_PAUSE_MCU_NUM*/, cfg_cmdq_params.pauseMCUidx[i]-1 , 0xFFFFFFFF) ;
cmdqRecWrite(jpegCMDQ_handle, 0x18004140 /*REG_ADDR_JPGDEC_DEST_ADDR0_Y */, cfg_cmdq_params.decRowBuf0[i] , 0xFFFFFFFF) ;
cmdqRecWrite(jpegCMDQ_handle, 0x18004144 /*REG_ADDR_JPGDEC_DEST_ADDR0_U */, cfg_cmdq_params.decRowBuf1[i] , 0xFFFFFFFF) ;
cmdqRecWrite(jpegCMDQ_handle, 0x18004148 /*REG_ADDR_JPGDEC_DEST_ADDR0_V */, cfg_cmdq_params.decRowBuf2[i] , 0xFFFFFFFF) ;
JPEG_MSG("[JPEGDRV]JPEG gen CMDQ go!!\n");
//trigger
cmdqRecWrite(jpegCMDQ_handle, 0x18004274 /*REG_ADDR_JPGDEC_INTERRUPT_STATUS*/ , BIT_INQST_MASK_PAUSE , 0xFFFFFFFF) ;
JPEG_MSG("[JPEGDRV]JPEG gen CMDQ wait!!\n");
//wait frame done
cmdqRecWait(jpegCMDQ_handle, CMDQ_EVENT_JPEG_DEC_EOF) ;
//cmdqRecPoll(jpegCMDQ_handle, 0x18004274 /*REG_ADDR_JPGDEC_INTERRUPT_STATUS*/ , BIT_INQST_MASK_PAUSE , 0x0010) ;
}
JPEG_MSG("[JPEGDRV]JPEG flush CMDQ start!!\n");
cmdqRecFlush(jpegCMDQ_handle) ;
JPEG_MSG("[JPEGDRV]JPEG flush CMDQ end!!\n");
cmdqRecDestroy(jpegCMDQ_handle) ;
JPEG_MSG("[JPEGDRV]JPEG destroy CMDQ end!!\n");
break;
case JPEG_DEC_IOCTL_RESUME:
if(*pStatus != JPEG_DEC_PROCESS)
{
JPEG_MSG("[JPEGDRV]Permission Denied! This process can not access decoder\n");
return -EFAULT;
}
if(dec_status == 0)
{
JPEG_MSG("[JPEGDRV]JPEG Decoder is unlocked!!");
*pStatus = 0;
return -EFAULT;
}
if(copy_from_user(&dec_row_params, (void *)arg, sizeof(JPEG_DEC_CONFIG_ROW)))
{
JPEG_MSG("[JPEGDRV]JPEG Decoder : Copy from user error\n");
return -EFAULT;
}
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Resume, [%d] %x %x %x !!\n", dec_row_params.pauseMCU -1,dec_row_params.decRowBuf[0], dec_row_params.decRowBuf[1], dec_row_params.decRowBuf[2]);
jpeg_drv_dec_set_dst_bank0( dec_row_params.decRowBuf[0], dec_row_params.decRowBuf[1], dec_row_params.decRowBuf[2]);
jpeg_drv_dec_set_pause_mcu_idx(dec_row_params.pauseMCU -1) ;
// lock CPU to ensure irq is enabled after trigger HW
spin_lock(&jpeg_dec_lock);
jpeg_drv_dec_resume(BIT_INQST_MASK_PAUSE);
spin_unlock(&jpeg_dec_lock);
break;
case JPEG_DEC_IOCTL_START: /* OT:OK */
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Start!!\n");
//Debug: printk("0xF0: 0x%08x\n", *(volatile unsigned int*)(JPEG_DEC_BASE + 0xF0));
jpeg_drv_dec_start();
break;
case JPEG_DEC_IOCTL_WAIT:
if(*pStatus != JPEG_DEC_PROCESS)
{
JPEG_WRN("Permission Denied! This process can not access decoder");
return -EFAULT;
}
if(dec_status == 0)
{
JPEG_WRN("Decoder status is available, HOW COULD THIS HAPPEN ??");
*pStatus = 0;
return -EFAULT;
}
if(copy_from_user(&outParams, (void *)arg, sizeof(JPEG_DEC_DRV_OUT)))
{
JPEG_WRN("JPEG Decoder : Copy from user error\n");
return -EFAULT;
}
//set timeout
timeout_jiff = outParams.timeout* HZ / 1000;
//JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Wait Resume Time Jiffies : %ld\n", timeout_jiff);
#ifdef FPGA_VERSION
//#if 1
JPEG_MSG("[JPEGDRV]Polling JPEG Status");
do
{
_jpeg_dec_int_status = REG_JPGDEC_INTERRUPT_STATUS;
} while(_jpeg_dec_int_status == 0);
#else
//if(outParams.timeout >= 5000){
//
// JPEG_MSG("Polling JPEG Status");
// do
// {
// _jpeg_dec_int_status = REG_JPGDEC_INTERRUPT_STATUS;
// timeout--;
// } while(_jpeg_dec_int_status == 0 && timeout != 0);
// if(timeout == 0) JPEG_MSG("Polling JPEG Status TIMEOUT!!\n");
//}else
if(jpeg_isr_dec_lisr()<0){
//JPEG_MSG("wait JPEG irq\n");
wait_event_interruptible_timeout(dec_wait_queue, _jpeg_dec_int_status, timeout_jiff);
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Enter IRQ Wait Done!!\n");
//printk("[JPEGDRV]wait JPEG irq done\n");
}else{
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Enter IRQ Wait Already Done!!\n");
//printk("[JPEGDRV]JPEG decoder already done\n");
}
#endif
decResult = jpeg_drv_dec_get_result();
//jpeg_drv_dec_dump_key_reg();
if(decResult >= 2)
{
JPEG_MSG("[JPEGDRV]Decode Result : %d, status %x!\n", decResult, _jpeg_dec_int_status );
jpeg_drv_dec_dump_key_reg();
//jpeg_drv_dec_dump_reg();
jpeg_drv_dec_warm_reset();
}
irq_st = _jpeg_dec_int_status ;
decResult = decResult | (irq_st<<8) ;
_jpeg_dec_int_status = 0;
if(copy_to_user(outParams.result, &decResult, sizeof(unsigned int)))
{
JPEG_WRN("JPEG Decoder : Copy to user error (result)\n");
return -EFAULT;
}
break;
case JPEG_DEC_IOCTL_BREAK:
if (jpeg_drv_dec_break() < 0)
return -EFAULT;
break;
case JPEG_DEC_IOCTL_DUMP_REG:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder DUMP REGISTER !!\n");
jpeg_drv_dec_dump_reg();
break;
case JPEG_DEC_IOCTL_DEINIT:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Deinit !!\n");
// copy input parameters
if(*pStatus != JPEG_DEC_PROCESS)
{
JPEG_ERR("Permission Denied! This process can not access encoder");
return -EFAULT;
}
if(dec_status == 0)
{
JPEG_ERR("Encoder status is available, HOW COULD THIS HAPPEN ??");
*pStatus = 0;
return -EFAULT;
}
jpeg_drv_dec_deinit();
*pStatus = 0;
break;
#ifdef FOR_COMPILE
case JPEG_DEC_IOCTL_RW_REG: /* OT:OK */
jpeg_drv_dec_rw_reg();
break;
#endif
default:
JPEG_ERR("JPEG DEC IOCTL NO THIS COMMAND\n");
break;
}
return 0;
}
#endif //JPEG_DEC_DRIVER
static int jpeg_enc_ioctl(unsigned int cmd, unsigned long arg, struct file *file)
{
int retValue;
//unsigned int decResult;
long timeout_jiff;
unsigned int file_size, enc_result_code;
//unsigned int _jpeg_enc_int_status;
unsigned int jpeg_enc_wait_timeout = 0;
unsigned int cycle_count;
unsigned int ret ;
unsigned int *pStatus;
//JpegDrvEncParam cfgEnc;
JPEG_ENC_DRV_IN cfgEnc;
JPEG_ENC_DRV_OUT enc_result;
pStatus = (unsigned int*)file->private_data;
if(NULL == pStatus)
{
JPEG_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n");
return -EFAULT;
}
switch(cmd)
{
case JPEG_ENC_IOCTL_RW_REG:
//jpeg_drv_enc_rw_reg();
break;
// initial and reset JPEG encoder
case JPEG_ENC_IOCTL_INIT:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Init!!\n");
retValue = jpeg_drv_enc_init();
if(retValue == 0)
{
*pStatus = JPEG_ENC_PROCESS;
}
return retValue;
break;
case JPEG_ENC_IOCTL_WARM_RESET:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Warm Reset\n");
enc_result_code = jpeg_drv_enc_warm_reset();
if (0 == enc_result_code)
{
return -EFAULT;
}
break;
// configure the register
case JPEG_ENC_IOCTL_CONFIG:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Configure Hardware\n");
if(*pStatus != JPEG_ENC_PROCESS)
{
JPEG_WRN("Permission Denied! This process can not access encoder");
return -EFAULT;
}
if(enc_status == 0)
{
JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??");
*pStatus = 0;
return -EFAULT;
}
// copy input parameters
if(copy_from_user(&cfgEnc, (void *)arg, sizeof(JPEG_ENC_DRV_IN)))
{
JPEG_MSG("[JPEGDRV]JPEG Encoder : Copy from user error\n");
return -EFAULT;
}
// 0. reset
jpeg_drv_enc_reset();
// 1. set src config
//memset(&src_cfg, 0, sizeof(JpegDrvEncSrcCfg));
//src_cfg.luma_addr = cfgEnc.srcBufferAddr;
//if (cfgEnc.encFormat == NV12 || cfgEnc.encFormat == NV21)
//{
// unsigned int srcChromaAddr = cfgEnc.srcChromaAddr;
// srcChromaAddr = TO_CEIL(srcChromaAddr, 128); //((srcChromaAddr+127)&~127);
// src_cfg.chroma_addr = srcChromaAddr;
//}
//
//src_cfg.width = cfgEnc.encWidth;
//src_cfg.height = cfgEnc.encHeight;
//src_cfg.yuv_format = cfgEnc.encFormat;
// 1. set src config
JPEG_MSG("[JPEGDRV]SRC_IMG: %x %x, DU:%x, fmt:%x!!\n", cfgEnc.encWidth, cfgEnc.encHeight, cfgEnc.totalEncDU, cfgEnc.encFormat);
ret = jpeg_drv_enc_set_src_image(cfgEnc.encWidth, cfgEnc.encHeight, cfgEnc.encFormat, cfgEnc.totalEncDU) ;
if(ret == 0){
JPEG_MSG("[JPEGDRV]JPEG Encoder set srouce image failed\n");
return -EFAULT;
}
// 2. set src buffer info
JPEG_MSG("[JPEGDRV]SRC_BUF: addr %x, %x, stride %x, %x!!\n", cfgEnc.srcBufferAddr, cfgEnc.srcChromaAddr ,cfgEnc.imgStride, cfgEnc.memStride);
ret = jpeg_drv_enc_set_src_buf(cfgEnc.encFormat, cfgEnc.imgStride, cfgEnc.memStride, cfgEnc.srcBufferAddr, cfgEnc.srcChromaAddr);
if(ret == 0){
JPEG_MSG("[JPEGDRV]JPEG Encoder set srouce buffer failed\n");
return -EFAULT;
}
//if (0 == jpeg_drv_enc_src_cfg(src_cfg))
//{
// JPEG_MSG("JPEG Encoder src cfg failed\n");
// return -EFAULT;
//}
// 3. set dst buffer info
JPEG_MSG("[JPEGDRV]DST_BUF: addr:%x, size:%x, ofs:%x, mask:%x!!\n",cfgEnc.dstBufferAddr, cfgEnc.dstBufferSize, cfgEnc.dstBufAddrOffset, cfgEnc.dstBufAddrOffsetMask);
ret = jpeg_drv_enc_set_dst_buff(cfgEnc.dstBufferAddr, cfgEnc.dstBufferSize, cfgEnc.dstBufAddrOffset, cfgEnc.dstBufAddrOffsetMask);
if (ret == 0 ){
JPEG_MSG("[JPEGDRV]JPEG Encoder set dst buffer failed\n");
return -EFAULT;
}
//memset(&dst_cfg, 0, sizeof(JpegDrvEncDstCfg));
//
//dst_cfg.dst_addr = cfgEnc.dstBufferAddr;
//dst_cfg.dst_size = cfgEnc.dstBufferSize;
//dst_cfg.exif_en = cfgEnc.enableEXIF;
//
//JPEG_MSG("go L:%d, %x, %d, %d !!", __LINE__, dst_cfg.dst_addr, dst_cfg.dst_size, dst_cfg.file_format);
//
//if (0 == jpeg_drv_enc_dst_buff(dst_cfg))
// return -EFAULT;
// 4 .set ctrl config
JPEG_MSG("[JPEGDRV]ENC_CFG: exif:%d, q:%d, DRI:%d !!\n", cfgEnc.enableEXIF, cfgEnc.encQuality, cfgEnc.restartInterval);
jpeg_drv_enc_ctrl_cfg(cfgEnc.enableEXIF, cfgEnc.encQuality, cfgEnc.restartInterval);
//memset(&ctrl_cfg, 0, sizeof(JpegDrvEncCtrlCfg));
//
//ctrl_cfg.quality = cfgEnc.encQuality;
//ctrl_cfg.gmc_disable = cfgEnc.disableGMC;
//ctrl_cfg.restart_interval = cfgEnc.restartInterval;
//
break;
case JPEG_ENC_IOCTL_START:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Start!!\n");
if(*pStatus != JPEG_ENC_PROCESS)
{
JPEG_WRN("Permission Denied! This process can not access encoder");
return -EFAULT;
}
if(enc_status == 0)
{
JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??");
*pStatus = 0;
return -EFAULT;
}
jpeg_drv_enc_start();
break;
case JPEG_ENC_IOCTL_WAIT:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Wait!!\n");
if(*pStatus != JPEG_ENC_PROCESS)
{
JPEG_WRN("Permission Denied! This process can not access encoder");
return -EFAULT;
}
if(enc_status == 0)
{
JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??");
*pStatus = 0;
return -EFAULT;
}
if(copy_from_user(&enc_result, (void *)arg, sizeof(JPEG_ENC_DRV_OUT)))
{
JPEG_WRN("JPEG Encoder : Copy from user error\n");
return -EFAULT;
}
//TODO: ENC_DONE in REG_JPEG_ENC_INTERRUPT_STATUS need to set to 0 after read.
jpeg_enc_wait_timeout = 0xFFFFFF;
#ifdef FPGA_VERSION
do{
_jpeg_enc_int_status = REG_JPEG_ENC_INTERRUPT_STATUS;
jpeg_enc_wait_timeout--;
}while(_jpeg_enc_int_status == 0 && jpeg_enc_wait_timeout > 0);
if (jpeg_enc_wait_timeout == 0)
JPEG_MSG("JPEG Encoder timeout\n");
ret = jpeg_drv_enc_get_result(&file_size);
//JPEG_MSG("Result : %d, Size : %u, addres : 0x%x\n", ret, file_size, ioread32(JPG_CODEC_BASE + 0x120));
JPEG_MSG("Result : %d, Size : %u, addres : 0x%x\n", ret, file_size, ioread32(JPEG_ENC_BASE + 0x120));
if(_jpeg_enc_int_status != 1)
{
jpeg_drv_enc_dump_reg();
}
#else
//set timeout
timeout_jiff = enc_result.timeout* HZ / 1000;
JPEG_MSG("[JPEGDRV]JPEG Encoder Time Jiffies : %ld\n", timeout_jiff);
if(jpeg_isr_enc_lisr()<0)
{
wait_event_interruptible_timeout(enc_wait_queue, _jpeg_enc_int_status, timeout_jiff);
JPEG_MSG("[JPEGDRV]JPEG Encoder Wait done !!\n");
}
else
{
JPEG_MSG("[JPEGDRV]JPEG Encoder already done !!\n");
}
ret = jpeg_drv_enc_get_result(&file_size);
JPEG_MSG("[JPEGDRV]Result : %d, Size : %u!!\n", ret, file_size);
if(ret != 0)
{
jpeg_drv_enc_dump_reg();
jpeg_drv_enc_warm_reset();
}
#endif
cycle_count = jpeg_drv_enc_get_cycle_count();
if(copy_to_user(enc_result.fileSize, &file_size, sizeof(unsigned int)))
{
JPEG_MSG("[JPEGDRV]JPEG Encoder : Copy to user error (file size)\n");
return -EFAULT;
}
if(copy_to_user(enc_result.result, &ret, sizeof(unsigned int)))
{
JPEG_MSG("[JPEGDRV]JPEG Encoder : Copy to user error (status)\n");
return -EFAULT;
}
if(copy_to_user(enc_result.cycleCount, &cycle_count, sizeof(unsigned int)))
{
JPEG_MSG("[JPEGDRV]JPEG Encoder : Copy to user error (cycle)\n");
return -EFAULT;
}
break;
case JPEG_ENC_IOCTL_DEINIT:
JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Deinit!!\n");
// copy input parameters
if(*pStatus != JPEG_ENC_PROCESS)
{
JPEG_WRN("Permission Denied! This process can not access encoder");
return -EFAULT;
}
if(enc_status == 0)
{
JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??");
*pStatus = 0;
return -EFAULT;
}
jpeg_drv_enc_deinit();
*pStatus = 0;
break;
case JPEG_ENC_IOCTL_DUMP_REG:
jpeg_drv_enc_dump_reg();
break;
default:
JPEG_MSG("[JPEGDRV]JPEG ENC IOCTL NO THIS COMMAND\n");
}
return 0;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
#ifdef CONFIG_COMPAT
static int compat_get_jpeg_dec_ioctl_wait_data(
compat_JPEG_DEC_DRV_OUT __user *data32,
JPEG_DEC_DRV_OUT __user *data)
{
compat_long_t timeout;
compat_uptr_t result;
int err;
err = get_user(timeout, &data32->timeout);
err |= put_user(timeout, &data->timeout);
err |= get_user(result, &data32->result);
err |= put_user(compat_ptr(result), &data->result);
return err;
}
static int compat_put_jpeg_dec_ioctl_wait_data(
compat_JPEG_DEC_DRV_OUT __user *data32,
JPEG_DEC_DRV_OUT __user *data)
{
compat_long_t timeout;
//compat_uptr_t result;
int err;
err = get_user(timeout, &data->timeout);
err |= put_user(timeout, &data32->timeout);
//err |= get_user(result, &data->result);
//err |= put_user(result, &data32->result);
return err;
}
static int compat_get_jpeg_dec_ioctl_chksum_data(
compat_JpegDrvDecResult __user *data32,
JpegDrvDecResult __user *data)
{
compat_uptr_t pChksum;
int err;
err = get_user(pChksum, &data32->pChksum);
err |= put_user(compat_ptr(pChksum), &data->pChksum);
return err;
}
static int compat_put_jpeg_dec_ioctl_chksum_data(
compat_JpegDrvDecResult __user *data32,
JpegDrvDecResult __user *data)
{
//compat_uptr_t pChksum;
//int err;
//err = get_user(pChksum, &data->pChksum);
//err |= put_user(pChksum, &data32->pChksum);
return 0;
}
static int compat_get_jpeg_enc_ioctl_wait_data(
compat_JPEG_ENC_DRV_OUT __user *data32,
JPEG_ENC_DRV_OUT __user *data)
{
compat_long_t timeout;
compat_uptr_t fileSize;
compat_uptr_t result;
compat_uptr_t cycleCount;
int err;
err = get_user(timeout, &data32->timeout);
err |= put_user(timeout, &data->timeout);
err |= get_user(fileSize, &data32->fileSize);
err |= put_user(compat_ptr(fileSize), &data->fileSize);
err |= get_user(result, &data32->result);
err |= put_user(compat_ptr(result), &data->result);
err |= get_user(cycleCount, &data32->cycleCount);
err |= put_user(compat_ptr(cycleCount), &data->cycleCount);
return err;
}
static int compat_put_jpeg_enc_ioctl_wait_data(
compat_JPEG_ENC_DRV_OUT __user *data32,
JPEG_ENC_DRV_OUT __user *data)
{
compat_long_t timeout;
//compat_uptr_t fileSize;
//compat_uptr_t result;
//compat_uptr_t cycleCount;
int err;
err = get_user(timeout, &data->timeout);
err |= put_user(timeout, &data32->timeout);
//err |= get_user(fileSize, &data->fileSize);
//err |= put_user(fileSize, &data32->fileSize);
//err |= get_user(result, &data->result);
//err |= put_user(result, &data32->result);
//err |= get_user(cycleCount, &data->cycleCount);
//err |= put_user(cycleCount, &data32->cycleCount);
return err;
}
static long compat_jpeg_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
long ret;
if (!filp->f_op || !filp->f_op->unlocked_ioctl)
return -ENOTTY;
switch (cmd)
{
case COMPAT_JPEG_DEC_IOCTL_WAIT:
{
compat_JPEG_DEC_DRV_OUT __user *data32;
JPEG_DEC_DRV_OUT __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_jpeg_dec_ioctl_wait_data(data32, data);
if (err)
return err;
ret = filp->f_op->unlocked_ioctl(filp, JPEG_DEC_IOCTL_WAIT,(unsigned long)data);
err = compat_put_jpeg_dec_ioctl_wait_data(data32, data);
return ret ? ret : err;
}
case COMPAT_JPEG_DEC_IOCTL_CHKSUM:
{
compat_JpegDrvDecResult __user *data32;
JpegDrvDecResult __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_jpeg_dec_ioctl_chksum_data(data32, data);
if (err)
return err;
ret = filp->f_op->unlocked_ioctl(filp, JPEG_DEC_IOCTL_CHKSUM,(unsigned long)data);
err = compat_put_jpeg_dec_ioctl_chksum_data(data32, data);
return ret ? ret : err;
}
case COMPAT_JPEG_ENC_IOCTL_WAIT:
{
compat_JPEG_ENC_DRV_OUT __user *data32;
JPEG_ENC_DRV_OUT __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_jpeg_enc_ioctl_wait_data(data32, data);
if (err)
return err;
ret = filp->f_op->unlocked_ioctl(filp, JPEG_ENC_IOCTL_WAIT,(unsigned long)data);
err = compat_put_jpeg_enc_ioctl_wait_data(data32, data);
return ret ? ret : err;
}
case JPEG_DEC_IOCTL_INIT:
case JPEG_DEC_IOCTL_START:
case JPEG_DEC_IOCTL_DEINIT:
case JPEG_DEC_IOCTL_DUMP_REG:
case JPEG_ENC_IOCTL_INIT:
case JPEG_ENC_IOCTL_DEINIT:
case JPEG_ENC_IOCTL_START:
return filp->f_op->unlocked_ioctl(filp, cmd, arg);
case JPEG_DEC_IOCTL_CONFIG:
case JPEG_DEC_IOCTL_RESUME:
case JPEG_DEC_IOCTL_FLUSH_CMDQ:
case JPEG_ENC_IOCTL_CONFIG:
return filp->f_op->unlocked_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
default:
return -ENOIOCTLCMD;
}
}
#endif
//static int jpeg_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
static long jpeg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
switch(cmd)
{
#ifdef JPEG_DEC_DRIVER
case JPEG_DEC_IOCTL_INIT:
case JPEG_DEC_IOCTL_CONFIG:
case JPEG_DEC_IOCTL_START:
case JPEG_DEC_IOCTL_RESUME:
case JPEG_DEC_IOCTL_WAIT:
case JPEG_DEC_IOCTL_DEINIT:
case JPEG_DEC_IOCTL_DUMP_REG:
case JPEG_DEC_IOCTL_FLUSH_CMDQ:
return jpeg_dec_ioctl(cmd, arg, file);
#endif
case JPEG_ENC_IOCTL_INIT:
case JPEG_ENC_IOCTL_CONFIG:
case JPEG_ENC_IOCTL_WAIT:
case JPEG_ENC_IOCTL_DEINIT:
case JPEG_ENC_IOCTL_START:
return jpeg_enc_ioctl(cmd, arg, file);
default :
break;
}
return -EINVAL;
}
static int jpeg_open(struct inode *inode, struct file *file)
{
unsigned int *pStatus;
//Allocate and initialize private data
file->private_data = kmalloc(sizeof(unsigned int) , GFP_ATOMIC);
if(NULL == file->private_data)
{
JPEG_WRN("Not enough entry for JPEG open operation\n");
return -ENOMEM;
}
pStatus = (unsigned int *)file->private_data;
*pStatus = 0;
return 0;
}
static ssize_t jpeg_read(struct file *file, char __user *data, size_t len, loff_t *ppos)
{
JPEG_MSG("jpeg driver read\n");
return 0;
}
static int jpeg_release(struct inode *inode, struct file *file)
{
if(NULL != file->private_data)
{
kfree(file->private_data);
file->private_data = NULL;
}
return 0;
}
static int jpeg_flush(struct file * a_pstFile , fl_owner_t a_id)
{
unsigned int *pStatus;
pStatus = (unsigned int*)a_pstFile->private_data;
if(NULL == pStatus)
{
JPEG_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n");
return -EFAULT;
}
if (*pStatus == JPEG_ENC_PROCESS)
{
if(enc_status != 0)
{
JPEG_WRN("Error! Enable error handling for jpeg encoder");
jpeg_drv_enc_deinit();
}
}
#ifdef JPEG_DEC_DRIVER
else if (*pStatus == JPEG_DEC_PROCESS)
{
if(dec_status != 0)
{
JPEG_WRN("Error! Enable error handling for jpeg decoder");
jpeg_drv_dec_deinit();
}
}
#endif
return 0;
}
/* Kernel interface */
static struct file_operations jpeg_fops = {
.owner = THIS_MODULE,
//.ioctl = jpeg_ioctl,
.unlocked_ioctl = jpeg_unlocked_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_jpeg_ioctl,
#endif
.open = jpeg_open,
.release = jpeg_release,
.flush = jpeg_flush,
.read = jpeg_read,
};
const long jpeg_dev_get_encoder_base_VA(void)
{
return gJpegqDev.encRegBaseVA;
}
const long jpeg_dev_get_decoder_base_VA(void)
{
return gJpegqDev.decRegBaseVA;
}
static int jpeg_probe(struct platform_device *pdev)
{
#ifdef CONFIG_OF
int new_count;
struct JpegDeviceStruct* jpegDev;
struct device_node *node = NULL;
new_count = nrJpegDevs + 1;
gJpegqDevs = krealloc(gJpegqDevs,
sizeof(struct JpegDeviceStruct) * new_count, GFP_KERNEL);
if (!gJpegqDevs) {
dev_err(&pdev->dev, "Unable to allocate cam_isp_devs\n");
return -ENOMEM;
}
jpegDev = &(gJpegqDevs[nrJpegDevs]);
jpegDev->pDev = &pdev->dev;
memset(&gJpegqDev, 0x0, sizeof(JpegDeviceStruct));
node = of_find_compatible_node(NULL, NULL, "mediatek,JPGENC");
jpegDev->encRegBaseVA = (unsigned long)of_iomap(node, 0);
jpegDev->encIrqId = irq_of_parse_and_map(node, 0);
node = of_find_compatible_node(NULL, NULL, "mediatek,JPGDEC");
jpegDev->decRegBaseVA = (unsigned long)of_iomap(node, 0);
jpegDev->decIrqId = irq_of_parse_and_map(node, 0);
gJpegqDev = *jpegDev;
#else
gJpegqDev.encRegBaseVA = (0L | 0xF7003000);
gJpegqDev.decRegBaseVA = (0L | 0xF7004000);
gJpegqDev.encIrqId = JPGENC_IRQ_BIT_ID;
gJpegqDev.decIrqId = JPGDEC_IRQ_BIT_ID;
gJpegqDev.pDev = &pdev->dev;
#endif
#ifdef JPEG_DEV
int ret;
struct class_device *class_dev = NULL;
JPEG_MSG("-------------jpeg driver probe-------\n");
ret = alloc_chrdev_region(&jpeg_devno, 0, 1, JPEG_DEVNAME);
if(ret)
{
JPEG_ERR("Error: Can't Get Major number for JPEG Device\n");
}
else
{
JPEG_MSG("Get JPEG Device Major number (%d)\n", jpeg_devno);
}
jpeg_cdev = cdev_alloc();
jpeg_cdev->owner = THIS_MODULE;
jpeg_cdev->ops = &jpeg_fops;
ret = cdev_add(jpeg_cdev, jpeg_devno, 1);
jpeg_class = class_create(THIS_MODULE, JPEG_DEVNAME);
class_dev = (struct class_device *)device_create(jpeg_class, NULL, jpeg_devno, NULL, JPEG_DEVNAME);
#else
proc_create("mtk_jpeg", 0, NULL, &jpeg_fops);
#endif
spin_lock_init(&jpeg_enc_lock);
// initial codec, register codec ISR
enc_status = 0;
_jpeg_enc_int_status = 0;
#ifdef JPEG_DEC_DRIVER
spin_lock_init(&jpeg_dec_lock);
dec_status = 0;
_jpeg_dec_int_status = 0;
_jpeg_dec_mode = 0;
#endif
#ifndef FPGA_VERSION
#ifdef JPEG_DEC_DRIVER
init_waitqueue_head(&dec_wait_queue);
#endif
init_waitqueue_head(&enc_wait_queue);
//mt6575_irq_set_sens(MT6575_JPEG_CODEC_IRQ_ID, MT65xx_LEVEL_SENSITIVE);
//mt6575_irq_set_polarity(MT6575_JPEG_CODEC_IRQ_ID, MT65xx_POLARITY_LOW);
//mt6575_irq_unmask(MT6575_JPEG_CODEC_IRQ_ID);
JPEG_MSG("request JPEG Encoder IRQ \n");
enable_irq(gJpegqDev.encIrqId);
if(request_irq(gJpegqDev.encIrqId, jpeg_drv_enc_isr, IRQF_TRIGGER_LOW, "jpeg_enc_driver" , NULL))
//if(request_irq(JPGENC_IRQ_BIT_ID, jpeg_drv_enc_isr, /*IRQF_TRIGGER_RISING*/ IRQF_TRIGGER_HIGH, "jpeg_enc_driver" , NULL))
//if(request_irq(JPGENC_IRQ_BIT_ID, jpeg_drv_enc_isr, IRQF_TRIGGER_RISING , "jpeg_enc_driver" , NULL))
{
JPEG_ERR("JPEG ENC Driver request irq failed\n");
}
#ifdef JPEG_DEC_DRIVER
enable_irq(gJpegqDev.decIrqId);
JPEG_MSG("request JPEG Decoder IRQ \n");
//if(request_irq(JPGDEC_IRQ_BIT_ID, jpeg_drv_dec_isr, IRQF_TRIGGER_LOW, "jpeg_dec_driver" , NULL))
//if(request_irq(JPGDEC_IRQ_BIT_ID, jpeg_drv_dec_isr, /*IRQF_TRIGGER_RISING*/ IRQF_TRIGGER_HIGH, "jpeg_dec_driver" , NULL))
//if(request_irq(JPGDEC_IRQ_BIT_ID, jpeg_drv_dec_isr, IRQF_TRIGGER_RISING , "jpeg_dec_driver" , NULL))
if(request_irq(gJpegqDev.decIrqId, jpeg_drv_dec_isr, IRQF_TRIGGER_FALLING , "jpeg_dec_driver" , NULL))
{
JPEG_ERR("JPEG DEC Driver request irq failed\n");
}
#endif
#endif
JPEG_MSG("JPEG Probe Done\n");
#ifdef JPEG_DEV
NOT_REFERENCED(class_dev);
#endif
return 0;
}
static int jpeg_remove(struct platform_device *pdev)
{
JPEG_MSG("JPEG Codec remove\n");
//unregister_chrdev(JPEGDEC_MAJOR, JPEGDEC_DEVNAME);
#ifndef FPGA_VERSION
free_irq(JPGENC_IRQ_BIT_ID, NULL);
#ifdef JPEG_DEC_DRIVER
free_irq(JPGDEC_IRQ_BIT_ID, NULL);
#endif
#endif
JPEG_MSG("Done\n");
return 0;
}
static void jpeg_shutdown(struct platform_device *pdev)
{
JPEG_MSG("JPEG Codec shutdown\n");
/* Nothing yet */
}
/* PM suspend */
static int jpeg_suspend(struct platform_device *pdev, pm_message_t mesg)
{
#ifdef JPEG_DEC_DRIVER
jpeg_drv_dec_deinit();
#endif
jpeg_drv_enc_deinit();
return 0;
}
/* PM resume */
static int jpeg_resume(struct platform_device *pdev)
{
return 0;
}
static int jpeg_pm_suspend(struct device *pDevice)
{
struct platform_device *pdev = to_platform_device(pDevice);
BUG_ON(pdev == NULL);
return jpeg_suspend(pdev, PMSG_SUSPEND);
}
static int jpeg_pm_resume(struct device *pDevice)
{
struct platform_device *pdev = to_platform_device(pDevice);
BUG_ON(pdev == NULL);
return jpeg_resume(pdev);
}
static int jpeg_pm_restore_noirq(struct device *pDevice)
{
return 0;
}
static struct dev_pm_ops jpeg_pm_ops = {
.suspend = jpeg_pm_suspend,
.resume = jpeg_pm_resume,
.freeze = NULL,
.thaw = NULL,
.poweroff = NULL,
.restore = NULL,
.restore_noirq = jpeg_pm_restore_noirq,
};
static struct platform_driver jpeg_driver = {
.probe = jpeg_probe,
.remove = jpeg_remove,
.shutdown = jpeg_shutdown,
.suspend = jpeg_suspend,
.resume = jpeg_resume,
.driver = {
.name = JPEG_DEVNAME,
.pm = &jpeg_pm_ops,
#ifdef CONFIG_OF
.of_match_table = jpeg_of_ids,
#endif
},
};
static void jpeg_device_release(struct device *dev)
{
// Nothing to release?
}
static u64 jpegdec_dmamask = ~(u32)0;
static struct platform_device jpeg_device = {
.name = JPEG_DEVNAME,
.id = 0,
.dev = {
.release = jpeg_device_release,
.dma_mask = &jpegdec_dmamask,
.coherent_dma_mask = 0xffffffff,
},
.num_resources = 0,
};
static int __init jpeg_init(void)
{
int ret;
JPEG_MSG("JPEG Codec initialize\n");
#if 0
JPEG_MSG("Register the JPEG Codec device\n");
if(platform_device_register(&jpeg_device))
{
JPEG_ERR("failed to register jpeg codec device\n");
ret = -ENODEV;
return ret;
}
#endif
JPEG_MSG("Register the JPEG Codec driver\n");
if(platform_driver_register(&jpeg_driver))
{
JPEG_ERR("failed to register jpeg codec driver\n");
platform_device_unregister(&jpeg_device);
ret = -ENODEV;
return ret;
}
cmdqCoreRegisterCB(CMDQ_GROUP_JPEG,
cmdqJpegClockOn,
cmdqJpegDumpInfo,
cmdqJpegResetEng,
cmdqJpegClockOff);
return 0;
}
static void __exit jpeg_exit(void)
{
#ifdef JPEG_DEV
cdev_del(jpeg_cdev);
unregister_chrdev_region(jpeg_devno, 1);
device_destroy(jpeg_class, jpeg_devno);
class_destroy(jpeg_class);
#else
remove_proc_entry("mtk_jpeg", NULL);
#endif
cmdqCoreRegisterCB(CMDQ_GROUP_JPEG,
NULL,
NULL,
NULL,
NULL);
//JPEG_MSG("Unregistering driver\n");
platform_driver_unregister(&jpeg_driver);
platform_device_unregister(&jpeg_device);
JPEG_MSG("Done\n");
}
module_init(jpeg_init);
module_exit(jpeg_exit);
MODULE_AUTHOR("Hao-Ting Huang <otis.huang@mediatek.com>");
MODULE_DESCRIPTION("MT6582 JPEG Codec Driver");
MODULE_LICENSE("GPL");
|