2 * Samsung S5P/EXYNOS4 SoC series camera interface (camera capture) driver
4 * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd.
5 * Author: Sylwester Nawrocki, <s.nawrocki@samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/errno.h>
16 #include <linux/bug.h>
17 #include <linux/interrupt.h>
18 #include <linux/device.h>
19 #include <linux/pm_runtime.h>
20 #include <linux/list.h>
21 #include <linux/slab.h>
23 #include <linux/videodev2.h>
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-ioctl.h>
26 #include <media/v4l2-mem2mem.h>
27 #include <media/videobuf2-core.h>
28 #include <media/videobuf2-dma-contig.h>
30 #include "fimc-mdevice.h"
31 #include "fimc-core.h"
33 static int fimc_init_capture(struct fimc_dev *fimc)
35 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
36 struct fimc_sensor_info *sensor;
40 if (fimc->pipeline.sensor == NULL || ctx == NULL)
42 if (ctx->s_frame.fmt == NULL)
45 sensor = v4l2_get_subdev_hostdata(fimc->pipeline.sensor);
47 spin_lock_irqsave(&fimc->slock, flags);
48 fimc_prepare_dma_offset(ctx, &ctx->d_frame);
49 fimc_set_yuv_order(ctx);
51 fimc_hw_set_camera_polarity(fimc, sensor->pdata);
52 fimc_hw_set_camera_type(fimc, sensor->pdata);
53 fimc_hw_set_camera_source(fimc, sensor->pdata);
54 fimc_hw_set_camera_offset(fimc, &ctx->s_frame);
56 ret = fimc_set_scaler_info(ctx);
58 fimc_hw_set_input_path(ctx);
59 fimc_hw_set_prescaler(ctx);
60 fimc_hw_set_mainscaler(ctx);
61 fimc_hw_set_target_format(ctx);
62 fimc_hw_set_rotation(ctx);
63 fimc_hw_set_effect(ctx);
64 fimc_hw_set_output_path(ctx);
65 fimc_hw_set_out_dma(ctx);
67 spin_unlock_irqrestore(&fimc->slock, flags);
71 static int fimc_capture_state_cleanup(struct fimc_dev *fimc)
73 struct fimc_vid_cap *cap = &fimc->vid_cap;
74 struct fimc_vid_buffer *buf;
77 spin_lock_irqsave(&fimc->slock, flags);
78 fimc->state &= ~(1 << ST_CAPT_RUN | 1 << ST_CAPT_PEND |
79 1 << ST_CAPT_SHUT | 1 << ST_CAPT_STREAM |
80 1 << ST_CAPT_ISP_STREAM);
82 fimc->vid_cap.active_buf_cnt = 0;
84 /* Release buffers that were enqueued in the driver by videobuf2. */
85 while (!list_empty(&cap->pending_buf_q)) {
86 buf = pending_queue_pop(cap);
87 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
90 while (!list_empty(&cap->active_buf_q)) {
91 buf = active_queue_pop(cap);
92 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
95 spin_unlock_irqrestore(&fimc->slock, flags);
97 if (test_bit(ST_CAPT_ISP_STREAM, &fimc->state))
98 return fimc_pipeline_s_stream(fimc, 0);
103 static int fimc_stop_capture(struct fimc_dev *fimc)
105 struct fimc_vid_cap *cap = &fimc->vid_cap;
108 if (!fimc_capture_active(fimc))
111 spin_lock_irqsave(&fimc->slock, flags);
112 set_bit(ST_CAPT_SHUT, &fimc->state);
113 fimc_deactivate_capture(fimc);
114 spin_unlock_irqrestore(&fimc->slock, flags);
116 wait_event_timeout(fimc->irq_queue,
117 !test_bit(ST_CAPT_SHUT, &fimc->state),
118 FIMC_SHUTDOWN_TIMEOUT);
120 return fimc_capture_state_cleanup(fimc);
124 static int start_streaming(struct vb2_queue *q, unsigned int count)
126 struct fimc_ctx *ctx = q->drv_priv;
127 struct fimc_dev *fimc = ctx->fimc_dev;
128 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
133 vid_cap->frame_count = 0;
135 ret = fimc_init_capture(fimc);
139 set_bit(ST_CAPT_PEND, &fimc->state);
141 min_bufs = fimc->vid_cap.reqbufs_count > 1 ? 2 : 1;
143 if (vid_cap->active_buf_cnt >= min_bufs &&
144 !test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) {
145 fimc_activate_capture(ctx);
147 if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
148 fimc_pipeline_s_stream(fimc, 1);
153 fimc_capture_state_cleanup(fimc);
157 static int stop_streaming(struct vb2_queue *q)
159 struct fimc_ctx *ctx = q->drv_priv;
160 struct fimc_dev *fimc = ctx->fimc_dev;
162 if (!fimc_capture_active(fimc))
165 return fimc_stop_capture(fimc);
168 int fimc_capture_suspend(struct fimc_dev *fimc)
173 int fimc_capture_resume(struct fimc_dev *fimc)
178 static unsigned int get_plane_size(struct fimc_frame *fr, unsigned int plane)
180 if (!fr || plane >= fr->fmt->memplanes)
182 return fr->f_width * fr->f_height * fr->fmt->depth[plane] / 8;
185 static int queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
186 unsigned int *num_planes, unsigned int sizes[],
189 struct fimc_ctx *ctx = vq->drv_priv;
190 struct fimc_fmt *fmt = ctx->d_frame.fmt;
196 *num_planes = fmt->memplanes;
198 for (i = 0; i < fmt->memplanes; i++) {
199 sizes[i] = get_plane_size(&ctx->d_frame, i);
200 allocators[i] = ctx->fimc_dev->alloc_ctx;
206 static int buffer_prepare(struct vb2_buffer *vb)
208 struct vb2_queue *vq = vb->vb2_queue;
209 struct fimc_ctx *ctx = vq->drv_priv;
212 if (ctx->d_frame.fmt == NULL)
215 for (i = 0; i < ctx->d_frame.fmt->memplanes; i++) {
216 unsigned long size = ctx->d_frame.payload[i];
218 if (vb2_plane_size(vb, i) < size) {
219 v4l2_err(ctx->fimc_dev->vid_cap.vfd,
220 "User buffer too small (%ld < %ld)\n",
221 vb2_plane_size(vb, i), size);
224 vb2_set_plane_payload(vb, i, size);
230 static void buffer_queue(struct vb2_buffer *vb)
232 struct fimc_vid_buffer *buf
233 = container_of(vb, struct fimc_vid_buffer, vb);
234 struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
235 struct fimc_dev *fimc = ctx->fimc_dev;
236 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
240 spin_lock_irqsave(&fimc->slock, flags);
241 fimc_prepare_addr(ctx, &buf->vb, &ctx->d_frame, &buf->paddr);
243 if (!test_bit(ST_CAPT_STREAM, &fimc->state)
244 && vid_cap->active_buf_cnt < FIMC_MAX_OUT_BUFS) {
245 /* Setup the buffer directly for processing. */
246 int buf_id = (vid_cap->reqbufs_count == 1) ? -1 :
249 fimc_hw_set_output_addr(fimc, &buf->paddr, buf_id);
250 buf->index = vid_cap->buf_index;
251 active_queue_add(vid_cap, buf);
253 if (++vid_cap->buf_index >= FIMC_MAX_OUT_BUFS)
254 vid_cap->buf_index = 0;
256 fimc_pending_queue_add(vid_cap, buf);
259 min_bufs = vid_cap->reqbufs_count > 1 ? 2 : 1;
262 if (vb2_is_streaming(&vid_cap->vbq) &&
263 vid_cap->active_buf_cnt >= min_bufs &&
264 !test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) {
265 fimc_activate_capture(ctx);
266 spin_unlock_irqrestore(&fimc->slock, flags);
268 if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
269 fimc_pipeline_s_stream(fimc, 1);
272 spin_unlock_irqrestore(&fimc->slock, flags);
275 static void fimc_lock(struct vb2_queue *vq)
277 struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
278 mutex_lock(&ctx->fimc_dev->lock);
281 static void fimc_unlock(struct vb2_queue *vq)
283 struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
284 mutex_unlock(&ctx->fimc_dev->lock);
287 static struct vb2_ops fimc_capture_qops = {
288 .queue_setup = queue_setup,
289 .buf_prepare = buffer_prepare,
290 .buf_queue = buffer_queue,
291 .wait_prepare = fimc_unlock,
292 .wait_finish = fimc_lock,
293 .start_streaming = start_streaming,
294 .stop_streaming = stop_streaming,
298 * fimc_capture_ctrls_create - initialize the control handler
299 * Initialize the capture video node control handler and fill it
300 * with the FIMC controls. Inherit any sensor's controls if the
301 * 'user_subdev_api' flag is false (default behaviour).
302 * This function need to be called with the graph mutex held.
304 int fimc_capture_ctrls_create(struct fimc_dev *fimc)
306 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
309 if (WARN_ON(vid_cap->ctx == NULL))
311 if (vid_cap->ctx->ctrls_rdy)
314 ret = fimc_ctrls_create(vid_cap->ctx);
315 if (ret || vid_cap->user_subdev_api)
318 return v4l2_ctrl_add_handler(&vid_cap->ctx->ctrl_handler,
319 fimc->pipeline.sensor->ctrl_handler);
322 static int fimc_capture_open(struct file *file)
324 struct fimc_dev *fimc = video_drvdata(file);
325 int ret = v4l2_fh_open(file);
330 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
332 /* Return if the corresponding video mem2mem node is already opened. */
333 if (fimc_m2m_active(fimc))
336 pm_runtime_get_sync(&fimc->pdev->dev);
338 if (++fimc->vid_cap.refcnt == 1) {
339 ret = fimc_pipeline_initialize(fimc,
340 &fimc->vid_cap.vfd->entity, true);
342 dev_err(&fimc->pdev->dev,
343 "Video pipeline initialization failed\n");
344 pm_runtime_put_sync(&fimc->pdev->dev);
345 fimc->vid_cap.refcnt--;
346 v4l2_fh_release(file);
349 ret = fimc_capture_ctrls_create(fimc);
354 static int fimc_capture_close(struct file *file)
356 struct fimc_dev *fimc = video_drvdata(file);
358 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
360 if (--fimc->vid_cap.refcnt == 0) {
361 fimc_stop_capture(fimc);
362 fimc_pipeline_shutdown(fimc);
363 fimc_ctrls_delete(fimc->vid_cap.ctx);
364 vb2_queue_release(&fimc->vid_cap.vbq);
367 pm_runtime_put(&fimc->pdev->dev);
369 return v4l2_fh_release(file);
372 static unsigned int fimc_capture_poll(struct file *file,
373 struct poll_table_struct *wait)
375 struct fimc_dev *fimc = video_drvdata(file);
377 return vb2_poll(&fimc->vid_cap.vbq, file, wait);
380 static int fimc_capture_mmap(struct file *file, struct vm_area_struct *vma)
382 struct fimc_dev *fimc = video_drvdata(file);
384 return vb2_mmap(&fimc->vid_cap.vbq, vma);
387 /* video device file operations */
388 static const struct v4l2_file_operations fimc_capture_fops = {
389 .owner = THIS_MODULE,
390 .open = fimc_capture_open,
391 .release = fimc_capture_close,
392 .poll = fimc_capture_poll,
393 .unlocked_ioctl = video_ioctl2,
394 .mmap = fimc_capture_mmap,
397 static int fimc_vidioc_querycap_capture(struct file *file, void *priv,
398 struct v4l2_capability *cap)
400 struct fimc_dev *fimc = video_drvdata(file);
402 strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
403 strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
404 cap->bus_info[0] = 0;
405 cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE |
406 V4L2_CAP_VIDEO_CAPTURE_MPLANE;
411 static int fimc_cap_enum_fmt_mplane(struct file *file, void *priv,
412 struct v4l2_fmtdesc *f)
414 struct fimc_fmt *fmt;
416 fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_CAM | FMT_FLAGS_M2M,
420 strncpy(f->description, fmt->name, sizeof(f->description) - 1);
421 f->pixelformat = fmt->fourcc;
422 if (fmt->fourcc == V4L2_MBUS_FMT_JPEG_1X8)
423 f->flags |= V4L2_FMT_FLAG_COMPRESSED;
433 static int fimc_cap_g_fmt_mplane(struct file *file, void *fh,
434 struct v4l2_format *f)
436 struct fimc_dev *fimc = video_drvdata(file);
437 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
439 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
442 return fimc_fill_format(&ctx->d_frame, f);
445 static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
446 struct v4l2_format *f)
448 struct fimc_dev *fimc = video_drvdata(file);
449 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
454 static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
455 struct v4l2_format *f)
457 struct fimc_dev *fimc = video_drvdata(file);
458 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
459 struct v4l2_pix_format_mplane *pix;
460 struct fimc_frame *frame;
464 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
467 if (vb2_is_busy(&fimc->vid_cap.vbq) || fimc_capture_active(fimc))
470 frame = &ctx->d_frame;
472 pix = &f->fmt.pix_mp;
473 frame->fmt = fimc_find_format(&pix->pixelformat, NULL,
474 FMT_FLAGS_M2M | FMT_FLAGS_CAM, 0);
475 if (WARN(frame->fmt == NULL, "Pixel format lookup failed\n"))
478 for (i = 0; i < frame->fmt->colplanes; i++) {
480 (pix->width * pix->height * frame->fmt->depth[i]) >> 3;
483 /* Output DMA frame pixel size and offsets. */
484 frame->f_width = pix->plane_fmt[0].bytesperline * 8
485 / frame->fmt->depth[0];
486 frame->f_height = pix->height;
487 frame->width = pix->width;
488 frame->height = pix->height;
489 frame->o_width = pix->width;
490 frame->o_height = pix->height;
494 ctx->state |= (FIMC_PARAMS | FIMC_DST_FMT);
499 static int fimc_cap_enum_input(struct file *file, void *priv,
500 struct v4l2_input *i)
502 struct fimc_dev *fimc = video_drvdata(file);
503 struct v4l2_subdev *sd = fimc->pipeline.sensor;
508 i->type = V4L2_INPUT_TYPE_CAMERA;
510 strlcpy(i->name, sd->name, sizeof(i->name));
514 static int fimc_cap_s_input(struct file *file, void *priv, unsigned int i)
516 return i == 0 ? i : -EINVAL;
519 static int fimc_cap_g_input(struct file *file, void *priv, unsigned int *i)
525 static int fimc_cap_streamon(struct file *file, void *priv,
526 enum v4l2_buf_type type)
528 struct fimc_dev *fimc = video_drvdata(file);
529 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
530 struct fimc_pipeline *p = &fimc->pipeline;
532 if (fimc_capture_active(fimc))
535 if (!(ctx->state & FIMC_DST_FMT)) {
536 v4l2_err(fimc->vid_cap.vfd, "Format is not set\n");
539 media_entity_pipeline_start(&p->sensor->entity, p->pipe);
541 return vb2_streamon(&fimc->vid_cap.vbq, type);
544 static int fimc_cap_streamoff(struct file *file, void *priv,
545 enum v4l2_buf_type type)
547 struct fimc_dev *fimc = video_drvdata(file);
548 struct v4l2_subdev *sd = fimc->pipeline.sensor;
551 ret = vb2_streamoff(&fimc->vid_cap.vbq, type);
553 media_entity_pipeline_stop(&sd->entity);
557 static int fimc_cap_reqbufs(struct file *file, void *priv,
558 struct v4l2_requestbuffers *reqbufs)
560 struct fimc_dev *fimc = video_drvdata(file);
561 int ret = vb2_reqbufs(&fimc->vid_cap.vbq, reqbufs);
564 fimc->vid_cap.reqbufs_count = reqbufs->count;
568 static int fimc_cap_querybuf(struct file *file, void *priv,
569 struct v4l2_buffer *buf)
571 struct fimc_dev *fimc = video_drvdata(file);
573 return vb2_querybuf(&fimc->vid_cap.vbq, buf);
576 static int fimc_cap_qbuf(struct file *file, void *priv,
577 struct v4l2_buffer *buf)
579 struct fimc_dev *fimc = video_drvdata(file);
581 return vb2_qbuf(&fimc->vid_cap.vbq, buf);
584 static int fimc_cap_dqbuf(struct file *file, void *priv,
585 struct v4l2_buffer *buf)
587 struct fimc_dev *fimc = video_drvdata(file);
589 return vb2_dqbuf(&fimc->vid_cap.vbq, buf, file->f_flags & O_NONBLOCK);
592 static int fimc_cap_cropcap(struct file *file, void *fh,
593 struct v4l2_cropcap *cr)
595 struct fimc_dev *fimc = video_drvdata(file);
596 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
598 if (cr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
603 cr->bounds.width = f->o_width;
604 cr->bounds.height = f->o_height;
605 cr->defrect = cr->bounds;
610 static int fimc_cap_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
612 struct fimc_dev *fimc = video_drvdata(file);
613 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
615 cr->c.left = f->offs_h;
616 cr->c.top = f->offs_v;
617 cr->c.width = f->width;
618 cr->c.height = f->height;
623 static int fimc_cap_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
625 struct fimc_dev *fimc = video_drvdata(file);
626 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
627 struct fimc_frame *f;
630 if (fimc_capture_active(fimc))
633 ret = fimc_try_crop(ctx, cr);
637 if (!(ctx->state & FIMC_DST_FMT)) {
638 v4l2_err(fimc->vid_cap.vfd, "Capture format is not set\n");
643 /* Check for the pixel scaling ratio when cropping input image. */
644 ret = fimc_check_scaler_ratio(cr->c.width, cr->c.height,
645 ctx->d_frame.width, ctx->d_frame.height,
648 v4l2_err(fimc->vid_cap.vfd, "Out of the scaler range\n");
652 f->offs_h = cr->c.left;
653 f->offs_v = cr->c.top;
654 f->width = cr->c.width;
655 f->height = cr->c.height;
660 static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
661 .vidioc_querycap = fimc_vidioc_querycap_capture,
663 .vidioc_enum_fmt_vid_cap_mplane = fimc_cap_enum_fmt_mplane,
664 .vidioc_try_fmt_vid_cap_mplane = fimc_cap_try_fmt_mplane,
665 .vidioc_s_fmt_vid_cap_mplane = fimc_cap_s_fmt_mplane,
666 .vidioc_g_fmt_vid_cap_mplane = fimc_cap_g_fmt_mplane,
668 .vidioc_reqbufs = fimc_cap_reqbufs,
669 .vidioc_querybuf = fimc_cap_querybuf,
671 .vidioc_qbuf = fimc_cap_qbuf,
672 .vidioc_dqbuf = fimc_cap_dqbuf,
674 .vidioc_streamon = fimc_cap_streamon,
675 .vidioc_streamoff = fimc_cap_streamoff,
677 .vidioc_g_crop = fimc_cap_g_crop,
678 .vidioc_s_crop = fimc_cap_s_crop,
679 .vidioc_cropcap = fimc_cap_cropcap,
681 .vidioc_enum_input = fimc_cap_enum_input,
682 .vidioc_s_input = fimc_cap_s_input,
683 .vidioc_g_input = fimc_cap_g_input,
686 /* Media operations */
687 static int fimc_link_setup(struct media_entity *entity,
688 const struct media_pad *local,
689 const struct media_pad *remote, u32 flags)
691 struct video_device *vd = media_entity_to_video_device(entity);
692 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(remote->entity);
693 struct fimc_dev *fimc = video_get_drvdata(vd);
695 if (WARN_ON(fimc == NULL))
698 dbg("%s --> %s, flags: 0x%x. input: 0x%x",
699 local->entity->name, remote->entity->name, flags,
700 fimc->vid_cap.input);
702 if (flags & MEDIA_LNK_FL_ENABLED) {
703 if (fimc->vid_cap.input != 0)
705 fimc->vid_cap.input = sd->grp_id;
709 fimc->vid_cap.input = 0;
713 static const struct media_entity_operations fimc_media_ops = {
714 .link_setup = fimc_link_setup,
717 /* fimc->lock must be already initialized */
718 int fimc_register_capture_device(struct fimc_dev *fimc,
719 struct v4l2_device *v4l2_dev)
721 struct video_device *vfd;
722 struct fimc_vid_cap *vid_cap;
723 struct fimc_ctx *ctx;
724 struct fimc_frame *fr;
728 ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
732 ctx->fimc_dev = fimc;
733 ctx->in_path = FIMC_CAMERA;
734 ctx->out_path = FIMC_DMA;
735 ctx->state = FIMC_CTX_CAP;
737 /* Default format of the output frames */
739 fr->fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_CAM, 0);
740 fr->width = fr->f_width = fr->o_width = 640;
741 fr->height = fr->f_height = fr->o_height = 480;
743 vfd = video_device_alloc();
745 v4l2_err(v4l2_dev, "Failed to allocate video device\n");
749 snprintf(vfd->name, sizeof(vfd->name), "%s.capture",
750 dev_name(&fimc->pdev->dev));
752 vfd->fops = &fimc_capture_fops;
753 vfd->ioctl_ops = &fimc_capture_ioctl_ops;
754 vfd->v4l2_dev = v4l2_dev;
756 vfd->release = video_device_release;
757 vfd->lock = &fimc->lock;
758 video_set_drvdata(vfd, fimc);
760 vid_cap = &fimc->vid_cap;
762 vid_cap->active_buf_cnt = 0;
763 vid_cap->reqbufs_count = 0;
766 INIT_LIST_HEAD(&vid_cap->pending_buf_q);
767 INIT_LIST_HEAD(&vid_cap->active_buf_q);
768 spin_lock_init(&ctx->slock);
771 q = &fimc->vid_cap.vbq;
772 memset(q, 0, sizeof(*q));
773 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
774 q->io_modes = VB2_MMAP | VB2_USERPTR;
775 q->drv_priv = fimc->vid_cap.ctx;
776 q->ops = &fimc_capture_qops;
777 q->mem_ops = &vb2_dma_contig_memops;
778 q->buf_struct_size = sizeof(struct fimc_vid_buffer);
782 fimc->vid_cap.vd_pad.flags = MEDIA_PAD_FL_SINK;
783 ret = media_entity_init(&vfd->entity, 1, &fimc->vid_cap.vd_pad, 0);
787 vfd->entity.ops = &fimc_media_ops;
788 vfd->ctrl_handler = &ctx->ctrl_handler;
792 video_device_release(vfd);
798 void fimc_unregister_capture_device(struct fimc_dev *fimc)
800 struct video_device *vfd = fimc->vid_cap.vfd;
803 media_entity_cleanup(&vfd->entity);
804 /* Can also be called if video device was
806 video_unregister_device(vfd);
808 kfree(fimc->vid_cap.ctx);
809 fimc->vid_cap.ctx = NULL;