Skip to content

Commit 0b09f98

Browse files
bingbucaomchehab
authored andcommitted
media: Revert "media: staging/intel-ipu3: make imgu use fixed running mode"
This reverts commit e878742. Imgu should still keep the capability and flexibility to allow user to run 2 video pipes, as the user may use the video pipe to capture still frames with less system load and power than still pipe. Suggested-by: Tomasz Figa <[email protected]> Signed-off-by: Bingbu Cao <[email protected]> Signed-off-by: Sakari Ailus <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent a03003c commit 0b09f98

File tree

4 files changed

+77
-12
lines changed

4 files changed

+77
-12
lines changed

Documentation/media/v4l-drivers/ipu3.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ The IPU3 ImgU pipelines can be configured using the Media Controller, defined at
234234
Firmware binary selection
235235
-------------------------
236236

237-
The firmware binary is selected according to the running mode of imgu. There are
238-
2 modes are available - "video" and "still". "ipu3-imgu video" are running under
239-
"video" mode and "ipu3-imgu still" is running under "still" mode.
237+
The firmware binary is selected using the V4L2_CID_INTEL_IPU3_MODE, currently
238+
defined in drivers/staging/media/ipu3/include/intel-ipu3.h . "VIDEO" and "STILL"
239+
modes are available.
240240

241241
Processing the image in raw Bayer format
242242
----------------------------------------

drivers/staging/media/ipu3/include/intel-ipu3.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#define V4L2_META_FMT_IPU3_PARAMS v4l2_fourcc('i', 'p', '3', 'p') /* IPU3 processing parameters */
1313
#define V4L2_META_FMT_IPU3_STAT_3A v4l2_fourcc('i', 'p', '3', 's') /* IPU3 3A statistics */
1414

15+
/* from include/uapi/linux/v4l2-controls.h */
16+
#define V4L2_CID_INTEL_IPU3_BASE (V4L2_CID_USER_BASE + 0x10c0)
17+
#define V4L2_CID_INTEL_IPU3_MODE (V4L2_CID_INTEL_IPU3_BASE + 1)
18+
1519
/******************* ipu3_uapi_stats_3a *******************/
1620

1721
#define IPU3_UAPI_MAX_STRIPES 2

drivers/staging/media/ipu3/ipu3-v4l2.c

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ static int imgu_subdev_s_stream(struct v4l2_subdev *sd, int enable)
6767
struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe];
6868

6969
dev_dbg(dev, "%s %d for pipe %u", __func__, enable, pipe);
70+
/* grab ctrl after streamon and return after off */
71+
v4l2_ctrl_grab(imgu_sd->ctrl, enable);
7072

