From 7d1860ccdd180549b0c7d89996d5c555d80cd2e8 Mon Sep 17 00:00:00 2001 From: Zefa Chen Date: Sat, 20 Aug 2022 19:17:34 +0800 Subject: [PATCH] media: rockchip: vicap add sensor streaming protection for thunderboot Signed-off-by: Zefa Chen Change-Id: Iabfaf61c8ffac8d97712701ff96a84d091ab1117 --- drivers/media/platform/rockchip/cif/dev.c | 32 ++++++++++++++++++++--- drivers/media/platform/rockchip/cif/dev.h | 2 ++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/rockchip/cif/dev.c b/drivers/media/platform/rockchip/cif/dev.c index fa85aed2f5c1..607526575771 100644 --- a/drivers/media/platform/rockchip/cif/dev.c +++ b/drivers/media/platform/rockchip/cif/dev.c @@ -1049,6 +1049,13 @@ static void rkcif_set_sensor_streamon_in_sync_mode(struct rkcif_device *cif_dev) mutex_unlock(&hw->dev_lock); } +static void rkcif_sensor_streaming_cb(void *data) +{ + struct v4l2_subdev *subdevs = (struct v4l2_subdev *)data; + + v4l2_subdev_call(subdevs, video, s_stream, 1); +} + /* * stream-on order: isp_subdev, mipi dphy, sensor * stream-off order: mipi dphy, sensor, isp_subdev @@ -1057,7 +1064,7 @@ static int rkcif_pipeline_set_stream(struct rkcif_pipeline *p, bool on) { struct rkcif_device *cif_dev = container_of(p, struct rkcif_device, pipe); bool can_be_set = false; - int i, ret; + int i, ret = 0; if (cif_dev->hdr.hdr_mode == NO_HDR || cif_dev->hdr.hdr_mode == HDR_COMPR) { if ((on && atomic_inc_return(&p->stream_cnt) > 1) || @@ -1086,7 +1093,16 @@ static int rkcif_pipeline_set_stream(struct rkcif_pipeline *p, bool on) /* phy -> sensor */ for (i = 0; i < p->num_subdevs; i++) { - ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on); + if (p->subdevs[i] == cif_dev->terminal_sensor.sd && + on && + cif_dev->is_thunderboot && + !rk_tb_mcu_is_done()) { + cif_dev->tb_client.data = p->subdevs[i]; + cif_dev->tb_client.cb = rkcif_sensor_streaming_cb; + rk_tb_client_register_cb(&cif_dev->tb_client); + } else { + ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on); + } if (on && ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) goto err_stream_off; } @@ -1150,8 +1166,16 @@ static int rkcif_pipeline_set_stream(struct rkcif_pipeline *p, bool on) /* phy -> sensor */ for (i = 0; i < p->num_subdevs; i++) { - ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on); - + if (p->subdevs[i] == cif_dev->terminal_sensor.sd && + on && + cif_dev->is_thunderboot && + !rk_tb_mcu_is_done()) { + cif_dev->tb_client.data = p->subdevs[i]; + cif_dev->tb_client.cb = rkcif_sensor_streaming_cb; + rk_tb_client_register_cb(&cif_dev->tb_client); + } else { + ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on); + } if (on && ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) goto err_stream_off; } diff --git a/drivers/media/platform/rockchip/cif/dev.h b/drivers/media/platform/rockchip/cif/dev.h index 46477f8a1511..edcb6690f7b4 100644 --- a/drivers/media/platform/rockchip/cif/dev.h +++ b/drivers/media/platform/rockchip/cif/dev.h @@ -18,6 +18,7 @@ #include #include #include +#include #include "regs.h" #include "version.h" @@ -813,6 +814,7 @@ struct rkcif_device { struct csi2_dphy_hw *dphy_hw; phys_addr_t resmem_pa; size_t resmem_size; + struct rk_tb_client tb_client; bool is_start_hdr; bool reset_work_cancel; bool iommu_en;