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.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include <asm/cacheflush.h>
27 #include <linux/clk.h>
29 #include <linux/module.h>
30 #include <linux/pagemap.h>
31 #include <linux/scatterlist.h>
32 #include <linux/sched.h>
33 #include <linux/slab.h>
34 #include <linux/vmalloc.h>
35 #include <media/v4l2-dev.h>
36 #include <media/v4l2-ioctl.h>
37 #include <media/videobuf2-dma-contig.h>
43 /* -----------------------------------------------------------------------------
48 * NOTE: When adding new media bus codes, always remember to add
49 * corresponding in-memory formats to the table below!!!
51 static struct isp_format_info formats
[] = {
52 { V4L2_MBUS_FMT_Y8_1X8
, V4L2_MBUS_FMT_Y8_1X8
,
53 V4L2_MBUS_FMT_Y8_1X8
, V4L2_MBUS_FMT_Y8_1X8
,
54 V4L2_PIX_FMT_GREY
, 8, 1, },
55 { V4L2_MBUS_FMT_Y10_1X10
, V4L2_MBUS_FMT_Y10_1X10
,
56 V4L2_MBUS_FMT_Y10_1X10
, V4L2_MBUS_FMT_Y8_1X8
,
57 V4L2_PIX_FMT_Y10
, 10, 2, },
58 { V4L2_MBUS_FMT_Y12_1X12
, V4L2_MBUS_FMT_Y10_1X10
,
59 V4L2_MBUS_FMT_Y12_1X12
, V4L2_MBUS_FMT_Y8_1X8
,
60 V4L2_PIX_FMT_Y12
, 12, 2, },
61 { V4L2_MBUS_FMT_SBGGR8_1X8
, V4L2_MBUS_FMT_SBGGR8_1X8
,
62 V4L2_MBUS_FMT_SBGGR8_1X8
, V4L2_MBUS_FMT_SBGGR8_1X8
,
63 V4L2_PIX_FMT_SBGGR8
, 8, 1, },
64 { V4L2_MBUS_FMT_SGBRG8_1X8
, V4L2_MBUS_FMT_SGBRG8_1X8
,
65 V4L2_MBUS_FMT_SGBRG8_1X8
, V4L2_MBUS_FMT_SGBRG8_1X8
,
66 V4L2_PIX_FMT_SGBRG8
, 8, 1, },
67 { V4L2_MBUS_FMT_SGRBG8_1X8
, V4L2_MBUS_FMT_SGRBG8_1X8
,
68 V4L2_MBUS_FMT_SGRBG8_1X8
, V4L2_MBUS_FMT_SGRBG8_1X8
,
69 V4L2_PIX_FMT_SGRBG8
, 8, 1, },
70 { V4L2_MBUS_FMT_SRGGB8_1X8
, V4L2_MBUS_FMT_SRGGB8_1X8
,
71 V4L2_MBUS_FMT_SRGGB8_1X8
, V4L2_MBUS_FMT_SRGGB8_1X8
,
72 V4L2_PIX_FMT_SRGGB8
, 8, 1, },
73 { V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8
, V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8
,
74 V4L2_MBUS_FMT_SBGGR10_1X10
, 0,
75 V4L2_PIX_FMT_SBGGR10DPCM8
, 8, 1, },
76 { V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8
, V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8
,
77 V4L2_MBUS_FMT_SGBRG10_1X10
, 0,
78 V4L2_PIX_FMT_SGBRG10DPCM8
, 8, 1, },
79 { V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8
, V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8
,
80 V4L2_MBUS_FMT_SGRBG10_1X10
, 0,
81 V4L2_PIX_FMT_SGRBG10DPCM8
, 8, 1, },
82 { V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8
, V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8
,
83 V4L2_MBUS_FMT_SRGGB10_1X10
, 0,
84 V4L2_PIX_FMT_SRGGB10DPCM8
, 8, 1, },
85 { V4L2_MBUS_FMT_SBGGR10_1X10
, V4L2_MBUS_FMT_SBGGR10_1X10
,
86 V4L2_MBUS_FMT_SBGGR10_1X10
, V4L2_MBUS_FMT_SBGGR8_1X8
,
87 V4L2_PIX_FMT_SBGGR10
, 10, 2, },
88 { V4L2_MBUS_FMT_SGBRG10_1X10
, V4L2_MBUS_FMT_SGBRG10_1X10
,
89 V4L2_MBUS_FMT_SGBRG10_1X10
, V4L2_MBUS_FMT_SGBRG8_1X8
,
90 V4L2_PIX_FMT_SGBRG10
, 10, 2, },
91 { V4L2_MBUS_FMT_SGRBG10_1X10
, V4L2_MBUS_FMT_SGRBG10_1X10
,
92 V4L2_MBUS_FMT_SGRBG10_1X10
, V4L2_MBUS_FMT_SGRBG8_1X8
,
93 V4L2_PIX_FMT_SGRBG10
, 10, 2, },
94 { V4L2_MBUS_FMT_SRGGB10_1X10
, V4L2_MBUS_FMT_SRGGB10_1X10
,
95 V4L2_MBUS_FMT_SRGGB10_1X10
, V4L2_MBUS_FMT_SRGGB8_1X8
,
96 V4L2_PIX_FMT_SRGGB10
, 10, 2, },
97 { V4L2_MBUS_FMT_SBGGR12_1X12
, V4L2_MBUS_FMT_SBGGR10_1X10
,
98 V4L2_MBUS_FMT_SBGGR12_1X12
, V4L2_MBUS_FMT_SBGGR8_1X8
,
99 V4L2_PIX_FMT_SBGGR12
, 12, 2, },
100 { V4L2_MBUS_FMT_SGBRG12_1X12
, V4L2_MBUS_FMT_SGBRG10_1X10
,
101 V4L2_MBUS_FMT_SGBRG12_1X12
, V4L2_MBUS_FMT_SGBRG8_1X8
,
102 V4L2_PIX_FMT_SGBRG12
, 12, 2, },
103 { V4L2_MBUS_FMT_SGRBG12_1X12
, V4L2_MBUS_FMT_SGRBG10_1X10
,
104 V4L2_MBUS_FMT_SGRBG12_1X12
, V4L2_MBUS_FMT_SGRBG8_1X8
,
105 V4L2_PIX_FMT_SGRBG12
, 12, 2, },
106 { V4L2_MBUS_FMT_SRGGB12_1X12
, V4L2_MBUS_FMT_SRGGB10_1X10
,
107 V4L2_MBUS_FMT_SRGGB12_1X12
, V4L2_MBUS_FMT_SRGGB8_1X8
,
108 V4L2_PIX_FMT_SRGGB12
, 12, 2, },
109 { V4L2_MBUS_FMT_UYVY8_1X16
, V4L2_MBUS_FMT_UYVY8_1X16
,
110 V4L2_MBUS_FMT_UYVY8_1X16
, 0,
111 V4L2_PIX_FMT_UYVY
, 16, 2, },
112 { V4L2_MBUS_FMT_YUYV8_1X16
, V4L2_MBUS_FMT_YUYV8_1X16
,
113 V4L2_MBUS_FMT_YUYV8_1X16
, 0,
114 V4L2_PIX_FMT_YUYV
, 16, 2, },
115 { V4L2_MBUS_FMT_UYVY8_2X8
, V4L2_MBUS_FMT_UYVY8_2X8
,
116 V4L2_MBUS_FMT_UYVY8_2X8
, 0,
117 V4L2_PIX_FMT_UYVY
, 8, 2, },
118 { V4L2_MBUS_FMT_YUYV8_2X8
, V4L2_MBUS_FMT_YUYV8_2X8
,
119 V4L2_MBUS_FMT_YUYV8_2X8
, 0,
120 V4L2_PIX_FMT_YUYV
, 8, 2, },
121 /* Empty entry to catch the unsupported pixel code (0) used by the CCDC
122 * module and avoid NULL pointer dereferences.
127 const struct isp_format_info
*
128 omap3isp_video_format_info(enum v4l2_mbus_pixelcode code
)
132 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
) {
133 if (formats
[i
].code
== code
)
141 * isp_video_mbus_to_pix - Convert v4l2_mbus_framefmt to v4l2_pix_format
142 * @video: ISP video instance
143 * @mbus: v4l2_mbus_framefmt format (input)
144 * @pix: v4l2_pix_format format (output)
146 * Fill the output pix structure with information from the input mbus format.
147 * The bytesperline and sizeimage fields are computed from the requested bytes
148 * per line value in the pix format and information from the video instance.
150 * Return the number of padding bytes at end of line.
152 static unsigned int isp_video_mbus_to_pix(const struct isp_video
*video
,
153 const struct v4l2_mbus_framefmt
*mbus
,
154 struct v4l2_pix_format
*pix
)
156 unsigned int bpl
= pix
->bytesperline
;
157 unsigned int min_bpl
;
160 memset(pix
, 0, sizeof(*pix
));
161 pix
->width
= mbus
->width
;
162 pix
->height
= mbus
->height
;
164 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
) {
165 if (formats
[i
].code
== mbus
->code
)
169 if (WARN_ON(i
== ARRAY_SIZE(formats
)))
172 min_bpl
= pix
->width
* formats
[i
].bpp
;
174 /* Clamp the requested bytes per line value. If the maximum bytes per
175 * line value is zero, the module doesn't support user configurable line
176 * sizes. Override the requested value with the minimum in that case.
179 bpl
= clamp(bpl
, min_bpl
, video
->bpl_max
);
183 if (!video
->bpl_zero_padding
|| bpl
!= min_bpl
)
184 bpl
= ALIGN(bpl
, video
->bpl_alignment
);
186 pix
->pixelformat
= formats
[i
].pixelformat
;
187 pix
->bytesperline
= bpl
;
188 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
189 pix
->colorspace
= mbus
->colorspace
;
190 pix
->field
= mbus
->field
;
192 return bpl
- min_bpl
;
195 static void isp_video_pix_to_mbus(const struct v4l2_pix_format
*pix
,
196 struct v4l2_mbus_framefmt
*mbus
)
200 memset(mbus
, 0, sizeof(*mbus
));
201 mbus
->width
= pix
->width
;
202 mbus
->height
= pix
->height
;
204 /* Skip the last format in the loop so that it will be selected if no
207 for (i
= 0; i
< ARRAY_SIZE(formats
) - 1; ++i
) {
208 if (formats
[i
].pixelformat
== pix
->pixelformat
)
212 mbus
->code
= formats
[i
].code
;
213 mbus
->colorspace
= pix
->colorspace
;
214 mbus
->field
= pix
->field
;
217 static struct v4l2_subdev
*
218 isp_video_remote_subdev(struct isp_video
*video
, u32
*pad
)
220 struct media_pad
*remote
;
222 remote
= media_entity_remote_pad(&video
->pad
);
224 if (remote
== NULL
||
225 media_entity_type(remote
->entity
) != MEDIA_ENT_T_V4L2_SUBDEV
)
229 *pad
= remote
->index
;
231 return media_entity_to_v4l2_subdev(remote
->entity
);
234 /* Return a pointer to the ISP video instance at the far end of the pipeline. */
235 static int isp_video_get_graph_data(struct isp_video
*video
,
236 struct isp_pipeline
*pipe
)
238 struct media_entity_graph graph
;
239 struct media_entity
*entity
= &video
->video
.entity
;
240 struct media_device
*mdev
= entity
->parent
;
241 struct isp_video
*far_end
= NULL
;
243 mutex_lock(&mdev
->graph_mutex
);
244 media_entity_graph_walk_start(&graph
, entity
);
246 while ((entity
= media_entity_graph_walk_next(&graph
))) {
247 struct isp_video
*__video
;
249 pipe
->entities
|= 1 << entity
->id
;
254 if (entity
== &video
->video
.entity
)
257 if (media_entity_type(entity
) != MEDIA_ENT_T_DEVNODE
)
260 __video
= to_isp_video(media_entity_to_video_device(entity
));
261 if (__video
->type
!= video
->type
)
265 mutex_unlock(&mdev
->graph_mutex
);
267 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
268 pipe
->input
= far_end
;
269 pipe
->output
= video
;
275 pipe
->output
= far_end
;
282 __isp_video_get_format(struct isp_video
*video
, struct v4l2_format
*format
)
284 struct v4l2_subdev_format fmt
;
285 struct v4l2_subdev
*subdev
;
289 subdev
= isp_video_remote_subdev(video
, &pad
);
294 fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
296 mutex_lock(&video
->mutex
);
297 ret
= v4l2_subdev_call(subdev
, pad
, get_fmt
, NULL
, &fmt
);
298 mutex_unlock(&video
->mutex
);
303 format
->type
= video
->type
;
304 return isp_video_mbus_to_pix(video
, &fmt
.format
, &format
->fmt
.pix
);
308 isp_video_check_format(struct isp_video
*video
, struct isp_video_fh
*vfh
)
310 struct v4l2_format format
;
313 memcpy(&format
, &vfh
->format
, sizeof(format
));
314 ret
= __isp_video_get_format(video
, &format
);
318 if (vfh
->format
.fmt
.pix
.pixelformat
!= format
.fmt
.pix
.pixelformat
||
319 vfh
->format
.fmt
.pix
.height
!= format
.fmt
.pix
.height
||
320 vfh
->format
.fmt
.pix
.width
!= format
.fmt
.pix
.width
||
321 vfh
->format
.fmt
.pix
.bytesperline
!= format
.fmt
.pix
.bytesperline
||
322 vfh
->format
.fmt
.pix
.sizeimage
!= format
.fmt
.pix
.sizeimage
)
328 /* -----------------------------------------------------------------------------
329 * Video queue operations
332 static int isp_video_queue_setup(struct vb2_queue
*queue
,
333 const struct v4l2_format
*fmt
,
334 unsigned int *count
, unsigned int *num_planes
,
335 unsigned int sizes
[], void *alloc_ctxs
[])
337 struct isp_video_fh
*vfh
= vb2_get_drv_priv(queue
);
338 struct isp_video
*video
= vfh
->video
;
342 sizes
[0] = vfh
->format
.fmt
.pix
.sizeimage
;
346 alloc_ctxs
[0] = video
->alloc_ctx
;
348 *count
= min(*count
, video
->capture_mem
/ PAGE_ALIGN(sizes
[0]));
353 static int isp_video_buffer_prepare(struct vb2_buffer
*buf
)
355 struct isp_video_fh
*vfh
= vb2_get_drv_priv(buf
->vb2_queue
);
356 struct isp_buffer
*buffer
= to_isp_buffer(buf
);
357 struct isp_video
*video
= vfh
->video
;
360 /* Refuse to prepare the buffer is the video node has registered an
361 * error. We don't need to take any lock here as the operation is
362 * inherently racy. The authoritative check will be performed in the
363 * queue handler, which can't return an error, this check is just a best
364 * effort to notify userspace as early as possible.
366 if (unlikely(video
->error
))
369 addr
= vb2_dma_contig_plane_dma_addr(buf
, 0);
370 if (!IS_ALIGNED(addr
, 32)) {
371 dev_dbg(video
->isp
->dev
,
372 "Buffer address must be aligned to 32 bytes boundary.\n");
376 vb2_set_plane_payload(&buffer
->vb
, 0, vfh
->format
.fmt
.pix
.sizeimage
);
377 buffer
->isp_addr
= addr
;
383 * isp_video_buffer_queue - Add buffer to streaming queue
386 * In memory-to-memory mode, start streaming on the pipeline if buffers are
387 * queued on both the input and the output, if the pipeline isn't already busy.
388 * If the pipeline is busy, it will be restarted in the output module interrupt
391 static void isp_video_buffer_queue(struct vb2_buffer
*buf
)
393 struct isp_video_fh
*vfh
= vb2_get_drv_priv(buf
->vb2_queue
);
394 struct isp_buffer
*buffer
= to_isp_buffer(buf
);
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_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
);
437 static const struct vb2_ops isp_video_queue_ops
= {
438 .queue_setup
= isp_video_queue_setup
,
439 .buf_prepare
= isp_video_buffer_prepare
,
440 .buf_queue
= isp_video_buffer_queue
,
444 * omap3isp_video_buffer_next - Complete the current buffer and return the next
445 * @video: ISP video object
447 * Remove the current video buffer from the DMA queue and fill its timestamp and
448 * field count before handing it back to videobuf2.
450 * For capture video nodes the buffer state is set to VB2_BUF_STATE_DONE if no
451 * error has been flagged in the pipeline, or to VB2_BUF_STATE_ERROR otherwise.
452 * For video output nodes the buffer state is always set to VB2_BUF_STATE_DONE.
454 * The DMA queue is expected to contain at least one buffer.
456 * Return a pointer to the next buffer in the DMA queue, or NULL if the queue is
459 struct isp_buffer
*omap3isp_video_buffer_next(struct isp_video
*video
)
461 struct isp_pipeline
*pipe
= to_isp_pipeline(&video
->video
.entity
);
462 enum isp_pipeline_state state
;
463 struct isp_buffer
*buf
;
467 spin_lock_irqsave(&video
->irqlock
, flags
);
468 if (WARN_ON(list_empty(&video
->dmaqueue
))) {
469 spin_unlock_irqrestore(&video
->irqlock
, flags
);
473 buf
= list_first_entry(&video
->dmaqueue
, struct isp_buffer
,
475 list_del(&buf
->irqlist
);
476 spin_unlock_irqrestore(&video
->irqlock
, flags
);
479 buf
->vb
.v4l2_buf
.timestamp
.tv_sec
= ts
.tv_sec
;
480 buf
->vb
.v4l2_buf
.timestamp
.tv_usec
= ts
.tv_nsec
/ NSEC_PER_USEC
;
482 /* Do frame number propagation only if this is the output video node.
483 * Frame number either comes from the CSI receivers or it gets
484 * incremented here if H3A is not active.
485 * Note: There is no guarantee that the output buffer will finish
486 * first, so the input number might lag behind by 1 in some cases.
488 if (video
== pipe
->output
&& !pipe
->do_propagation
)
489 buf
->vb
.v4l2_buf
.sequence
=
490 atomic_inc_return(&pipe
->frame_number
);
492 buf
->vb
.v4l2_buf
.sequence
= atomic_read(&pipe
->frame_number
);
494 /* Report pipeline errors to userspace on the capture device side. */
495 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& pipe
->error
) {
496 state
= VB2_BUF_STATE_ERROR
;
499 state
= VB2_BUF_STATE_DONE
;
502 vb2_buffer_done(&buf
->vb
, state
);
504 spin_lock_irqsave(&video
->irqlock
, flags
);
506 if (list_empty(&video
->dmaqueue
)) {
507 spin_unlock_irqrestore(&video
->irqlock
, flags
);
509 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
510 state
= ISP_PIPELINE_QUEUE_OUTPUT
511 | ISP_PIPELINE_STREAM
;
513 state
= ISP_PIPELINE_QUEUE_INPUT
514 | ISP_PIPELINE_STREAM
;
516 spin_lock_irqsave(&pipe
->lock
, flags
);
517 pipe
->state
&= ~state
;
518 if (video
->pipe
.stream_state
== ISP_PIPELINE_STREAM_CONTINUOUS
)
519 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
520 spin_unlock_irqrestore(&pipe
->lock
, flags
);
524 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& pipe
->input
!= NULL
) {
525 spin_lock(&pipe
->lock
);
526 pipe
->state
&= ~ISP_PIPELINE_STREAM
;
527 spin_unlock(&pipe
->lock
);
530 buf
= list_first_entry(&video
->dmaqueue
, struct isp_buffer
,
532 buf
->vb
.state
= VB2_BUF_STATE_ACTIVE
;
534 spin_unlock_irqrestore(&video
->irqlock
, flags
);
540 * omap3isp_video_cancel_stream - Cancel stream on a video node
541 * @video: ISP video object
543 * Cancelling a stream mark all buffers on the video node as erroneous and makes
544 * sure no new buffer can be queued.
546 void omap3isp_video_cancel_stream(struct isp_video
*video
)
550 spin_lock_irqsave(&video
->irqlock
, flags
);
552 while (!list_empty(&video
->dmaqueue
)) {
553 struct isp_buffer
*buf
;
555 buf
= list_first_entry(&video
->dmaqueue
,
556 struct isp_buffer
, irqlist
);
557 list_del(&buf
->irqlist
);
558 vb2_buffer_done(&buf
->vb
, VB2_BUF_STATE_ERROR
);
563 spin_unlock_irqrestore(&video
->irqlock
, flags
);
567 * omap3isp_video_resume - Perform resume operation on the buffers
568 * @video: ISP video object
569 * @continuous: Pipeline is in single shot mode if 0 or continuous mode otherwise
571 * This function is intended to be used on suspend/resume scenario. It
572 * requests video queue layer to discard buffers marked as DONE if it's in
573 * continuous mode and requests ISP modules to queue again the ACTIVE buffer
576 void omap3isp_video_resume(struct isp_video
*video
, int continuous
)
578 struct isp_buffer
*buf
= NULL
;
580 if (continuous
&& video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
581 mutex_lock(&video
->queue_lock
);
582 vb2_discard_done(video
->queue
);
583 mutex_unlock(&video
->queue_lock
);
586 if (!list_empty(&video
->dmaqueue
)) {
587 buf
= list_first_entry(&video
->dmaqueue
,
588 struct isp_buffer
, irqlist
);
589 video
->ops
->queue(video
, buf
);
590 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_QUEUED
;
593 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
597 /* -----------------------------------------------------------------------------
602 isp_video_querycap(struct file
*file
, void *fh
, struct v4l2_capability
*cap
)
604 struct isp_video
*video
= video_drvdata(file
);
606 strlcpy(cap
->driver
, ISP_VIDEO_DRIVER_NAME
, sizeof(cap
->driver
));
607 strlcpy(cap
->card
, video
->video
.name
, sizeof(cap
->card
));
608 strlcpy(cap
->bus_info
, "media", sizeof(cap
->bus_info
));
610 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
611 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
613 cap
->capabilities
= V4L2_CAP_VIDEO_OUTPUT
| V4L2_CAP_STREAMING
;
619 isp_video_get_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
621 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
622 struct isp_video
*video
= video_drvdata(file
);
624 if (format
->type
!= video
->type
)
627 mutex_lock(&video
->mutex
);
628 *format
= vfh
->format
;
629 mutex_unlock(&video
->mutex
);
635 isp_video_set_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
637 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
638 struct isp_video
*video
= video_drvdata(file
);
639 struct v4l2_mbus_framefmt fmt
;
641 if (format
->type
!= video
->type
)
644 mutex_lock(&video
->mutex
);
646 /* Fill the bytesperline and sizeimage fields by converting to media bus
647 * format and back to pixel format.
649 isp_video_pix_to_mbus(&format
->fmt
.pix
, &fmt
);
650 isp_video_mbus_to_pix(video
, &fmt
, &format
->fmt
.pix
);
652 vfh
->format
= *format
;
654 mutex_unlock(&video
->mutex
);
659 isp_video_try_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
661 struct isp_video
*video
= video_drvdata(file
);
662 struct v4l2_subdev_format fmt
;
663 struct v4l2_subdev
*subdev
;
667 if (format
->type
!= video
->type
)
670 subdev
= isp_video_remote_subdev(video
, &pad
);
674 isp_video_pix_to_mbus(&format
->fmt
.pix
, &fmt
.format
);
677 fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
678 ret
= v4l2_subdev_call(subdev
, pad
, get_fmt
, NULL
, &fmt
);
680 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
682 isp_video_mbus_to_pix(video
, &fmt
.format
, &format
->fmt
.pix
);
687 isp_video_cropcap(struct file
*file
, void *fh
, struct v4l2_cropcap
*cropcap
)
689 struct isp_video
*video
= video_drvdata(file
);
690 struct v4l2_subdev
*subdev
;
693 subdev
= isp_video_remote_subdev(video
, NULL
);
697 mutex_lock(&video
->mutex
);
698 ret
= v4l2_subdev_call(subdev
, video
, cropcap
, cropcap
);
699 mutex_unlock(&video
->mutex
);
701 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
705 isp_video_get_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
707 struct isp_video
*video
= video_drvdata(file
);
708 struct v4l2_subdev_format format
;
709 struct v4l2_subdev
*subdev
;
713 subdev
= isp_video_remote_subdev(video
, &pad
);
717 /* Try the get crop operation first and fallback to get format if not
720 ret
= v4l2_subdev_call(subdev
, video
, g_crop
, crop
);
721 if (ret
!= -ENOIOCTLCMD
)
725 format
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
726 ret
= v4l2_subdev_call(subdev
, pad
, get_fmt
, NULL
, &format
);
728 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
732 crop
->c
.width
= format
.format
.width
;
733 crop
->c
.height
= format
.format
.height
;
739 isp_video_set_crop(struct file
*file
, void *fh
, const struct v4l2_crop
*crop
)
741 struct isp_video
*video
= video_drvdata(file
);
742 struct v4l2_subdev
*subdev
;
745 subdev
= isp_video_remote_subdev(video
, NULL
);
749 mutex_lock(&video
->mutex
);
750 ret
= v4l2_subdev_call(subdev
, video
, s_crop
, crop
);
751 mutex_unlock(&video
->mutex
);
753 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
757 isp_video_get_param(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
759 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
760 struct isp_video
*video
= video_drvdata(file
);
762 if (video
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
763 video
->type
!= a
->type
)
766 memset(a
, 0, sizeof(*a
));
767 a
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
768 a
->parm
.output
.capability
= V4L2_CAP_TIMEPERFRAME
;
769 a
->parm
.output
.timeperframe
= vfh
->timeperframe
;
775 isp_video_set_param(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
777 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
778 struct isp_video
*video
= video_drvdata(file
);
780 if (video
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
781 video
->type
!= a
->type
)
784 if (a
->parm
.output
.timeperframe
.denominator
== 0)
785 a
->parm
.output
.timeperframe
.denominator
= 1;
787 vfh
->timeperframe
= a
->parm
.output
.timeperframe
;
793 isp_video_reqbufs(struct file
*file
, void *fh
, struct v4l2_requestbuffers
*rb
)
795 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
796 struct isp_video
*video
= video_drvdata(file
);
799 mutex_lock(&video
->queue_lock
);
800 ret
= vb2_reqbufs(&vfh
->queue
, rb
);
801 mutex_unlock(&video
->queue_lock
);
807 isp_video_querybuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
809 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
810 struct isp_video
*video
= video_drvdata(file
);
813 mutex_lock(&video
->queue_lock
);
814 ret
= vb2_querybuf(&vfh
->queue
, b
);
815 mutex_unlock(&video
->queue_lock
);
821 isp_video_qbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
823 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
824 struct isp_video
*video
= video_drvdata(file
);
827 mutex_lock(&video
->queue_lock
);
828 ret
= vb2_qbuf(&vfh
->queue
, b
);
829 mutex_unlock(&video
->queue_lock
);
835 isp_video_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
837 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
838 struct isp_video
*video
= video_drvdata(file
);
841 mutex_lock(&video
->queue_lock
);
842 ret
= vb2_dqbuf(&vfh
->queue
, b
, file
->f_flags
& O_NONBLOCK
);
843 mutex_unlock(&video
->queue_lock
);
848 static int isp_video_check_external_subdevs(struct isp_video
*video
,
849 struct isp_pipeline
*pipe
)
851 struct isp_device
*isp
= video
->isp
;
852 struct media_entity
*ents
[] = {
853 &isp
->isp_csi2a
.subdev
.entity
,
854 &isp
->isp_csi2c
.subdev
.entity
,
855 &isp
->isp_ccp2
.subdev
.entity
,
856 &isp
->isp_ccdc
.subdev
.entity
858 struct media_pad
*source_pad
;
859 struct media_entity
*source
= NULL
;
860 struct media_entity
*sink
;
861 struct v4l2_subdev_format fmt
;
862 struct v4l2_ext_controls ctrls
;
863 struct v4l2_ext_control ctrl
;
867 /* Memory-to-memory pipelines have no external subdev. */
868 if (pipe
->input
!= NULL
)
871 for (i
= 0; i
< ARRAY_SIZE(ents
); i
++) {
872 /* Is the entity part of the pipeline? */
873 if (!(pipe
->entities
& (1 << ents
[i
]->id
)))
876 /* ISP entities have always sink pad == 0. Find source. */
877 source_pad
= media_entity_remote_pad(&ents
[i
]->pads
[0]);
878 if (source_pad
== NULL
)
881 source
= source_pad
->entity
;
887 dev_warn(isp
->dev
, "can't find source, failing now\n");
891 if (media_entity_type(source
) != MEDIA_ENT_T_V4L2_SUBDEV
)
894 pipe
->external
= media_entity_to_v4l2_subdev(source
);
896 fmt
.pad
= source_pad
->index
;
897 fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
898 ret
= v4l2_subdev_call(media_entity_to_v4l2_subdev(sink
),
899 pad
, get_fmt
, NULL
, &fmt
);
900 if (unlikely(ret
< 0)) {
901 dev_warn(isp
->dev
, "get_fmt returned null!\n");
905 pipe
->external_width
=
906 omap3isp_video_format_info(fmt
.format
.code
)->width
;
908 memset(&ctrls
, 0, sizeof(ctrls
));
909 memset(&ctrl
, 0, sizeof(ctrl
));
911 ctrl
.id
= V4L2_CID_PIXEL_RATE
;
914 ctrls
.controls
= &ctrl
;
916 ret
= v4l2_g_ext_ctrls(pipe
->external
->ctrl_handler
, &ctrls
);
918 dev_warn(isp
->dev
, "no pixel rate control in subdev %s\n",
919 pipe
->external
->name
);
923 pipe
->external_rate
= ctrl
.value64
;
925 if (pipe
->entities
& (1 << isp
->isp_ccdc
.subdev
.entity
.id
)) {
926 unsigned int rate
= UINT_MAX
;
928 * Check that maximum allowed CCDC pixel rate isn't
929 * exceeded by the pixel rate.
931 omap3isp_ccdc_max_rate(&isp
->isp_ccdc
, &rate
);
932 if (pipe
->external_rate
> rate
)
942 * Every ISP pipeline has a single input and a single output. The input can be
943 * either a sensor or a video node. The output is always a video node.
945 * As every pipeline has an output video node, the ISP video objects at the
946 * pipeline output stores the pipeline state. It tracks the streaming state of
947 * both the input and output, as well as the availability of buffers.
949 * In sensor-to-memory mode, frames are always available at the pipeline input.
950 * Starting the sensor usually requires I2C transfers and must be done in
951 * interruptible context. The pipeline is started and stopped synchronously
952 * to the stream on/off commands. All modules in the pipeline will get their
953 * subdev set stream handler called. The module at the end of the pipeline must
954 * delay starting the hardware until buffers are available at its output.
956 * In memory-to-memory mode, starting/stopping the stream requires
957 * synchronization between the input and output. ISP modules can't be stopped
958 * in the middle of a frame, and at least some of the modules seem to become
959 * busy as soon as they're started, even if they don't receive a frame start
960 * event. For that reason frames need to be processed in single-shot mode. The
961 * driver needs to wait until a frame is completely processed and written to
962 * memory before restarting the pipeline for the next frame. Pipelined
963 * processing might be possible but requires more testing.
965 * Stream start must be delayed until buffers are available at both the input
966 * and output. The pipeline must be started in the videobuf queue callback with
967 * the buffers queue spinlock held. The modules subdev set stream operation must
971 isp_video_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type type
)
973 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
974 struct isp_video
*video
= video_drvdata(file
);
975 enum isp_pipeline_state state
;
976 struct isp_pipeline
*pipe
;
980 if (type
!= video
->type
)
983 mutex_lock(&video
->stream_lock
);
985 /* Start streaming on the pipeline. No link touching an entity in the
986 * pipeline can be activated or deactivated once streaming is started.
988 pipe
= video
->video
.entity
.pipe
989 ? to_isp_pipeline(&video
->video
.entity
) : &video
->pipe
;
993 if (video
->isp
->pdata
->set_constraints
)
994 video
->isp
->pdata
->set_constraints(video
->isp
, true);
995 pipe
->l3_ick
= clk_get_rate(video
->isp
->clock
[ISP_CLK_L3_ICK
]);
996 pipe
->max_rate
= pipe
->l3_ick
;
998 ret
= media_entity_pipeline_start(&video
->video
.entity
, &pipe
->pipe
);
1000 goto err_pipeline_start
;
1002 /* Verify that the currently configured format matches the output of
1003 * the connected subdev.
1005 ret
= isp_video_check_format(video
, vfh
);
1007 goto err_check_format
;
1009 video
->bpl_padding
= ret
;
1010 video
->bpl_value
= vfh
->format
.fmt
.pix
.bytesperline
;
1012 ret
= isp_video_get_graph_data(video
, pipe
);
1014 goto err_check_format
;
1016 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1017 state
= ISP_PIPELINE_STREAM_OUTPUT
| ISP_PIPELINE_IDLE_OUTPUT
;
1019 state
= ISP_PIPELINE_STREAM_INPUT
| ISP_PIPELINE_IDLE_INPUT
;
1021 ret
= isp_video_check_external_subdevs(video
, pipe
);
1023 goto err_check_format
;
1025 pipe
->error
= false;
1027 spin_lock_irqsave(&pipe
->lock
, flags
);
1028 pipe
->state
&= ~ISP_PIPELINE_STREAM
;
1029 pipe
->state
|= state
;
1030 spin_unlock_irqrestore(&pipe
->lock
, flags
);
1032 /* Set the maximum time per frame as the value requested by userspace.
1033 * This is a soft limit that can be overridden if the hardware doesn't
1034 * support the request limit.
1036 if (video
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1037 pipe
->max_timeperframe
= vfh
->timeperframe
;
1039 video
->queue
= &vfh
->queue
;
1040 INIT_LIST_HEAD(&video
->dmaqueue
);
1041 atomic_set(&pipe
->frame_number
, -1);
1043 mutex_lock(&video
->queue_lock
);
1044 ret
= vb2_streamon(&vfh
->queue
, type
);
1045 mutex_unlock(&video
->queue_lock
);
1047 goto err_check_format
;
1049 /* In sensor-to-memory mode, the stream can be started synchronously
1050 * to the stream on command. In memory-to-memory mode, it will be
1051 * started when buffers are queued on both the input and output.
1053 if (pipe
->input
== NULL
) {
1054 ret
= omap3isp_pipeline_set_stream(pipe
,
1055 ISP_PIPELINE_STREAM_CONTINUOUS
);
1057 goto err_set_stream
;
1058 spin_lock_irqsave(&video
->irqlock
, flags
);
1059 if (list_empty(&video
->dmaqueue
))
1060 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
1061 spin_unlock_irqrestore(&video
->irqlock
, flags
);
1064 mutex_unlock(&video
->stream_lock
);
1068 mutex_lock(&video
->queue_lock
);
1069 vb2_streamoff(&vfh
->queue
, type
);
1070 mutex_unlock(&video
->queue_lock
);
1072 media_entity_pipeline_stop(&video
->video
.entity
);
1074 if (video
->isp
->pdata
->set_constraints
)
1075 video
->isp
->pdata
->set_constraints(video
->isp
, false);
1076 /* The DMA queue must be emptied here, otherwise CCDC interrupts that
1077 * will get triggered the next time the CCDC is powered up will try to
1078 * access buffers that might have been freed but still present in the
1079 * DMA queue. This can easily get triggered if the above
1080 * omap3isp_pipeline_set_stream() call fails on a system with a
1081 * free-running sensor.
1083 INIT_LIST_HEAD(&video
->dmaqueue
);
1084 video
->queue
= NULL
;
1086 mutex_unlock(&video
->stream_lock
);
1091 isp_video_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type type
)
1093 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
1094 struct isp_video
*video
= video_drvdata(file
);
1095 struct isp_pipeline
*pipe
= to_isp_pipeline(&video
->video
.entity
);
1096 enum isp_pipeline_state state
;
1097 unsigned int streaming
;
1098 unsigned long flags
;
1100 if (type
!= video
->type
)
1103 mutex_lock(&video
->stream_lock
);
1105 /* Make sure we're not streaming yet. */
1106 mutex_lock(&video
->queue_lock
);
1107 streaming
= vb2_is_streaming(&vfh
->queue
);
1108 mutex_unlock(&video
->queue_lock
);
1113 /* Update the pipeline state. */
1114 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1115 state
= ISP_PIPELINE_STREAM_OUTPUT
1116 | ISP_PIPELINE_QUEUE_OUTPUT
;
1118 state
= ISP_PIPELINE_STREAM_INPUT
1119 | ISP_PIPELINE_QUEUE_INPUT
;
1121 spin_lock_irqsave(&pipe
->lock
, flags
);
1122 pipe
->state
&= ~state
;
1123 spin_unlock_irqrestore(&pipe
->lock
, flags
);
1125 /* Stop the stream. */
1126 omap3isp_pipeline_set_stream(pipe
, ISP_PIPELINE_STREAM_STOPPED
);
1127 omap3isp_video_cancel_stream(video
);
1129 mutex_lock(&video
->queue_lock
);
1130 vb2_streamoff(&vfh
->queue
, type
);
1131 mutex_unlock(&video
->queue_lock
);
1132 video
->queue
= NULL
;
1133 video
->error
= false;
1135 if (video
->isp
->pdata
->set_constraints
)
1136 video
->isp
->pdata
->set_constraints(video
->isp
, false);
1137 media_entity_pipeline_stop(&video
->video
.entity
);
1140 mutex_unlock(&video
->stream_lock
);
1145 isp_video_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*input
)
1147 if (input
->index
> 0)
1150 strlcpy(input
->name
, "camera", sizeof(input
->name
));
1151 input
->type
= V4L2_INPUT_TYPE_CAMERA
;
1157 isp_video_g_input(struct file
*file
, void *fh
, unsigned int *input
)
1165 isp_video_s_input(struct file
*file
, void *fh
, unsigned int input
)
1167 return input
== 0 ? 0 : -EINVAL
;
1170 static const struct v4l2_ioctl_ops isp_video_ioctl_ops
= {
1171 .vidioc_querycap
= isp_video_querycap
,
1172 .vidioc_g_fmt_vid_cap
= isp_video_get_format
,
1173 .vidioc_s_fmt_vid_cap
= isp_video_set_format
,
1174 .vidioc_try_fmt_vid_cap
= isp_video_try_format
,
1175 .vidioc_g_fmt_vid_out
= isp_video_get_format
,
1176 .vidioc_s_fmt_vid_out
= isp_video_set_format
,
1177 .vidioc_try_fmt_vid_out
= isp_video_try_format
,
1178 .vidioc_cropcap
= isp_video_cropcap
,
1179 .vidioc_g_crop
= isp_video_get_crop
,
1180 .vidioc_s_crop
= isp_video_set_crop
,
1181 .vidioc_g_parm
= isp_video_get_param
,
1182 .vidioc_s_parm
= isp_video_set_param
,
1183 .vidioc_reqbufs
= isp_video_reqbufs
,
1184 .vidioc_querybuf
= isp_video_querybuf
,
1185 .vidioc_qbuf
= isp_video_qbuf
,
1186 .vidioc_dqbuf
= isp_video_dqbuf
,
1187 .vidioc_streamon
= isp_video_streamon
,
1188 .vidioc_streamoff
= isp_video_streamoff
,
1189 .vidioc_enum_input
= isp_video_enum_input
,
1190 .vidioc_g_input
= isp_video_g_input
,
1191 .vidioc_s_input
= isp_video_s_input
,
1194 /* -----------------------------------------------------------------------------
1195 * V4L2 file operations
1198 static int isp_video_open(struct file
*file
)
1200 struct isp_video
*video
= video_drvdata(file
);
1201 struct isp_video_fh
*handle
;
1202 struct vb2_queue
*queue
;
1205 handle
= kzalloc(sizeof(*handle
), GFP_KERNEL
);
1209 v4l2_fh_init(&handle
->vfh
, &video
->video
);
1210 v4l2_fh_add(&handle
->vfh
);
1212 /* If this is the first user, initialise the pipeline. */
1213 if (omap3isp_get(video
->isp
) == NULL
) {
1218 ret
= omap3isp_pipeline_pm_use(&video
->video
.entity
, 1);
1220 omap3isp_put(video
->isp
);
1224 queue
= &handle
->queue
;
1225 queue
->type
= video
->type
;
1226 queue
->io_modes
= VB2_MMAP
| VB2_USERPTR
;
1227 queue
->drv_priv
= handle
;
1228 queue
->ops
= &isp_video_queue_ops
;
1229 queue
->mem_ops
= &vb2_dma_contig_memops
;
1230 queue
->buf_struct_size
= sizeof(struct isp_buffer
);
1231 queue
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1233 ret
= vb2_queue_init(&handle
->queue
);
1235 omap3isp_put(video
->isp
);
1239 memset(&handle
->format
, 0, sizeof(handle
->format
));
1240 handle
->format
.type
= video
->type
;
1241 handle
->timeperframe
.denominator
= 1;
1243 handle
->video
= video
;
1244 file
->private_data
= &handle
->vfh
;
1248 v4l2_fh_del(&handle
->vfh
);
1255 static int isp_video_release(struct file
*file
)
1257 struct isp_video
*video
= video_drvdata(file
);
1258 struct v4l2_fh
*vfh
= file
->private_data
;
1259 struct isp_video_fh
*handle
= to_isp_video_fh(vfh
);
1261 /* Disable streaming and free the buffers queue resources. */
1262 isp_video_streamoff(file
, vfh
, video
->type
);
1264 mutex_lock(&video
->queue_lock
);
1265 vb2_queue_release(&handle
->queue
);
1266 mutex_unlock(&video
->queue_lock
);
1268 omap3isp_pipeline_pm_use(&video
->video
.entity
, 0);
1270 /* Release the file handle. */
1273 file
->private_data
= NULL
;
1275 omap3isp_put(video
->isp
);
1280 static unsigned int isp_video_poll(struct file
*file
, poll_table
*wait
)
1282 struct isp_video_fh
*vfh
= to_isp_video_fh(file
->private_data
);
1283 struct isp_video
*video
= video_drvdata(file
);
1286 mutex_lock(&video
->queue_lock
);
1287 ret
= vb2_poll(&vfh
->queue
, file
, wait
);
1288 mutex_unlock(&video
->queue_lock
);
1293 static int isp_video_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1295 struct isp_video_fh
*vfh
= to_isp_video_fh(file
->private_data
);
1296 struct isp_video
*video
= video_drvdata(file
);
1299 mutex_lock(&video
->queue_lock
);
1300 ret
= vb2_mmap(&vfh
->queue
, vma
);
1301 mutex_unlock(&video
->queue_lock
);
1306 static struct v4l2_file_operations isp_video_fops
= {
1307 .owner
= THIS_MODULE
,
1308 .unlocked_ioctl
= video_ioctl2
,
1309 .open
= isp_video_open
,
1310 .release
= isp_video_release
,
1311 .poll
= isp_video_poll
,
1312 .mmap
= isp_video_mmap
,
1315 /* -----------------------------------------------------------------------------
1319 static const struct isp_video_operations isp_video_dummy_ops
= {
1322 int omap3isp_video_init(struct isp_video
*video
, const char *name
)
1324 const char *direction
;
1327 switch (video
->type
) {
1328 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1329 direction
= "output";
1330 video
->pad
.flags
= MEDIA_PAD_FL_SINK
1331 | MEDIA_PAD_FL_MUST_CONNECT
;
1333 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1334 direction
= "input";
1335 video
->pad
.flags
= MEDIA_PAD_FL_SOURCE
1336 | MEDIA_PAD_FL_MUST_CONNECT
;
1337 video
->video
.vfl_dir
= VFL_DIR_TX
;
1344 video
->alloc_ctx
= vb2_dma_contig_init_ctx(video
->isp
->dev
);
1345 if (IS_ERR(video
->alloc_ctx
))
1346 return PTR_ERR(video
->alloc_ctx
);
1348 ret
= media_entity_init(&video
->video
.entity
, 1, &video
->pad
, 0);
1350 vb2_dma_contig_cleanup_ctx(video
->alloc_ctx
);
1354 mutex_init(&video
->mutex
);
1355 atomic_set(&video
->active
, 0);
1357 spin_lock_init(&video
->pipe
.lock
);
1358 mutex_init(&video
->stream_lock
);
1359 mutex_init(&video
->queue_lock
);
1360 spin_lock_init(&video
->irqlock
);
1362 /* Initialize the video device. */
1363 if (video
->ops
== NULL
)
1364 video
->ops
= &isp_video_dummy_ops
;
1366 video
->video
.fops
= &isp_video_fops
;
1367 snprintf(video
->video
.name
, sizeof(video
->video
.name
),
1368 "OMAP3 ISP %s %s", name
, direction
);
1369 video
->video
.vfl_type
= VFL_TYPE_GRABBER
;
1370 video
->video
.release
= video_device_release_empty
;
1371 video
->video
.ioctl_ops
= &isp_video_ioctl_ops
;
1372 video
->pipe
.stream_state
= ISP_PIPELINE_STREAM_STOPPED
;
1374 video_set_drvdata(&video
->video
, video
);
1379 void omap3isp_video_cleanup(struct isp_video
*video
)
1381 vb2_dma_contig_cleanup_ctx(video
->alloc_ctx
);
1382 media_entity_cleanup(&video
->video
.entity
);
1383 mutex_destroy(&video
->queue_lock
);
1384 mutex_destroy(&video
->stream_lock
);
1385 mutex_destroy(&video
->mutex
);
1388 int omap3isp_video_register(struct isp_video
*video
, struct v4l2_device
*vdev
)
1392 video
->video
.v4l2_dev
= vdev
;
1394 ret
= video_register_device(&video
->video
, VFL_TYPE_GRABBER
, -1);
1396 dev_err(video
->isp
->dev
,
1397 "%s: could not register video device (%d)\n",
1403 void omap3isp_video_unregister(struct isp_video
*video
)
1405 if (video_is_registered(&video
->video
))
1406 video_unregister_device(&video
->video
);