7173
if (!enable) {
7274
imgu_sd->active = false;
@@ -94,7 +96,7 @@ static int imgu_subdev_s_stream(struct v4l2_subdev *sd, int enable)
9496
if (imgu_pipe->nodes[IMGU_NODE_VF].enabled)
9597
css_pipe->vf_output_en = true;
9698

97-
if (imgu_sd->running_mode == IPU3_RUNNING_MODE_VIDEO)
99+
if (atomic_read(&imgu_sd->running_mode) == IPU3_RUNNING_MODE_VIDEO)
98100
css_pipe->pipe_id = IPU3_CSS_PIPE_ID_VIDEO;
99101
else
100102
css_pipe->pipe_id = IPU3_CSS_PIPE_ID_CAPTURE;
@@ -666,7 +668,7 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node,
666668
if (imgu_pipe->nodes[IMGU_NODE_VF].enabled)
667669
css_pipe->vf_output_en = true;
668670

669-
if (imgu_sd->running_mode == IPU3_RUNNING_MODE_VIDEO)
671+
if (atomic_read(&imgu_sd->running_mode) == IPU3_RUNNING_MODE_VIDEO)
670672
css_pipe->pipe_id = IPU3_CSS_PIPE_ID_VIDEO;
671673
else
672674
css_pipe->pipe_id = IPU3_CSS_PIPE_ID_CAPTURE;
@@ -897,6 +899,11 @@ static struct v4l2_subdev_internal_ops imgu_subdev_internal_ops = {
897899
.open = imgu_subdev_open,
898900
};
899901

902+
static const struct v4l2_subdev_core_ops imgu_subdev_core_ops = {
903+
.subscribe_event = v4l2_ctrl_subdev_subscribe_event,
904+
.unsubscribe_event = v4l2_event_subdev_unsubscribe,
905+
};
906+
900907
static const struct v4l2_subdev_video_ops imgu_subdev_video_ops = {
901908
.s_stream = imgu_subdev_s_stream,
902909
};
@@ -910,6 +917,7 @@ static const struct v4l2_subdev_pad_ops imgu_subdev_pad_ops = {
910917
};
911918

912919
static const struct v4l2_subdev_ops imgu_subdev_ops = {
920+
.core = &imgu_subdev_core_ops,
913921
.video = &imgu_subdev_video_ops,
914922
.pad = &imgu_subdev_pad_ops,
915923
};
@@ -1003,6 +1011,44 @@ static const struct v4l2_ioctl_ops imgu_v4l2_meta_ioctl_ops = {
10031011
.vidioc_expbuf = vb2_ioctl_expbuf,
10041012
};
10051013

1014+
static int imgu_sd_s_ctrl(struct v4l2_ctrl *ctrl)
1015+
{
1016+
struct imgu_v4l2_subdev *imgu_sd =
1017+
container_of(ctrl->handler, struct imgu_v4l2_subdev, ctrl_handler);
1018+
struct imgu_device *imgu = v4l2_get_subdevdata(&imgu_sd->subdev);
1019+
struct device *dev = &imgu->pci_dev->dev;
1020+
1021+
dev_dbg(dev, "set val %d to ctrl 0x%8x for subdev %u",
1022+
ctrl->val, ctrl->id, imgu_sd->pipe);
1023+
1024+
switch (ctrl->id) {
1025+
case V4L2_CID_INTEL_IPU3_MODE:
1026+
atomic_set(&imgu_sd->running_mode, ctrl->val);
1027+
return 0;
1028+
default:
1029+
return -EINVAL;
1030+
}
1031+
}
1032+
1033+
static const struct v4l2_ctrl_ops imgu_subdev_ctrl_ops = {
1034+
.s_ctrl = imgu_sd_s_ctrl,
1035+
};
1036+
1037+
static const char * const imgu_ctrl_mode_strings[] = {
1038+
"Video mode",
1039+
"Still mode",
1040+
};
1041+
1042+
static const struct v4l2_ctrl_config imgu_subdev_ctrl_mode = {
1043+
.ops = &imgu_subdev_ctrl_ops,
1044+
.id = V4L2_CID_INTEL_IPU3_MODE,
1045+
.name = "IPU3 Pipe Mode",
1046+
.type = V4L2_CTRL_TYPE_MENU,
1047+
.max = ARRAY_SIZE(imgu_ctrl_mode_strings) - 1,
1048+
.def = IPU3_RUNNING_MODE_VIDEO,
1049+
.qmenu = imgu_ctrl_mode_strings,
1050+
};
1051+
10061052
/******************** Framework registration ********************/
10071053

10081054
/* helper function to config node's video properties */
@@ -1048,6 +1094,7 @@ static int imgu_v4l2_subdev_register(struct imgu_device *imgu,
10481094
unsigned int pipe)
10491095
{
10501096
int i, r;
1097+
struct v4l2_ctrl_handler *hdl = &imgu_sd->ctrl_handler;
10511098
struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe];
10521099

10531100
/* Initialize subdev media entity */
@@ -1068,12 +1115,21 @@ static int imgu_v4l2_subdev_register(struct imgu_device *imgu,
10681115
v4l2_subdev_init(&imgu_sd->subdev, &imgu_subdev_ops);
10691116
imgu_sd->subdev.entity.function = MEDIA_ENT_F_PROC_VIDEO_STATISTICS;
10701117
imgu_sd->subdev.internal_ops = &imgu_subdev_internal_ops;
1071-
imgu_sd->subdev.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
1118+
imgu_sd->subdev.flags = V4L2_SUBDEV_FL_HAS_DEVNODE |
1119+
V4L2_SUBDEV_FL_HAS_EVENTS;
10721120
snprintf(imgu_sd->subdev.name, sizeof(imgu_sd->subdev.name),
1073-
"%s %s", IMGU_NAME, pipe ? "still" : "video");
1121+
"%s %u", IMGU_NAME, pipe);
10741122
v4l2_set_subdevdata(&imgu_sd->subdev, imgu);
1075-
imgu_sd->running_mode =
1076-
pipe ? IPU3_RUNNING_MODE_STILL : IPU3_RUNNING_MODE_VIDEO;
1123+
atomic_set(&imgu_sd->running_mode, IPU3_RUNNING_MODE_VIDEO);
1124+
v4l2_ctrl_handler_init(hdl, 1);
1125+
imgu_sd->subdev.ctrl_handler = hdl;
1126+
imgu_sd->ctrl = v4l2_ctrl_new_custom(hdl, &imgu_subdev_ctrl_mode, NULL);
1127+
if (hdl->error) {
1128+
r = hdl->error;
1129+
dev_err(&imgu->pci_dev->dev,
1130+
"failed to create subdev v4l2 ctrl with err %d", r);
1131+
goto fail_subdev;
1132+
}
10771133
r = v4l2_device_register_subdev(&imgu->v4l2_dev, &imgu_sd->subdev);
10781134
if (r) {
10791135
dev_err(&imgu->pci_dev->dev,
@@ -1085,6 +1141,7 @@ static int imgu_v4l2_subdev_register(struct imgu_device *imgu,
10851141
return 0;
10861142

10871143
fail_subdev:
1144+
v4l2_ctrl_handler_free(imgu_sd->subdev.ctrl_handler);
10881145
media_entity_cleanup(&imgu_sd->subdev.entity);
10891146

10901147
return r;
@@ -1179,8 +1236,8 @@ static int imgu_v4l2_node_setup(struct imgu_device *imgu, unsigned int pipe,
11791236
}
11801237

11811238
/* Initialize vdev */
1182-
snprintf(vdev->name, sizeof(vdev->name), "%s %s %s",
1183-
IMGU_NAME, pipe ? "still" : "video", node->name);
1239+
snprintf(vdev->name, sizeof(vdev->name), "%s %u %s",
1240+
IMGU_NAME, pipe, node->name);
11841241
vdev->release = video_device_release_empty;
11851242
vdev->fops = &imgu_v4l2_fops;
11861243
vdev->lock = &node->lock;
@@ -1255,6 +1312,7 @@ static void imgu_v4l2_subdev_cleanup(struct imgu_device *imgu, unsigned int i)
12551312
struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[i];
12561313

12571314
v4l2_device_unregister_subdev(&imgu_pipe->imgu_sd.subdev);
1315+
v4l2_ctrl_handler_free(imgu_pipe->imgu_sd.subdev.ctrl_handler);
12581316
media_entity_cleanup(&imgu_pipe->imgu_sd.subdev.entity);
12591317
}
12601318

drivers/staging/media/ipu3/ipu3.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/iova.h>
88
#include <linux/pci.h>
99

10+
#include <media/v4l2-ctrls.h>
1011
#include <media/v4l2-device.h>
1112
#include <media/videobuf2-dma-sg.h>
1213

@@ -95,7 +96,9 @@ struct imgu_v4l2_subdev {
9596
struct v4l2_rect bds; /* bayer-domain scaled resolution*/
9697
struct v4l2_rect gdc; /* gdc output resolution */
9798
} rect;
98-
unsigned int running_mode;
99+
struct v4l2_ctrl_handler ctrl_handler;
100+
struct v4l2_ctrl *ctrl;
101+
atomic_t running_mode;
99102
bool active;
100103
};
101104

0 commit comments

Comments
 (0)