1 // SPDX-License-Identifier: GPL-2.0-only
5 * TI OMAP3 ISP - Generic video node
7 * Copyright (C) 2009-2010 Nokia Corporation
9 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
10 * Sakari Ailus <sakari.ailus@iki.fi>
13 #include <asm/cacheflush.h>
14 #include <linux/clk.h>
16 #include <linux/module.h>
17 #include <linux/pagemap.h>
18 #include <linux/scatterlist.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
21 #include <linux/vmalloc.h>
23 #include <media/v4l2-dev.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-mc.h>
26 #include <media/videobuf2-dma-contig.h>
32 /* -----------------------------------------------------------------------------
37 * NOTE: When adding new media bus codes, always remember to add
38 * corresponding in-memory formats to the table below!!!
40 static struct isp_format_info formats[] = {
41 { MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y8_1X8,
42 MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y8_1X8,
43 V4L2_PIX_FMT_GREY, 8, 1, },
44 { MEDIA_BUS_FMT_Y10_1X10, MEDIA_BUS_FMT_Y10_1X10,
45 MEDIA_BUS_FMT_Y10_1X10, MEDIA_BUS_FMT_Y8_1X8,
46 V4L2_PIX_FMT_Y10, 10, 2, },
47 { MEDIA_BUS_FMT_Y12_1X12, MEDIA_BUS_FMT_Y10_1X10,
48 MEDIA_BUS_FMT_Y12_1X12, MEDIA_BUS_FMT_Y8_1X8,
49 V4L2_PIX_FMT_Y12, 12, 2, },
50 { MEDIA_BUS_FMT_SBGGR8_1X8, MEDIA_BUS_FMT_SBGGR8_1X8,
51 MEDIA_BUS_FMT_SBGGR8_1X8, MEDIA_BUS_FMT_SBGGR8_1X8,
52 V4L2_PIX_FMT_SBGGR8, 8, 1, },
53 { MEDIA_BUS_FMT_SGBRG8_1X8, MEDIA_BUS_FMT_SGBRG8_1X8,
54 MEDIA_BUS_FMT_SGBRG8_1X8, MEDIA_BUS_FMT_SGBRG8_1X8,
55 V4L2_PIX_FMT_SGBRG8, 8, 1, },
56 { MEDIA_BUS_FMT_SGRBG8_1X8, MEDIA_BUS_FMT_SGRBG8_1X8,
57 MEDIA_BUS_FMT_SGRBG8_1X8, MEDIA_BUS_FMT_SGRBG8_1X8,
58 V4L2_PIX_FMT_SGRBG8, 8, 1, },
59 { MEDIA_BUS_FMT_SRGGB8_1X8, MEDIA_BUS_FMT_SRGGB8_1X8,
60 MEDIA_BUS_FMT_SRGGB8_1X8, MEDIA_BUS_FMT_SRGGB8_1X8,
61 V4L2_PIX_FMT_SRGGB8, 8, 1, },
62 { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8,
63 MEDIA_BUS_FMT_SBGGR10_1X10, 0,
64 V4L2_PIX_FMT_SBGGR10DPCM8, 8, 1, },
65 { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8,
66 MEDIA_BUS_FMT_SGBRG10_1X10, 0,
67 V4L2_PIX_FMT_SGBRG10DPCM8, 8, 1, },
68 { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8,
69 MEDIA_BUS_FMT_SGRBG10_1X10, 0,
70 V4L2_PIX_FMT_SGRBG10DPCM8, 8, 1, },
71 { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8,
72 MEDIA_BUS_FMT_SRGGB10_1X10, 0,
73 V4L2_PIX_FMT_SRGGB10DPCM8, 8, 1, },
74 { MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR10_1X10,
75 MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR8_1X8,
76 V4L2_PIX_FMT_SBGGR10, 10, 2, },
77 { MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG10_1X10,
78 MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG8_1X8,
79 V4L2_PIX_FMT_SGBRG10, 10, 2, },
80 { MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG10_1X10,
81 MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG8_1X8,
82 V4L2_PIX_FMT_SGRBG10, 10, 2, },
83 { MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB10_1X10,
84 MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB8_1X8,
85 V4L2_PIX_FMT_SRGGB10, 10, 2, },
86 { MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR10_1X10,
87 MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR8_1X8,
88 V4L2_PIX_FMT_SBGGR12, 12, 2, },
89 { MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG10_1X10,
90 MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG8_1X8,
91 V4L2_PIX_FMT_SGBRG12, 12, 2, },
92 { MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG10_1X10,
93 MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG8_1X8,
94 V4L2_PIX_FMT_SGRBG12, 12, 2, },
95 { MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB10_1X10,
96 MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB8_1X8,
97 V4L2_PIX_FMT_SRGGB12, 12, 2, },
98 { MEDIA_BUS_FMT_UYVY8_1X16, MEDIA_BUS_FMT_UYVY8_1X16,
99 MEDIA_BUS_FMT_UYVY8_1X16, 0,
100 V4L2_PIX_FMT_UYVY, 16, 2, },
101 { MEDIA_BUS_FMT_YUYV8_1X16, MEDIA_BUS_FMT_YUYV8_1X16,
102 MEDIA_BUS_FMT_YUYV8_1X16, 0,
103 V4L2_PIX_FMT_YUYV, 16, 2, },
104 { MEDIA_BUS_FMT_UYVY8_2X8, MEDIA_BUS_FMT_UYVY8_2X8,
105 MEDIA_BUS_FMT_UYVY8_2X8, 0,
106 V4L2_PIX_FMT_UYVY, 8, 2, },
107 { MEDIA_BUS_FMT_YUYV8_2X8, MEDIA_BUS_FMT_YUYV8_2X8,
108 MEDIA_BUS_FMT_YUYV8_2X8, 0,
109 V4L2_PIX_FMT_YUYV, 8, 2, },
110 /* Empty entry to catch the unsupported pixel code (0) used by the CCDC
111 * module and avoid NULL pointer dereferences.
116 const struct isp_format_info *omap3isp_video_format_info(u32 code)
120 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
121 if (formats[i].code == code)
129 * isp_video_mbus_to_pix - Convert v4l2_mbus_framefmt to v4l2_pix_format
130 * @video: ISP video instance
131 * @mbus: v4l2_mbus_framefmt format (input)
132 * @pix: v4l2_pix_format format (output)
134 * Fill the output pix structure with information from the input mbus format.
135 * The bytesperline and sizeimage fields are computed from the requested bytes
136 * per line value in the pix format and information from the video instance.
138 * Return the number of padding bytes at end of line.
140 static unsigned int isp_video_mbus_to_pix(const struct isp_video *video,
141 const struct v4l2_mbus_framefmt *mbus,
142 struct v4l2_pix_format *pix)
144 unsigned int bpl = pix->bytesperline;
145 unsigned int min_bpl;
148 memset(pix, 0, sizeof(*pix));
149 pix->width = mbus->width;
150 pix->height = mbus->height;
152 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
153 if (formats[i].code == mbus->code)
157 if (WARN_ON(i == ARRAY_SIZE(formats)))
160 min_bpl = pix->width * formats[i].bpp;
162 /* Clamp the requested bytes per line value. If the maximum bytes per
163 * line value is zero, the module doesn't support user configurable line
164 * sizes. Override the requested value with the minimum in that case.
167 bpl = clamp(bpl, min_bpl, video->bpl_max);
171 if (!video->bpl_zero_padding || bpl != min_bpl)
172 bpl = ALIGN(bpl, video->bpl_alignment);
174 pix->pixelformat = formats[i].pixelformat;
175 pix->bytesperline = bpl;
176 pix->sizeimage = pix->bytesperline * pix->height;
177 pix->colorspace = mbus->colorspace;
178 pix->field = mbus->field;
180 return bpl - min_bpl;
183 static void isp_video_pix_to_mbus(const struct v4l2_pix_format *pix,
184 struct v4l2_mbus_framefmt *mbus)
188 memset(mbus, 0, sizeof(*mbus));
189 mbus->width = pix->width;
190 mbus->height = pix->height;
192 /* Skip the last format in the loop so that it will be selected if no
195 for (i = 0; i < ARRAY_SIZE(formats) - 1; ++i) {
196 if (formats[i].pixelformat == pix->pixelformat)
200 mbus->code = formats[i].code;
201 mbus->colorspace = pix->colorspace;
202 mbus->field = pix->field;
205 static struct v4l2_subdev *
206 isp_video_remote_subdev(struct isp_video *video, u32 *pad)
208 struct media_pad *remote;
210 remote = media_entity_remote_pad(&video->pad);
212 if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
216 *pad = remote->index;
218 return media_entity_to_v4l2_subdev(remote->entity);
221 /* Return a pointer to the ISP video instance at the far end of the pipeline. */
222 static int isp_video_get_graph_data(struct isp_video *video,
223 struct isp_pipeline *pipe)
225 struct media_graph graph;
226 struct media_entity *entity = &video->video.entity;
227 struct media_device *mdev = entity->graph_obj.mdev;
228 struct isp_video *far_end = NULL;
231 mutex_lock(&mdev->graph_mutex);
232 ret = media_graph_walk_init(&graph, mdev);
234 mutex_unlock(&mdev->graph_mutex);
238 media_graph_walk_start(&graph, entity);
240 while ((entity = media_graph_walk_next(&graph))) {
241 struct isp_video *__video;
243 media_entity_enum_set(&pipe->ent_enum, entity);
248 if (entity == &video->video.entity)
251 if (!is_media_entity_v4l2_video_device(entity))
254 __video = to_isp_video(media_entity_to_video_device(entity));
255 if (__video->type != video->type)
259 mutex_unlock(&mdev->graph_mutex);
261 media_graph_walk_cleanup(&graph);
263 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
264 pipe->input = far_end;
265 pipe->output = video;
271 pipe->output = far_end;
278 __isp_video_get_format(struct isp_video *video, struct v4l2_format *format)
280 struct v4l2_subdev_format fmt;
281 struct v4l2_subdev *subdev;
285 subdev = isp_video_remote_subdev(video, &pad);
290 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
292 mutex_lock(&video->mutex);
293 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
294 mutex_unlock(&video->mutex);
299 format->type = video->type;
300 return isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
304 isp_video_check_format(struct isp_video *video, struct isp_video_fh *vfh)
306 struct v4l2_format format;
309 memcpy(&format, &vfh->format, sizeof(format));
310 ret = __isp_video_get_format(video, &format);
314 if (vfh->format.fmt.pix.pixelformat != format.fmt.pix.pixelformat ||
315 vfh->format.fmt.pix.height != format.fmt.pix.height ||
316 vfh->format.fmt.pix.width != format.fmt.pix.width ||
317 vfh->format.fmt.pix.bytesperline != format.fmt.pix.bytesperline ||
318 vfh->format.fmt.pix.sizeimage != format.fmt.pix.sizeimage ||
319 vfh->format.fmt.pix.field != format.fmt.pix.field)
325 /* -----------------------------------------------------------------------------
326 * Video queue operations
329 static int isp_video_queue_setup(struct vb2_queue *queue,
330 unsigned int *count, unsigned int *num_planes,
331 unsigned int sizes[], struct device *alloc_devs[])
333 struct isp_video_fh *vfh = vb2_get_drv_priv(queue);
334 struct isp_video *video = vfh->video;
338 sizes[0] = vfh->format.fmt.pix.sizeimage;
342 *count = min(*count, video->capture_mem / PAGE_ALIGN(sizes[0]));
347 static int isp_video_buffer_prepare(struct vb2_buffer *buf)
349 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(buf);
350 struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2_queue);
351 struct isp_buffer *buffer = to_isp_buffer(vbuf);
352 struct isp_video *video = vfh->video;
355 /* Refuse to prepare the buffer is the video node has registered an
356 * error. We don't need to take any lock here as the operation is
357 * inherently racy. The authoritative check will be performed in the
358 * queue handler, which can't return an error, this check is just a best
359 * effort to notify userspace as early as possible.
361 if (unlikely(video->error))
364 addr = vb2_dma_contig_plane_dma_addr(buf, 0);
365 if (!IS_ALIGNED(addr, 32)) {
366 dev_dbg(video->isp->dev,
367 "Buffer address must be aligned to 32 bytes boundary.\n");
371 vb2_set_plane_payload(&buffer->vb.vb2_buf, 0,
372 vfh->format.fmt.pix.sizeimage);
379 * isp_video_buffer_queue - Add buffer to streaming queue
382 * In memory-to-memory mode, start streaming on the pipeline if buffers are
383 * queued on both the input and the output, if the pipeline isn't already busy.
384 * If the pipeline is busy, it will be restarted in the output module interrupt
387 static void isp_video_buffer_queue(struct vb2_buffer *buf)
389 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(buf);
390 struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2_queue);
391 struct isp_buffer *buffer = to_isp_buffer(vbuf);
392 struct isp_video *video = vfh->video;
393 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
394 enum isp_pipeline_state state;
399 spin_lock_irqsave(&video->irqlock, flags);
401 if (unlikely(video->error)) {
402 vb2_buffer_done(&buffer->vb.vb2_buf, VB2_BUF_STATE_ERROR);
403 spin_unlock_irqrestore(&video->irqlock, flags);
407 empty = list_empty(&video->dmaqueue);
408 list_add_tail(&buffer->irqlist, &video->dmaqueue);
410 spin_unlock_irqrestore(&video->irqlock, flags);
413 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
414 state = ISP_PIPELINE_QUEUE_OUTPUT;
416 state = ISP_PIPELINE_QUEUE_INPUT;
418 spin_lock_irqsave(&pipe->lock, flags);
419 pipe->state |= state;
420 video->ops->queue(video, buffer);
421 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_QUEUED;
423 start = isp_pipeline_ready(pipe);
425 pipe->state |= ISP_PIPELINE_STREAM;
426 spin_unlock_irqrestore(&pipe->lock, flags);
429 omap3isp_pipeline_set_stream(pipe,
430 ISP_PIPELINE_STREAM_SINGLESHOT);
435 * omap3isp_video_return_buffers - Return all queued buffers to videobuf2
436 * @video: ISP video object
437 * @state: new state for the returned buffers
439 * Return all buffers queued on the video node to videobuf2 in the given state.
440 * The buffer state should be VB2_BUF_STATE_QUEUED if called due to an error
441 * when starting the stream, or VB2_BUF_STATE_ERROR otherwise.
443 * The function must be called with the video irqlock held.
445 static void omap3isp_video_return_buffers(struct isp_video *video,
446 enum vb2_buffer_state state)
448 while (!list_empty(&video->dmaqueue)) {
449 struct isp_buffer *buf;
451 buf = list_first_entry(&video->dmaqueue,
452 struct isp_buffer, irqlist);
453 list_del(&buf->irqlist);
454 vb2_buffer_done(&buf->vb.vb2_buf, state);
458 static int isp_video_start_streaming(struct vb2_queue *queue,
461 struct isp_video_fh *vfh = vb2_get_drv_priv(queue);
462 struct isp_video *video = vfh->video;
463 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
467 /* In sensor-to-memory mode, the stream can be started synchronously
468 * to the stream on command. In memory-to-memory mode, it will be
469 * started when buffers are queued on both the input and output.
474 ret = omap3isp_pipeline_set_stream(pipe,
475 ISP_PIPELINE_STREAM_CONTINUOUS);
477 spin_lock_irqsave(&video->irqlock, flags);
478 omap3isp_video_return_buffers(video, VB2_BUF_STATE_QUEUED);
479 spin_unlock_irqrestore(&video->irqlock, flags);
483 spin_lock_irqsave(&video->irqlock, flags);
484 if (list_empty(&video->dmaqueue))
485 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
486 spin_unlock_irqrestore(&video->irqlock, flags);
491 static const struct vb2_ops isp_video_queue_ops = {
492 .queue_setup = isp_video_queue_setup,
493 .buf_prepare = isp_video_buffer_prepare,
494 .buf_queue = isp_video_buffer_queue,
495 .start_streaming = isp_video_start_streaming,
499 * omap3isp_video_buffer_next - Complete the current buffer and return the next
500 * @video: ISP video object
502 * Remove the current video buffer from the DMA queue and fill its timestamp and
503 * field count before handing it back to videobuf2.
505 * For capture video nodes the buffer state is set to VB2_BUF_STATE_DONE if no
506 * error has been flagged in the pipeline, or to VB2_BUF_STATE_ERROR otherwise.
507 * For video output nodes the buffer state is always set to VB2_BUF_STATE_DONE.
509 * The DMA queue is expected to contain at least one buffer.
511 * Return a pointer to the next buffer in the DMA queue, or NULL if the queue is
514 struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video)
516 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
517 enum vb2_buffer_state vb_state;
518 struct isp_buffer *buf;
521 spin_lock_irqsave(&video->irqlock, flags);
522 if (WARN_ON(list_empty(&video->dmaqueue))) {
523 spin_unlock_irqrestore(&video->irqlock, flags);
527 buf = list_first_entry(&video->dmaqueue, struct isp_buffer,
529 list_del(&buf->irqlist);
530 spin_unlock_irqrestore(&video->irqlock, flags);
532 buf->vb.vb2_buf.timestamp = ktime_get_ns();
534 /* Do frame number propagation only if this is the output video node.
535 * Frame number either comes from the CSI receivers or it gets
536 * incremented here if H3A is not active.
537 * Note: There is no guarantee that the output buffer will finish
538 * first, so the input number might lag behind by 1 in some cases.
540 if (video == pipe->output && !pipe->do_propagation)
542 atomic_inc_return(&pipe->frame_number);
544 buf->vb.sequence = atomic_read(&pipe->frame_number);
546 if (pipe->field != V4L2_FIELD_NONE)
547 buf->vb.sequence /= 2;
549 buf->vb.field = pipe->field;
551 /* Report pipeline errors to userspace on the capture device side. */
552 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->error) {
553 vb_state = VB2_BUF_STATE_ERROR;
556 vb_state = VB2_BUF_STATE_DONE;
559 vb2_buffer_done(&buf->vb.vb2_buf, vb_state);
561 spin_lock_irqsave(&video->irqlock, flags);
563 if (list_empty(&video->dmaqueue)) {
564 enum isp_pipeline_state state;
566 spin_unlock_irqrestore(&video->irqlock, flags);
568 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
569 state = ISP_PIPELINE_QUEUE_OUTPUT
570 | ISP_PIPELINE_STREAM;
572 state = ISP_PIPELINE_QUEUE_INPUT
573 | ISP_PIPELINE_STREAM;
575 spin_lock_irqsave(&pipe->lock, flags);
576 pipe->state &= ~state;
577 if (video->pipe.stream_state == ISP_PIPELINE_STREAM_CONTINUOUS)
578 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
579 spin_unlock_irqrestore(&pipe->lock, flags);
583 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->input != NULL) {
584 spin_lock(&pipe->lock);
585 pipe->state &= ~ISP_PIPELINE_STREAM;
586 spin_unlock(&pipe->lock);
589 buf = list_first_entry(&video->dmaqueue, struct isp_buffer,
592 spin_unlock_irqrestore(&video->irqlock, flags);
598 * omap3isp_video_cancel_stream - Cancel stream on a video node
599 * @video: ISP video object
601 * Cancelling a stream returns all buffers queued on the video node to videobuf2
602 * in the erroneous state and makes sure no new buffer can be queued.
604 void omap3isp_video_cancel_stream(struct isp_video *video)
608 spin_lock_irqsave(&video->irqlock, flags);
609 omap3isp_video_return_buffers(video, VB2_BUF_STATE_ERROR);
611 spin_unlock_irqrestore(&video->irqlock, flags);
615 * omap3isp_video_resume - Perform resume operation on the buffers
616 * @video: ISP video object
617 * @continuous: Pipeline is in single shot mode if 0 or continuous mode otherwise
619 * This function is intended to be used on suspend/resume scenario. It
620 * requests video queue layer to discard buffers marked as DONE if it's in
621 * continuous mode and requests ISP modules to queue again the ACTIVE buffer
624 void omap3isp_video_resume(struct isp_video *video, int continuous)
626 struct isp_buffer *buf = NULL;
628 if (continuous && video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
629 mutex_lock(&video->queue_lock);
630 vb2_discard_done(video->queue);
631 mutex_unlock(&video->queue_lock);
634 if (!list_empty(&video->dmaqueue)) {
635 buf = list_first_entry(&video->dmaqueue,
636 struct isp_buffer, irqlist);
637 video->ops->queue(video, buf);
638 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_QUEUED;
641 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
645 /* -----------------------------------------------------------------------------
650 isp_video_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
652 struct isp_video *video = video_drvdata(file);
654 strscpy(cap->driver, ISP_VIDEO_DRIVER_NAME, sizeof(cap->driver));
655 strscpy(cap->card, video->video.name, sizeof(cap->card));
656 strscpy(cap->bus_info, "media", sizeof(cap->bus_info));
658 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT
659 | V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS;
661 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
662 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
664 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
670 isp_video_get_format(struct file *file, void *fh, struct v4l2_format *format)
672 struct isp_video_fh *vfh = to_isp_video_fh(fh);
673 struct isp_video *video = video_drvdata(file);
675 if (format->type != video->type)
678 mutex_lock(&video->mutex);
679 *format = vfh->format;
680 mutex_unlock(&video->mutex);
686 isp_video_set_format(struct file *file, void *fh, struct v4l2_format *format)
688 struct isp_video_fh *vfh = to_isp_video_fh(fh);
689 struct isp_video *video = video_drvdata(file);
690 struct v4l2_mbus_framefmt fmt;
692 if (format->type != video->type)
695 /* Replace unsupported field orders with sane defaults. */
696 switch (format->fmt.pix.field) {
697 case V4L2_FIELD_NONE:
698 /* Progressive is supported everywhere. */
700 case V4L2_FIELD_ALTERNATE:
701 /* ALTERNATE is not supported on output nodes. */
702 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
703 format->fmt.pix.field = V4L2_FIELD_NONE;
705 case V4L2_FIELD_INTERLACED:
706 /* The ISP has no concept of video standard, select the
707 * top-bottom order when the unqualified interlaced order is
710 format->fmt.pix.field = V4L2_FIELD_INTERLACED_TB;
712 case V4L2_FIELD_INTERLACED_TB:
713 case V4L2_FIELD_INTERLACED_BT:
714 /* Interlaced orders are only supported at the CCDC output. */
715 if (video != &video->isp->isp_ccdc.video_out)
716 format->fmt.pix.field = V4L2_FIELD_NONE;
719 case V4L2_FIELD_BOTTOM:
720 case V4L2_FIELD_SEQ_TB:
721 case V4L2_FIELD_SEQ_BT:
723 /* All other field orders are currently unsupported, default to
726 format->fmt.pix.field = V4L2_FIELD_NONE;
730 /* Fill the bytesperline and sizeimage fields by converting to media bus
731 * format and back to pixel format.
733 isp_video_pix_to_mbus(&format->fmt.pix, &fmt);
734 isp_video_mbus_to_pix(video, &fmt, &format->fmt.pix);
736 mutex_lock(&video->mutex);
737 vfh->format = *format;
738 mutex_unlock(&video->mutex);
744 isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format)
746 struct isp_video *video = video_drvdata(file);
747 struct v4l2_subdev_format fmt;
748 struct v4l2_subdev *subdev;
752 if (format->type != video->type)
755 subdev = isp_video_remote_subdev(video, &pad);
759 isp_video_pix_to_mbus(&format->fmt.pix, &fmt.format);
762 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
763 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
765 return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
767 isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
772 isp_video_get_selection(struct file *file, void *fh, struct v4l2_selection *sel)
774 struct isp_video *video = video_drvdata(file);
775 struct v4l2_subdev_format format;
776 struct v4l2_subdev *subdev;
777 struct v4l2_subdev_selection sdsel = {
778 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
779 .target = sel->target,
784 switch (sel->target) {
785 case V4L2_SEL_TGT_CROP:
786 case V4L2_SEL_TGT_CROP_BOUNDS:
787 case V4L2_SEL_TGT_CROP_DEFAULT:
788 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
791 case V4L2_SEL_TGT_COMPOSE:
792 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
793 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
794 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
800 subdev = isp_video_remote_subdev(video, &pad);
804 /* Try the get selection operation first and fallback to get format if not
808 ret = v4l2_subdev_call(subdev, pad, get_selection, NULL, &sdsel);
811 if (ret != -ENOIOCTLCMD)
815 format.which = V4L2_SUBDEV_FORMAT_ACTIVE;
816 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &format);
818 return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
822 sel->r.width = format.format.width;
823 sel->r.height = format.format.height;
829 isp_video_set_selection(struct file *file, void *fh, struct v4l2_selection *sel)
831 struct isp_video *video = video_drvdata(file);
832 struct v4l2_subdev *subdev;
833 struct v4l2_subdev_selection sdsel = {
834 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
835 .target = sel->target,
842 switch (sel->target) {
843 case V4L2_SEL_TGT_CROP:
844 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
847 case V4L2_SEL_TGT_COMPOSE:
848 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
854 subdev = isp_video_remote_subdev(video, &pad);
859 mutex_lock(&video->mutex);
860 ret = v4l2_subdev_call(subdev, pad, set_selection, NULL, &sdsel);
861 mutex_unlock(&video->mutex);
865 return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
869 isp_video_get_param(struct file *file, void *fh, struct v4l2_streamparm *a)
871 struct isp_video_fh *vfh = to_isp_video_fh(fh);
872 struct isp_video *video = video_drvdata(file);
874 if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
875 video->type != a->type)
878 memset(a, 0, sizeof(*a));
879 a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
880 a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
881 a->parm.output.timeperframe = vfh->timeperframe;
887 isp_video_set_param(struct file *file, void *fh, struct v4l2_streamparm *a)
889 struct isp_video_fh *vfh = to_isp_video_fh(fh);
890 struct isp_video *video = video_drvdata(file);
892 if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
893 video->type != a->type)
896 if (a->parm.output.timeperframe.denominator == 0)
897 a->parm.output.timeperframe.denominator = 1;
899 vfh->timeperframe = a->parm.output.timeperframe;
905 isp_video_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *rb)
907 struct isp_video_fh *vfh = to_isp_video_fh(fh);
908 struct isp_video *video = video_drvdata(file);
911 mutex_lock(&video->queue_lock);
912 ret = vb2_reqbufs(&vfh->queue, rb);
913 mutex_unlock(&video->queue_lock);
919 isp_video_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
921 struct isp_video_fh *vfh = to_isp_video_fh(fh);
922 struct isp_video *video = video_drvdata(file);
925 mutex_lock(&video->queue_lock);
926 ret = vb2_querybuf(&vfh->queue, b);
927 mutex_unlock(&video->queue_lock);
933 isp_video_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
935 struct isp_video_fh *vfh = to_isp_video_fh(fh);
936 struct isp_video *video = video_drvdata(file);
939 mutex_lock(&video->queue_lock);
940 ret = vb2_qbuf(&vfh->queue, video->video.v4l2_dev->mdev, b);
941 mutex_unlock(&video->queue_lock);
947 isp_video_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
949 struct isp_video_fh *vfh = to_isp_video_fh(fh);
950 struct isp_video *video = video_drvdata(file);
953 mutex_lock(&video->queue_lock);
954 ret = vb2_dqbuf(&vfh->queue, b, file->f_flags & O_NONBLOCK);
955 mutex_unlock(&video->queue_lock);
960 static int isp_video_check_external_subdevs(struct isp_video *video,
961 struct isp_pipeline *pipe)
963 struct isp_device *isp = video->isp;
964 struct media_entity *ents[] = {
965 &isp->isp_csi2a.subdev.entity,
966 &isp->isp_csi2c.subdev.entity,
967 &isp->isp_ccp2.subdev.entity,
968 &isp->isp_ccdc.subdev.entity
970 struct media_pad *source_pad;
971 struct media_entity *source = NULL;
972 struct media_entity *sink;
973 struct v4l2_subdev_format fmt;
974 struct v4l2_ext_controls ctrls;
975 struct v4l2_ext_control ctrl;
979 /* Memory-to-memory pipelines have no external subdev. */
980 if (pipe->input != NULL)
983 for (i = 0; i < ARRAY_SIZE(ents); i++) {
984 /* Is the entity part of the pipeline? */
985 if (!media_entity_enum_test(&pipe->ent_enum, ents[i]))
988 /* ISP entities have always sink pad == 0. Find source. */
989 source_pad = media_entity_remote_pad(&ents[i]->pads[0]);
990 if (source_pad == NULL)
993 source = source_pad->entity;
999 dev_warn(isp->dev, "can't find source, failing now\n");
1003 if (!is_media_entity_v4l2_subdev(source))
1006 pipe->external = media_entity_to_v4l2_subdev(source);
1008 fmt.pad = source_pad->index;
1009 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1010 ret = v4l2_subdev_call(media_entity_to_v4l2_subdev(sink),
1011 pad, get_fmt, NULL, &fmt);
1012 if (unlikely(ret < 0)) {
1013 dev_warn(isp->dev, "get_fmt returned null!\n");
1017 pipe->external_width =
1018 omap3isp_video_format_info(fmt.format.code)->width;
1020 memset(&ctrls, 0, sizeof(ctrls));
1021 memset(&ctrl, 0, sizeof(ctrl));
1023 ctrl.id = V4L2_CID_PIXEL_RATE;
1026 ctrls.controls = &ctrl;
1028 ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, NULL, &ctrls);
1030 dev_warn(isp->dev, "no pixel rate control in subdev %s\n",
1031 pipe->external->name);
1035 pipe->external_rate = ctrl.value64;
1037 if (media_entity_enum_test(&pipe->ent_enum,
1038 &isp->isp_ccdc.subdev.entity)) {
1039 unsigned int rate = UINT_MAX;
1041 * Check that maximum allowed CCDC pixel rate isn't
1042 * exceeded by the pixel rate.
1044 omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
1045 if (pipe->external_rate > rate)
1055 * Every ISP pipeline has a single input and a single output. The input can be
1056 * either a sensor or a video node. The output is always a video node.
1058 * As every pipeline has an output video node, the ISP video objects at the
1059 * pipeline output stores the pipeline state. It tracks the streaming state of
1060 * both the input and output, as well as the availability of buffers.
1062 * In sensor-to-memory mode, frames are always available at the pipeline input.
1063 * Starting the sensor usually requires I2C transfers and must be done in
1064 * interruptible context. The pipeline is started and stopped synchronously
1065 * to the stream on/off commands. All modules in the pipeline will get their
1066 * subdev set stream handler called. The module at the end of the pipeline must
1067 * delay starting the hardware until buffers are available at its output.
1069 * In memory-to-memory mode, starting/stopping the stream requires
1070 * synchronization between the input and output. ISP modules can't be stopped
1071 * in the middle of a frame, and at least some of the modules seem to become
1072 * busy as soon as they're started, even if they don't receive a frame start
1073 * event. For that reason frames need to be processed in single-shot mode. The
1074 * driver needs to wait until a frame is completely processed and written to
1075 * memory before restarting the pipeline for the next frame. Pipelined
1076 * processing might be possible but requires more testing.
1078 * Stream start must be delayed until buffers are available at both the input
1079 * and output. The pipeline must be started in the videobuf queue callback with
1080 * the buffers queue spinlock held. The modules subdev set stream operation must
1084 isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
1086 struct isp_video_fh *vfh = to_isp_video_fh(fh);
1087 struct isp_video *video = video_drvdata(file);
1088 enum isp_pipeline_state state;
1089 struct isp_pipeline *pipe;
1090 unsigned long flags;
1093 if (type != video->type)
1096 mutex_lock(&video->stream_lock);
1098 /* Start streaming on the pipeline. No link touching an entity in the
1099 * pipeline can be activated or deactivated once streaming is started.
1101 pipe = video->video.entity.pipe
1102 ? to_isp_pipeline(&video->video.entity) : &video->pipe;
1104 ret = media_entity_enum_init(&pipe->ent_enum, &video->isp->media_dev);
1108 /* TODO: Implement PM QoS */
1109 pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
1110 pipe->max_rate = pipe->l3_ick;
1112 ret = media_pipeline_start(&video->video.entity, &pipe->pipe);
1114 goto err_pipeline_start;
1116 /* Verify that the currently configured format matches the output of
1117 * the connected subdev.
1119 ret = isp_video_check_format(video, vfh);
1121 goto err_check_format;
1123 video->bpl_padding = ret;
1124 video->bpl_value = vfh->format.fmt.pix.bytesperline;
1126 ret = isp_video_get_graph_data(video, pipe);
1128 goto err_check_format;
1130 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1131 state = ISP_PIPELINE_STREAM_OUTPUT | ISP_PIPELINE_IDLE_OUTPUT;
1133 state = ISP_PIPELINE_STREAM_INPUT | ISP_PIPELINE_IDLE_INPUT;
1135 ret = isp_video_check_external_subdevs(video, pipe);
1137 goto err_check_format;
1139 pipe->error = false;
1141 spin_lock_irqsave(&pipe->lock, flags);
1142 pipe->state &= ~ISP_PIPELINE_STREAM;
1143 pipe->state |= state;
1144 spin_unlock_irqrestore(&pipe->lock, flags);
1146 /* Set the maximum time per frame as the value requested by userspace.
1147 * This is a soft limit that can be overridden if the hardware doesn't
1148 * support the request limit.
1150 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1151 pipe->max_timeperframe = vfh->timeperframe;
1153 video->queue = &vfh->queue;
1154 INIT_LIST_HEAD(&video->dmaqueue);
1155 atomic_set(&pipe->frame_number, -1);
1156 pipe->field = vfh->format.fmt.pix.field;
1158 mutex_lock(&video->queue_lock);
1159 ret = vb2_streamon(&vfh->queue, type);
1160 mutex_unlock(&video->queue_lock);
1162 goto err_check_format;
1164 mutex_unlock(&video->stream_lock);
1169 media_pipeline_stop(&video->video.entity);
1171 /* TODO: Implement PM QoS */
1172 /* The DMA queue must be emptied here, otherwise CCDC interrupts that
1173 * will get triggered the next time the CCDC is powered up will try to
1174 * access buffers that might have been freed but still present in the
1175 * DMA queue. This can easily get triggered if the above
1176 * omap3isp_pipeline_set_stream() call fails on a system with a
1177 * free-running sensor.
1179 INIT_LIST_HEAD(&video->dmaqueue);
1180 video->queue = NULL;
1182 media_entity_enum_cleanup(&pipe->ent_enum);
1185 mutex_unlock(&video->stream_lock);
1191 isp_video_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
1193 struct isp_video_fh *vfh = to_isp_video_fh(fh);
1194 struct isp_video *video = video_drvdata(file);
1195 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
1196 enum isp_pipeline_state state;
1197 unsigned int streaming;
1198 unsigned long flags;
1200 if (type != video->type)
1203 mutex_lock(&video->stream_lock);
1205 /* Make sure we're not streaming yet. */
1206 mutex_lock(&video->queue_lock);
1207 streaming = vb2_is_streaming(&vfh->queue);
1208 mutex_unlock(&video->queue_lock);
1213 /* Update the pipeline state. */
1214 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1215 state = ISP_PIPELINE_STREAM_OUTPUT
1216 | ISP_PIPELINE_QUEUE_OUTPUT;
1218 state = ISP_PIPELINE_STREAM_INPUT
1219 | ISP_PIPELINE_QUEUE_INPUT;
1221 spin_lock_irqsave(&pipe->lock, flags);
1222 pipe->state &= ~state;
1223 spin_unlock_irqrestore(&pipe->lock, flags);
1225 /* Stop the stream. */
1226 omap3isp_pipeline_set_stream(pipe, ISP_PIPELINE_STREAM_STOPPED);
1227 omap3isp_video_cancel_stream(video);
1229 mutex_lock(&video->queue_lock);
1230 vb2_streamoff(&vfh->queue, type);
1231 mutex_unlock(&video->queue_lock);
1232 video->queue = NULL;
1233 video->error = false;
1235 /* TODO: Implement PM QoS */
1236 media_pipeline_stop(&video->video.entity);
1238 media_entity_enum_cleanup(&pipe->ent_enum);
1241 mutex_unlock(&video->stream_lock);
1246 isp_video_enum_input(struct file *file, void *fh, struct v4l2_input *input)
1248 if (input->index > 0)
1251 strscpy(input->name, "camera", sizeof(input->name));
1252 input->type = V4L2_INPUT_TYPE_CAMERA;
1258 isp_video_g_input(struct file *file, void *fh, unsigned int *input)
1266 isp_video_s_input(struct file *file, void *fh, unsigned int input)
1268 return input == 0 ? 0 : -EINVAL;
1271 static const struct v4l2_ioctl_ops isp_video_ioctl_ops = {
1272 .vidioc_querycap = isp_video_querycap,
1273 .vidioc_g_fmt_vid_cap = isp_video_get_format,
1274 .vidioc_s_fmt_vid_cap = isp_video_set_format,
1275 .vidioc_try_fmt_vid_cap = isp_video_try_format,
1276 .vidioc_g_fmt_vid_out = isp_video_get_format,
1277 .vidioc_s_fmt_vid_out = isp_video_set_format,
1278 .vidioc_try_fmt_vid_out = isp_video_try_format,
1279 .vidioc_g_selection = isp_video_get_selection,
1280 .vidioc_s_selection = isp_video_set_selection,
1281 .vidioc_g_parm = isp_video_get_param,
1282 .vidioc_s_parm = isp_video_set_param,
1283 .vidioc_reqbufs = isp_video_reqbufs,
1284 .vidioc_querybuf = isp_video_querybuf,
1285 .vidioc_qbuf = isp_video_qbuf,
1286 .vidioc_dqbuf = isp_video_dqbuf,
1287 .vidioc_streamon = isp_video_streamon,
1288 .vidioc_streamoff = isp_video_streamoff,
1289 .vidioc_enum_input = isp_video_enum_input,
1290 .vidioc_g_input = isp_video_g_input,
1291 .vidioc_s_input = isp_video_s_input,
1294 /* -----------------------------------------------------------------------------
1295 * V4L2 file operations
1298 static int isp_video_open(struct file *file)
1300 struct isp_video *video = video_drvdata(file);
1301 struct isp_video_fh *handle;
1302 struct vb2_queue *queue;
1305 handle = kzalloc(sizeof(*handle), GFP_KERNEL);
1309 v4l2_fh_init(&handle->vfh, &video->video);
1310 v4l2_fh_add(&handle->vfh);
1312 /* If this is the first user, initialise the pipeline. */
1313 if (omap3isp_get(video->isp) == NULL) {
1318 ret = v4l2_pipeline_pm_use(&video->video.entity, 1);
1320 omap3isp_put(video->isp);
1324 queue = &handle->queue;
1325 queue->type = video->type;
1326 queue->io_modes = VB2_MMAP | VB2_USERPTR;
1327 queue->drv_priv = handle;
1328 queue->ops = &isp_video_queue_ops;
1329 queue->mem_ops = &vb2_dma_contig_memops;
1330 queue->buf_struct_size = sizeof(struct isp_buffer);
1331 queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1332 queue->dev = video->isp->dev;
1334 ret = vb2_queue_init(&handle->queue);
1336 omap3isp_put(video->isp);
1340 memset(&handle->format, 0, sizeof(handle->format));
1341 handle->format.type = video->type;
1342 handle->timeperframe.denominator = 1;
1344 handle->video = video;
1345 file->private_data = &handle->vfh;
1349 v4l2_fh_del(&handle->vfh);
1350 v4l2_fh_exit(&handle->vfh);
1357 static int isp_video_release(struct file *file)
1359 struct isp_video *video = video_drvdata(file);
1360 struct v4l2_fh *vfh = file->private_data;
1361 struct isp_video_fh *handle = to_isp_video_fh(vfh);
1363 /* Disable streaming and free the buffers queue resources. */
1364 isp_video_streamoff(file, vfh, video->type);
1366 mutex_lock(&video->queue_lock);
1367 vb2_queue_release(&handle->queue);
1368 mutex_unlock(&video->queue_lock);
1370 v4l2_pipeline_pm_use(&video->video.entity, 0);
1372 /* Release the file handle. */
1376 file->private_data = NULL;
1378 omap3isp_put(video->isp);
1383 static __poll_t isp_video_poll(struct file *file, poll_table *wait)
1385 struct isp_video_fh *vfh = to_isp_video_fh(file->private_data);
1386 struct isp_video *video = video_drvdata(file);
1389 mutex_lock(&video->queue_lock);
1390 ret = vb2_poll(&vfh->queue, file, wait);
1391 mutex_unlock(&video->queue_lock);
1396 static int isp_video_mmap(struct file *file, struct vm_area_struct *vma)
1398 struct isp_video_fh *vfh = to_isp_video_fh(file->private_data);
1400 return vb2_mmap(&vfh->queue, vma);
1403 static const struct v4l2_file_operations isp_video_fops = {
1404 .owner = THIS_MODULE,
1405 .unlocked_ioctl = video_ioctl2,
1406 .open = isp_video_open,
1407 .release = isp_video_release,
1408 .poll = isp_video_poll,
1409 .mmap = isp_video_mmap,
1412 /* -----------------------------------------------------------------------------
1416 static const struct isp_video_operations isp_video_dummy_ops = {
1419 int omap3isp_video_init(struct isp_video *video, const char *name)
1421 const char *direction;
1424 switch (video->type) {
1425 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1426 direction = "output";
1427 video->pad.flags = MEDIA_PAD_FL_SINK
1428 | MEDIA_PAD_FL_MUST_CONNECT;
1430 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1431 direction = "input";
1432 video->pad.flags = MEDIA_PAD_FL_SOURCE
1433 | MEDIA_PAD_FL_MUST_CONNECT;
1434 video->video.vfl_dir = VFL_DIR_TX;
1441 ret = media_entity_pads_init(&video->video.entity, 1, &video->pad);
1445 mutex_init(&video->mutex);
1446 atomic_set(&video->active, 0);
1448 spin_lock_init(&video->pipe.lock);
1449 mutex_init(&video->stream_lock);
1450 mutex_init(&video->queue_lock);
1451 spin_lock_init(&video->irqlock);
1453 /* Initialize the video device. */
1454 if (video->ops == NULL)
1455 video->ops = &isp_video_dummy_ops;
1457 video->video.fops = &isp_video_fops;
1458 snprintf(video->video.name, sizeof(video->video.name),
1459 "OMAP3 ISP %s %s", name, direction);
1460 video->video.vfl_type = VFL_TYPE_GRABBER;
1461 video->video.release = video_device_release_empty;
1462 video->video.ioctl_ops = &isp_video_ioctl_ops;
1463 video->pipe.stream_state = ISP_PIPELINE_STREAM_STOPPED;
1465 video_set_drvdata(&video->video, video);
1470 void omap3isp_video_cleanup(struct isp_video *video)
1472 media_entity_cleanup(&video->video.entity);
1473 mutex_destroy(&video->queue_lock);
1474 mutex_destroy(&video->stream_lock);
1475 mutex_destroy(&video->mutex);
1478 int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev)
1482 video->video.v4l2_dev = vdev;
1484 ret = video_register_device(&video->video, VFL_TYPE_GRABBER, -1);
1486 dev_err(video->isp->dev,
1487 "%s: could not register video device (%d)\n",
1493 void omap3isp_video_unregister(struct isp_video *video)
1495 if (video_is_registered(&video->video))
1496 video_unregister_device(&video->video);