Skip to content

Commit cd83f84

Browse files
committed
ipu6: ipu-isys-video video node support for camera subdev
- ipu-isys-video.c: - control for enhanced node support by pipeline subdevices enumerating - inheritance of sub-device controls within same vc - s/g_parm ioctl ops to set/get fps on subdev - vidioc_enum_framesizes - implement remote sensor polling - vidioc_enum_frameintervals - implement remote sensor polling - vidioc_enum_fmt - select only sub-device formats - vidioc_s_fmt_vid_cap_mplane - set remote link format - vidioc_try_fmt_vid_cap_mplane - try remote format - link validation for isys entities intel#134 - metadata support for D4XX_META format - ipu-isys-csi2-be-soc.c: link validation intel#134 - CSI2 BE SOC has multiple formats on capture pads that's the point where it match external pad0 format which will inherit format from CSI-2 external entity. - ipu-isys-csi2.c: link validation intel#134 - inherit format from CSI-2 external entity. - ipu-isys.h: V4L2_CID_IPU_ENUMERATE_LINK - ipu-isys-video.h: ipu_isys_video.enum_link_state state for link enumeration by vc - ipu-psys.c: fix compilation issue on kernel 5.15 - Resloves ipu-psys: MODULE_IMPORT_NS(DMA_BUF) for kernel 5.15 intel#77 - ipu-isys-queue.c: - Move firmware bring-up from video open to queue start streaming. This will increase firmware stability for start-stop toggling without closing video node for all streams. - Move firmware shutdown from video close to queue stop streaming Improves recovery process for multithread processes that not close video handle. Signed-off-by: Dmitry Perchanov <[email protected]>
1 parent f8c0659 commit cd83f84

File tree

7 files changed

+809
-148
lines changed

7 files changed

+809
-148
lines changed

drivers/media/pci/intel/ipu-isys-csi2-be-soc.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,38 @@ static struct v4l2_subdev_ops csi2_be_soc_sd_ops = {
186186
.pad = &csi2_be_soc_sd_pad_ops,
187187
};
188188

189+
static int csi2_be_soc_link_validate(struct media_link *link)
190+
{
191+
struct media_pipeline *media_pipe;
192+
struct ipu_isys_pipeline *ip;
193+
struct v4l2_subdev *source_sd;
194+
struct v4l2_subdev *sink_sd;
195+
struct v4l2_subdev_format fmt = { 0 };
196+
197+
int rval;
198+
199+
if (!link->sink->entity || !link->source->entity)
200+
return -EINVAL;
201+
media_pipe = media_entity_pipeline(link->sink->entity);
202+
if (!media_pipe)
203+
return -EINVAL;
204+
205+
ip = to_ipu_isys_pipeline(media_pipe);
206+
source_sd = media_entity_to_v4l2_subdev(link->source->entity);
207+
sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);
208+
209+
fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
210+
211+
fmt.pad = CSI2_PAD_SOURCE;
212+
rval = v4l2_subdev_call(source_sd, pad, get_fmt, NULL, &fmt);
213+
214+
fmt.pad = CSI2_BE_SOC_PAD_SINK;
215+
rval = v4l2_subdev_call(sink_sd, pad, set_fmt, NULL, &fmt);
216+
return v4l2_subdev_link_validate(link);
217+
}
218+
189219
static struct media_entity_operations csi2_be_soc_entity_ops = {
220+
.link_validate = csi2_be_soc_link_validate,
190221
};
191222

192223
static void csi2_be_soc_set_ffmt(struct v4l2_subdev *sd,

drivers/media/pci/intel/ipu-isys-csi2.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ static int csi2_link_validate(struct media_link *link)
333333
struct ipu_isys_pipeline *ip;
334334
struct v4l2_subdev *source_sd;
335335
struct v4l2_subdev *sink_sd;
336+
struct v4l2_subdev_format fmt = { 0 };
336337

337338
int rval;
338339

@@ -350,8 +351,20 @@ static int csi2_link_validate(struct media_link *link)
350351
ipu_isys_video_add_capture_done(ip, csi2_capture_done);
351352
source_sd = media_entity_to_v4l2_subdev(link->source->entity);
352353
sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);
354+
353355
if (!source_sd)
354356
return -ENODEV;
357+
/* source is external entity, get it's format */
358+
fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
359+
fmt.pad = CSI2_PAD_SINK;
360+
rval = v4l2_subdev_call(source_sd, pad, get_fmt, NULL, &fmt);
361+
362+
/* set csi2 format for the same as external entity */
363+
rval = v4l2_subdev_call(sink_sd, pad, set_fmt, NULL, &fmt);
364+
365+
rval = v4l2_subdev_link_validate(link);
366+
if (rval)
367+
return rval;
355368

