1 // SPDX-License-Identifier: GPL-2.0+
3 * Video Capture Subdev for Freescale i.MX5/6 SOC
5 * Copyright (c) 2012-2016 Mentor Graphics Inc.
7 #include <linux/delay.h>
9 #include <linux/module.h>
10 #include <linux/of_platform.h>
11 #include <linux/pinctrl/consumer.h>
12 #include <linux/platform_device.h>
13 #include <linux/sched.h>
14 #include <linux/slab.h>
15 #include <linux/spinlock.h>
16 #include <linux/timer.h>
17 #include <media/v4l2-ctrls.h>
18 #include <media/v4l2-device.h>
19 #include <media/v4l2-event.h>
20 #include <media/v4l2-fwnode.h>
21 #include <media/v4l2-ioctl.h>
22 #include <media/v4l2-mc.h>
23 #include <media/v4l2-subdev.h>
24 #include <media/videobuf2-dma-contig.h>
25 #include <video/imx-ipu-v3.h>
26 #include <media/imx.h>
27 #include "imx-media.h"
30 struct imx_media_video_dev vdev;
32 struct v4l2_subdev *src_sd;
36 struct imx_media_dev *md;
38 struct media_pad vdev_pad;
40 struct mutex mutex; /* capture device mutex */
42 /* the videobuf2 queue */
44 /* list of ready imx_media_buffer's from q */
45 struct list_head ready_q;
49 /* controls inherited from subdevs */
50 struct v4l2_ctrl_handler ctrl_hdlr;
53 bool stop; /* streaming is stopping */
56 #define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
58 /* In bytes, per queue */
59 #define VID_MEM_LIMIT SZ_64M
61 static const struct vb2_ops capture_qops;
67 static int vidioc_querycap(struct file *file, void *fh,
68 struct v4l2_capability *cap)
70 struct capture_priv *priv = video_drvdata(file);
72 strscpy(cap->driver, "imx-media-capture", sizeof(cap->driver));
73 strscpy(cap->card, "imx-media-capture", sizeof(cap->card));
74 snprintf(cap->bus_info, sizeof(cap->bus_info),
75 "platform:%s", priv->src_sd->name);
80 static int capture_enum_framesizes(struct file *file, void *fh,
81 struct v4l2_frmsizeenum *fsize)
83 struct capture_priv *priv = video_drvdata(file);
84 const struct imx_media_pixfmt *cc;
85 struct v4l2_subdev_frame_size_enum fse = {
86 .index = fsize->index,
87 .pad = priv->src_sd_pad,
88 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
92 cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY, true);
96 fse.code = cc->codes[0];
98 ret = v4l2_subdev_call(priv->src_sd, pad, enum_frame_size, NULL, &fse);
102 if (fse.min_width == fse.max_width &&
103 fse.min_height == fse.max_height) {
104 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
105 fsize->discrete.width = fse.min_width;
106 fsize->discrete.height = fse.min_height;
108 fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
109 fsize->stepwise.min_width = fse.min_width;
110 fsize->stepwise.max_width = fse.max_width;
111 fsize->stepwise.min_height = fse.min_height;
112 fsize->stepwise.max_height = fse.max_height;
113 fsize->stepwise.step_width = 1;
114 fsize->stepwise.step_height = 1;
120 static int capture_enum_frameintervals(struct file *file, void *fh,
121 struct v4l2_frmivalenum *fival)
123 struct capture_priv *priv = video_drvdata(file);
124 const struct imx_media_pixfmt *cc;
125 struct v4l2_subdev_frame_interval_enum fie = {
126 .index = fival->index,
127 .pad = priv->src_sd_pad,
128 .width = fival->width,
129 .height = fival->height,
130 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
134 cc = imx_media_find_format(fival->pixel_format, CS_SEL_ANY, true);
138 fie.code = cc->codes[0];
140 ret = v4l2_subdev_call(priv->src_sd, pad, enum_frame_interval,
145 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
146 fival->discrete = fie.interval;
151 static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
152 struct v4l2_fmtdesc *f)
154 struct capture_priv *priv = video_drvdata(file);
155 const struct imx_media_pixfmt *cc_src;
156 struct v4l2_subdev_format fmt_src;
160 fmt_src.pad = priv->src_sd_pad;
161 fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
162 ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src);
164 v4l2_err(priv->src_sd, "failed to get src_sd format\n");
168 cc_src = imx_media_find_ipu_format(fmt_src.format.code, CS_SEL_ANY);
170 u32 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
171 CS_SEL_YUV : CS_SEL_RGB;
173 ret = imx_media_enum_format(&fourcc, f->index, cs_sel);
177 cc_src = imx_media_find_mbus_format(fmt_src.format.code,
179 if (WARN_ON(!cc_src))
184 fourcc = cc_src->fourcc;
187 f->pixelformat = fourcc;
192 static int capture_g_fmt_vid_cap(struct file *file, void *fh,
193 struct v4l2_format *f)
195 struct capture_priv *priv = video_drvdata(file);
202 static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
203 struct v4l2_subdev_format *fmt_src,
204 struct v4l2_format *f,
205 struct v4l2_rect *compose)
207 const struct imx_media_pixfmt *cc, *cc_src;
209 cc_src = imx_media_find_ipu_format(fmt_src->format.code, CS_SEL_ANY);
213 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
214 CS_SEL_YUV : CS_SEL_RGB;
215 fourcc = f->fmt.pix.pixelformat;
217 cc = imx_media_find_format(fourcc, cs_sel, false);
219 imx_media_enum_format(&fourcc, 0, cs_sel);
220 cc = imx_media_find_format(fourcc, cs_sel, false);
223 cc_src = imx_media_find_mbus_format(fmt_src->format.code,
225 if (WARN_ON(!cc_src))
231 /* allow IDMAC interweave but enforce field order from source */
232 if (V4L2_FIELD_IS_INTERLACED(f->fmt.pix.field)) {
233 switch (fmt_src->format.field) {
234 case V4L2_FIELD_SEQ_TB:
235 fmt_src->format.field = V4L2_FIELD_INTERLACED_TB;
237 case V4L2_FIELD_SEQ_BT:
238 fmt_src->format.field = V4L2_FIELD_INTERLACED_BT;
245 imx_media_mbus_fmt_to_pix_fmt(&f->fmt.pix, compose,
246 &fmt_src->format, cc);
251 static int capture_try_fmt_vid_cap(struct file *file, void *fh,
252 struct v4l2_format *f)
254 struct capture_priv *priv = video_drvdata(file);
255 struct v4l2_subdev_format fmt_src;
258 fmt_src.pad = priv->src_sd_pad;
259 fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
260 ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src);
264 return __capture_try_fmt_vid_cap(priv, &fmt_src, f, NULL);
267 static int capture_s_fmt_vid_cap(struct file *file, void *fh,
268 struct v4l2_format *f)
270 struct capture_priv *priv = video_drvdata(file);
271 struct v4l2_subdev_format fmt_src;
272 struct v4l2_rect compose;
275 if (vb2_is_busy(&priv->q)) {
276 v4l2_err(priv->src_sd, "%s queue busy\n", __func__);
280 fmt_src.pad = priv->src_sd_pad;
281 fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
282 ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src);
286 ret = __capture_try_fmt_vid_cap(priv, &fmt_src, f, &compose);
290 priv->vdev.fmt.fmt.pix = f->fmt.pix;
291 priv->vdev.cc = imx_media_find_format(f->fmt.pix.pixelformat,
293 priv->vdev.compose = compose;
298 static int capture_querystd(struct file *file, void *fh, v4l2_std_id *std)
300 struct capture_priv *priv = video_drvdata(file);
302 return v4l2_subdev_call(priv->src_sd, video, querystd, std);
305 static int capture_g_std(struct file *file, void *fh, v4l2_std_id *std)
307 struct capture_priv *priv = video_drvdata(file);
309 return v4l2_subdev_call(priv->src_sd, video, g_std, std);
312 static int capture_s_std(struct file *file, void *fh, v4l2_std_id std)
314 struct capture_priv *priv = video_drvdata(file);
316 if (vb2_is_busy(&priv->q))
319 return v4l2_subdev_call(priv->src_sd, video, s_std, std);
322 static int capture_g_selection(struct file *file, void *fh,
323 struct v4l2_selection *s)
325 struct capture_priv *priv = video_drvdata(file);
328 case V4L2_SEL_TGT_COMPOSE:
329 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
330 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
331 /* The compose rectangle is fixed to the source format. */
332 s->r = priv->vdev.compose;
334 case V4L2_SEL_TGT_COMPOSE_PADDED:
336 * The hardware writes with a configurable but fixed DMA burst
337 * size. If the source format width is not burst size aligned,
338 * the written frame contains padding to the right.
342 s->r.width = priv->vdev.fmt.fmt.pix.width;
343 s->r.height = priv->vdev.fmt.fmt.pix.height;
352 static int capture_g_parm(struct file *file, void *fh,
353 struct v4l2_streamparm *a)
355 struct capture_priv *priv = video_drvdata(file);
356 struct v4l2_subdev_frame_interval fi;
359 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
362 memset(&fi, 0, sizeof(fi));
363 fi.pad = priv->src_sd_pad;
364 ret = v4l2_subdev_call(priv->src_sd, video, g_frame_interval, &fi);
368 a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
369 a->parm.capture.timeperframe = fi.interval;
374 static int capture_s_parm(struct file *file, void *fh,
375 struct v4l2_streamparm *a)
377 struct capture_priv *priv = video_drvdata(file);
378 struct v4l2_subdev_frame_interval fi;
381 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
384 memset(&fi, 0, sizeof(fi));
385 fi.pad = priv->src_sd_pad;
386 fi.interval = a->parm.capture.timeperframe;
387 ret = v4l2_subdev_call(priv->src_sd, video, s_frame_interval, &fi);
391 a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
392 a->parm.capture.timeperframe = fi.interval;
397 static int capture_subscribe_event(struct v4l2_fh *fh,
398 const struct v4l2_event_subscription *sub)
401 case V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR:
402 return v4l2_event_subscribe(fh, sub, 0, NULL);
403 case V4L2_EVENT_SOURCE_CHANGE:
404 return v4l2_src_change_event_subscribe(fh, sub);
405 case V4L2_EVENT_CTRL:
406 return v4l2_ctrl_subscribe_event(fh, sub);
412 static const struct v4l2_ioctl_ops capture_ioctl_ops = {
413 .vidioc_querycap = vidioc_querycap,
415 .vidioc_enum_framesizes = capture_enum_framesizes,
416 .vidioc_enum_frameintervals = capture_enum_frameintervals,
418 .vidioc_enum_fmt_vid_cap = capture_enum_fmt_vid_cap,
419 .vidioc_g_fmt_vid_cap = capture_g_fmt_vid_cap,
420 .vidioc_try_fmt_vid_cap = capture_try_fmt_vid_cap,
421 .vidioc_s_fmt_vid_cap = capture_s_fmt_vid_cap,
423 .vidioc_querystd = capture_querystd,
424 .vidioc_g_std = capture_g_std,
425 .vidioc_s_std = capture_s_std,
427 .vidioc_g_selection = capture_g_selection,
429 .vidioc_g_parm = capture_g_parm,
430 .vidioc_s_parm = capture_s_parm,
432 .vidioc_reqbufs = vb2_ioctl_reqbufs,
433 .vidioc_create_bufs = vb2_ioctl_create_bufs,
434 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
435 .vidioc_querybuf = vb2_ioctl_querybuf,
436 .vidioc_qbuf = vb2_ioctl_qbuf,
437 .vidioc_dqbuf = vb2_ioctl_dqbuf,
438 .vidioc_expbuf = vb2_ioctl_expbuf,
439 .vidioc_streamon = vb2_ioctl_streamon,
440 .vidioc_streamoff = vb2_ioctl_streamoff,
442 .vidioc_subscribe_event = capture_subscribe_event,
443 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
450 static int capture_queue_setup(struct vb2_queue *vq,
451 unsigned int *nbuffers,
452 unsigned int *nplanes,
453 unsigned int sizes[],
454 struct device *alloc_devs[])
456 struct capture_priv *priv = vb2_get_drv_priv(vq);
457 struct v4l2_pix_format *pix = &priv->vdev.fmt.fmt.pix;
458 unsigned int count = *nbuffers;
460 if (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
464 if (*nplanes != 1 || sizes[0] < pix->sizeimage)
466 count += vq->num_buffers;
469 count = min_t(__u32, VID_MEM_LIMIT / pix->sizeimage, count);
472 *nbuffers = (count < vq->num_buffers) ? 0 :
473 count - vq->num_buffers;
478 sizes[0] = pix->sizeimage;
483 static int capture_buf_init(struct vb2_buffer *vb)
485 struct imx_media_buffer *buf = to_imx_media_vb(vb);
487 INIT_LIST_HEAD(&buf->list);
492 static int capture_buf_prepare(struct vb2_buffer *vb)
494 struct vb2_queue *vq = vb->vb2_queue;
495 struct capture_priv *priv = vb2_get_drv_priv(vq);
496 struct v4l2_pix_format *pix = &priv->vdev.fmt.fmt.pix;
498 if (vb2_plane_size(vb, 0) < pix->sizeimage) {
499 v4l2_err(priv->src_sd,
500 "data will not fit into plane (%lu < %lu)\n",
501 vb2_plane_size(vb, 0), (long)pix->sizeimage);
505 vb2_set_plane_payload(vb, 0, pix->sizeimage);
510 static void capture_buf_queue(struct vb2_buffer *vb)
512 struct capture_priv *priv = vb2_get_drv_priv(vb->vb2_queue);
513 struct imx_media_buffer *buf = to_imx_media_vb(vb);
516 spin_lock_irqsave(&priv->q_lock, flags);
518 list_add_tail(&buf->list, &priv->ready_q);
520 spin_unlock_irqrestore(&priv->q_lock, flags);
523 static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
525 struct capture_priv *priv = vb2_get_drv_priv(vq);
526 struct imx_media_buffer *buf, *tmp;
530 ret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,
533 v4l2_err(priv->src_sd, "pipeline start failed with %d\n", ret);
542 spin_lock_irqsave(&priv->q_lock, flags);
543 list_for_each_entry_safe(buf, tmp, &priv->ready_q, list) {
544 list_del(&buf->list);
545 vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_QUEUED);
547 spin_unlock_irqrestore(&priv->q_lock, flags);
551 static void capture_stop_streaming(struct vb2_queue *vq)
553 struct capture_priv *priv = vb2_get_drv_priv(vq);
554 struct imx_media_buffer *frame;
555 struct imx_media_buffer *tmp;
559 spin_lock_irqsave(&priv->q_lock, flags);
561 spin_unlock_irqrestore(&priv->q_lock, flags);
563 ret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,
566 v4l2_warn(priv->src_sd, "pipeline stop failed with %d\n", ret);
568 /* release all active buffers */
569 spin_lock_irqsave(&priv->q_lock, flags);
570 list_for_each_entry_safe(frame, tmp, &priv->ready_q, list) {
571 list_del(&frame->list);
572 vb2_buffer_done(&frame->vbuf.vb2_buf, VB2_BUF_STATE_ERROR);
574 spin_unlock_irqrestore(&priv->q_lock, flags);
577 static const struct vb2_ops capture_qops = {
578 .queue_setup = capture_queue_setup,
579 .buf_init = capture_buf_init,
580 .buf_prepare = capture_buf_prepare,
581 .buf_queue = capture_buf_queue,
582 .wait_prepare = vb2_ops_wait_prepare,
583 .wait_finish = vb2_ops_wait_finish,
584 .start_streaming = capture_start_streaming,
585 .stop_streaming = capture_stop_streaming,
591 static int capture_open(struct file *file)
593 struct capture_priv *priv = video_drvdata(file);
594 struct video_device *vfd = priv->vdev.vfd;
597 if (mutex_lock_interruptible(&priv->mutex))
600 ret = v4l2_fh_open(file);
602 v4l2_err(priv->src_sd, "v4l2_fh_open failed\n");
604 ret = v4l2_pipeline_pm_use(&vfd->entity, 1);
606 v4l2_fh_release(file);
608 mutex_unlock(&priv->mutex);
612 static int capture_release(struct file *file)
614 struct capture_priv *priv = video_drvdata(file);
615 struct video_device *vfd = priv->vdev.vfd;
616 struct vb2_queue *vq = &priv->q;
619 mutex_lock(&priv->mutex);
621 if (file->private_data == vq->owner) {
622 vb2_queue_release(vq);
626 v4l2_pipeline_pm_use(&vfd->entity, 0);
628 v4l2_fh_release(file);
629 mutex_unlock(&priv->mutex);
633 static const struct v4l2_file_operations capture_fops = {
634 .owner = THIS_MODULE,
635 .open = capture_open,
636 .release = capture_release,
637 .poll = vb2_fop_poll,
638 .unlocked_ioctl = video_ioctl2,
639 .mmap = vb2_fop_mmap,
642 static struct video_device capture_videodev = {
643 .fops = &capture_fops,
644 .ioctl_ops = &capture_ioctl_ops,
646 .release = video_device_release,
647 .vfl_dir = VFL_DIR_RX,
648 .tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
649 .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING,
652 void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev,
653 const struct v4l2_pix_format *pix,
654 const struct v4l2_rect *compose)
656 struct capture_priv *priv = to_capture_priv(vdev);
658 mutex_lock(&priv->mutex);
659 priv->vdev.fmt.fmt.pix = *pix;
660 priv->vdev.cc = imx_media_find_format(pix->pixelformat, CS_SEL_ANY,
662 priv->vdev.compose = *compose;
663 mutex_unlock(&priv->mutex);
665 EXPORT_SYMBOL_GPL(imx_media_capture_device_set_format);
667 struct imx_media_buffer *
668 imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev)
670 struct capture_priv *priv = to_capture_priv(vdev);
671 struct imx_media_buffer *buf = NULL;
674 spin_lock_irqsave(&priv->q_lock, flags);
676 /* get next queued buffer */
677 if (!list_empty(&priv->ready_q)) {
678 buf = list_entry(priv->ready_q.next, struct imx_media_buffer,
680 list_del(&buf->list);
683 spin_unlock_irqrestore(&priv->q_lock, flags);
687 EXPORT_SYMBOL_GPL(imx_media_capture_device_next_buf);
689 void imx_media_capture_device_error(struct imx_media_video_dev *vdev)
691 struct capture_priv *priv = to_capture_priv(vdev);
692 struct vb2_queue *vq = &priv->q;
695 if (!vb2_is_streaming(vq))
698 spin_lock_irqsave(&priv->q_lock, flags);
700 spin_unlock_irqrestore(&priv->q_lock, flags);
702 EXPORT_SYMBOL_GPL(imx_media_capture_device_error);
704 int imx_media_capture_device_register(struct imx_media_dev *md,
705 struct imx_media_video_dev *vdev)
707 struct capture_priv *priv = to_capture_priv(vdev);
708 struct v4l2_subdev *sd = priv->src_sd;
709 struct video_device *vfd = vdev->vfd;
710 struct vb2_queue *vq = &priv->q;
711 struct v4l2_subdev_format fmt_src;
716 vfd->v4l2_dev = sd->v4l2_dev;
718 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
720 v4l2_err(sd, "Failed to register video device\n");
724 vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
725 vq->io_modes = VB2_MMAP | VB2_DMABUF;
727 vq->buf_struct_size = sizeof(struct imx_media_buffer);
728 vq->ops = &capture_qops;
729 vq->mem_ops = &vb2_dma_contig_memops;
730 vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
731 vq->lock = &priv->mutex;
732 vq->min_buffers_needed = 2;
735 ret = vb2_queue_init(vq);
737 v4l2_err(sd, "vb2_queue_init failed\n");
741 INIT_LIST_HEAD(&priv->ready_q);
743 priv->vdev_pad.flags = MEDIA_PAD_FL_SINK;
744 ret = media_entity_pads_init(&vfd->entity, 1, &priv->vdev_pad);
746 v4l2_err(sd, "failed to init dev pad\n");
750 /* create the link from the src_sd devnode pad to device node */
751 ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
754 v4l2_err(sd, "failed to create link to device node\n");
758 /* setup default format */
759 fmt_src.pad = priv->src_sd_pad;
760 fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
761 v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt_src);
763 v4l2_err(sd, "failed to get src_sd format\n");
767 vdev->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
768 imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, &vdev->compose,
769 &fmt_src.format, NULL);
770 vdev->cc = imx_media_find_format(vdev->fmt.fmt.pix.pixelformat,
773 v4l2_info(sd, "Registered %s as /dev/%s\n", vfd->name,
774 video_device_node_name(vfd));
776 vfd->ctrl_handler = &priv->ctrl_hdlr;
780 video_unregister_device(vfd);
783 EXPORT_SYMBOL_GPL(imx_media_capture_device_register);
785 void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev)
787 struct capture_priv *priv = to_capture_priv(vdev);
788 struct video_device *vfd = priv->vdev.vfd;
790 mutex_lock(&priv->mutex);
792 if (video_is_registered(vfd)) {
793 video_unregister_device(vfd);
794 media_entity_cleanup(&vfd->entity);
797 mutex_unlock(&priv->mutex);
799 EXPORT_SYMBOL_GPL(imx_media_capture_device_unregister);
801 struct imx_media_video_dev *
802 imx_media_capture_device_init(struct v4l2_subdev *src_sd, int pad)
804 struct capture_priv *priv;
805 struct video_device *vfd;
807 priv = devm_kzalloc(src_sd->dev, sizeof(*priv), GFP_KERNEL);
809 return ERR_PTR(-ENOMEM);
811 priv->src_sd = src_sd;
812 priv->src_sd_pad = pad;
813 priv->dev = src_sd->dev;
815 mutex_init(&priv->mutex);
816 spin_lock_init(&priv->q_lock);
818 snprintf(capture_videodev.name, sizeof(capture_videodev.name),
819 "%s capture", src_sd->name);
821 vfd = video_device_alloc();
823 return ERR_PTR(-ENOMEM);
825 *vfd = capture_videodev;
826 vfd->lock = &priv->mutex;
827 vfd->queue = &priv->q;
828 priv->vdev.vfd = vfd;
830 INIT_LIST_HEAD(&priv->vdev.list);
832 video_set_drvdata(vfd, priv);
834 v4l2_ctrl_handler_init(&priv->ctrl_hdlr, 0);
838 EXPORT_SYMBOL_GPL(imx_media_capture_device_init);
840 void imx_media_capture_device_remove(struct imx_media_video_dev *vdev)
842 struct capture_priv *priv = to_capture_priv(vdev);
844 v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
846 EXPORT_SYMBOL_GPL(imx_media_capture_device_remove);
848 MODULE_DESCRIPTION("i.MX5/6 v4l2 video capture interface driver");
849 MODULE_AUTHOR("Steve Longerbeam <steve_longerbeam@mentor.com>");
850 MODULE_LICENSE("GPL");