hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/platform/rockchip/cif/dev.c
....@@ -20,7 +20,6 @@
2020 #include <media/videobuf2-dma-contig.h>
2121 #include <media/v4l2-fwnode.h>
2222 #include <linux/iommu.h>
23
-#include <dt-bindings/soc/rockchip-system-status.h>
2423 #include <soc/rockchip/rockchip-system-status.h>
2524 #include <linux/io.h>
2625 #include <linux/mfd/syscon.h>
....@@ -644,12 +643,16 @@
644643 }
645644 }
646645 if (index < CIF_REG_INDEX_MAX) {
647
- if (index == CIF_REG_DVP_CTRL || reg->offset != 0x0)
646
+ if (index == CIF_REG_DVP_CTRL || reg->offset != 0x0) {
648647 write_cif_reg(base, reg->offset + csi_offset, val);
649
- else
648
+ v4l2_dbg(4, rkcif_debug, &dev->v4l2_dev,
649
+ "write reg[0x%x]:0x%x!!!\n",
650
+ reg->offset + csi_offset, val);
651
+ } else {
650652 v4l2_dbg(1, rkcif_debug, &dev->v4l2_dev,
651653 "write reg[%d]:0x%x failed, maybe useless!!!\n",
652654 index, val);
655
+ }
653656 }
654657 }
655658
....@@ -681,6 +684,9 @@
681684 reg_val = read_cif_reg(base, reg->offset + csi_offset);
682685 reg_val |= val;
683686 write_cif_reg(base, reg->offset + csi_offset, reg_val);
687
+ v4l2_dbg(4, rkcif_debug, &dev->v4l2_dev,
688
+ "write or reg[0x%x]:0x%x!!!\n",
689
+ reg->offset + csi_offset, val);
684690 } else {
685691 v4l2_dbg(1, rkcif_debug, &dev->v4l2_dev,
686692 "write reg[%d]:0x%x with OR failed, maybe useless!!!\n",
....@@ -717,6 +723,9 @@
717723 reg_val = read_cif_reg(base, reg->offset + csi_offset);
718724 reg_val &= val;
719725 write_cif_reg(base, reg->offset + csi_offset, reg_val);
726
+ v4l2_dbg(4, rkcif_debug, &dev->v4l2_dev,
727
+ "write and reg[0x%x]:0x%x!!!\n",
728
+ reg->offset + csi_offset, val);
720729 } else {
721730 v4l2_dbg(1, rkcif_debug, &dev->v4l2_dev,
722731 "write reg[%d]:0x%x with OR failed, maybe useless!!!\n",
....@@ -1124,6 +1133,7 @@
11241133 cif_dev->reset_watchdog_timer.is_triggered = false;
11251134 cif_dev->reset_watchdog_timer.is_running = false;
11261135 cif_dev->err_state_work.last_timestamp = 0;
1136
+ cif_dev->is_toisp_reset = false;
11271137 for (i = 0; i < cif_dev->num_channels; i++)
11281138 cif_dev->reset_watchdog_timer.last_buf_wakeup_cnt[i] = 0;
11291139 cif_dev->reset_watchdog_timer.run_cnt = 0;
....@@ -1208,6 +1218,7 @@
12081218 cif_dev->is_start_hdr = true;
12091219 cif_dev->reset_watchdog_timer.is_triggered = false;
12101220 cif_dev->reset_watchdog_timer.is_running = false;
1221
+ cif_dev->is_toisp_reset = false;
12111222 for (i = 0; i < cif_dev->num_channels; i++)
12121223 cif_dev->reset_watchdog_timer.last_buf_wakeup_cnt[i] = 0;
12131224 cif_dev->reset_watchdog_timer.run_cnt = 0;
....@@ -1561,16 +1572,6 @@
15611572
15621573 if (!completion_done(&dev->cmpl_ntf))
15631574 complete(&dev->cmpl_ntf);
1564
- if (dev->active_sensor &&
1565
- (dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_DPHY ||
1566
- dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_CPHY)) {
1567
- ret = v4l2_subdev_call(dev->active_sensor->sd,
1568
- core, ioctl,
1569
- RKCIF_CMD_SET_CSI_IDX,
1570
- &dev->csi_host_idx);
1571
- if (ret)
1572
- v4l2_err(&dev->v4l2_dev, "set csi idx %d fail\n", dev->csi_host_idx);
1573
- }
15741575 v4l2_info(&dev->v4l2_dev, "Async subdev notifier completed\n");
15751576
15761577 return ret;
....@@ -1908,6 +1909,32 @@
19081909 INIT_WORK(&dev->reset_work.work, rkcif_reset_work);
19091910 }
19101911
1912
+void rkcif_set_sensor_stream(struct work_struct *work)
1913
+{
1914
+ struct rkcif_sensor_work *sensor_work = container_of(work,
1915
+ struct rkcif_sensor_work,
1916
+ work);
1917
+ struct rkcif_device *cif_dev = container_of(sensor_work,
1918
+ struct rkcif_device,
1919
+ sensor_work);
1920
+
1921
+ v4l2_subdev_call(cif_dev->terminal_sensor.sd,
1922
+ core, ioctl,
1923
+ RKMODULE_SET_QUICK_STREAM,
1924
+ &sensor_work->on);
1925
+}
1926
+
1927
+static void rkcif_deal_err_intr(struct work_struct *work)
1928
+{
1929
+ struct delayed_work *dwork = to_delayed_work(work);
1930
+ struct rkcif_device *cif_dev = container_of(dwork,
1931
+ struct rkcif_device,
1932
+ work_deal_err);
1933
+
1934
+ cif_dev->intr_mask |= CSI_BANDWIDTH_LACK_V1;
1935
+ rkcif_write_register_or(cif_dev, CIF_REG_MIPI_LVDS_INTEN, CSI_BANDWIDTH_LACK_V1);
1936
+}
1937
+
19111938 int rkcif_plat_init(struct rkcif_device *cif_dev, struct device_node *node, int inf_id)
19121939 {
19131940 struct device *dev = cif_dev->dev;
....@@ -1927,6 +1954,7 @@
19271954 atomic_set(&cif_dev->pipe.power_cnt, 0);
19281955 atomic_set(&cif_dev->pipe.stream_cnt, 0);
19291956 atomic_set(&cif_dev->power_cnt, 0);
1957
+ atomic_set(&cif_dev->streamoff_cnt, 0);
19301958 cif_dev->is_start_hdr = false;
19311959 cif_dev->pipe.open = rkcif_pipeline_open;
19321960 cif_dev->pipe.close = rkcif_pipeline_close;
....@@ -1940,10 +1968,15 @@
19401968 cif_dev->early_line = 0;
19411969 cif_dev->is_thunderboot = false;
19421970 cif_dev->rdbk_debug = 0;
1971
+
1972
+ cif_dev->resume_mode = 0;
1973
+ memset(&cif_dev->channels[0].capture_info, 0, sizeof(cif_dev->channels[0].capture_info));
19431974 if (cif_dev->chip_id == CHIP_RV1126_CIF_LITE)
19441975 cif_dev->isr_hdl = rkcif_irq_lite_handler;
19451976
19461977 INIT_WORK(&cif_dev->err_state_work.work, rkcif_err_print_work);
1978
+ INIT_WORK(&cif_dev->sensor_work.work, rkcif_set_sensor_stream);
1979
+ INIT_DELAYED_WORK(&cif_dev->work_deal_err, rkcif_deal_err_intr);
19471980
19481981 if (cif_dev->chip_id < CHIP_RV1126_CIF) {
19491982 if (cif_dev->inf_id == RKCIF_MIPI_LVDS) {
....@@ -1997,6 +2030,17 @@
19972030 cif_dev->csi_host_idx = of_alias_get_id(node, "rkcif_mipi_lvds");
19982031 if (cif_dev->csi_host_idx < 0 || cif_dev->csi_host_idx > 5)
19992032 cif_dev->csi_host_idx = 0;
2033
+ if (cif_dev->hw_dev->is_rk3588s2) {
2034
+ if (cif_dev->csi_host_idx == 0)
2035
+ cif_dev->csi_host_idx = 2;
2036
+ else if (cif_dev->csi_host_idx == 2)
2037
+ cif_dev->csi_host_idx = 4;
2038
+ else if (cif_dev->csi_host_idx == 3)
2039
+ cif_dev->csi_host_idx = 5;
2040
+ v4l2_info(&cif_dev->v4l2_dev, "rk3588s2 attach to mipi%d\n",
2041
+ cif_dev->csi_host_idx);
2042
+ }
2043
+ cif_dev->csi_host_idx_def = cif_dev->csi_host_idx;
20002044 cif_dev->media_dev.dev = dev;
20012045 v4l2_dev = &cif_dev->v4l2_dev;
20022046 v4l2_dev->mdev = &cif_dev->media_dev;
....@@ -2106,6 +2150,8 @@
21062150 struct resource r;
21072151 int ret;
21082152
2153
+ cif_dev->is_thunderboot = false;
2154
+ cif_dev->is_rtt_suspend = false;
21092155 /* Get reserved memory region from Device-tree */
21102156 np = of_parse_phandle(dev->of_node, "memory-region-thunderboot", 0);
21112157 if (!np) {
....@@ -2121,7 +2167,14 @@
21212167
21222168 cif_dev->resmem_pa = r.start;
21232169 cif_dev->resmem_size = resource_size(&r);
2124
- cif_dev->is_thunderboot = true;
2170
+ cif_dev->resmem_addr = dma_map_single(dev, phys_to_virt(r.start),
2171
+ sizeof(struct rkisp_thunderboot_resmem_head),
2172
+ DMA_BIDIRECTIONAL);
2173
+
2174
+ if (device_property_read_bool(dev, "rtt-suspend"))
2175
+ cif_dev->is_rtt_suspend = true;
2176
+ if (IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP))
2177
+ cif_dev->is_thunderboot = true;
21252178 dev_info(dev, "Allocated reserved memory, paddr: 0x%x, size 0x%x\n",
21262179 (u32)cif_dev->resmem_pa,
21272180 (u32)cif_dev->resmem_size);
....@@ -2159,7 +2212,9 @@
21592212 if (sysfs_create_group(&pdev->dev.kobj, &dev_attr_grp))
21602213 return -ENODEV;
21612214
2162
- rkcif_attach_hw(cif_dev);
2215
+ ret = rkcif_attach_hw(cif_dev);
2216
+ if (ret)
2217
+ return ret;
21632218
21642219 rkcif_parse_dts(cif_dev);
21652220
....@@ -2194,6 +2249,22 @@
21942249 sysfs_remove_group(&pdev->dev.kobj, &dev_attr_grp);
21952250 del_timer_sync(&cif_dev->reset_watchdog_timer.timer);
21962251
2252
+ return 0;
2253
+}
2254
+
2255
+static int __maybe_unused rkcif_sleep_suspend(struct device *dev)
2256
+{
2257
+ struct rkcif_device *cif_dev = dev_get_drvdata(dev);
2258
+
2259
+ rkcif_stream_suspend(cif_dev, RKCIF_RESUME_CIF);
2260
+ return 0;
2261
+}
2262
+
2263
+static int __maybe_unused rkcif_sleep_resume(struct device *dev)
2264
+{
2265
+ struct rkcif_device *cif_dev = dev_get_drvdata(dev);
2266
+
2267
+ rkcif_stream_resume(cif_dev, RKCIF_RESUME_CIF);
21972268 return 0;
21982269 }
21992270
....@@ -2267,8 +2338,7 @@
22672338 #endif
22682339
22692340 static const struct dev_pm_ops rkcif_plat_pm_ops = {
2270
- SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
2271
- pm_runtime_force_resume)
2341
+ SET_SYSTEM_SLEEP_PM_OPS(rkcif_sleep_suspend, rkcif_sleep_resume)
22722342 SET_RUNTIME_PM_OPS(rkcif_runtime_suspend, rkcif_runtime_resume, NULL)
22732343 };
22742344