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/omap-iommu.h>
31 #include <linux/pagemap.h>
32 #include <linux/scatterlist.h>
33 #include <linux/sched.h>
34 #include <linux/slab.h>
35 #include <linux/vmalloc.h>
36 #include <media/v4l2-dev.h>
37 #include <media/v4l2-ioctl.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 /* -----------------------------------------------------------------------------
332 #define IOMMU_FLAG (IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_8)
335 * ispmmu_vmap - Wrapper for Virtual memory mapping of a scatter gather list
336 * @dev: Device pointer specific to the OMAP3 ISP.
337 * @sglist: Pointer to source Scatter gather list to allocate.
338 * @sglen: Number of elements of the scatter-gatter list.
340 * Returns a resulting mapped device address by the ISP MMU, or -ENOMEM if
341 * we ran out of memory.
344 ispmmu_vmap(struct isp_device
*isp
, const struct scatterlist
*sglist
, int sglen
)
346 struct sg_table
*sgt
;
349 sgt
= kmalloc(sizeof(*sgt
), GFP_KERNEL
);
353 sgt
->sgl
= (struct scatterlist
*)sglist
;
355 sgt
->orig_nents
= sglen
;
357 da
= omap_iommu_vmap(isp
->domain
, isp
->dev
, 0, sgt
, IOMMU_FLAG
);
358 if (IS_ERR_VALUE(da
))
365 * ispmmu_vunmap - Unmap a device address from the ISP MMU
366 * @dev: Device pointer specific to the OMAP3 ISP.
367 * @da: Device address generated from a ispmmu_vmap call.
369 static void ispmmu_vunmap(struct isp_device
*isp
, dma_addr_t da
)
371 struct sg_table
*sgt
;
373 sgt
= omap_iommu_vunmap(isp
->domain
, isp
->dev
, (u32
)da
);
377 /* -----------------------------------------------------------------------------
378 * Video queue operations
381 static void isp_video_queue_prepare(struct isp_video_queue
*queue
,
382 unsigned int *nbuffers
, unsigned int *size
)
384 struct isp_video_fh
*vfh
=
385 container_of(queue
, struct isp_video_fh
, queue
);
386 struct isp_video
*video
= vfh
->video
;
388 *size
= vfh
->format
.fmt
.pix
.sizeimage
;
392 *nbuffers
= min(*nbuffers
, video
->capture_mem
/ PAGE_ALIGN(*size
));
395 static void isp_video_buffer_cleanup(struct isp_video_buffer
*buf
)
397 struct isp_video_fh
*vfh
= isp_video_queue_to_isp_video_fh(buf
->queue
);
398 struct isp_buffer
*buffer
= to_isp_buffer(buf
);
399 struct isp_video
*video
= vfh
->video
;
401 if (buffer
->isp_addr
) {
402 ispmmu_vunmap(video
->isp
, buffer
->isp_addr
);
403 buffer
->isp_addr
= 0;
407 static int isp_video_buffer_prepare(struct isp_video_buffer
*buf
)
409 struct isp_video_fh
*vfh
= isp_video_queue_to_isp_video_fh(buf
->queue
);
410 struct isp_buffer
*buffer
= to_isp_buffer(buf
);
411 struct isp_video
*video
= vfh
->video
;
414 /* Refuse to prepare the buffer is the video node has registered an
415 * error. We don't need to take any lock here as the operation is
416 * inherently racy. The authoritative check will be performed in the
417 * queue handler, which can't return an error, this check is just a best
418 * effort to notify userspace as early as possible.
420 if (unlikely(video
->error
))
423 addr
= ispmmu_vmap(video
->isp
, buf
->sglist
, buf
->sglen
);
424 if (IS_ERR_VALUE(addr
))
427 if (!IS_ALIGNED(addr
, 32)) {
428 dev_dbg(video
->isp
->dev
, "Buffer address must be "
429 "aligned to 32 bytes boundary.\n");
430 ispmmu_vunmap(video
->isp
, buffer
->isp_addr
);
434 buf
->vbuf
.bytesused
= vfh
->format
.fmt
.pix
.sizeimage
;
435 buffer
->isp_addr
= addr
;
440 * isp_video_buffer_queue - Add buffer to streaming queue
443 * In memory-to-memory mode, start streaming on the pipeline if buffers are
444 * queued on both the input and the output, if the pipeline isn't already busy.
445 * If the pipeline is busy, it will be restarted in the output module interrupt
448 static void isp_video_buffer_queue(struct isp_video_buffer
*buf
)
450 struct isp_video_fh
*vfh
= isp_video_queue_to_isp_video_fh(buf
->queue
);
451 struct isp_buffer
*buffer
= to_isp_buffer(buf
);
452 struct isp_video
*video
= vfh
->video
;
453 struct isp_pipeline
*pipe
= to_isp_pipeline(&video
->video
.entity
);
454 enum isp_pipeline_state state
;
459 if (unlikely(video
->error
)) {
460 buf
->state
= ISP_BUF_STATE_ERROR
;
465 empty
= list_empty(&video
->dmaqueue
);
466 list_add_tail(&buffer
->buffer
.irqlist
, &video
->dmaqueue
);
469 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
470 state
= ISP_PIPELINE_QUEUE_OUTPUT
;
472 state
= ISP_PIPELINE_QUEUE_INPUT
;
474 spin_lock_irqsave(&pipe
->lock
, flags
);
475 pipe
->state
|= state
;
476 video
->ops
->queue(video
, buffer
);
477 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_QUEUED
;
479 start
= isp_pipeline_ready(pipe
);
481 pipe
->state
|= ISP_PIPELINE_STREAM
;
482 spin_unlock_irqrestore(&pipe
->lock
, flags
);
485 omap3isp_pipeline_set_stream(pipe
,
486 ISP_PIPELINE_STREAM_SINGLESHOT
);
490 static const struct isp_video_queue_operations isp_video_queue_ops
= {
491 .queue_prepare
= &isp_video_queue_prepare
,
492 .buffer_prepare
= &isp_video_buffer_prepare
,
493 .buffer_queue
= &isp_video_buffer_queue
,
494 .buffer_cleanup
= &isp_video_buffer_cleanup
,
498 * omap3isp_video_buffer_next - Complete the current buffer and return the next
499 * @video: ISP video object
501 * Remove the current video buffer from the DMA queue and fill its timestamp,
502 * field count and state fields before waking up its completion handler.
504 * For capture video nodes the buffer state is set to ISP_BUF_STATE_DONE if no
505 * error has been flagged in the pipeline, or to ISP_BUF_STATE_ERROR otherwise.
506 * For video output nodes the buffer state is always set to ISP_BUF_STATE_DONE.
508 * The DMA queue is expected to contain at least one buffer.
510 * Return a pointer to the next buffer in the DMA queue, or NULL if the queue is
513 struct isp_buffer
*omap3isp_video_buffer_next(struct isp_video
*video
)
515 struct isp_pipeline
*pipe
= to_isp_pipeline(&video
->video
.entity
);
516 struct isp_video_queue
*queue
= video
->queue
;
517 enum isp_pipeline_state state
;
518 struct isp_video_buffer
*buf
;
522 spin_lock_irqsave(&queue
->irqlock
, flags
);
523 if (WARN_ON(list_empty(&video
->dmaqueue
))) {
524 spin_unlock_irqrestore(&queue
->irqlock
, flags
);
528 buf
= list_first_entry(&video
->dmaqueue
, struct isp_video_buffer
,
530 list_del(&buf
->irqlist
);
531 spin_unlock_irqrestore(&queue
->irqlock
, flags
);
534 buf
->vbuf
.timestamp
.tv_sec
= ts
.tv_sec
;
535 buf
->vbuf
.timestamp
.tv_usec
= ts
.tv_nsec
/ NSEC_PER_USEC
;
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
)
544 buf
->vbuf
.sequence
= atomic_inc_return(&pipe
->frame_number
);
546 buf
->vbuf
.sequence
= atomic_read(&pipe
->frame_number
);
548 /* Report pipeline errors to userspace on the capture device side. */
549 if (queue
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& pipe
->error
) {
550 buf
->state
= ISP_BUF_STATE_ERROR
;
553 buf
->state
= ISP_BUF_STATE_DONE
;
558 if (list_empty(&video
->dmaqueue
)) {
559 if (queue
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
560 state
= ISP_PIPELINE_QUEUE_OUTPUT
561 | ISP_PIPELINE_STREAM
;
563 state
= ISP_PIPELINE_QUEUE_INPUT
564 | ISP_PIPELINE_STREAM
;
566 spin_lock_irqsave(&pipe
->lock
, flags
);
567 pipe
->state
&= ~state
;
568 if (video
->pipe
.stream_state
== ISP_PIPELINE_STREAM_CONTINUOUS
)
569 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
570 spin_unlock_irqrestore(&pipe
->lock
, flags
);
574 if (queue
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& pipe
->input
!= NULL
) {
575 spin_lock_irqsave(&pipe
->lock
, flags
);
576 pipe
->state
&= ~ISP_PIPELINE_STREAM
;
577 spin_unlock_irqrestore(&pipe
->lock
, flags
);
580 buf
= list_first_entry(&video
->dmaqueue
, struct isp_video_buffer
,
582 buf
->state
= ISP_BUF_STATE_ACTIVE
;
583 return to_isp_buffer(buf
);
587 * omap3isp_video_cancel_stream - Cancel stream on a video node
588 * @video: ISP video object
590 * Cancelling a stream mark all buffers on the video node as erroneous and makes
591 * sure no new buffer can be queued.
593 void omap3isp_video_cancel_stream(struct isp_video
*video
)
595 struct isp_video_queue
*queue
= video
->queue
;
598 spin_lock_irqsave(&queue
->irqlock
, flags
);
600 while (!list_empty(&video
->dmaqueue
)) {
601 struct isp_video_buffer
*buf
;
603 buf
= list_first_entry(&video
->dmaqueue
,
604 struct isp_video_buffer
, irqlist
);
605 list_del(&buf
->irqlist
);
607 buf
->state
= ISP_BUF_STATE_ERROR
;
613 spin_unlock_irqrestore(&queue
->irqlock
, flags
);
617 * omap3isp_video_resume - Perform resume operation on the buffers
618 * @video: ISP video object
619 * @continuous: Pipeline is in single shot mode if 0 or continuous mode otherwise
621 * This function is intended to be used on suspend/resume scenario. It
622 * requests video queue layer to discard buffers marked as DONE if it's in
623 * continuous mode and requests ISP modules to queue again the ACTIVE buffer
626 void omap3isp_video_resume(struct isp_video
*video
, int continuous
)
628 struct isp_buffer
*buf
= NULL
;
630 if (continuous
&& video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
631 omap3isp_video_queue_discard_done(video
->queue
);
633 if (!list_empty(&video
->dmaqueue
)) {
634 buf
= list_first_entry(&video
->dmaqueue
,
635 struct isp_buffer
, buffer
.irqlist
);
636 video
->ops
->queue(video
, buf
);
637 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_QUEUED
;
640 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
644 /* -----------------------------------------------------------------------------
649 isp_video_querycap(struct file
*file
, void *fh
, struct v4l2_capability
*cap
)
651 struct isp_video
*video
= video_drvdata(file
);
653 strlcpy(cap
->driver
, ISP_VIDEO_DRIVER_NAME
, sizeof(cap
->driver
));
654 strlcpy(cap
->card
, video
->video
.name
, sizeof(cap
->card
));
655 strlcpy(cap
->bus_info
, "media", sizeof(cap
->bus_info
));
657 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
658 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
660 cap
->capabilities
= V4L2_CAP_VIDEO_OUTPUT
| V4L2_CAP_STREAMING
;
666 isp_video_get_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
668 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
669 struct isp_video
*video
= video_drvdata(file
);
671 if (format
->type
!= video
->type
)
674 mutex_lock(&video
->mutex
);
675 *format
= vfh
->format
;
676 mutex_unlock(&video
->mutex
);
682 isp_video_set_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
684 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
685 struct isp_video
*video
= video_drvdata(file
);
686 struct v4l2_mbus_framefmt fmt
;
688 if (format
->type
!= video
->type
)
691 mutex_lock(&video
->mutex
);
693 /* Fill the bytesperline and sizeimage fields by converting to media bus
694 * format and back to pixel format.
696 isp_video_pix_to_mbus(&format
->fmt
.pix
, &fmt
);
697 isp_video_mbus_to_pix(video
, &fmt
, &format
->fmt
.pix
);
699 vfh
->format
= *format
;
701 mutex_unlock(&video
->mutex
);
706 isp_video_try_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
708 struct isp_video
*video
= video_drvdata(file
);
709 struct v4l2_subdev_format fmt
;
710 struct v4l2_subdev
*subdev
;
714 if (format
->type
!= video
->type
)
717 subdev
= isp_video_remote_subdev(video
, &pad
);
721 isp_video_pix_to_mbus(&format
->fmt
.pix
, &fmt
.format
);
724 fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
725 ret
= v4l2_subdev_call(subdev
, pad
, get_fmt
, NULL
, &fmt
);
727 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
729 isp_video_mbus_to_pix(video
, &fmt
.format
, &format
->fmt
.pix
);
734 isp_video_cropcap(struct file
*file
, void *fh
, struct v4l2_cropcap
*cropcap
)
736 struct isp_video
*video
= video_drvdata(file
);
737 struct v4l2_subdev
*subdev
;
740 subdev
= isp_video_remote_subdev(video
, NULL
);
744 mutex_lock(&video
->mutex
);
745 ret
= v4l2_subdev_call(subdev
, video
, cropcap
, cropcap
);
746 mutex_unlock(&video
->mutex
);
748 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
752 isp_video_get_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
754 struct isp_video
*video
= video_drvdata(file
);
755 struct v4l2_subdev_format format
;
756 struct v4l2_subdev
*subdev
;
760 subdev
= isp_video_remote_subdev(video
, &pad
);
764 /* Try the get crop operation first and fallback to get format if not
767 ret
= v4l2_subdev_call(subdev
, video
, g_crop
, crop
);
768 if (ret
!= -ENOIOCTLCMD
)
772 format
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
773 ret
= v4l2_subdev_call(subdev
, pad
, get_fmt
, NULL
, &format
);
775 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
779 crop
->c
.width
= format
.format
.width
;
780 crop
->c
.height
= format
.format
.height
;
786 isp_video_set_crop(struct file
*file
, void *fh
, const struct v4l2_crop
*crop
)
788 struct isp_video
*video
= video_drvdata(file
);
789 struct v4l2_subdev
*subdev
;
792 subdev
= isp_video_remote_subdev(video
, NULL
);
796 mutex_lock(&video
->mutex
);
797 ret
= v4l2_subdev_call(subdev
, video
, s_crop
, crop
);
798 mutex_unlock(&video
->mutex
);
800 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
804 isp_video_get_param(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
806 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
807 struct isp_video
*video
= video_drvdata(file
);
809 if (video
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
810 video
->type
!= a
->type
)
813 memset(a
, 0, sizeof(*a
));
814 a
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
815 a
->parm
.output
.capability
= V4L2_CAP_TIMEPERFRAME
;
816 a
->parm
.output
.timeperframe
= vfh
->timeperframe
;
822 isp_video_set_param(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
824 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
825 struct isp_video
*video
= video_drvdata(file
);
827 if (video
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
828 video
->type
!= a
->type
)
831 if (a
->parm
.output
.timeperframe
.denominator
== 0)
832 a
->parm
.output
.timeperframe
.denominator
= 1;
834 vfh
->timeperframe
= a
->parm
.output
.timeperframe
;
840 isp_video_reqbufs(struct file
*file
, void *fh
, struct v4l2_requestbuffers
*rb
)
842 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
844 return omap3isp_video_queue_reqbufs(&vfh
->queue
, rb
);
848 isp_video_querybuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
850 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
852 return omap3isp_video_queue_querybuf(&vfh
->queue
, b
);
856 isp_video_qbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
858 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
860 return omap3isp_video_queue_qbuf(&vfh
->queue
, b
);
864 isp_video_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
866 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
868 return omap3isp_video_queue_dqbuf(&vfh
->queue
, b
,
869 file
->f_flags
& O_NONBLOCK
);
872 static int isp_video_check_external_subdevs(struct isp_video
*video
,
873 struct isp_pipeline
*pipe
)
875 struct isp_device
*isp
= video
->isp
;
876 struct media_entity
*ents
[] = {
877 &isp
->isp_csi2a
.subdev
.entity
,
878 &isp
->isp_csi2c
.subdev
.entity
,
879 &isp
->isp_ccp2
.subdev
.entity
,
880 &isp
->isp_ccdc
.subdev
.entity
882 struct media_pad
*source_pad
;
883 struct media_entity
*source
= NULL
;
884 struct media_entity
*sink
;
885 struct v4l2_subdev_format fmt
;
886 struct v4l2_ext_controls ctrls
;
887 struct v4l2_ext_control ctrl
;
891 for (i
= 0; i
< ARRAY_SIZE(ents
); i
++) {
892 /* Is the entity part of the pipeline? */
893 if (!(pipe
->entities
& (1 << ents
[i
]->id
)))
896 /* ISP entities have always sink pad == 0. Find source. */
897 source_pad
= media_entity_remote_pad(&ents
[i
]->pads
[0]);
898 if (source_pad
== NULL
)
901 source
= source_pad
->entity
;
907 dev_warn(isp
->dev
, "can't find source, failing now\n");
911 if (media_entity_type(source
) != MEDIA_ENT_T_V4L2_SUBDEV
)
914 pipe
->external
= media_entity_to_v4l2_subdev(source
);
916 fmt
.pad
= source_pad
->index
;
917 fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
918 ret
= v4l2_subdev_call(media_entity_to_v4l2_subdev(sink
),
919 pad
, get_fmt
, NULL
, &fmt
);
920 if (unlikely(ret
< 0)) {
921 dev_warn(isp
->dev
, "get_fmt returned null!\n");
925 pipe
->external_width
=
926 omap3isp_video_format_info(fmt
.format
.code
)->width
;
928 memset(&ctrls
, 0, sizeof(ctrls
));
929 memset(&ctrl
, 0, sizeof(ctrl
));
931 ctrl
.id
= V4L2_CID_PIXEL_RATE
;
934 ctrls
.controls
= &ctrl
;
936 ret
= v4l2_g_ext_ctrls(pipe
->external
->ctrl_handler
, &ctrls
);
938 dev_warn(isp
->dev
, "no pixel rate control in subdev %s\n",
939 pipe
->external
->name
);
943 pipe
->external_rate
= ctrl
.value64
;
945 if (pipe
->entities
& (1 << isp
->isp_ccdc
.subdev
.entity
.id
)) {
946 unsigned int rate
= UINT_MAX
;
948 * Check that maximum allowed CCDC pixel rate isn't
949 * exceeded by the pixel rate.
951 omap3isp_ccdc_max_rate(&isp
->isp_ccdc
, &rate
);
952 if (pipe
->external_rate
> rate
)
962 * Every ISP pipeline has a single input and a single output. The input can be
963 * either a sensor or a video node. The output is always a video node.
965 * As every pipeline has an output video node, the ISP video objects at the
966 * pipeline output stores the pipeline state. It tracks the streaming state of
967 * both the input and output, as well as the availability of buffers.
969 * In sensor-to-memory mode, frames are always available at the pipeline input.
970 * Starting the sensor usually requires I2C transfers and must be done in
971 * interruptible context. The pipeline is started and stopped synchronously
972 * to the stream on/off commands. All modules in the pipeline will get their
973 * subdev set stream handler called. The module at the end of the pipeline must
974 * delay starting the hardware until buffers are available at its output.
976 * In memory-to-memory mode, starting/stopping the stream requires
977 * synchronization between the input and output. ISP modules can't be stopped
978 * in the middle of a frame, and at least some of the modules seem to become
979 * busy as soon as they're started, even if they don't receive a frame start
980 * event. For that reason frames need to be processed in single-shot mode. The
981 * driver needs to wait until a frame is completely processed and written to
982 * memory before restarting the pipeline for the next frame. Pipelined
983 * processing might be possible but requires more testing.
985 * Stream start must be delayed until buffers are available at both the input
986 * and output. The pipeline must be started in the videobuf queue callback with
987 * the buffers queue spinlock held. The modules subdev set stream operation must
991 isp_video_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type type
)
993 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
994 struct isp_video
*video
= video_drvdata(file
);
995 enum isp_pipeline_state state
;
996 struct isp_pipeline
*pipe
;
1000 if (type
!= video
->type
)
1003 mutex_lock(&video
->stream_lock
);
1005 if (video
->streaming
) {
1006 mutex_unlock(&video
->stream_lock
);
1010 /* Start streaming on the pipeline. No link touching an entity in the
1011 * pipeline can be activated or deactivated once streaming is started.
1013 pipe
= video
->video
.entity
.pipe
1014 ? to_isp_pipeline(&video
->video
.entity
) : &video
->pipe
;
1018 if (video
->isp
->pdata
->set_constraints
)
1019 video
->isp
->pdata
->set_constraints(video
->isp
, true);
1020 pipe
->l3_ick
= clk_get_rate(video
->isp
->clock
[ISP_CLK_L3_ICK
]);
1021 pipe
->max_rate
= pipe
->l3_ick
;
1023 ret
= media_entity_pipeline_start(&video
->video
.entity
, &pipe
->pipe
);
1025 goto err_pipeline_start
;
1027 /* Verify that the currently configured format matches the output of
1028 * the connected subdev.
1030 ret
= isp_video_check_format(video
, vfh
);
1032 goto err_check_format
;
1034 video
->bpl_padding
= ret
;
1035 video
->bpl_value
= vfh
->format
.fmt
.pix
.bytesperline
;
1037 ret
= isp_video_get_graph_data(video
, pipe
);
1039 goto err_check_format
;
1041 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1042 state
= ISP_PIPELINE_STREAM_OUTPUT
| ISP_PIPELINE_IDLE_OUTPUT
;
1044 state
= ISP_PIPELINE_STREAM_INPUT
| ISP_PIPELINE_IDLE_INPUT
;
1046 ret
= isp_video_check_external_subdevs(video
, pipe
);
1048 goto err_check_format
;
1050 pipe
->error
= false;
1052 spin_lock_irqsave(&pipe
->lock
, flags
);
1053 pipe
->state
&= ~ISP_PIPELINE_STREAM
;
1054 pipe
->state
|= state
;
1055 spin_unlock_irqrestore(&pipe
->lock
, flags
);
1057 /* Set the maximum time per frame as the value requested by userspace.
1058 * This is a soft limit that can be overridden if the hardware doesn't
1059 * support the request limit.
1061 if (video
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1062 pipe
->max_timeperframe
= vfh
->timeperframe
;
1064 video
->queue
= &vfh
->queue
;
1065 INIT_LIST_HEAD(&video
->dmaqueue
);
1066 atomic_set(&pipe
->frame_number
, -1);
1068 ret
= omap3isp_video_queue_streamon(&vfh
->queue
);
1070 goto err_check_format
;
1072 /* In sensor-to-memory mode, the stream can be started synchronously
1073 * to the stream on command. In memory-to-memory mode, it will be
1074 * started when buffers are queued on both the input and output.
1076 if (pipe
->input
== NULL
) {
1077 ret
= omap3isp_pipeline_set_stream(pipe
,
1078 ISP_PIPELINE_STREAM_CONTINUOUS
);
1080 goto err_set_stream
;
1081 spin_lock_irqsave(&video
->queue
->irqlock
, flags
);
1082 if (list_empty(&video
->dmaqueue
))
1083 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
1084 spin_unlock_irqrestore(&video
->queue
->irqlock
, flags
);
1087 video
->streaming
= 1;
1089 mutex_unlock(&video
->stream_lock
);
1093 omap3isp_video_queue_streamoff(&vfh
->queue
);
1095 media_entity_pipeline_stop(&video
->video
.entity
);
1097 if (video
->isp
->pdata
->set_constraints
)
1098 video
->isp
->pdata
->set_constraints(video
->isp
, false);
1099 /* The DMA queue must be emptied here, otherwise CCDC interrupts that
1100 * will get triggered the next time the CCDC is powered up will try to
1101 * access buffers that might have been freed but still present in the
1102 * DMA queue. This can easily get triggered if the above
1103 * omap3isp_pipeline_set_stream() call fails on a system with a
1104 * free-running sensor.
1106 INIT_LIST_HEAD(&video
->dmaqueue
);
1107 video
->queue
= NULL
;
1109 mutex_unlock(&video
->stream_lock
);
1114 isp_video_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type type
)
1116 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
1117 struct isp_video
*video
= video_drvdata(file
);
1118 struct isp_pipeline
*pipe
= to_isp_pipeline(&video
->video
.entity
);
1119 enum isp_pipeline_state state
;
1120 unsigned int streaming
;
1121 unsigned long flags
;
1123 if (type
!= video
->type
)
1126 mutex_lock(&video
->stream_lock
);
1128 /* Make sure we're not streaming yet. */
1129 mutex_lock(&vfh
->queue
.lock
);
1130 streaming
= vfh
->queue
.streaming
;
1131 mutex_unlock(&vfh
->queue
.lock
);
1136 /* Update the pipeline state. */
1137 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1138 state
= ISP_PIPELINE_STREAM_OUTPUT
1139 | ISP_PIPELINE_QUEUE_OUTPUT
;
1141 state
= ISP_PIPELINE_STREAM_INPUT
1142 | ISP_PIPELINE_QUEUE_INPUT
;
1144 spin_lock_irqsave(&pipe
->lock
, flags
);
1145 pipe
->state
&= ~state
;
1146 spin_unlock_irqrestore(&pipe
->lock
, flags
);
1148 /* Stop the stream. */
1149 omap3isp_pipeline_set_stream(pipe
, ISP_PIPELINE_STREAM_STOPPED
);
1150 omap3isp_video_queue_streamoff(&vfh
->queue
);
1151 video
->queue
= NULL
;
1152 video
->streaming
= 0;
1153 video
->error
= false;
1155 if (video
->isp
->pdata
->set_constraints
)
1156 video
->isp
->pdata
->set_constraints(video
->isp
, false);
1157 media_entity_pipeline_stop(&video
->video
.entity
);
1160 mutex_unlock(&video
->stream_lock
);
1165 isp_video_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*input
)
1167 if (input
->index
> 0)
1170 strlcpy(input
->name
, "camera", sizeof(input
->name
));
1171 input
->type
= V4L2_INPUT_TYPE_CAMERA
;
1177 isp_video_g_input(struct file
*file
, void *fh
, unsigned int *input
)
1185 isp_video_s_input(struct file
*file
, void *fh
, unsigned int input
)
1187 return input
== 0 ? 0 : -EINVAL
;
1190 static const struct v4l2_ioctl_ops isp_video_ioctl_ops
= {
1191 .vidioc_querycap
= isp_video_querycap
,
1192 .vidioc_g_fmt_vid_cap
= isp_video_get_format
,
1193 .vidioc_s_fmt_vid_cap
= isp_video_set_format
,
1194 .vidioc_try_fmt_vid_cap
= isp_video_try_format
,
1195 .vidioc_g_fmt_vid_out
= isp_video_get_format
,
1196 .vidioc_s_fmt_vid_out
= isp_video_set_format
,
1197 .vidioc_try_fmt_vid_out
= isp_video_try_format
,
1198 .vidioc_cropcap
= isp_video_cropcap
,
1199 .vidioc_g_crop
= isp_video_get_crop
,
1200 .vidioc_s_crop
= isp_video_set_crop
,
1201 .vidioc_g_parm
= isp_video_get_param
,
1202 .vidioc_s_parm
= isp_video_set_param
,
1203 .vidioc_reqbufs
= isp_video_reqbufs
,
1204 .vidioc_querybuf
= isp_video_querybuf
,
1205 .vidioc_qbuf
= isp_video_qbuf
,
1206 .vidioc_dqbuf
= isp_video_dqbuf
,
1207 .vidioc_streamon
= isp_video_streamon
,
1208 .vidioc_streamoff
= isp_video_streamoff
,
1209 .vidioc_enum_input
= isp_video_enum_input
,
1210 .vidioc_g_input
= isp_video_g_input
,
1211 .vidioc_s_input
= isp_video_s_input
,
1214 /* -----------------------------------------------------------------------------
1215 * V4L2 file operations
1218 static int isp_video_open(struct file
*file
)
1220 struct isp_video
*video
= video_drvdata(file
);
1221 struct isp_video_fh
*handle
;
1224 handle
= kzalloc(sizeof(*handle
), GFP_KERNEL
);
1228 v4l2_fh_init(&handle
->vfh
, &video
->video
);
1229 v4l2_fh_add(&handle
->vfh
);
1231 /* If this is the first user, initialise the pipeline. */
1232 if (omap3isp_get(video
->isp
) == NULL
) {
1237 ret
= omap3isp_pipeline_pm_use(&video
->video
.entity
, 1);
1239 omap3isp_put(video
->isp
);
1243 omap3isp_video_queue_init(&handle
->queue
, video
->type
,
1244 &isp_video_queue_ops
, video
->isp
->dev
,
1245 sizeof(struct isp_buffer
));
1247 memset(&handle
->format
, 0, sizeof(handle
->format
));
1248 handle
->format
.type
= video
->type
;
1249 handle
->timeperframe
.denominator
= 1;
1251 handle
->video
= video
;
1252 file
->private_data
= &handle
->vfh
;
1256 v4l2_fh_del(&handle
->vfh
);
1263 static int isp_video_release(struct file
*file
)
1265 struct isp_video
*video
= video_drvdata(file
);
1266 struct v4l2_fh
*vfh
= file
->private_data
;
1267 struct isp_video_fh
*handle
= to_isp_video_fh(vfh
);
1269 /* Disable streaming and free the buffers queue resources. */
1270 isp_video_streamoff(file
, vfh
, video
->type
);
1272 mutex_lock(&handle
->queue
.lock
);
1273 omap3isp_video_queue_cleanup(&handle
->queue
);
1274 mutex_unlock(&handle
->queue
.lock
);
1276 omap3isp_pipeline_pm_use(&video
->video
.entity
, 0);
1278 /* Release the file handle. */
1281 file
->private_data
= NULL
;
1283 omap3isp_put(video
->isp
);
1288 static unsigned int isp_video_poll(struct file
*file
, poll_table
*wait
)
1290 struct isp_video_fh
*vfh
= to_isp_video_fh(file
->private_data
);
1291 struct isp_video_queue
*queue
= &vfh
->queue
;
1293 return omap3isp_video_queue_poll(queue
, file
, wait
);
1296 static int isp_video_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1298 struct isp_video_fh
*vfh
= to_isp_video_fh(file
->private_data
);
1300 return omap3isp_video_queue_mmap(&vfh
->queue
, vma
);
1303 static struct v4l2_file_operations isp_video_fops
= {
1304 .owner
= THIS_MODULE
,
1305 .unlocked_ioctl
= video_ioctl2
,
1306 .open
= isp_video_open
,
1307 .release
= isp_video_release
,
1308 .poll
= isp_video_poll
,
1309 .mmap
= isp_video_mmap
,
1312 /* -----------------------------------------------------------------------------
1316 static const struct isp_video_operations isp_video_dummy_ops
= {
1319 int omap3isp_video_init(struct isp_video
*video
, const char *name
)
1321 const char *direction
;
1324 switch (video
->type
) {
1325 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1326 direction
= "output";
1327 video
->pad
.flags
= MEDIA_PAD_FL_SINK
1328 | MEDIA_PAD_FL_MUST_CONNECT
;
1330 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1331 direction
= "input";
1332 video
->pad
.flags
= MEDIA_PAD_FL_SOURCE
1333 | MEDIA_PAD_FL_MUST_CONNECT
;
1334 video
->video
.vfl_dir
= VFL_DIR_TX
;
1341 ret
= media_entity_init(&video
->video
.entity
, 1, &video
->pad
, 0);
1345 mutex_init(&video
->mutex
);
1346 atomic_set(&video
->active
, 0);
1348 spin_lock_init(&video
->pipe
.lock
);
1349 mutex_init(&video
->stream_lock
);
1351 /* Initialize the video device. */
1352 if (video
->ops
== NULL
)
1353 video
->ops
= &isp_video_dummy_ops
;
1355 video
->video
.fops
= &isp_video_fops
;
1356 snprintf(video
->video
.name
, sizeof(video
->video
.name
),
1357 "OMAP3 ISP %s %s", name
, direction
);
1358 video
->video
.vfl_type
= VFL_TYPE_GRABBER
;
1359 video
->video
.release
= video_device_release_empty
;
1360 video
->video
.ioctl_ops
= &isp_video_ioctl_ops
;
1361 video
->pipe
.stream_state
= ISP_PIPELINE_STREAM_STOPPED
;
1363 video_set_drvdata(&video
->video
, video
);
1368 void omap3isp_video_cleanup(struct isp_video
*video
)
1370 media_entity_cleanup(&video
->video
.entity
);
1371 mutex_destroy(&video
->stream_lock
);
1372 mutex_destroy(&video
->mutex
);
1375 int omap3isp_video_register(struct isp_video
*video
, struct v4l2_device
*vdev
)
1379 video
->video
.v4l2_dev
= vdev
;
1381 ret
= video_register_device(&video
->video
, VFL_TYPE_GRABBER
, -1);
1383 dev_err(video
->isp
->dev
,
1384 "%s: could not register video device (%d)\n",
1390 void omap3isp_video_unregister(struct isp_video
*video
)
1392 if (video_is_registered(&video
->video
))
1393 video_unregister_device(&video
->video
);