forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/media/platform/rockchip/isp/capture.c
....@@ -11,17 +11,18 @@
1111 #include <media/videobuf2-dma-contig.h>
1212 #include "dev.h"
1313 #include "regs.h"
14
+#include "rkisp_tb_helper.h"
1415
1516 #define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416
1617 #define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT 3312
1718 #define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920
1819 #define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT 1080
1920 #define STREAM_MIN_RSZ_OUTPUT_WIDTH 32
20
-#define STREAM_MIN_RSZ_OUTPUT_HEIGHT 16
21
+#define STREAM_MIN_RSZ_OUTPUT_HEIGHT 32
2122 #define STREAM_OUTPUT_STEP_WISE 8
2223
23
-#define STREAM_MIN_MP_SP_INPUT_WIDTH 32
24
-#define STREAM_MIN_MP_SP_INPUT_HEIGHT 32
24
+#define STREAM_MIN_MP_SP_INPUT_WIDTH STREAM_MIN_RSZ_OUTPUT_WIDTH
25
+#define STREAM_MIN_MP_SP_INPUT_HEIGHT STREAM_MIN_RSZ_OUTPUT_HEIGHT
2526
2627 static int hdr_dma_frame(struct rkisp_device *dev)
2728 {
....@@ -124,7 +125,7 @@
124125 if (atomic_read(&dev->cap_dev.refcnt) > 1 ||
125126 !dev->active_sensor ||
126127 (dev->active_sensor &&
127
- dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) ||
128
+ dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) ||
128129 (dev->isp_inp & INP_CIF) ||
129130 (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21))
130131 return;
....@@ -157,7 +158,7 @@
157158
158159 if (!dev->active_sensor ||
159160 (dev->active_sensor &&
160
- dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) ||
161
+ dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) ||
161162 (dev->isp_inp & INP_CIF) ||
162163 (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21))
163164 return 0;
....@@ -165,7 +166,7 @@
165166 for (i = RKISP_STREAM_DMATX0; i <= RKISP_STREAM_DMATX2; i++) {
166167 dmatx = &dev->cap_dev.stream[i];
167168 if (dmatx->ops && dmatx->ops->frame_end)
168
- dmatx->ops->frame_end(dmatx);
169
+ dmatx->ops->frame_end(dmatx, FRAME_INIT);
169170 }
170171
171172 if (dev->dmarx_dev.trigger)
....@@ -225,7 +226,7 @@
225226 if (atomic_inc_return(&dev->hdr.refcnt) > 1 ||
226227 !dev->active_sensor ||
227228 (dev->active_sensor &&
228
- dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) ||
229
+ dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) ||
229230 (dev->isp_inp & INP_CIF) ||
230231 (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21))
231232 return 0;
....@@ -294,7 +295,7 @@
294295 if (atomic_dec_return(&dev->hdr.refcnt) ||
295296 !dev->active_sensor ||
296297 (dev->active_sensor &&
297
- dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) ||
298
+ dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) ||
298299 (dev->isp_inp & INP_CIF) ||
299300 (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21))
300301 return;
....@@ -351,7 +352,7 @@
351352 if (!hw->dummy_buf.mem_priv ||
352353 !dev->active_sensor ||
353354 (dev->active_sensor &&
354
- dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) ||
355
+ dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) ||
355356 (dev->isp_inp & INP_CIF) ||
356357 (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21))
357358 return;
....@@ -360,14 +361,14 @@
360361 */
361362 for (i = 0; i < hw->dev_num; i++) {
362363 isp = hw->isp[i];
363
- if (!(isp->isp_inp & INP_CSI))
364
+ if (!isp ||
365
+ (isp && !(isp->isp_inp & INP_CSI)))
364366 continue;
365367 for (j = RKISP_STREAM_DMATX0; j < RKISP_MAX_STREAM; j++) {
366368 stream = &isp->cap_dev.stream[j];
367369 if (!stream->linked || stream->curr_buf || stream->next_buf)
368370 continue;
369
- if (!rkisp_read(dev, stream->config->mi.y_base_ad_init, true))
370
- mi_set_y_addr(stream, hw->dummy_buf.dma_addr);
371
+ mi_set_y_addr(stream, hw->dummy_buf.dma_addr);
371372 }
372373 }
373374 }
....@@ -393,6 +394,7 @@
393394 case V4L2_PIX_FMT_NV16:
394395 case V4L2_PIX_FMT_NV61:
395396 case V4L2_PIX_FMT_YVU422M:
397
+ case V4L2_PIX_FMT_FBC2:
396398 *xsubs = 2;
397399 *ysubs = 1;
398400 break;
....@@ -403,6 +405,7 @@
403405 case V4L2_PIX_FMT_YUV420:
404406 case V4L2_PIX_FMT_YVU420:
405407 case V4L2_PIX_FMT_FBCG:
408
+ case V4L2_PIX_FMT_FBC0:
406409 *xsubs = 2;
407410 *ysubs = 2;
408411 break;
....@@ -431,326 +434,48 @@
431434 return 0;
432435 }
433436
434
-static const struct capture_fmt mp_fmts[] = {
435
- /* yuv422 */
436
- {
437
- .fourcc = V4L2_PIX_FMT_UYVY,
438
- .fmt_type = FMT_YUV,
439
- .bpp = { 16 },
440
- .cplanes = 1,
441
- .mplanes = 1,
442
- .uv_swap = 0,
443
- .write_format = MI_CTRL_MP_WRITE_YUVINT,
444
- }, {
445
- .fourcc = V4L2_PIX_FMT_YUV422P,
446
- .fmt_type = FMT_YUV,
447
- .bpp = { 8, 4, 4 },
448
- .cplanes = 3,
449
- .mplanes = 1,
450
- .uv_swap = 0,
451
- .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8,
452
- }, {
453
- .fourcc = V4L2_PIX_FMT_NV16,
454
- .fmt_type = FMT_YUV,
455
- .bpp = { 8, 16 },
456
- .cplanes = 2,
457
- .mplanes = 1,
458
- .uv_swap = 0,
459
- .write_format = MI_CTRL_MP_WRITE_YUV_SPLA,
460
- }, {
461
- .fourcc = V4L2_PIX_FMT_NV61,
462
- .fmt_type = FMT_YUV,
463
- .bpp = { 8, 16 },
464
- .cplanes = 2,
465
- .mplanes = 1,
466
- .uv_swap = 1,
467
- .write_format = MI_CTRL_MP_WRITE_YUV_SPLA,
468
- }, {
469
- .fourcc = V4L2_PIX_FMT_YUV422M,
470
- .fmt_type = FMT_YUV,
471
- .bpp = { 8, 8, 8 },
472
- .cplanes = 3,
473
- .mplanes = 3,
474
- .uv_swap = 0,
475
- .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8,
476
- },
477
- /* yuv420 */
478
- {
479
- .fourcc = V4L2_PIX_FMT_NV21,
480
- .fmt_type = FMT_YUV,
481
- .bpp = { 8, 16 },
482
- .cplanes = 2,
483
- .mplanes = 1,
484
- .uv_swap = 1,
485
- .write_format = MI_CTRL_MP_WRITE_YUV_SPLA,
486
- }, {
487
- .fourcc = V4L2_PIX_FMT_NV12,
488
- .fmt_type = FMT_YUV,
489
- .bpp = { 8, 16 },
490
- .cplanes = 2,
491
- .mplanes = 1,
492
- .uv_swap = 0,
493
- .write_format = MI_CTRL_MP_WRITE_YUV_SPLA,
494
- }, {
495
- .fourcc = V4L2_PIX_FMT_NV21M,
496
- .fmt_type = FMT_YUV,
497
- .bpp = { 8, 16 },
498
- .cplanes = 2,
499
- .mplanes = 2,
500
- .uv_swap = 1,
501
- .write_format = MI_CTRL_MP_WRITE_YUV_SPLA,
502
- }, {
503
- .fourcc = V4L2_PIX_FMT_NV12M,
504
- .fmt_type = FMT_YUV,
505
- .bpp = { 8, 16 },
506
- .cplanes = 2,
507
- .mplanes = 2,
508
- .uv_swap = 0,
509
- .write_format = MI_CTRL_MP_WRITE_YUV_SPLA,
510
- }, {
511
- .fourcc = V4L2_PIX_FMT_YUV420,
512
- .fmt_type = FMT_YUV,
513
- .bpp = { 8, 8, 8 },
514
- .cplanes = 3,
515
- .mplanes = 1,
516
- .uv_swap = 0,
517
- .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8,
518
- },
519
- /* yuv444 */
520
- {
521
- .fourcc = V4L2_PIX_FMT_YUV444M,
522
- .fmt_type = FMT_YUV,
523
- .bpp = { 8, 8, 8 },
524
- .cplanes = 3,
525
- .mplanes = 3,
526
- .uv_swap = 0,
527
- .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8,
528
- },
529
- /* raw */
530
- {
531
- .fourcc = V4L2_PIX_FMT_SRGGB8,
532
- .fmt_type = FMT_BAYER,
533
- .bpp = { 8 },
534
- .mplanes = 1,
535
- .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8,
536
- }, {
537
- .fourcc = V4L2_PIX_FMT_SGRBG8,
538
- .fmt_type = FMT_BAYER,
539
- .bpp = { 8 },
540
- .mplanes = 1,
541
- .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8,
542
- }, {
543
- .fourcc = V4L2_PIX_FMT_SGBRG8,
544
- .fmt_type = FMT_BAYER,
545
- .bpp = { 8 },
546
- .mplanes = 1,
547
- .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8,
548
- }, {
549
- .fourcc = V4L2_PIX_FMT_SBGGR8,
550
- .fmt_type = FMT_BAYER,
551
- .bpp = { 8 },
552
- .mplanes = 1,
553
- .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8,
554
- }, {
555
- .fourcc = V4L2_PIX_FMT_SRGGB10,
556
- .fmt_type = FMT_BAYER,
557
- .bpp = { 10 },
558
- .mplanes = 1,
559
- .write_format = MI_CTRL_MP_WRITE_RAW12,
560
- }, {
561
- .fourcc = V4L2_PIX_FMT_SGRBG10,
562
- .fmt_type = FMT_BAYER,
563
- .bpp = { 10 },
564
- .mplanes = 1,
565
- .write_format = MI_CTRL_MP_WRITE_RAW12,
566
- }, {
567
- .fourcc = V4L2_PIX_FMT_SGBRG10,
568
- .fmt_type = FMT_BAYER,
569
- .bpp = { 10 },
570
- .mplanes = 1,
571
- .write_format = MI_CTRL_MP_WRITE_RAW12,
572
- }, {
573
- .fourcc = V4L2_PIX_FMT_SBGGR10,
574
- .fmt_type = FMT_BAYER,
575
- .bpp = { 10 },
576
- .mplanes = 1,
577
- .write_format = MI_CTRL_MP_WRITE_RAW12,
578
- }, {
579
- .fourcc = V4L2_PIX_FMT_SRGGB12,
580
- .fmt_type = FMT_BAYER,
581
- .bpp = { 12 },
582
- .mplanes = 1,
583
- .write_format = MI_CTRL_MP_WRITE_RAW12,
584
- }, {
585
- .fourcc = V4L2_PIX_FMT_SGRBG12,
586
- .fmt_type = FMT_BAYER,
587
- .bpp = { 12 },
588
- .mplanes = 1,
589
- .write_format = MI_CTRL_MP_WRITE_RAW12,
590
- }, {
591
- .fourcc = V4L2_PIX_FMT_SGBRG12,
592
- .fmt_type = FMT_BAYER,
593
- .bpp = { 12 },
594
- .mplanes = 1,
595
- .write_format = MI_CTRL_MP_WRITE_RAW12,
596
- }, {
597
- .fourcc = V4L2_PIX_FMT_SBGGR12,
598
- .fmt_type = FMT_BAYER,
599
- .bpp = { 12 },
600
- .mplanes = 1,
601
- .write_format = MI_CTRL_MP_WRITE_RAW12,
602
- },
603
-};
437
+int rkisp_stream_frame_start(struct rkisp_device *dev, u32 isp_mis)
438
+{
439
+ struct rkisp_stream *stream;
440
+ int i;
604441
605
-static const struct capture_fmt sp_fmts[] = {
606
- /* yuv422 */
607
- {
608
- .fourcc = V4L2_PIX_FMT_UYVY,
609
- .fmt_type = FMT_YUV,
610
- .bpp = { 16 },
611
- .cplanes = 1,
612
- .mplanes = 1,
613
- .uv_swap = 0,
614
- .write_format = MI_CTRL_SP_WRITE_INT,
615
- .output_format = MI_CTRL_SP_OUTPUT_YUV422,
616
- }, {
617
- .fourcc = V4L2_PIX_FMT_YUV422P,
618
- .fmt_type = FMT_YUV,
619
- .bpp = { 8, 8, 8 },
620
- .cplanes = 3,
621
- .mplanes = 1,
622
- .uv_swap = 0,
623
- .write_format = MI_CTRL_SP_WRITE_PLA,
624
- .output_format = MI_CTRL_SP_OUTPUT_YUV422,
625
- }, {
626
- .fourcc = V4L2_PIX_FMT_NV16,
627
- .fmt_type = FMT_YUV,
628
- .bpp = { 8, 16 },
629
- .cplanes = 2,
630
- .mplanes = 1,
631
- .uv_swap = 0,
632
- .write_format = MI_CTRL_SP_WRITE_SPLA,
633
- .output_format = MI_CTRL_SP_OUTPUT_YUV422,
634
- }, {
635
- .fourcc = V4L2_PIX_FMT_NV61,
636
- .fmt_type = FMT_YUV,
637
- .bpp = { 8, 16 },
638
- .cplanes = 2,
639
- .mplanes = 1,
640
- .uv_swap = 1,
641
- .write_format = MI_CTRL_SP_WRITE_SPLA,
642
- .output_format = MI_CTRL_SP_OUTPUT_YUV422,
643
- }, {
644
- .fourcc = V4L2_PIX_FMT_YUV422M,
645
- .fmt_type = FMT_YUV,
646
- .bpp = { 8, 8, 8 },
647
- .cplanes = 3,
648
- .mplanes = 3,
649
- .uv_swap = 0,
650
- .write_format = MI_CTRL_SP_WRITE_PLA,
651
- .output_format = MI_CTRL_SP_OUTPUT_YUV422,
652
- },
653
- /* yuv420 */
654
- {
655
- .fourcc = V4L2_PIX_FMT_NV21,
656
- .fmt_type = FMT_YUV,
657
- .bpp = { 8, 16 },
658
- .cplanes = 2,
659
- .mplanes = 1,
660
- .uv_swap = 1,
661
- .write_format = MI_CTRL_SP_WRITE_SPLA,
662
- .output_format = MI_CTRL_SP_OUTPUT_YUV420,
663
- }, {
664
- .fourcc = V4L2_PIX_FMT_NV12,
665
- .fmt_type = FMT_YUV,
666
- .bpp = { 8, 16 },
667
- .cplanes = 2,
668
- .mplanes = 1,
669
- .uv_swap = 0,
670
- .write_format = MI_CTRL_SP_WRITE_SPLA,
671
- .output_format = MI_CTRL_SP_OUTPUT_YUV420,
672
- }, {
673
- .fourcc = V4L2_PIX_FMT_NV21M,
674
- .fmt_type = FMT_YUV,
675
- .bpp = { 8, 16 },
676
- .cplanes = 2,
677
- .mplanes = 2,
678
- .uv_swap = 1,
679
- .write_format = MI_CTRL_SP_WRITE_SPLA,
680
- .output_format = MI_CTRL_SP_OUTPUT_YUV420,
681
- }, {
682
- .fourcc = V4L2_PIX_FMT_NV12M,
683
- .fmt_type = FMT_YUV,
684
- .bpp = { 8, 16 },
685
- .cplanes = 2,
686
- .mplanes = 2,
687
- .uv_swap = 0,
688
- .write_format = MI_CTRL_SP_WRITE_SPLA,
689
- .output_format = MI_CTRL_SP_OUTPUT_YUV420,
690
- }, {
691
- .fourcc = V4L2_PIX_FMT_YUV420,
692
- .fmt_type = FMT_YUV,
693
- .bpp = { 8, 8, 8 },
694
- .cplanes = 3,
695
- .mplanes = 1,
696
- .uv_swap = 0,
697
- .write_format = MI_CTRL_SP_WRITE_PLA,
698
- .output_format = MI_CTRL_SP_OUTPUT_YUV420,
699
- },
700
- /* yuv444 */
701
- {
702
- .fourcc = V4L2_PIX_FMT_YUV444M,
703
- .fmt_type = FMT_YUV,
704
- .bpp = { 8, 8, 8 },
705
- .cplanes = 3,
706
- .mplanes = 3,
707
- .uv_swap = 0,
708
- .write_format = MI_CTRL_SP_WRITE_PLA,
709
- .output_format = MI_CTRL_SP_OUTPUT_YUV444,
710
- },
711
- /* yuv400 */
712
- {
713
- .fourcc = V4L2_PIX_FMT_GREY,
714
- .fmt_type = FMT_YUV,
715
- .bpp = { 8 },
716
- .cplanes = 1,
717
- .mplanes = 1,
718
- .uv_swap = 0,
719
- .write_format = MI_CTRL_SP_WRITE_PLA,
720
- .output_format = MI_CTRL_SP_OUTPUT_YUV400,
721
- },
722
- /* rgb */
723
- {
724
- .fourcc = V4L2_PIX_FMT_XBGR32,
725
- .fmt_type = FMT_RGB,
726
- .bpp = { 32 },
727
- .mplanes = 1,
728
- .write_format = MI_CTRL_SP_WRITE_PLA,
729
- .output_format = MI_CTRL_SP_OUTPUT_RGB888,
730
- }, {
731
- .fourcc = V4L2_PIX_FMT_RGB565,
732
- .fmt_type = FMT_RGB,
733
- .bpp = { 16 },
734
- .mplanes = 1,
735
- .write_format = MI_CTRL_SP_WRITE_PLA,
736
- .output_format = MI_CTRL_SP_OUTPUT_RGB565,
737
- },
738
- /* fbcg */
739
- {
740
- .fourcc = V4L2_PIX_FMT_FBCG,
741
- .fmt_type = FMT_FBCGAIN,
742
- .bpp = { 8, 16 },
743
- .cplanes = 2,
744
- .mplanes = 2,
745
- .uv_swap = 0,
746
- .write_format = MI_CTRL_SP_WRITE_SPLA,
747
- .output_format = MI_CTRL_SP_OUTPUT_YUV420,
442
+ if (isp_mis)
443
+ rkisp_dvbm_event(dev, CIF_ISP_V_START);
444
+ rkisp_bridge_update_mi(dev, isp_mis);
445
+
446
+ for (i = 0; i < RKISP_MAX_STREAM; i++) {
447
+ if (i == RKISP_STREAM_VIR || i == RKISP_STREAM_LUMA)
448
+ continue;
449
+ stream = &dev->cap_dev.stream[i];
450
+ if (stream->streaming &&
451
+ stream->ops && stream->ops->frame_start)
452
+ stream->ops->frame_start(stream, isp_mis);
748453 }
749
-};
454
+
455
+ return 0;
456
+}
457
+
458
+void rkisp_stream_buf_done_early(struct rkisp_device *dev)
459
+{
460
+ struct rkisp_stream *stream;
461
+ int i;
462
+
463
+ if (!dev->cap_dev.is_done_early)
464
+ return;
465
+
466
+ for (i = 0; i < RKISP_MAX_STREAM; i++) {
467
+ if (i == RKISP_STREAM_VIR || i == RKISP_STREAM_LUMA ||
468
+ i == RKISP_STREAM_DMATX0 || i == RKISP_STREAM_DMATX1 ||
469
+ i == RKISP_STREAM_DMATX2 || i == RKISP_STREAM_DMATX3)
470
+ continue;
471
+ stream = &dev->cap_dev.stream[i];
472
+ if (stream->streaming && !stream->stopping &&
473
+ stream->ops && stream->ops->frame_end)
474
+ stream->ops->frame_end(stream, FRAME_WORK);
475
+ }
476
+}
750477
751478 struct stream_config rkisp_mp_stream_config = {
752
- .fmts = mp_fmts,
753
- .fmt_size = ARRAY_SIZE(mp_fmts),
754479 /* constraints */
755480 .max_rsz_width = STREAM_MAX_MP_RSZ_OUTPUT_WIDTH,
756481 .max_rsz_height = STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT,
....@@ -802,12 +527,11 @@
802527 .cb_offs_cnt_init = CIF_MI_MP_CB_OFFS_CNT_INIT,
803528 .cr_offs_cnt_init = CIF_MI_MP_CR_OFFS_CNT_INIT,
804529 .y_base_ad_shd = CIF_MI_MP_Y_BASE_AD_SHD,
530
+ .y_pic_size = ISP3X_MI_MP_WR_Y_PIC_SIZE,
805531 },
806532 };
807533
808534 struct stream_config rkisp_sp_stream_config = {
809
- .fmts = sp_fmts,
810
- .fmt_size = ARRAY_SIZE(sp_fmts),
811535 /* constraints */
812536 .max_rsz_width = STREAM_MAX_SP_RSZ_OUTPUT_WIDTH,
813537 .max_rsz_height = STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT,
....@@ -859,6 +583,7 @@
859583 .cb_offs_cnt_init = CIF_MI_SP_CB_OFFS_CNT_INIT,
860584 .cr_offs_cnt_init = CIF_MI_SP_CR_OFFS_CNT_INIT,
861585 .y_base_ad_shd = CIF_MI_SP_Y_BASE_AD_SHD,
586
+ .y_pic_size = ISP3X_MI_SP_WR_Y_PIC_SIZE,
862587 },
863588 };
864589
....@@ -876,21 +601,40 @@
876601 return NULL;
877602 }
878603
879
-/*
880
- * Make sure max resize/output resolution is smaller than
881
- * isp sub device output size. This assumes it's not
882
- * recommended to use ISP scale-up function to get output size
883
- * that exceeds sensor max resolution.
884
- */
885
-static void restrict_rsz_resolution(struct rkisp_device *dev,
886
- const struct stream_config *config,
604
+static void restrict_rsz_resolution(struct rkisp_stream *stream,
605
+ const struct stream_config *cfg,
887606 struct v4l2_rect *max_rsz)
888607 {
889
- struct v4l2_rect *input_win;
608
+ struct rkisp_device *dev = stream->ispdev;
609
+ struct v4l2_rect *input_win = rkisp_get_isp_sd_win(&dev->isp_sdev);
890610
891
- input_win = rkisp_get_isp_sd_win(&dev->isp_sdev);
892
- max_rsz->width = min_t(int, input_win->width, config->max_rsz_width);
893
- max_rsz->height = min_t(int, input_win->height, config->max_rsz_height);
611
+ if (stream->id == RKISP_STREAM_VIR ||
612
+ (dev->isp_ver == ISP_V30 && stream->id == RKISP_STREAM_BP)) {
613
+ max_rsz->width = input_win->width;
614
+ max_rsz->height = input_win->height;
615
+ } else if (stream->id == RKISP_STREAM_FBC) {
616
+ max_rsz->width = stream->dcrop.width;
617
+ max_rsz->height = stream->dcrop.height;
618
+ } else if (stream->id == RKISP_STREAM_MPDS ||
619
+ stream->id == RKISP_STREAM_BPDS) {
620
+ struct rkisp_stream *t = &dev->cap_dev.stream[stream->conn_id];
621
+
622
+ max_rsz->width = t->out_fmt.width / 4;
623
+ max_rsz->height = t->out_fmt.height / 4;
624
+ } else if (stream->id == RKISP_STREAM_LUMA) {
625
+ u32 div = dev->is_bigmode ? 32 : 16;
626
+
627
+ max_rsz->width = ALIGN(DIV_ROUND_UP(input_win->width, div), 4);
628
+ max_rsz->height = DIV_ROUND_UP(input_win->height, div);
629
+ } else if (dev->hw_dev->unite) {
630
+ /* scale down only for unite mode */
631
+ max_rsz->width = min_t(int, input_win->width, cfg->max_rsz_width);
632
+ max_rsz->height = min_t(int, input_win->height, cfg->max_rsz_height);
633
+ } else {
634
+ /* scale up/down */
635
+ max_rsz->width = cfg->max_rsz_width;
636
+ max_rsz->height = cfg->max_rsz_height;
637
+ }
894638 }
895639
896640 static int rkisp_set_fmt(struct rkisp_stream *stream,
....@@ -898,18 +642,17 @@
898642 bool try)
899643 {
900644 const struct capture_fmt *fmt;
645
+ struct rkisp_vdev_node *node = &stream->vnode;
901646 const struct stream_config *config = stream->config;
902647 struct rkisp_device *dev = stream->ispdev;
903
- struct rkisp_stream *other_stream;
904
- unsigned int imagsize = 0;
905
- unsigned int planes;
906
- u32 xsubs = 1, ysubs = 1;
907
- unsigned int i;
648
+ struct v4l2_rect max_rsz;
649
+ u32 i, planes, imagsize = 0, xsubs = 1, ysubs = 1;
908650
909651 fmt = find_fmt(stream, pixm->pixelformat);
910652 if (!fmt) {
911
- v4l2_err(&stream->ispdev->v4l2_dev,
912
- "nonsupport pixelformat:%c%c%c%c\n",
653
+ v4l2_err(&dev->v4l2_dev,
654
+ "%s nonsupport pixelformat:%c%c%c%c\n",
655
+ node->vdev.name,
913656 pixm->pixelformat,
914657 pixm->pixelformat >> 8,
915658 pixm->pixelformat >> 16,
....@@ -917,51 +660,89 @@
917660 return -EINVAL;
918661 }
919662
663
+ /* do checks on resolution */
664
+ restrict_rsz_resolution(stream, config, &max_rsz);
920665 if (stream->id == RKISP_STREAM_MP ||
921
- stream->id == RKISP_STREAM_SP) {
922
- struct v4l2_rect max_rsz;
666
+ stream->id == RKISP_STREAM_SP ||
667
+ (stream->id == RKISP_STREAM_BP && dev->isp_ver != ISP_V30)) {
668
+ pixm->width = clamp_t(u32, pixm->width, config->min_rsz_width, max_rsz.width);
669
+ } else if (pixm->width != max_rsz.width &&
670
+ pixm->height != max_rsz.height &&
671
+ (stream->id == RKISP_STREAM_LUMA ||
672
+ (dev->isp_ver == ISP_V30 &&
673
+ (stream->id == RKISP_STREAM_BP || stream->id == RKISP_STREAM_FBC)))) {
674
+ v4l2_warn(&dev->v4l2_dev,
675
+ "%s no scale %dx%d should equal to %dx%d\n",
676
+ node->vdev.name,
677
+ pixm->width, pixm->height,
678
+ max_rsz.width, max_rsz.height);
679
+ pixm->width = max_rsz.width;
680
+ pixm->height = max_rsz.height;
681
+ } else if (stream->id == RKISP_STREAM_MPDS || stream->id == RKISP_STREAM_BPDS) {
682
+ struct rkisp_stream *t = &dev->cap_dev.stream[stream->conn_id];
923683
924
- other_stream = (stream->id == RKISP_STREAM_MP) ?
925
- &dev->cap_dev.stream[RKISP_STREAM_SP] :
926
- &dev->cap_dev.stream[RKISP_STREAM_MP];
927
- /* do checks on resolution */
928
- restrict_rsz_resolution(stream->ispdev, config, &max_rsz);
929
- pixm->width = clamp_t(u32, pixm->width,
930
- config->min_rsz_width, max_rsz.width);
931
- pixm->height = clamp_t(u32, pixm->height,
932
- config->min_rsz_height, max_rsz.height);
933
- } else {
934
- other_stream =
935
- &stream->ispdev->cap_dev.stream[RKISP_STREAM_MP];
684
+ if (pixm->pixelformat != t->out_fmt.pixelformat ||
685
+ pixm->width != max_rsz.width || pixm->height != max_rsz.height) {
686
+ v4l2_warn(&dev->v4l2_dev,
687
+ "%s from %s, force to %dx%d %c%c%c%c\n",
688
+ node->vdev.name, t->vnode.vdev.name,
689
+ max_rsz.width, max_rsz.height,
690
+ t->out_fmt.pixelformat,
691
+ t->out_fmt.pixelformat >> 8,
692
+ t->out_fmt.pixelformat >> 16,
693
+ t->out_fmt.pixelformat >> 24);
694
+ pixm->pixelformat = t->out_fmt.pixelformat;
695
+ pixm->width = max_rsz.width;
696
+ pixm->height = max_rsz.height;
697
+ }
698
+ } else if (stream->id == RKISP_STREAM_VIR) {
699
+ struct rkisp_stream *t;
700
+
701
+ if (stream->conn_id != -1) {
702
+ t = &dev->cap_dev.stream[stream->conn_id];
703
+ *pixm = t->out_fmt;
704
+ } else {
705
+ for (i = RKISP_STREAM_MP; i < RKISP_STREAM_VIR; i++) {
706
+ t = &dev->cap_dev.stream[i];
707
+ if (t->out_isp_fmt.fmt_type != FMT_YUV || !t->streaming)
708
+ continue;
709
+ if (t->out_fmt.plane_fmt[0].sizeimage > imagsize) {
710
+ imagsize = t->out_fmt.plane_fmt[0].sizeimage;
711
+ *pixm = t->out_fmt;
712
+ stream->conn_id = t->id;
713
+ }
714
+ }
715
+ }
716
+ if (stream->conn_id == -1) {
717
+ v4l2_err(&dev->v4l2_dev, "no output stream for iqtool\n");
718
+ return -EINVAL;
719
+ }
720
+ imagsize = 0;
936721 }
722
+
937723 pixm->num_planes = fmt->mplanes;
938724 pixm->field = V4L2_FIELD_NONE;
939725 /* get quantization from ispsd */
940726 pixm->quantization = stream->ispdev->isp_sdev.quantization;
941
-
942
- /* output full range by default, take effect in isp_params */
943
- if (!pixm->quantization)
944
- pixm->quantization = V4L2_QUANTIZATION_FULL_RANGE;
945
- /* can not change quantization when stream-on */
946
- if (other_stream->streaming)
947
- pixm->quantization = other_stream->out_fmt.quantization;
948727
949728 /* calculate size */
950729 rkisp_fcc_xysubs(fmt->fourcc, &xsubs, &ysubs);
951730 planes = fmt->cplanes ? fmt->cplanes : fmt->mplanes;
952731 for (i = 0; i < planes; i++) {
953732 struct v4l2_plane_pix_format *plane_fmt;
954
- unsigned int width, height, bytesperline;
733
+ unsigned int width, height, bytesperline, w, h;
955734
956735 plane_fmt = pixm->plane_fmt + i;
957736
958
- if (i == 0) {
959
- width = pixm->width;
960
- height = pixm->height;
961
- } else {
962
- width = pixm->width / xsubs;
963
- height = pixm->height / ysubs;
964
- }
737
+ w = (fmt->fmt_type == FMT_FBC) ?
738
+ ALIGN(pixm->width, 16) : pixm->width;
739
+ h = (fmt->fmt_type == FMT_FBC) ?
740
+ ALIGN(pixm->height, 16) : pixm->height;
741
+ /* mainpath for warp default */
742
+ if (dev->cap_dev.wrap_line && stream->id == RKISP_STREAM_MP)
743
+ h = dev->cap_dev.wrap_line;
744
+ width = i ? w / xsubs : w;
745
+ height = i ? h / ysubs : h;
965746
966747 if (dev->isp_ver == ISP_V20 &&
967748 fmt->fmt_type == FMT_BAYER &&
....@@ -978,20 +759,28 @@
978759 bytesperline = ALIGN(width * fmt->bpp[i] / 8, 256);
979760 else
980761 bytesperline = width * DIV_ROUND_UP(fmt->bpp[i], 8);
981
- /* 128bit AXI, 16byte align for bytesperline */
982
- if (dev->isp_ver >= ISP_V20 && stream->id == RKISP_STREAM_SP)
983
- bytesperline = ALIGN(bytesperline, 16);
984
- /* stride is only available for sp stream and y plane */
985
- if (stream->id != RKISP_STREAM_SP || i != 0 ||
986
- plane_fmt->bytesperline < bytesperline)
762
+
763
+ if (i != 0 || plane_fmt->bytesperline < bytesperline)
987764 plane_fmt->bytesperline = bytesperline;
765
+
766
+ /* 128bit AXI, 16byte align for bytesperline */
767
+ if ((dev->isp_ver == ISP_V20 && stream->id == RKISP_STREAM_SP) ||
768
+ dev->isp_ver >= ISP_V30)
769
+ plane_fmt->bytesperline = ALIGN(plane_fmt->bytesperline, 16);
988770
989771 plane_fmt->sizeimage = plane_fmt->bytesperline * height;
990772
991
- /* uv address is y size offset need 64 align */
773
+ /* FMT_FBCGAIN: uv address is y size offset need 64 align
774
+ * FMT_FBC: width and height need 16 align
775
+ * header: width * height / 16, and 4096 align for mpp
776
+ * payload: yuv420 or yuv422 size
777
+ */
992778 if (fmt->fmt_type == FMT_FBCGAIN && i == 0)
993779 plane_fmt->sizeimage = ALIGN(plane_fmt->sizeimage, 64);
994
-
780
+ else if (fmt->fmt_type == FMT_FBC && i == 0)
781
+ plane_fmt->sizeimage = ALIGN(plane_fmt->sizeimage >> 4, RK_MPP_ALIGN);
782
+ else if (fmt->fmt_type == FMT_FBC)
783
+ plane_fmt->sizeimage += w * h;
995784 imagsize += plane_fmt->sizeimage;
996785 }
997786
....@@ -1015,22 +804,29 @@
1015804 }
1016805
1017806 v4l2_dbg(1, rkisp_debug, &stream->ispdev->v4l2_dev,
1018
- "%s: stream: %d req(%d, %d) out(%d, %d)\n", __func__,
1019
- stream->id, pixm->width, pixm->height,
807
+ "%s: %s req(%d, %d) out(%d, %d)\n", __func__,
808
+ node->vdev.name, pixm->width, pixm->height,
1020809 stream->out_fmt.width, stream->out_fmt.height);
1021810 }
1022811
1023812 return 0;
1024813 }
1025814
815
+struct rockit_isp_ops rockit_isp_ops = {
816
+ .rkisp_set_fmt = rkisp_set_fmt,
817
+};
818
+
1026819 int rkisp_fh_open(struct file *filp)
1027820 {
1028821 struct rkisp_stream *stream = video_drvdata(filp);
1029822 int ret;
1030823
824
+ if (!stream->ispdev->is_probe_end)
825
+ return -EINVAL;
826
+
1031827 ret = v4l2_fh_open(filp);
1032828 if (!ret) {
1033
- ret = v4l2_pipeline_pm_use(&stream->vnode.vdev.entity, 1);
829
+ ret = v4l2_pipeline_pm_get(&stream->vnode.vdev.entity);
1034830 if (ret < 0)
1035831 vb2_fop_release(filp);
1036832 }
....@@ -1044,12 +840,8 @@
1044840 int ret;
1045841
1046842 ret = vb2_fop_release(file);
1047
- if (!ret) {
1048
- ret = v4l2_pipeline_pm_use(&stream->vnode.vdev.entity, 0);
1049
- if (ret < 0)
1050
- v4l2_err(&stream->ispdev->v4l2_dev,
1051
- "set pipeline power failed %d\n", ret);
1052
- }
843
+ if (!ret)
844
+ v4l2_pipeline_pm_put(&stream->vnode.vdev.entity);
1053845 return ret;
1054846 }
1055847
....@@ -1066,14 +858,15 @@
1066858 pixm.pixelformat = stream->out_isp_fmt.fourcc;
1067859 if (!pixm.pixelformat)
1068860 return;
1069
- pixm.width = width;
1070
- pixm.height = height;
1071
- rkisp_set_fmt(stream, &pixm, false);
1072861
1073862 stream->dcrop.left = 0;
1074863 stream->dcrop.top = 0;
1075864 stream->dcrop.width = width;
1076865 stream->dcrop.height = height;
866
+
867
+ pixm.width = width;
868
+ pixm.height = height;
869
+ rkisp_set_fmt(stream, &pixm, false);
1077870 }
1078871
1079872 /************************* v4l2_file_operations***************************/
....@@ -1119,8 +912,9 @@
1119912 const struct stream_config *config = stream->config;
1120913 struct v4l2_frmsize_stepwise *s = &fsize->stepwise;
1121914 struct v4l2_frmsize_discrete *d = &fsize->discrete;
1122
- const struct ispsd_out_fmt *input_isp_fmt;
915
+ struct rkisp_device *dev = stream->ispdev;
1123916 struct v4l2_rect max_rsz;
917
+ struct v4l2_rect *input_win = rkisp_get_isp_sd_win(&dev->isp_sdev);
1124918
1125919 if (fsize->index != 0)
1126920 return -EINVAL;
....@@ -1128,10 +922,15 @@
1128922 if (!find_fmt(stream, fsize->pixel_format))
1129923 return -EINVAL;
1130924
1131
- restrict_rsz_resolution(stream->ispdev, config, &max_rsz);
925
+ restrict_rsz_resolution(stream, config, &max_rsz);
1132926
1133
- input_isp_fmt = rkisp_get_ispsd_out_fmt(&stream->ispdev->isp_sdev);
1134
- if (input_isp_fmt->fmt_type == FMT_BAYER) {
927
+ if (stream->out_isp_fmt.fmt_type == FMT_BAYER ||
928
+ stream->id == RKISP_STREAM_FBC ||
929
+ stream->id == RKISP_STREAM_BPDS ||
930
+ stream->id == RKISP_STREAM_MPDS ||
931
+ stream->id == RKISP_STREAM_LUMA ||
932
+ stream->id == RKISP_STREAM_VIR ||
933
+ (stream->id == RKISP_STREAM_BP && dev->hw_dev->isp_ver == ISP_V30)) {
1135934 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
1136935 d->width = max_rsz.width;
1137936 d->height = max_rsz.height;
....@@ -1139,13 +938,286 @@
1139938 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
1140939 s->min_width = STREAM_MIN_RSZ_OUTPUT_WIDTH;
1141940 s->min_height = STREAM_MIN_RSZ_OUTPUT_HEIGHT;
1142
- s->max_width = max_rsz.width;
1143
- s->max_height = max_rsz.height;
941
+ s->max_width = min_t(u32, max_rsz.width, input_win->width);
942
+ s->max_height = input_win->height;
1144943 s->step_width = STREAM_OUTPUT_STEP_WISE;
1145944 s->step_height = STREAM_OUTPUT_STEP_WISE;
1146945 }
1147946
1148947 return 0;
948
+}
949
+
950
+static int rkisp_get_cmsk(struct rkisp_stream *stream, struct rkisp_cmsk_cfg *cfg)
951
+{
952
+ struct rkisp_device *dev = stream->ispdev;
953
+ unsigned long lock_flags = 0;
954
+ u32 i, win_en, mode;
955
+
956
+ if ((dev->isp_ver != ISP_V30 && dev->isp_ver != ISP_V32) ||
957
+ stream->id == RKISP_STREAM_FBC ||
958
+ stream->id == RKISP_STREAM_MPDS ||
959
+ stream->id == RKISP_STREAM_BPDS) {
960
+ v4l2_err(&dev->v4l2_dev, "%s not support\n", __func__);
961
+ return -EINVAL;
962
+ }
963
+
964
+ spin_lock_irqsave(&dev->cmsk_lock, lock_flags);
965
+ *cfg = dev->cmsk_cfg;
966
+ spin_unlock_irqrestore(&dev->cmsk_lock, lock_flags);
967
+
968
+ switch (stream->id) {
969
+ case RKISP_STREAM_MP:
970
+ win_en = cfg->win[0].win_en;
971
+ mode = cfg->win[0].mode;
972
+ break;
973
+ case RKISP_STREAM_SP:
974
+ win_en = cfg->win[1].win_en;
975
+ mode = cfg->win[1].mode;
976
+ break;
977
+ case RKISP_STREAM_BP:
978
+ default:
979
+ win_en = cfg->win[2].win_en;
980
+ mode = cfg->win[2].mode;
981
+ break;
982
+ }
983
+
984
+ cfg->width_ro = dev->isp_sdev.out_crop.width;
985
+ cfg->height_ro = dev->isp_sdev.out_crop.height;
986
+ for (i = 0; i < RKISP_CMSK_WIN_MAX; i++) {
987
+ cfg->win[i].win_en = !!(win_en & BIT(i));
988
+ cfg->win[i].mode = !!(mode & BIT(i));
989
+ }
990
+
991
+ return 0;
992
+}
993
+
994
+static int rkisp_set_cmsk(struct rkisp_stream *stream, struct rkisp_cmsk_cfg *cfg)
995
+{
996
+ struct rkisp_device *dev = stream->ispdev;
997
+ unsigned long lock_flags = 0;
998
+ u16 i, win_en = 0, mode = 0;
999
+ u16 h_offs, v_offs, h_size, v_size;
1000
+ u32 width = dev->isp_sdev.out_crop.width;
1001
+ u32 height = dev->isp_sdev.out_crop.height;
1002
+ u32 align = (dev->isp_ver == ISP_V30) ? 8 : 2;
1003
+ bool warn = false;
1004
+
1005
+ if ((dev->isp_ver != ISP_V30 && dev->isp_ver != ISP_V32) ||
1006
+ stream->id == RKISP_STREAM_FBC ||
1007
+ stream->id == RKISP_STREAM_MPDS ||
1008
+ stream->id == RKISP_STREAM_BPDS) {
1009
+ v4l2_err(&dev->v4l2_dev, "%s not support\n", __func__);
1010
+ return -EINVAL;
1011
+ }
1012
+
1013
+ spin_lock_irqsave(&dev->cmsk_lock, lock_flags);
1014
+ dev->is_cmsk_upd = true;
1015
+ for (i = 0; i < RKISP_CMSK_WIN_MAX; i++) {
1016
+ win_en |= cfg->win[i].win_en ? BIT(i) : 0;
1017
+ mode |= cfg->win[i].mode ? BIT(i) : 0;
1018
+
1019
+ if (cfg->win[i].win_en) {
1020
+ if (cfg->win[i].mode) {
1021
+ dev->cmsk_cfg.win[i].cover_color_y = cfg->win[i].cover_color_y;
1022
+ dev->cmsk_cfg.win[i].cover_color_u = cfg->win[i].cover_color_u;
1023
+ dev->cmsk_cfg.win[i].cover_color_v = cfg->win[i].cover_color_v;
1024
+ }
1025
+ h_offs = cfg->win[i].h_offs & ~0x1;
1026
+ v_offs = cfg->win[i].v_offs & ~0x1;
1027
+ h_size = ALIGN_DOWN(cfg->win[i].h_size, align);
1028
+ v_size = ALIGN_DOWN(cfg->win[i].v_size, align);
1029
+ if (h_offs != cfg->win[i].h_offs ||
1030
+ v_offs != cfg->win[i].v_offs ||
1031
+ h_size != cfg->win[i].h_size ||
1032
+ v_size != cfg->win[i].v_size)
1033
+ warn = true;
1034
+ if (h_offs + h_size > width) {
1035
+ h_size = ALIGN_DOWN(width - h_offs, align);
1036
+ warn = true;
1037
+ }
1038
+ if (v_offs + v_size > height) {
1039
+ v_size = ALIGN_DOWN(height - v_offs, align);
1040
+ warn = true;
1041
+ }
1042
+ if (warn) {
1043
+ warn = false;
1044
+ v4l2_warn(&dev->v4l2_dev,
1045
+ "%s cmsk offs 2 align, size %d align and offs + size < resolution\n"
1046
+ "\t cmsk win%d result to offs:%d %d, size:%d %d\n",
1047
+ stream->vnode.vdev.name, i, align, h_offs, v_offs, h_size, v_size);
1048
+ }
1049
+ dev->cmsk_cfg.win[i].h_offs = h_offs;
1050
+ dev->cmsk_cfg.win[i].v_offs = v_offs;
1051
+ dev->cmsk_cfg.win[i].h_size = h_size;
1052
+ dev->cmsk_cfg.win[i].v_size = v_size;
1053
+ }
1054
+ }
1055
+
1056
+ switch (stream->id) {
1057
+ case RKISP_STREAM_MP:
1058
+ dev->cmsk_cfg.win[0].win_en = win_en;
1059
+ dev->cmsk_cfg.win[0].mode = mode;
1060
+ break;
1061
+ case RKISP_STREAM_SP:
1062
+ dev->cmsk_cfg.win[1].win_en = win_en;
1063
+ dev->cmsk_cfg.win[1].mode = mode;
1064
+ break;
1065
+ case RKISP_STREAM_BP:
1066
+ default:
1067
+ dev->cmsk_cfg.win[2].win_en = win_en;
1068
+ dev->cmsk_cfg.win[2].mode = mode;
1069
+ break;
1070
+ }
1071
+ dev->cmsk_cfg.mosaic_block = cfg->mosaic_block;
1072
+ spin_unlock_irqrestore(&dev->cmsk_lock, lock_flags);
1073
+ return 0;
1074
+
1075
+}
1076
+
1077
+static int rkisp_get_stream_info(struct rkisp_stream *stream,
1078
+ struct rkisp_stream_info *info)
1079
+{
1080
+ struct rkisp_device *dev = stream->ispdev;
1081
+ u32 id = 0;
1082
+
1083
+ rkisp_dmarx_get_frame(stream->ispdev, &id, NULL, NULL, true);
1084
+ info->cur_frame_id = stream->dbg.id;
1085
+ info->input_frame_loss = dev->isp_sdev.dbg.frameloss;
1086
+ info->output_frame_loss = stream->dbg.frameloss;
1087
+ info->stream_on = stream->streaming;
1088
+ info->stream_id = stream->id;
1089
+ return 0;
1090
+}
1091
+
1092
+static int rkisp_get_mirror_flip(struct rkisp_stream *stream,
1093
+ struct rkisp_mirror_flip *cfg)
1094
+{
1095
+ struct rkisp_device *dev = stream->ispdev;
1096
+
1097
+ if (dev->isp_ver != ISP_V32)
1098
+ return -EINVAL;
1099
+
1100
+ cfg->mirror = dev->cap_dev.is_mirror;
1101
+ cfg->flip = stream->is_flip;
1102
+ return 0;
1103
+}
1104
+
1105
+static int rkisp_set_mirror_flip(struct rkisp_stream *stream,
1106
+ struct rkisp_mirror_flip *cfg)
1107
+{
1108
+ struct rkisp_device *dev = stream->ispdev;
1109
+
1110
+ if (dev->isp_ver != ISP_V32)
1111
+ return -EINVAL;
1112
+
1113
+ if (dev->cap_dev.wrap_line) {
1114
+ v4l2_warn(&dev->v4l2_dev, "wrap_line mode can not set the mirror");
1115
+ dev->cap_dev.is_mirror = 0;
1116
+ } else {
1117
+ dev->cap_dev.is_mirror = cfg->mirror;
1118
+ }
1119
+
1120
+ stream->is_flip = cfg->flip;
1121
+ stream->is_mf_upd = true;
1122
+ return 0;
1123
+}
1124
+
1125
+static int rkisp_get_wrap_line(struct rkisp_stream *stream, struct rkisp_wrap_info *arg)
1126
+{
1127
+ struct rkisp_device *dev = stream->ispdev;
1128
+
1129
+ if (dev->isp_ver != ISP_V32 && stream->id != RKISP_STREAM_MP)
1130
+ return -EINVAL;
1131
+
1132
+ arg->width = dev->cap_dev.wrap_width;
1133
+ arg->height = dev->cap_dev.wrap_line;
1134
+ return 0;
1135
+}
1136
+
1137
+static int rkisp_set_wrap_line(struct rkisp_stream *stream, struct rkisp_wrap_info *arg)
1138
+{
1139
+ struct rkisp_device *dev = stream->ispdev;
1140
+
1141
+ if (dev->isp_ver != ISP_V32 ||
1142
+ dev->hw_dev->dev_link_num > 1 ||
1143
+ !stream->ops->set_wrap ||
1144
+ dev->hw_dev->unite) {
1145
+ v4l2_err(&dev->v4l2_dev,
1146
+ "wrap only support for single sensor and mainpath\n");
1147
+ return -EINVAL;
1148
+ }
1149
+ dev->cap_dev.wrap_width = arg->width;
1150
+ return stream->ops->set_wrap(stream, arg->height);
1151
+}
1152
+
1153
+static int rkisp_set_fps(struct rkisp_stream *stream, int *fps)
1154
+{
1155
+ struct rkisp_device *dev = stream->ispdev;
1156
+
1157
+ if (dev->isp_ver != ISP_V32)
1158
+ return -EINVAL;
1159
+
1160
+ return rkisp_rockit_fps_set(fps, stream);
1161
+}
1162
+
1163
+static int rkisp_get_fps(struct rkisp_stream *stream, int *fps)
1164
+{
1165
+ struct rkisp_device *dev = stream->ispdev;
1166
+
1167
+ if (dev->isp_ver != ISP_V32)
1168
+ return -EINVAL;
1169
+
1170
+ return rkisp_rockit_fps_get(fps, stream);
1171
+}
1172
+
1173
+int rkisp_get_tb_stream_info(struct rkisp_stream *stream,
1174
+ struct rkisp_tb_stream_info *info)
1175
+{
1176
+ struct rkisp_device *dev = stream->ispdev;
1177
+
1178
+ if (stream->id != RKISP_STREAM_MP) {
1179
+ v4l2_err(&dev->v4l2_dev, "fast only support for MP\n");
1180
+ return -EINVAL;
1181
+ }
1182
+
1183
+ if (!dev->tb_stream_info.buf_max) {
1184
+ v4l2_err(&dev->v4l2_dev, "thunderboot no enough memory for image\n");
1185
+ return -EINVAL;
1186
+ }
1187
+
1188
+ memcpy(info, &dev->tb_stream_info, sizeof(*info));
1189
+ return 0;
1190
+}
1191
+
1192
+int rkisp_free_tb_stream_buf(struct rkisp_stream *stream)
1193
+{
1194
+ struct rkisp_device *dev = stream->ispdev;
1195
+ struct rkisp_isp_subdev *sdev = &dev->isp_sdev;
1196
+ struct v4l2_subdev *sd = &sdev->sd;
1197
+
1198
+ return sd->ops->core->ioctl(sd, RKISP_CMD_FREE_SHARED_BUF, NULL);
1199
+}
1200
+
1201
+static int rkisp_set_iqtool_connect_id(struct rkisp_stream *stream, int stream_id)
1202
+{
1203
+ struct rkisp_device *dev = stream->ispdev;
1204
+
1205
+ if (stream->id != RKISP_STREAM_VIR) {
1206
+ v4l2_err(&dev->v4l2_dev, "only support for iqtool video\n");
1207
+ goto err;
1208
+ }
1209
+
1210
+ if (stream_id != RKISP_STREAM_MP &&
1211
+ stream_id != RKISP_STREAM_SP &&
1212
+ stream_id != RKISP_STREAM_BP) {
1213
+ v4l2_err(&dev->v4l2_dev, "invalid connect stream id\n");
1214
+ goto err;
1215
+ }
1216
+
1217
+ stream->conn_id = stream_id;
1218
+ return 0;
1219
+err:
1220
+ return -EINVAL;
11491221 }
11501222
11511223 static long rkisp_ioctl_default(struct file *file, void *fh,
....@@ -1154,7 +1226,7 @@
11541226 struct rkisp_stream *stream = video_drvdata(file);
11551227 long ret = 0;
11561228
1157
- if (!arg)
1229
+ if (!arg && cmd != RKISP_CMD_FREE_TB_STREAM_BUF)
11581230 return -EINVAL;
11591231
11601232 switch (cmd) {
....@@ -1184,6 +1256,42 @@
11841256 else
11851257 stream->memory =
11861258 SW_CSI_RWA_WR_SIMG_SWP | SW_CSI_RAW_WR_SIMG_MODE;
1259
+ break;
1260
+ case RKISP_CMD_GET_CMSK:
1261
+ ret = rkisp_get_cmsk(stream, arg);
1262
+ break;
1263
+ case RKISP_CMD_SET_CMSK:
1264
+ ret = rkisp_set_cmsk(stream, arg);
1265
+ break;
1266
+ case RKISP_CMD_GET_STREAM_INFO:
1267
+ ret = rkisp_get_stream_info(stream, arg);
1268
+ break;
1269
+ case RKISP_CMD_GET_MIRROR_FLIP:
1270
+ ret = rkisp_get_mirror_flip(stream, arg);
1271
+ break;
1272
+ case RKISP_CMD_SET_MIRROR_FLIP:
1273
+ ret = rkisp_set_mirror_flip(stream, arg);
1274
+ break;
1275
+ case RKISP_CMD_GET_WRAP_LINE:
1276
+ ret = rkisp_get_wrap_line(stream, arg);
1277
+ break;
1278
+ case RKISP_CMD_SET_WRAP_LINE:
1279
+ ret = rkisp_set_wrap_line(stream, arg);
1280
+ break;
1281
+ case RKISP_CMD_SET_FPS:
1282
+ ret = rkisp_set_fps(stream, arg);
1283
+ break;
1284
+ case RKISP_CMD_GET_FPS:
1285
+ ret = rkisp_get_fps(stream, arg);
1286
+ break;
1287
+ case RKISP_CMD_GET_TB_STREAM_INFO:
1288
+ ret = rkisp_get_tb_stream_info(stream, arg);
1289
+ break;
1290
+ case RKISP_CMD_FREE_TB_STREAM_BUF:
1291
+ ret = rkisp_free_tb_stream_buf(stream);
1292
+ break;
1293
+ case RKISP_CMD_SET_IQTOOL_CONN_ID:
1294
+ ret = rkisp_set_iqtool_connect_id(stream, *(int *)arg);
11871295 break;
11881296 default:
11891297 ret = -EINVAL;
....@@ -1235,12 +1343,67 @@
12351343 {
12361344 struct rkisp_stream *stream = video_drvdata(file);
12371345 const struct capture_fmt *fmt = NULL;
1346
+ struct rkisp_device *dev = stream->ispdev;
1347
+ struct ispsd_in_fmt *isp_in_fmt = &dev->isp_sdev.in_fmt;
1348
+ struct ispsd_out_fmt *isp_out_fmt = &dev->isp_sdev.out_fmt;
1349
+ int ret = -EINVAL;
1350
+
1351
+ /* only one output format for raw */
1352
+ if (isp_out_fmt->fmt_type == FMT_BAYER ||
1353
+ stream->id == RKISP_STREAM_DMATX0 ||
1354
+ stream->id == RKISP_STREAM_DMATX1 ||
1355
+ stream->id == RKISP_STREAM_DMATX2 ||
1356
+ stream->id == RKISP_STREAM_DMATX3) {
1357
+ u32 pixelformat = rkisp_mbus_pixelcode_to_v4l2(isp_in_fmt->mbus_code);
1358
+
1359
+ if (f->index == 0) {
1360
+ fmt = find_fmt(stream, pixelformat);
1361
+ if (fmt) {
1362
+ f->pixelformat = pixelformat;
1363
+ ret = 0;
1364
+ }
1365
+ }
1366
+ return ret;
1367
+ }
12381368
12391369 if (f->index >= stream->config->fmt_size)
12401370 return -EINVAL;
12411371
12421372 fmt = &stream->config->fmts[f->index];
1373
+ /* only output yuv format */
1374
+ if (isp_out_fmt->fmt_type == FMT_YUV && fmt->fmt_type == FMT_BAYER)
1375
+ return -EINVAL;
1376
+
12431377 f->pixelformat = fmt->fourcc;
1378
+ switch (f->pixelformat) {
1379
+ case V4L2_PIX_FMT_FBC2:
1380
+ strscpy(f->description,
1381
+ "Rockchip yuv422sp fbc encoder",
1382
+ sizeof(f->description));
1383
+ break;
1384
+ case V4L2_PIX_FMT_FBC0:
1385
+ strscpy(f->description,
1386
+ "Rockchip yuv420sp fbc encoder",
1387
+ sizeof(f->description));
1388
+ break;
1389
+ case V4L2_PIX_FMT_FBCG:
1390
+ strscpy(f->description,
1391
+ "Rockchip fbc gain",
1392
+ sizeof(f->description));
1393
+ break;
1394
+ case V4l2_PIX_FMT_EBD8:
1395
+ strscpy(f->description,
1396
+ "Embedded data 8-bit",
1397
+ sizeof(f->description));
1398
+ break;
1399
+ case V4l2_PIX_FMT_SPD16:
1400
+ strscpy(f->description,
1401
+ "Shield pix data 16-bit",
1402
+ sizeof(f->description));
1403
+ break;
1404
+ default:
1405
+ break;
1406
+ }
12441407
12451408 return 0;
12461409 }
....@@ -1302,13 +1465,19 @@
13021465 struct v4l2_rect *sel,
13031466 const struct v4l2_rect *in)
13041467 {
1468
+ struct rkisp_device *dev = stream->ispdev;
1469
+ bool is_unite = !!dev->hw_dev->unite;
1470
+ u32 align = is_unite ? 4 : 2;
1471
+
13051472 /* Not crop for MP bayer raw data and dmatx path */
13061473 if ((stream->id == RKISP_STREAM_MP &&
13071474 stream->out_isp_fmt.fmt_type == FMT_BAYER) ||
13081475 stream->id == RKISP_STREAM_DMATX0 ||
13091476 stream->id == RKISP_STREAM_DMATX1 ||
13101477 stream->id == RKISP_STREAM_DMATX2 ||
1311
- stream->id == RKISP_STREAM_DMATX3) {
1478
+ stream->id == RKISP_STREAM_DMATX3 ||
1479
+ stream->id == RKISP_STREAM_MPDS ||
1480
+ stream->id == RKISP_STREAM_BPDS) {
13121481 sel->left = 0;
13131482 sel->top = 0;
13141483 sel->width = in->width;
....@@ -1317,7 +1486,7 @@
13171486 }
13181487
13191488 sel->left = ALIGN(sel->left, 2);
1320
- sel->width = ALIGN(sel->width, 2);
1489
+ sel->width = ALIGN(sel->width, align);
13211490 sel->left = clamp_t(u32, sel->left, 0,
13221491 in->width - STREAM_MIN_MP_SP_INPUT_WIDTH);
13231492 sel->top = clamp_t(u32, sel->top, 0,
....@@ -1326,6 +1495,13 @@
13261495 in->width - sel->left);
13271496 sel->height = clamp_t(u32, sel->height, STREAM_MIN_MP_SP_INPUT_HEIGHT,
13281497 in->height - sel->top);
1498
+ if (is_unite && (sel->width + 2 * sel->left) != in->width) {
1499
+ sel->left = ALIGN_DOWN((in->width - sel->width) / 2, 2);
1500
+ v4l2_warn(&dev->v4l2_dev,
1501
+ "try horizontal center crop(%d,%d)/%dx%d for dual isp\n",
1502
+ sel->left, sel->top, sel->width, sel->height);
1503
+ }
1504
+ stream->is_crop_upd = true;
13291505 return sel;
13301506 }
13311507
....@@ -1333,18 +1509,9 @@
13331509 struct v4l2_selection *sel)
13341510 {
13351511 struct rkisp_stream *stream = video_drvdata(file);
1336
- struct video_device *vdev = &stream->vnode.vdev;
1337
- struct rkisp_vdev_node *node = vdev_to_node(vdev);
13381512 struct rkisp_device *dev = stream->ispdev;
13391513 struct v4l2_rect *dcrop = &stream->dcrop;
13401514 const struct v4l2_rect *input_win;
1341
-
1342
- if (vb2_is_busy(&node->buf_queue)) {
1343
- v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__);
1344
- return -EBUSY;
1345
- }
1346
-
1347
- input_win = rkisp_get_isp_sd_win(&dev->isp_sdev);
13481515
13491516 if (sel->target != V4L2_SEL_TGT_CROP)
13501517 return -EINVAL;
....@@ -1352,6 +1519,7 @@
13521519 if (sel->flags != 0)
13531520 return -EINVAL;
13541521
1522
+ input_win = rkisp_get_isp_sd_win(&dev->isp_sdev);
13551523 *dcrop = *rkisp_update_crop(stream, &sel->r, input_win);
13561524 v4l2_dbg(1, rkisp_debug, &dev->v4l2_dev,
13571525 "stream %d crop(%d,%d)/%dx%d\n", stream->id,
....@@ -1389,7 +1557,7 @@
13891557 .vidioc_streamoff = vb2_ioctl_streamoff,
13901558 .vidioc_enum_input = rkisp_enum_input,
13911559 .vidioc_try_fmt_vid_cap_mplane = rkisp_try_fmt_vid_cap_mplane,
1392
- .vidioc_enum_fmt_vid_cap_mplane = rkisp_enum_fmt_vid_cap_mplane,
1560
+ .vidioc_enum_fmt_vid_cap = rkisp_enum_fmt_vid_cap_mplane,
13931561 .vidioc_s_fmt_vid_cap_mplane = rkisp_s_fmt_vid_cap_mplane,
13941562 .vidioc_g_fmt_vid_cap_mplane = rkisp_g_fmt_vid_cap_mplane,
13951563 .vidioc_s_selection = rkisp_s_selection,
....@@ -1400,8 +1568,78 @@
14001568 .vidioc_default = rkisp_ioctl_default,
14011569 };
14021570
1571
+static void rkisp_buf_done_task(unsigned long arg)
1572
+{
1573
+ struct rkisp_stream *stream = (struct rkisp_stream *)arg;
1574
+ struct rkisp_buffer *buf = NULL;
1575
+ unsigned long lock_flags = 0;
1576
+ LIST_HEAD(local_list);
1577
+
1578
+ spin_lock_irqsave(&stream->vbq_lock, lock_flags);
1579
+ list_replace_init(&stream->buf_done_list, &local_list);
1580
+ spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
1581
+
1582
+ while (!list_empty(&local_list)) {
1583
+ buf = list_first_entry(&local_list,
1584
+ struct rkisp_buffer, queue);
1585
+ list_del(&buf->queue);
1586
+
1587
+ v4l2_dbg(2, rkisp_debug, &stream->ispdev->v4l2_dev,
1588
+ "stream:%d seq:%d buf:0x%x done\n",
1589
+ stream->id, buf->vb.sequence, buf->buff_addr[0]);
1590
+ vb2_buffer_done(&buf->vb.vb2_buf,
1591
+ stream->streaming ? VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR);
1592
+ }
1593
+}
1594
+
1595
+void rkisp_stream_buf_done(struct rkisp_stream *stream,
1596
+ struct rkisp_buffer *buf)
1597
+{
1598
+ unsigned long lock_flags = 0;
1599
+
1600
+ if (!stream || !buf)
1601
+ return;
1602
+ spin_lock_irqsave(&stream->vbq_lock, lock_flags);
1603
+ list_add_tail(&buf->queue, &stream->buf_done_list);
1604
+ spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
1605
+ tasklet_schedule(&stream->buf_done_tasklet);
1606
+}
1607
+
1608
+static void rkisp_stream_fast(struct work_struct *work)
1609
+{
1610
+ struct rkisp_capture_device *cap_dev =
1611
+ container_of(work, struct rkisp_capture_device, fast_work);
1612
+ struct rkisp_stream *stream = &cap_dev->stream[0];
1613
+ struct rkisp_device *ispdev = cap_dev->ispdev;
1614
+ struct v4l2_subdev *sd = ispdev->active_sensor->sd;
1615
+ int ret;
1616
+
1617
+ if (ispdev->isp_ver != ISP_V32)
1618
+ return;
1619
+
1620
+ mutex_lock(&ispdev->hw_dev->dev_lock);
1621
+ rkisp_chk_tb_over(ispdev);
1622
+ mutex_unlock(&ispdev->hw_dev->dev_lock);
1623
+ if (ispdev->tb_head.complete != RKISP_TB_OK)
1624
+ return;
1625
+ ret = v4l2_pipeline_pm_get(&stream->vnode.vdev.entity);
1626
+ if (ret < 0) {
1627
+ dev_err(ispdev->dev, "%s PM get fail:%d\n", __func__, ret);
1628
+ ispdev->is_thunderboot = false;
1629
+ return;
1630
+ }
1631
+
1632
+ if (ispdev->hw_dev->dev_num > 1)
1633
+ ispdev->hw_dev->is_single = false;
1634
+ ispdev->is_pre_on = true;
1635
+ ispdev->is_rdbk_auto = true;
1636
+ ispdev->pipe.open(&ispdev->pipe, &stream->vnode.vdev.entity, true);
1637
+ v4l2_subdev_call(sd, video, s_stream, true);
1638
+}
1639
+
14031640 void rkisp_unregister_stream_vdev(struct rkisp_stream *stream)
14041641 {
1642
+ tasklet_kill(&stream->buf_done_tasklet);
14051643 media_entity_cleanup(&stream->vnode.vdev.entity);
14061644 video_unregister_device(&stream->vnode.vdev);
14071645 }
....@@ -1431,7 +1669,7 @@
14311669 node->pad.flags = MEDIA_PAD_FL_SINK;
14321670 vdev->queue = &node->buf_queue;
14331671
1434
- ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1672
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
14351673 if (ret < 0) {
14361674 v4l2_err(v4l2_dev,
14371675 "video_register_device failed with error %d\n", ret);
....@@ -1461,6 +1699,11 @@
14611699 sink, 0, stream->linked);
14621700 if (ret < 0)
14631701 goto unreg;
1702
+ INIT_LIST_HEAD(&stream->buf_done_list);
1703
+ tasklet_init(&stream->buf_done_tasklet,
1704
+ rkisp_buf_done_task,
1705
+ (unsigned long)stream);
1706
+ tasklet_disable(&stream->buf_done_tasklet);
14641707 return 0;
14651708 unreg:
14661709 video_unregister_device(vdev);
....@@ -1470,18 +1713,55 @@
14701713 int rkisp_register_stream_vdevs(struct rkisp_device *dev)
14711714 {
14721715 struct rkisp_capture_device *cap_dev = &dev->cap_dev;
1716
+ struct stream_config *st_cfg = &rkisp_mp_stream_config;
14731717 int ret = 0;
14741718
14751719 memset(cap_dev, 0, sizeof(*cap_dev));
14761720 cap_dev->ispdev = dev;
14771721 atomic_set(&cap_dev->refcnt, 0);
14781722
1479
- if (dev->isp_ver <= ISP_V13)
1723
+ if (dev->isp_ver <= ISP_V13) {
1724
+ if (dev->isp_ver == ISP_V12) {
1725
+ st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V12;
1726
+ st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V12;
1727
+ } else if (dev->isp_ver == ISP_V13) {
1728
+ st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V13;
1729
+ st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V13;
1730
+ }
14801731 ret = rkisp_register_stream_v1x(dev);
1481
- else if (dev->isp_ver == ISP_V20)
1732
+ } else if (dev->isp_ver == ISP_V20) {
14821733 ret = rkisp_register_stream_v20(dev);
1483
- else if (dev->isp_ver == ISP_V21)
1734
+ } else if (dev->isp_ver == ISP_V21) {
1735
+ st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V21;
1736
+ st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V21;
14841737 ret = rkisp_register_stream_v21(dev);
1738
+ } else if (dev->isp_ver == ISP_V30) {
1739
+ st_cfg->max_rsz_width = dev->hw_dev->unite ?
1740
+ CIF_ISP_INPUT_W_MAX_V30_UNITE : CIF_ISP_INPUT_W_MAX_V30;
1741
+ st_cfg->max_rsz_height = dev->hw_dev->unite ?
1742
+ CIF_ISP_INPUT_H_MAX_V30_UNITE : CIF_ISP_INPUT_H_MAX_V30;
1743
+ ret = rkisp_register_stream_v30(dev);
1744
+ } else if (dev->isp_ver == ISP_V32) {
1745
+ st_cfg->max_rsz_width = dev->hw_dev->unite ?
1746
+ CIF_ISP_INPUT_W_MAX_V32_UNITE : CIF_ISP_INPUT_W_MAX_V32;
1747
+ st_cfg->max_rsz_height = dev->hw_dev->unite ?
1748
+ CIF_ISP_INPUT_H_MAX_V32_UNITE : CIF_ISP_INPUT_H_MAX_V32;
1749
+ st_cfg = &rkisp_sp_stream_config;
1750
+ st_cfg->max_rsz_width = dev->hw_dev->unite ?
1751
+ CIF_ISP_INPUT_W_MAX_V32_UNITE : CIF_ISP_INPUT_W_MAX_V32;
1752
+ st_cfg->max_rsz_height = dev->hw_dev->unite ?
1753
+ CIF_ISP_INPUT_H_MAX_V32_UNITE : CIF_ISP_INPUT_H_MAX_V32;
1754
+ ret = rkisp_register_stream_v32(dev);
1755
+ } else if (dev->isp_ver == ISP_V32_L) {
1756
+ st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V32_L;
1757
+ st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V32_L;
1758
+ st_cfg = &rkisp_sp_stream_config;
1759
+ st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V32_L;
1760
+ st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V32_L;
1761
+ ret = rkisp_register_stream_v32(dev);
1762
+ }
1763
+
1764
+ INIT_WORK(&cap_dev->fast_work, rkisp_stream_fast);
14851765 return ret;
14861766 }
14871767
....@@ -1493,6 +1773,10 @@
14931773 rkisp_unregister_stream_v20(dev);
14941774 else if (dev->isp_ver == ISP_V21)
14951775 rkisp_unregister_stream_v21(dev);
1776
+ else if (dev->isp_ver == ISP_V30)
1777
+ rkisp_unregister_stream_v30(dev);
1778
+ else if (dev->isp_ver == ISP_V32 || dev->isp_ver == ISP_V32_L)
1779
+ rkisp_unregister_stream_v32(dev);
14961780 }
14971781
14981782 void rkisp_mi_isr(u32 mis_val, struct rkisp_device *dev)
....@@ -1503,4 +1787,8 @@
15031787 rkisp_mi_v20_isr(mis_val, dev);
15041788 else if (dev->isp_ver == ISP_V21)
15051789 rkisp_mi_v21_isr(mis_val, dev);
1790
+ else if (dev->isp_ver == ISP_V30)
1791
+ rkisp_mi_v30_isr(mis_val, dev);
1792
+ else if (dev->isp_ver == ISP_V32 || dev->isp_ver == ISP_V32_L)
1793
+ rkisp_mi_v32_isr(mis_val, dev);
15061794 }