2 * Samsung S5P SoC series camera interface (camera capture) driver
4 * Copyright (c) 2010 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/version.h>
15 #include <linux/types.h>
16 #include <linux/errno.h>
17 #include <linux/bug.h>
18 #include <linux/interrupt.h>
19 #include <linux/device.h>
20 #include <linux/platform_device.h>
21 #include <linux/list.h>
22 #include <linux/slab.h>
23 #include <linux/clk.h>
24 #include <linux/i2c.h>
26 #include <linux/videodev2.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-ioctl.h>
29 #include <media/v4l2-mem2mem.h>
30 #include <media/videobuf-core.h>
31 #include <media/videobuf-dma-contig.h>
33 #include "fimc-core.h"
35 static struct v4l2_subdev
*fimc_subdev_register(struct fimc_dev
*fimc
,
36 struct s3c_fimc_isp_info
*isp_info
)
38 struct i2c_adapter
*i2c_adap
;
39 struct fimc_vid_cap
*vid_cap
= &fimc
->vid_cap
;
40 struct v4l2_subdev
*sd
= NULL
;
42 i2c_adap
= i2c_get_adapter(isp_info
->i2c_bus_num
);
44 return ERR_PTR(-ENOMEM
);
46 sd
= v4l2_i2c_new_subdev_board(&vid_cap
->v4l2_dev
, i2c_adap
,
47 isp_info
->board_info
, NULL
);
49 v4l2_err(&vid_cap
->v4l2_dev
, "failed to acquire subdev\n");
53 v4l2_info(&vid_cap
->v4l2_dev
, "subdevice %s registered successfuly\n",
54 isp_info
->board_info
->type
);
59 static void fimc_subdev_unregister(struct fimc_dev
*fimc
)
61 struct fimc_vid_cap
*vid_cap
= &fimc
->vid_cap
;
62 struct i2c_client
*client
;
64 if (vid_cap
->input_index
< 0)
65 return; /* Subdevice already released or not registered. */
68 v4l2_device_unregister_subdev(vid_cap
->sd
);
69 client
= v4l2_get_subdevdata(vid_cap
->sd
);
70 i2c_unregister_device(client
);
71 i2c_put_adapter(client
->adapter
);
75 vid_cap
->input_index
= -1;
79 * fimc_subdev_attach - attach v4l2_subdev to camera host interface
81 * @fimc: FIMC device information
82 * @index: index to the array of available subdevices,
83 * -1 for full array search or non negative value
84 * to select specific subdevice
86 static int fimc_subdev_attach(struct fimc_dev
*fimc
, int index
)
88 struct fimc_vid_cap
*vid_cap
= &fimc
->vid_cap
;
89 struct s3c_platform_fimc
*pdata
= fimc
->pdata
;
90 struct s3c_fimc_isp_info
*isp_info
;
91 struct v4l2_subdev
*sd
;
94 for (i
= 0; i
< FIMC_MAX_CAMIF_CLIENTS
; ++i
) {
95 isp_info
= pdata
->isp_info
[i
];
97 if (!isp_info
|| (index
>= 0 && i
!= index
))
100 sd
= fimc_subdev_register(fimc
, isp_info
);
103 vid_cap
->input_index
= i
;
109 vid_cap
->input_index
= -1;
111 v4l2_err(&vid_cap
->v4l2_dev
, "fimc%d: sensor attach failed\n",
116 static int fimc_isp_subdev_init(struct fimc_dev
*fimc
, int index
)
118 struct s3c_fimc_isp_info
*isp_info
;
121 ret
= fimc_subdev_attach(fimc
, index
);
125 isp_info
= fimc
->pdata
->isp_info
[fimc
->vid_cap
.input_index
];
126 ret
= fimc_hw_set_camera_polarity(fimc
, isp_info
);
128 ret
= v4l2_subdev_call(fimc
->vid_cap
.sd
, core
,
134 fimc_subdev_unregister(fimc
);
135 err("ISP initialization failed: %d", ret
);
140 * At least one buffer on the pending_buf_q queue is required.
141 * Locking: The caller holds fimc->slock spinlock.
143 int fimc_vid_cap_buf_queue(struct fimc_dev
*fimc
,
144 struct fimc_vid_buffer
*fimc_vb
)
146 struct fimc_vid_cap
*cap
= &fimc
->vid_cap
;
147 struct fimc_ctx
*ctx
= cap
->ctx
;
150 BUG_ON(!fimc
|| !fimc_vb
);
152 ret
= fimc_prepare_addr(ctx
, fimc_vb
, &ctx
->d_frame
,
157 if (test_bit(ST_CAPT_STREAM
, &fimc
->state
)) {
158 fimc_pending_queue_add(cap
, fimc_vb
);
160 /* Setup the buffer directly for processing. */
161 int buf_id
= (cap
->reqbufs_count
== 1) ? -1 : cap
->buf_index
;
162 fimc_hw_set_output_addr(fimc
, &fimc_vb
->paddr
, buf_id
);
164 fimc_vb
->index
= cap
->buf_index
;
165 active_queue_add(cap
, fimc_vb
);
167 if (++cap
->buf_index
>= FIMC_MAX_OUT_BUFS
)
173 static int fimc_stop_capture(struct fimc_dev
*fimc
)
176 struct fimc_vid_cap
*cap
;
179 cap
= &fimc
->vid_cap
;
181 if (!fimc_capture_active(fimc
))
184 spin_lock_irqsave(&fimc
->slock
, flags
);
185 set_bit(ST_CAPT_SHUT
, &fimc
->state
);
186 fimc_deactivate_capture(fimc
);
187 spin_unlock_irqrestore(&fimc
->slock
, flags
);
189 wait_event_timeout(fimc
->irq_queue
,
190 test_bit(ST_CAPT_SHUT
, &fimc
->state
),
191 FIMC_SHUTDOWN_TIMEOUT
);
193 ret
= v4l2_subdev_call(cap
->sd
, video
, s_stream
, 0);
195 v4l2_err(&fimc
->vid_cap
.v4l2_dev
, "s_stream(0) failed\n");
197 spin_lock_irqsave(&fimc
->slock
, flags
);
198 fimc
->state
&= ~(1 << ST_CAPT_RUN
| 1 << ST_CAPT_PEND
|
199 1 << ST_CAPT_STREAM
);
201 fimc
->vid_cap
.active_buf_cnt
= 0;
202 spin_unlock_irqrestore(&fimc
->slock
, flags
);
204 dbg("state: 0x%lx", fimc
->state
);
208 static int fimc_capture_open(struct file
*file
)
210 struct fimc_dev
*fimc
= video_drvdata(file
);
213 dbg("pid: %d, state: 0x%lx", task_pid_nr(current
), fimc
->state
);
215 /* Return if the corresponding video mem2mem node is already opened. */
216 if (fimc_m2m_active(fimc
))
219 if (mutex_lock_interruptible(&fimc
->lock
))
222 if (++fimc
->vid_cap
.refcnt
== 1) {
223 ret
= fimc_isp_subdev_init(fimc
, -1);
225 fimc
->vid_cap
.refcnt
--;
230 file
->private_data
= fimc
->vid_cap
.ctx
;
232 mutex_unlock(&fimc
->lock
);
236 static int fimc_capture_close(struct file
*file
)
238 struct fimc_dev
*fimc
= video_drvdata(file
);
240 if (mutex_lock_interruptible(&fimc
->lock
))
243 dbg("pid: %d, state: 0x%lx", task_pid_nr(current
), fimc
->state
);
245 if (--fimc
->vid_cap
.refcnt
== 0) {
246 fimc_stop_capture(fimc
);
248 videobuf_stop(&fimc
->vid_cap
.vbq
);
249 videobuf_mmap_free(&fimc
->vid_cap
.vbq
);
251 v4l2_err(&fimc
->vid_cap
.v4l2_dev
, "releasing ISP\n");
252 v4l2_subdev_call(fimc
->vid_cap
.sd
, core
, s_power
, 0);
253 fimc_subdev_unregister(fimc
);
256 mutex_unlock(&fimc
->lock
);
260 static unsigned int fimc_capture_poll(struct file
*file
,
261 struct poll_table_struct
*wait
)
263 struct fimc_ctx
*ctx
= file
->private_data
;
264 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
265 struct fimc_vid_cap
*cap
= &fimc
->vid_cap
;
268 if (mutex_lock_interruptible(&fimc
->lock
))
271 ret
= videobuf_poll_stream(file
, &cap
->vbq
, wait
);
272 mutex_unlock(&fimc
->lock
);
277 static int fimc_capture_mmap(struct file
*file
, struct vm_area_struct
*vma
)
279 struct fimc_ctx
*ctx
= file
->private_data
;
280 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
281 struct fimc_vid_cap
*cap
= &fimc
->vid_cap
;
284 if (mutex_lock_interruptible(&fimc
->lock
))
287 ret
= videobuf_mmap_mapper(&cap
->vbq
, vma
);
288 mutex_unlock(&fimc
->lock
);
293 /* video device file operations */
294 static const struct v4l2_file_operations fimc_capture_fops
= {
295 .owner
= THIS_MODULE
,
296 .open
= fimc_capture_open
,
297 .release
= fimc_capture_close
,
298 .poll
= fimc_capture_poll
,
299 .unlocked_ioctl
= video_ioctl2
,
300 .mmap
= fimc_capture_mmap
,
303 static int fimc_vidioc_querycap_capture(struct file
*file
, void *priv
,
304 struct v4l2_capability
*cap
)
306 struct fimc_ctx
*ctx
= file
->private_data
;
307 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
309 strncpy(cap
->driver
, fimc
->pdev
->name
, sizeof(cap
->driver
) - 1);
310 strncpy(cap
->card
, fimc
->pdev
->name
, sizeof(cap
->card
) - 1);
311 cap
->bus_info
[0] = 0;
312 cap
->version
= KERNEL_VERSION(1, 0, 0);
313 cap
->capabilities
= V4L2_CAP_STREAMING
| V4L2_CAP_VIDEO_CAPTURE
;
318 /* Synchronize formats of the camera interface input and attached sensor. */
319 static int sync_capture_fmt(struct fimc_ctx
*ctx
)
321 struct fimc_frame
*frame
= &ctx
->s_frame
;
322 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
323 struct v4l2_mbus_framefmt
*fmt
= &fimc
->vid_cap
.fmt
;
326 fmt
->width
= ctx
->d_frame
.o_width
;
327 fmt
->height
= ctx
->d_frame
.o_height
;
329 ret
= v4l2_subdev_call(fimc
->vid_cap
.sd
, video
, s_mbus_fmt
, fmt
);
330 if (ret
== -ENOIOCTLCMD
) {
331 err("s_mbus_fmt failed");
334 dbg("w: %d, h: %d, code= %d", fmt
->width
, fmt
->height
, fmt
->code
);
336 frame
->fmt
= find_mbus_format(fmt
, FMT_FLAGS_CAM
);
338 err("fimc source format not found\n");
342 frame
->f_width
= fmt
->width
;
343 frame
->f_height
= fmt
->height
;
344 frame
->width
= fmt
->width
;
345 frame
->height
= fmt
->height
;
346 frame
->o_width
= fmt
->width
;
347 frame
->o_height
= fmt
->height
;
354 static int fimc_cap_s_fmt(struct file
*file
, void *priv
,
355 struct v4l2_format
*f
)
357 struct fimc_ctx
*ctx
= priv
;
358 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
359 struct fimc_frame
*frame
;
360 struct v4l2_pix_format
*pix
;
363 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
366 ret
= fimc_vidioc_try_fmt(file
, priv
, f
);
370 if (mutex_lock_interruptible(&fimc
->lock
))
373 if (fimc_capture_active(fimc
)) {
378 frame
= &ctx
->d_frame
;
381 frame
->fmt
= find_format(f
, FMT_FLAGS_M2M
| FMT_FLAGS_CAM
);
383 err("fimc target format not found\n");
388 /* Output DMA frame pixel size and offsets. */
389 frame
->f_width
= pix
->bytesperline
* 8 / frame
->fmt
->depth
;
390 frame
->f_height
= pix
->height
;
391 frame
->width
= pix
->width
;
392 frame
->height
= pix
->height
;
393 frame
->o_width
= pix
->width
;
394 frame
->o_height
= pix
->height
;
395 frame
->size
= (pix
->width
* pix
->height
* frame
->fmt
->depth
) >> 3;
399 ret
= sync_capture_fmt(ctx
);
401 ctx
->state
|= (FIMC_PARAMS
| FIMC_DST_FMT
);
404 mutex_unlock(&fimc
->lock
);
408 static int fimc_cap_enum_input(struct file
*file
, void *priv
,
409 struct v4l2_input
*i
)
411 struct fimc_ctx
*ctx
= priv
;
412 struct s3c_platform_fimc
*pldata
= ctx
->fimc_dev
->pdata
;
413 struct s3c_fimc_isp_info
*isp_info
;
415 if (i
->index
>= FIMC_MAX_CAMIF_CLIENTS
)
418 isp_info
= pldata
->isp_info
[i
->index
];
419 if (isp_info
== NULL
)
422 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
423 strncpy(i
->name
, isp_info
->board_info
->type
, 32);
427 static int fimc_cap_s_input(struct file
*file
, void *priv
,
430 struct fimc_ctx
*ctx
= priv
;
431 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
432 struct s3c_platform_fimc
*pdata
= fimc
->pdata
;
435 if (fimc_capture_active(ctx
->fimc_dev
))
438 if (mutex_lock_interruptible(&fimc
->lock
))
441 if (i
>= FIMC_MAX_CAMIF_CLIENTS
|| !pdata
->isp_info
[i
]) {
446 if (fimc
->vid_cap
.sd
) {
447 ret
= v4l2_subdev_call(fimc
->vid_cap
.sd
, core
, s_power
, 0);
449 err("s_power failed: %d", ret
);
452 /* Release the attached sensor subdevice. */
453 fimc_subdev_unregister(fimc
);
455 ret
= fimc_isp_subdev_init(fimc
, i
);
458 mutex_unlock(&fimc
->lock
);
462 static int fimc_cap_g_input(struct file
*file
, void *priv
,
465 struct fimc_ctx
*ctx
= priv
;
466 struct fimc_vid_cap
*cap
= &ctx
->fimc_dev
->vid_cap
;
468 *i
= cap
->input_index
;
472 static int fimc_cap_streamon(struct file
*file
, void *priv
,
473 enum v4l2_buf_type type
)
475 struct s3c_fimc_isp_info
*isp_info
;
476 struct fimc_ctx
*ctx
= priv
;
477 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
480 if (mutex_lock_interruptible(&fimc
->lock
))
483 if (fimc_capture_active(fimc
) || !fimc
->vid_cap
.sd
)
486 if (!(ctx
->state
& FIMC_DST_FMT
)) {
487 v4l2_err(&fimc
->vid_cap
.v4l2_dev
, "Format is not set\n");
492 ret
= v4l2_subdev_call(fimc
->vid_cap
.sd
, video
, s_stream
, 1);
493 if (ret
&& ret
!= -ENOIOCTLCMD
)
496 ret
= fimc_prepare_config(ctx
, ctx
->state
);
500 isp_info
= fimc
->pdata
->isp_info
[fimc
->vid_cap
.input_index
];
501 fimc_hw_set_camera_type(fimc
, isp_info
);
502 fimc_hw_set_camera_source(fimc
, isp_info
);
503 fimc_hw_set_camera_offset(fimc
, &ctx
->s_frame
);
505 if (ctx
->state
& FIMC_PARAMS
) {
506 ret
= fimc_set_scaler_info(ctx
);
508 err("Scaler setup error");
511 fimc_hw_set_input_path(ctx
);
512 fimc_hw_set_scaler(ctx
);
513 fimc_hw_set_target_format(ctx
);
514 fimc_hw_set_rotation(ctx
);
515 fimc_hw_set_effect(ctx
);
518 fimc_hw_set_output_path(ctx
);
519 fimc_hw_set_out_dma(ctx
);
521 INIT_LIST_HEAD(&fimc
->vid_cap
.pending_buf_q
);
522 INIT_LIST_HEAD(&fimc
->vid_cap
.active_buf_q
);
523 fimc
->vid_cap
.active_buf_cnt
= 0;
524 fimc
->vid_cap
.frame_count
= 0;
525 fimc
->vid_cap
.buf_index
= fimc_hw_get_frame_index(fimc
);
527 set_bit(ST_CAPT_PEND
, &fimc
->state
);
528 ret
= videobuf_streamon(&fimc
->vid_cap
.vbq
);
531 mutex_unlock(&fimc
->lock
);
535 static int fimc_cap_streamoff(struct file
*file
, void *priv
,
536 enum v4l2_buf_type type
)
538 struct fimc_ctx
*ctx
= priv
;
539 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
540 struct fimc_vid_cap
*cap
= &fimc
->vid_cap
;
544 spin_lock_irqsave(&fimc
->slock
, flags
);
545 if (!fimc_capture_running(fimc
) && !fimc_capture_pending(fimc
)) {
546 spin_unlock_irqrestore(&fimc
->slock
, flags
);
547 dbg("state: 0x%lx", fimc
->state
);
550 spin_unlock_irqrestore(&fimc
->slock
, flags
);
552 if (mutex_lock_interruptible(&fimc
->lock
))
555 fimc_stop_capture(fimc
);
556 ret
= videobuf_streamoff(&cap
->vbq
);
557 mutex_unlock(&fimc
->lock
);
561 static int fimc_cap_reqbufs(struct file
*file
, void *priv
,
562 struct v4l2_requestbuffers
*reqbufs
)
564 struct fimc_ctx
*ctx
= priv
;
565 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
566 struct fimc_vid_cap
*cap
= &fimc
->vid_cap
;
569 if (fimc_capture_active(ctx
->fimc_dev
))
572 if (mutex_lock_interruptible(&fimc
->lock
))
575 ret
= videobuf_reqbufs(&cap
->vbq
, reqbufs
);
577 cap
->reqbufs_count
= reqbufs
->count
;
579 mutex_unlock(&fimc
->lock
);
583 static int fimc_cap_querybuf(struct file
*file
, void *priv
,
584 struct v4l2_buffer
*buf
)
586 struct fimc_ctx
*ctx
= priv
;
587 struct fimc_vid_cap
*cap
= &ctx
->fimc_dev
->vid_cap
;
589 if (fimc_capture_active(ctx
->fimc_dev
))
592 return videobuf_querybuf(&cap
->vbq
, buf
);
595 static int fimc_cap_qbuf(struct file
*file
, void *priv
,
596 struct v4l2_buffer
*buf
)
598 struct fimc_ctx
*ctx
= priv
;
599 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
600 struct fimc_vid_cap
*cap
= &fimc
->vid_cap
;
603 if (mutex_lock_interruptible(&fimc
->lock
))
606 ret
= videobuf_qbuf(&cap
->vbq
, buf
);
608 mutex_unlock(&fimc
->lock
);
612 static int fimc_cap_dqbuf(struct file
*file
, void *priv
,
613 struct v4l2_buffer
*buf
)
615 struct fimc_ctx
*ctx
= priv
;
618 if (mutex_lock_interruptible(&ctx
->fimc_dev
->lock
))
621 ret
= videobuf_dqbuf(&ctx
->fimc_dev
->vid_cap
.vbq
, buf
,
622 file
->f_flags
& O_NONBLOCK
);
624 mutex_unlock(&ctx
->fimc_dev
->lock
);
628 static int fimc_cap_s_ctrl(struct file
*file
, void *priv
,
629 struct v4l2_control
*ctrl
)
631 struct fimc_ctx
*ctx
= priv
;
634 if (mutex_lock_interruptible(&ctx
->fimc_dev
->lock
))
637 /* Allow any controls but 90/270 rotation while streaming */
638 if (!fimc_capture_active(ctx
->fimc_dev
) ||
639 ctrl
->id
!= V4L2_CID_ROTATE
||
640 (ctrl
->value
!= 90 && ctrl
->value
!= 270)) {
641 ret
= check_ctrl_val(ctx
, ctrl
);
643 ret
= fimc_s_ctrl(ctx
, ctrl
);
645 ctx
->state
|= FIMC_PARAMS
;
649 ret
= v4l2_subdev_call(ctx
->fimc_dev
->vid_cap
.sd
,
652 mutex_unlock(&ctx
->fimc_dev
->lock
);
656 static int fimc_cap_cropcap(struct file
*file
, void *fh
,
657 struct v4l2_cropcap
*cr
)
659 struct fimc_frame
*f
;
660 struct fimc_ctx
*ctx
= fh
;
661 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
663 if (cr
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
666 if (mutex_lock_interruptible(&fimc
->lock
))
672 cr
->bounds
.width
= f
->o_width
;
673 cr
->bounds
.height
= f
->o_height
;
674 cr
->defrect
= cr
->bounds
;
676 mutex_unlock(&fimc
->lock
);
680 static int fimc_cap_g_crop(struct file
*file
, void *fh
, struct v4l2_crop
*cr
)
682 struct fimc_frame
*f
;
683 struct fimc_ctx
*ctx
= file
->private_data
;
684 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
687 if (mutex_lock_interruptible(&fimc
->lock
))
691 cr
->c
.left
= f
->offs_h
;
692 cr
->c
.top
= f
->offs_v
;
693 cr
->c
.width
= f
->width
;
694 cr
->c
.height
= f
->height
;
696 mutex_unlock(&fimc
->lock
);
700 static int fimc_cap_s_crop(struct file
*file
, void *fh
,
701 struct v4l2_crop
*cr
)
703 struct fimc_frame
*f
;
704 struct fimc_ctx
*ctx
= file
->private_data
;
705 struct fimc_dev
*fimc
= ctx
->fimc_dev
;
708 if (fimc_capture_active(fimc
))
711 ret
= fimc_try_crop(ctx
, cr
);
715 if (mutex_lock_interruptible(&fimc
->lock
))
718 if (!(ctx
->state
& FIMC_DST_FMT
)) {
719 v4l2_err(&fimc
->vid_cap
.v4l2_dev
,
720 "Capture color format not set\n");
725 /* Check for the pixel scaling ratio when cropping input image. */
726 ret
= fimc_check_scaler_ratio(&cr
->c
, &ctx
->d_frame
);
728 v4l2_err(&fimc
->vid_cap
.v4l2_dev
, "Out of the scaler range");
731 f
->offs_h
= cr
->c
.left
;
732 f
->offs_v
= cr
->c
.top
;
733 f
->width
= cr
->c
.width
;
734 f
->height
= cr
->c
.height
;
738 mutex_unlock(&fimc
->lock
);
743 static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops
= {
744 .vidioc_querycap
= fimc_vidioc_querycap_capture
,
746 .vidioc_enum_fmt_vid_cap
= fimc_vidioc_enum_fmt
,
747 .vidioc_try_fmt_vid_cap
= fimc_vidioc_try_fmt
,
748 .vidioc_s_fmt_vid_cap
= fimc_cap_s_fmt
,
749 .vidioc_g_fmt_vid_cap
= fimc_vidioc_g_fmt
,
751 .vidioc_reqbufs
= fimc_cap_reqbufs
,
752 .vidioc_querybuf
= fimc_cap_querybuf
,
754 .vidioc_qbuf
= fimc_cap_qbuf
,
755 .vidioc_dqbuf
= fimc_cap_dqbuf
,
757 .vidioc_streamon
= fimc_cap_streamon
,
758 .vidioc_streamoff
= fimc_cap_streamoff
,
760 .vidioc_queryctrl
= fimc_vidioc_queryctrl
,
761 .vidioc_g_ctrl
= fimc_vidioc_g_ctrl
,
762 .vidioc_s_ctrl
= fimc_cap_s_ctrl
,
764 .vidioc_g_crop
= fimc_cap_g_crop
,
765 .vidioc_s_crop
= fimc_cap_s_crop
,
766 .vidioc_cropcap
= fimc_cap_cropcap
,
768 .vidioc_enum_input
= fimc_cap_enum_input
,
769 .vidioc_s_input
= fimc_cap_s_input
,
770 .vidioc_g_input
= fimc_cap_g_input
,
773 int fimc_register_capture_device(struct fimc_dev
*fimc
)
775 struct v4l2_device
*v4l2_dev
= &fimc
->vid_cap
.v4l2_dev
;
776 struct video_device
*vfd
;
777 struct fimc_vid_cap
*vid_cap
;
778 struct fimc_ctx
*ctx
;
779 struct v4l2_format f
;
782 ctx
= kzalloc(sizeof *ctx
, GFP_KERNEL
);
786 ctx
->fimc_dev
= fimc
;
787 ctx
->in_path
= FIMC_CAMERA
;
788 ctx
->out_path
= FIMC_DMA
;
789 ctx
->state
= FIMC_CTX_CAP
;
791 f
.fmt
.pix
.pixelformat
= V4L2_PIX_FMT_RGB24
;
792 ctx
->d_frame
.fmt
= find_format(&f
, FMT_FLAGS_M2M
);
794 if (!v4l2_dev
->name
[0])
795 snprintf(v4l2_dev
->name
, sizeof(v4l2_dev
->name
),
796 "%s.capture", dev_name(&fimc
->pdev
->dev
));
798 ret
= v4l2_device_register(NULL
, v4l2_dev
);
802 vfd
= video_device_alloc();
804 v4l2_err(v4l2_dev
, "Failed to allocate video device\n");
808 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s:cap",
809 dev_name(&fimc
->pdev
->dev
));
811 vfd
->fops
= &fimc_capture_fops
;
812 vfd
->ioctl_ops
= &fimc_capture_ioctl_ops
;
814 vfd
->release
= video_device_release
;
815 video_set_drvdata(vfd
, fimc
);
817 vid_cap
= &fimc
->vid_cap
;
819 vid_cap
->active_buf_cnt
= 0;
820 vid_cap
->reqbufs_count
= 0;
822 /* The default color format for image sensor. */
823 vid_cap
->fmt
.code
= V4L2_MBUS_FMT_YUYV8_2X8
;
825 INIT_LIST_HEAD(&vid_cap
->pending_buf_q
);
826 INIT_LIST_HEAD(&vid_cap
->active_buf_q
);
827 spin_lock_init(&ctx
->slock
);
830 videobuf_queue_dma_contig_init(&vid_cap
->vbq
, &fimc_qops
,
831 vid_cap
->v4l2_dev
.dev
, &fimc
->irqlock
,
832 V4L2_BUF_TYPE_VIDEO_CAPTURE
, V4L2_FIELD_NONE
,
833 sizeof(struct fimc_vid_buffer
), (void *)ctx
, NULL
);
835 ret
= video_register_device(vfd
, VFL_TYPE_GRABBER
, -1);
837 v4l2_err(v4l2_dev
, "Failed to register video device\n");
842 "FIMC capture driver registered as /dev/video%d\n",
848 video_device_release(vfd
);
850 v4l2_device_unregister(v4l2_dev
);
852 dev_err(&fimc
->pdev
->dev
, "failed to install\n");
856 void fimc_unregister_capture_device(struct fimc_dev
*fimc
)
858 struct fimc_vid_cap
*capture
= &fimc
->vid_cap
;
861 video_unregister_device(capture
->vfd
);