Commit 08415820 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

media: staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into imx7_csi

Now that the driver doesn't use any helper that relies on the
imx_media_video_dev structure anymore, merge its fields directly in the
imx7_csi structure. Update all the users accordingly, and drop the list
field that isn't used by the driver.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: default avatarRui Miguel Silva <rmfrfs@gmail.com>
Tested-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 1f55211b
...@@ -212,9 +212,13 @@ struct imx7_csi { ...@@ -212,9 +212,13 @@ struct imx7_csi {
const struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM]; const struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM];
/* Video device */ /* Video device */
struct imx_media_video_dev vdev; /* Video device */ struct video_device *vdev; /* Video device */
struct media_pad vdev_pad; /* Video device pad */ struct media_pad vdev_pad; /* Video device pad */
struct v4l2_pix_format vdev_fmt; /* The user format */
const struct imx_media_pixfmt *vdev_cc;
struct v4l2_rect vdev_compose; /* The compose rectangle */
struct mutex vdev_mutex; /* Protect vdev operations */ struct mutex vdev_mutex; /* Protect vdev operations */
struct vb2_queue q; /* The videobuf2 queue */ struct vb2_queue q; /* The videobuf2 queue */
...@@ -413,11 +417,10 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi, ...@@ -413,11 +417,10 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi,
static int imx7_csi_dma_setup(struct imx7_csi *csi) static int imx7_csi_dma_setup(struct imx7_csi *csi)
{ {
struct imx_media_video_dev *vdev = &csi->vdev;
int ret; int ret;
ret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf, ret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf,
vdev->fmt.sizeimage); csi->vdev_fmt.sizeimage);
if (ret < 0) { if (ret < 0) {
v4l2_warn(&csi->sd, "consider increasing the CMA area\n"); v4l2_warn(&csi->sd, "consider increasing the CMA area\n");
return ret; return ret;
...@@ -464,8 +467,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi) ...@@ -464,8 +467,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)
static void imx7_csi_configure(struct imx7_csi *csi) static void imx7_csi_configure(struct imx7_csi *csi)
{ {
struct imx_media_video_dev *vdev = &csi->vdev; struct v4l2_pix_format *out_pix = &csi->vdev_fmt;
struct v4l2_pix_format *out_pix = &vdev->fmt;
int width = out_pix->width; int width = out_pix->width;
u32 stride = 0; u32 stride = 0;
u32 cr3 = BIT_FRMCNT_RST; u32 cr3 = BIT_FRMCNT_RST;
...@@ -664,14 +666,13 @@ static void imx7_csi_error_recovery(struct imx7_csi *csi) ...@@ -664,14 +666,13 @@ static void imx7_csi_error_recovery(struct imx7_csi *csi)
static void imx7_csi_vb2_buf_done(struct imx7_csi *csi) static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)
{ {
struct imx_media_video_dev *vdev = &csi->vdev;
struct imx7_csi_vb2_buffer *done, *next; struct imx7_csi_vb2_buffer *done, *next;
struct vb2_buffer *vb; struct vb2_buffer *vb;
dma_addr_t phys; dma_addr_t phys;
done = csi->active_vb2_buf[csi->buf_num]; done = csi->active_vb2_buf[csi->buf_num];
if (done) { if (done) {
done->vbuf.field = vdev->fmt.field; done->vbuf.field = csi->vdev_fmt.field;
done->vbuf.sequence = csi->frame_sequence; done->vbuf.sequence = csi->frame_sequence;
vb = &done->vbuf.vb2_buf; vb = &done->vbuf.vb2_buf;
vb->timestamp = ktime_get_ns(); vb->timestamp = ktime_get_ns();
...@@ -829,7 +830,7 @@ static int imx7_csi_video_g_fmt_vid_cap(struct file *file, void *fh, ...@@ -829,7 +830,7 @@ static int imx7_csi_video_g_fmt_vid_cap(struct file *file, void *fh,
{ {
struct imx7_csi *csi = video_drvdata(file); struct imx7_csi *csi = video_drvdata(file);
f->fmt.pix = csi->vdev.fmt; f->fmt.pix = csi->vdev_fmt;
return 0; return 0;
} }
...@@ -896,10 +897,10 @@ static int imx7_csi_video_s_fmt_vid_cap(struct file *file, void *fh, ...@@ -896,10 +897,10 @@ static int imx7_csi_video_s_fmt_vid_cap(struct file *file, void *fh,
return -EBUSY; return -EBUSY;
} }
cc = __imx7_csi_video_try_fmt(&f->fmt.pix, &csi->vdev.compose); cc = __imx7_csi_video_try_fmt(&f->fmt.pix, &csi->vdev_compose);
csi->vdev.cc = cc; csi->vdev_cc = cc;
csi->vdev.fmt = f->fmt.pix; csi->vdev_fmt = f->fmt.pix;
return 0; return 0;
} }
...@@ -914,7 +915,7 @@ static int imx7_csi_video_g_selection(struct file *file, void *fh, ...@@ -914,7 +915,7 @@ static int imx7_csi_video_g_selection(struct file *file, void *fh,
case V4L2_SEL_TGT_COMPOSE_DEFAULT: case V4L2_SEL_TGT_COMPOSE_DEFAULT:
case V4L2_SEL_TGT_COMPOSE_BOUNDS: case V4L2_SEL_TGT_COMPOSE_BOUNDS:
/* The compose rectangle is fixed to the source format. */ /* The compose rectangle is fixed to the source format. */
s->r = csi->vdev.compose; s->r = csi->vdev_compose;
break; break;
case V4L2_SEL_TGT_COMPOSE_PADDED: case V4L2_SEL_TGT_COMPOSE_PADDED:
/* /*
...@@ -924,8 +925,8 @@ static int imx7_csi_video_g_selection(struct file *file, void *fh, ...@@ -924,8 +925,8 @@ static int imx7_csi_video_g_selection(struct file *file, void *fh,
*/ */
s->r.left = 0; s->r.left = 0;
s->r.top = 0; s->r.top = 0;
s->r.width = csi->vdev.fmt.width; s->r.width = csi->vdev_fmt.width;
s->r.height = csi->vdev.fmt.height; s->r.height = csi->vdev_fmt.height;
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -982,7 +983,7 @@ static int imx7_csi_video_queue_setup(struct vb2_queue *vq, ...@@ -982,7 +983,7 @@ static int imx7_csi_video_queue_setup(struct vb2_queue *vq,
struct device *alloc_devs[]) struct device *alloc_devs[])
{ {
struct imx7_csi *csi = vb2_get_drv_priv(vq); struct imx7_csi *csi = vb2_get_drv_priv(vq);
struct v4l2_pix_format *pix = &csi->vdev.fmt; struct v4l2_pix_format *pix = &csi->vdev_fmt;
unsigned int count = *nbuffers; unsigned int count = *nbuffers;
if (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
...@@ -1020,7 +1021,7 @@ static int imx7_csi_video_buf_init(struct vb2_buffer *vb) ...@@ -1020,7 +1021,7 @@ static int imx7_csi_video_buf_init(struct vb2_buffer *vb)
static int imx7_csi_video_buf_prepare(struct vb2_buffer *vb) static int imx7_csi_video_buf_prepare(struct vb2_buffer *vb)
{ {
struct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue); struct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);
struct v4l2_pix_format *pix = &csi->vdev.fmt; struct v4l2_pix_format *pix = &csi->vdev_fmt;
if (vb2_plane_size(vb, 0) < pix->sizeimage) { if (vb2_plane_size(vb, 0) < pix->sizeimage) {
dev_err(csi->dev, dev_err(csi->dev,
...@@ -1063,12 +1064,12 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi) ...@@ -1063,12 +1064,12 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
/* /*
* Verify that the media bus size matches the size set on the video * Verify that the media bus size matches the size set on the video
* node. It is sufficient to check the compose rectangle size without * node. It is sufficient to check the compose rectangle size without
* checking the rounded size from vdev.fmt, as the rounded size is * checking the rounded size from pix_fmt, as the rounded size is
* derived directly from the compose rectangle size, and will thus * derived directly from the compose rectangle size, and will thus
* always match if the compose rectangle matches. * always match if the compose rectangle matches.
*/ */
if (csi->vdev.compose.width != fmt_src.format.width || if (csi->vdev_compose.width != fmt_src.format.width ||
csi->vdev.compose.height != fmt_src.format.height) csi->vdev_compose.height != fmt_src.format.height)
return -EPIPE; return -EPIPE;
/* /*
...@@ -1076,7 +1077,7 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi) ...@@ -1076,7 +1077,7 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
* set on the video node. * set on the video node.
*/ */
cc = imx7_csi_video_find_format(fmt_src.format.code, 0); cc = imx7_csi_video_find_format(fmt_src.format.code, 0);
if (!cc || csi->vdev.cc->cs != cc->cs) if (!cc || csi->vdev_cc->cs != cc->cs)
return -EPIPE; return -EPIPE;
return 0; return 0;
...@@ -1164,7 +1165,6 @@ static const struct vb2_ops imx7_csi_video_qops = { ...@@ -1164,7 +1165,6 @@ static const struct vb2_ops imx7_csi_video_qops = {
static int imx7_csi_video_open(struct file *file) static int imx7_csi_video_open(struct file *file)
{ {
struct imx7_csi *csi = video_drvdata(file); struct imx7_csi *csi = video_drvdata(file);
struct video_device *vfd = csi->vdev.vfd;
int ret; int ret;
if (mutex_lock_interruptible(&csi->vdev_mutex)) if (mutex_lock_interruptible(&csi->vdev_mutex))
...@@ -1176,7 +1176,7 @@ static int imx7_csi_video_open(struct file *file) ...@@ -1176,7 +1176,7 @@ static int imx7_csi_video_open(struct file *file)
goto out; goto out;
} }
ret = v4l2_pipeline_pm_get(&vfd->entity); ret = v4l2_pipeline_pm_get(&csi->vdev->entity);
if (ret) if (ret)
v4l2_fh_release(file); v4l2_fh_release(file);
...@@ -1188,7 +1188,6 @@ static int imx7_csi_video_open(struct file *file) ...@@ -1188,7 +1188,6 @@ static int imx7_csi_video_open(struct file *file)
static int imx7_csi_video_release(struct file *file) static int imx7_csi_video_release(struct file *file)
{ {
struct imx7_csi *csi = video_drvdata(file); struct imx7_csi *csi = video_drvdata(file);
struct video_device *vfd = csi->vdev.vfd;
struct vb2_queue *vq = &csi->q; struct vb2_queue *vq = &csi->q;
mutex_lock(&csi->vdev_mutex); mutex_lock(&csi->vdev_mutex);
...@@ -1198,7 +1197,7 @@ static int imx7_csi_video_release(struct file *file) ...@@ -1198,7 +1197,7 @@ static int imx7_csi_video_release(struct file *file)
vq->owner = NULL; vq->owner = NULL;
} }
v4l2_pipeline_pm_put(&vfd->entity); v4l2_pipeline_pm_put(&csi->vdev->entity);
v4l2_fh_release(file); v4l2_fh_release(file);
mutex_unlock(&csi->vdev_mutex); mutex_unlock(&csi->vdev_mutex);
...@@ -1243,17 +1242,15 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi) ...@@ -1243,17 +1242,15 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi)
.pad = IMX7_CSI_PAD_SRC, .pad = IMX7_CSI_PAD_SRC,
.which = V4L2_SUBDEV_FORMAT_ACTIVE, .which = V4L2_SUBDEV_FORMAT_ACTIVE,
}; };
struct imx_media_video_dev *vdev = &csi->vdev;
fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8; fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
fmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH; fmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH;
fmt_src.format.height = IMX_MEDIA_DEF_PIX_HEIGHT; fmt_src.format.height = IMX_MEDIA_DEF_PIX_HEIGHT;
imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt, &fmt_src.format, NULL); imx_media_mbus_fmt_to_pix_fmt(&csi->vdev_fmt, &fmt_src.format, NULL);
vdev->compose.width = fmt_src.format.width; csi->vdev_compose.width = fmt_src.format.width;
vdev->compose.height = fmt_src.format.height; csi->vdev_compose.height = fmt_src.format.height;
vdev->cc = imx_media_find_pixel_format(vdev->fmt.pixelformat, csi->vdev_cc = imx_media_find_pixel_format(csi->vdev_fmt.pixelformat,
PIXFMT_SEL_ANY); PIXFMT_SEL_ANY);
return 0; return 0;
...@@ -1263,10 +1260,10 @@ static int imx7_csi_video_register(struct imx7_csi *csi) ...@@ -1263,10 +1260,10 @@ static int imx7_csi_video_register(struct imx7_csi *csi)
{ {
struct v4l2_subdev *sd = &csi->sd; struct v4l2_subdev *sd = &csi->sd;
struct v4l2_device *v4l2_dev = sd->v4l2_dev; struct v4l2_device *v4l2_dev = sd->v4l2_dev;
struct video_device *vfd = csi->vdev.vfd; struct video_device *vdev = csi->vdev;
int ret; int ret;
vfd->v4l2_dev = v4l2_dev; vdev->v4l2_dev = v4l2_dev;
/* Initialize the default format and compose rectangle. */ /* Initialize the default format and compose rectangle. */
ret = imx7_csi_video_init_format(csi); ret = imx7_csi_video_init_format(csi);
...@@ -1274,22 +1271,22 @@ static int imx7_csi_video_register(struct imx7_csi *csi) ...@@ -1274,22 +1271,22 @@ static int imx7_csi_video_register(struct imx7_csi *csi)
return ret; return ret;
/* Register the video device. */ /* Register the video device. */
ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1); ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
if (ret) { if (ret) {
dev_err(csi->dev, "Failed to register video device\n"); dev_err(csi->dev, "Failed to register video device\n");
return ret; return ret;
} }
dev_info(csi->dev, "Registered %s as /dev/%s\n", vfd->name, dev_info(csi->dev, "Registered %s as /dev/%s\n", vdev->name,
video_device_node_name(vfd)); video_device_node_name(vdev));
/* Create the link from the CSI subdev to the video device. */ /* Create the link from the CSI subdev to the video device. */
ret = media_create_pad_link(&sd->entity, IMX7_CSI_PAD_SRC, &vfd->entity, ret = media_create_pad_link(&sd->entity, IMX7_CSI_PAD_SRC,
0, MEDIA_LNK_FL_IMMUTABLE | &vdev->entity, 0, MEDIA_LNK_FL_IMMUTABLE |
MEDIA_LNK_FL_ENABLED); MEDIA_LNK_FL_ENABLED);
if (ret) { if (ret) {
dev_err(csi->dev, "failed to create link to device node\n"); dev_err(csi->dev, "failed to create link to device node\n");
video_unregister_device(vfd); video_unregister_device(vdev);
return ret; return ret;
} }
...@@ -1298,15 +1295,13 @@ static int imx7_csi_video_register(struct imx7_csi *csi) ...@@ -1298,15 +1295,13 @@ static int imx7_csi_video_register(struct imx7_csi *csi)
static void imx7_csi_video_unregister(struct imx7_csi *csi) static void imx7_csi_video_unregister(struct imx7_csi *csi)
{ {
struct video_device *vfd = csi->vdev.vfd; media_entity_cleanup(&csi->vdev->entity);
video_unregister_device(csi->vdev);
media_entity_cleanup(&vfd->entity);
video_unregister_device(vfd);
} }
static int imx7_csi_video_init(struct imx7_csi *csi) static int imx7_csi_video_init(struct imx7_csi *csi)
{ {
struct video_device *vfd; struct video_device *vdev;
struct vb2_queue *vq; struct vb2_queue *vq;
int ret; int ret;
...@@ -1315,32 +1310,31 @@ static int imx7_csi_video_init(struct imx7_csi *csi) ...@@ -1315,32 +1310,31 @@ static int imx7_csi_video_init(struct imx7_csi *csi)
spin_lock_init(&csi->q_lock); spin_lock_init(&csi->q_lock);
/* Allocate and initialize the video device. */ /* Allocate and initialize the video device. */
vfd = video_device_alloc(); vdev = video_device_alloc();
if (!vfd) if (!vdev)
return -ENOMEM; return -ENOMEM;
vfd->fops = &imx7_csi_video_fops; vdev->fops = &imx7_csi_video_fops;
vfd->ioctl_ops = &imx7_csi_video_ioctl_ops; vdev->ioctl_ops = &imx7_csi_video_ioctl_ops;
vfd->minor = -1; vdev->minor = -1;
vfd->release = video_device_release; vdev->release = video_device_release;
vfd->vfl_dir = VFL_DIR_RX; vdev->vfl_dir = VFL_DIR_RX;
vfd->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM; vdev->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
| V4L2_CAP_IO_MC; | V4L2_CAP_IO_MC;
vfd->lock = &csi->vdev_mutex; vdev->lock = &csi->vdev_mutex;
vfd->queue = &csi->q; vdev->queue = &csi->q;
snprintf(vfd->name, sizeof(vfd->name), "%s capture", csi->sd.name); snprintf(vdev->name, sizeof(vdev->name), "%s capture", csi->sd.name);
video_set_drvdata(vfd, csi); video_set_drvdata(vdev, csi);
csi->vdev.vfd = vfd; csi->vdev = vdev;
INIT_LIST_HEAD(&csi->vdev.list);
/* Initialize the video device pad. */ /* Initialize the video device pad. */
csi->vdev_pad.flags = MEDIA_PAD_FL_SINK; csi->vdev_pad.flags = MEDIA_PAD_FL_SINK;
ret = media_entity_pads_init(&vfd->entity, 1, &csi->vdev_pad); ret = media_entity_pads_init(&vdev->entity, 1, &csi->vdev_pad);
if (ret) { if (ret) {
video_device_release(vfd); video_device_release(vdev);
return ret; return ret;
} }
...@@ -1360,7 +1354,7 @@ static int imx7_csi_video_init(struct imx7_csi *csi) ...@@ -1360,7 +1354,7 @@ static int imx7_csi_video_init(struct imx7_csi *csi)
ret = vb2_queue_init(vq); ret = vb2_queue_init(vq);
if (ret) { if (ret) {
dev_err(csi->dev, "vb2_queue_init failed\n"); dev_err(csi->dev, "vb2_queue_init failed\n");
video_device_release(vfd); video_device_release(vdev);
return ret; return ret;
} }
...@@ -1629,8 +1623,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd, ...@@ -1629,8 +1623,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
struct v4l2_subdev_format *sink_fmt) struct v4l2_subdev_format *sink_fmt)
{ {
struct imx7_csi *csi = v4l2_get_subdevdata(sd); struct imx7_csi *csi = v4l2_get_subdevdata(sd);
struct imx_media_video_dev *vdev = &csi->vdev; const struct v4l2_pix_format *out_pix = &csi->vdev_fmt;
const struct v4l2_pix_format *out_pix = &vdev->fmt;
struct media_pad *pad = NULL; struct media_pad *pad = NULL;
unsigned int i; unsigned int i;
int ret; int ret;
......
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