forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/media/platform/rockchip/isp/dmarx.c
....@@ -346,9 +346,9 @@
346346 default:
347347 val |= CIF_CSI2_DT_RAW12;
348348 }
349
- rkisp_write(dev, CSI2RX_RAW_RD_CTRL,
350
- stream->memory << 2, false);
351
- rkisp_write(dev, CSI2RX_DATA_IDS_1, val, false);
349
+ rkisp_unite_write(dev, CSI2RX_RAW_RD_CTRL,
350
+ stream->memory << 2, false);
351
+ rkisp_unite_write(dev, CSI2RX_DATA_IDS_1, val, false);
352352 rkisp_rawrd_set_pic_size(dev, stream->out_fmt.width,
353353 stream->out_fmt.height);
354354 mi_raw_length(stream);
....@@ -364,25 +364,40 @@
364364 {
365365 struct rkisp_device *dev = stream->ispdev;
366366 void __iomem *base = dev->base_addr;
367
+ struct capture_fmt *fmt = &stream->out_isp_fmt;
368
+ u32 val = 0;
367369
368370 if (stream->curr_buf) {
369
- rkisp_write(dev, stream->config->mi.y_base_ad_init,
370
- stream->curr_buf->buff_addr[RKISP_PLANE_Y],
371
- false);
371
+ if (dev->vicap_in.merge_num > 1) {
372
+ val = stream->out_fmt.plane_fmt[0].bytesperline;
373
+ val /= dev->vicap_in.merge_num;
374
+ val *= dev->vicap_in.index;
375
+ }
376
+ val += stream->curr_buf->buff_addr[RKISP_PLANE_Y];
377
+ rkisp_write(dev, stream->config->mi.y_base_ad_init, val, false);
378
+ if (dev->hw_dev->unite) {
379
+ u32 offs = stream->out_fmt.width / 2 - RKMOUDLE_UNITE_EXTEND_PIXEL;
380
+
381
+ if (stream->memory)
382
+ offs *= DIV_ROUND_UP(fmt->bpp[0], 8);
383
+ else
384
+ offs = offs * fmt->bpp[0] / 8;
385
+ val += offs;
386
+ rkisp_next_write(dev, stream->config->mi.y_base_ad_init, val, false);
387
+ }
372388 stream->frame_end = false;
373
- if (stream->id == RKISP_STREAM_RAWRD2 &&
374
- stream->out_isp_fmt.fmt_type == FMT_YUV) {
389
+ if (stream->id == RKISP_STREAM_RAWRD2 && stream->out_isp_fmt.fmt_type == FMT_YUV) {
375390 struct vb2_v4l2_buffer *vbuf = &stream->curr_buf->vb;
376391 struct isp2x_csi_trigger trigger = {
377392 .frame_timestamp = vbuf->vb2_buf.timestamp,
378393 .sof_timestamp = vbuf->vb2_buf.timestamp,
379394 .frame_id = vbuf->sequence,
380
- .mode = T_START_X1,
395
+ .mode = 0,
381396 .times = 0,
382397 };
383398
384399 if (!vbuf->sequence)
385
- trigger.frame_id = atomic_inc_return(&dev->isp_sdev.frm_sync_seq);
400
+ trigger.frame_id = atomic_inc_return(&dev->isp_sdev.frm_sync_seq) - 1;
386401 rkisp_rdbk_trigger_event(dev, T_CMD_QUEUE, &trigger);
387402 }
388403 } else if (dev->dmarx_dev.trigger == T_AUTO) {
....@@ -430,8 +445,37 @@
430445
431446 spin_lock_irqsave(&stream->vbq_lock, lock_flags);
432447 if (stream->curr_buf) {
433
- vb2_buffer_done(&stream->curr_buf->vb.vb2_buf,
434
- VB2_BUF_STATE_DONE);
448
+ if (stream->curr_buf->other) {
449
+ struct rkisp_device *dev = stream->ispdev;
450
+ struct v4l2_subdev *sd = dev->active_sensor->sd;
451
+ struct rkisp_rx_buf *rx_buf = stream->curr_buf->other;
452
+
453
+ if (rx_buf->is_switch && stream->id == RKISP_STREAM_RAWRD2) {
454
+ switch (dev->rd_mode) {
455
+ case HDR_RDBK_FRAME3:
456
+ dev->rd_mode = HDR_LINEX3_DDR;
457
+ break;
458
+ case HDR_RDBK_FRAME2:
459
+ dev->rd_mode = HDR_LINEX2_DDR;
460
+ break;
461
+ default:
462
+ dev->rd_mode = HDR_NORMAL;
463
+ }
464
+ dev->hdr.op_mode = dev->rd_mode;
465
+ rkisp_unite_write(dev, CSI2RX_CTRL0,
466
+ SW_IBUF_OP_MODE(dev->hdr.op_mode), true);
467
+ rkisp_unite_set_bits(dev, CSI2RX_MASK_STAT,
468
+ 0, ISP21_MIPI_DROP_FRM, true);
469
+ rkisp_unite_clear_bits(dev, CIF_ISP_IMSC, CIF_ISP_FRAME_IN, true);
470
+ dev_info(dev->dev,
471
+ "switch online seq:%d mode:0x%x\n",
472
+ rx_buf->sequence, dev->rd_mode);
473
+ }
474
+ rx_buf->runtime_us = dev->isp_sdev.dbg.interval / 1000;
475
+ v4l2_subdev_call(sd, video, s_rx_buffer, rx_buf, NULL);
476
+ } else {
477
+ vb2_buffer_done(&stream->curr_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
478
+ }
435479 stream->curr_buf = NULL;
436480 }
437481
....@@ -443,7 +487,7 @@
443487 list_del(&stream->curr_buf->queue);
444488 }
445489
446
- if (stream->streaming)
490
+ if (stream->curr_buf)
447491 stream->ops->update_mi(stream);
448492 spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
449493 return 0;
....@@ -458,10 +502,11 @@
458502 int ret = 0;
459503
460504 stream->stopping = true;
461
- if ((dev->isp_state & ISP_START) && !stream->frame_end) {
505
+ if ((dev->isp_state & ISP_START) && !stream->frame_end &&
506
+ !dev->hw_dev->is_shutdown) {
462507 ret = wait_event_timeout(stream->done,
463508 !stream->streaming,
464
- msecs_to_jiffies(100));
509
+ msecs_to_jiffies(300));
465510 if (!ret)
466511 v4l2_warn(v4l2_dev,
467512 "dmarx:%d waiting on event return error %d\n",
....@@ -513,8 +558,8 @@
513558 }
514559
515560 rkisp_chk_tb_over(dev);
516
- v4l2_dbg(1, rkisp_debug, &dev->v4l2_dev, "%s count %d, size %d\n",
517
- v4l2_type_names[queue->type], *num_buffers, sizes[0]);
561
+ v4l2_dbg(1, rkisp_debug, &dev->v4l2_dev, "%s %s count %d, size %d\n",
562
+ stream->vnode.vdev.name, v4l2_type_names[queue->type], *num_buffers, sizes[0]);
518563
519564 return 0;
520565 }
....@@ -535,6 +580,7 @@
535580 struct sg_table *sgt;
536581 int i;
537582
583
+ ispbuf->other = NULL;
538584 memset(ispbuf->buff_addr, 0, sizeof(ispbuf->buff_addr));
539585 for (i = 0; i < isp_fmt->mplanes; i++) {
540586 void *vaddr = vb2_plane_vaddr(vb, i);
....@@ -602,15 +648,15 @@
602648 unsigned long lock_flags = 0;
603649
604650 spin_lock_irqsave(&stream->vbq_lock, lock_flags);
605
- if (stream->curr_buf) {
651
+ if (stream->curr_buf && !stream->curr_buf->other)
606652 list_add_tail(&stream->curr_buf->queue, &stream->buf_queue);
607
- stream->curr_buf = NULL;
608
- }
653
+ stream->curr_buf = NULL;
609654 while (!list_empty(&stream->buf_queue)) {
610655 buf = list_first_entry(&stream->buf_queue,
611656 struct rkisp_buffer, queue);
612657 list_del(&buf->queue);
613
- vb2_buffer_done(&buf->vb.vb2_buf, state);
658
+ if (!buf->other)
659
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
614660 }
615661 spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
616662 }
....@@ -618,6 +664,10 @@
618664 static void dmarx_stop_streaming(struct vb2_queue *queue)
619665 {
620666 struct rkisp_stream *stream = queue->drv_priv;
667
+ struct v4l2_device *v4l2_dev = &stream->ispdev->v4l2_dev;
668
+
669
+ v4l2_dbg(1, rkisp_debug, v4l2_dev, "%s %s id:%d\n",
670
+ __func__, stream->vnode.vdev.name, stream->id);
621671
622672 if (!stream->streaming)
623673 return;
....@@ -626,7 +676,7 @@
626676 destroy_buf_queue(stream, VB2_BUF_STATE_ERROR);
627677
628678 if (stream->id == RKISP_STREAM_RAWRD2 &&
629
- (stream->ispdev->isp_ver == ISP_V20 || stream->ispdev->isp_ver == ISP_V21))
679
+ stream->ispdev->isp_ver >= ISP_V20)
630680 kfifo_reset(&stream->ispdev->rdbk_kfifo);
631681 }
632682
....@@ -638,19 +688,20 @@
638688 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
639689 int ret = -1;
640690
691
+ v4l2_dbg(1, rkisp_debug, v4l2_dev, "%s %s id:%d\n",
692
+ __func__, stream->vnode.vdev.name, stream->id);
693
+
641694 if (WARN_ON(stream->streaming))
642695 return -EBUSY;
643696
644697 if (!stream->linked) {
645
- v4l2_err(v4l2_dev, "check video link\n");
698
+ v4l2_err(v4l2_dev, "check %s link\n", stream->vnode.vdev.name);
646699 goto free_buf_queue;
647700 }
648701
649702 ret = dmarx_start(stream);
650703 if (ret < 0) {
651
- v4l2_err(v4l2_dev,
652
- "start dmarx stream:%d failed\n",
653
- stream->id);
704
+ v4l2_err(v4l2_dev, "start %s failed\n", stream->vnode.vdev.name);
654705 goto free_buf_queue;
655706 }
656707 return 0;
....@@ -685,6 +736,8 @@
685736 q->allow_cache_hints = 1;
686737 q->bidirectional = 1;
687738 q->gfp_flags = GFP_DMA32;
739
+ if (stream->ispdev->hw_dev->is_dma_contig)
740
+ q->dma_attrs = DMA_ATTR_FORCE_CONTIGUOUS;
688741 return vb2_queue_init(q);
689742 }
690743
....@@ -736,15 +789,17 @@
736789 fmt->fmt_type == FMT_BAYER)
737790 height += RKMODULE_EXTEND_LINE;
738791
739
- if ((stream->ispdev->isp_ver == ISP_V20 ||
740
- stream->ispdev->isp_ver == ISP_V21) &&
792
+ if (stream->ispdev->isp_ver >= ISP_V20 &&
741793 fmt->fmt_type == FMT_BAYER &&
742794 !stream->memory &&
743795 stream->id != RKISP_STREAM_DMARX)
744796 bytesperline = ALIGN(width * fmt->bpp[i] / 8, 256);
745797 else
746798 bytesperline = width * DIV_ROUND_UP(fmt->bpp[i], 8);
747
- /* stride is only available for sp stream and y plane */
799
+
800
+ if (stream->ispdev->vicap_in.merge_num > 1)
801
+ bytesperline *= stream->ispdev->vicap_in.merge_num;
802
+
748803 if (i != 0 ||
749804 plane_fmt->bytesperline < bytesperline)
750805 plane_fmt->bytesperline = bytesperline;
....@@ -770,7 +825,7 @@
770825 DIV_ROUND_UP(fmt->bpp[0], 8);
771826
772827 v4l2_dbg(1, rkisp_debug, &stream->ispdev->v4l2_dev,
773
- "%s: stream: %d req(%d, %d) out(%d, %d)\n", __func__,
828
+ "%s: rx:%d req(%d, %d) out(%d, %d)\n", __func__,
774829 stream->id, pixm->width, pixm->height,
775830 stream->out_fmt.width, stream->out_fmt.height);
776831 }
....@@ -786,6 +841,9 @@
786841 .unlocked_ioctl = video_ioctl2,
787842 .poll = vb2_fop_poll,
788843 .mmap = vb2_fop_mmap,
844
+#ifdef CONFIG_COMPAT
845
+ .compat_ioctl32 = video_ioctl2,
846
+#endif
789847 };
790848
791849 static int rkisp_try_fmt_vid_out_mplane(struct file *file, void *fh,
....@@ -820,7 +878,8 @@
820878 struct rkisp_device *dev = stream->ispdev;
821879
822880 if (vb2_is_busy(&node->buf_queue)) {
823
- v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__);
881
+ v4l2_err(&dev->v4l2_dev, "%s rx:%d queue busy\n",
882
+ __func__, stream->id);
824883 return -EBUSY;
825884 }
826885
....@@ -904,7 +963,7 @@
904963 .vidioc_streamon = vb2_ioctl_streamon,
905964 .vidioc_streamoff = vb2_ioctl_streamoff,
906965 .vidioc_try_fmt_vid_out_mplane = rkisp_try_fmt_vid_out_mplane,
907
- .vidioc_enum_fmt_vid_out_mplane = rkisp_enum_fmt_vid_out_mplane,
966
+ .vidioc_enum_fmt_vid_out = rkisp_enum_fmt_vid_out_mplane,
908967 .vidioc_s_fmt_vid_out_mplane = rkisp_s_fmt_vid_out_mplane,
909968 .vidioc_g_fmt_vid_out_mplane = rkisp_g_fmt_vid_out_mplane,
910969 .vidioc_querycap = rkisp_querycap,
....@@ -945,7 +1004,7 @@
9451004 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
9461005 vdev->queue = &node->buf_queue;
9471006
948
- ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1007
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
9491008 if (ret < 0) {
9501009 v4l2_err(v4l2_dev,
9511010 "%s failed with error %d\n", __func__, ret);
....@@ -1072,6 +1131,8 @@
10721131 {
10731132 struct rkisp_isp_subdev *sdev = &dev->isp_sdev;
10741133 u8 mult = sdev->in_fmt.fmt_type == FMT_YUV ? 2 : 1;
1134
+ bool is_unite = !!dev->hw_dev->unite;
1135
+ u32 w = !is_unite ? width : width / 2 + RKMOUDLE_UNITE_EXTEND_PIXEL;
10751136
10761137 /* rx height should equal to isp height + offset for read back mode */
10771138 height = sdev->in_crop.top + sdev->in_crop.height;
....@@ -1083,7 +1144,8 @@
10831144 dev->rd_mode == HDR_RDBK_FRAME1)
10841145 height += RKMODULE_EXTEND_LINE;
10851146
1086
- rkisp_write(dev, CSI2RX_RAW_RD_PIC_SIZE, height << 16 | width * mult, false);
1147
+ w *= mult;
1148
+ rkisp_unite_write(dev, CSI2RX_RAW_RD_PIC_SIZE, height << 16 | w, false);
10871149 }
10881150
10891151 void rkisp_dmarx_get_frame(struct rkisp_device *dev, u32 *id,
....@@ -1094,9 +1156,10 @@
10941156 u64 sof_time = 0, frame_timestamp = 0;
10951157 u32 frame_id = 0;
10961158
1097
- if (!dev->dmarx_dev.trigger && id) {
1098
- *id = atomic_read(&dev->isp_sdev.frm_sync_seq) - 1;
1099
- return;
1159
+ if (!IS_HDR_RDBK(dev->rd_mode)) {
1160
+ frame_id = atomic_read(&dev->isp_sdev.frm_sync_seq) - 1;
1161
+ frame_timestamp = dev->isp_sdev.frm_timestamp;
1162
+ goto end;
11001163 }
11011164
11021165 spin_lock_irqsave(&dev->rdbk_lock, flag);
....@@ -1110,6 +1173,7 @@
11101173 frame_timestamp = dev->dmarx_dev.pre_frame.timestamp;
11111174 }
11121175 spin_unlock_irqrestore(&dev->rdbk_lock, flag);
1176
+end:
11131177 if (id)
11141178 *id = frame_id;
11151179 if (sof_timestamp)
....@@ -1131,7 +1195,7 @@
11311195 if (ret < 0)
11321196 goto err;
11331197 #endif
1134
- if (dev->isp_ver == ISP_V20 || dev->isp_ver == ISP_V21) {
1198
+ if (dev->isp_ver >= ISP_V20) {
11351199 ret = dmarx_init(dev, RKISP_STREAM_RAWRD0);
11361200 if (ret < 0)
11371201 goto err_free_dmarx;
....@@ -1139,7 +1203,7 @@
11391203 if (ret < 0)
11401204 goto err_free_dmarx0;
11411205 }
1142
- if (dev->isp_ver == ISP_V20) {
1206
+ if (dev->isp_ver == ISP_V20 || dev->isp_ver == ISP_V30) {
11431207 ret = dmarx_init(dev, RKISP_STREAM_RAWRD1);
11441208 if (ret < 0)
11451209 goto err_free_dmarx2;
....@@ -1168,14 +1232,14 @@
11681232 rkisp_unregister_dmarx_video(stream);
11691233 #endif
11701234
1171
- if (dev->isp_ver == ISP_V20 || dev->isp_ver == ISP_V21) {
1235
+ if (dev->isp_ver >= ISP_V20) {
11721236 stream = &dmarx_dev->stream[RKISP_STREAM_RAWRD0];
11731237 rkisp_unregister_dmarx_video(stream);
11741238
11751239 stream = &dmarx_dev->stream[RKISP_STREAM_RAWRD2];
11761240 rkisp_unregister_dmarx_video(stream);
11771241 }
1178
- if (dev->isp_ver == ISP_V20) {
1242
+ if (dev->isp_ver == ISP_V20 || dev->isp_ver == ISP_V30) {
11791243 stream = &dmarx_dev->stream[RKISP_STREAM_RAWRD1];
11801244 rkisp_unregister_dmarx_video(stream);
11811245 }