4 * TI OMAP3 ISP - Generic video node
6 * Copyright (C) 2009-2010 Nokia Corporation
8 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 * Sakari Ailus <sakari.ailus@iki.fi>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <asm/cacheflush.h>
17 #include <linux/clk.h>
19 #include <linux/module.h>
20 #include <linux/pagemap.h>
21 #include <linux/scatterlist.h>
22 #include <linux/sched.h>
23 #include <linux/slab.h>
24 #include <linux/vmalloc.h>
25 #include <media/v4l2-dev.h>
26 #include <media/v4l2-ioctl.h>
27 #include <media/videobuf2-dma-contig.h>
33 /* -----------------------------------------------------------------------------
38 * NOTE: When adding new media bus codes, always remember to add
39 * corresponding in-memory formats to the table below!!!
41 static struct isp_format_info formats[] = {
42 { MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y8_1X8,
43 MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y8_1X8,
44 V4L2_PIX_FMT_GREY, 8, 1, },
45 { MEDIA_BUS_FMT_Y10_1X10, MEDIA_BUS_FMT_Y10_1X10,
46 MEDIA_BUS_FMT_Y10_1X10, MEDIA_BUS_FMT_Y8_1X8,
47 V4L2_PIX_FMT_Y10, 10, 2, },
48 { MEDIA_BUS_FMT_Y12_1X12, MEDIA_BUS_FMT_Y10_1X10,
49 MEDIA_BUS_FMT_Y12_1X12, MEDIA_BUS_FMT_Y8_1X8,
50 V4L2_PIX_FMT_Y12, 12, 2, },
51 { MEDIA_BUS_FMT_SBGGR8_1X8, MEDIA_BUS_FMT_SBGGR8_1X8,
52 MEDIA_BUS_FMT_SBGGR8_1X8, MEDIA_BUS_FMT_SBGGR8_1X8,
53 V4L2_PIX_FMT_SBGGR8, 8, 1, },
54 { MEDIA_BUS_FMT_SGBRG8_1X8, MEDIA_BUS_FMT_SGBRG8_1X8,
55 MEDIA_BUS_FMT_SGBRG8_1X8, MEDIA_BUS_FMT_SGBRG8_1X8,
56 V4L2_PIX_FMT_SGBRG8, 8, 1, },
57 { MEDIA_BUS_FMT_SGRBG8_1X8, MEDIA_BUS_FMT_SGRBG8_1X8,
58 MEDIA_BUS_FMT_SGRBG8_1X8, MEDIA_BUS_FMT_SGRBG8_1X8,
59 V4L2_PIX_FMT_SGRBG8, 8, 1, },
60 { MEDIA_BUS_FMT_SRGGB8_1X8, MEDIA_BUS_FMT_SRGGB8_1X8,
61 MEDIA_BUS_FMT_SRGGB8_1X8, MEDIA_BUS_FMT_SRGGB8_1X8,
62 V4L2_PIX_FMT_SRGGB8, 8, 1, },
63 { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8,
64 MEDIA_BUS_FMT_SBGGR10_1X10, 0,
65 V4L2_PIX_FMT_SBGGR10DPCM8, 8, 1, },
66 { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8,
67 MEDIA_BUS_FMT_SGBRG10_1X10, 0,
68 V4L2_PIX_FMT_SGBRG10DPCM8, 8, 1, },
69 { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8,
70 MEDIA_BUS_FMT_SGRBG10_1X10, 0,
71 V4L2_PIX_FMT_SGRBG10DPCM8, 8, 1, },
72 { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8,
73 MEDIA_BUS_FMT_SRGGB10_1X10, 0,
74 V4L2_PIX_FMT_SRGGB10DPCM8, 8, 1, },
75 { MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR10_1X10,
76 MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR8_1X8,
77 V4L2_PIX_FMT_SBGGR10, 10, 2, },
78 { MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG10_1X10,
79 MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG8_1X8,
80 V4L2_PIX_FMT_SGBRG10, 10, 2, },
81 { MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG10_1X10,
82 MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG8_1X8,
83 V4L2_PIX_FMT_SGRBG10, 10, 2, },
84 { MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB10_1X10,
85 MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB8_1X8,
86 V4L2_PIX_FMT_SRGGB10, 10, 2, },
87 { MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR10_1X10,
88 MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR8_1X8,
89 V4L2_PIX_FMT_SBGGR12, 12, 2, },
90 { MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG10_1X10,
91 MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG8_1X8,
92 V4L2_PIX_FMT_SGBRG12, 12, 2, },
93 { MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG10_1X10,
94 MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG8_1X8,
95 V4L2_PIX_FMT_SGRBG12, 12, 2, },
96 { MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB10_1X10,
97 MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB8_1X8,
98 V4L2_PIX_FMT_SRGGB12, 12, 2, },
99 { MEDIA_BUS_FMT_UYVY8_1X16, MEDIA_BUS_FMT_UYVY8_1X16,
100 MEDIA_BUS_FMT_UYVY8_1X16, 0,
101 V4L2_PIX_FMT_UYVY, 16, 2, },
102 { MEDIA_BUS_FMT_YUYV8_1X16, MEDIA_BUS_FMT_YUYV8_1X16,
103 MEDIA_BUS_FMT_YUYV8_1X16, 0,
104 V4L2_PIX_FMT_YUYV, 16, 2, },
105 { MEDIA_BUS_FMT_UYVY8_2X8, MEDIA_BUS_FMT_UYVY8_2X8,
106 MEDIA_BUS_FMT_UYVY8_2X8, 0,
107 V4L2_PIX_FMT_UYVY, 8, 2, },
108 { MEDIA_BUS_FMT_YUYV8_2X8, MEDIA_BUS_FMT_YUYV8_2X8,
109 MEDIA_BUS_FMT_YUYV8_2X8, 0,
110 V4L2_PIX_FMT_YUYV, 8, 2, },
111 /* Empty entry to catch the unsupported pixel code (0) used by the CCDC
112 * module and avoid NULL pointer dereferences.
117 const struct isp_format_info *omap3isp_video_format_info(u32 code)
121 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
122 if (formats[i].code == code)
130 * isp_video_mbus_to_pix - Convert v4l2_mbus_framefmt to v4l2_pix_format
131 * @video: ISP video instance
132 * @mbus: v4l2_mbus_framefmt format (input)
133 * @pix: v4l2_pix_format format (output)
135 * Fill the output pix structure with information from the input mbus format.
136 * The bytesperline and sizeimage fields are computed from the requested bytes
137 * per line value in the pix format and information from the video instance.
139 * Return the number of padding bytes at end of line.
141 static unsigned int isp_video_mbus_to_pix(const struct isp_video *video,
142 const struct v4l2_mbus_framefmt *mbus,
143 struct v4l2_pix_format *pix)
145 unsigned int bpl = pix->bytesperline;
146 unsigned int min_bpl;
149 memset(pix, 0, sizeof(*pix));
150 pix->width = mbus->width;
151 pix->height = mbus->height;
153 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
154 if (formats[i].code == mbus->code)
158 if (WARN_ON(i == ARRAY_SIZE(formats)))
161 min_bpl = pix->width * formats[i].bpp;
163 /* Clamp the requested bytes per line value. If the maximum bytes per
164 * line value is zero, the module doesn't support user configurable line
165 * sizes. Override the requested value with the minimum in that case.
168 bpl = clamp(bpl, min_bpl, video->bpl_max);
172 if (!video->bpl_zero_padding || bpl != min_bpl)
173 bpl = ALIGN(bpl, video->bpl_alignment);
175 pix->pixelformat = formats[i].pixelformat;
176 pix->bytesperline = bpl;
177 pix->sizeimage = pix->bytesperline * pix->height;
178 pix->colorspace = mbus->colorspace;
179 pix->field = mbus->field;
181 return bpl - min_bpl;
184 static void isp_video_pix_to_mbus(const struct v4l2_pix_format *pix,
185 struct v4l2_mbus_framefmt *mbus)
189 memset(mbus, 0, sizeof(*mbus));
190 mbus->width = pix->width;
191 mbus->height = pix->height;
193 /* Skip the last format in the loop so that it will be selected if no
196 for (i = 0; i < ARRAY_SIZE(formats) - 1; ++i) {
197 if (formats[i].pixelformat == pix->pixelformat)
201 mbus->code = formats[i].code;
202 mbus->colorspace = pix->colorspace;
203 mbus->field = pix->field;
206 static struct v4l2_subdev *
207 isp_video_remote_subdev(struct isp_video *video, u32 *pad)
209 struct media_pad *remote;
211 remote = media_entity_remote_pad(&video->pad);
213 if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
217 *pad = remote->index;
219 return media_entity_to_v4l2_subdev(remote->entity);
222 /* Return a pointer to the ISP video instance at the far end of the pipeline. */
223 static int isp_video_get_graph_data(struct isp_video *video,
224 struct isp_pipeline *pipe)
226 struct media_entity_graph graph;
227 struct media_entity *entity = &video->video.entity;
228 struct media_device *mdev = entity->graph_obj.mdev;
229 struct isp_video *far_end = NULL;
232 mutex_lock(&mdev->graph_mutex);
233 ret = media_entity_graph_walk_init(&graph, entity->graph_obj.mdev);
235 mutex_unlock(&mdev->graph_mutex);
239 media_entity_graph_walk_start(&graph, entity);
241 while ((entity = media_entity_graph_walk_next(&graph))) {
242 struct isp_video *__video;
244 media_entity_enum_set(&pipe->ent_enum, entity);
249 if (entity == &video->video.entity)
252 if (!is_media_entity_v4l2_io(entity))
255 __video = to_isp_video(media_entity_to_video_device(entity));
256 if (__video->type != video->type)
260 mutex_unlock(&mdev->graph_mutex);
262 media_entity_graph_walk_cleanup(&graph);
264 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
265 pipe->input = far_end;
266 pipe->output = video;
272 pipe->output = far_end;
279 __isp_video_get_format(struct isp_video *video, struct v4l2_format *format)
281 struct v4l2_subdev_format fmt;
282 struct v4l2_subdev *subdev;
286 subdev = isp_video_remote_subdev(video, &pad);
291 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
293 mutex_lock(&video->mutex);
294 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
295 mutex_unlock(&video->mutex);
300 format->type = video->type;
301 return isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
305 isp_video_check_format(struct isp_video *video, struct isp_video_fh *vfh)
307 struct v4l2_format format;
310 memcpy(&format, &vfh->format, sizeof(format));
311 ret = __isp_video_get_format(video, &format);
315 if (vfh->format.fmt.pix.pixelformat != format.fmt.pix.pixelformat ||
316 vfh->format.fmt.pix.height != format.fmt.pix.height ||
317 vfh->format.fmt.pix.width != format.fmt.pix.width ||
318 vfh->format.fmt.pix.bytesperline != format.fmt.pix.bytesperline ||
319 vfh->format.fmt.pix.sizeimage != format.fmt.pix.sizeimage ||
320 vfh->format.fmt.pix.field != format.fmt.pix.field)
326 /* -----------------------------------------------------------------------------
327 * Video queue operations
330 static int isp_video_queue_setup(struct vb2_queue *queue,
331 unsigned int *count, unsigned int *num_planes,
332 unsigned int sizes[], void *alloc_ctxs[])
334 struct isp_video_fh *vfh = vb2_get_drv_priv(queue);
335 struct isp_video *video = vfh->video;
339 sizes[0] = vfh->format.fmt.pix.sizeimage;
343 alloc_ctxs[0] = video->alloc_ctx;
345 *count = min(*count, video->capture_mem / PAGE_ALIGN(sizes[0]));
350 static int isp_video_buffer_prepare(struct vb2_buffer *buf)
352 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(buf);
353 struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2_queue);
354 struct isp_buffer *buffer = to_isp_buffer(vbuf);
355 struct isp_video *video = vfh->video;
358 /* Refuse to prepare the buffer is the video node has registered an
359 * error. We don't need to take any lock here as the operation is
360 * inherently racy. The authoritative check will be performed in the
361 * queue handler, which can't return an error, this check is just a best
362 * effort to notify userspace as early as possible.
364 if (unlikely(video->error))
367 addr = vb2_dma_contig_plane_dma_addr(buf, 0);
368 if (!IS_ALIGNED(addr, 32)) {
369 dev_dbg(video->isp->dev,
370 "Buffer address must be aligned to 32 bytes boundary.\n");
374 vb2_set_plane_payload(&buffer->vb.vb2_buf, 0,
375 vfh->format.fmt.pix.sizeimage);
382 * isp_video_buffer_queue - Add buffer to streaming queue
385 * In memory-to-memory mode, start streaming on the pipeline if buffers are
386 * queued on both the input and the output, if the pipeline isn't already busy.
387 * If the pipeline is busy, it will be restarted in the output module interrupt
390 static void isp_video_buffer_queue(struct vb2_buffer *buf)
392 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(buf);
393 struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2_queue);
394 struct isp_buffer *buffer = to_isp_buffer(vbuf);
395 struct isp_video *video = vfh->video;
396 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
397 enum isp_pipeline_state state;
402 spin_lock_irqsave(&video->irqlock, flags);
404 if (unlikely(video->error)) {
405 vb2_buffer_done(&buffer->vb.vb2_buf, VB2_BUF_STATE_ERROR);
406 spin_unlock_irqrestore(&video->irqlock, flags);
410 empty = list_empty(&video->dmaqueue);
411 list_add_tail(&buffer->irqlist, &video->dmaqueue);
413 spin_unlock_irqrestore(&video->irqlock, flags);
416 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
417 state = ISP_PIPELINE_QUEUE_OUTPUT;
419 state = ISP_PIPELINE_QUEUE_INPUT;
421 spin_lock_irqsave(&pipe->lock, flags);
422 pipe->state |= state;
423 video->ops->queue(video, buffer);
424 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_QUEUED;
426 start = isp_pipeline_ready(pipe);
428 pipe->state |= ISP_PIPELINE_STREAM;
429 spin_unlock_irqrestore(&pipe->lock, flags);
432 omap3isp_pipeline_set_stream(pipe,
433 ISP_PIPELINE_STREAM_SINGLESHOT);
438 * omap3isp_video_return_buffers - Return all queued buffers to videobuf2
439 * @video: ISP video object
440 * @state: new state for the returned buffers
442 * Return all buffers queued on the video node to videobuf2 in the given state.
443 * The buffer state should be VB2_BUF_STATE_QUEUED if called due to an error
444 * when starting the stream, or VB2_BUF_STATE_ERROR otherwise.
446 * The function must be called with the video irqlock held.
448 static void omap3isp_video_return_buffers(struct isp_video *video,
449 enum vb2_buffer_state state)
451 while (!list_empty(&video->dmaqueue)) {
452 struct isp_buffer *buf;
454 buf = list_first_entry(&video->dmaqueue,
455 struct isp_buffer, irqlist);
456 list_del(&buf->irqlist);
457 vb2_buffer_done(&buf->vb.vb2_buf, state);
461 static int isp_video_start_streaming(struct vb2_queue *queue,
464 struct isp_video_fh *vfh = vb2_get_drv_priv(queue);
465 struct isp_video *video = vfh->video;
466 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
470 /* In sensor-to-memory mode, the stream can be started synchronously
471 * to the stream on command. In memory-to-memory mode, it will be
472 * started when buffers are queued on both the input and output.
477 ret = omap3isp_pipeline_set_stream(pipe,
478 ISP_PIPELINE_STREAM_CONTINUOUS);
480 spin_lock_irqsave(&video->irqlock, flags);
481 omap3isp_video_return_buffers(video, VB2_BUF_STATE_QUEUED);
482 spin_unlock_irqrestore(&video->irqlock, flags);
486 spin_lock_irqsave(&video->irqlock, flags);
487 if (list_empty(&video->dmaqueue))
488 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
489 spin_unlock_irqrestore(&video->irqlock, flags);
494 static const struct vb2_ops isp_video_queue_ops = {
495 .queue_setup = isp_video_queue_setup,
496 .buf_prepare = isp_video_buffer_prepare,
497 .buf_queue = isp_video_buffer_queue,
498 .start_streaming = isp_video_start_streaming,
502 * omap3isp_video_buffer_next - Complete the current buffer and return the next
503 * @video: ISP video object
505 * Remove the current video buffer from the DMA queue and fill its timestamp and
506 * field count before handing it back to videobuf2.
508 * For capture video nodes the buffer state is set to VB2_BUF_STATE_DONE if no
509 * error has been flagged in the pipeline, or to VB2_BUF_STATE_ERROR otherwise.
510 * For video output nodes the buffer state is always set to VB2_BUF_STATE_DONE.
512 * The DMA queue is expected to contain at least one buffer.
514 * Return a pointer to the next buffer in the DMA queue, or NULL if the queue is
517 struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video)
519 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
520 enum vb2_buffer_state vb_state;
521 struct isp_buffer *buf;
524 spin_lock_irqsave(&video->irqlock, flags);
525 if (WARN_ON(list_empty(&video->dmaqueue))) {
526 spin_unlock_irqrestore(&video->irqlock, flags);
530 buf = list_first_entry(&video->dmaqueue, struct isp_buffer,
532 list_del(&buf->irqlist);
533 spin_unlock_irqrestore(&video->irqlock, flags);
535 buf->vb.vb2_buf.timestamp = ktime_get_ns();
537 /* Do frame number propagation only if this is the output video node.
538 * Frame number either comes from the CSI receivers or it gets
539 * incremented here if H3A is not active.
540 * Note: There is no guarantee that the output buffer will finish
541 * first, so the input number might lag behind by 1 in some cases.
543 if (video == pipe->output && !pipe->do_propagation)
545 atomic_inc_return(&pipe->frame_number);
547 buf->vb.sequence = atomic_read(&pipe->frame_number);
549 if (pipe->field != V4L2_FIELD_NONE)
550 buf->vb.sequence /= 2;
552 buf->vb.field = pipe->field;
554 /* Report pipeline errors to userspace on the capture device side. */
555 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->error) {
556 vb_state = VB2_BUF_STATE_ERROR;
559 vb_state = VB2_BUF_STATE_DONE;
562 vb2_buffer_done(&buf->vb.vb2_buf, vb_state);
564 spin_lock_irqsave(&video->irqlock, flags);
566 if (list_empty(&video->dmaqueue)) {
567 enum isp_pipeline_state state;
569 spin_unlock_irqrestore(&video->irqlock, flags);
571 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
572 state = ISP_PIPELINE_QUEUE_OUTPUT
573 | ISP_PIPELINE_STREAM;
575 state = ISP_PIPELINE_QUEUE_INPUT
576 | ISP_PIPELINE_STREAM;
578 spin_lock_irqsave(&pipe->lock, flags);
579 pipe->state &= ~state;
580 if (video->pipe.stream_state == ISP_PIPELINE_STREAM_CONTINUOUS)
581 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
582 spin_unlock_irqrestore(&pipe->lock, flags);
586 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->input != NULL) {
587 spin_lock(&pipe->lock);
588 pipe->state &= ~ISP_PIPELINE_STREAM;
589 spin_unlock(&pipe->lock);
592 buf = list_first_entry(&video->dmaqueue, struct isp_buffer,
595 spin_unlock_irqrestore(&video->irqlock, flags);
601 * omap3isp_video_cancel_stream - Cancel stream on a video node
602 * @video: ISP video object
604 * Cancelling a stream returns all buffers queued on the video node to videobuf2
605 * in the erroneous state and makes sure no new buffer can be queued.
607 void omap3isp_video_cancel_stream(struct isp_video *video)
611 spin_lock_irqsave(&video->irqlock, flags);
612 omap3isp_video_return_buffers(video, VB2_BUF_STATE_ERROR);
614 spin_unlock_irqrestore(&video->irqlock, flags);
618 * omap3isp_video_resume - Perform resume operation on the buffers
619 * @video: ISP video object
620 * @continuous: Pipeline is in single shot mode if 0 or continuous mode otherwise
622 * This function is intended to be used on suspend/resume scenario. It
623 * requests video queue layer to discard buffers marked as DONE if it's in
624 * continuous mode and requests ISP modules to queue again the ACTIVE buffer
627 void omap3isp_video_resume(struct isp_video *video, int continuous)
629 struct isp_buffer *buf = NULL;
631 if (continuous && video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
632 mutex_lock(&video->queue_lock);
633 vb2_discard_done(video->queue);
634 mutex_unlock(&video->queue_lock);
637 if (!list_empty(&video->dmaqueue)) {
638 buf = list_first_entry(&video->dmaqueue,
639 struct isp_buffer, irqlist);
640 video->ops->queue(video, buf);
641 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_QUEUED;
644 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
648 /* -----------------------------------------------------------------------------
653 isp_video_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
655 struct isp_video *video = video_drvdata(file);
657 strlcpy(cap->driver, ISP_VIDEO_DRIVER_NAME, sizeof(cap->driver));
658 strlcpy(cap->card, video->video.name, sizeof(cap->card));
659 strlcpy(cap->bus_info, "media", sizeof(cap->bus_info));
661 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT
662 | V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS;
664 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
665 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
667 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
673 isp_video_get_format(struct file *file, void *fh, struct v4l2_format *format)
675 struct isp_video_fh *vfh = to_isp_video_fh(fh);
676 struct isp_video *video = video_drvdata(file);
678 if (format->type != video->type)
681 mutex_lock(&video->mutex);
682 *format = vfh->format;
683 mutex_unlock(&video->mutex);
689 isp_video_set_format(struct file *file, void *fh, struct v4l2_format *format)
691 struct isp_video_fh *vfh = to_isp_video_fh(fh);
692 struct isp_video *video = video_drvdata(file);
693 struct v4l2_mbus_framefmt fmt;
695 if (format->type != video->type)
698 /* Replace unsupported field orders with sane defaults. */
699 switch (format->fmt.pix.field) {
700 case V4L2_FIELD_NONE:
701 /* Progressive is supported everywhere. */
703 case V4L2_FIELD_ALTERNATE:
704 /* ALTERNATE is not supported on output nodes. */
705 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
706 format->fmt.pix.field = V4L2_FIELD_NONE;
708 case V4L2_FIELD_INTERLACED:
709 /* The ISP has no concept of video standard, select the
710 * top-bottom order when the unqualified interlaced order is
713 format->fmt.pix.field = V4L2_FIELD_INTERLACED_TB;
715 case V4L2_FIELD_INTERLACED_TB:
716 case V4L2_FIELD_INTERLACED_BT:
717 /* Interlaced orders are only supported at the CCDC output. */
718 if (video != &video->isp->isp_ccdc.video_out)
719 format->fmt.pix.field = V4L2_FIELD_NONE;
722 case V4L2_FIELD_BOTTOM:
723 case V4L2_FIELD_SEQ_TB:
724 case V4L2_FIELD_SEQ_BT:
726 /* All other field orders are currently unsupported, default to
729 format->fmt.pix.field = V4L2_FIELD_NONE;
733 /* Fill the bytesperline and sizeimage fields by converting to media bus
734 * format and back to pixel format.
736 isp_video_pix_to_mbus(&format->fmt.pix, &fmt);
737 isp_video_mbus_to_pix(video, &fmt, &format->fmt.pix);
739 mutex_lock(&video->mutex);
740 vfh->format = *format;
741 mutex_unlock(&video->mutex);
747 isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format)
749 struct isp_video *video = video_drvdata(file);
750 struct v4l2_subdev_format fmt;
751 struct v4l2_subdev *subdev;
755 if (format->type != video->type)
758 subdev = isp_video_remote_subdev(video, &pad);
762 isp_video_pix_to_mbus(&format->fmt.pix, &fmt.format);
765 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
766 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
768 return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
770 isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
775 isp_video_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap)
777 struct isp_video *video = video_drvdata(file);
778 struct v4l2_subdev *subdev;
781 subdev = isp_video_remote_subdev(video, NULL);
785 mutex_lock(&video->mutex);
786 ret = v4l2_subdev_call(subdev, video, cropcap, cropcap);
787 mutex_unlock(&video->mutex);
789 return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
793 isp_video_get_crop(struct file *file, void *fh, struct v4l2_crop *crop)
795 struct isp_video *video = video_drvdata(file);
796 struct v4l2_subdev_format format;
797 struct v4l2_subdev *subdev;
801 subdev = isp_video_remote_subdev(video, &pad);
805 /* Try the get crop operation first and fallback to get format if not
808 ret = v4l2_subdev_call(subdev, video, g_crop, crop);
809 if (ret != -ENOIOCTLCMD)
813 format.which = V4L2_SUBDEV_FORMAT_ACTIVE;
814 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &format);
816 return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
820 crop->c.width = format.format.width;
821 crop->c.height = format.format.height;
827 isp_video_set_crop(struct file *file, void *fh, const struct v4l2_crop *crop)
829 struct isp_video *video = video_drvdata(file);
830 struct v4l2_subdev *subdev;
833 subdev = isp_video_remote_subdev(video, NULL);
837 mutex_lock(&video->mutex);
838 ret = v4l2_subdev_call(subdev, video, s_crop, crop);
839 mutex_unlock(&video->mutex);
841 return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
845 isp_video_get_param(struct file *file, void *fh, struct v4l2_streamparm *a)
847 struct isp_video_fh *vfh = to_isp_video_fh(fh);
848 struct isp_video *video = video_drvdata(file);
850 if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
851 video->type != a->type)
854 memset(a, 0, sizeof(*a));
855 a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
856 a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
857 a->parm.output.timeperframe = vfh->timeperframe;
863 isp_video_set_param(struct file *file, void *fh, struct v4l2_streamparm *a)
865 struct isp_video_fh *vfh = to_isp_video_fh(fh);
866 struct isp_video *video = video_drvdata(file);
868 if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
869 video->type != a->type)
872 if (a->parm.output.timeperframe.denominator == 0)
873 a->parm.output.timeperframe.denominator = 1;
875 vfh->timeperframe = a->parm.output.timeperframe;
881 isp_video_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *rb)
883 struct isp_video_fh *vfh = to_isp_video_fh(fh);
884 struct isp_video *video = video_drvdata(file);
887 mutex_lock(&video->queue_lock);
888 ret = vb2_reqbufs(&vfh->queue, rb);
889 mutex_unlock(&video->queue_lock);
895 isp_video_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
897 struct isp_video_fh *vfh = to_isp_video_fh(fh);
898 struct isp_video *video = video_drvdata(file);
901 mutex_lock(&video->queue_lock);
902 ret = vb2_querybuf(&vfh->queue, b);
903 mutex_unlock(&video->queue_lock);
909 isp_video_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
911 struct isp_video_fh *vfh = to_isp_video_fh(fh);
912 struct isp_video *video = video_drvdata(file);
915 mutex_lock(&video->queue_lock);
916 ret = vb2_qbuf(&vfh->queue, b);
917 mutex_unlock(&video->queue_lock);
923 isp_video_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
925 struct isp_video_fh *vfh = to_isp_video_fh(fh);
926 struct isp_video *video = video_drvdata(file);
929 mutex_lock(&video->queue_lock);
930 ret = vb2_dqbuf(&vfh->queue, b, file->f_flags & O_NONBLOCK);
931 mutex_unlock(&video->queue_lock);
936 static int isp_video_check_external_subdevs(struct isp_video *video,
937 struct isp_pipeline *pipe)
939 struct isp_device *isp = video->isp;
940 struct media_entity *ents[] = {
941 &isp->isp_csi2a.subdev.entity,
942 &isp->isp_csi2c.subdev.entity,
943 &isp->isp_ccp2.subdev.entity,
944 &isp->isp_ccdc.subdev.entity
946 struct media_pad *source_pad;
947 struct media_entity *source = NULL;
948 struct media_entity *sink;
949 struct v4l2_subdev_format fmt;
950 struct v4l2_ext_controls ctrls;
951 struct v4l2_ext_control ctrl;
955 /* Memory-to-memory pipelines have no external subdev. */
956 if (pipe->input != NULL)
959 for (i = 0; i < ARRAY_SIZE(ents); i++) {
960 /* Is the entity part of the pipeline? */
961 if (!media_entity_enum_test(&pipe->ent_enum, ents[i]))
964 /* ISP entities have always sink pad == 0. Find source. */
965 source_pad = media_entity_remote_pad(&ents[i]->pads[0]);
966 if (source_pad == NULL)
969 source = source_pad->entity;
975 dev_warn(isp->dev, "can't find source, failing now\n");
979 if (!is_media_entity_v4l2_subdev(source))
982 pipe->external = media_entity_to_v4l2_subdev(source);
984 fmt.pad = source_pad->index;
985 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
986 ret = v4l2_subdev_call(media_entity_to_v4l2_subdev(sink),
987 pad, get_fmt, NULL, &fmt);
988 if (unlikely(ret < 0)) {
989 dev_warn(isp->dev, "get_fmt returned null!\n");
993 pipe->external_width =
994 omap3isp_video_format_info(fmt.format.code)->width;
996 memset(&ctrls, 0, sizeof(ctrls));
997 memset(&ctrl, 0, sizeof(ctrl));
999 ctrl.id = V4L2_CID_PIXEL_RATE;
1002 ctrls.controls = &ctrl;
1004 ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, &ctrls);
1006 dev_warn(isp->dev, "no pixel rate control in subdev %s\n",
1007 pipe->external->name);
1011 pipe->external_rate = ctrl.value64;
1013 if (media_entity_enum_test(&pipe->ent_enum,
1014 &isp->isp_ccdc.subdev.entity)) {
1015 unsigned int rate = UINT_MAX;
1017 * Check that maximum allowed CCDC pixel rate isn't
1018 * exceeded by the pixel rate.
1020 omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
1021 if (pipe->external_rate > rate)
1031 * Every ISP pipeline has a single input and a single output. The input can be
1032 * either a sensor or a video node. The output is always a video node.
1034 * As every pipeline has an output video node, the ISP video objects at the
1035 * pipeline output stores the pipeline state. It tracks the streaming state of
1036 * both the input and output, as well as the availability of buffers.
1038 * In sensor-to-memory mode, frames are always available at the pipeline input.
1039 * Starting the sensor usually requires I2C transfers and must be done in
1040 * interruptible context. The pipeline is started and stopped synchronously
1041 * to the stream on/off commands. All modules in the pipeline will get their
1042 * subdev set stream handler called. The module at the end of the pipeline must
1043 * delay starting the hardware until buffers are available at its output.
1045 * In memory-to-memory mode, starting/stopping the stream requires
1046 * synchronization between the input and output. ISP modules can't be stopped
1047 * in the middle of a frame, and at least some of the modules seem to become
1048 * busy as soon as they're started, even if they don't receive a frame start
1049 * event. For that reason frames need to be processed in single-shot mode. The
1050 * driver needs to wait until a frame is completely processed and written to
1051 * memory before restarting the pipeline for the next frame. Pipelined
1052 * processing might be possible but requires more testing.
1054 * Stream start must be delayed until buffers are available at both the input
1055 * and output. The pipeline must be started in the videobuf queue callback with
1056 * the buffers queue spinlock held. The modules subdev set stream operation must
1060 isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
1062 struct isp_video_fh *vfh = to_isp_video_fh(fh);
1063 struct isp_video *video = video_drvdata(file);
1064 enum isp_pipeline_state state;
1065 struct isp_pipeline *pipe;
1066 unsigned long flags;
1069 if (type != video->type)
1072 mutex_lock(&video->stream_lock);
1074 /* Start streaming on the pipeline. No link touching an entity in the
1075 * pipeline can be activated or deactivated once streaming is started.
1077 pipe = video->video.entity.pipe
1078 ? to_isp_pipeline(&video->video.entity) : &video->pipe;
1080 ret = media_entity_enum_init(&pipe->ent_enum, &video->isp->media_dev);
1084 /* TODO: Implement PM QoS */
1085 pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
1086 pipe->max_rate = pipe->l3_ick;
1088 ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
1090 goto err_pipeline_start;
1092 /* Verify that the currently configured format matches the output of
1093 * the connected subdev.
1095 ret = isp_video_check_format(video, vfh);
1097 goto err_check_format;
1099 video->bpl_padding = ret;
1100 video->bpl_value = vfh->format.fmt.pix.bytesperline;
1102 ret = isp_video_get_graph_data(video, pipe);
1104 goto err_check_format;
1106 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1107 state = ISP_PIPELINE_STREAM_OUTPUT | ISP_PIPELINE_IDLE_OUTPUT;
1109 state = ISP_PIPELINE_STREAM_INPUT | ISP_PIPELINE_IDLE_INPUT;
1111 ret = isp_video_check_external_subdevs(video, pipe);
1113 goto err_check_format;
1115 pipe->error = false;
1117 spin_lock_irqsave(&pipe->lock, flags);
1118 pipe->state &= ~ISP_PIPELINE_STREAM;
1119 pipe->state |= state;
1120 spin_unlock_irqrestore(&pipe->lock, flags);
1122 /* Set the maximum time per frame as the value requested by userspace.
1123 * This is a soft limit that can be overridden if the hardware doesn't
1124 * support the request limit.
1126 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1127 pipe->max_timeperframe = vfh->timeperframe;
1129 video->queue = &vfh->queue;
1130 INIT_LIST_HEAD(&video->dmaqueue);
1131 atomic_set(&pipe->frame_number, -1);
1132 pipe->field = vfh->format.fmt.pix.field;
1134 mutex_lock(&video->queue_lock);
1135 ret = vb2_streamon(&vfh->queue, type);
1136 mutex_unlock(&video->queue_lock);
1138 goto err_check_format;
1140 mutex_unlock(&video->stream_lock);
1145 media_entity_pipeline_stop(&video->video.entity);
1147 /* TODO: Implement PM QoS */
1148 /* The DMA queue must be emptied here, otherwise CCDC interrupts that
1149 * will get triggered the next time the CCDC is powered up will try to
1150 * access buffers that might have been freed but still present in the
1151 * DMA queue. This can easily get triggered if the above
1152 * omap3isp_pipeline_set_stream() call fails on a system with a
1153 * free-running sensor.
1155 INIT_LIST_HEAD(&video->dmaqueue);
1156 video->queue = NULL;
1158 media_entity_enum_cleanup(&pipe->ent_enum);
1161 mutex_unlock(&video->stream_lock);
1167 isp_video_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
1169 struct isp_video_fh *vfh = to_isp_video_fh(fh);
1170 struct isp_video *video = video_drvdata(file);
1171 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
1172 enum isp_pipeline_state state;
1173 unsigned int streaming;
1174 unsigned long flags;
1176 if (type != video->type)
1179 mutex_lock(&video->stream_lock);
1181 /* Make sure we're not streaming yet. */
1182 mutex_lock(&video->queue_lock);
1183 streaming = vb2_is_streaming(&vfh->queue);
1184 mutex_unlock(&video->queue_lock);
1189 /* Update the pipeline state. */
1190 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1191 state = ISP_PIPELINE_STREAM_OUTPUT
1192 | ISP_PIPELINE_QUEUE_OUTPUT;
1194 state = ISP_PIPELINE_STREAM_INPUT
1195 | ISP_PIPELINE_QUEUE_INPUT;
1197 spin_lock_irqsave(&pipe->lock, flags);
1198 pipe->state &= ~state;
1199 spin_unlock_irqrestore(&pipe->lock, flags);
1201 /* Stop the stream. */
1202 omap3isp_pipeline_set_stream(pipe, ISP_PIPELINE_STREAM_STOPPED);
1203 omap3isp_video_cancel_stream(video);
1205 mutex_lock(&video->queue_lock);
1206 vb2_streamoff(&vfh->queue, type);
1207 mutex_unlock(&video->queue_lock);
1208 video->queue = NULL;
1209 video->error = false;
1211 /* TODO: Implement PM QoS */
1212 media_entity_pipeline_stop(&video->video.entity);
1214 media_entity_enum_cleanup(&pipe->ent_enum);
1217 mutex_unlock(&video->stream_lock);
1222 isp_video_enum_input(struct file *file, void *fh, struct v4l2_input *input)
1224 if (input->index > 0)
1227 strlcpy(input->name, "camera", sizeof(input->name));
1228 input->type = V4L2_INPUT_TYPE_CAMERA;
1234 isp_video_g_input(struct file *file, void *fh, unsigned int *input)
1242 isp_video_s_input(struct file *file, void *fh, unsigned int input)
1244 return input == 0 ? 0 : -EINVAL;
1247 static const struct v4l2_ioctl_ops isp_video_ioctl_ops = {
1248 .vidioc_querycap = isp_video_querycap,
1249 .vidioc_g_fmt_vid_cap = isp_video_get_format,
1250 .vidioc_s_fmt_vid_cap = isp_video_set_format,
1251 .vidioc_try_fmt_vid_cap = isp_video_try_format,
1252 .vidioc_g_fmt_vid_out = isp_video_get_format,
1253 .vidioc_s_fmt_vid_out = isp_video_set_format,
1254 .vidioc_try_fmt_vid_out = isp_video_try_format,
1255 .vidioc_cropcap = isp_video_cropcap,
1256 .vidioc_g_crop = isp_video_get_crop,
1257 .vidioc_s_crop = isp_video_set_crop,
1258 .vidioc_g_parm = isp_video_get_param,
1259 .vidioc_s_parm = isp_video_set_param,
1260 .vidioc_reqbufs = isp_video_reqbufs,
1261 .vidioc_querybuf = isp_video_querybuf,
1262 .vidioc_qbuf = isp_video_qbuf,
1263 .vidioc_dqbuf = isp_video_dqbuf,
1264 .vidioc_streamon = isp_video_streamon,
1265 .vidioc_streamoff = isp_video_streamoff,
1266 .vidioc_enum_input = isp_video_enum_input,
1267 .vidioc_g_input = isp_video_g_input,
1268 .vidioc_s_input = isp_video_s_input,
1271 /* -----------------------------------------------------------------------------
1272 * V4L2 file operations
1275 static int isp_video_open(struct file *file)
1277 struct isp_video *video = video_drvdata(file);
1278 struct isp_video_fh *handle;
1279 struct vb2_queue *queue;
1282 handle = kzalloc(sizeof(*handle), GFP_KERNEL);
1286 v4l2_fh_init(&handle->vfh, &video->video);
1287 v4l2_fh_add(&handle->vfh);
1289 /* If this is the first user, initialise the pipeline. */
1290 if (omap3isp_get(video->isp) == NULL) {
1295 ret = media_entity_graph_walk_init(&handle->graph,
1296 &video->isp->media_dev);
1300 ret = omap3isp_pipeline_pm_use(&video->video.entity, 1, &handle->graph);
1302 omap3isp_put(video->isp);
1306 queue = &handle->queue;
1307 queue->type = video->type;
1308 queue->io_modes = VB2_MMAP | VB2_USERPTR;
1309 queue->drv_priv = handle;
1310 queue->ops = &isp_video_queue_ops;
1311 queue->mem_ops = &vb2_dma_contig_memops;
1312 queue->buf_struct_size = sizeof(struct isp_buffer);
1313 queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1315 ret = vb2_queue_init(&handle->queue);
1317 omap3isp_put(video->isp);
1321 memset(&handle->format, 0, sizeof(handle->format));
1322 handle->format.type = video->type;
1323 handle->timeperframe.denominator = 1;
1325 handle->video = video;
1326 file->private_data = &handle->vfh;
1330 v4l2_fh_del(&handle->vfh);
1331 media_entity_graph_walk_cleanup(&handle->graph);
1338 static int isp_video_release(struct file *file)
1340 struct isp_video *video = video_drvdata(file);
1341 struct v4l2_fh *vfh = file->private_data;
1342 struct isp_video_fh *handle = to_isp_video_fh(vfh);
1344 /* Disable streaming and free the buffers queue resources. */
1345 isp_video_streamoff(file, vfh, video->type);
1347 mutex_lock(&video->queue_lock);
1348 vb2_queue_release(&handle->queue);
1349 mutex_unlock(&video->queue_lock);
1351 omap3isp_pipeline_pm_use(&video->video.entity, 0, &handle->graph);
1352 media_entity_graph_walk_cleanup(&handle->graph);
1354 /* Release the file handle. */
1357 file->private_data = NULL;
1359 omap3isp_put(video->isp);
1364 static unsigned int isp_video_poll(struct file *file, poll_table *wait)
1366 struct isp_video_fh *vfh = to_isp_video_fh(file->private_data);
1367 struct isp_video *video = video_drvdata(file);
1370 mutex_lock(&video->queue_lock);
1371 ret = vb2_poll(&vfh->queue, file, wait);
1372 mutex_unlock(&video->queue_lock);
1377 static int isp_video_mmap(struct file *file, struct vm_area_struct *vma)
1379 struct isp_video_fh *vfh = to_isp_video_fh(file->private_data);
1381 return vb2_mmap(&vfh->queue, vma);
1384 static struct v4l2_file_operations isp_video_fops = {
1385 .owner = THIS_MODULE,
1386 .unlocked_ioctl = video_ioctl2,
1387 .open = isp_video_open,
1388 .release = isp_video_release,
1389 .poll = isp_video_poll,
1390 .mmap = isp_video_mmap,
1393 /* -----------------------------------------------------------------------------
1397 static const struct isp_video_operations isp_video_dummy_ops = {
1400 int omap3isp_video_init(struct isp_video *video, const char *name)
1402 const char *direction;
1405 switch (video->type) {
1406 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1407 direction = "output";
1408 video->pad.flags = MEDIA_PAD_FL_SINK
1409 | MEDIA_PAD_FL_MUST_CONNECT;
1411 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1412 direction = "input";
1413 video->pad.flags = MEDIA_PAD_FL_SOURCE
1414 | MEDIA_PAD_FL_MUST_CONNECT;
1415 video->video.vfl_dir = VFL_DIR_TX;
1422 video->alloc_ctx = vb2_dma_contig_init_ctx(video->isp->dev);
1423 if (IS_ERR(video->alloc_ctx))
1424 return PTR_ERR(video->alloc_ctx);
1426 ret = media_entity_pads_init(&video->video.entity, 1, &video->pad);
1428 vb2_dma_contig_cleanup_ctx(video->alloc_ctx);
1432 mutex_init(&video->mutex);
1433 atomic_set(&video->active, 0);
1435 spin_lock_init(&video->pipe.lock);
1436 mutex_init(&video->stream_lock);
1437 mutex_init(&video->queue_lock);
1438 spin_lock_init(&video->irqlock);
1440 /* Initialize the video device. */
1441 if (video->ops == NULL)
1442 video->ops = &isp_video_dummy_ops;
1444 video->video.fops = &isp_video_fops;
1445 snprintf(video->video.name, sizeof(video->video.name),
1446 "OMAP3 ISP %s %s", name, direction);
1447 video->video.vfl_type = VFL_TYPE_GRABBER;
1448 video->video.release = video_device_release_empty;
1449 video->video.ioctl_ops = &isp_video_ioctl_ops;
1450 video->pipe.stream_state = ISP_PIPELINE_STREAM_STOPPED;
1452 video_set_drvdata(&video->video, video);
1457 void omap3isp_video_cleanup(struct isp_video *video)
1459 vb2_dma_contig_cleanup_ctx(video->alloc_ctx);
1460 media_entity_cleanup(&video->video.entity);
1461 mutex_destroy(&video->queue_lock);
1462 mutex_destroy(&video->stream_lock);
1463 mutex_destroy(&video->mutex);
1466 int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev)
1470 video->video.v4l2_dev = vdev;
1472 ret = video_register_device(&video->video, VFL_TYPE_GRABBER, -1);
1474 dev_err(video->isp->dev,
1475 "%s: could not register video device (%d)\n",
1481 void omap3isp_video_unregister(struct isp_video *video)
1483 if (video_is_registered(&video->video))
1484 video_unregister_device(&video->video);