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 void fimc_capture_state_cleanup(struct fimc_dev
*fimc
)
35 struct fimc_vid_cap
*cap
= &fimc
->vid_cap
;
36 struct fimc_vid_buffer
*buf
;
39 spin_lock_irqsave(&fimc
->slock
, flags
);
40 fimc
->state
&= ~(1 << ST_CAPT_RUN
| 1 << ST_CAPT_PEND
|
41 1 << ST_CAPT_SHUT
| 1 << ST_CAPT_STREAM
);
43 fimc
->vid_cap
.active_buf_cnt
= 0;
45 /* Release buffers that were enqueued in the driver by videobuf2. */
46 while (!list_empty(&cap
->pending_buf_q
)) {
47 buf
= pending_queue_pop(cap
);
48 vb2_buffer_done(&buf
->vb
, VB2_BUF_STATE_ERROR
);
51 while (!list_empty(&cap
->active_buf_q
)) {
52 buf
= active_queue_pop(cap
);
53 vb2_buffer_done(&buf
->vb
, VB2_BUF_STATE_ERROR
);
56 spin_unlock_irqrestore(&fimc
->slock
, flags
);
59 static int fimc_stop_capture(struct fimc_dev
*fimc
)
61 struct fimc_vid_cap
*cap
= &fimc
->vid_cap
;
64 if (!fimc_capture_active(fimc
))
67 spin_lock_irqsave(&fimc
->slock
, flags
);
68 set_bit(ST_CAPT_SHUT
, &fimc
->state
);
69 fimc_deactivate_capture(fimc
);
70 spin_unlock_irqrestore(&fimc
->slock
, flags
);
72 wait_event_timeout(fimc
->irq_queue
,
73 !test_bit(ST_CAPT_SHUT
, &fimc
->state
),
74 FIMC_SHUTDOWN_TIMEOUT
);
76 v4l2_subdev_call(cap
->sd
, video
, s_stream
, 0);
78 fimc_capture_state_cleanup(fimc
);
79 dbg("state: 0x%lx", fimc
->state
);
84 static int start_streaming(struct vb2_queue
*q
, unsigned int count
)
86 struct fimc_ctx
*ctx
= q
->drv_priv
;
87 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
88 struct s5p_fimc_isp_info
*isp_info
;
94 ret
= v4l2_subdev_call(fimc
->vid_cap
.sd
, video
, s_stream
, 1);
95 if (ret
&& ret
!= -ENOIOCTLCMD
)
98 ret
= fimc_prepare_config(ctx
, ctx
->state
);
102 isp_info
= &fimc
->pdata
->isp_info
[fimc
->vid_cap
.input_index
];
103 fimc_hw_set_camera_type(fimc
, isp_info
);
104 fimc_hw_set_camera_source(fimc
, isp_info
);
105 fimc_hw_set_camera_offset(fimc
, &ctx
->s_frame
);
107 if (ctx
->state
& FIMC_PARAMS
) {
108 ret
= fimc_set_scaler_info(ctx
);
110 err("Scaler setup error");
113 fimc_hw_set_input_path(ctx
);
114 fimc_hw_set_prescaler(ctx
);
115 fimc_hw_set_mainscaler(ctx
);
116 fimc_hw_set_target_format(ctx
);
117 fimc_hw_set_rotation(ctx
);
118 fimc_hw_set_effect(ctx
);
121 fimc_hw_set_output_path(ctx
);
122 fimc_hw_set_out_dma(ctx
);
124 INIT_LIST_HEAD(&fimc
->vid_cap
.pending_buf_q
);
125 INIT_LIST_HEAD(&fimc
->vid_cap
.active_buf_q
);
126 fimc
->vid_cap
.frame_count
= 0;
127 fimc
->vid_cap
.buf_index
= 0;
129 set_bit(ST_CAPT_PEND
, &fimc
->state
);
131 min_bufs
= fimc
->vid_cap
.reqbufs_count
> 1 ? 2 : 1;
133 if (fimc
->vid_cap
.active_buf_cnt
>= min_bufs
)
134 fimc_activate_capture(ctx
);
138 fimc_capture_state_cleanup(fimc
);
142 static int stop_streaming(struct vb2_queue
*q
)
144 struct fimc_ctx
*ctx
= q
->drv_priv
;
145 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
147 if (!fimc_capture_active(fimc
))
150 return fimc_stop_capture(fimc
);
153 int fimc_capture_suspend(struct fimc_dev
*fimc
)
158 int fimc_capture_resume(struct fimc_dev
*fimc
)
163 static unsigned int get_plane_size(struct fimc_frame
*fr
, unsigned int plane
)
165 if (!fr
|| plane
>= fr
->fmt
->memplanes
)
167 return fr
->f_width
* fr
->f_height
* fr
->fmt
->depth
[plane
] / 8;
170 static int queue_setup(struct vb2_queue
*vq
, unsigned int *num_buffers
,
171 unsigned int *num_planes
, unsigned int sizes
[],
174 struct fimc_ctx
*ctx
= vq
->drv_priv
;
175 struct fimc_fmt
*fmt
= ctx
->d_frame
.fmt
;
181 *num_planes
= fmt
->memplanes
;
183 for (i
= 0; i
< fmt
->memplanes
; i
++) {
184 sizes
[i
] = get_plane_size(&ctx
->d_frame
, i
);
185 allocators
[i
] = ctx
->fimc_dev
->alloc_ctx
;
191 static int buffer_prepare(struct vb2_buffer
*vb
)
193 struct vb2_queue
*vq
= vb
->vb2_queue
;
194 struct fimc_ctx
*ctx
= vq
->drv_priv
;
197 if (!ctx
->d_frame
.fmt
|| vq
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
200 for (i
= 0; i
< ctx
->d_frame
.fmt
->memplanes
; i
++) {
201 unsigned long size
= get_plane_size(&ctx
->d_frame
, i
);
203 if (vb2_plane_size(vb
, i
) < size
) {
204 v4l2_err(ctx
->fimc_dev
->vid_cap
.vfd
,
205 "User buffer too small (%ld < %ld)\n",
206 vb2_plane_size(vb
, i
), size
);
210 vb2_set_plane_payload(vb
, i
, size
);
216 static void buffer_queue(struct vb2_buffer
*vb
)
218 struct fimc_ctx
*ctx
= vb2_get_drv_priv(vb
->vb2_queue
);
219 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
220 struct fimc_vid_buffer
*buf
221 = container_of(vb
, struct fimc_vid_buffer
, vb
);
222 struct fimc_vid_cap
*vid_cap
= &fimc
->vid_cap
;
226 spin_lock_irqsave(&fimc
->slock
, flags
);
227 fimc_prepare_addr(ctx
, &buf
->vb
, &ctx
->d_frame
, &buf
->paddr
);
229 if (!test_bit(ST_CAPT_STREAM
, &fimc
->state
)
230 && vid_cap
->active_buf_cnt
< FIMC_MAX_OUT_BUFS
) {
231 /* Setup the buffer directly for processing. */
232 int buf_id
= (vid_cap
->reqbufs_count
== 1) ? -1 :
235 fimc_hw_set_output_addr(fimc
, &buf
->paddr
, buf_id
);
236 buf
->index
= vid_cap
->buf_index
;
237 active_queue_add(vid_cap
, buf
);
239 if (++vid_cap
->buf_index
>= FIMC_MAX_OUT_BUFS
)
240 vid_cap
->buf_index
= 0;
242 fimc_pending_queue_add(vid_cap
, buf
);
245 min_bufs
= vid_cap
->reqbufs_count
> 1 ? 2 : 1;
247 if (vb2_is_streaming(&vid_cap
->vbq
) &&
248 vid_cap
->active_buf_cnt
>= min_bufs
&&
249 !test_and_set_bit(ST_CAPT_STREAM
, &fimc
->state
))
250 fimc_activate_capture(ctx
);
252 spin_unlock_irqrestore(&fimc
->slock
, flags
);
255 static void fimc_lock(struct vb2_queue
*vq
)
257 struct fimc_ctx
*ctx
= vb2_get_drv_priv(vq
);
258 mutex_lock(&ctx
->fimc_dev
->lock
);
261 static void fimc_unlock(struct vb2_queue
*vq
)
263 struct fimc_ctx
*ctx
= vb2_get_drv_priv(vq
);
264 mutex_unlock(&ctx
->fimc_dev
->lock
);
267 static struct vb2_ops fimc_capture_qops
= {
268 .queue_setup
= queue_setup
,
269 .buf_prepare
= buffer_prepare
,
270 .buf_queue
= buffer_queue
,
271 .wait_prepare
= fimc_unlock
,
272 .wait_finish
= fimc_lock
,
273 .start_streaming
= start_streaming
,
274 .stop_streaming
= stop_streaming
,
278 * fimc_capture_ctrls_create - initialize the control handler
279 * Initialize the capture video node control handler and fill it
280 * with the FIMC controls. Inherit any sensor's controls if the
281 * 'user_subdev_api' flag is false (default behaviour).
282 * This function need to be called with the graph mutex held.
284 int fimc_capture_ctrls_create(struct fimc_dev
*fimc
)
286 struct fimc_vid_cap
*vid_cap
= &fimc
->vid_cap
;
289 if (WARN_ON(vid_cap
->ctx
== NULL
))
291 if (vid_cap
->ctx
->ctrls_rdy
)
294 ret
= fimc_ctrls_create(vid_cap
->ctx
);
295 if (ret
|| vid_cap
->user_subdev_api
)
298 return v4l2_ctrl_add_handler(&vid_cap
->ctx
->ctrl_handler
,
299 fimc
->pipeline
.sensor
->ctrl_handler
);
302 static int fimc_capture_open(struct file
*file
)
304 struct fimc_dev
*fimc
= video_drvdata(file
);
305 int ret
= v4l2_fh_open(file
);
310 dbg("pid: %d, state: 0x%lx", task_pid_nr(current
), fimc
->state
);
312 /* Return if the corresponding video mem2mem node is already opened. */
313 if (fimc_m2m_active(fimc
))
316 ret
= pm_runtime_get_sync(&fimc
->pdev
->dev
);
318 v4l2_fh_release(file
);
322 if (++fimc
->vid_cap
.refcnt
== 1)
323 ret
= fimc_capture_ctrls_create(fimc
);
328 static int fimc_capture_close(struct file
*file
)
330 struct fimc_dev
*fimc
= video_drvdata(file
);
332 dbg("pid: %d, state: 0x%lx", task_pid_nr(current
), fimc
->state
);
334 if (--fimc
->vid_cap
.refcnt
== 0) {
335 fimc_stop_capture(fimc
);
336 fimc_ctrls_delete(fimc
->vid_cap
.ctx
);
337 vb2_queue_release(&fimc
->vid_cap
.vbq
);
340 pm_runtime_put(&fimc
->pdev
->dev
);
342 return v4l2_fh_release(file
);
345 static unsigned int fimc_capture_poll(struct file
*file
,
346 struct poll_table_struct
*wait
)
348 struct fimc_dev
*fimc
= video_drvdata(file
);
350 return vb2_poll(&fimc
->vid_cap
.vbq
, file
, wait
);
353 static int fimc_capture_mmap(struct file
*file
, struct vm_area_struct
*vma
)
355 struct fimc_dev
*fimc
= video_drvdata(file
);
357 return vb2_mmap(&fimc
->vid_cap
.vbq
, vma
);
360 /* video device file operations */
361 static const struct v4l2_file_operations fimc_capture_fops
= {
362 .owner
= THIS_MODULE
,
363 .open
= fimc_capture_open
,
364 .release
= fimc_capture_close
,
365 .poll
= fimc_capture_poll
,
366 .unlocked_ioctl
= video_ioctl2
,
367 .mmap
= fimc_capture_mmap
,
370 static int fimc_vidioc_querycap_capture(struct file
*file
, void *priv
,
371 struct v4l2_capability
*cap
)
373 struct fimc_dev
*fimc
= video_drvdata(file
);
375 strncpy(cap
->driver
, fimc
->pdev
->name
, sizeof(cap
->driver
) - 1);
376 strncpy(cap
->card
, fimc
->pdev
->name
, sizeof(cap
->card
) - 1);
377 cap
->bus_info
[0] = 0;
378 cap
->capabilities
= V4L2_CAP_STREAMING
| V4L2_CAP_VIDEO_CAPTURE
|
379 V4L2_CAP_VIDEO_CAPTURE_MPLANE
;
384 /* Synchronize formats of the camera interface input and attached sensor. */
385 static int sync_capture_fmt(struct fimc_ctx
*ctx
)
387 struct fimc_frame
*frame
= &ctx
->s_frame
;
388 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
389 struct v4l2_mbus_framefmt
*fmt
= &fimc
->vid_cap
.fmt
;
392 fmt
->width
= ctx
->d_frame
.o_width
;
393 fmt
->height
= ctx
->d_frame
.o_height
;
395 ret
= v4l2_subdev_call(fimc
->vid_cap
.sd
, video
, s_mbus_fmt
, fmt
);
396 if (ret
== -ENOIOCTLCMD
) {
397 err("s_mbus_fmt failed");
400 dbg("w: %d, h: %d, code= %d", fmt
->width
, fmt
->height
, fmt
->code
);
402 frame
->fmt
= find_mbus_format(fmt
, FMT_FLAGS_CAM
);
404 err("fimc source format not found\n");
408 frame
->f_width
= fmt
->width
;
409 frame
->f_height
= fmt
->height
;
410 frame
->width
= fmt
->width
;
411 frame
->height
= fmt
->height
;
412 frame
->o_width
= fmt
->width
;
413 frame
->o_height
= fmt
->height
;
420 static int fimc_cap_g_fmt_mplane(struct file
*file
, void *fh
,
421 struct v4l2_format
*f
)
423 struct fimc_dev
*fimc
= video_drvdata(file
);
424 struct fimc_ctx
*ctx
= fimc
->vid_cap
.ctx
;
426 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
429 return fimc_fill_format(&ctx
->d_frame
, f
);
432 static int fimc_cap_try_fmt_mplane(struct file
*file
, void *fh
,
433 struct v4l2_format
*f
)
435 struct fimc_dev
*fimc
= video_drvdata(file
);
436 struct fimc_ctx
*ctx
= fimc
->vid_cap
.ctx
;
438 return fimc_try_fmt_mplane(ctx
, f
);
441 static int fimc_cap_s_fmt_mplane(struct file
*file
, void *priv
,
442 struct v4l2_format
*f
)
444 struct fimc_dev
*fimc
= video_drvdata(file
);
445 struct fimc_ctx
*ctx
= fimc
->vid_cap
.ctx
;
446 struct v4l2_pix_format_mplane
*pix
;
447 struct fimc_frame
*frame
;
451 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
454 ret
= fimc_try_fmt_mplane(ctx
, f
);
458 if (vb2_is_busy(&fimc
->vid_cap
.vbq
) || fimc_capture_active(fimc
))
461 frame
= &ctx
->d_frame
;
463 pix
= &f
->fmt
.pix_mp
;
464 frame
->fmt
= find_format(f
, FMT_FLAGS_M2M
| FMT_FLAGS_CAM
);
466 v4l2_err(fimc
->vid_cap
.vfd
,
467 "Not supported capture (FIMC target) color format\n");
471 for (i
= 0; i
< frame
->fmt
->colplanes
; i
++) {
473 (pix
->width
* pix
->height
* frame
->fmt
->depth
[i
]) >> 3;
476 /* Output DMA frame pixel size and offsets. */
477 frame
->f_width
= pix
->plane_fmt
[0].bytesperline
* 8
478 / frame
->fmt
->depth
[0];
479 frame
->f_height
= pix
->height
;
480 frame
->width
= pix
->width
;
481 frame
->height
= pix
->height
;
482 frame
->o_width
= pix
->width
;
483 frame
->o_height
= pix
->height
;
487 ctx
->state
|= (FIMC_PARAMS
| FIMC_DST_FMT
);
489 ret
= sync_capture_fmt(ctx
);
493 static int fimc_cap_enum_input(struct file
*file
, void *priv
,
494 struct v4l2_input
*i
)
496 struct fimc_dev
*fimc
= video_drvdata(file
);
502 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
506 static int fimc_cap_s_input(struct file
*file
, void *priv
, unsigned int i
)
508 return i
== 0 ? i
: -EINVAL
;
511 static int fimc_cap_g_input(struct file
*file
, void *priv
, unsigned int *i
)
517 static int fimc_cap_streamon(struct file
*file
, void *priv
,
518 enum v4l2_buf_type type
)
520 struct fimc_dev
*fimc
= video_drvdata(file
);
521 struct fimc_ctx
*ctx
= fimc
->vid_cap
.ctx
;
523 if (fimc_capture_active(fimc
) || !fimc
->vid_cap
.sd
)
526 if (!(ctx
->state
& FIMC_DST_FMT
)) {
527 v4l2_err(fimc
->vid_cap
.vfd
, "Format is not set\n");
531 return vb2_streamon(&fimc
->vid_cap
.vbq
, type
);
534 static int fimc_cap_streamoff(struct file
*file
, void *priv
,
535 enum v4l2_buf_type type
)
537 struct fimc_dev
*fimc
= video_drvdata(file
);
539 return vb2_streamoff(&fimc
->vid_cap
.vbq
, type
);
542 static int fimc_cap_reqbufs(struct file
*file
, void *priv
,
543 struct v4l2_requestbuffers
*reqbufs
)
545 struct fimc_dev
*fimc
= video_drvdata(file
);
546 int ret
= vb2_reqbufs(&fimc
->vid_cap
.vbq
, reqbufs
);
549 fimc
->vid_cap
.reqbufs_count
= reqbufs
->count
;
553 static int fimc_cap_querybuf(struct file
*file
, void *priv
,
554 struct v4l2_buffer
*buf
)
556 struct fimc_dev
*fimc
= video_drvdata(file
);
558 return vb2_querybuf(&fimc
->vid_cap
.vbq
, buf
);
561 static int fimc_cap_qbuf(struct file
*file
, void *priv
,
562 struct v4l2_buffer
*buf
)
564 struct fimc_dev
*fimc
= video_drvdata(file
);
566 return vb2_qbuf(&fimc
->vid_cap
.vbq
, buf
);
569 static int fimc_cap_dqbuf(struct file
*file
, void *priv
,
570 struct v4l2_buffer
*buf
)
572 struct fimc_dev
*fimc
= video_drvdata(file
);
574 return vb2_dqbuf(&fimc
->vid_cap
.vbq
, buf
, file
->f_flags
& O_NONBLOCK
);
577 static int fimc_cap_cropcap(struct file
*file
, void *fh
,
578 struct v4l2_cropcap
*cr
)
580 struct fimc_dev
*fimc
= video_drvdata(file
);
581 struct fimc_frame
*f
= &fimc
->vid_cap
.ctx
->s_frame
;
583 if (cr
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
588 cr
->bounds
.width
= f
->o_width
;
589 cr
->bounds
.height
= f
->o_height
;
590 cr
->defrect
= cr
->bounds
;
595 static int fimc_cap_g_crop(struct file
*file
, void *fh
, struct v4l2_crop
*cr
)
597 struct fimc_dev
*fimc
= video_drvdata(file
);
598 struct fimc_frame
*f
= &fimc
->vid_cap
.ctx
->s_frame
;
600 cr
->c
.left
= f
->offs_h
;
601 cr
->c
.top
= f
->offs_v
;
602 cr
->c
.width
= f
->width
;
603 cr
->c
.height
= f
->height
;
608 static int fimc_cap_s_crop(struct file
*file
, void *fh
, struct v4l2_crop
*cr
)
610 struct fimc_dev
*fimc
= video_drvdata(file
);
611 struct fimc_ctx
*ctx
= fimc
->vid_cap
.ctx
;
612 struct fimc_frame
*f
;
615 if (fimc_capture_active(fimc
))
618 ret
= fimc_try_crop(ctx
, cr
);
622 if (!(ctx
->state
& FIMC_DST_FMT
)) {
623 v4l2_err(fimc
->vid_cap
.vfd
, "Capture format is not set\n");
628 /* Check for the pixel scaling ratio when cropping input image. */
629 ret
= fimc_check_scaler_ratio(cr
->c
.width
, cr
->c
.height
,
630 ctx
->d_frame
.width
, ctx
->d_frame
.height
,
633 v4l2_err(fimc
->vid_cap
.vfd
, "Out of the scaler range\n");
637 f
->offs_h
= cr
->c
.left
;
638 f
->offs_v
= cr
->c
.top
;
639 f
->width
= cr
->c
.width
;
640 f
->height
= cr
->c
.height
;
646 static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops
= {
647 .vidioc_querycap
= fimc_vidioc_querycap_capture
,
649 .vidioc_enum_fmt_vid_cap_mplane
= fimc_vidioc_enum_fmt_mplane
,
650 .vidioc_try_fmt_vid_cap_mplane
= fimc_cap_try_fmt_mplane
,
651 .vidioc_s_fmt_vid_cap_mplane
= fimc_cap_s_fmt_mplane
,
652 .vidioc_g_fmt_vid_cap_mplane
= fimc_cap_g_fmt_mplane
,
654 .vidioc_reqbufs
= fimc_cap_reqbufs
,
655 .vidioc_querybuf
= fimc_cap_querybuf
,
657 .vidioc_qbuf
= fimc_cap_qbuf
,
658 .vidioc_dqbuf
= fimc_cap_dqbuf
,
660 .vidioc_streamon
= fimc_cap_streamon
,
661 .vidioc_streamoff
= fimc_cap_streamoff
,
663 .vidioc_g_crop
= fimc_cap_g_crop
,
664 .vidioc_s_crop
= fimc_cap_s_crop
,
665 .vidioc_cropcap
= fimc_cap_cropcap
,
667 .vidioc_enum_input
= fimc_cap_enum_input
,
668 .vidioc_s_input
= fimc_cap_s_input
,
669 .vidioc_g_input
= fimc_cap_g_input
,
672 /* fimc->lock must be already initialized */
673 int fimc_register_capture_device(struct fimc_dev
*fimc
,
674 struct v4l2_device
*v4l2_dev
)
676 struct video_device
*vfd
;
677 struct fimc_vid_cap
*vid_cap
;
678 struct fimc_ctx
*ctx
;
679 struct v4l2_format f
;
680 struct fimc_frame
*fr
;
684 ctx
= kzalloc(sizeof *ctx
, GFP_KERNEL
);
688 ctx
->fimc_dev
= fimc
;
689 ctx
->in_path
= FIMC_CAMERA
;
690 ctx
->out_path
= FIMC_DMA
;
691 ctx
->state
= FIMC_CTX_CAP
;
693 /* Default format of the output frames */
694 f
.fmt
.pix
.pixelformat
= V4L2_PIX_FMT_RGB32
;
696 fr
->fmt
= find_format(&f
, FMT_FLAGS_M2M
);
697 fr
->width
= fr
->f_width
= fr
->o_width
= 640;
698 fr
->height
= fr
->f_height
= fr
->o_height
= 480;
700 vfd
= video_device_alloc();
702 v4l2_err(v4l2_dev
, "Failed to allocate video device\n");
706 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s.capture",
707 dev_name(&fimc
->pdev
->dev
));
709 vfd
->fops
= &fimc_capture_fops
;
710 vfd
->ioctl_ops
= &fimc_capture_ioctl_ops
;
711 vfd
->v4l2_dev
= v4l2_dev
;
713 vfd
->release
= video_device_release
;
714 vfd
->lock
= &fimc
->lock
;
715 video_set_drvdata(vfd
, fimc
);
717 vid_cap
= &fimc
->vid_cap
;
719 vid_cap
->active_buf_cnt
= 0;
720 vid_cap
->reqbufs_count
= 0;
722 /* Default color format for image sensor */
723 vid_cap
->fmt
.code
= V4L2_MBUS_FMT_YUYV8_2X8
;
725 INIT_LIST_HEAD(&vid_cap
->pending_buf_q
);
726 INIT_LIST_HEAD(&vid_cap
->active_buf_q
);
727 spin_lock_init(&ctx
->slock
);
730 q
= &fimc
->vid_cap
.vbq
;
731 memset(q
, 0, sizeof(*q
));
732 q
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
;
733 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
;
734 q
->drv_priv
= fimc
->vid_cap
.ctx
;
735 q
->ops
= &fimc_capture_qops
;
736 q
->mem_ops
= &vb2_dma_contig_memops
;
737 q
->buf_struct_size
= sizeof(struct fimc_vid_buffer
);
741 fimc
->vid_cap
.vd_pad
.flags
= MEDIA_PAD_FL_SINK
;
742 ret
= media_entity_init(&vfd
->entity
, 1, &fimc
->vid_cap
.vd_pad
, 0);
746 vfd
->ctrl_handler
= &ctx
->ctrl_handler
;
750 video_device_release(vfd
);
756 void fimc_unregister_capture_device(struct fimc_dev
*fimc
)
758 struct video_device
*vfd
= fimc
->vid_cap
.vfd
;
761 media_entity_cleanup(&vfd
->entity
);
762 /* Can also be called if video device was
764 video_unregister_device(vfd
);
766 kfree(fimc
->vid_cap
.ctx
);
767 fimc
->vid_cap
.ctx
= NULL
;