forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/media/platform/rockchip/cif/capture.c
....@@ -18,8 +18,8 @@
1818 #include <media/videobuf2-dma-contig.h>
1919 #include <media/videobuf2-dma-sg.h>
2020 #include <soc/rockchip/rockchip-system-status.h>
21
-#include <dt-bindings/soc/rockchip-system-status.h>
2221 #include <soc/rockchip/rockchip_iommu.h>
22
+#include <linux/rk-isp32-config.h>
2323
2424 #include "dev.h"
2525 #include "mipi-csi2.h"
....@@ -515,6 +515,10 @@
515515 .csi_fmt_val = CSI_WRDDR_TYPE_RGB888,
516516 .field = V4L2_FIELD_NONE,
517517 }, {
518
+ .mbus_code = MEDIA_BUS_FMT_GBR888_1X24,
519
+ .csi_fmt_val = CSI_WRDDR_TYPE_RGB888,
520
+ .field = V4L2_FIELD_NONE,
521
+ }, {
518522 .mbus_code = MEDIA_BUS_FMT_RGB565_1X16,
519523 .csi_fmt_val = CSI_WRDDR_TYPE_RGB565,
520524 .field = V4L2_FIELD_NONE,
....@@ -611,6 +615,7 @@
611615 break;
612616 case MEDIA_BUS_FMT_RGB888_1X24:
613617 case MEDIA_BUS_FMT_BGR888_1X24:
618
+ case MEDIA_BUS_FMT_GBR888_1X24:
614619 if (output_fmt->fourcc == V4L2_PIX_FMT_RGB24 ||
615620 output_fmt->fourcc == V4L2_PIX_FMT_BGR24)
616621 ret = 0;
....@@ -671,7 +676,7 @@
671676 break;
672677 }
673678 if (ret)
674
- v4l2_err(&stream->cifdev->v4l2_dev,
679
+ v4l2_dbg(4, rkcif_debug, &stream->cifdev->v4l2_dev,
675680 "input mbus_code 0x%x, can't transform to %c%c%c%c\n",
676681 input_fmt->mbus_code,
677682 output_fmt->fourcc & 0xff,
....@@ -801,6 +806,7 @@
801806 return 0x1e;
802807 case MEDIA_BUS_FMT_RGB888_1X24:
803808 case MEDIA_BUS_FMT_BGR888_1X24:
809
+ case MEDIA_BUS_FMT_GBR888_1X24:
804810 if (dsi_input) {
805811 if (cmd_mode_en) /* dsi command mode*/
806812 return 0x39;
....@@ -847,11 +853,13 @@
847853 }
848854
849855 const struct
850
-cif_input_fmt *get_input_fmt(struct v4l2_subdev *sd, struct v4l2_rect *rect,
856
+cif_input_fmt *rkcif_get_input_fmt(struct rkcif_device *dev, struct v4l2_rect *rect,
851857 u32 pad_id, struct csi_channel_info *csi_info)
852858 {
853859 struct v4l2_subdev_format fmt;
860
+ struct v4l2_subdev *sd = dev->terminal_sensor.sd;
854861 struct rkmodule_channel_info ch_info = {0};
862
+ struct rkmodule_capture_info capture_info;
855863 int ret;
856864 u32 i;
857865
....@@ -909,7 +917,26 @@
909917 rect->top = 0;
910918 rect->width = fmt.format.width;
911919 rect->height = fmt.format.height;
912
-
920
+ ret = v4l2_subdev_call(sd,
921
+ core, ioctl,
922
+ RKMODULE_GET_CAPTURE_MODE,
923
+ &capture_info);
924
+ if (!ret) {
925
+ if (capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE &&
926
+ dev->hw_dev->is_rk3588s2) {
927
+ for (i = 0; i < capture_info.multi_dev.dev_num; i++) {
928
+ if (capture_info.multi_dev.dev_idx[i] == 0)
929
+ capture_info.multi_dev.dev_idx[i] = 2;
930
+ else if (capture_info.multi_dev.dev_idx[i] == 2)
931
+ capture_info.multi_dev.dev_idx[i] = 4;
932
+ else if (capture_info.multi_dev.dev_idx[i] == 3)
933
+ capture_info.multi_dev.dev_idx[i] = 5;
934
+ }
935
+ }
936
+ csi_info->capture_info = capture_info;
937
+ } else {
938
+ csi_info->capture_info.mode = RKMODULE_CAPTURE_MODE_NONE;
939
+ }
913940 for (i = 0; i < ARRAY_SIZE(in_fmts); i++)
914941 if (fmt.format.code == in_fmts[i].mbus_code &&
915942 fmt.format.field == in_fmts[i].field)
....@@ -1587,25 +1614,29 @@
15871614 return ret;
15881615 }
15891616
1590
-static void rkcif_rx_buffer_free(struct rkcif_stream *stream)
1617
+static struct v4l2_subdev *get_rkisp_sd(struct sditf_priv *priv)
15911618 {
15921619 struct media_pad *pad = NULL;
1620
+
1621
+ if (priv && priv->pads[0].entity->num_links) {
1622
+ if (priv->is_combine_mode)
1623
+ pad = media_entity_remote_pad(&priv->pads[1]);
1624
+ else
1625
+ pad = media_entity_remote_pad(&priv->pads[0]);
1626
+ if (pad)
1627
+ return media_entity_to_v4l2_subdev(pad->entity);
1628
+ }
1629
+ return NULL;
1630
+}
1631
+
1632
+static void rkcif_rx_buffer_free(struct rkcif_stream *stream)
1633
+{
15931634 struct v4l2_subdev *sd;
15941635 struct rkisp_rx_buf *dbufs;
15951636 struct rkcif_device *dev = stream->cifdev;
15961637
1597
- if (dev->sditf[0] && dev->sditf[0]->num_sensors != 0) {
1598
- if (dev->sditf[0]->is_combine_mode)
1599
- pad = media_entity_remote_pad(&dev->sditf[0]->pads[1]);
1600
- else
1601
- pad = media_entity_remote_pad(&dev->sditf[0]->pads[0]);
1602
- } else {
1603
- return;
1604
- }
1605
-
1606
- if (pad)
1607
- sd = media_entity_to_v4l2_subdev(pad->entity);
1608
- else
1638
+ sd = get_rkisp_sd(dev->sditf[0]);
1639
+ if (!sd)
16091640 return;
16101641
16111642 while (!list_empty(&stream->rx_buf_head_vicap)) {
....@@ -1619,31 +1650,23 @@
16191650 }
16201651 }
16211652
1622
-static void rkcif_s_rx_buffer(struct rkcif_device *dev, struct rkisp_rx_buf *dbufs)
1653
+static void rkcif_s_rx_buffer(struct rkcif_stream *stream, struct rkisp_rx_buf *dbufs)
16231654 {
1624
- struct media_pad *pad = NULL;
1655
+ struct rkcif_device *dev = stream->cifdev;
16251656 struct v4l2_subdev *sd;
16261657 struct rkcif_rx_buffer *rx_buf = NULL;
16271658
1628
- if (dev->sditf[0]) {
1629
- if (dev->sditf[0]->is_combine_mode)
1630
- pad = media_entity_remote_pad(&dev->sditf[0]->pads[1]);
1631
- else
1632
- pad = media_entity_remote_pad(&dev->sditf[0]->pads[0]);
1633
- } else {
1659
+ sd = get_rkisp_sd(dev->sditf[0]);
1660
+ if (!sd)
16341661 return;
1635
- }
1636
- if (pad)
1637
- sd = media_entity_to_v4l2_subdev(pad->entity);
1638
- else
1639
- return;
1640
- if (dev->rdbk_debug &&
1641
- dbufs->sequence < 15) {
1662
+ if ((dev->rdbk_debug &&
1663
+ dbufs->sequence < 15) ||
1664
+ rkcif_debug == 3) {
16421665 rx_buf = to_cif_rx_buf(dbufs);
16431666 v4l2_info(&dev->v4l2_dev,
16441667 "s_buf seq %d type %d, dma addr %x, %lld\n",
16451668 dbufs->sequence, dbufs->type, (u32)rx_buf->dummy.dma_addr,
1646
- ktime_get_ns());
1669
+ rkcif_time_get_ns(dev));
16471670 }
16481671 v4l2_subdev_call(sd, video, s_rx_buffer, dbufs, NULL);
16491672 }
....@@ -1668,6 +1691,20 @@
16681691 val &= ~(RKCIF_SKIP_EN(stream->id));
16691692 rkcif_write_register(dev, CIF_REG_MIPI_LVDS_CTRL, val);
16701693 stream->skip_info.skip_en = false;
1694
+}
1695
+
1696
+static void rkcif_rdbk_with_tools(struct rkcif_stream *stream,
1697
+ struct rkcif_rx_buffer *active_buf)
1698
+{
1699
+ unsigned long flags;
1700
+
1701
+ spin_lock_irqsave(&stream->tools_vdev->vbq_lock, flags);
1702
+ if (stream->tools_vdev->state == RKCIF_STATE_STREAMING) {
1703
+ list_add_tail(&active_buf->list, &stream->tools_vdev->buf_done_head);
1704
+ if (!work_busy(&stream->tools_vdev->work))
1705
+ schedule_work(&stream->tools_vdev->work);
1706
+ }
1707
+ spin_unlock_irqrestore(&stream->tools_vdev->vbq_lock, flags);
16711708 }
16721709
16731710 static void rkcif_rdbk_frame_end_toisp(struct rkcif_stream *stream,
....@@ -1731,9 +1768,15 @@
17311768 }
17321769 dev->rdbk_rx_buf[RDBK_M]->dbufs.sequence = dev->rdbk_rx_buf[RDBK_L]->dbufs.sequence;
17331770 dev->rdbk_rx_buf[RDBK_S]->dbufs.sequence = dev->rdbk_rx_buf[RDBK_L]->dbufs.sequence;
1734
- rkcif_s_rx_buffer(dev, &dev->rdbk_rx_buf[RDBK_L]->dbufs);
1735
- rkcif_s_rx_buffer(dev, &dev->rdbk_rx_buf[RDBK_M]->dbufs);
1736
- rkcif_s_rx_buffer(dev, &dev->rdbk_rx_buf[RDBK_S]->dbufs);
1771
+ rkcif_s_rx_buffer(&dev->stream[RDBK_L], &dev->rdbk_rx_buf[RDBK_L]->dbufs);
1772
+ rkcif_s_rx_buffer(&dev->stream[RDBK_M], &dev->rdbk_rx_buf[RDBK_M]->dbufs);
1773
+ rkcif_s_rx_buffer(&dev->stream[RDBK_S], &dev->rdbk_rx_buf[RDBK_S]->dbufs);
1774
+ rkcif_rdbk_with_tools(&dev->stream[RDBK_L], dev->rdbk_rx_buf[RDBK_L]);
1775
+ rkcif_rdbk_with_tools(&dev->stream[RDBK_M], dev->rdbk_rx_buf[RDBK_M]);
1776
+ rkcif_rdbk_with_tools(&dev->stream[RDBK_S], dev->rdbk_rx_buf[RDBK_S]);
1777
+ atomic_dec(&dev->stream[RDBK_L].buf_cnt);
1778
+ atomic_dec(&dev->stream[RDBK_M].buf_cnt);
1779
+ atomic_dec(&dev->stream[RDBK_S].buf_cnt);
17371780 dev->rdbk_rx_buf[RDBK_L] = NULL;
17381781 dev->rdbk_rx_buf[RDBK_M] = NULL;
17391782 dev->rdbk_rx_buf[RDBK_S] = NULL;
....@@ -1770,8 +1813,12 @@
17701813 }
17711814 }
17721815 dev->rdbk_rx_buf[RDBK_M]->dbufs.sequence = dev->rdbk_rx_buf[RDBK_L]->dbufs.sequence;
1773
- rkcif_s_rx_buffer(dev, &dev->rdbk_rx_buf[RDBK_L]->dbufs);
1774
- rkcif_s_rx_buffer(dev, &dev->rdbk_rx_buf[RDBK_M]->dbufs);
1816
+ rkcif_s_rx_buffer(&dev->stream[RDBK_L], &dev->rdbk_rx_buf[RDBK_L]->dbufs);
1817
+ rkcif_s_rx_buffer(&dev->stream[RDBK_M], &dev->rdbk_rx_buf[RDBK_M]->dbufs);
1818
+ rkcif_rdbk_with_tools(&dev->stream[RDBK_L], dev->rdbk_rx_buf[RDBK_L]);
1819
+ rkcif_rdbk_with_tools(&dev->stream[RDBK_M], dev->rdbk_rx_buf[RDBK_M]);
1820
+ atomic_dec(&dev->stream[RDBK_L].buf_cnt);
1821
+ atomic_dec(&dev->stream[RDBK_M].buf_cnt);
17751822 dev->rdbk_rx_buf[RDBK_L] = NULL;
17761823 dev->rdbk_rx_buf[RDBK_M] = NULL;
17771824 }
....@@ -1783,14 +1830,51 @@
17831830 spin_unlock_irqrestore(&dev->hdr_lock, flags);
17841831 }
17851832
1833
+static void rkcif_write_buff_addr_multi_dev_combine(struct rkcif_stream *stream,
1834
+ u32 frm_addr_y, u32 frm_addr_uv,
1835
+ u32 buff_addr_y, u32 buff_addr_cbcr,
1836
+ bool is_dummy_buf)
1837
+{
1838
+ struct rkcif_device *dev = stream->cifdev;
1839
+ struct rkmodule_capture_info *capture_info = &dev->channels[stream->id].capture_info;
1840
+ u32 addr_y, addr_cbcr;
1841
+ int addr_offset = 0;
1842
+ int i = 0;
1843
+ int tmp_host_index = dev->csi_host_idx;
1844
+
1845
+ for (i = 0; i < capture_info->multi_dev.dev_num; i++) {
1846
+ if (is_dummy_buf) {
1847
+ addr_y = buff_addr_y;
1848
+ } else {
1849
+ addr_offset = dev->channels[stream->id].left_virtual_width;
1850
+ addr_y = buff_addr_y + addr_offset * i;
1851
+ }
1852
+ dev->csi_host_idx = capture_info->multi_dev.dev_idx[i];
1853
+ rkcif_write_register(dev, frm_addr_y, addr_y);
1854
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW &&
1855
+ frm_addr_uv && buff_addr_cbcr) {
1856
+ if (is_dummy_buf) {
1857
+ addr_cbcr = buff_addr_cbcr;
1858
+ } else {
1859
+ addr_offset = dev->channels[stream->id].left_virtual_width;
1860
+ addr_cbcr = buff_addr_cbcr + addr_offset * i;
1861
+ }
1862
+ rkcif_write_register(dev, frm_addr_uv, addr_cbcr);
1863
+ }
1864
+ }
1865
+ dev->csi_host_idx = tmp_host_index;
1866
+}
1867
+
17861868 static void rkcif_assign_new_buffer_init_toisp(struct rkcif_stream *stream,
17871869 int channel_id)
17881870 {
17891871 struct rkcif_device *dev = stream->cifdev;
17901872 struct rkcif_rx_buffer *rx_buf;
17911873 struct v4l2_mbus_config *mbus_cfg = &dev->active_sensor->mbus;
1874
+ struct rkmodule_capture_info *capture_info = &dev->channels[channel_id].capture_info;
17921875 u32 frm0_addr_y;
17931876 u32 frm1_addr_y;
1877
+ u32 buff_addr_y;
17941878 unsigned long flags;
17951879
17961880 if (mbus_cfg->type == V4L2_MBUS_CSI2_DPHY ||
....@@ -1817,9 +1901,18 @@
18171901 }
18181902 }
18191903
1820
- if (stream->curr_buf_toisp)
1821
- rkcif_write_register(dev, frm0_addr_y,
1822
- stream->curr_buf_toisp->dummy.dma_addr);
1904
+ if (stream->curr_buf_toisp) {
1905
+ buff_addr_y = stream->curr_buf_toisp->dummy.dma_addr;
1906
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
1907
+ rkcif_write_buff_addr_multi_dev_combine(stream, frm0_addr_y, 0,
1908
+ buff_addr_y, 0, false);
1909
+ } else {
1910
+ rkcif_write_register(dev, frm0_addr_y, buff_addr_y);
1911
+ }
1912
+ } else {
1913
+ if (stream->lack_buf_cnt < 2)
1914
+ stream->lack_buf_cnt++;
1915
+ }
18231916
18241917 if (!stream->next_buf_toisp) {
18251918 if (!list_empty(&stream->rx_buf_head)) {
....@@ -1836,12 +1929,41 @@
18361929 }
18371930 }
18381931
1839
- if (stream->next_buf_toisp)
1840
- rkcif_write_register(dev, frm1_addr_y,
1841
- stream->next_buf_toisp->dummy.dma_addr);
1932
+ if (stream->next_buf_toisp) {
1933
+ buff_addr_y = stream->next_buf_toisp->dummy.dma_addr;
1934
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
1935
+ rkcif_write_buff_addr_multi_dev_combine(stream, frm1_addr_y, 0,
1936
+ buff_addr_y, 0, false);
1937
+ } else {
1938
+ rkcif_write_register(dev, frm1_addr_y, buff_addr_y);
1939
+ }
1940
+ } else {
1941
+ if (stream->lack_buf_cnt < 2)
1942
+ stream->lack_buf_cnt++;
1943
+ }
18421944
18431945 spin_unlock_irqrestore(&stream->vbq_lock, flags);
18441946 stream->buf_owner = RKCIF_DMAEN_BY_ISP;
1947
+}
1948
+
1949
+static void rkcif_dphy_quick_stream(struct rkcif_device *dev, int on)
1950
+{
1951
+ struct rkcif_pipeline *p = NULL;
1952
+ int j = 0;
1953
+
1954
+ if (dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_DPHY ||
1955
+ dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_CPHY ||
1956
+ dev->active_sensor->mbus.type == V4L2_MBUS_CCP2) {
1957
+ p = &dev->pipe;
1958
+ for (j = 0; j < p->num_subdevs; j++) {
1959
+ if (p->subdevs[j] != dev->terminal_sensor.sd &&
1960
+ p->subdevs[j] != dev->active_sensor->sd) {
1961
+ v4l2_subdev_call(p->subdevs[j], core, ioctl,
1962
+ RKMODULE_SET_QUICK_STREAM, &on);
1963
+ break;
1964
+ }
1965
+ }
1966
+ }
18451967 }
18461968
18471969 static int rkcif_assign_new_buffer_update_toisp(struct rkcif_stream *stream,
....@@ -1849,11 +1971,13 @@
18491971 {
18501972 struct rkcif_device *dev = stream->cifdev;
18511973 struct v4l2_mbus_config *mbus_cfg = &dev->active_sensor->mbus;
1974
+ struct rkmodule_capture_info *capture_info = &dev->channels[channel_id].capture_info;
18521975 struct rkcif_rx_buffer *buffer = NULL;
18531976 struct rkcif_rx_buffer *active_buf = NULL;
18541977 struct sditf_priv *priv = dev->sditf[0];
1855
- u32 frm_addr_y;
1978
+ u32 frm_addr_y, buff_addr_y;
18561979 unsigned long flags;
1980
+
18571981
18581982 if (mbus_cfg->type == V4L2_MBUS_CSI2_DPHY ||
18591983 mbus_cfg->type == V4L2_MBUS_CSI2_CPHY ||
....@@ -1866,13 +1990,19 @@
18661990 get_dvp_reg_index_of_frm0_y_addr(channel_id) :
18671991 get_dvp_reg_index_of_frm1_y_addr(channel_id);
18681992 }
1993
+
18691994 spin_lock_irqsave(&stream->vbq_lock, flags);
1995
+ if (stream->cur_skip_frame)
1996
+ goto out_get_buf;
1997
+ memset(&stream->toisp_buf_state, 0, sizeof(stream->toisp_buf_state));
18701998 if (!list_empty(&stream->rx_buf_head)) {
1999
+ if (stream->curr_buf_toisp && stream->next_buf_toisp &&
2000
+ stream->curr_buf_toisp != stream->next_buf_toisp)
2001
+ stream->toisp_buf_state.state = RKCIF_TOISP_BUF_ROTATE;
2002
+ else
2003
+ stream->toisp_buf_state.state = RKCIF_TOISP_BUF_LOSS;
18712004 if (stream->frame_phase == CIF_CSI_FRAME0_READY) {
1872
- if (stream->curr_buf_toisp == stream->next_buf_toisp)
1873
- active_buf = NULL;
1874
- else
1875
- active_buf = stream->curr_buf_toisp;
2005
+ active_buf = stream->curr_buf_toisp;
18762006
18772007 buffer = list_first_entry(&stream->rx_buf_head,
18782008 struct rkcif_rx_buffer, list);
....@@ -1887,22 +2017,24 @@
18872017 active_buf->dbufs.is_first = true;
18882018 active_buf->dbufs.sequence = stream->frame_idx - 1;
18892019 active_buf->dbufs.timestamp = stream->readout.fs_timestamp;
1890
- active_buf->fe_timestamp = ktime_get_ns();
2020
+ active_buf->fe_timestamp = rkcif_time_get_ns(dev);
18912021 stream->last_frame_idx = stream->frame_idx;
1892
- if (dev->hdr.hdr_mode == NO_HDR)
1893
- rkcif_s_rx_buffer(dev, &active_buf->dbufs);
1894
- else
2022
+ if (dev->hdr.hdr_mode == NO_HDR) {
2023
+ rkcif_s_rx_buffer(stream, &active_buf->dbufs);
2024
+ if (dev->is_support_tools && stream->tools_vdev)
2025
+ rkcif_rdbk_with_tools(stream, active_buf);
2026
+ atomic_dec(&stream->buf_cnt);
2027
+ } else {
18952028 rkcif_rdbk_frame_end_toisp(stream, active_buf);
1896
- stream->buf_num_toisp--;
2029
+ }
18972030 } else {
1898
- rkcif_s_rx_buffer(dev, &stream->next_buf_toisp->dbufs);
1899
- stream->buf_num_toisp--;
2031
+ if (active_buf)
2032
+ rkcif_s_rx_buffer(stream, &active_buf->dbufs);
2033
+ if (dev->is_support_tools && stream->tools_vdev)
2034
+ rkcif_rdbk_with_tools(stream, active_buf);
19002035 }
19012036 } else if (stream->frame_phase == CIF_CSI_FRAME1_READY) {
1902
- if (stream->curr_buf_toisp == stream->next_buf_toisp)
1903
- active_buf = NULL;
1904
- else
1905
- active_buf = stream->next_buf_toisp;
2037
+ active_buf = stream->next_buf_toisp;
19062038 buffer = list_first_entry(&stream->rx_buf_head,
19072039 struct rkcif_rx_buffer, list);
19082040 if (buffer) {
....@@ -1916,16 +2048,21 @@
19162048 active_buf->dbufs.is_first = true;
19172049 active_buf->dbufs.sequence = stream->frame_idx - 1;
19182050 active_buf->dbufs.timestamp = stream->readout.fs_timestamp;
1919
- active_buf->fe_timestamp = ktime_get_ns();
2051
+ active_buf->fe_timestamp = rkcif_time_get_ns(dev);
19202052 stream->last_frame_idx = stream->frame_idx;
1921
- if (dev->hdr.hdr_mode == NO_HDR)
1922
- rkcif_s_rx_buffer(dev, &active_buf->dbufs);
1923
- else
2053
+ if (dev->hdr.hdr_mode == NO_HDR) {
2054
+ rkcif_s_rx_buffer(stream, &active_buf->dbufs);
2055
+ if (dev->is_support_tools && stream->tools_vdev)
2056
+ rkcif_rdbk_with_tools(stream, active_buf);
2057
+ atomic_dec(&stream->buf_cnt);
2058
+ } else {
19242059 rkcif_rdbk_frame_end_toisp(stream, active_buf);
1925
- stream->buf_num_toisp--;
2060
+ }
19262061 } else {
1927
- rkcif_s_rx_buffer(dev, &stream->curr_buf_toisp->dbufs);
1928
- stream->buf_num_toisp--;
2062
+ if (active_buf)
2063
+ rkcif_s_rx_buffer(stream, &active_buf->dbufs);
2064
+ if (dev->is_support_tools && stream->tools_vdev)
2065
+ rkcif_rdbk_with_tools(stream, active_buf);
19292066 }
19302067 }
19312068 if (stream->lack_buf_cnt)
....@@ -1938,10 +2075,8 @@
19382075 if (dev->hw_dev->dummy_buf.vaddr) {
19392076 if (stream->frame_phase == CIF_CSI_FRAME0_READY) {
19402077 active_buf = stream->curr_buf_toisp;
1941
- stream->curr_buf_toisp = NULL;
19422078 } else {
19432079 active_buf = stream->next_buf_toisp;
1944
- stream->next_buf_toisp = NULL;
19452080 }
19462081 } else if (stream->curr_buf_toisp && stream->next_buf_toisp &&
19472082 stream->curr_buf_toisp != stream->next_buf_toisp) {
....@@ -1954,23 +2089,34 @@
19542089 stream->next_buf_toisp = stream->curr_buf_toisp;
19552090 buffer = stream->curr_buf_toisp;
19562091 }
2092
+ stream->toisp_buf_state.state = RKCIF_TOISP_BUF_THESAME;
19572093 if (stream->cifdev->rdbk_debug)
19582094 v4l2_info(&stream->cifdev->v4l2_dev,
19592095 "stream[%d] hold buf %x\n",
19602096 stream->id,
19612097 (u32)stream->next_buf_toisp->dummy.dma_addr);
2098
+ } else {
2099
+ stream->toisp_buf_state.state = RKCIF_TOISP_BUF_LOSS;
2100
+ if (stream->is_single_cap) {
2101
+ active_buf = stream->curr_buf_toisp;
2102
+ stream->curr_buf_toisp = NULL;
2103
+ stream->next_buf_toisp = NULL;
2104
+ }
19622105 }
2106
+
19632107 if (active_buf) {
19642108 if (stream->frame_idx == 1)
19652109 active_buf->dbufs.is_first = true;
19662110 active_buf->dbufs.sequence = stream->frame_idx - 1;
19672111 active_buf->dbufs.timestamp = stream->readout.fs_timestamp;
1968
- active_buf->fe_timestamp = ktime_get_ns();
2112
+ active_buf->fe_timestamp = rkcif_time_get_ns(dev);
19692113 stream->last_frame_idx = stream->frame_idx;
1970
- if (dev->hdr.hdr_mode == NO_HDR)
1971
- rkcif_s_rx_buffer(dev, &active_buf->dbufs);
1972
- else
2114
+ if (dev->hdr.hdr_mode == NO_HDR) {
2115
+ rkcif_s_rx_buffer(stream, &active_buf->dbufs);
2116
+ atomic_dec(&stream->buf_cnt);
2117
+ } else {
19732118 rkcif_rdbk_frame_end_toisp(stream, active_buf);
2119
+ }
19742120 } else {
19752121 if (stream->cifdev->rdbk_debug && dev->hw_dev->dummy_buf.vaddr)
19762122 v4l2_info(&stream->cifdev->v4l2_dev,
....@@ -1978,13 +2124,19 @@
19782124 stream->id,
19792125 stream->frame_idx - 1);
19802126 }
2127
+ if (dev->is_support_tools && stream->tools_vdev && active_buf)
2128
+ rkcif_rdbk_with_tools(stream, active_buf);
19812129 }
1982
-
19832130 out_get_buf:
19842131 stream->frame_phase_cache = stream->frame_phase;
19852132 if (buffer) {
1986
- rkcif_write_register(dev, frm_addr_y,
1987
- buffer->dummy.dma_addr);
2133
+ buff_addr_y = buffer->dummy.dma_addr;
2134
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2135
+ rkcif_write_buff_addr_multi_dev_combine(stream, frm_addr_y, 0,
2136
+ buff_addr_y, 0, false);
2137
+ } else {
2138
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
2139
+ }
19882140 if (dev->rdbk_debug > 1 &&
19892141 stream->frame_idx < 15)
19902142 v4l2_info(&dev->v4l2_dev,
....@@ -1994,8 +2146,13 @@
19942146 frm_addr_y, (u32)buffer->dummy.dma_addr);
19952147 } else if (dev->hw_dev->dummy_buf.vaddr && priv &&
19962148 priv->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO) {
1997
- rkcif_write_register(dev, frm_addr_y,
1998
- dev->hw_dev->dummy_buf.dma_addr);
2149
+ buff_addr_y = dev->hw_dev->dummy_buf.dma_addr;
2150
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2151
+ rkcif_write_buff_addr_multi_dev_combine(stream, frm_addr_y, 0,
2152
+ buff_addr_y, 0, true);
2153
+ } else {
2154
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
2155
+ }
19992156 }
20002157 spin_unlock_irqrestore(&stream->vbq_lock, flags);
20012158 return 0;
....@@ -2018,16 +2175,20 @@
20182175 struct rkcif_device *dev = stream->cifdev;
20192176 struct v4l2_mbus_config *mbus_cfg = &dev->active_sensor->mbus;
20202177 struct rkcif_rx_buffer *buffer = NULL;
2178
+ struct rkmodule_capture_info *capture_info = &dev->channels[stream->id].capture_info;
20212179 struct rkcif_rx_buffer *active_buf = NULL;
2022
- u32 frm_addr_y;
2180
+ u32 frm_addr_y, buff_addr_y;
20232181 u32 vblank = 0;
20242182 u32 vblank_ns = 0;
20252183 u64 cur_time = 0;
20262184 int frame_phase = 0;
20272185 int frame_phase_next = 0;
2028
- bool is_early_update = false;
20292186
2030
- if (stream->curr_buf_toisp != stream->next_buf_toisp) {
2187
+ if (stream->toisp_buf_state.state == RKCIF_TOISP_BUF_ROTATE ||
2188
+ (stream->toisp_buf_state.state == RKCIF_TOISP_BUF_THESAME &&
2189
+ stream->toisp_buf_state.check_cnt >= 1) ||
2190
+ (stream->toisp_buf_state.state == RKCIF_TOISP_BUF_LOSS &&
2191
+ stream->toisp_buf_state.check_cnt >= 2)) {
20312192 if (dev->rdbk_debug > 2 &&
20322193 stream->frame_idx < 15)
20332194 v4l2_info(&dev->v4l2_dev,
....@@ -2041,20 +2202,26 @@
20412202 dev->sensor_linetime = rkcif_get_linetime(stream);
20422203 vblank = rkcif_get_sensor_vblank(dev);
20432204 vblank_ns = vblank * dev->sensor_linetime;
2044
- cur_time = ktime_get_ns();
2205
+ cur_time = rkcif_time_get_ns(dev);
20452206
2046
- if (dev->chip_id > CHIP_RK3568_CIF &&
2047
- dev->hdr.hdr_mode == NO_HDR &&
2048
- cur_time - stream->readout.fe_timestamp < (vblank_ns - 500000) &&
2049
- stream->lack_buf_cnt == 2 &&
2050
- stream->frame_idx > stream->last_frame_idx) {
2051
- is_early_update = true;
2052
- frame_phase = stream->frame_phase & CIF_CSI_FRAME0_READY ?
2053
- CIF_CSI_FRAME1_READY : CIF_CSI_FRAME0_READY;
2054
- frame_phase_next = stream->frame_phase & CIF_CSI_FRAME0_READY ?
2055
- CIF_CSI_FRAME0_READY : CIF_CSI_FRAME1_READY;
2056
- } else {
2207
+ if (stream->toisp_buf_state.state == RKCIF_TOISP_BUF_THESAME) {
20572208 frame_phase = stream->frame_phase;
2209
+ } else {
2210
+ if (stream->toisp_buf_state.state == RKCIF_TOISP_BUF_LOSS &&
2211
+ stream->toisp_buf_state.check_cnt == 0 &&
2212
+ cur_time - stream->readout.fe_timestamp < (vblank_ns - 500000)) {
2213
+ stream->toisp_buf_state.is_early_update = true;
2214
+ frame_phase = stream->frame_phase & CIF_CSI_FRAME0_READY ?
2215
+ CIF_CSI_FRAME1_READY : CIF_CSI_FRAME0_READY;
2216
+ frame_phase_next = stream->frame_phase & CIF_CSI_FRAME0_READY ?
2217
+ CIF_CSI_FRAME0_READY : CIF_CSI_FRAME1_READY;
2218
+ } else {
2219
+ if (stream->toisp_buf_state.check_cnt == 1 &&
2220
+ (!stream->toisp_buf_state.is_early_update))
2221
+ return;
2222
+ frame_phase = stream->frame_phase;
2223
+ stream->toisp_buf_state.is_early_update = false;
2224
+ }
20582225 }
20592226 if (dev->rdbk_debug > 2 &&
20602227 stream->frame_idx < 15)
....@@ -2082,8 +2249,15 @@
20822249 if (buffer) {
20832250 list_del(&buffer->list);
20842251 stream->curr_buf_toisp = buffer;
2085
- rkcif_write_register(dev, frm_addr_y,
2086
- stream->curr_buf_toisp->dummy.dma_addr);
2252
+ buff_addr_y = stream->curr_buf_toisp->dummy.dma_addr;
2253
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2254
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2255
+ frm_addr_y, 0,
2256
+ buff_addr_y, 0,
2257
+ false);
2258
+ } else {
2259
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
2260
+ }
20872261 if (dev->rdbk_debug > 1 &&
20882262 stream->frame_idx < 15)
20892263 v4l2_info(&dev->v4l2_dev,
....@@ -2091,7 +2265,6 @@
20912265 stream->id,
20922266 stream->frame_idx - 1, frm_addr_y,
20932267 (u32)stream->curr_buf_toisp->dummy.dma_addr);
2094
- stream->buf_num_toisp--;
20952268 }
20962269 } else if (frame_phase == CIF_CSI_FRAME1_READY) {
20972270 active_buf = stream->next_buf_toisp;
....@@ -2100,8 +2273,15 @@
21002273 if (buffer) {
21012274 list_del(&buffer->list);
21022275 stream->next_buf_toisp = buffer;
2103
- rkcif_write_register(dev, frm_addr_y,
2104
- stream->next_buf_toisp->dummy.dma_addr);
2276
+ buff_addr_y = stream->next_buf_toisp->dummy.dma_addr;
2277
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2278
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2279
+ frm_addr_y, 0,
2280
+ buff_addr_y, 0,
2281
+ false);
2282
+ } else {
2283
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
2284
+ }
21052285 if (dev->rdbk_debug > 1 &&
21062286 stream->frame_idx < 15)
21072287 v4l2_info(&dev->v4l2_dev,
....@@ -2109,13 +2289,12 @@
21092289 stream->id,
21102290 stream->frame_idx - 1, frm_addr_y,
21112291 (u32)stream->next_buf_toisp->dummy.dma_addr);
2112
- stream->buf_num_toisp--;
21132292 }
21142293 }
21152294 if (stream->lack_buf_cnt)
21162295 stream->lack_buf_cnt--;
21172296 }
2118
- if (is_early_update) {
2297
+ if (stream->toisp_buf_state.is_early_update) {
21192298 if (dev->rdbk_debug > 1 &&
21202299 stream->frame_idx < 15)
21212300 v4l2_info(&dev->v4l2_dev,
....@@ -2131,7 +2310,7 @@
21312310 active_buf->dbufs.sequence = stream->frame_idx - 1;
21322311 active_buf->dbufs.timestamp = stream->readout.fs_timestamp;
21332312 stream->last_frame_idx = stream->frame_idx;
2134
- rkcif_s_rx_buffer(dev, &active_buf->dbufs);
2313
+ rkcif_s_rx_buffer(stream, &active_buf->dbufs);
21352314 }
21362315 if (dev->hw_dev->dummy_buf.vaddr)
21372316 return;
....@@ -2150,9 +2329,15 @@
21502329 stream->next_buf_toisp = stream->curr_buf_toisp;
21512330 else
21522331 stream->curr_buf_toisp = stream->next_buf_toisp;
2153
- rkcif_write_register(dev, frm_addr_y,
2154
- stream->curr_buf_toisp->dummy.dma_addr);
2332
+ buff_addr_y = stream->curr_buf_toisp->dummy.dma_addr;
2333
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2334
+ rkcif_write_buff_addr_multi_dev_combine(stream, frm_addr_y, 0,
2335
+ buff_addr_y, 0, false);
2336
+ } else {
2337
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
2338
+ }
21552339 }
2340
+ stream->toisp_buf_state.check_cnt++;
21562341 }
21572342
21582343 static void rkcif_assign_new_buffer_init(struct rkcif_stream *stream,
....@@ -2162,10 +2347,12 @@
21622347 struct v4l2_mbus_config *mbus_cfg = &dev->active_sensor->mbus;
21632348 u32 frm0_addr_y, frm0_addr_uv;
21642349 u32 frm1_addr_y, frm1_addr_uv;
2350
+ u32 buff_addr_y, buff_addr_cbcr;
21652351 unsigned long flags;
21662352 struct rkcif_dummy_buffer *dummy_buf = &dev->hw_dev->dummy_buf;
21672353 struct csi_channel_info *channel = &dev->channels[channel_id];
21682354
2355
+ stream->lack_buf_cnt = 0;
21692356 if (mbus_cfg->type == V4L2_MBUS_CSI2_DPHY ||
21702357 mbus_cfg->type == V4L2_MBUS_CSI2_CPHY ||
21712358 mbus_cfg->type == V4L2_MBUS_CCP2) {
....@@ -2187,21 +2374,45 @@
21872374 stream->curr_buf = list_first_entry(&stream->buf_head,
21882375 struct rkcif_buffer,
21892376 queue);
2377
+ v4l2_dbg(4, rkcif_debug, &dev->v4l2_dev, "%s %d, stream[%d] buf idx %d\n",
2378
+ __func__, __LINE__, stream->id, stream->curr_buf->vb.vb2_buf.index);
21902379 list_del(&stream->curr_buf->queue);
21912380 }
21922381 }
21932382
21942383 if (stream->curr_buf) {
2195
- rkcif_write_register(dev, frm0_addr_y,
2196
- stream->curr_buf->buff_addr[RKCIF_PLANE_Y]);
2197
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2198
- rkcif_write_register(dev, frm0_addr_uv,
2199
- stream->curr_buf->buff_addr[RKCIF_PLANE_CBCR]);
2384
+ buff_addr_y = stream->curr_buf->buff_addr[RKCIF_PLANE_Y];
2385
+ buff_addr_cbcr = stream->curr_buf->buff_addr[RKCIF_PLANE_CBCR];
2386
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2387
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2388
+ frm0_addr_y,
2389
+ frm0_addr_uv,
2390
+ buff_addr_y,
2391
+ buff_addr_cbcr,
2392
+ false);
2393
+ } else {
2394
+ rkcif_write_register(dev, frm0_addr_y,
2395
+ stream->curr_buf->buff_addr[RKCIF_PLANE_Y]);
2396
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2397
+ rkcif_write_register(dev, frm0_addr_uv,
2398
+ stream->curr_buf->buff_addr[RKCIF_PLANE_CBCR]);
2399
+ }
22002400 } else {
22012401 if (dummy_buf->vaddr) {
2202
- rkcif_write_register(dev, frm0_addr_y, dummy_buf->dma_addr);
2203
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2204
- rkcif_write_register(dev, frm0_addr_uv, dummy_buf->dma_addr);
2402
+ buff_addr_y = dummy_buf->dma_addr;
2403
+ buff_addr_cbcr = dummy_buf->dma_addr;
2404
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2405
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2406
+ frm0_addr_y,
2407
+ frm0_addr_uv,
2408
+ buff_addr_y,
2409
+ buff_addr_cbcr,
2410
+ true);
2411
+ } else {
2412
+ rkcif_write_register(dev, frm0_addr_y, buff_addr_y);
2413
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2414
+ rkcif_write_register(dev, frm0_addr_uv, buff_addr_cbcr);
2415
+ }
22052416 } else {
22062417 if (stream->lack_buf_cnt < 2)
22072418 stream->lack_buf_cnt++;
....@@ -2211,43 +2422,71 @@
22112422 if (stream->cif_fmt_in->field == V4L2_FIELD_INTERLACED) {
22122423 stream->next_buf = stream->curr_buf;
22132424 if (stream->next_buf) {
2214
- rkcif_write_register(dev, frm1_addr_y,
2215
- stream->next_buf->buff_addr[RKCIF_PLANE_Y] + (channel->virtual_width / 2));
2216
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2217
- rkcif_write_register(dev, frm1_addr_uv,
2218
- stream->next_buf->buff_addr[RKCIF_PLANE_CBCR] + (channel->virtual_width / 2));
2425
+ buff_addr_y = stream->next_buf->buff_addr[RKCIF_PLANE_Y];
2426
+ buff_addr_cbcr = stream->next_buf->buff_addr[RKCIF_PLANE_CBCR];
2427
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2428
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2429
+ frm1_addr_y,
2430
+ frm1_addr_uv,
2431
+ buff_addr_y,
2432
+ buff_addr_cbcr,
2433
+ false);
2434
+ } else {
2435
+ rkcif_write_register(dev, frm1_addr_y,
2436
+ buff_addr_y + (channel->virtual_width / 2));
2437
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2438
+ rkcif_write_register(dev, frm1_addr_uv,
2439
+ buff_addr_cbcr + (channel->virtual_width / 2));
2440
+ }
22192441 }
22202442 } else {
22212443 if (!stream->next_buf) {
22222444 if (!list_empty(&stream->buf_head)) {
22232445 stream->next_buf = list_first_entry(&stream->buf_head,
22242446 struct rkcif_buffer, queue);
2447
+ v4l2_dbg(4, rkcif_debug, &dev->v4l2_dev, "%s %d, stream[%d] buf idx %d\n",
2448
+ __func__, __LINE__, stream->id, stream->next_buf->vb.vb2_buf.index);
22252449 list_del(&stream->next_buf->queue);
2450
+ } else if (stream->curr_buf) {
2451
+ stream->next_buf = stream->curr_buf;
22262452 }
22272453 }
22282454
2229
- if (stream->next_buf) {
2230
- rkcif_write_register(dev, frm1_addr_y,
2231
- stream->next_buf->buff_addr[RKCIF_PLANE_Y]);
2232
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2233
- rkcif_write_register(dev, frm1_addr_uv,
2234
- stream->next_buf->buff_addr[RKCIF_PLANE_CBCR]);
2235
- } else {
2236
- if (dummy_buf->vaddr) {
2455
+ if (!stream->next_buf && dummy_buf->vaddr) {
2456
+ buff_addr_y = dummy_buf->dma_addr;
2457
+ buff_addr_cbcr = dummy_buf->dma_addr;
2458
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2459
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2460
+ frm1_addr_y,
2461
+ frm1_addr_uv,
2462
+ buff_addr_y,
2463
+ buff_addr_cbcr,
2464
+ true);
2465
+ } else {
22372466 rkcif_write_register(dev, frm1_addr_y, dummy_buf->dma_addr);
22382467 if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
22392468 rkcif_write_register(dev, frm1_addr_uv, dummy_buf->dma_addr);
2469
+ }
2470
+
2471
+ } else if (!stream->next_buf && stream->curr_buf) {
2472
+ stream->next_buf = stream->curr_buf;
2473
+ if (stream->lack_buf_cnt < 2)
2474
+ stream->lack_buf_cnt++;
2475
+ }
2476
+ if (stream->next_buf) {
2477
+ buff_addr_y = stream->next_buf->buff_addr[RKCIF_PLANE_Y];
2478
+ buff_addr_cbcr = stream->next_buf->buff_addr[RKCIF_PLANE_CBCR];
2479
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2480
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2481
+ frm1_addr_y,
2482
+ frm1_addr_uv,
2483
+ buff_addr_y,
2484
+ buff_addr_cbcr,
2485
+ false);
22402486 } else {
2241
- if (stream->curr_buf) {
2242
- stream->next_buf = stream->curr_buf;
2243
- rkcif_write_register(dev, frm1_addr_y,
2244
- stream->next_buf->buff_addr[RKCIF_PLANE_Y]);
2245
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2246
- rkcif_write_register(dev, frm1_addr_uv,
2247
- stream->next_buf->buff_addr[RKCIF_PLANE_CBCR]);
2248
- }
2249
- if (stream->lack_buf_cnt < 2)
2250
- stream->lack_buf_cnt++;
2487
+ rkcif_write_register(dev, frm1_addr_y, buff_addr_y);
2488
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2489
+ rkcif_write_register(dev, frm1_addr_uv, buff_addr_cbcr);
22512490 }
22522491 }
22532492 }
....@@ -2295,6 +2534,7 @@
22952534 struct rkisp_rx_buf *dbufs = NULL;
22962535 struct dma_buf *dbuf = NULL;
22972536 int ret = 0;
2537
+ u32 buff_addr_y, buff_addr_cbcr;
22982538 unsigned long flags;
22992539
23002540 if (mbus_cfg->type == V4L2_MBUS_CSI2_DPHY ||
....@@ -2315,19 +2555,9 @@
23152555 get_dvp_reg_index_of_frm1_uv_addr(channel_id);
23162556 }
23172557
2318
- if (dev->hdr.hdr_mode != NO_HDR && stream->id != 0 && (!dev->rdbk_buf[RDBK_L])) {
2558
+ if (stream->to_stop_dma && (stream->dma_en & RKCIF_DMAEN_BY_ISP)) {
23192559 v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev, "%s %d\n", __func__, __LINE__);
2320
- return -EINVAL;
2321
- }
2322
-
2323
- if (stream->to_stop_dma) {
2324
- if (stream->dma_en & RKCIF_DMAEN_BY_ISP) {
2325
- v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev, "%s %d\n", __func__, __LINE__);
2326
- goto stop_dma;
2327
- } else {
2328
- v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev, "%s %d\n", __func__, __LINE__);
2329
- return -EINVAL;
2330
- }
2560
+ goto stop_dma;
23312561 }
23322562
23332563 spin_lock_irqsave(&stream->vbq_lock, flags);
....@@ -2347,8 +2577,8 @@
23472577 list_del(&stream->curr_buf->queue);
23482578 buffer = stream->curr_buf;
23492579 v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev,
2350
- "stream[%d] update curr_buf 0x%x\n",
2351
- stream->id, buffer->buff_addr[0]);
2580
+ "stream[%d] update curr_buf 0x%x, buf idx %d\n",
2581
+ stream->id, buffer->buff_addr[0], stream->curr_buf->vb.vb2_buf.index);
23522582 }
23532583 } else if (stream->frame_phase == CIF_CSI_FRAME1_READY) {
23542584 if (!stream->next_buf)
....@@ -2368,14 +2598,14 @@
23682598 list_del(&stream->next_buf->queue);
23692599 buffer = stream->next_buf;
23702600 v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev,
2371
- "stream[%d] update next_buf 0x%x\n",
2372
- stream->id, buffer->buff_addr[0]);
2601
+ "stream[%d] update next_buf 0x%x, buf idx %d\n",
2602
+ stream->id, buffer->buff_addr[0], stream->next_buf->vb.vb2_buf.index);
23732603 }
23742604 }
23752605 }
2376
- } else if (!(stream->dma_en & RKCIF_DMAEN_BY_ISP)) {
2606
+ } else {
23772607 buffer = NULL;
2378
- if (dummy_buf->vaddr) {
2608
+ if (!(stream->cur_stream_mode & RKCIF_STREAM_MODE_TOISP) && dummy_buf->vaddr) {
23792609 if (stream->frame_phase == CIF_CSI_FRAME0_READY) {
23802610 stream->curr_buf = NULL;
23812611 } else if (stream->frame_phase == CIF_CSI_FRAME1_READY) {
....@@ -2386,12 +2616,11 @@
23862616 stream->next_buf = NULL;
23872617 }
23882618 }
2389
- } else if (stream->curr_buf && stream->next_buf &&
2390
- stream->curr_buf != stream->next_buf) {
2391
- if (stream->frame_phase == CIF_CSI_FRAME0_READY) {
2619
+ } else if (stream->curr_buf != stream->next_buf) {
2620
+ if (stream->frame_phase == CIF_CSI_FRAME0_READY && stream->next_buf) {
23922621 stream->curr_buf = stream->next_buf;
23932622 buffer = stream->next_buf;
2394
- } else if (stream->frame_phase == CIF_CSI_FRAME1_READY) {
2623
+ } else if (stream->frame_phase == CIF_CSI_FRAME1_READY && stream->curr_buf) {
23952624 stream->next_buf = stream->curr_buf;
23962625 buffer = stream->curr_buf;
23972626 }
....@@ -2407,19 +2636,37 @@
24072636 stream->frame_phase_cache = stream->frame_phase;
24082637
24092638 if (buffer) {
2639
+ buff_addr_y = buffer->buff_addr[RKCIF_PLANE_Y];
2640
+ buff_addr_cbcr = buffer->buff_addr[RKCIF_PLANE_CBCR];
24102641 if (stream->cif_fmt_in->field == V4L2_FIELD_INTERLACED &&
24112642 stream->frame_phase == CIF_CSI_FRAME1_READY) {
2412
- rkcif_write_register(dev, frm_addr_y,
2413
- buffer->buff_addr[RKCIF_PLANE_Y] + (channel->virtual_width / 2));
2414
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2415
- rkcif_write_register(dev, frm_addr_uv,
2416
- buffer->buff_addr[RKCIF_PLANE_CBCR] + (channel->virtual_width / 2));
2643
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2644
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2645
+ frm_addr_y,
2646
+ frm_addr_uv,
2647
+ buff_addr_y,
2648
+ buff_addr_cbcr,
2649
+ false);
2650
+ } else {
2651
+ rkcif_write_register(dev, frm_addr_y,
2652
+ buff_addr_y + (channel->virtual_width / 2));
2653
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2654
+ rkcif_write_register(dev, frm_addr_uv,
2655
+ buff_addr_cbcr + (channel->virtual_width / 2));
2656
+ }
24172657 } else {
2418
- rkcif_write_register(dev, frm_addr_y,
2419
- buffer->buff_addr[RKCIF_PLANE_Y]);
2420
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2421
- rkcif_write_register(dev, frm_addr_uv,
2422
- buffer->buff_addr[RKCIF_PLANE_CBCR]);
2658
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2659
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2660
+ frm_addr_y,
2661
+ frm_addr_uv,
2662
+ buff_addr_y,
2663
+ buff_addr_cbcr,
2664
+ false);
2665
+ } else {
2666
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
2667
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2668
+ rkcif_write_register(dev, frm_addr_uv, buff_addr_cbcr);
2669
+ }
24232670 }
24242671 if (stream->dma_en & RKCIF_DMAEN_BY_ISP) {
24252672 if (stream->buf_replace_cnt < 2)
....@@ -2438,50 +2685,7 @@
24382685 }
24392686 }
24402687 if (dbufs)
2441
- rkcif_s_rx_buffer(dev, dbufs);
2442
- stream->buf_num_toisp--;
2443
- }
2444
- } else {
2445
- if (stream->dma_en & RKCIF_DMAEN_BY_ISP) {
2446
- rkcif_write_register(dev, frm_addr_y,
2447
- stream->curr_buf_toisp->dummy.dma_addr);
2448
- if (stream->frame_phase == CIF_CSI_FRAME0_READY &&
2449
- stream->next_buf)
2450
- dbuf = stream->next_buf->dbuf;
2451
- else if (stream->frame_phase == CIF_CSI_FRAME1_READY &&
2452
- stream->curr_buf)
2453
- dbuf = stream->curr_buf->dbuf;
2454
-
2455
- if (dbuf) {
2456
- list_for_each_entry(dbufs, &stream->rx_buf_head_vicap, list)
2457
- if (dbufs->dbuf == dbuf)
2458
- break;
2459
- } else {
2460
- dbufs = &stream->curr_buf_toisp->dbufs;
2461
- }
2462
- rkcif_s_rx_buffer(dev, dbufs);
2463
- stream->buf_num_toisp--;
2464
- if (stream->curr_buf && stream->frame_phase == CIF_CSI_FRAME0_READY) {
2465
- stream->curr_buf = NULL;
2466
- if (stream->buf_replace_cnt)
2467
- stream->buf_replace_cnt--;
2468
- } else if (stream->next_buf && stream->frame_phase == CIF_CSI_FRAME1_READY) {
2469
- stream->next_buf = NULL;
2470
- if (stream->buf_replace_cnt)
2471
- stream->buf_replace_cnt--;
2472
- }
2473
- } else if (dummy_buf->vaddr) {
2474
- rkcif_write_register(dev, frm_addr_y, dummy_buf->dma_addr);
2475
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2476
- rkcif_write_register(dev, frm_addr_uv, dummy_buf->dma_addr);
2477
- dev->err_state |= (RKCIF_ERR_ID0_NOT_BUF << stream->id);
2478
- dev->irq_stats.not_active_buf_cnt[stream->id]++;
2479
- } else {
2480
- ret = -EINVAL;
2481
- stream->curr_buf = NULL;
2482
- stream->next_buf = NULL;
2483
- dev->err_state |= (RKCIF_ERR_ID0_NOT_BUF << stream->id);
2484
- dev->irq_stats.not_active_buf_cnt[stream->id]++;
2688
+ rkcif_s_rx_buffer(stream, dbufs);
24852689 }
24862690 }
24872691 spin_unlock_irqrestore(&stream->vbq_lock, flags);
....@@ -2489,8 +2693,13 @@
24892693 stop_dma:
24902694 if (stream->buf_replace_cnt) {
24912695 spin_lock_irqsave(&stream->vbq_lock, flags);
2492
- rkcif_write_register(dev, frm_addr_y,
2493
- stream->curr_buf_toisp->dummy.dma_addr);
2696
+ buff_addr_y = stream->curr_buf_toisp->dummy.dma_addr;
2697
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE)
2698
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2699
+ frm_addr_y, 0,
2700
+ buff_addr_y, 0, false);
2701
+ else
2702
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
24942703 if (stream->frame_phase == CIF_CSI_FRAME0_READY &&
24952704 stream->next_buf)
24962705 dbuf = stream->next_buf->dbuf;
....@@ -2506,16 +2715,13 @@
25062715 dbufs = &stream->curr_buf_toisp->dbufs;
25072716 }
25082717 if (dbufs)
2509
- rkcif_s_rx_buffer(dev, dbufs);
2510
- stream->buf_num_toisp--;
2718
+ rkcif_s_rx_buffer(stream, dbufs);
25112719
25122720 if (stream->frame_phase == CIF_CSI_FRAME0_READY &&
25132721 stream->curr_buf) {
2514
- list_add_tail(&stream->curr_buf->queue, &stream->buf_head);
25152722 stream->curr_buf = NULL;
25162723 } else if (stream->frame_phase == CIF_CSI_FRAME1_READY &&
25172724 stream->next_buf) {
2518
- list_add_tail(&stream->next_buf->queue, &stream->buf_head);
25192725 stream->next_buf = NULL;
25202726 }
25212727 stream->buf_replace_cnt--;
....@@ -2587,8 +2793,10 @@
25872793 struct rkcif_device *dev = stream->cifdev;
25882794 struct rkcif_dummy_buffer *dummy_buf = &dev->hw_dev->dummy_buf;
25892795 struct v4l2_mbus_config *mbus_cfg = &dev->active_sensor->mbus;
2796
+ struct rkmodule_capture_info *capture_info = &dev->channels[stream->id].capture_info;
25902797 struct rkcif_buffer *buffer = NULL;
25912798 u32 frm_addr_y, frm_addr_uv;
2799
+ u32 buff_addr_y, buff_addr_cbcr;
25922800 int channel_id = stream->id;
25932801 int ret = 0;
25942802 unsigned long flags;
....@@ -2619,16 +2827,35 @@
26192827 }
26202828 spin_unlock_irqrestore(&stream->vbq_lock, flags);
26212829 if (buffer) {
2622
- rkcif_write_register(dev, frm_addr_y,
2623
- buffer->buff_addr[RKCIF_PLANE_Y]);
2624
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2625
- rkcif_write_register(dev, frm_addr_uv,
2626
- buffer->buff_addr[RKCIF_PLANE_CBCR]);
2830
+ buff_addr_y = buffer->buff_addr[RKCIF_PLANE_Y];
2831
+ buff_addr_cbcr = buffer->buff_addr[RKCIF_PLANE_CBCR];
2832
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2833
+ rkcif_write_buff_addr_multi_dev_combine(stream, frm_addr_y,
2834
+ frm_addr_uv,
2835
+ buff_addr_y,
2836
+ buff_addr_cbcr,
2837
+ false);
2838
+ } else {
2839
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
2840
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2841
+ rkcif_write_register(dev, frm_addr_uv, buff_addr_cbcr);
2842
+ }
26272843 } else {
26282844 if (dummy_buf->vaddr) {
2629
- rkcif_write_register(dev, frm_addr_y, dummy_buf->dma_addr);
2630
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2631
- rkcif_write_register(dev, frm_addr_uv, dummy_buf->dma_addr);
2845
+ buff_addr_y = dummy_buf->dma_addr;
2846
+ buff_addr_cbcr = dummy_buf->dma_addr;
2847
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
2848
+ rkcif_write_buff_addr_multi_dev_combine(stream,
2849
+ frm_addr_y,
2850
+ frm_addr_uv,
2851
+ buff_addr_y,
2852
+ buff_addr_cbcr,
2853
+ true);
2854
+ } else {
2855
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
2856
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
2857
+ rkcif_write_register(dev, frm_addr_uv, buff_addr_cbcr);
2858
+ }
26322859 } else {
26332860 if (dev->chip_id < CHIP_RK3588_CIF)
26342861 ret = -EINVAL;
....@@ -2653,7 +2880,13 @@
26532880 int frame_phase = 0;
26542881
26552882 spin_lock_irqsave(&stream->vbq_lock, flags);
2883
+ memset(&stream->toisp_buf_state, 0, sizeof(stream->toisp_buf_state));
26562884 if (!list_empty(&stream->rx_buf_head)) {
2885
+ if (stream->curr_buf_toisp && stream->next_buf_toisp &&
2886
+ stream->curr_buf_toisp != stream->next_buf_toisp)
2887
+ stream->toisp_buf_state.state = RKCIF_TOISP_BUF_ROTATE;
2888
+ else
2889
+ stream->toisp_buf_state.state = RKCIF_TOISP_BUF_LOSS;
26572890 if (stream->line_int_cnt % 2) {
26582891 buffer = list_first_entry(&stream->rx_buf_head,
26592892 struct rkcif_rx_buffer, list);
....@@ -2689,8 +2922,10 @@
26892922 "stream[%d] hold buf %x\n",
26902923 stream->id,
26912924 (u32)stream->next_buf_toisp->dummy.dma_addr);
2925
+ stream->toisp_buf_state.state = RKCIF_TOISP_BUF_THESAME;
26922926 } else {
26932927 ret = -EINVAL;
2928
+ stream->toisp_buf_state.state = RKCIF_TOISP_BUF_LOSS;
26942929 }
26952930 }
26962931 if (buffer) {
....@@ -3163,6 +3398,7 @@
31633398 struct csi_channel_info *channel)
31643399 {
31653400 struct rkcif_device *dev = stream->cifdev;
3401
+ struct sditf_priv *priv = dev->sditf[0];
31663402 const struct cif_output_fmt *fmt;
31673403 u32 fourcc;
31683404 int vc = dev->channels[stream->id].vc;
....@@ -3187,7 +3423,7 @@
31873423 channel->crop_st_x = stream->crop[CROP_SRC_ACT].left;
31883424
31893425 channel->crop_st_y = stream->crop[CROP_SRC_ACT].top;
3190
- if (dev->sditf_cnt > 1 && dev->sditf_cnt <= RKCIF_MAX_SDITF)
3426
+ if (priv && priv->is_combine_mode && dev->sditf_cnt <= RKCIF_MAX_SDITF)
31913427 channel->crop_st_y *= dev->sditf_cnt;
31923428 channel->width = stream->crop[CROP_SRC_ACT].width;
31933429 channel->height = stream->crop[CROP_SRC_ACT].height;
....@@ -3197,7 +3433,7 @@
31973433 channel->crop_en = 0;
31983434 }
31993435
3200
- if (dev->sditf_cnt > 1 && dev->sditf_cnt <= RKCIF_MAX_SDITF)
3436
+ if (priv && priv->is_combine_mode && dev->sditf_cnt <= RKCIF_MAX_SDITF)
32013437 channel->height *= dev->sditf_cnt;
32023438
32033439 fmt = rkcif_find_output_fmt(stream, stream->pixm.pixelformat);
....@@ -3207,6 +3443,8 @@
32073443 return -EINVAL;
32083444 }
32093445
3446
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE)
3447
+ channel->width /= channel->capture_info.multi_dev.dev_num;
32103448 /*
32113449 * for mipi or lvds, when enable compact, the virtual width of raw10/raw12
32123450 * needs aligned with :ALIGN(bits_per_pixel * width / 8, 8), if enable 16bit mode
....@@ -3216,9 +3454,19 @@
32163454 if (fmt->fmt_type == CIF_FMT_TYPE_RAW && stream->is_compact &&
32173455 fmt->csi_fmt_val != CSI_WRDDR_TYPE_RGB888 &&
32183456 fmt->csi_fmt_val != CSI_WRDDR_TYPE_RGB565) {
3219
- channel->virtual_width = ALIGN(channel->width * fmt->raw_bpp / 8, 256);
3457
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
3458
+ channel->virtual_width = ALIGN(channel->width * 2 * fmt->raw_bpp / 8, 256);
3459
+ channel->left_virtual_width = channel->width * fmt->raw_bpp / 8;
3460
+ } else {
3461
+ channel->virtual_width = ALIGN(channel->width * fmt->raw_bpp / 8, 256);
3462
+ }
32203463 } else {
3221
- channel->virtual_width = ALIGN(channel->width * fmt->bpp[0] / 8, 8);
3464
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
3465
+ channel->virtual_width = ALIGN(channel->width * 2 * fmt->bpp[0] / 8, 8);
3466
+ channel->left_virtual_width = ALIGN(channel->width * fmt->bpp[0] / 8, 8);
3467
+ } else {
3468
+ channel->virtual_width = ALIGN(channel->width * fmt->bpp[0] / 8, 8);
3469
+ }
32223470 }
32233471
32243472 if (channel->fmt_val == CSI_WRDDR_TYPE_RGB888 || channel->fmt_val == CSI_WRDDR_TYPE_RGB565)
....@@ -3237,6 +3485,8 @@
32373485 channel->width *= 2;
32383486 }
32393487 channel->virtual_width *= 2;
3488
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE)
3489
+ channel->left_virtual_width *= 2;
32403490 }
32413491 if (stream->cif_fmt_in->field == V4L2_FIELD_INTERLACED) {
32423492 channel->virtual_width *= 2;
....@@ -3387,6 +3637,7 @@
33873637 val &= ~CSI_HIGH_ALIGN;
33883638 rkcif_write_register(dev, get_reg_index_of_id_ctrl0(channel->id), val);
33893639
3640
+ dev->intr_mask = rkcif_read_register(dev, CIF_REG_MIPI_LVDS_INTEN);
33903641 return 0;
33913642 }
33923643
....@@ -3585,15 +3836,18 @@
35853836
35863837 /*config reg for rk3588*/
35873838 static int rkcif_csi_channel_set_v1(struct rkcif_stream *stream,
3588
- struct csi_channel_info *channel,
3589
- enum v4l2_mbus_type mbus_type, unsigned int mode)
3839
+ struct csi_channel_info *channel,
3840
+ enum v4l2_mbus_type mbus_type, unsigned int mode,
3841
+ int index)
35903842 {
35913843 unsigned int val = 0x0;
35923844 struct rkcif_device *dev = stream->cifdev;
35933845 struct rkcif_stream *detect_stream = &dev->stream[0];
35943846 struct sditf_priv *priv = dev->sditf[0];
3847
+ struct rkmodule_capture_info *capture_info = &channel->capture_info;
35953848 unsigned int wait_line = 0x3fff;
35963849 unsigned int dma_en = 0;
3850
+ int offset = 0;
35973851
35983852 if (channel->id >= 4)
35993853 return -EINVAL;
....@@ -3609,21 +3863,28 @@
36093863 CSI_DMA_END_INTSTAT(channel->id) |
36103864 CSI_LINE_INTSTAT_V1(channel->id)));
36113865
3612
- rkcif_write_register_or(dev, CIF_REG_MIPI_LVDS_INTEN,
3613
- CSI_START_INTEN(channel->id));
3866
+ if (!(capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE &&
3867
+ index < capture_info->multi_dev.dev_num - 1)) {
36143868
3615
- if (priv && priv->mode.rdbk_mode && detect_stream->is_line_wake_up) {
36163869 rkcif_write_register_or(dev, CIF_REG_MIPI_LVDS_INTEN,
3617
- CSI_LINE_INTEN_RK3588(channel->id));
3618
- wait_line = dev->wait_line;
3619
- }
3620
- rkcif_write_register(dev, CIF_REG_MIPI_LVDS_LINE_INT_NUM_ID0_1,
3621
- wait_line << 16 | wait_line);
3622
- rkcif_write_register(dev, CIF_REG_MIPI_LVDS_LINE_INT_NUM_ID2_3,
3623
- wait_line << 16 | wait_line);
3870
+ CSI_START_INTEN(channel->id));
36243871
3625
- rkcif_write_register_or(dev, CIF_REG_MIPI_LVDS_INTEN,
3626
- CSI_DMA_END_INTEN(channel->id));
3872
+ if (priv && priv->mode.rdbk_mode && detect_stream->is_line_wake_up) {
3873
+ rkcif_write_register_or(dev, CIF_REG_MIPI_LVDS_INTEN,
3874
+ CSI_LINE_INTEN_RK3588(channel->id));
3875
+ wait_line = dev->wait_line;
3876
+ }
3877
+ rkcif_write_register(dev, CIF_REG_MIPI_LVDS_LINE_INT_NUM_ID0_1,
3878
+ wait_line << 16 | wait_line);
3879
+ rkcif_write_register(dev, CIF_REG_MIPI_LVDS_LINE_INT_NUM_ID2_3,
3880
+ wait_line << 16 | wait_line);
3881
+
3882
+ rkcif_write_register_or(dev, CIF_REG_MIPI_LVDS_INTEN,
3883
+ CSI_DMA_END_INTEN(channel->id));
3884
+
3885
+ rkcif_write_register_or(dev, CIF_REG_MIPI_LVDS_INTEN,
3886
+ CSI_ALL_ERROR_INTEN_V1);
3887
+ }
36273888 if (stream->cifdev->id_use_cnt == 0) {
36283889 val = CIF_MIPI_LVDS_SW_PRESS_VALUE_RK3588(0x3) |
36293890 CIF_MIPI_LVDS_SW_PRESS_ENABLE |
....@@ -3637,24 +3898,25 @@
36373898 else
36383899 val |= CIF_MIPI_LVDS_SW_SEL_LVDS_RV1106;
36393900 rkcif_write_register(dev, CIF_REG_MIPI_LVDS_CTRL, val);
3640
-
3641
- rkcif_write_register_or(dev, CIF_REG_MIPI_LVDS_INTEN,
3642
- CSI_ALL_ERROR_INTEN_V1);
36433901 }
36443902 #if IS_ENABLED(CONFIG_CPU_RV1106)
36453903 if (channel->id == 1)
36463904 rv1106_sdmmc_get_lock();
36473905 #endif
3906
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE &&
3907
+ priv && priv->mode.rdbk_mode == RKISP_VICAP_ONLINE &&
3908
+ (dev->hdr.hdr_mode == NO_HDR ||
3909
+ (dev->hdr.hdr_mode == HDR_X2 && stream->id == 1) ||
3910
+ (dev->hdr.hdr_mode == HDR_X3 && stream->id == 2)))
3911
+ offset = channel->capture_info.multi_dev.pixel_offset;
3912
+
36483913 rkcif_write_register(dev, get_reg_index_of_id_ctrl1(channel->id),
3649
- channel->width | (channel->height << 16));
3914
+ (channel->width + offset) | (channel->height << 16));
36503915
36513916 #if IS_ENABLED(CONFIG_CPU_RV1106)
36523917 if (channel->id == 1)
36533918 rv1106_sdmmc_put_lock();
36543919 #endif
3655
-
3656
- rkcif_write_register(dev, get_reg_index_of_frm0_y_vlw(channel->id),
3657
- channel->virtual_width);
36583920
36593921 if (channel->crop_en)
36603922 rkcif_write_register(dev, get_reg_index_of_id_crop_start(channel->id),
....@@ -3673,6 +3935,17 @@
36733935 rkcif_assign_new_buffer_pingpong_rockit(stream,
36743936 RKCIF_YUV_ADDR_STATE_INIT,
36753937 channel->id);
3938
+
3939
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE &&
3940
+ index == (capture_info->multi_dev.dev_num - 1) &&
3941
+ priv && priv->mode.rdbk_mode != RKISP_VICAP_ONLINE)
3942
+ rkcif_write_register(dev, get_reg_index_of_id_crop_start(channel->id),
3943
+ channel->crop_st_y << 16 |
3944
+ (channel->crop_st_x + capture_info->multi_dev.pixel_offset));
3945
+
3946
+ rkcif_write_register(dev, get_reg_index_of_frm0_y_vlw(channel->id),
3947
+ channel->virtual_width);
3948
+
36763949 if (stream->lack_buf_cnt == 2)
36773950 stream->dma_en = 0;
36783951
....@@ -3735,7 +4008,25 @@
37354008 }
37364009 if (dev->chip_id >= CHIP_RV1106_CIF)
37374010 rkcif_modify_frame_skip_config(stream);
3738
- stream->cifdev->id_use_cnt++;
4011
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
4012
+ if (index == (capture_info->multi_dev.dev_num - 1))
4013
+ stream->cifdev->id_use_cnt++;
4014
+ } else {
4015
+ stream->cifdev->id_use_cnt++;
4016
+ }
4017
+ if (!(capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE &&
4018
+ index < capture_info->multi_dev.dev_num - 1)) {
4019
+ if (mode == RKCIF_STREAM_MODE_CAPTURE)
4020
+ rkcif_assign_new_buffer_pingpong(stream,
4021
+ RKCIF_YUV_ADDR_STATE_INIT,
4022
+ channel->id);
4023
+ else if (mode == RKCIF_STREAM_MODE_TOISP ||
4024
+ mode == RKCIF_STREAM_MODE_TOISP_RDBK)
4025
+ rkcif_assign_new_buffer_pingpong_toisp(stream,
4026
+ RKCIF_YUV_ADDR_STATE_INIT,
4027
+ channel->id);
4028
+ }
4029
+ dev->intr_mask = rkcif_read_register(dev, CIF_REG_MIPI_LVDS_INTEN);
37394030 return 0;
37404031 }
37414032
....@@ -3747,6 +4038,7 @@
37474038 enum v4l2_mbus_type mbus_type = active_sensor->mbus.type;
37484039 struct csi_channel_info *channel;
37494040 u32 ret = 0;
4041
+ int i;
37504042
37514043 if (stream->state < RKCIF_STATE_STREAMING) {
37524044 stream->frame_idx = 0;
....@@ -3785,10 +4077,18 @@
37854077 } else if (mode == RKCIF_STREAM_MODE_ROCKIT) {
37864078 stream->dma_en |= RKCIF_DMAEN_BY_ROCKIT;
37874079 }
3788
- if (stream->cifdev->chip_id < CHIP_RK3588_CIF)
4080
+ if (stream->cifdev->chip_id < CHIP_RK3588_CIF) {
37894081 rkcif_csi_channel_set(stream, channel, mbus_type);
3790
- else
3791
- rkcif_csi_channel_set_v1(stream, channel, mbus_type, mode);
4082
+ } else {
4083
+ if (channel->capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
4084
+ for (i = 0; i < channel->capture_info.multi_dev.dev_num; i++) {
4085
+ dev->csi_host_idx = channel->capture_info.multi_dev.dev_idx[i];
4086
+ rkcif_csi_channel_set_v1(stream, channel, mbus_type, mode, i);
4087
+ }
4088
+ } else {
4089
+ rkcif_csi_channel_set_v1(stream, channel, mbus_type, mode, 0);
4090
+ }
4091
+ }
37924092 } else {
37934093 if (stream->cifdev->chip_id >= CHIP_RK3588_CIF) {
37944094 if (mode == RKCIF_STREAM_MODE_CAPTURE) {
....@@ -3828,7 +4128,9 @@
38284128 struct v4l2_mbus_config *mbus_cfg = &cif_dev->active_sensor->mbus;
38294129 u32 val;
38304130 int id;
4131
+ int i = 0;
38314132
4133
+ stream->cifdev->id_use_cnt--;
38324134 if (mbus_cfg->type == V4L2_MBUS_CSI2_DPHY ||
38334135 mbus_cfg->type == V4L2_MBUS_CSI2_CPHY ||
38344136 mbus_cfg->type == V4L2_MBUS_CCP2) {
....@@ -3840,7 +4142,14 @@
38404142 else
38414143 val &= ~LVDS_ENABLE_CAPTURE;
38424144
3843
- rkcif_write_register(cif_dev, get_reg_index_of_id_ctrl0(id), val);
4145
+ if (cif_dev->channels[id].capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
4146
+ for (i = 0; i < cif_dev->channels[id].capture_info.multi_dev.dev_num; i++) {
4147
+ cif_dev->csi_host_idx = cif_dev->channels[id].capture_info.multi_dev.dev_idx[i];
4148
+ rkcif_write_register(cif_dev, get_reg_index_of_id_ctrl0(id), val);
4149
+ }
4150
+ } else {
4151
+ rkcif_write_register(cif_dev, get_reg_index_of_id_ctrl0(id), val);
4152
+ }
38444153
38454154 rkcif_write_register_or(cif_dev, CIF_REG_MIPI_LVDS_INTSTAT,
38464155 CSI_START_INTSTAT(id) |
....@@ -3859,8 +4168,16 @@
38594168 if (stream->cifdev->id_use_cnt == 0) {
38604169 rkcif_write_register_and(cif_dev, CIF_REG_MIPI_LVDS_INTEN,
38614170 ~CSI_ALL_ERROR_INTEN_V1);
3862
- rkcif_write_register_and(cif_dev, CIF_REG_MIPI_LVDS_CTRL,
3863
- ~CSI_ENABLE_CAPTURE);
4171
+ if (cif_dev->channels[id].capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
4172
+ for (i = 0; i < cif_dev->channels[id].capture_info.multi_dev.dev_num; i++) {
4173
+ cif_dev->csi_host_idx = cif_dev->channels[id].capture_info.multi_dev.dev_idx[i];
4174
+ rkcif_write_register_and(cif_dev, CIF_REG_MIPI_LVDS_CTRL,
4175
+ ~CSI_ENABLE_CAPTURE);
4176
+ }
4177
+ } else {
4178
+ rkcif_write_register_and(cif_dev, CIF_REG_MIPI_LVDS_CTRL,
4179
+ ~CSI_ENABLE_CAPTURE);
4180
+ }
38644181 }
38654182 }
38664183
....@@ -3876,7 +4193,6 @@
38764193 rkcif_config_dvp_pin(cif_dev, false);
38774194 }
38784195 }
3879
- stream->cifdev->id_use_cnt--;
38804196 stream->state = RKCIF_STATE_READY;
38814197 stream->dma_en = 0;
38824198 }
....@@ -3955,7 +4271,7 @@
39554271 plane_fmt = &pixm->plane_fmt[i];
39564272 sizes[i] = plane_fmt->sizeimage / height * h;
39574273 }
3958
-
4274
+ stream->total_buf_num = *num_buffers;
39594275 v4l2_dbg(1, rkcif_debug, &dev->v4l2_dev, "%s count %d, size %d, extended(%d, %d)\n",
39604276 v4l2_type_names[queue->type], *num_buffers, sizes[0],
39614277 is_extended, extend_line->is_extended);
....@@ -3973,6 +4289,8 @@
39734289 u32 frm_addr_y = 0, frm_addr_uv = 0;
39744290 u32 frm0_addr_y = 0, frm0_addr_uv = 0;
39754291 u32 frm1_addr_y = 0, frm1_addr_uv = 0;
4292
+ u32 buff_addr_y = 0, buff_addr_cbcr = 0;
4293
+ struct rkmodule_capture_info *capture_info = &dev->channels[channel_id].capture_info;
39764294 unsigned long flags;
39774295 int frame_phase = 0;
39784296 bool is_dual_update_buf = false;
....@@ -4039,22 +4357,51 @@
40394357 }
40404358 if (buffer) {
40414359 if (is_dual_update_buf) {
4042
- rkcif_write_register(dev, frm0_addr_y,
4043
- buffer->buff_addr[RKCIF_PLANE_Y]);
4044
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
4045
- rkcif_write_register(dev, frm0_addr_uv,
4046
- buffer->buff_addr[RKCIF_PLANE_CBCR]);
4047
- rkcif_write_register(dev, frm1_addr_y,
4048
- buffer->buff_addr[RKCIF_PLANE_Y]);
4049
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
4050
- rkcif_write_register(dev, frm1_addr_uv,
4051
- buffer->buff_addr[RKCIF_PLANE_CBCR]);
4360
+ buff_addr_y = buffer->buff_addr[RKCIF_PLANE_Y];
4361
+ buff_addr_cbcr = buffer->buff_addr[RKCIF_PLANE_CBCR];
4362
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
4363
+ rkcif_write_buff_addr_multi_dev_combine(stream,
4364
+ frm0_addr_y,
4365
+ frm0_addr_uv,
4366
+ buff_addr_y,
4367
+ buff_addr_cbcr,
4368
+ false);
4369
+ rkcif_write_buff_addr_multi_dev_combine(stream,
4370
+ frm1_addr_y,
4371
+ frm1_addr_uv,
4372
+ buff_addr_y,
4373
+ buff_addr_cbcr,
4374
+ false);
4375
+ } else {
4376
+ rkcif_write_register(dev, frm0_addr_y, buff_addr_y);
4377
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
4378
+ rkcif_write_register(dev,
4379
+ frm0_addr_uv,
4380
+ buff_addr_cbcr);
4381
+ rkcif_write_register(dev, frm1_addr_y, buff_addr_y);
4382
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
4383
+ rkcif_write_register(dev,
4384
+ frm1_addr_uv,
4385
+ buff_addr_cbcr);
4386
+ }
40524387 } else {
4053
- rkcif_write_register(dev, frm_addr_y,
4054
- buffer->buff_addr[RKCIF_PLANE_Y]);
4055
- if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
4056
- rkcif_write_register(dev, frm_addr_uv,
4057
- buffer->buff_addr[RKCIF_PLANE_CBCR]);
4388
+
4389
+ buff_addr_y = buffer->buff_addr[RKCIF_PLANE_Y];
4390
+ buff_addr_cbcr = buffer->buff_addr[RKCIF_PLANE_CBCR];
4391
+ if (capture_info->mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
4392
+ rkcif_write_buff_addr_multi_dev_combine(stream,
4393
+ frm_addr_y,
4394
+ frm_addr_uv,
4395
+ buff_addr_y,
4396
+ buff_addr_cbcr,
4397
+ false);
4398
+ } else {
4399
+ rkcif_write_register(dev, frm_addr_y, buff_addr_y);
4400
+ if (stream->cif_fmt_out->fmt_type != CIF_FMT_TYPE_RAW)
4401
+ rkcif_write_register(dev,
4402
+ frm_addr_uv,
4403
+ buff_addr_cbcr);
4404
+ }
40584405 }
40594406 }
40604407 } else {
....@@ -4065,11 +4412,17 @@
40654412 if (stream->frame_phase_cache == CIF_CSI_FRAME0_READY) {
40664413 stream->curr_buf = list_first_entry(&stream->buf_head,
40674414 struct rkcif_buffer, queue);
4415
+ v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev,
4416
+ "%s %d, stream[%d] buf idx %d\n",
4417
+ __func__, __LINE__, stream->id, stream->curr_buf->vb.vb2_buf.index);
40684418 if (stream->curr_buf)
40694419 list_del(&stream->curr_buf->queue);
40704420 } else if (stream->frame_phase_cache == CIF_CSI_FRAME1_READY) {
40714421 stream->next_buf = list_first_entry(&stream->buf_head,
40724422 struct rkcif_buffer, queue);
4423
+ v4l2_dbg(4, rkcif_debug, &dev->v4l2_dev,
4424
+ "%s %d, stream[%d] buf idx %d\n",
4425
+ __func__, __LINE__, stream->id, stream->next_buf->vb.vb2_buf.index);
40734426 if (stream->next_buf)
40744427 list_del(&stream->next_buf->queue);
40754428 }
....@@ -4098,6 +4451,7 @@
40984451 }
40994452 if (stream->lack_buf_cnt)
41004453 stream->lack_buf_cnt--;
4454
+
41014455 } else {
41024456 v4l2_info(&dev->v4l2_dev, "%s %d, state %d, curr_buf %p, next_buf %p\n",
41034457 __func__, __LINE__, stream->state, stream->curr_buf, stream->next_buf);
....@@ -4195,11 +4549,13 @@
41954549 list_add_tail(&dbufs->list, &stream->rx_buf_head_vicap);
41964550 }
41974551 if (stream->cifdev->workmode == RKCIF_WORKMODE_PINGPONG &&
4198
- stream->lack_buf_cnt)
4552
+ stream->lack_buf_cnt &&
4553
+ stream->cur_stream_mode & RKCIF_STREAM_MODE_CAPTURE)
41994554 rkcif_check_buffer_update_pingpong(stream, stream->id);
42004555 v4l2_dbg(3, rkcif_debug, &stream->cifdev->v4l2_dev,
42014556 "stream[%d] buf queue, index: %d, dma_addr 0x%x\n",
42024557 stream->id, vb->index, cifbuf->buff_addr[0]);
4558
+ atomic_inc(&stream->buf_cnt);
42034559 }
42044560
42054561 void rkcif_free_rx_buf(struct rkcif_stream *stream, int buf_num)
....@@ -4207,11 +4563,54 @@
42074563 struct rkcif_rx_buffer *buf;
42084564 struct rkcif_device *dev = stream->cifdev;
42094565 struct sditf_priv *priv = dev->sditf[0];
4566
+ struct v4l2_subdev *sd;
42104567 int i = 0;
42114568 unsigned long flags;
4569
+ phys_addr_t resmem_free_start;
4570
+ phys_addr_t resmem_free_end;
4571
+ u32 share_head_size = 0;
42124572
42134573 if (!priv)
42144574 return;
4575
+
4576
+ sd = get_rkisp_sd(dev->sditf[0]);
4577
+ if (!sd)
4578
+ return;
4579
+
4580
+ if (dev->is_rtt_suspend && dev->is_thunderboot) {
4581
+ stream->curr_buf_toisp = NULL;
4582
+ stream->next_buf_toisp = NULL;
4583
+ INIT_LIST_HEAD(&stream->rx_buf_head);
4584
+
4585
+ for (i = 0; i < buf_num; i++) {
4586
+ buf = &stream->rx_buf[i];
4587
+ if (buf->dbufs.is_init)
4588
+ v4l2_subdev_call(sd, core, ioctl,
4589
+ RKISP_VICAP_CMD_RX_BUFFER_FREE, &buf->dbufs);
4590
+ buf->dummy.is_free = true;
4591
+ }
4592
+
4593
+ if (IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP)) {
4594
+ share_head_size = dev->thunderboot_sensor_num * sizeof(struct rkisp32_thunderboot_resmem_head);
4595
+ if (share_head_size != dev->share_mem_size)
4596
+ v4l2_info(&stream->cifdev->v4l2_dev,
4597
+ "share mem head error, rtt head size %d, arm head size %d\n",
4598
+ dev->share_mem_size, share_head_size);
4599
+ resmem_free_start = dev->resmem_pa + share_head_size + dev->nr_buf_size;
4600
+ resmem_free_end = dev->resmem_pa + dev->resmem_size;
4601
+ v4l2_info(&stream->cifdev->v4l2_dev,
4602
+ "free reserved mem start 0x%x, end 0x%x, share_head_size 0x%x, nr_buf_size 0x%x\n",
4603
+ (u32)resmem_free_start, (u32)resmem_free_end, share_head_size, dev->nr_buf_size);
4604
+ free_reserved_area(phys_to_virt(resmem_free_start),
4605
+ phys_to_virt(resmem_free_end),
4606
+ -1, "rkisp_thunderboot");
4607
+ }
4608
+ atomic_set(&stream->buf_cnt, 0);
4609
+ stream->total_buf_num = 0;
4610
+ stream->rx_buf_num = 0;
4611
+
4612
+ return;
4613
+ }
42154614
42164615 spin_lock_irqsave(&stream->vbq_lock, flags);
42174616 stream->curr_buf_toisp = NULL;
....@@ -4225,11 +4624,17 @@
42254624 buf = &stream->rx_buf[i];
42264625 if (buf->dummy.is_free)
42274626 continue;
4627
+ if (buf->dbufs.is_init)
4628
+ v4l2_subdev_call(sd, core, ioctl,
4629
+ RKISP_VICAP_CMD_RX_BUFFER_FREE, &buf->dbufs);
42284630 if (!dev->is_thunderboot)
42294631 rkcif_free_buffer(dev, &buf->dummy);
42304632 else
42314633 list_add_tail(&buf->list_free, &priv->buf_free_list);
4634
+ atomic_dec(&stream->buf_cnt);
4635
+ stream->total_buf_num--;
42324636 }
4637
+ stream->rx_buf_num = 0;
42334638
42344639 if (dev->is_thunderboot) {
42354640 spin_unlock_irqrestore(&dev->buffree_lock, flags);
....@@ -4240,6 +4645,7 @@
42404645 "free rx_buf, buf_num %d\n", buf_num);
42414646 }
42424647
4648
+static void rkcif_get_resmem_head(struct rkcif_device *cif_dev);
42434649 int rkcif_init_rx_buf(struct rkcif_stream *stream, int buf_num)
42444650 {
42454651 struct rkcif_device *dev = stream->cifdev;
....@@ -4287,10 +4693,12 @@
42874693 dummy->is_need_vaddr = true;
42884694 dummy->is_need_dbuf = true;
42894695 if (dev->is_thunderboot) {
4696
+ if (i == 0)
4697
+ rkcif_get_resmem_head(dev);
42904698 buf->buf_idx = i;
42914699 ret = rkcif_alloc_reserved_mem_buf(dev, buf);
42924700 if (ret) {
4293
- priv->buf_num = i;
4701
+ stream->rx_buf_num = i;
42944702 v4l2_info(&dev->v4l2_dev,
42954703 "reserved mem support alloc buf num %d, require buf num %d\n",
42964704 i, buf_num);
....@@ -4303,7 +4711,7 @@
43034711 } else {
43044712 ret = rkcif_alloc_buffer(dev, dummy);
43054713 if (ret) {
4306
- priv->buf_num = i;
4714
+ stream->rx_buf_num = i;
43074715 v4l2_info(&dev->v4l2_dev,
43084716 "alloc buf num %d, require buf num %d\n",
43094717 i, buf_num);
....@@ -4319,16 +4727,17 @@
43194727 buf->dbufs.is_uncompact = false;
43204728 else
43214729 buf->dbufs.is_uncompact = true;
4322
- if (priv && priv->mode.rdbk_mode == RKISP_VICAP_ONLINE && i == 0) {
4730
+ if (priv && i == 0) {
43234731 buf->dbufs.is_first = true;
4324
- rkcif_s_rx_buffer(dev, &buf->dbufs);
4325
- stream->buf_num_toisp--;
4732
+ if (priv->mode.rdbk_mode == RKISP_VICAP_ONLINE)
4733
+ rkcif_s_rx_buffer(stream, &buf->dbufs);
43264734 }
43274735 i++;
43284736 if (!dev->is_thunderboot && i >= buf_num) {
4737
+ stream->rx_buf_num = buf_num;
43294738 break;
43304739 } else if (i >= RKISP_VICAP_BUF_CNT_MAX) {
4331
- priv->buf_num = i;
4740
+ stream->rx_buf_num = i;
43324741 v4l2_info(&dev->v4l2_dev,
43334742 "reserved mem alloc buf num %d\n", i);
43344743 break;
....@@ -4337,8 +4746,9 @@
43374746 "init rx_buf,dma_addr 0x%llx size: 0x%x\n",
43384747 (u64)dummy->dma_addr, pixm->plane_fmt[0].sizeimage);
43394748 }
4340
- if (priv->buf_num) {
4341
- stream->buf_num_toisp = priv->buf_num;
4749
+ if (stream->rx_buf_num) {
4750
+ stream->total_buf_num = stream->rx_buf_num;
4751
+ atomic_set(&stream->buf_cnt, stream->rx_buf_num);
43424752 return 0;
43434753 } else {
43444754 return -EINVAL;
....@@ -4352,6 +4762,7 @@
43524762 struct rkcif_dummy_buffer *dummy_buf = &hw->dummy_buf;
43534763 struct rkcif_device *tmp_dev = NULL;
43544764 struct v4l2_subdev_frame_interval_enum fie;
4765
+ struct v4l2_subdev_format fmt;
43554766 u32 max_size = 0;
43564767 u32 size = 0;
43574768 int ret = 0;
....@@ -4369,7 +4780,9 @@
43694780 pad, enum_frame_interval,
43704781 NULL, &fie);
43714782 if (!ret) {
4372
- if (fie.code == MEDIA_BUS_FMT_RGB888_1X24)
4783
+ if (fie.code == MEDIA_BUS_FMT_RGB888_1X24 ||
4784
+ fie.code == MEDIA_BUS_FMT_BGR888_1X24 ||
4785
+ fie.code == MEDIA_BUS_FMT_GBR888_1X24)
43734786 size = fie.width * fie.height * 3;
43744787 else
43754788 size = fie.width * fie.height * 2;
....@@ -4386,6 +4799,23 @@
43864799 continue;
43874800 }
43884801 }
4802
+
4803
+ if (max_size == 0 && dev->terminal_sensor.sd) {
4804
+ fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
4805
+ ret = v4l2_subdev_call(dev->terminal_sensor.sd,
4806
+ pad, get_fmt, NULL, &fmt);
4807
+ if (!ret) {
4808
+ if (fmt.format.code == MEDIA_BUS_FMT_RGB888_1X24 ||
4809
+ fmt.format.code == MEDIA_BUS_FMT_BGR888_1X24 ||
4810
+ fmt.format.code == MEDIA_BUS_FMT_GBR888_1X24)
4811
+ size = fmt.format.width * fmt.format.height * 3;
4812
+ else
4813
+ size = fmt.format.width * fmt.format.height * 2;
4814
+ if (size > max_size)
4815
+ max_size = size;
4816
+ }
4817
+ }
4818
+
43894819 dummy_buf->size = max_size;
43904820
43914821 dummy_buf->is_need_vaddr = true;
....@@ -4583,7 +5013,7 @@
45835013 spin_lock_irqsave(&stream->fps_lock, flags);
45845014 fs_time = stream->readout.fs_timestamp;
45855015 spin_unlock_irqrestore(&stream->fps_lock, flags);
4586
- cur_time = ktime_get_ns();
5016
+ cur_time = rkcif_time_get_ns(dev);
45875017 if (cur_time > fs_time &&
45885018 cur_time - fs_time < (frame_time_ns - 10000000)) {
45895019 spin_lock_irqsave(&stream->vbq_lock, flags);
....@@ -4621,14 +5051,16 @@
46215051 } else if (mode == RKCIF_STREAM_MODE_CAPTURE && stream->dma_en & RKCIF_DMAEN_BY_VICAP) {
46225052 //only stop dma
46235053 stream->to_stop_dma = RKCIF_DMAEN_BY_VICAP;
5054
+ stream->is_wait_dma_stop = true;
46245055 wait_event_timeout(stream->wq_stopped,
4625
- stream->to_stop_dma != RKCIF_DMAEN_BY_VICAP,
5056
+ !stream->is_wait_dma_stop,
46265057 msecs_to_jiffies(1000));
46275058 } else if (mode == RKCIF_STREAM_MODE_TOISP && stream->dma_en & RKCIF_DMAEN_BY_VICAP) {
46285059 //only stop dma
46295060 stream->to_stop_dma = RKCIF_DMAEN_BY_ISP;
5061
+ stream->is_wait_dma_stop = true;
46305062 wait_event_timeout(stream->wq_stopped,
4631
- stream->to_stop_dma != RKCIF_DMAEN_BY_ISP,
5063
+ !stream->is_wait_dma_stop,
46325064 msecs_to_jiffies(1000));
46335065 }
46345066 if ((mode & RKCIF_STREAM_MODE_CAPTURE) == RKCIF_STREAM_MODE_CAPTURE) {
....@@ -4641,12 +5073,12 @@
46415073 list_add_tail(&stream->next_buf->queue, &stream->buf_head);
46425074 spin_unlock_irqrestore(&stream->vbq_lock, flags);
46435075
4644
- stream->curr_buf = NULL;
4645
- stream->next_buf = NULL;
4646
-
46475076 if (dev->hdr.hdr_mode == HDR_X2 ||
46485077 dev->hdr.hdr_mode == HDR_X3)
46495078 rkcif_release_rdbk_buf(stream);
5079
+
5080
+ stream->curr_buf = NULL;
5081
+ stream->next_buf = NULL;
46505082
46515083 rkcif_rx_buffer_free(stream);
46525084 list_for_each_entry(buf, &stream->buf_head, queue) {
....@@ -4664,6 +5096,8 @@
46645096 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
46655097 }
46665098 }
5099
+ stream->total_buf_num = 0;
5100
+ atomic_set(&stream->buf_cnt, 0);
46675101 stream->lack_buf_cnt = 0;
46685102 stream->dma_en &= ~RKCIF_DMAEN_BY_VICAP;
46695103 }
....@@ -4694,8 +5128,10 @@
46945128 }
46955129 }
46965130 mutex_unlock(&hw_dev->dev_lock);
4697
- if (dev->can_be_reset && dev->chip_id >= CHIP_RK3588_CIF)
5131
+ if (dev->can_be_reset && dev->chip_id >= CHIP_RK3588_CIF) {
46985132 rkcif_do_soft_reset(dev);
5133
+ atomic_set(&dev->streamoff_cnt, 0);
5134
+ }
46995135 if (dev->can_be_reset && can_reset) {
47005136 dev->can_be_reset = false;
47015137 dev->reset_work_cancel = true;
....@@ -4704,10 +5140,12 @@
47045140 dev->wait_line = 0;
47055141 stream->is_line_wake_up = false;
47065142 }
4707
- tasklet_disable(&stream->vb_done_tasklet);
5143
+ if (can_reset && hw_dev->dummy_buf.vaddr)
5144
+ rkcif_destroy_dummy_buf(stream);
47085145 }
4709
- if (can_reset && hw_dev->dummy_buf.vaddr)
4710
- rkcif_destroy_dummy_buf(stream);
5146
+ if (mode == RKCIF_STREAM_MODE_CAPTURE)
5147
+ tasklet_disable(&stream->vb_done_tasklet);
5148
+
47115149 stream->cur_stream_mode &= ~mode;
47125150 INIT_LIST_HEAD(&stream->vb_done_list);
47135151 v4l2_info(&dev->v4l2_dev, "stream[%d] stopping finished, dma_en 0x%x\n", stream->id, stream->dma_en);
....@@ -4981,6 +5419,7 @@
49815419 stream->crop_mask |= CROP_SRC_SENSOR_MASK;
49825420 dev->terminal_sensor.selection = input_sel;
49835421 } else {
5422
+ stream->crop_mask &= ~CROP_SRC_SENSOR_MASK;
49845423 dev->terminal_sensor.selection.r = dev->terminal_sensor.raw_rect;
49855424 }
49865425 }
....@@ -5001,8 +5440,10 @@
50015440 stream->crop[CROP_SRC_ACT].top = stream->crop[CROP_SRC_USR].top +
50025441 stream->crop[CROP_SRC_SENSOR].top;
50035442 }
5004
- } else {
5443
+ } else if (stream->crop_mask & CROP_SRC_SENSOR_MASK) {
50055444 stream->crop[CROP_SRC_ACT] = stream->crop[CROP_SRC_SENSOR];
5445
+ } else {
5446
+ stream->crop[CROP_SRC_ACT] = dev->terminal_sensor.raw_rect;
50065447 }
50075448 }
50085449
....@@ -5018,9 +5459,9 @@
50185459 struct v4l2_rect input, *crop;
50195460
50205461 if (dev->terminal_sensor.sd) {
5021
- stream->cif_fmt_in = get_input_fmt(dev->terminal_sensor.sd,
5022
- &input, stream->id,
5023
- &dev->channels[stream->id]);
5462
+ stream->cif_fmt_in = rkcif_get_input_fmt(dev,
5463
+ &input, stream->id,
5464
+ &dev->channels[stream->id]);
50245465 if (!stream->cif_fmt_in) {
50255466 v4l2_err(v4l2_dev, "Input fmt is invalid\n");
50265467 return -EINVAL;
....@@ -5548,6 +5989,7 @@
55485989 rkcif_write_register(dev, CIF_REG_DVP_CTRL,
55495990 AXI_BURST_16 | workmode | ENABLE_CAPTURE);
55505991 }
5992
+ dev->intr_mask = rkcif_read_register(dev, CIF_REG_DVP_INTSTAT);
55515993 #if IS_ENABLED(CONFIG_CPU_RV1106)
55525994 rv1106_sdmmc_put_lock();
55535995 #endif
....@@ -5562,6 +6004,7 @@
55626004 {
55636005 struct rkcif_hw *hw = cifdev->hw_dev;
55646006 struct rkcif_device *dev;
6007
+ struct sditf_priv *priv;
55656008 int i = 0, j = 0;
55666009 int ret = 0;
55676010 int count = 0;
....@@ -5610,12 +6053,12 @@
56106053 else
56116054 sync_cfg.group = 0;
56126055 }
6056
+ cifdev->sync_cfg = sync_cfg;
56136057 if (sync_cfg.type == NO_SYNC_MODE ||
56146058 hw->sync_config[sync_cfg.group].is_attach) {
56156059 mutex_unlock(&hw->dev_lock);
56166060 return;
56176061 }
5618
- cifdev->sync_cfg = sync_cfg;
56196062
56206063 sync_config = &hw->sync_config[sync_cfg.group];
56216064 memset(sync_config, 0, sizeof(struct rkcif_multi_sync_config));
....@@ -5639,26 +6082,31 @@
56396082 else
56406083 sync_cfg.group = 0;
56416084 } else {
5642
- for (j = 0; j < dev->sditf_cnt; j++) {
5643
- ret |= v4l2_subdev_call(dev->sditf[j]->sensor_sd,
5644
- core, ioctl,
5645
- RKMODULE_GET_SYNC_MODE,
5646
- &sync_type);
5647
- if (!ret && sync_type)
5648
- break;
6085
+ priv = dev->sditf[0];
6086
+ if (priv && priv->is_combine_mode && dev->sditf_cnt <= RKCIF_MAX_SDITF) {
6087
+ for (j = 0; j < dev->sditf_cnt; j++) {
6088
+ ret |= v4l2_subdev_call(dev->sditf[j]->sensor_sd,
6089
+ core, ioctl,
6090
+ RKMODULE_GET_SYNC_MODE,
6091
+ &sync_type);
6092
+ if (!ret && sync_type) {
6093
+ priv = dev->sditf[j];
6094
+ break;
6095
+ }
6096
+ }
6097
+ if (!ret)
6098
+ sync_cfg.type = sync_type;
6099
+ else
6100
+ sync_cfg.type = NO_SYNC_MODE;
6101
+ ret = v4l2_subdev_call(priv->sensor_sd,
6102
+ core, ioctl,
6103
+ RKMODULE_GET_GROUP_ID,
6104
+ &sync_group);
6105
+ if (!ret && sync_group < RKCIF_MAX_GROUP)
6106
+ sync_cfg.group = sync_group;
6107
+ else
6108
+ sync_cfg.group = 0;
56496109 }
5650
- if (!ret)
5651
- sync_cfg.type = sync_type;
5652
- else
5653
- sync_cfg.type = NO_SYNC_MODE;
5654
- ret = v4l2_subdev_call(dev->sditf[j]->sensor_sd,
5655
- core, ioctl,
5656
- RKMODULE_GET_GROUP_ID,
5657
- &sync_group);
5658
- if (!ret && sync_group < RKCIF_MAX_GROUP)
5659
- sync_cfg.group = sync_group;
5660
- else
5661
- sync_cfg.group = 0;
56626110 }
56636111 if (sync_cfg.group == cifdev->sync_cfg.group) {
56646112 if (sync_cfg.type == EXTERNAL_MASTER_MODE) {
....@@ -5681,6 +6129,11 @@
56816129 sync_config->sync_mask |= BIT(dev->csi_host_idx);
56826130 }
56836131 dev->sync_cfg = sync_cfg;
6132
+ } else {
6133
+ ret = v4l2_subdev_call(dev->terminal_sensor.sd,
6134
+ core, ioctl,
6135
+ RKMODULE_GET_SYNC_MODE,
6136
+ &sync_type);
56846137 }
56856138 }
56866139 if (sync_config->int_master.count == 1) {
....@@ -5714,15 +6167,19 @@
57146167 struct rkcif_hw *hw_dev = dev->hw_dev;
57156168 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
57166169 struct rkcif_sensor_info *sensor_info = dev->active_sensor;
5717
- struct rkcif_sensor_info *terminal_sensor = &dev->terminal_sensor;
6170
+ struct rkcif_sensor_info *terminal_sensor = NULL;
57186171 struct rkmodule_hdr_cfg hdr_cfg;
6172
+ struct rkcif_csi_info csi_info = {0};
57196173 int rkmodule_stream_seq = RKMODULE_START_STREAM_DEFAULT;
57206174 int ret;
6175
+ int i = 0;
6176
+ u32 skip_frame = 0;
57216177
57226178 v4l2_info(&dev->v4l2_dev, "stream[%d] start streaming\n", stream->id);
57236179
57246180 rkcif_attach_sync_mode(dev);
57256181 mutex_lock(&dev->stream_lock);
6182
+
57266183 if ((stream->cur_stream_mode & RKCIF_STREAM_MODE_CAPTURE) == mode) {
57276184 ret = -EBUSY;
57286185 v4l2_err(v4l2_dev, "stream in busy state\n");
....@@ -5735,7 +6192,7 @@
57356192 else
57366193 stream->is_line_inten = false;
57376194
5738
- if (dev->active_sensor) {
6195
+ if (!dev->active_sensor) {
57396196 ret = rkcif_update_sensor_info(stream);
57406197 if (ret < 0) {
57416198 v4l2_err(v4l2_dev,
....@@ -5744,7 +6201,7 @@
57446201 goto out;
57456202 }
57466203 }
5747
-
6204
+ terminal_sensor = &dev->terminal_sensor;
57486205 if (terminal_sensor->sd) {
57496206 ret = v4l2_subdev_call(terminal_sensor->sd,
57506207 core, ioctl,
....@@ -5775,6 +6232,39 @@
57756232 goto destroy_buf;
57766233
57776234 mutex_lock(&hw_dev->dev_lock);
6235
+ if (atomic_read(&dev->pipe.stream_cnt) == 0 &&
6236
+ dev->active_sensor &&
6237
+ (dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_DPHY ||
6238
+ dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_CPHY ||
6239
+ dev->active_sensor->mbus.type == V4L2_MBUS_CCP2)) {
6240
+ if (dev->channels[0].capture_info.mode == RKMODULE_MULTI_DEV_COMBINE_ONE) {
6241
+ csi_info.csi_num = dev->channels[0].capture_info.multi_dev.dev_num;
6242
+ if (csi_info.csi_num > RKCIF_MAX_CSI_NUM) {
6243
+ v4l2_err(v4l2_dev,
6244
+ "csi num %d, max %d\n",
6245
+ csi_info.csi_num, RKCIF_MAX_CSI_NUM);
6246
+ goto out;
6247
+ }
6248
+ for (i = 0; i < csi_info.csi_num; i++) {
6249
+ csi_info.csi_idx[i] = dev->channels[0].capture_info.multi_dev.dev_idx[i];
6250
+ if (dev->hw_dev->is_rk3588s2)
6251
+ v4l2_info(v4l2_dev, "rk3588s2 combine mode attach to mipi%d\n",
6252
+ csi_info.csi_idx[i]);
6253
+ }
6254
+ } else {
6255
+ csi_info.csi_num = 1;
6256
+ dev->csi_host_idx = dev->csi_host_idx_def;
6257
+ csi_info.csi_idx[0] = dev->csi_host_idx;
6258
+ }
6259
+ ret = v4l2_subdev_call(dev->active_sensor->sd,
6260
+ core, ioctl,
6261
+ RKCIF_CMD_SET_CSI_IDX,
6262
+ &csi_info);
6263
+ if (ret)
6264
+ v4l2_err(&dev->v4l2_dev, "set csi idx %d fail\n", dev->csi_host_idx);
6265
+
6266
+ }
6267
+
57786268 if (((dev->active_sensor && dev->active_sensor->mbus.type == V4L2_MBUS_BT656) ||
57796269 dev->is_use_dummybuf) &&
57806270 (!dev->hw_dev->dummy_buf.vaddr) &&
....@@ -5788,8 +6278,10 @@
57886278 }
57896279 mutex_unlock(&hw_dev->dev_lock);
57906280
5791
- if (stream->cur_stream_mode == RKCIF_STREAM_MODE_NONE) {
6281
+ if (mode == RKCIF_STREAM_MODE_CAPTURE)
57926282 tasklet_enable(&stream->vb_done_tasklet);
6283
+
6284
+ if (stream->cur_stream_mode == RKCIF_STREAM_MODE_NONE) {
57936285 ret = dev->pipe.open(&dev->pipe, &node->vdev.entity, true);
57946286 if (ret < 0) {
57956287 v4l2_err(v4l2_dev, "open cif pipeline failed %d\n",
....@@ -5807,8 +6299,17 @@
58076299 rkmodule_stream_seq == RKMODULE_START_STREAM_FRONT) {
58086300 ret = dev->pipe.set_stream(&dev->pipe, true);
58096301 if (ret < 0)
5810
- goto runtime_put;
6302
+ goto destroy_buf;
58116303 }
6304
+ ret = v4l2_subdev_call(terminal_sensor->sd,
6305
+ core, ioctl,
6306
+ RKMODULE_GET_SKIP_FRAME,
6307
+ &skip_frame);
6308
+ if (!ret && skip_frame < RKCIF_SKIP_FRAME_MAX)
6309
+ stream->skip_frame = skip_frame;
6310
+ else
6311
+ stream->skip_frame = 0;
6312
+ stream->cur_skip_frame = stream->skip_frame;
58126313 }
58136314 if (dev->chip_id >= CHIP_RK1808_CIF) {
58146315 if (dev->active_sensor &&
....@@ -5823,7 +6324,7 @@
58236324 }
58246325
58256326 if (ret < 0)
5826
- goto runtime_put;
6327
+ goto destroy_buf;
58276328
58286329 if (stream->cur_stream_mode == RKCIF_STREAM_MODE_NONE) {
58296330 ret = media_pipeline_start(&node->vdev.entity, &dev->pipe.pipe);
....@@ -5869,15 +6370,19 @@
58696370 rkcif_stream_stop(stream);
58706371 pipe_stream_off:
58716372 dev->pipe.set_stream(&dev->pipe, false);
5872
-runtime_put:
5873
- pm_runtime_put_sync(dev->dev);
6373
+
58746374 destroy_buf:
5875
- if (stream->next_buf)
5876
- vb2_buffer_done(&stream->next_buf->vb.vb2_buf,
5877
- VB2_BUF_STATE_QUEUED);
6375
+ if (mode == RKCIF_STREAM_MODE_CAPTURE)
6376
+ tasklet_disable(&stream->vb_done_tasklet);
58786377 if (stream->curr_buf)
5879
- vb2_buffer_done(&stream->curr_buf->vb.vb2_buf,
5880
- VB2_BUF_STATE_QUEUED);
6378
+ list_add_tail(&stream->curr_buf->queue, &stream->buf_head);
6379
+ if (stream->next_buf &&
6380
+ stream->next_buf != stream->curr_buf)
6381
+ list_add_tail(&stream->next_buf->queue, &stream->buf_head);
6382
+
6383
+ stream->curr_buf = NULL;
6384
+ stream->next_buf = NULL;
6385
+ atomic_set(&stream->buf_cnt, 0);
58816386 while (!list_empty(&stream->buf_head)) {
58826387 struct rkcif_buffer *buf;
58836388
....@@ -5942,6 +6447,7 @@
59426447 bool try)
59436448 {
59446449 struct rkcif_device *dev = stream->cifdev;
6450
+ struct sditf_priv *priv = dev->sditf[0];
59456451 const struct cif_output_fmt *fmt;
59466452 const struct cif_input_fmt *cif_fmt_in = NULL;
59476453 struct v4l2_rect input_rect;
....@@ -5949,6 +6455,7 @@
59496455 u32 xsubs = 1, ysubs = 1, i;
59506456 struct rkmodule_hdr_cfg hdr_cfg;
59516457 struct rkcif_extend_info *extend_line = &stream->extend_line;
6458
+ struct csi_channel_info *channel_info = &dev->channels[stream->id];
59526459 int ret;
59536460
59546461 for (i = 0; i < RKCIF_MAX_PLANE; i++)
....@@ -5962,9 +6469,9 @@
59626469 input_rect.height = RKCIF_DEFAULT_HEIGHT;
59636470
59646471 if (dev->terminal_sensor.sd) {
5965
- cif_fmt_in = get_input_fmt(dev->terminal_sensor.sd,
5966
- &input_rect, stream->id,
5967
- &dev->channels[stream->id]);
6472
+ cif_fmt_in = rkcif_get_input_fmt(dev,
6473
+ &input_rect, stream->id,
6474
+ channel_info);
59686475 stream->cif_fmt_in = cif_fmt_in;
59696476 } else {
59706477 v4l2_err(&stream->cifdev->v4l2_dev,
....@@ -6006,8 +6513,9 @@
60066513
60076514 planes = fmt->cplanes ? fmt->cplanes : fmt->mplanes;
60086515
6009
- if (cif_fmt_in && (cif_fmt_in->mbus_code == MEDIA_BUS_FMT_SPD_2X8 ||
6010
- cif_fmt_in->mbus_code == MEDIA_BUS_FMT_EBD_1X8))
6516
+ if (cif_fmt_in &&
6517
+ (cif_fmt_in->mbus_code == MEDIA_BUS_FMT_SPD_2X8 ||
6518
+ cif_fmt_in->mbus_code == MEDIA_BUS_FMT_EBD_1X8))
60116519 stream->crop_enable = false;
60126520
60136521 for (i = 0; i < planes; i++) {
....@@ -6032,7 +6540,7 @@
60326540 }
60336541 }
60346542
6035
- if (dev->sditf_cnt > 1 && dev->sditf_cnt <= RKCIF_MAX_SDITF)
6543
+ if (priv && priv->is_combine_mode && dev->sditf_cnt <= RKCIF_MAX_SDITF)
60366544 height *= dev->sditf_cnt;
60376545
60386546 extend_line->pixm.height = height + RKMODULE_EXTEND_LINE;
....@@ -6042,8 +6550,9 @@
60426550 * to optimize reading and writing of ddr, aliged with 256.
60436551 */
60446552 if (fmt->fmt_type == CIF_FMT_TYPE_RAW &&
6045
- (stream->cif_fmt_in->mbus_code == MEDIA_BUS_FMT_EBD_1X8 ||
6046
- stream->cif_fmt_in->mbus_code == MEDIA_BUS_FMT_SPD_2X8)) {
6553
+ cif_fmt_in &&
6554
+ (cif_fmt_in->mbus_code == MEDIA_BUS_FMT_EBD_1X8 ||
6555
+ cif_fmt_in->mbus_code == MEDIA_BUS_FMT_SPD_2X8)) {
60476556 stream->is_compact = false;
60486557 }
60496558
....@@ -6157,6 +6666,7 @@
61576666
61586667 stream->is_high_align = false;
61596668 stream->is_finish_stop_dma = false;
6669
+ stream->is_wait_dma_stop = false;
61606670
61616671 if (dev->chip_id == CHIP_RV1126_CIF ||
61626672 dev->chip_id == CHIP_RV1126_CIF_LITE)
....@@ -6184,6 +6694,11 @@
61846694 stream->buf_owner = 0;
61856695 stream->buf_replace_cnt = 0;
61866696 stream->is_stop_capture = false;
6697
+ stream->is_single_cap = false;
6698
+ atomic_set(&stream->buf_cnt, 0);
6699
+ stream->rx_buf_num = 0;
6700
+ init_completion(&stream->stop_complete);
6701
+ stream->is_wait_stop_complete = false;
61876702 }
61886703
61896704 static int rkcif_fh_open(struct file *filp)
....@@ -6329,9 +6844,9 @@
63296844 input_rect.height = RKCIF_DEFAULT_HEIGHT;
63306845
63316846 if (dev->terminal_sensor.sd)
6332
- get_input_fmt(dev->terminal_sensor.sd,
6333
- &input_rect, stream->id,
6334
- &csi_info);
6847
+ rkcif_get_input_fmt(dev,
6848
+ &input_rect, stream->id,
6849
+ &csi_info);
63356850
63366851 if (dev->hw_dev->adapt_to_usbcamerahal) {
63376852 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
....@@ -6410,7 +6925,7 @@
64106925 return -EINVAL;
64116926
64126927 if (dev->terminal_sensor.sd) {
6413
- cif_fmt_in = get_input_fmt(dev->terminal_sensor.sd,
6928
+ cif_fmt_in = rkcif_get_input_fmt(dev,
64146929 &input_rect, stream->id,
64156930 &dev->channels[stream->id]);
64166931 stream->cif_fmt_in = cif_fmt_in;
....@@ -6769,8 +7284,18 @@
67697284 skip_n);
67707285 }
67717286
7287
+static bool rkcif_check_can_be_online(struct rkcif_device *cif_dev)
7288
+{
7289
+ if (cif_dev->sditf[0] == NULL || cif_dev->sditf[0]->mode.name == NULL ||
7290
+ (cif_dev->chip_id == CHIP_RV1106_CIF &&
7291
+ strstr(cif_dev->sditf[0]->mode.name, "unite")))
7292
+ return false;
7293
+ return true;
7294
+}
7295
+
67727296 static int rkcif_do_reset_work(struct rkcif_device *cif_dev,
67737297 enum rkmodule_reset_src reset_src);
7298
+static bool rkcif_check_single_dev_stream_on(struct rkcif_hw *hw);
67747299
67757300 static long rkcif_ioctl_default(struct file *file, void *fh,
67767301 bool valid_prio, unsigned int cmd, void *arg)
....@@ -6782,6 +7307,13 @@
67827307 struct csi_channel_info csi_info;
67837308 struct rkcif_fps fps;
67847309 int reset_src;
7310
+ struct rkcif_quick_stream_param *stream_param;
7311
+ bool is_single_dev = false;
7312
+ struct v4l2_subdev *sd;
7313
+ int ret = -EINVAL;
7314
+ int i = 0;
7315
+ int stream_num = 0;
7316
+ bool is_can_be_online = false;
67857317
67867318 switch (cmd) {
67877319 case RKCIF_CMD_GET_CSI_MEMORY_MODE:
....@@ -6796,8 +7328,8 @@
67967328 break;
67977329 case RKCIF_CMD_SET_CSI_MEMORY_MODE:
67987330 if (dev->terminal_sensor.sd) {
6799
- in_fmt = get_input_fmt(dev->terminal_sensor.sd,
6800
- &rect, 0, &csi_info);
7331
+ in_fmt = rkcif_get_input_fmt(dev,
7332
+ &rect, 0, &csi_info);
68017333 if (in_fmt == NULL) {
68027334 v4l2_err(&dev->v4l2_dev, "can't get sensor input format\n");
68037335 return -EINVAL;
....@@ -6830,6 +7362,91 @@
68307362 case RKCIF_CMD_SET_RESET:
68317363 reset_src = *(int *)arg;
68327364 return rkcif_do_reset_work(dev, reset_src);
7365
+ case RKCIF_CMD_SET_QUICK_STREAM:
7366
+ stream_param = (struct rkcif_quick_stream_param *)arg;
7367
+ if (!dev->sditf[0])
7368
+ return -EINVAL;
7369
+ if (dev->hdr.hdr_mode == HDR_X2)
7370
+ stream_num = 2;
7371
+ else if (dev->hdr.hdr_mode == HDR_X3)
7372
+ stream_num = 3;
7373
+ else
7374
+ stream_num = 1;
7375
+ if (stream_param->on) {
7376
+ for (i = 0; i < stream_num; i++)
7377
+ dev->stream[i].cur_skip_frame = dev->stream[i].skip_frame;
7378
+ is_single_dev = rkcif_check_single_dev_stream_on(dev->hw_dev);
7379
+ is_can_be_online = rkcif_check_can_be_online(dev);
7380
+ if (is_single_dev && is_can_be_online) {
7381
+ for (i = 0; i < stream_num - 1; i++) {
7382
+ dev->stream[i].to_en_dma = RKCIF_DMAEN_BY_ISP;
7383
+ rkcif_enable_dma_capture(&dev->stream[i], true);
7384
+ }
7385
+ dev->sditf[0]->mode.rdbk_mode = RKISP_VICAP_ONLINE;
7386
+ sditf_change_to_online(dev->sditf[0]);
7387
+ sd = get_rkisp_sd(dev->sditf[0]);
7388
+ if (sd)
7389
+ ret = v4l2_subdev_call(sd, core, ioctl,
7390
+ RKISP_VICAP_CMD_MODE, &dev->sditf[0]->mode);
7391
+ if (ret) {
7392
+ v4l2_err(&dev->v4l2_dev, "set isp work mode online fail\n");
7393
+ return -EINVAL;
7394
+ }
7395
+ } else {
7396
+ sditf_disable_immediately(dev->sditf[0]);
7397
+ dev->sditf[0]->mode.rdbk_mode = RKISP_VICAP_RDBK_AUTO;
7398
+ sd = get_rkisp_sd(dev->sditf[0]);
7399
+ if (sd)
7400
+ ret = v4l2_subdev_call(sd, core, ioctl,
7401
+ RKISP_VICAP_CMD_MODE, &dev->sditf[0]->mode);
7402
+ for (i = 0; i < stream_num; i++) {
7403
+ if (dev->sditf[0]->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO)
7404
+ dev->stream[i].to_en_dma = RKCIF_DMAEN_BY_ISP;
7405
+ else
7406
+ dev->stream[i].to_en_dma = RKCIF_DMAEN_BY_VICAP;
7407
+ rkcif_enable_dma_capture(&dev->stream[i], true);
7408
+ }
7409
+ }
7410
+ rkcif_dphy_quick_stream(dev, stream_param->on);
7411
+ v4l2_subdev_call(dev->terminal_sensor.sd, core, ioctl,
7412
+ RKMODULE_SET_QUICK_STREAM, &stream_param->on);
7413
+ } else {
7414
+ if (dev->sditf[0]->mode.rdbk_mode == RKISP_VICAP_ONLINE) {
7415
+ for (i = 0; i < stream_num - 1; i++) {
7416
+ reinit_completion(&dev->stream[i].stop_complete);
7417
+ dev->stream[i].is_wait_stop_complete = true;
7418
+ dev->stream[i].to_stop_dma = RKCIF_DMAEN_BY_ISP;
7419
+ wait_for_completion_timeout(&dev->stream[i].stop_complete,
7420
+ msecs_to_jiffies(RKCIF_STOP_MAX_WAIT_TIME_MS));
7421
+ }
7422
+ stream->cifdev->sensor_state = stream_param->on;
7423
+ stream->cifdev->sensor_state_change = true;
7424
+ dev->stream[i].is_wait_stop_complete = true;
7425
+ wait_for_completion_timeout(&dev->stream[i].stop_complete,
7426
+ msecs_to_jiffies(RKCIF_STOP_MAX_WAIT_TIME_MS));
7427
+ } else {
7428
+ for (i = 0; i < stream_num; i++) {
7429
+ dev->stream[i].is_wait_stop_complete = true;
7430
+ reinit_completion(&dev->stream[i].stop_complete);
7431
+ if (dev->sditf[0]->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO)
7432
+ dev->stream[i].to_stop_dma = RKCIF_DMAEN_BY_ISP;
7433
+ else
7434
+ dev->stream[i].to_stop_dma = RKCIF_DMAEN_BY_VICAP;
7435
+ wait_for_completion_timeout(&dev->stream[i].stop_complete,
7436
+ msecs_to_jiffies(RKCIF_STOP_MAX_WAIT_TIME_MS));
7437
+ }
7438
+ rkcif_dphy_quick_stream(dev, stream_param->on);
7439
+ v4l2_subdev_call(dev->terminal_sensor.sd, core, ioctl,
7440
+ RKMODULE_SET_QUICK_STREAM, &stream_param->on);
7441
+ }
7442
+ stream_param->frame_num = dev->stream[0].frame_idx - 1;
7443
+ if (!dev->is_rtt_suspend) {
7444
+ dev->resume_mode = stream_param->resume_mode;
7445
+ v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev,
7446
+ "set resume mode %d\n", dev->resume_mode);
7447
+ }
7448
+ }
7449
+ break;
68337450 default:
68347451 return -EINVAL;
68357452 }
....@@ -6876,6 +7493,7 @@
68767493 v4l2_dbg(2, rkcif_debug, &stream->cifdev->v4l2_dev,
68777494 "stream[%d] vb done, index: %d, sequence %d\n", stream->id,
68787495 vb_done->vb2_buf.index, vb_done->sequence);
7496
+ atomic_dec(&stream->buf_cnt);
68797497 }
68807498
68817499 static void rkcif_tasklet_handle(unsigned long data)
....@@ -7632,7 +8250,7 @@
76328250 timer->csi2_err_triggered_cnt++;
76338251 if (timer->csi2_err_triggered_cnt == 1) {
76348252 is_first_err = true;
7635
- timer->csi2_first_err_timestamp = ktime_get_ns();
8253
+ timer->csi2_first_err_timestamp = rkcif_time_get_ns(dev);
76368254 }
76378255
76388256 is_assign_triggered = true;
....@@ -7644,7 +8262,7 @@
76448262
76458263 if (!is_first_err) {
76468264 if (timer->csi2_err_triggered_cnt >= 1) {
7647
- cur_time = ktime_get_ns();
8265
+ cur_time = rkcif_time_get_ns(dev);
76488266 diff_time = cur_time - timer->csi2_first_err_timestamp;
76498267 diff_time = div_u64(diff_time, 1000000);
76508268 if (diff_time >= timer->err_time_interval) {
....@@ -7987,7 +8605,7 @@
79878605 v4l2_err(&dev->v4l2_dev,
79888606 "s/m/l frame err, timestamp s:%lld m:%lld l:%lld\n",
79898607 s_ts, m_ts, l_ts);
7990
- goto RDBK_FRM_UNMATCH;
8608
+ return;
79918609 }
79928610
79938611 if ((m_ts - l_ts) > time || (s_ts - m_ts) > time) {
....@@ -8008,7 +8626,7 @@
80088626 v4l2_err(&dev->v4l2_dev,
80098627 "timestamp no match, s:%lld m:%lld l:%lld, fps:%d\n",
80108628 s_ts, m_ts, l_ts, fps);
8011
- goto RDBK_FRM_UNMATCH;
8629
+ return;
80128630 }
80138631 }
80148632 dev->rdbk_buf[RDBK_M]->vb.sequence = dev->rdbk_buf[RDBK_L]->vb.sequence;
....@@ -8037,7 +8655,7 @@
80378655 v4l2_err(&dev->v4l2_dev, "lost medium frames\n");
80388656 if (!dev->rdbk_buf[RDBK_S])
80398657 v4l2_err(&dev->v4l2_dev, "lost short frames\n");
8040
- goto RDBK_FRM_UNMATCH;
8658
+ return;
80418659 }
80428660 } else if (dev->hdr.hdr_mode == HDR_X2) {
80438661 if (dev->rdbk_buf[RDBK_L] && dev->rdbk_buf[RDBK_M]) {
....@@ -8048,7 +8666,7 @@
80488666 v4l2_err(&dev->v4l2_dev,
80498667 "s/l frame err, timestamp s:%lld l:%lld\n",
80508668 s_ts, l_ts);
8051
- goto RDBK_FRM_UNMATCH;
8669
+ return;
80528670 }
80538671
80548672 if ((s_ts - l_ts) > time) {
....@@ -8068,7 +8686,7 @@
80688686 v4l2_err(&dev->v4l2_dev,
80698687 "timestamp no match, s:%lld l:%lld, fps:%d\n",
80708688 s_ts, l_ts, fps);
8071
- goto RDBK_FRM_UNMATCH;
8689
+ return;
80728690 }
80738691 }
80748692 dev->rdbk_buf[RDBK_M]->vb.sequence = dev->rdbk_buf[RDBK_L]->vb.sequence;
....@@ -8092,27 +8710,8 @@
80928710 v4l2_err(&dev->v4l2_dev, "lost long frames\n");
80938711 if (!dev->rdbk_buf[RDBK_M])
80948712 v4l2_err(&dev->v4l2_dev, "lost short frames\n");
8095
- goto RDBK_FRM_UNMATCH;
8713
+ return;
80968714 }
8097
- }
8098
-
8099
- dev->rdbk_buf[RDBK_L] = NULL;
8100
- dev->rdbk_buf[RDBK_M] = NULL;
8101
- dev->rdbk_buf[RDBK_S] = NULL;
8102
- return;
8103
-
8104
-RDBK_FRM_UNMATCH:
8105
- if (dev->rdbk_buf[RDBK_L]) {
8106
- dev->rdbk_buf[RDBK_L]->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE;
8107
- rkcif_buf_queue(&dev->rdbk_buf[RDBK_L]->vb.vb2_buf);
8108
- }
8109
- if (dev->rdbk_buf[RDBK_M]) {
8110
- dev->rdbk_buf[RDBK_M]->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE;
8111
- rkcif_buf_queue(&dev->rdbk_buf[RDBK_M]->vb.vb2_buf);
8112
- }
8113
- if (dev->rdbk_buf[RDBK_S]) {
8114
- dev->rdbk_buf[RDBK_S]->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE;
8115
- rkcif_buf_queue(&dev->rdbk_buf[RDBK_S]->vb.vb2_buf);
81168715 }
81178716
81188717 dev->rdbk_buf[RDBK_L] = NULL;
....@@ -8147,9 +8746,13 @@
81478746
81488747 if (active_buf) {
81498748 vb_done = &active_buf->vb;
8150
- vb_done->vb2_buf.timestamp = stream->readout.fs_timestamp;
8749
+ if (cif_dev->chip_id < CHIP_RK3588_CIF &&
8750
+ cif_dev->active_sensor->mbus.type == V4L2_MBUS_BT656)
8751
+ vb_done->vb2_buf.timestamp = stream->readout.fe_timestamp;
8752
+ else
8753
+ vb_done->vb2_buf.timestamp = stream->readout.fs_timestamp;
81518754 vb_done->sequence = stream->frame_idx - 1;
8152
- active_buf->fe_timestamp = ktime_get_ns();
8755
+ active_buf->fe_timestamp = rkcif_time_get_ns(cif_dev);
81538756 if (stream->is_line_wake_up) {
81548757 spin_lock_irqsave(&stream->fps_lock, flags);
81558758 if (mode)
....@@ -8161,6 +8764,19 @@
81618764 }
81628765 if (stream->cif_fmt_in->field == V4L2_FIELD_INTERLACED)
81638766 vb_done->sequence /= 2;
8767
+ if (stream->cur_skip_frame) {
8768
+ rkcif_buf_queue(&active_buf->vb.vb2_buf);
8769
+ return;
8770
+ }
8771
+ } else if (cif_dev->rdbk_buf[stream->id]) {
8772
+ vb_done = &cif_dev->rdbk_buf[stream->id]->vb;
8773
+ if (cif_dev->chip_id < CHIP_RK3588_CIF &&
8774
+ cif_dev->active_sensor->mbus.type == V4L2_MBUS_BT656)
8775
+ vb_done->vb2_buf.timestamp = stream->readout.fe_timestamp;
8776
+ else
8777
+ vb_done->vb2_buf.timestamp = stream->readout.fs_timestamp;
8778
+ vb_done->sequence = stream->frame_idx - 1;
8779
+ cif_dev->rdbk_buf[stream->id]->fe_timestamp = rkcif_time_get_ns(cif_dev);
81648780 }
81658781
81668782 if (cif_dev->hdr.hdr_mode == NO_HDR || cif_dev->hdr.hdr_mode == HDR_COMPR) {
....@@ -8184,7 +8800,7 @@
81848800 if (cif_dev->is_start_hdr) {
81858801 spin_lock_irqsave(&cif_dev->hdr_lock, flags);
81868802 if (mipi_id == RKCIF_STREAM_MIPI_ID0) {
8187
- if (cif_dev->rdbk_buf[RDBK_L]) {
8803
+ if (cif_dev->rdbk_buf[RDBK_L] && active_buf) {
81888804 v4l2_err(&cif_dev->v4l2_dev,
81898805 "multiple long data in %s frame,frm_idx:%d,state:0x%x\n",
81908806 cif_dev->hdr.hdr_mode == HDR_X2 ? "hdr_x2" : "hdr_x3",
....@@ -8197,7 +8813,7 @@
81978813 if (active_buf)
81988814 cif_dev->rdbk_buf[RDBK_L] = active_buf;
81998815 } else if (mipi_id == RKCIF_STREAM_MIPI_ID1) {
8200
- if (cif_dev->rdbk_buf[RDBK_M]) {
8816
+ if (cif_dev->rdbk_buf[RDBK_M] && active_buf) {
82018817 v4l2_err(&cif_dev->v4l2_dev,
82028818 "multiple %s frame,frm_idx:%d,state:0x%x\n",
82038819 cif_dev->hdr.hdr_mode == HDR_X2 ? "short data in hdr_x2" : "medium data in hdr_x3",
....@@ -8212,7 +8828,7 @@
82128828 if (cif_dev->hdr.hdr_mode == HDR_X2)
82138829 rkcif_rdbk_frame_end(stream);
82148830 } else if (mipi_id == RKCIF_STREAM_MIPI_ID2) {
8215
- if (cif_dev->rdbk_buf[RDBK_S]) {
8831
+ if (cif_dev->rdbk_buf[RDBK_S] && active_buf) {
82168832 v4l2_err(&cif_dev->v4l2_dev,
82178833 "multiple %s frame, frm_idx:%d,state:0x%x\n",
82188834 cif_dev->hdr.hdr_mode == HDR_X2 ? "err short data in hdr_x3" : "short data in hdr_x3",
....@@ -8308,8 +8924,10 @@
83088924 spin_lock_irqsave(&priv->cif_dev->buffree_lock, flags);
83098925 for (i = 0; i < priv->buf_num; i++) {
83108926 rx_buf = &stream->rx_buf[i];
8311
- if (rx_buf && (!rx_buf->dummy.is_free) && rx_buf != buf)
8927
+ if (rx_buf && (!rx_buf->dummy.is_free) && rx_buf != buf) {
83128928 list_add_tail(&rx_buf->list_free, &priv->buf_free_list);
8929
+ stream->total_buf_num--;
8930
+ }
83138931 }
83148932 spin_unlock_irqrestore(&priv->cif_dev->buffree_lock, flags);
83158933 schedule_work(&priv->buffree_work.work);
....@@ -8377,13 +8995,15 @@
83778995 spin_unlock_irqrestore(&stream->vbq_lock, flags);
83788996 active_buf->dbufs.sequence = stream->frame_idx - 1;
83798997 active_buf->dbufs.timestamp = stream->readout.fs_timestamp;
8380
- active_buf->fe_timestamp = ktime_get_ns();
8998
+ active_buf->fe_timestamp = rkcif_time_get_ns(stream->cifdev);
83818999 stream->last_frame_idx = stream->frame_idx;
8382
- if (stream->cifdev->hdr.hdr_mode == NO_HDR)
8383
- rkcif_s_rx_buffer(stream->cifdev, &active_buf->dbufs);
8384
- else
9000
+ if (stream->cifdev->hdr.hdr_mode == NO_HDR) {
9001
+ rkcif_s_rx_buffer(stream, &active_buf->dbufs);
9002
+ if (stream->cifdev->is_support_tools && stream->tools_vdev)
9003
+ rkcif_rdbk_with_tools(stream, active_buf);
9004
+ } else {
83859005 rkcif_rdbk_frame_end_toisp(stream, active_buf);
8386
- stream->buf_num_toisp--;
9006
+ }
83879007 }
83889008 }
83899009 }
....@@ -8395,7 +9015,7 @@
83959015 unsigned long flags;
83969016
83979017 spin_lock_irqsave(&stream->fps_lock, flags);
8398
- stream->readout.fe_timestamp = ktime_get_ns();
9018
+ stream->readout.fe_timestamp = rkcif_time_get_ns(cif_dev);
83999019
84009020 if (cif_dev->inf_id == RKCIF_DVP) {
84019021 spin_unlock_irqrestore(&stream->fps_lock, flags);
....@@ -8442,11 +9062,11 @@
84429062 if (stream->frame_phase & CIF_CSI_FRAME0_READY) {
84439063 if (stream->curr_buf)
84449064 active_buf = stream->curr_buf;
8445
- stream->fps_stats.frm0_timestamp = ktime_get_ns();
9065
+ stream->fps_stats.frm0_timestamp = rkcif_time_get_ns(cif_dev);
84469066 } else if (stream->frame_phase & CIF_CSI_FRAME1_READY) {
84479067 if (stream->next_buf)
84489068 active_buf = stream->next_buf;
8449
- stream->fps_stats.frm1_timestamp = ktime_get_ns();
9069
+ stream->fps_stats.frm1_timestamp = rkcif_time_get_ns(cif_dev);
84509070 }
84519071 spin_unlock_irqrestore(&stream->fps_lock, flags);
84529072 }
....@@ -8455,8 +9075,8 @@
84559075
84569076 if (!stream->is_line_wake_up) {
84579077 ret = rkcif_assign_new_buffer_pingpong(stream,
8458
- RKCIF_YUV_ADDR_STATE_UPDATE,
8459
- mipi_id);
9078
+ RKCIF_YUV_ADDR_STATE_UPDATE,
9079
+ mipi_id);
84609080 if (ret && cif_dev->chip_id < CHIP_RK3588_CIF)
84619081 return;
84629082 } else {
....@@ -8464,7 +9084,11 @@
84649084 if (ret && cif_dev->chip_id < CHIP_RK3588_CIF)
84659085 return;
84669086 }
8467
- if (!stream->is_line_wake_up && stream->dma_en & RKCIF_DMAEN_BY_VICAP)
9087
+ if (cif_dev->chip_id < CHIP_RK3588_CIF &&
9088
+ cif_dev->active_sensor->mbus.type == V4L2_MBUS_BT656 &&
9089
+ stream->id != 0)
9090
+ stream->frame_idx++;
9091
+ if (!stream->is_line_wake_up)
84689092 rkcif_buf_done_prepare(stream, active_buf, mipi_id, 0);
84699093
84709094 if (cif_dev->chip_id == CHIP_RV1126_CIF ||
....@@ -8486,9 +9110,9 @@
84869110
84879111 spin_lock(&stream->fps_lock);
84889112 if (stream->frame_phase & CIF_CSI_FRAME0_READY)
8489
- stream->fps_stats.frm0_timestamp = ktime_get_ns();
9113
+ stream->fps_stats.frm0_timestamp = rkcif_time_get_ns(cif_dev);
84909114 else if (stream->frame_phase & CIF_CSI_FRAME1_READY)
8491
- stream->fps_stats.frm1_timestamp = ktime_get_ns();
9115
+ stream->fps_stats.frm1_timestamp = rkcif_time_get_ns(cif_dev);
84929116 spin_unlock(&stream->fps_lock);
84939117
84949118 if (cif_dev->inf_id == RKCIF_MIPI_LVDS)
....@@ -8520,11 +9144,11 @@
85209144 if (stream->frame_phase & CIF_CSI_FRAME0_READY) {
85219145 if (stream->curr_buf_rockit)
85229146 active_buf = stream->curr_buf_rockit;
8523
- stream->fps_stats.frm0_timestamp = ktime_get_ns();
9147
+ stream->fps_stats.frm0_timestamp = rkcif_time_get_ns(cif_dev);
85249148 } else if (stream->frame_phase & CIF_CSI_FRAME1_READY) {
85259149 if (stream->next_buf_rockit)
85269150 active_buf = stream->next_buf_rockit;
8527
- stream->fps_stats.frm1_timestamp = ktime_get_ns();
9151
+ stream->fps_stats.frm1_timestamp = rkcif_time_get_ns(cif_dev);
85289152 }
85299153 spin_unlock_irqrestore(&stream->fps_lock, flags);
85309154 }
....@@ -8581,6 +9205,15 @@
85819205 }
85829206 }
85839207
9208
+static void rkcif_toisp_set_stream(struct rkcif_device *dev, int on)
9209
+{
9210
+ struct v4l2_subdev *sd = get_rkisp_sd(dev->sditf[0]);
9211
+
9212
+ if (sd)
9213
+ v4l2_subdev_call(sd, core, ioctl,
9214
+ RKISP_VICAP_CMD_SET_STREAM, &on);
9215
+}
9216
+
85849217 static int rkcif_do_reset_work(struct rkcif_device *cif_dev,
85859218 enum rkmodule_reset_src reset_src)
85869219 {
....@@ -8590,6 +9223,7 @@
85909223 struct rkcif_sensor_info *terminal_sensor = &cif_dev->terminal_sensor;
85919224 struct rkcif_resume_info *resume_info = &cif_dev->reset_work.resume_info;
85929225 struct rkcif_timer *timer = &cif_dev->reset_watchdog_timer;
9226
+ struct sditf_priv *priv = cif_dev->sditf[0];
85939227 int i, j, ret = 0;
85949228 u32 on, sof_cnt;
85959229 int capture_mode = 0;
....@@ -8658,10 +9292,12 @@
86589292 __func__, on ? "on" : "off", p->subdevs[i]->name);
86599293 }
86609294
8661
- for (i = 0; i < cif_dev->sditf_cnt; i++) {
8662
- if (cif_dev->sditf[i] && cif_dev->sditf[i]->sensor_sd)
8663
- ret = v4l2_subdev_call(cif_dev->sditf[i]->sensor_sd, core, ioctl,
8664
- RKMODULE_SET_QUICK_STREAM, &on);
9295
+ if (priv && priv->is_combine_mode && cif_dev->sditf_cnt <= RKCIF_MAX_SDITF) {
9296
+ for (i = 0; i < cif_dev->sditf_cnt; i++) {
9297
+ if (cif_dev->sditf[i] && cif_dev->sditf[i]->sensor_sd)
9298
+ ret = v4l2_subdev_call(cif_dev->sditf[i]->sensor_sd, core, ioctl,
9299
+ RKMODULE_SET_QUICK_STREAM, &on);
9300
+ }
86659301 }
86669302
86679303 rockchip_clear_system_status(SYS_STATUS_CIF0);
....@@ -8683,6 +9319,9 @@
86839319 goto unlock_stream;
86849320 }
86859321 }
9322
+
9323
+ if (priv && priv->mode.rdbk_mode == RKISP_VICAP_ONLINE)
9324
+ rkcif_toisp_set_stream(cif_dev, 1);
86869325
86879326 for (i = 0; i < j; i++) {
86889327 stream = resume_stream[i];
....@@ -8756,10 +9395,12 @@
87569395 p->subdevs[i]->name);
87579396 }
87589397
8759
- for (i = 0; i < cif_dev->sditf_cnt; i++) {
8760
- if (cif_dev->sditf[i] && cif_dev->sditf[i]->sensor_sd)
8761
- v4l2_subdev_call(cif_dev->sditf[i]->sensor_sd, core, ioctl,
8762
- RKMODULE_SET_QUICK_STREAM, &on);
9398
+ if (priv && priv->is_combine_mode && cif_dev->sditf_cnt <= RKCIF_MAX_SDITF) {
9399
+ for (i = 0; i < cif_dev->sditf_cnt; i++) {
9400
+ if (cif_dev->sditf[i] && cif_dev->sditf[i]->sensor_sd)
9401
+ v4l2_subdev_call(cif_dev->sditf[i]->sensor_sd, core, ioctl,
9402
+ RKMODULE_SET_QUICK_STREAM, &on);
9403
+ }
87639404 }
87649405
87659406 if (cif_dev->chip_id < CHIP_RK3588_CIF)
....@@ -8820,7 +9461,7 @@
88209461 v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev, "diff_time:%lld,devi_t:%ld,devi_h:%d\n",
88219462 diff_time, timer->line_end_cycle * deviation, deviation);
88229463
8823
- cur_time = ktime_get_ns();
9464
+ cur_time = rkcif_time_get_ns(dev);
88249465 time_distance = timestamp0 > timestamp1 ?
88259466 cur_time - timestamp0 : cur_time - timestamp1;
88269467 time_distance = div_u64(time_distance, 1000);
....@@ -8929,6 +9570,7 @@
89299570 timer->csi2_err_cnt_even = 0;
89309571 timer->csi2_err_fs_fe_cnt = 0;
89319572 timer->notifer_called_cnt = 0;
9573
+ dev->is_toisp_reset = false;
89329574 for (i = 0; i < dev->num_channels; i++) {
89339575 stream = &dev->stream[i];
89349576 if (stream->state == RKCIF_STATE_STREAMING)
....@@ -8938,10 +9580,10 @@
89389580 if (timer->is_ctrl_by_user) {
89399581 rkcif_send_reset_event(dev, timer->reset_src);
89409582 } else {
9583
+ dev->reset_work.reset_src = timer->reset_src;
89419584 if (!schedule_work(&dev->reset_work.work))
89429585 v4l2_info(&dev->v4l2_dev,
89439586 "schedule reset work failed\n");
8944
- dev->reset_work.reset_src = timer->reset_src;
89459587 }
89469588 }
89479589
....@@ -8955,6 +9597,15 @@
89559597 unsigned long flags;
89569598 int ret, is_reset = 0;
89579599 struct rkmodule_vicap_reset_info rst_info;
9600
+
9601
+ if (dev->is_toisp_reset) {
9602
+ is_reset = 1;
9603
+ timer->reset_src = RKCIF_RESET_SRC_ERR_ISP;
9604
+ }
9605
+ if (is_reset) {
9606
+ rkcif_init_reset_work(timer);
9607
+ return is_reset;
9608
+ }
89589609
89599610 if (timer->last_buf_wakeup_cnt[stream->id] < stream->buf_wake_up_cnt &&
89609611 check_cnt == 0) {
....@@ -9329,6 +9980,7 @@
93299980 if (stream->buf_owner == RKCIF_DMAEN_BY_ISP)
93309981 stream->buf_owner = RKCIF_DMAEN_BY_ISP_TO_VICAP;
93319982
9983
+ atomic_dec(&cif_dev->streamoff_cnt);
93329984 if (stream->dma_en) {
93339985 stream->dma_en |= stream->to_en_dma;
93349986 stream->to_en_dma = 0;
....@@ -9399,7 +10051,7 @@
939910051 return -EINVAL;
940010052
940110053 stream->dma_en &= ~stream->to_stop_dma;
9402
-
10054
+ atomic_inc(&cif_dev->streamoff_cnt);
940310055 if (stream->dma_en != 0) {
940410056 if (stream->dma_en & RKCIF_DMAEN_BY_ISP)
940510057 stream->buf_owner = RKCIF_DMAEN_BY_ISP;
....@@ -9437,6 +10089,11 @@
943710089 rkcif_write_register(cif_dev, CIF_REG_DVP_CTRL, val);
943810090 }
943910091 stream->to_stop_dma = 0;
10092
+ v4l2_dbg(4, rkcif_debug, &cif_dev->v4l2_dev,
10093
+ "stream[%d] replace_cnt %d, y_addr 0x%x, 0x%x\n",
10094
+ stream->id, stream->buf_replace_cnt,
10095
+ rkcif_read_register(cif_dev, get_reg_index_of_frm0_y_addr(stream->id)),
10096
+ rkcif_read_register(cif_dev, get_reg_index_of_frm1_y_addr(stream->id)));
944010097 return 0;
944110098 }
944210099
....@@ -9490,6 +10147,7 @@
949010147 int i = 0;
949110148 u32 val = 0;
949210149 u64 cur_time = 0;
10150
+ int on = 0;
949310151
949410152 for (i = 0; i < TOISP_CH_MAX; i++) {
949510153 ch = rkcif_g_toisp_ch(intstat_glb, index);
....@@ -9507,7 +10165,30 @@
950710165 stream->stopping = false;
950810166 wake_up(&stream->wq_stopped);
950910167 }
9510
-
10168
+ if (stream->cifdev->sensor_state_change) {
10169
+ rkcif_dphy_quick_stream(stream->cifdev, on);
10170
+ stream->cifdev->sensor_work.on = stream->cifdev->sensor_state;
10171
+ schedule_work(&stream->cifdev->sensor_work.work);
10172
+ stream->cifdev->sensor_state_change = false;
10173
+ if (stream->is_wait_stop_complete) {
10174
+ stream->is_wait_stop_complete = false;
10175
+ complete(&stream->stop_complete);
10176
+ }
10177
+ }
10178
+ if (stream->is_single_cap && (!stream->cur_skip_frame) &&
10179
+ (stream->cifdev->hdr.hdr_mode == NO_HDR ||
10180
+ (stream->cifdev->hdr.hdr_mode == HDR_X2 && stream->id == 1) ||
10181
+ (stream->cifdev->hdr.hdr_mode == HDR_X3 && stream->id == 2))) {
10182
+ rkcif_dphy_quick_stream(stream->cifdev, on);
10183
+ stream->cifdev->sensor_work.on = 0;
10184
+ schedule_work(&stream->cifdev->sensor_work.work);
10185
+ stream->is_single_cap = false;
10186
+ }
10187
+ if (stream->cur_skip_frame &&
10188
+ (stream->cifdev->hdr.hdr_mode == NO_HDR ||
10189
+ (stream->cifdev->hdr.hdr_mode == HDR_X2 && stream->id == 1) ||
10190
+ (stream->cifdev->hdr.hdr_mode == HDR_X3 && stream->id == 2)))
10191
+ stream->cur_skip_frame--;
951110192 if (stream->cifdev->chip_id >= CHIP_RV1106_CIF)
951210193 rkcif_modify_frame_skip_config(stream);
951310194 if (stream->cifdev->rdbk_debug &&
....@@ -9544,9 +10225,14 @@
954410225 if (stream->id == 0)
954510226 rkcif_send_sof(stream->cifdev);
954610227 stream->frame_idx++;
9547
- cur_time = ktime_get_ns();
10228
+ cur_time = rkcif_time_get_ns(stream->cifdev);
954810229 stream->readout.readout_time = cur_time - stream->readout.fs_timestamp;
954910230 stream->readout.fs_timestamp = cur_time;
10231
+ stream->buf_wake_up_cnt++;
10232
+ if (stream->frame_idx % 2)
10233
+ stream->fps_stats.frm0_timestamp = rkcif_time_get_ns(stream->cifdev);
10234
+ else
10235
+ stream->fps_stats.frm1_timestamp = rkcif_time_get_ns(stream->cifdev);
955010236 if (stream->cifdev->rdbk_debug &&
955110237 stream->frame_idx < 15)
955210238 v4l2_info(&priv->cif_dev->v4l2_dev,
....@@ -9616,15 +10302,16 @@
961610302
961710303 sync_config = &hw->sync_config[cif_dev->sync_cfg.group];
961810304 sync_config->sync_code |= BIT(cif_dev->csi_host_idx);
9619
- if (sync_config->sync_code != sync_config->sync_mask)
9620
- return -EINVAL;
9621
-
962210305 v4l2_dbg(3, rkcif_debug, &cif_dev->v4l2_dev,
9623
- "sync code 0x%x, mask 0x%x, update 0x%x, cache 0x%x\n",
10306
+ "sync code 0x%x, mask 0x%x, update 0x%x, cache 0x%x, timestamp %llu\n",
962410307 sync_config->sync_code,
962510308 sync_config->sync_mask,
962610309 sync_config->update_code,
9627
- sync_config->update_cache);
10310
+ sync_config->update_cache,
10311
+ detect_stream->readout.fs_timestamp);
10312
+
10313
+ if (sync_config->sync_code != sync_config->sync_mask)
10314
+ return -EINVAL;
962810315
962910316 for (i = 0; i < sync_config->dev_cnt; i++) {
963010317 if (sync_config->mode == RKCIF_MASTER_MASTER) {
....@@ -9670,7 +10357,7 @@
967010357 if (cif_dev->chip_id < CHIP_RK3588_CIF)
967110358 detect_stream->fs_cnt_in_single_frame++;
967210359 spin_lock_irqsave(&detect_stream->fps_lock, flags);
9673
- detect_stream->readout.fs_timestamp = ktime_get_ns();
10360
+ detect_stream->readout.fs_timestamp = rkcif_time_get_ns(cif_dev);
967410361 spin_unlock_irqrestore(&detect_stream->fps_lock, flags);
967510362
967610363 if (cif_dev->sync_cfg.type != RKCIF_NOSYNC_MODE) {
....@@ -9721,7 +10408,7 @@
972110408 "stream[%d] sof %d %lld\n",
972210409 detect_stream->id,
972310410 detect_stream->frame_idx - 1,
9724
- ktime_get_ns());
10411
+ rkcif_time_get_ns(cif_dev));
972510412 }
972610413 }
972710414
....@@ -9780,6 +10467,425 @@
978010467 return is_update;
978110468 }
978210469
10470
+static bool rkcif_check_single_dev_stream_on(struct rkcif_hw *hw)
10471
+{
10472
+ struct rkcif_device *cif_dev = NULL;
10473
+ struct rkcif_stream *stream = NULL;
10474
+ int i = 0, j = 0;
10475
+ int stream_cnt = 0;
10476
+
10477
+ if (hw->dev_num == 1)
10478
+ return true;
10479
+ for (i = 0; i < hw->dev_num; i++) {
10480
+ cif_dev = hw->cif_dev[i];
10481
+ for (j = 0; j < RKCIF_MAX_STREAM_MIPI; j++) {
10482
+ stream = &cif_dev->stream[j];
10483
+ if (stream->state == RKCIF_STATE_STREAMING ||
10484
+ stream->state == RKCIF_STATE_RESET_IN_STREAMING) {
10485
+ stream_cnt++;
10486
+ break;
10487
+ }
10488
+ }
10489
+ }
10490
+ if (stream_cnt > 1)
10491
+ return false;
10492
+ return true;
10493
+}
10494
+
10495
+static void rkcif_get_resmem_head(struct rkcif_device *cif_dev)
10496
+{
10497
+ void *resmem_va = phys_to_virt(cif_dev->resmem_pa);
10498
+ struct rkisp_thunderboot_resmem_head *head = NULL;
10499
+ int size = 0;
10500
+ int offset = 0;
10501
+ int ret = 0;
10502
+ int cam_idx = 0;
10503
+ char cam_idx_str[3] = {0};
10504
+
10505
+ if (!cif_dev->is_rtt_suspend)
10506
+ return;
10507
+ strscpy(cam_idx_str, cif_dev->terminal_sensor.sd->name + 1, 2);
10508
+ cam_idx_str[2] = '\0';
10509
+ ret = kstrtoint(cam_idx_str, 0, &cam_idx);
10510
+ if (ret) {
10511
+ v4l2_err(&cif_dev->v4l2_dev,
10512
+ "get camera index fail\n");
10513
+ return;
10514
+ }
10515
+
10516
+ if (cif_dev->chip_id == CHIP_RV1106_CIF) {
10517
+ size = sizeof(struct rkisp32_thunderboot_resmem_head);
10518
+ offset = size * cam_idx;
10519
+ }
10520
+ /* currently, thunderboot with mcu only run one camera */
10521
+ offset = 0;
10522
+
10523
+ if (size && size < cif_dev->resmem_size) {
10524
+ dma_sync_single_for_cpu(cif_dev->dev, cif_dev->resmem_addr + offset,
10525
+ size, DMA_FROM_DEVICE);
10526
+ if (cif_dev->chip_id == CHIP_RV1106_CIF) {
10527
+ struct rkisp32_thunderboot_resmem_head *tmp = resmem_va + offset;
10528
+
10529
+ head = &tmp->head;
10530
+ cif_dev->resume_mode = head->rtt_mode;
10531
+ cif_dev->nr_buf_size = head->nr_buf_size;
10532
+ cif_dev->share_mem_size = head->share_mem_size;
10533
+ cif_dev->thunderboot_sensor_num = head->camera_num;
10534
+ }
10535
+ }
10536
+ v4l2_err(&cif_dev->v4l2_dev,
10537
+ "get camera index %02x, resume_mode 0x%x, nr_buf_size %d\n",
10538
+ cam_idx, cif_dev->resume_mode, cif_dev->nr_buf_size);
10539
+}
10540
+
10541
+static int rkcif_subdevs_set_power(struct rkcif_device *cif_dev, int on)
10542
+{
10543
+ struct sditf_priv *priv = cif_dev->sditf[0];
10544
+ int ret = 0;
10545
+ int i = 0;
10546
+
10547
+ if (cif_dev->terminal_sensor.sd)
10548
+ ret = v4l2_subdev_call(cif_dev->terminal_sensor.sd,
10549
+ core, s_power, on);
10550
+ if (priv && priv->is_combine_mode && cif_dev->sditf_cnt <= RKCIF_MAX_SDITF) {
10551
+ for (i = 0; i < cif_dev->sditf_cnt; i++) {
10552
+ if (cif_dev->sditf[i] && cif_dev->sditf[i]->sensor_sd)
10553
+ v4l2_subdev_call(cif_dev->sditf[i]->sensor_sd, core,
10554
+ s_power, on);
10555
+ }
10556
+ }
10557
+ return ret;
10558
+}
10559
+
10560
+static void rkcif_sensor_quick_streaming_cb(void *data)
10561
+{
10562
+ struct v4l2_subdev *subdevs = (struct v4l2_subdev *)data;
10563
+ int on = 1;
10564
+
10565
+ v4l2_subdev_call(subdevs, core, ioctl,
10566
+ RKMODULE_SET_QUICK_STREAM, &on);
10567
+}
10568
+
10569
+static int rkcif_subdevs_set_stream(struct rkcif_device *cif_dev, int on)
10570
+{
10571
+ struct rkcif_pipeline *p = &cif_dev->pipe;
10572
+ struct rkcif_sensor_info *terminal_sensor = &cif_dev->terminal_sensor;
10573
+ struct sditf_priv *priv = cif_dev->sditf[0];
10574
+ int i = 0;
10575
+ int ret = 0;
10576
+
10577
+ for (i = 0; i < p->num_subdevs; i++) {
10578
+ if (p->subdevs[i] == terminal_sensor->sd && on)
10579
+ rkcif_set_sof(cif_dev, cif_dev->stream[0].frame_idx);
10580
+ if (p->subdevs[i] == terminal_sensor->sd &&
10581
+ cif_dev->chip_id == CHIP_RV1106_CIF) {
10582
+ if (!rk_tb_mcu_is_done() && on) {
10583
+ cif_dev->tb_client.data = p->subdevs[i];
10584
+ cif_dev->tb_client.cb = rkcif_sensor_quick_streaming_cb;
10585
+ rk_tb_client_register_cb(&cif_dev->tb_client);
10586
+ } else {
10587
+ ret = v4l2_subdev_call(p->subdevs[i], core, ioctl,
10588
+ RKMODULE_SET_QUICK_STREAM, &on);
10589
+ if (ret)
10590
+ v4l2_dbg(1, rkcif_debug, &cif_dev->v4l2_dev,
10591
+ "%s:quick stream %s subdev:%s failed\n",
10592
+ __func__, on ? "on" : "off",
10593
+ p->subdevs[i]->name);
10594
+ }
10595
+ } else {
10596
+ ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on);
10597
+ if (ret)
10598
+ v4l2_dbg(1, rkcif_debug, &cif_dev->v4l2_dev,
10599
+ "%s:stream %s subdev:%s failed\n",
10600
+ __func__, on ? "on" : "off", p->subdevs[i]->name);
10601
+ }
10602
+ }
10603
+
10604
+ if (priv && priv->is_combine_mode && cif_dev->sditf_cnt <= RKCIF_MAX_SDITF) {
10605
+ for (i = 0; i < cif_dev->sditf_cnt; i++) {
10606
+ if (cif_dev->sditf[i] && cif_dev->sditf[i]->sensor_sd) {
10607
+ ret = v4l2_subdev_call(cif_dev->sditf[i]->sensor_sd, video, s_stream, on);
10608
+ if (ret)
10609
+ v4l2_dbg(1, rkcif_debug, &cif_dev->v4l2_dev,
10610
+ "%s:stream %s subdev:%s failed\n",
10611
+ __func__, on ? "on" : "off",
10612
+ cif_dev->sditf[i]->sensor_sd->name);
10613
+ }
10614
+ }
10615
+ }
10616
+ return ret;
10617
+}
10618
+
10619
+int rkcif_stream_suspend(struct rkcif_device *cif_dev, int mode)
10620
+{
10621
+ struct rkcif_stream *stream = NULL;
10622
+ struct rkcif_resume_info *resume_info = &cif_dev->reset_work.resume_info;
10623
+ struct sditf_priv *priv = cif_dev->sditf[0];
10624
+ int ret = 0;
10625
+ int i = 0;
10626
+ int sof_cnt = 0;
10627
+ int on = 0;
10628
+ int suspend_cnt = 0;
10629
+
10630
+ mutex_lock(&cif_dev->stream_lock);
10631
+
10632
+ if (priv && priv->mode.rdbk_mode == RKISP_VICAP_ONLINE && mode == RKCIF_RESUME_CIF)
10633
+ goto out_suspend;
10634
+
10635
+ for (i = 0; i < RKCIF_MAX_STREAM_MIPI; i++) {
10636
+ stream = &cif_dev->stream[i];
10637
+
10638
+ if (stream->state == RKCIF_STATE_STREAMING) {
10639
+ suspend_cnt++;
10640
+ v4l2_dbg(1, rkcif_debug, &cif_dev->v4l2_dev,
10641
+ "stream[%d] stopping\n", stream->id);
10642
+ if (stream->dma_en) {
10643
+ stream->stopping = true;
10644
+ ret = wait_event_timeout(stream->wq_stopped,
10645
+ stream->state != RKCIF_STATE_STREAMING,
10646
+ msecs_to_jiffies(500));
10647
+ if (!ret) {
10648
+ rkcif_stream_stop(stream);
10649
+ stream->stopping = false;
10650
+ }
10651
+ } else {
10652
+ rkcif_stream_stop(stream);
10653
+ }
10654
+
10655
+ if (stream->id == RKCIF_STREAM_MIPI_ID0) {
10656
+ sof_cnt = rkcif_get_sof(cif_dev);
10657
+ v4l2_dbg(1, rkcif_debug, &cif_dev->v4l2_dev,
10658
+ "%s: stream[%d] sync frmid & csi_sof, frm_id:%d, csi_sof:%d\n",
10659
+ __func__,
10660
+ stream->id,
10661
+ stream->frame_idx,
10662
+ sof_cnt);
10663
+
10664
+ resume_info->frm_sync_seq = stream->frame_idx;
10665
+ }
10666
+
10667
+ stream->state = RKCIF_STATE_RESET_IN_STREAMING;
10668
+ stream->is_fs_fe_not_paired = false;
10669
+ stream->fs_cnt_in_single_frame = 0;
10670
+
10671
+ v4l2_dbg(1, rkcif_debug, &cif_dev->v4l2_dev,
10672
+ "%s stop stream[%d] in streaming, frm_id:%d, csi_sof:%d\n",
10673
+ __func__, stream->id, stream->frame_idx, rkcif_get_sof(cif_dev));
10674
+
10675
+ }
10676
+ }
10677
+
10678
+ if (suspend_cnt == 0)
10679
+ goto out_suspend;
10680
+
10681
+ if (!cif_dev->resume_mode)
10682
+ rkcif_subdevs_set_power(cif_dev, on);
10683
+
10684
+ rkcif_subdevs_set_stream(cif_dev, on);
10685
+
10686
+out_suspend:
10687
+ mutex_unlock(&cif_dev->stream_lock);
10688
+ return 0;
10689
+}
10690
+
10691
+int rkcif_stream_resume(struct rkcif_device *cif_dev, int mode)
10692
+{
10693
+ struct rkcif_stream *stream = NULL;
10694
+ struct sditf_priv *priv = cif_dev->sditf[0];
10695
+ struct v4l2_subdev *sd = NULL;
10696
+ int ret = 0;
10697
+ int i = 0;
10698
+ u32 capture_mode = 0;
10699
+ int on = 1;
10700
+ int resume_cnt = 0;
10701
+ unsigned long flags;
10702
+ bool is_single_dev = false;
10703
+ bool is_can_be_online = false;
10704
+ struct rkisp_vicap_mode vicap_mode;
10705
+
10706
+ mutex_lock(&cif_dev->stream_lock);
10707
+
10708
+ rkcif_get_resmem_head(cif_dev);
10709
+ is_single_dev = rkcif_check_single_dev_stream_on(cif_dev->hw_dev);
10710
+ is_can_be_online = rkcif_check_can_be_online(cif_dev);
10711
+ if (cif_dev->resume_mode == RKISP_RTT_MODE_ONE_FRAME) {
10712
+ if (cif_dev->is_rtt_suspend) {
10713
+ capture_mode = RKCIF_STREAM_MODE_TOISP_RDBK;
10714
+ if (priv)
10715
+ priv->mode.rdbk_mode = RKISP_VICAP_RDBK_AUTO;
10716
+ } else {
10717
+ if (priv && priv->mode.rdbk_mode == RKISP_VICAP_ONLINE) {
10718
+ if (cif_dev->chip_id == CHIP_RV1106_CIF) {
10719
+ capture_mode = RKCIF_STREAM_MODE_TOISP_RDBK;
10720
+ priv->mode.rdbk_mode = RKISP_VICAP_RDBK_AUTO;
10721
+ } else {
10722
+ capture_mode = RKCIF_STREAM_MODE_TOISP;
10723
+ }
10724
+ } else if (priv &&
10725
+ (priv->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO ||
10726
+ priv->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO_ONE_FRAME)) {
10727
+ capture_mode = RKCIF_STREAM_MODE_TOISP_RDBK;
10728
+ } else {
10729
+ capture_mode = RKCIF_STREAM_MODE_CAPTURE;
10730
+ }
10731
+ }
10732
+ } else if (cif_dev->resume_mode == RKISP_RTT_MODE_MULTI_FRAME) {
10733
+ if (is_single_dev && is_can_be_online) {
10734
+ capture_mode = RKCIF_STREAM_MODE_TOISP;
10735
+ if (priv)
10736
+ priv->mode.rdbk_mode = RKISP_VICAP_ONLINE;
10737
+ } else {
10738
+ if (cif_dev->is_thunderboot) {
10739
+ capture_mode = RKCIF_STREAM_MODE_TOISP_RDBK;
10740
+ if (priv)
10741
+ priv->mode.rdbk_mode = RKISP_VICAP_RDBK_AUTO;
10742
+ } else {
10743
+ capture_mode = RKCIF_STREAM_MODE_CAPTURE;
10744
+ if (priv)
10745
+ priv->mode.rdbk_mode = RKISP_VICAP_RDBK_AIQ;
10746
+ }
10747
+ }
10748
+ } else {
10749
+ if (priv && priv->mode.rdbk_mode == RKISP_VICAP_ONLINE)
10750
+ capture_mode = RKCIF_STREAM_MODE_TOISP;
10751
+ else if (priv &&
10752
+ (priv->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO ||
10753
+ priv->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO_ONE_FRAME))
10754
+ capture_mode = RKCIF_STREAM_MODE_TOISP_RDBK;
10755
+ else
10756
+ capture_mode = RKCIF_STREAM_MODE_CAPTURE;
10757
+ }
10758
+ if (priv && priv->mode.rdbk_mode == RKISP_VICAP_ONLINE && mode == RKCIF_RESUME_CIF)
10759
+ goto out_resume;
10760
+
10761
+ for (i = 0; i < RKCIF_MAX_STREAM_MIPI; i++) {
10762
+ stream = &cif_dev->stream[i];
10763
+ if (stream->state != RKCIF_STATE_RESET_IN_STREAMING)
10764
+ continue;
10765
+
10766
+ stream->fs_cnt_in_single_frame = 0;
10767
+ if (cif_dev->resume_mode == RKISP_RTT_MODE_ONE_FRAME)
10768
+ stream->is_single_cap = true;
10769
+ spin_lock_irqsave(&stream->vbq_lock, flags);
10770
+ if (!priv || priv->mode.rdbk_mode == RKISP_VICAP_RDBK_AIQ) {
10771
+ if (stream->cif_fmt_in->field == V4L2_FIELD_INTERLACED) {
10772
+ if (stream->curr_buf == stream->next_buf) {
10773
+ if (stream->curr_buf)
10774
+ list_add_tail(&stream->curr_buf->queue, &stream->buf_head);
10775
+ } else {
10776
+ if (stream->curr_buf)
10777
+ list_add_tail(&stream->curr_buf->queue, &stream->buf_head);
10778
+ if (stream->next_buf)
10779
+ list_add_tail(&stream->next_buf->queue, &stream->buf_head);
10780
+ }
10781
+ stream->curr_buf = NULL;
10782
+ stream->next_buf = NULL;
10783
+ }
10784
+ } else {
10785
+ if (priv->mode.rdbk_mode == RKISP_VICAP_ONLINE) {
10786
+ if (stream->curr_buf_toisp == stream->next_buf_toisp) {
10787
+ if (stream->curr_buf_toisp)
10788
+ list_add_tail(&stream->curr_buf_toisp->list, &stream->rx_buf_head);
10789
+ } else {
10790
+ if (stream->curr_buf_toisp)
10791
+ list_add_tail(&stream->curr_buf_toisp->list, &stream->rx_buf_head);
10792
+ if (stream->next_buf_toisp)
10793
+ list_add_tail(&stream->next_buf_toisp->list, &stream->rx_buf_head);
10794
+ }
10795
+ stream->curr_buf_toisp = NULL;
10796
+ stream->next_buf_toisp = NULL;
10797
+ } else {
10798
+ if (stream->curr_buf_toisp == stream->next_buf_toisp) {
10799
+ if (stream->curr_buf_toisp)
10800
+ list_add_tail(&stream->curr_buf_toisp->list, &stream->rx_buf_head);
10801
+ } else {
10802
+ if (stream->curr_buf_toisp)
10803
+ list_add_tail(&stream->curr_buf_toisp->list, &stream->rx_buf_head);
10804
+ if (stream->next_buf_toisp)
10805
+ list_add_tail(&stream->next_buf_toisp->list, &stream->rx_buf_head);
10806
+ }
10807
+ stream->curr_buf_toisp = NULL;
10808
+ stream->next_buf_toisp = NULL;
10809
+ }
10810
+ }
10811
+
10812
+ spin_unlock_irqrestore(&stream->vbq_lock, flags);
10813
+
10814
+ if (priv) {
10815
+ if (priv->mode.rdbk_mode == RKISP_VICAP_ONLINE) {
10816
+ sditf_change_to_online(priv);
10817
+ if (cif_dev->resume_mode == RKISP_RTT_MODE_MULTI_FRAME &&
10818
+ stream->rx_buf_num &&
10819
+ (priv->hdr_cfg.hdr_mode == NO_HDR ||
10820
+ (priv->hdr_cfg.hdr_mode == HDR_X2 && stream->id == 1) ||
10821
+ (priv->hdr_cfg.hdr_mode == HDR_X3 && stream->id == 2)))
10822
+ rkcif_free_rx_buf(stream, priv->buf_num);
10823
+ else if (!stream->rx_buf_num &&
10824
+ ((priv->hdr_cfg.hdr_mode == HDR_X2 && stream->id == 0) ||
10825
+ (priv->hdr_cfg.hdr_mode == HDR_X3 && (stream->id == 0 || stream->id == 1))))
10826
+ rkcif_init_rx_buf(stream, 1);
10827
+ } else {
10828
+ if (stream->is_single_cap && stream->id == 0) {
10829
+ vicap_mode = priv->mode;
10830
+ vicap_mode.rdbk_mode = RKISP_VICAP_RDBK_AUTO_ONE_FRAME;
10831
+ sd = get_rkisp_sd(priv);
10832
+ if (sd) {
10833
+ ret = v4l2_subdev_call(sd, core, ioctl,
10834
+ RKISP_VICAP_CMD_MODE, &vicap_mode);
10835
+ if (ret)
10836
+ v4l2_err(&cif_dev->v4l2_dev,
10837
+ "set isp work mode rdbk aotu oneframe fail\n");
10838
+
10839
+ }
10840
+ }
10841
+ sditf_disable_immediately(priv);
10842
+ if (!stream->rx_buf_num &&
10843
+ capture_mode == RKCIF_STREAM_MODE_TOISP_RDBK) {
10844
+ if (cif_dev->resume_mode == RKISP_RTT_MODE_ONE_FRAME)
10845
+ rkcif_init_rx_buf(stream, 1);
10846
+ else
10847
+ rkcif_init_rx_buf(stream, priv->buf_num);
10848
+ }
10849
+ }
10850
+ }
10851
+
10852
+ stream->lack_buf_cnt = 0;
10853
+ if (cif_dev->active_sensor &&
10854
+ (cif_dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_DPHY ||
10855
+ cif_dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_CPHY ||
10856
+ cif_dev->active_sensor->mbus.type == V4L2_MBUS_CCP2))
10857
+ ret = rkcif_csi_stream_start(stream, capture_mode);
10858
+ else
10859
+ ret = rkcif_stream_start(stream, capture_mode);
10860
+ if (ret)
10861
+ v4l2_err(&cif_dev->v4l2_dev, "%s:resume stream[%d] failed\n",
10862
+ __func__, stream->id);
10863
+
10864
+ resume_cnt++;
10865
+ stream->cur_skip_frame = stream->skip_frame;
10866
+ v4l2_dbg(1, rkcif_debug, &cif_dev->v4l2_dev,
10867
+ "resume stream[%d], frm_idx:%d, csi_sof:%d\n",
10868
+ stream->id, stream->frame_idx,
10869
+ rkcif_get_sof(cif_dev));
10870
+ }
10871
+
10872
+ if (resume_cnt == 0)
10873
+ goto out_resume;
10874
+
10875
+ if (!cif_dev->resume_mode)
10876
+ rkcif_subdevs_set_power(cif_dev, on);
10877
+
10878
+ atomic_set(&cif_dev->streamoff_cnt, 0);
10879
+ rkcif_subdevs_set_stream(cif_dev, on);
10880
+
10881
+ if (cif_dev->chip_id < CHIP_RK3588_CIF)
10882
+ rkcif_start_luma(&cif_dev->luma_vdev,
10883
+ cif_dev->stream[RKCIF_STREAM_MIPI_ID0].cif_fmt_in);
10884
+out_resume:
10885
+ mutex_unlock(&cif_dev->stream_lock);
10886
+ return 0;
10887
+}
10888
+
978310889 void rkcif_err_print_work(struct work_struct *work)
978410890 {
978510891 struct rkcif_err_state_work *err_state_work = container_of(work,
....@@ -9795,7 +10901,7 @@
979510901 u64 cur_time = 0;
979610902 bool is_print = false;
979710903
9798
- cur_time = ktime_get_ns();
10904
+ cur_time = rkcif_time_get_ns(dev);
979910905 if (err_state_work->last_timestamp == 0) {
980010906 is_print = true;
980110907 } else {
....@@ -9839,10 +10945,18 @@
983910945 v4l2_err(&dev->v4l2_dev,
984010946 "stream[3], frm0/frm1 end simultaneously,frm id:%d, cnt %llu\n",
984110947 dev->stream[3].frame_idx, dev->irq_stats.trig_simult_cnt[3]);
9842
- if (err_state & RKCIF_ERR_SIZE)
9843
- v4l2_err(&dev->v4l2_dev,
9844
- "ERROR: csi size err, intstat:0x%x, lastline:0x%x, cnt %llu\n",
9845
- intstat, lastline, dev->irq_stats.csi_size_err_cnt);
10948
+ if (err_state & RKCIF_ERR_SIZE) {
10949
+ if (dev->chip_id >= CHIP_RK3588_CIF)
10950
+ v4l2_err(&dev->v4l2_dev,
10951
+ "ERROR: csi size err, intstat:0x%x, size:0x%x,0x%x,0x%x,0x%x, cnt %llu\n",
10952
+ intstat, err_state_work->size_id0, err_state_work->size_id1,
10953
+ err_state_work->size_id2, err_state_work->size_id3,
10954
+ dev->irq_stats.csi_size_err_cnt);
10955
+ else
10956
+ v4l2_err(&dev->v4l2_dev,
10957
+ "ERROR: csi size err, intstat:0x%x, lastline:0x%x, cnt %llu\n",
10958
+ intstat, lastline, dev->irq_stats.csi_size_err_cnt);
10959
+ }
984610960 if (err_state & RKCIF_ERR_OVERFLOW)
984710961 v4l2_err(&dev->v4l2_dev,
984810962 "ERROR: csi fifo overflow, intstat:0x%x, lastline:0x%x, cnt %llu\n",
....@@ -9876,6 +10990,7 @@
987610990 unsigned long flags;
987710991 bool is_update = false;
987810992 int ret = 0;
10993
+ int on = 0;
987910994
988010995 if (!cif_dev->active_sensor)
988110996 return;
....@@ -9896,13 +11011,22 @@
989611011 if (intstat) {
989711012 rkcif_write_register(cif_dev, CIF_REG_MIPI_LVDS_INTSTAT, intstat);
989811013 v4l2_dbg(2, rkcif_debug, &cif_dev->v4l2_dev,
9899
- "intstat 0x%x\n",
9900
- intstat);
11014
+ "intstat 0x%x\n", intstat);
990111015 } else {
990211016 return;
990311017 }
990411018
990511019 if (intstat & CSI_SIZE_ERR) {
11020
+ if (cif_dev->chip_id >= CHIP_RK3588_CIF) {
11021
+ cif_dev->err_state_work.size_id0 = rkcif_read_register(cif_dev,
11022
+ CIF_REG_MIPI_FRAME_SIZE_ID0);
11023
+ cif_dev->err_state_work.size_id1 = rkcif_read_register(cif_dev,
11024
+ CIF_REG_MIPI_FRAME_SIZE_ID1);
11025
+ cif_dev->err_state_work.size_id2 = rkcif_read_register(cif_dev,
11026
+ CIF_REG_MIPI_FRAME_SIZE_ID2);
11027
+ cif_dev->err_state_work.size_id3 = rkcif_read_register(cif_dev,
11028
+ CIF_REG_MIPI_FRAME_SIZE_ID3);
11029
+ }
990611030 cif_dev->irq_stats.csi_size_err_cnt++;
990711031 cif_dev->err_state |= RKCIF_ERR_SIZE;
990811032 rkcif_write_register_or(cif_dev, CIF_REG_MIPI_LVDS_CTRL, 0x000A0000);
....@@ -9915,9 +11039,15 @@
991511039 return;
991611040 }
991711041
9918
- if (intstat & CSI_BANDWIDTH_LACK_V1) {
11042
+ if (intstat & CSI_BANDWIDTH_LACK_V1 &&
11043
+ cif_dev->intr_mask & CSI_BANDWIDTH_LACK_V1) {
991911044 cif_dev->irq_stats.csi_bwidth_lack_cnt++;
992011045 cif_dev->err_state |= RKCIF_ERR_BANDWIDTH_LACK;
11046
+ if (cif_dev->irq_stats.csi_bwidth_lack_cnt > 10) {
11047
+ rkcif_write_register_and(cif_dev, CIF_REG_MIPI_LVDS_INTEN, ~(CSI_BANDWIDTH_LACK_V1));
11048
+ cif_dev->intr_mask &= ~(CSI_BANDWIDTH_LACK_V1);
11049
+ schedule_delayed_work(&cif_dev->work_deal_err, msecs_to_jiffies(1000));
11050
+ }
992111051 }
992211052
992311053 if (intstat & CSI_ALL_ERROR_INTEN_V1) {
....@@ -9972,7 +11102,19 @@
997211102 stream->id,
997311103 stream->frame_idx - 1,
997411104 stream->frame_phase,
9975
- ktime_get_ns());
11105
+ rkcif_time_get_ns(cif_dev));
11106
+ if (stream->is_finish_stop_dma && stream->is_wait_dma_stop) {
11107
+ stream->is_wait_dma_stop = false;
11108
+ wake_up(&stream->wq_stopped);
11109
+ stream->is_finish_stop_dma = false;
11110
+ continue;
11111
+ }
11112
+
11113
+ if (stream->is_finish_stop_dma && stream->is_wait_stop_complete) {
11114
+ stream->is_finish_stop_dma = false;
11115
+ stream->is_wait_stop_complete = false;
11116
+ complete(&stream->stop_complete);
11117
+ }
997611118
997711119 if (stream->crop_dyn_en)
997811120 rkcif_dynamic_crop(stream);
....@@ -9982,13 +11124,42 @@
998211124 is_update = true;
998311125 else
998411126 is_update = rkcif_check_buffer_prepare(stream);
11127
+ v4l2_dbg(4, rkcif_debug, &cif_dev->v4l2_dev,
11128
+ "dma capture by vicap, is_updata %d, group mode %d, dma_en %d\n",
11129
+ is_update, cif_dev->sync_cfg.type, stream->dma_en);
998511130 if (is_update)
998611131 rkcif_update_stream(cif_dev, stream, mipi_id);
998711132 } else if (stream->dma_en & RKCIF_DMAEN_BY_ISP) {
11133
+ v4l2_dbg(4, rkcif_debug, &cif_dev->v4l2_dev,
11134
+ "dma capture by isp, dma_en 0x%x\n",
11135
+ stream->dma_en);
998811136 rkcif_update_stream_toisp(cif_dev, stream, mipi_id);
998911137 } else if (stream->dma_en & RKCIF_DMAEN_BY_ROCKIT) {
11138
+ v4l2_dbg(4, rkcif_debug, &cif_dev->v4l2_dev,
11139
+ "dma capture by rockit, dma_en 0x%x\n",
11140
+ stream->dma_en);
999011141 rkcif_update_stream_rockit(cif_dev, stream, mipi_id);
999111142 }
11143
+ if (stream->is_single_cap && !stream->cur_skip_frame) {
11144
+ if (stream->dma_en & RKCIF_DMAEN_BY_ISP)
11145
+ stream->to_stop_dma = RKCIF_DMAEN_BY_ISP;
11146
+ else if (stream->dma_en & RKCIF_DMAEN_BY_VICAP)
11147
+ stream->to_stop_dma = RKCIF_DMAEN_BY_VICAP;
11148
+ else if (stream->dma_en & RKCIF_DMAEN_BY_ROCKIT)
11149
+ stream->to_stop_dma = RKCIF_DMAEN_BY_ROCKIT;
11150
+ rkcif_stop_dma_capture(stream);
11151
+ stream->is_single_cap = false;
11152
+ if ((cif_dev->hdr.hdr_mode == NO_HDR && atomic_read(&cif_dev->streamoff_cnt) == 1) ||
11153
+ (cif_dev->hdr.hdr_mode == HDR_X2 && atomic_read(&cif_dev->streamoff_cnt) == 2) ||
11154
+ (cif_dev->hdr.hdr_mode == HDR_X3 && atomic_read(&cif_dev->streamoff_cnt) == 3)) {
11155
+ rkcif_dphy_quick_stream(stream->cifdev, on);
11156
+ cif_dev->sensor_work.on = 0;
11157
+ schedule_work(&cif_dev->sensor_work.work);
11158
+ }
11159
+ }
11160
+
11161
+ if (stream->cur_skip_frame)
11162
+ stream->cur_skip_frame--;
999211163
999311164 if (cif_dev->chip_id >= CHIP_RV1106_CIF)
999411165 rkcif_modify_frame_skip_config(stream);
....@@ -10003,13 +11174,13 @@
1000311174 }
1000411175
1000511176 spin_lock_irqsave(&stream->vbq_lock, flags);
10006
- if (stream->is_finish_stop_dma) {
10007
- wake_up(&stream->wq_stopped);
10008
- stream->is_finish_stop_dma = false;
10009
- }
10010
- if (!(stream->dma_en & RKCIF_DMAEN_BY_ISP) && stream->lack_buf_cnt == 2) {
11177
+ if (!(stream->cur_stream_mode & RKCIF_STREAM_MODE_TOISP) &&
11178
+ stream->lack_buf_cnt == 2) {
1001111179 stream->to_stop_dma = RKCIF_DMAEN_BY_VICAP;
1001211180 rkcif_stop_dma_capture(stream);
11181
+ v4l2_dbg(4, rkcif_debug, &cif_dev->v4l2_dev,
11182
+ "stream[%d] to stop dma, lack_buf_cnt %d\n",
11183
+ stream->id, stream->lack_buf_cnt);
1001311184 }
1001411185 spin_unlock_irqrestore(&stream->vbq_lock, flags);
1001511186 if (stream->to_en_scale) {
....@@ -10036,10 +11207,11 @@
1003611207 if (intstat & CSI_START_INTSTAT(i)) {
1003711208 stream = &cif_dev->stream[i];
1003811209 if (i == 0) {
10039
- rkcif_deal_sof(cif_dev);
11210
+ if (!stream->cur_skip_frame)
11211
+ rkcif_deal_sof(cif_dev);
1004011212 } else {
1004111213 spin_lock_irqsave(&stream->fps_lock, flags);
10042
- stream->readout.fs_timestamp = ktime_get_ns();
11214
+ stream->readout.fs_timestamp = rkcif_time_get_ns(cif_dev);
1004311215 stream->frame_idx++;
1004411216 spin_unlock_irqrestore(&stream->fps_lock, flags);
1004511217 }
....@@ -10070,7 +11242,8 @@
1007011242 v4l2_info(&cif_dev->v4l2_dev,
1007111243 "line int %lld\n",
1007211244 stream->line_int_cnt);
10073
- if (cif_dev->sditf[0] && cif_dev->sditf[0]->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO)
11245
+ if (cif_dev->sditf[0] && (cif_dev->sditf[0]->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO ||
11246
+ cif_dev->sditf[0]->mode.rdbk_mode == RKISP_VICAP_RDBK_AUTO_ONE_FRAME))
1007411247 rkcif_line_wake_up_rdbk(stream, stream->id);
1007511248 else
1007611249 rkcif_line_wake_up(stream, stream->id);
....@@ -10179,7 +11352,8 @@
1017911352
1018011353 if (intstat & DVP_FRAME0_START_ID0 || intstat & DVP_FRAME1_START_ID0) {
1018111354 stream->is_in_vblank = false;
10182
- rkcif_deal_sof(cif_dev);
11355
+ if (!stream->cur_skip_frame)
11356
+ rkcif_deal_sof(cif_dev);
1018311357 }
1018411358
1018511359 if (stream->crop_dyn_en)
....@@ -10291,10 +11465,11 @@
1029111465 if (intstat & CSI_START_INTSTAT(i)) {
1029211466 stream = &cif_dev->stream[i];
1029311467 if (i == 0) {
10294
- rkcif_deal_sof(cif_dev);
11468
+ if (!stream->cur_skip_frame)
11469
+ rkcif_deal_sof(cif_dev);
1029511470 } else {
1029611471 spin_lock_irqsave(&stream->fps_lock, flags);
10297
- stream->readout.fs_timestamp = ktime_get_ns();
11472
+ stream->readout.fs_timestamp = rkcif_time_get_ns(cif_dev);
1029811473 stream->frame_idx++;
1029911474 spin_unlock_irqrestore(&stream->fps_lock, flags);
1030011475 }
....@@ -10421,9 +11596,9 @@
1042111596
1042211597 spin_lock_irqsave(&stream->fps_lock, flags);
1042311598 if (stream->frame_phase & CIF_CSI_FRAME0_READY)
10424
- stream->fps_stats.frm0_timestamp = ktime_get_ns();
11599
+ stream->fps_stats.frm0_timestamp = rkcif_time_get_ns(cif_dev);
1042511600 else if (stream->frame_phase & CIF_CSI_FRAME1_READY)
10426
- stream->fps_stats.frm1_timestamp = ktime_get_ns();
11601
+ stream->fps_stats.frm1_timestamp = rkcif_time_get_ns(cif_dev);
1042711602 spin_unlock_irqrestore(&stream->fps_lock, flags);
1042811603
1042911604 ret = rkcif_assign_new_buffer_oneframe(stream,
....@@ -10494,7 +11669,8 @@
1049411669 (cif_dev->dvp_sof_in_oneframe == 0)) {
1049511670 if ((intstat & (PRE_INF_FRAME_END | PST_INF_FRAME_END)) == 0x0) {
1049611671 if ((intstat & INTSTAT_ERR) == 0x0) {
10497
- rkcif_deal_sof(cif_dev);
11672
+ if (!stream->cur_skip_frame)
11673
+ rkcif_deal_sof(cif_dev);
1049811674 int_en = rkcif_read_register(cif_dev, CIF_REG_DVP_INTEN);
1049911675 int_en &= ~LINE_INT_EN;
1050011676 rkcif_write_register(cif_dev, CIF_REG_DVP_INTEN, int_en);