Commit 47800bc4 authored by Sylwester Nawrocki's avatar Sylwester Nawrocki Committed by Mauro Carvalho Chehab

[media] s5p-fimc: Improved pipeline try format routine

Make the pipeline try format routine more generic to support any
number of subdevs in the pipeline, rather than hard coding it for
only a sensor, MIPI-CSIS and FIMC subdevs and the FIMC video node.
Signed-off-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 2bffebc1
...@@ -793,6 +793,21 @@ static int fimc_cap_enum_fmt_mplane(struct file *file, void *priv, ...@@ -793,6 +793,21 @@ static int fimc_cap_enum_fmt_mplane(struct file *file, void *priv,
return 0; return 0;
} }
static struct media_entity *fimc_pipeline_get_head(struct media_entity *me)
{
struct media_pad *pad = &me->pads[0];
while (!(pad->flags & MEDIA_PAD_FL_SOURCE)) {
pad = media_entity_remote_source(pad);
if (!pad)
break;
me = pad->entity;
pad = &me->pads[0];
}
return me;
}
/** /**
* fimc_pipeline_try_format - negotiate and/or set formats at pipeline * fimc_pipeline_try_format - negotiate and/or set formats at pipeline
* elements * elements
...@@ -808,19 +823,23 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx, ...@@ -808,19 +823,23 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx,
{ {
struct fimc_dev *fimc = ctx->fimc_dev; struct fimc_dev *fimc = ctx->fimc_dev;
struct v4l2_subdev *sd = fimc->pipeline.subdevs[IDX_SENSOR]; struct v4l2_subdev *sd = fimc->pipeline.subdevs[IDX_SENSOR];
struct v4l2_subdev *csis = fimc->pipeline.subdevs[IDX_CSIS];
struct v4l2_subdev_format sfmt; struct v4l2_subdev_format sfmt;
struct v4l2_mbus_framefmt *mf = &sfmt.format; struct v4l2_mbus_framefmt *mf = &sfmt.format;
struct fimc_fmt *ffmt = NULL; struct media_entity *me;
int ret, i = 0; struct fimc_fmt *ffmt;
struct media_pad *pad;
int ret, i = 1;
u32 fcc;
if (WARN_ON(!sd || !tfmt)) if (WARN_ON(!sd || !tfmt))
return -EINVAL; return -EINVAL;
memset(&sfmt, 0, sizeof(sfmt)); memset(&sfmt, 0, sizeof(sfmt));
sfmt.format = *tfmt; sfmt.format = *tfmt;
sfmt.which = set ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY; sfmt.which = set ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY;
me = fimc_pipeline_get_head(&sd->entity);
while (1) { while (1) {
ffmt = fimc_find_format(NULL, mf->code != 0 ? &mf->code : NULL, ffmt = fimc_find_format(NULL, mf->code != 0 ? &mf->code : NULL,
FMT_FLAGS_CAM, i++); FMT_FLAGS_CAM, i++);
...@@ -833,40 +852,52 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx, ...@@ -833,40 +852,52 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx,
} }
mf->code = tfmt->code = ffmt->mbus_code; mf->code = tfmt->code = ffmt->mbus_code;
ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &sfmt); /* set format on all pipeline subdevs */
if (ret) while (me != &fimc->vid_cap.subdev.entity) {
return ret; sd = media_entity_to_v4l2_subdev(me);
if (mf->code != tfmt->code) {
mf->code = 0; sfmt.pad = 0;
continue; ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &sfmt);
} if (ret)
if (mf->width != tfmt->width || mf->height != tfmt->height) { return ret;
u32 fcc = ffmt->fourcc;
tfmt->width = mf->width; if (me->pads[0].flags & MEDIA_PAD_FL_SINK) {
tfmt->height = mf->height; sfmt.pad = me->num_pads - 1;
ffmt = fimc_capture_try_format(ctx, mf->code = tfmt->code;
&tfmt->width, &tfmt->height, ret = v4l2_subdev_call(sd, pad, set_fmt, NULL,
NULL, &fcc, FIMC_SD_PAD_SOURCE); &sfmt);
if (ffmt && ffmt->mbus_code) if (ret)
mf->code = ffmt->mbus_code; return ret;
if (mf->width != tfmt->width || }
mf->height != tfmt->height)
continue; pad = media_entity_remote_source(&me->pads[sfmt.pad]);
tfmt->code = mf->code; if (!pad)
return -EINVAL;
me = pad->entity;
} }
if (csis)
ret = v4l2_subdev_call(csis, pad, set_fmt, NULL, &sfmt);
if (mf->code == tfmt->code && if (mf->code != tfmt->code)
mf->width == tfmt->width && mf->height == tfmt->height) continue;
break;
fcc = ffmt->fourcc;
tfmt->width = mf->width;
tfmt->height = mf->height;
ffmt = fimc_capture_try_format(ctx, &tfmt->width, &tfmt->height,
NULL, &fcc, FIMC_SD_PAD_SINK);
ffmt = fimc_capture_try_format(ctx, &tfmt->width, &tfmt->height,
NULL, &fcc, FIMC_SD_PAD_SOURCE);
if (ffmt && ffmt->mbus_code)
mf->code = ffmt->mbus_code;
if (mf->width != tfmt->width || mf->height != tfmt->height)
continue;
tfmt->code = mf->code;
break;
} }
if (fmt_id && ffmt) if (fmt_id && ffmt)
*fmt_id = ffmt; *fmt_id = ffmt;
*tfmt = *mf; *tfmt = *mf;
dbg("code: 0x%x, %dx%d, %p", mf->code, mf->width, mf->height, ffmt);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment