Commit 5964cbd8 authored by Steve Longerbeam's avatar Steve Longerbeam Committed by Mauro Carvalho Chehab

media: imx: Set capture compose rectangle in capture_device_set_format

The capture compose rectangle was not getting updated when setting
the source subdevice's source pad format. This causes the compose window
to be zero (or not updated) at stream start unless the capture device
format was set explicitly at the capture device node.

Fix by moving the calculation of the capture compose rectangle to
imx_media_mbus_fmt_to_pix_fmt(), and pass the rectangle to
imx_media_capture_device_set_format().

Fixes: 439d8186 ("media: imx: add capture compose rectangle")
Signed-off-by: default avatarSteve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 09714569
...@@ -912,6 +912,7 @@ static int prp_set_fmt(struct v4l2_subdev *sd, ...@@ -912,6 +912,7 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
const struct imx_media_pixfmt *cc; const struct imx_media_pixfmt *cc;
struct v4l2_pix_format vdev_fmt; struct v4l2_pix_format vdev_fmt;
struct v4l2_mbus_framefmt *fmt; struct v4l2_mbus_framefmt *fmt;
struct v4l2_rect vdev_compose;
int ret = 0; int ret = 0;
if (sdformat->pad >= PRPENCVF_NUM_PADS) if (sdformat->pad >= PRPENCVF_NUM_PADS)
...@@ -953,11 +954,11 @@ static int prp_set_fmt(struct v4l2_subdev *sd, ...@@ -953,11 +954,11 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
priv->cc[sdformat->pad] = cc; priv->cc[sdformat->pad] = cc;
/* propagate output pad format to capture device */ /* propagate output pad format to capture device */
imx_media_mbus_fmt_to_pix_fmt(&vdev_fmt, imx_media_mbus_fmt_to_pix_fmt(&vdev_fmt, &vdev_compose,
&priv->format_mbus[PRPENCVF_SRC_PAD], &priv->format_mbus[PRPENCVF_SRC_PAD],
priv->cc[PRPENCVF_SRC_PAD]); priv->cc[PRPENCVF_SRC_PAD]);
mutex_unlock(&priv->lock); mutex_unlock(&priv->lock);
imx_media_capture_device_set_format(vdev, &vdev_fmt); imx_media_capture_device_set_format(vdev, &vdev_fmt, &vdev_compose);
return 0; return 0;
out: out:
......
...@@ -205,7 +205,8 @@ static int capture_g_fmt_vid_cap(struct file *file, void *fh, ...@@ -205,7 +205,8 @@ static int capture_g_fmt_vid_cap(struct file *file, void *fh,
static int __capture_try_fmt_vid_cap(struct capture_priv *priv, static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
struct v4l2_subdev_format *fmt_src, struct v4l2_subdev_format *fmt_src,
struct v4l2_format *f) struct v4l2_format *f,
struct v4l2_rect *compose)
{ {
const struct imx_media_pixfmt *cc, *cc_src; const struct imx_media_pixfmt *cc, *cc_src;
...@@ -245,7 +246,8 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, ...@@ -245,7 +246,8 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
} }
} }
imx_media_mbus_fmt_to_pix_fmt(&f->fmt.pix, &fmt_src->format, cc); imx_media_mbus_fmt_to_pix_fmt(&f->fmt.pix, compose,
&fmt_src->format, cc);
return 0; return 0;
} }
...@@ -263,7 +265,7 @@ static int capture_try_fmt_vid_cap(struct file *file, void *fh, ...@@ -263,7 +265,7 @@ static int capture_try_fmt_vid_cap(struct file *file, void *fh,
if (ret) if (ret)
return ret; return ret;
return __capture_try_fmt_vid_cap(priv, &fmt_src, f); return __capture_try_fmt_vid_cap(priv, &fmt_src, f, NULL);
} }
static int capture_s_fmt_vid_cap(struct file *file, void *fh, static int capture_s_fmt_vid_cap(struct file *file, void *fh,
...@@ -271,6 +273,7 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh, ...@@ -271,6 +273,7 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
{ {
struct capture_priv *priv = video_drvdata(file); struct capture_priv *priv = video_drvdata(file);
struct v4l2_subdev_format fmt_src; struct v4l2_subdev_format fmt_src;
struct v4l2_rect compose;
int ret; int ret;
if (vb2_is_busy(&priv->q)) { if (vb2_is_busy(&priv->q)) {
...@@ -284,17 +287,14 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh, ...@@ -284,17 +287,14 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
if (ret) if (ret)
return ret; return ret;
ret = __capture_try_fmt_vid_cap(priv, &fmt_src, f); ret = __capture_try_fmt_vid_cap(priv, &fmt_src, f, &compose);
if (ret) if (ret)
return ret; return ret;
priv->vdev.fmt.fmt.pix = f->fmt.pix; priv->vdev.fmt.fmt.pix = f->fmt.pix;
priv->vdev.cc = imx_media_find_format(f->fmt.pix.pixelformat, priv->vdev.cc = imx_media_find_format(f->fmt.pix.pixelformat,
CS_SEL_ANY, true); CS_SEL_ANY, true);
priv->vdev.compose.left = 0; priv->vdev.compose = compose;
priv->vdev.compose.top = 0;
priv->vdev.compose.width = fmt_src.format.width;
priv->vdev.compose.height = fmt_src.format.height;
return 0; return 0;
} }
...@@ -655,7 +655,8 @@ static struct video_device capture_videodev = { ...@@ -655,7 +655,8 @@ static struct video_device capture_videodev = {
}; };
void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev, void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev,
struct v4l2_pix_format *pix) const struct v4l2_pix_format *pix,
const struct v4l2_rect *compose)
{ {
struct capture_priv *priv = to_capture_priv(vdev); struct capture_priv *priv = to_capture_priv(vdev);
...@@ -663,6 +664,7 @@ void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev, ...@@ -663,6 +664,7 @@ void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev,
priv->vdev.fmt.fmt.pix = *pix; priv->vdev.fmt.fmt.pix = *pix;
priv->vdev.cc = imx_media_find_format(pix->pixelformat, CS_SEL_ANY, priv->vdev.cc = imx_media_find_format(pix->pixelformat, CS_SEL_ANY,
true); true);
priv->vdev.compose = *compose;
mutex_unlock(&priv->mutex); mutex_unlock(&priv->mutex);
} }
EXPORT_SYMBOL_GPL(imx_media_capture_device_set_format); EXPORT_SYMBOL_GPL(imx_media_capture_device_set_format);
...@@ -768,10 +770,8 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) ...@@ -768,10 +770,8 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
} }
vdev->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; vdev->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, &vdev->compose,
&fmt_src.format, NULL); &fmt_src.format, NULL);
vdev->compose.width = fmt_src.format.width;
vdev->compose.height = fmt_src.format.height;
vdev->cc = imx_media_find_format(vdev->fmt.fmt.pix.pixelformat, vdev->cc = imx_media_find_format(vdev->fmt.fmt.pix.pixelformat,
CS_SEL_ANY, false); CS_SEL_ANY, false);
......
...@@ -1502,6 +1502,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd, ...@@ -1502,6 +1502,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
struct v4l2_pix_format vdev_fmt; struct v4l2_pix_format vdev_fmt;
struct v4l2_mbus_framefmt *fmt; struct v4l2_mbus_framefmt *fmt;
struct v4l2_rect *crop, *compose; struct v4l2_rect *crop, *compose;
struct v4l2_rect vdev_compose;
int ret; int ret;
if (sdformat->pad >= CSI_NUM_PADS) if (sdformat->pad >= CSI_NUM_PADS)
...@@ -1557,11 +1558,11 @@ static int csi_set_fmt(struct v4l2_subdev *sd, ...@@ -1557,11 +1558,11 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
priv->cc[sdformat->pad] = cc; priv->cc[sdformat->pad] = cc;
/* propagate IDMAC output pad format to capture device */ /* propagate IDMAC output pad format to capture device */
imx_media_mbus_fmt_to_pix_fmt(&vdev_fmt, imx_media_mbus_fmt_to_pix_fmt(&vdev_fmt, &vdev_compose,
&priv->format_mbus[CSI_SRC_PAD_IDMAC], &priv->format_mbus[CSI_SRC_PAD_IDMAC],
priv->cc[CSI_SRC_PAD_IDMAC]); priv->cc[CSI_SRC_PAD_IDMAC]);
mutex_unlock(&priv->lock); mutex_unlock(&priv->lock);
imx_media_capture_device_set_format(vdev, &vdev_fmt); imx_media_capture_device_set_format(vdev, &vdev_fmt, &vdev_compose);
return 0; return 0;
out: out:
......
...@@ -577,7 +577,8 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt, ...@@ -577,7 +577,8 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
EXPORT_SYMBOL_GPL(imx_media_fill_default_mbus_fields); EXPORT_SYMBOL_GPL(imx_media_fill_default_mbus_fields);
int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
struct v4l2_mbus_framefmt *mbus, struct v4l2_rect *compose,
const struct v4l2_mbus_framefmt *mbus,
const struct imx_media_pixfmt *cc) const struct imx_media_pixfmt *cc)
{ {
u32 width; u32 width;
...@@ -624,6 +625,17 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, ...@@ -624,6 +625,17 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
pix->sizeimage = cc->planar ? ((stride * pix->height * cc->bpp) >> 3) : pix->sizeimage = cc->planar ? ((stride * pix->height * cc->bpp) >> 3) :
stride * pix->height; stride * pix->height;
/*
* set capture compose rectangle, which is fixed to the
* source subdevice mbus format.
*/
if (compose) {
compose->left = 0;
compose->top = 0;
compose->width = mbus->width;
compose->height = mbus->height;
}
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(imx_media_mbus_fmt_to_pix_fmt); EXPORT_SYMBOL_GPL(imx_media_mbus_fmt_to_pix_fmt);
...@@ -635,13 +647,11 @@ int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image, ...@@ -635,13 +647,11 @@ int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image,
memset(image, 0, sizeof(*image)); memset(image, 0, sizeof(*image));
ret = imx_media_mbus_fmt_to_pix_fmt(&image->pix, mbus, NULL); ret = imx_media_mbus_fmt_to_pix_fmt(&image->pix, &image->rect,
mbus, NULL);
if (ret) if (ret)
return ret; return ret;
image->rect.width = mbus->width;
image->rect.height = mbus->height;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(imx_media_mbus_fmt_to_ipu_image); EXPORT_SYMBOL_GPL(imx_media_mbus_fmt_to_ipu_image);
......
...@@ -180,7 +180,8 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt, ...@@ -180,7 +180,8 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
struct v4l2_mbus_framefmt *fmt, struct v4l2_mbus_framefmt *fmt,
bool ic_route); bool ic_route);
int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
struct v4l2_mbus_framefmt *mbus, struct v4l2_rect *compose,
const struct v4l2_mbus_framefmt *mbus,
const struct imx_media_pixfmt *cc); const struct imx_media_pixfmt *cc);
int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image, int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image,
struct v4l2_mbus_framefmt *mbus); struct v4l2_mbus_framefmt *mbus);
...@@ -261,7 +262,8 @@ void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev); ...@@ -261,7 +262,8 @@ void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev);
struct imx_media_buffer * struct imx_media_buffer *
imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev); imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev);
void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev, void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev,
struct v4l2_pix_format *pix); const struct v4l2_pix_format *pix,
const struct v4l2_rect *compose);
void imx_media_capture_device_error(struct imx_media_video_dev *vdev); void imx_media_capture_device_error(struct imx_media_video_dev *vdev);
/* subdev group ids */ /* subdev group ids */
......
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