356369
if (strncmp(source_sd->name, IPU_ISYS_ENTITY_PREFIX,
357370
strlen(IPU_ISYS_ENTITY_PREFIX)) != 0) {

drivers/media/pci/intel/ipu-isys-queue.c

Lines changed: 145 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/module.h>
77
#include <linux/string.h>
88
#include <linux/delay.h>
9+
#include <linux/pm_runtime.h>
910

1011
#include <media/media-entity.h>
1112
#include <media/videobuf2-dma-contig.h>
@@ -817,6 +818,15 @@ static int __start_streaming(struct vb2_queue *q, unsigned int count)
817818

818819
mutex_unlock(&av->isys->stream_mutex);
819820

821+
if (av->pfmt->css_pixelformat){
822+
rval = aq->link_fmt_validate(aq);
823+
if (rval) {
824+
dev_err(&av->isys->adev->dev,
825+
"%s: link format validation failed (%d)\n",
826+
av->vdev.name, rval);
827+
goto out_unprepare_streaming;
828+
}
829+
}
820830
ip = to_ipu_isys_pipeline(media_entity_pipeline(&av->vdev.entity));
821831
pipe_av = container_of(ip, struct ipu_isys_video, ip);
822832
if (pipe_av != av) {
@@ -872,6 +882,7 @@ static int __start_streaming(struct vb2_queue *q, unsigned int count)
872882
mutex_lock(&av->mutex);
873883
}
874884

885+
out_unprepare_streaming:
875886
mutex_lock(&av->isys->stream_mutex);
876887
if (first)
877888
ipu_isys_video_prepare_streaming(av, 0);
@@ -883,12 +894,138 @@ static int __start_streaming(struct vb2_queue *q, unsigned int count)
883894
return rval;
884895
}
885896

897+
static int isys_fw_open(struct ipu_isys_video *av)
898+
{
899+
struct ipu_isys *isys = av->isys;
900+
struct ipu_bus_device *adev = to_ipu_bus_device(&isys->adev->dev);
901+
struct ipu_device *isp = adev->isp;
902+
int rval;
903+
const struct ipu_isys_internal_pdata *ipdata;
904+
905+
dev_warn(&isys->adev->dev, "%s:%d %s: enter\n",
906+
__func__, __LINE__, av->vdev.name);
907+
908+
mutex_lock(&isys->mutex);
909+
910+
if (isys->reset_needed || isp->flr_done) {
911+
mutex_unlock(&isys->mutex);
912+
dev_warn(&isys->adev->dev, "%s:%d %s: isys power cycle required\n",
913+
__func__, __LINE__, av->vdev.name);
914+
return -EIO;
915+
}
916+
mutex_unlock(&isys->mutex);
917+
918+
rval = pm_runtime_get_sync(&isys->adev->dev);
919+
if (rval < 0) {
920+
pm_runtime_put_noidle(&isys->adev->dev);
921+
return rval;
922+
}
923+
924+
mutex_lock(&isys->mutex);
925+
if (isys->video_opened++) {
926+
/* Already open */
927+
mutex_unlock(&isys->mutex);
928+
dev_warn(&isys->adev->dev, "%s:%d %s: Already open, exit %d\n",
929+
__func__, __LINE__, av->vdev.name, isys->video_opened);
930+
return 0;
931+
}
932+
933+
ipdata = isys->pdata->ipdata;
934+
ipu_configure_spc(adev->isp,
935+
&ipdata->hw_variant,
936+
IPU_CPD_PKG_DIR_ISYS_SERVER_IDX,
937+
isys->pdata->base, isys->pkg_dir,
938+
isys->pkg_dir_dma_addr);
939+
940+
/*
941+
* Buffers could have been left to wrong queue at last closure.
942+
* Move them now back to empty buffer queue.
943+
*/
944+
ipu_cleanup_fw_msg_bufs(isys);
945+
946+
if (isys->fwcom) {
947+
/*
948+
* Something went wrong in previous shutdown. As we are now
949+
* restarting isys we can safely delete old context.
950+
*/
951+
dev_err(&isys->adev->dev, "%s:%d %s Clearing old context\n",
952+
__func__, __LINE__, av->vdev.name);
953+
ipu_fw_isys_cleanup(isys);
954+
}
955+
956+
rval = ipu_fw_isys_init(av->isys, ipdata->num_parallel_streams);
957+
if (rval < 0)
958+
goto out_lib_init;
959+
960+
mutex_unlock(&isys->mutex);
961+
962+
dev_warn(&isys->adev->dev, "%s:%d %s: exit\n",
963+
__func__, __LINE__, av->vdev.name);
964+
return 0;
965+
966+
out_lib_init:
967+
isys->video_opened--;
968+
mutex_unlock(&isys->mutex);
969+
pm_runtime_put(&isys->adev->dev);
970+
971+
return rval;
972+
}
973+
974+
static int isys_fw_release(struct ipu_isys_video *av)
975+
{
976+
struct ipu_isys *isys = av->isys;
977+
int ret = 0;
978+
979+
dev_warn(&isys->adev->dev, "%s:%d %s: enter\n",
980+
__func__, __LINE__, av->vdev.name);
981+
mutex_lock(&isys->reset_mutex);
982+
while (isys->in_reset) {
983+
mutex_unlock(&isys->reset_mutex);
984+
dev_warn(&isys->adev->dev, "%s:%d %s: wait for reset\n",
985+
__func__, __LINE__, av->vdev.name);
986+
usleep_range(10000, 11000);
987+
mutex_lock(&isys->reset_mutex);
988+
}
989+
mutex_unlock(&isys->reset_mutex);
990+
991+
mutex_lock(&isys->mutex);
992+
dev_warn(&isys->adev->dev, "%s:%d %s: close fw video_opened: %d\n",
993+
__func__, __LINE__, av->vdev.name, isys->video_opened);
994+
if (isys->video_opened)
995+
isys->video_opened--;
996+
if (!isys->video_opened) {
997+
dev_warn(&isys->adev->dev, "%s:%d %s: close fw\n",
998+
__func__, __LINE__, av->vdev.name);
999+
ipu_fw_isys_close(isys);
1000+
1001+
if (isys->fwcom) {
1002+
isys->reset_needed = true;
1003+
ret = -EIO;
1004+
}
1005+
}
1006+
1007+
mutex_unlock(&isys->mutex);
1008+
1009+
if (isys->reset_needed)
1010+
pm_runtime_put_sync(&isys->adev->dev);
1011+
else
1012+
pm_runtime_put(&isys->adev->dev);
1013+
1014+
dev_warn(&isys->adev->dev, "%s:%d %s: exit\n",
1015+
__func__, __LINE__, av->vdev.name);
1016+
return ret;
1017+
}
1018+
8861019
static int start_streaming(struct vb2_queue *q, unsigned int count)
8871020
{
8881021
struct ipu_isys_queue *aq = vb2_queue_to_ipu_isys_queue(q);
8891022
struct ipu_isys_video *av = ipu_isys_queue_to_video(aq);
8901023
int rval;
8911024

1025+
rval = isys_fw_open(av);
1026+
if (rval < 0) {
1027+
dev_err(&av->isys->adev->dev, "isys_fw_open failed: %d\n", rval);
1028+
}
8921029
mutex_unlock(&av->mutex);
8931030
mutex_lock(&av->isys->reset_mutex);
8941031
while (av->isys->in_stop_streaming) {
@@ -903,7 +1040,8 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
9031040
mutex_lock(&av->mutex);
9041041

9051042
rval = __start_streaming(q, count);
906-
1043+
if (rval)
1044+
isys_fw_release(av);
9071045
return rval;
9081046
}
9091047

@@ -912,7 +1050,8 @@ static void reset_stop_streaming(struct ipu_isys_video *av)
9121050
struct ipu_isys_pipeline *ip = &av->ip;
9131051
struct ipu_isys_queue *aq = &av->aq;
9141052

915-
dev_dbg(&av->isys->adev->dev, "%s: stop streaming\n", av->vdev.name);
1053+
dev_warn(&av->isys->adev->dev, "%s():%d %s: stop streaming\n",
1054+
__func__, __LINE__, av->vdev.name);
9161055

9171056
mutex_lock(&av->isys->stream_mutex);
9181057
if (ip->nr_streaming == ip->nr_queues && ip->streaming)
@@ -932,7 +1071,8 @@ static int reset_start_streaming(struct ipu_isys_video *av)
9321071
unsigned long flags;
9331072
int rval;
9341073

935-
dev_dbg(&av->isys->adev->dev, "%s: start streaming\n", av->vdev.name);
1074+
dev_warn(&av->isys->adev->dev, "%s():%d %s: start streaming\n",
1075+
__func__, __LINE__, av->vdev.name);
9361076

9371077
spin_lock_irqsave(&aq->lock, flags);
9381078
while (!list_empty(&aq->active)) {
@@ -1171,7 +1311,8 @@ static void stop_streaming(struct vb2_queue *q)
11711311
mutex_lock(&av->isys->reset_mutex);
11721312
av->isys->in_stop_streaming = false;
11731313
mutex_unlock(&av->isys->reset_mutex);
1174-
1314+
if (0 == ip->nr_streaming)
1315+
isys_fw_release(av);
11751316
}
11761317

11771318
static unsigned int

0 commit comments

Comments
 (0)