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 * Validate a pipeline by checking both ends of all links for format
285 * Compute the minimum time per frame value as the maximum of time per frame
286 * limits reported by every block in the pipeline.
288 * Return 0 if all formats match, or -EPIPE if at least one link is found with
289 * different formats on its two ends or if the pipeline doesn't start with a
290 * video source (either a subdev with no input pad, or a non-subdev entity).
292 static int isp_video_validate_pipeline(struct isp_pipeline
*pipe
)
294 struct isp_device
*isp
= pipe
->output
->isp
;
295 struct media_pad
*pad
;
296 struct v4l2_subdev
*subdev
;
298 subdev
= isp_video_remote_subdev(pipe
->output
, NULL
);
303 /* Retrieve the sink format */
304 pad
= &subdev
->entity
.pads
[0];
305 if (!(pad
->flags
& MEDIA_PAD_FL_SINK
))
308 /* Update the maximum frame rate */
309 if (subdev
== &isp
->isp_res
.subdev
)
310 omap3isp_resizer_max_rate(&isp
->isp_res
,
313 /* Retrieve the source format. Return an error if no source
314 * entity can be found, and stop checking the pipeline if the
315 * source entity isn't a subdev.
317 pad
= media_entity_remote_pad(pad
);
321 if (media_entity_type(pad
->entity
) != MEDIA_ENT_T_V4L2_SUBDEV
)
324 subdev
= media_entity_to_v4l2_subdev(pad
->entity
);
331 __isp_video_get_format(struct isp_video
*video
, struct v4l2_format
*format
)
333 struct v4l2_subdev_format fmt
;
334 struct v4l2_subdev
*subdev
;
338 subdev
= isp_video_remote_subdev(video
, &pad
);
342 mutex_lock(&video
->mutex
);
345 fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
346 ret
= v4l2_subdev_call(subdev
, pad
, get_fmt
, NULL
, &fmt
);
347 if (ret
== -ENOIOCTLCMD
)
350 mutex_unlock(&video
->mutex
);
355 format
->type
= video
->type
;
356 return isp_video_mbus_to_pix(video
, &fmt
.format
, &format
->fmt
.pix
);
360 isp_video_check_format(struct isp_video
*video
, struct isp_video_fh
*vfh
)
362 struct v4l2_format format
;
365 memcpy(&format
, &vfh
->format
, sizeof(format
));
366 ret
= __isp_video_get_format(video
, &format
);
370 if (vfh
->format
.fmt
.pix
.pixelformat
!= format
.fmt
.pix
.pixelformat
||
371 vfh
->format
.fmt
.pix
.height
!= format
.fmt
.pix
.height
||
372 vfh
->format
.fmt
.pix
.width
!= format
.fmt
.pix
.width
||
373 vfh
->format
.fmt
.pix
.bytesperline
!= format
.fmt
.pix
.bytesperline
||
374 vfh
->format
.fmt
.pix
.sizeimage
!= format
.fmt
.pix
.sizeimage
)
380 /* -----------------------------------------------------------------------------
384 #define IOMMU_FLAG (IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_8)
387 * ispmmu_vmap - Wrapper for Virtual memory mapping of a scatter gather list
388 * @dev: Device pointer specific to the OMAP3 ISP.
389 * @sglist: Pointer to source Scatter gather list to allocate.
390 * @sglen: Number of elements of the scatter-gatter list.
392 * Returns a resulting mapped device address by the ISP MMU, or -ENOMEM if
393 * we ran out of memory.
396 ispmmu_vmap(struct isp_device
*isp
, const struct scatterlist
*sglist
, int sglen
)
398 struct sg_table
*sgt
;
401 sgt
= kmalloc(sizeof(*sgt
), GFP_KERNEL
);
405 sgt
->sgl
= (struct scatterlist
*)sglist
;
407 sgt
->orig_nents
= sglen
;
409 da
= omap_iommu_vmap(isp
->domain
, isp
->dev
, 0, sgt
, IOMMU_FLAG
);
410 if (IS_ERR_VALUE(da
))
417 * ispmmu_vunmap - Unmap a device address from the ISP MMU
418 * @dev: Device pointer specific to the OMAP3 ISP.
419 * @da: Device address generated from a ispmmu_vmap call.
421 static void ispmmu_vunmap(struct isp_device
*isp
, dma_addr_t da
)
423 struct sg_table
*sgt
;
425 sgt
= omap_iommu_vunmap(isp
->domain
, isp
->dev
, (u32
)da
);
429 /* -----------------------------------------------------------------------------
430 * Video queue operations
433 static void isp_video_queue_prepare(struct isp_video_queue
*queue
,
434 unsigned int *nbuffers
, unsigned int *size
)
436 struct isp_video_fh
*vfh
=
437 container_of(queue
, struct isp_video_fh
, queue
);
438 struct isp_video
*video
= vfh
->video
;
440 *size
= vfh
->format
.fmt
.pix
.sizeimage
;
444 *nbuffers
= min(*nbuffers
, video
->capture_mem
/ PAGE_ALIGN(*size
));
447 static void isp_video_buffer_cleanup(struct isp_video_buffer
*buf
)
449 struct isp_video_fh
*vfh
= isp_video_queue_to_isp_video_fh(buf
->queue
);
450 struct isp_buffer
*buffer
= to_isp_buffer(buf
);
451 struct isp_video
*video
= vfh
->video
;
453 if (buffer
->isp_addr
) {
454 ispmmu_vunmap(video
->isp
, buffer
->isp_addr
);
455 buffer
->isp_addr
= 0;
459 static int isp_video_buffer_prepare(struct isp_video_buffer
*buf
)
461 struct isp_video_fh
*vfh
= isp_video_queue_to_isp_video_fh(buf
->queue
);
462 struct isp_buffer
*buffer
= to_isp_buffer(buf
);
463 struct isp_video
*video
= vfh
->video
;
466 addr
= ispmmu_vmap(video
->isp
, buf
->sglist
, buf
->sglen
);
467 if (IS_ERR_VALUE(addr
))
470 if (!IS_ALIGNED(addr
, 32)) {
471 dev_dbg(video
->isp
->dev
, "Buffer address must be "
472 "aligned to 32 bytes boundary.\n");
473 ispmmu_vunmap(video
->isp
, buffer
->isp_addr
);
477 buf
->vbuf
.bytesused
= vfh
->format
.fmt
.pix
.sizeimage
;
478 buffer
->isp_addr
= addr
;
483 * isp_video_buffer_queue - Add buffer to streaming queue
486 * In memory-to-memory mode, start streaming on the pipeline if buffers are
487 * queued on both the input and the output, if the pipeline isn't already busy.
488 * If the pipeline is busy, it will be restarted in the output module interrupt
491 static void isp_video_buffer_queue(struct isp_video_buffer
*buf
)
493 struct isp_video_fh
*vfh
= isp_video_queue_to_isp_video_fh(buf
->queue
);
494 struct isp_buffer
*buffer
= to_isp_buffer(buf
);
495 struct isp_video
*video
= vfh
->video
;
496 struct isp_pipeline
*pipe
= to_isp_pipeline(&video
->video
.entity
);
497 enum isp_pipeline_state state
;
502 empty
= list_empty(&video
->dmaqueue
);
503 list_add_tail(&buffer
->buffer
.irqlist
, &video
->dmaqueue
);
506 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
507 state
= ISP_PIPELINE_QUEUE_OUTPUT
;
509 state
= ISP_PIPELINE_QUEUE_INPUT
;
511 spin_lock_irqsave(&pipe
->lock
, flags
);
512 pipe
->state
|= state
;
513 video
->ops
->queue(video
, buffer
);
514 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_QUEUED
;
516 start
= isp_pipeline_ready(pipe
);
518 pipe
->state
|= ISP_PIPELINE_STREAM
;
519 spin_unlock_irqrestore(&pipe
->lock
, flags
);
522 omap3isp_pipeline_set_stream(pipe
,
523 ISP_PIPELINE_STREAM_SINGLESHOT
);
527 static const struct isp_video_queue_operations isp_video_queue_ops
= {
528 .queue_prepare
= &isp_video_queue_prepare
,
529 .buffer_prepare
= &isp_video_buffer_prepare
,
530 .buffer_queue
= &isp_video_buffer_queue
,
531 .buffer_cleanup
= &isp_video_buffer_cleanup
,
535 * omap3isp_video_buffer_next - Complete the current buffer and return the next
536 * @video: ISP video object
538 * Remove the current video buffer from the DMA queue and fill its timestamp,
539 * field count and state fields before waking up its completion handler.
541 * For capture video nodes the buffer state is set to ISP_BUF_STATE_DONE if no
542 * error has been flagged in the pipeline, or to ISP_BUF_STATE_ERROR otherwise.
543 * For video output nodes the buffer state is always set to ISP_BUF_STATE_DONE.
545 * The DMA queue is expected to contain at least one buffer.
547 * Return a pointer to the next buffer in the DMA queue, or NULL if the queue is
550 struct isp_buffer
*omap3isp_video_buffer_next(struct isp_video
*video
)
552 struct isp_pipeline
*pipe
= to_isp_pipeline(&video
->video
.entity
);
553 struct isp_video_queue
*queue
= video
->queue
;
554 enum isp_pipeline_state state
;
555 struct isp_video_buffer
*buf
;
559 spin_lock_irqsave(&queue
->irqlock
, flags
);
560 if (WARN_ON(list_empty(&video
->dmaqueue
))) {
561 spin_unlock_irqrestore(&queue
->irqlock
, flags
);
565 buf
= list_first_entry(&video
->dmaqueue
, struct isp_video_buffer
,
567 list_del(&buf
->irqlist
);
568 spin_unlock_irqrestore(&queue
->irqlock
, flags
);
571 buf
->vbuf
.timestamp
.tv_sec
= ts
.tv_sec
;
572 buf
->vbuf
.timestamp
.tv_usec
= ts
.tv_nsec
/ NSEC_PER_USEC
;
574 /* Do frame number propagation only if this is the output video node.
575 * Frame number either comes from the CSI receivers or it gets
576 * incremented here if H3A is not active.
577 * Note: There is no guarantee that the output buffer will finish
578 * first, so the input number might lag behind by 1 in some cases.
580 if (video
== pipe
->output
&& !pipe
->do_propagation
)
581 buf
->vbuf
.sequence
= atomic_inc_return(&pipe
->frame_number
);
583 buf
->vbuf
.sequence
= atomic_read(&pipe
->frame_number
);
585 /* Report pipeline errors to userspace on the capture device side. */
586 if (queue
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& pipe
->error
) {
587 buf
->state
= ISP_BUF_STATE_ERROR
;
590 buf
->state
= ISP_BUF_STATE_DONE
;
595 if (list_empty(&video
->dmaqueue
)) {
596 if (queue
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
597 state
= ISP_PIPELINE_QUEUE_OUTPUT
598 | ISP_PIPELINE_STREAM
;
600 state
= ISP_PIPELINE_QUEUE_INPUT
601 | ISP_PIPELINE_STREAM
;
603 spin_lock_irqsave(&pipe
->lock
, flags
);
604 pipe
->state
&= ~state
;
605 if (video
->pipe
.stream_state
== ISP_PIPELINE_STREAM_CONTINUOUS
)
606 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
607 spin_unlock_irqrestore(&pipe
->lock
, flags
);
611 if (queue
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& pipe
->input
!= NULL
) {
612 spin_lock_irqsave(&pipe
->lock
, flags
);
613 pipe
->state
&= ~ISP_PIPELINE_STREAM
;
614 spin_unlock_irqrestore(&pipe
->lock
, flags
);
617 buf
= list_first_entry(&video
->dmaqueue
, struct isp_video_buffer
,
619 buf
->state
= ISP_BUF_STATE_ACTIVE
;
620 return to_isp_buffer(buf
);
624 * omap3isp_video_resume - Perform resume operation on the buffers
625 * @video: ISP video object
626 * @continuous: Pipeline is in single shot mode if 0 or continuous mode otherwise
628 * This function is intended to be used on suspend/resume scenario. It
629 * requests video queue layer to discard buffers marked as DONE if it's in
630 * continuous mode and requests ISP modules to queue again the ACTIVE buffer
633 void omap3isp_video_resume(struct isp_video
*video
, int continuous
)
635 struct isp_buffer
*buf
= NULL
;
637 if (continuous
&& video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
638 omap3isp_video_queue_discard_done(video
->queue
);
640 if (!list_empty(&video
->dmaqueue
)) {
641 buf
= list_first_entry(&video
->dmaqueue
,
642 struct isp_buffer
, buffer
.irqlist
);
643 video
->ops
->queue(video
, buf
);
644 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_QUEUED
;
647 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
651 /* -----------------------------------------------------------------------------
656 isp_video_querycap(struct file
*file
, void *fh
, struct v4l2_capability
*cap
)
658 struct isp_video
*video
= video_drvdata(file
);
660 strlcpy(cap
->driver
, ISP_VIDEO_DRIVER_NAME
, sizeof(cap
->driver
));
661 strlcpy(cap
->card
, video
->video
.name
, sizeof(cap
->card
));
662 strlcpy(cap
->bus_info
, "media", sizeof(cap
->bus_info
));
664 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
665 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
667 cap
->capabilities
= V4L2_CAP_VIDEO_OUTPUT
| V4L2_CAP_STREAMING
;
673 isp_video_get_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
675 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
676 struct isp_video
*video
= video_drvdata(file
);
678 if (format
->type
!= video
->type
)
681 mutex_lock(&video
->mutex
);
682 *format
= vfh
->format
;
683 mutex_unlock(&video
->mutex
);
689 isp_video_set_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
691 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
692 struct isp_video
*video
= video_drvdata(file
);
693 struct v4l2_mbus_framefmt fmt
;
695 if (format
->type
!= video
->type
)
698 mutex_lock(&video
->mutex
);
700 /* Fill the bytesperline and sizeimage fields by converting to media bus
701 * format and back to pixel format.
703 isp_video_pix_to_mbus(&format
->fmt
.pix
, &fmt
);
704 isp_video_mbus_to_pix(video
, &fmt
, &format
->fmt
.pix
);
706 vfh
->format
= *format
;
708 mutex_unlock(&video
->mutex
);
713 isp_video_try_format(struct file
*file
, void *fh
, struct v4l2_format
*format
)
715 struct isp_video
*video
= video_drvdata(file
);
716 struct v4l2_subdev_format fmt
;
717 struct v4l2_subdev
*subdev
;
721 if (format
->type
!= video
->type
)
724 subdev
= isp_video_remote_subdev(video
, &pad
);
728 isp_video_pix_to_mbus(&format
->fmt
.pix
, &fmt
.format
);
731 fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
732 ret
= v4l2_subdev_call(subdev
, pad
, get_fmt
, NULL
, &fmt
);
734 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
736 isp_video_mbus_to_pix(video
, &fmt
.format
, &format
->fmt
.pix
);
741 isp_video_cropcap(struct file
*file
, void *fh
, struct v4l2_cropcap
*cropcap
)
743 struct isp_video
*video
= video_drvdata(file
);
744 struct v4l2_subdev
*subdev
;
747 subdev
= isp_video_remote_subdev(video
, NULL
);
751 mutex_lock(&video
->mutex
);
752 ret
= v4l2_subdev_call(subdev
, video
, cropcap
, cropcap
);
753 mutex_unlock(&video
->mutex
);
755 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
759 isp_video_get_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
761 struct isp_video
*video
= video_drvdata(file
);
762 struct v4l2_subdev_format format
;
763 struct v4l2_subdev
*subdev
;
767 subdev
= isp_video_remote_subdev(video
, &pad
);
771 /* Try the get crop operation first and fallback to get format if not
774 ret
= v4l2_subdev_call(subdev
, video
, g_crop
, crop
);
775 if (ret
!= -ENOIOCTLCMD
)
779 format
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
780 ret
= v4l2_subdev_call(subdev
, pad
, get_fmt
, NULL
, &format
);
782 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
786 crop
->c
.width
= format
.format
.width
;
787 crop
->c
.height
= format
.format
.height
;
793 isp_video_set_crop(struct file
*file
, void *fh
, const struct v4l2_crop
*crop
)
795 struct isp_video
*video
= video_drvdata(file
);
796 struct v4l2_subdev
*subdev
;
799 subdev
= isp_video_remote_subdev(video
, NULL
);
803 mutex_lock(&video
->mutex
);
804 ret
= v4l2_subdev_call(subdev
, video
, s_crop
, crop
);
805 mutex_unlock(&video
->mutex
);
807 return ret
== -ENOIOCTLCMD
? -ENOTTY
: ret
;
811 isp_video_get_param(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
813 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
814 struct isp_video
*video
= video_drvdata(file
);
816 if (video
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
817 video
->type
!= a
->type
)
820 memset(a
, 0, sizeof(*a
));
821 a
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
822 a
->parm
.output
.capability
= V4L2_CAP_TIMEPERFRAME
;
823 a
->parm
.output
.timeperframe
= vfh
->timeperframe
;
829 isp_video_set_param(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
831 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
832 struct isp_video
*video
= video_drvdata(file
);
834 if (video
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
835 video
->type
!= a
->type
)
838 if (a
->parm
.output
.timeperframe
.denominator
== 0)
839 a
->parm
.output
.timeperframe
.denominator
= 1;
841 vfh
->timeperframe
= a
->parm
.output
.timeperframe
;
847 isp_video_reqbufs(struct file
*file
, void *fh
, struct v4l2_requestbuffers
*rb
)
849 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
851 return omap3isp_video_queue_reqbufs(&vfh
->queue
, rb
);
855 isp_video_querybuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
857 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
859 return omap3isp_video_queue_querybuf(&vfh
->queue
, b
);
863 isp_video_qbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
865 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
867 return omap3isp_video_queue_qbuf(&vfh
->queue
, b
);
871 isp_video_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
873 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
875 return omap3isp_video_queue_dqbuf(&vfh
->queue
, b
,
876 file
->f_flags
& O_NONBLOCK
);
879 static int isp_video_check_external_subdevs(struct isp_video
*video
,
880 struct isp_pipeline
*pipe
)
882 struct isp_device
*isp
= video
->isp
;
883 struct media_entity
*ents
[] = {
884 &isp
->isp_csi2a
.subdev
.entity
,
885 &isp
->isp_csi2c
.subdev
.entity
,
886 &isp
->isp_ccp2
.subdev
.entity
,
887 &isp
->isp_ccdc
.subdev
.entity
889 struct media_pad
*source_pad
;
890 struct media_entity
*source
= NULL
;
891 struct media_entity
*sink
;
892 struct v4l2_subdev_format fmt
;
893 struct v4l2_ext_controls ctrls
;
894 struct v4l2_ext_control ctrl
;
898 for (i
= 0; i
< ARRAY_SIZE(ents
); i
++) {
899 /* Is the entity part of the pipeline? */
900 if (!(pipe
->entities
& (1 << ents
[i
]->id
)))
903 /* ISP entities have always sink pad == 0. Find source. */
904 source_pad
= media_entity_remote_pad(&ents
[i
]->pads
[0]);
905 if (source_pad
== NULL
)
908 source
= source_pad
->entity
;
914 dev_warn(isp
->dev
, "can't find source, failing now\n");
918 if (media_entity_type(source
) != MEDIA_ENT_T_V4L2_SUBDEV
)
921 pipe
->external
= media_entity_to_v4l2_subdev(source
);
923 fmt
.pad
= source_pad
->index
;
924 fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
925 ret
= v4l2_subdev_call(media_entity_to_v4l2_subdev(sink
),
926 pad
, get_fmt
, NULL
, &fmt
);
927 if (unlikely(ret
< 0)) {
928 dev_warn(isp
->dev
, "get_fmt returned null!\n");
932 pipe
->external_width
=
933 omap3isp_video_format_info(fmt
.format
.code
)->width
;
935 memset(&ctrls
, 0, sizeof(ctrls
));
936 memset(&ctrl
, 0, sizeof(ctrl
));
938 ctrl
.id
= V4L2_CID_PIXEL_RATE
;
941 ctrls
.controls
= &ctrl
;
943 ret
= v4l2_g_ext_ctrls(pipe
->external
->ctrl_handler
, &ctrls
);
945 dev_warn(isp
->dev
, "no pixel rate control in subdev %s\n",
946 pipe
->external
->name
);
950 pipe
->external_rate
= ctrl
.value64
;
952 if (pipe
->entities
& (1 << isp
->isp_ccdc
.subdev
.entity
.id
)) {
953 unsigned int rate
= UINT_MAX
;
955 * Check that maximum allowed CCDC pixel rate isn't
956 * exceeded by the pixel rate.
958 omap3isp_ccdc_max_rate(&isp
->isp_ccdc
, &rate
);
959 if (pipe
->external_rate
> rate
)
969 * Every ISP pipeline has a single input and a single output. The input can be
970 * either a sensor or a video node. The output is always a video node.
972 * As every pipeline has an output video node, the ISP video objects at the
973 * pipeline output stores the pipeline state. It tracks the streaming state of
974 * both the input and output, as well as the availability of buffers.
976 * In sensor-to-memory mode, frames are always available at the pipeline input.
977 * Starting the sensor usually requires I2C transfers and must be done in
978 * interruptible context. The pipeline is started and stopped synchronously
979 * to the stream on/off commands. All modules in the pipeline will get their
980 * subdev set stream handler called. The module at the end of the pipeline must
981 * delay starting the hardware until buffers are available at its output.
983 * In memory-to-memory mode, starting/stopping the stream requires
984 * synchronization between the input and output. ISP modules can't be stopped
985 * in the middle of a frame, and at least some of the modules seem to become
986 * busy as soon as they're started, even if they don't receive a frame start
987 * event. For that reason frames need to be processed in single-shot mode. The
988 * driver needs to wait until a frame is completely processed and written to
989 * memory before restarting the pipeline for the next frame. Pipelined
990 * processing might be possible but requires more testing.
992 * Stream start must be delayed until buffers are available at both the input
993 * and output. The pipeline must be started in the videobuf queue callback with
994 * the buffers queue spinlock held. The modules subdev set stream operation must
998 isp_video_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type type
)
1000 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
1001 struct isp_video
*video
= video_drvdata(file
);
1002 enum isp_pipeline_state state
;
1003 struct isp_pipeline
*pipe
;
1004 unsigned long flags
;
1007 if (type
!= video
->type
)
1010 mutex_lock(&video
->stream_lock
);
1012 if (video
->streaming
) {
1013 mutex_unlock(&video
->stream_lock
);
1017 /* Start streaming on the pipeline. No link touching an entity in the
1018 * pipeline can be activated or deactivated once streaming is started.
1020 pipe
= video
->video
.entity
.pipe
1021 ? to_isp_pipeline(&video
->video
.entity
) : &video
->pipe
;
1025 if (video
->isp
->pdata
->set_constraints
)
1026 video
->isp
->pdata
->set_constraints(video
->isp
, true);
1027 pipe
->l3_ick
= clk_get_rate(video
->isp
->clock
[ISP_CLK_L3_ICK
]);
1028 pipe
->max_rate
= pipe
->l3_ick
;
1030 ret
= media_entity_pipeline_start(&video
->video
.entity
, &pipe
->pipe
);
1032 goto err_pipeline_start
;
1034 /* Verify that the currently configured format matches the output of
1035 * the connected subdev.
1037 ret
= isp_video_check_format(video
, vfh
);
1039 goto err_check_format
;
1041 video
->bpl_padding
= ret
;
1042 video
->bpl_value
= vfh
->format
.fmt
.pix
.bytesperline
;
1044 ret
= isp_video_get_graph_data(video
, pipe
);
1046 goto err_check_format
;
1048 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1049 state
= ISP_PIPELINE_STREAM_OUTPUT
| ISP_PIPELINE_IDLE_OUTPUT
;
1051 state
= ISP_PIPELINE_STREAM_INPUT
| ISP_PIPELINE_IDLE_INPUT
;
1053 ret
= isp_video_check_external_subdevs(video
, pipe
);
1055 goto err_check_format
;
1057 /* Validate the pipeline and update its state. */
1058 ret
= isp_video_validate_pipeline(pipe
);
1060 goto err_check_format
;
1062 pipe
->error
= false;
1064 spin_lock_irqsave(&pipe
->lock
, flags
);
1065 pipe
->state
&= ~ISP_PIPELINE_STREAM
;
1066 pipe
->state
|= state
;
1067 spin_unlock_irqrestore(&pipe
->lock
, flags
);
1069 /* Set the maximum time per frame as the value requested by userspace.
1070 * This is a soft limit that can be overridden if the hardware doesn't
1071 * support the request limit.
1073 if (video
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1074 pipe
->max_timeperframe
= vfh
->timeperframe
;
1076 video
->queue
= &vfh
->queue
;
1077 INIT_LIST_HEAD(&video
->dmaqueue
);
1078 atomic_set(&pipe
->frame_number
, -1);
1080 ret
= omap3isp_video_queue_streamon(&vfh
->queue
);
1082 goto err_check_format
;
1084 /* In sensor-to-memory mode, the stream can be started synchronously
1085 * to the stream on command. In memory-to-memory mode, it will be
1086 * started when buffers are queued on both the input and output.
1088 if (pipe
->input
== NULL
) {
1089 ret
= omap3isp_pipeline_set_stream(pipe
,
1090 ISP_PIPELINE_STREAM_CONTINUOUS
);
1092 goto err_set_stream
;
1093 spin_lock_irqsave(&video
->queue
->irqlock
, flags
);
1094 if (list_empty(&video
->dmaqueue
))
1095 video
->dmaqueue_flags
|= ISP_VIDEO_DMAQUEUE_UNDERRUN
;
1096 spin_unlock_irqrestore(&video
->queue
->irqlock
, flags
);
1099 video
->streaming
= 1;
1101 mutex_unlock(&video
->stream_lock
);
1105 omap3isp_video_queue_streamoff(&vfh
->queue
);
1107 media_entity_pipeline_stop(&video
->video
.entity
);
1109 if (video
->isp
->pdata
->set_constraints
)
1110 video
->isp
->pdata
->set_constraints(video
->isp
, false);
1111 /* The DMA queue must be emptied here, otherwise CCDC interrupts that
1112 * will get triggered the next time the CCDC is powered up will try to
1113 * access buffers that might have been freed but still present in the
1114 * DMA queue. This can easily get triggered if the above
1115 * omap3isp_pipeline_set_stream() call fails on a system with a
1116 * free-running sensor.
1118 INIT_LIST_HEAD(&video
->dmaqueue
);
1119 video
->queue
= NULL
;
1121 mutex_unlock(&video
->stream_lock
);
1126 isp_video_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type type
)
1128 struct isp_video_fh
*vfh
= to_isp_video_fh(fh
);
1129 struct isp_video
*video
= video_drvdata(file
);
1130 struct isp_pipeline
*pipe
= to_isp_pipeline(&video
->video
.entity
);
1131 enum isp_pipeline_state state
;
1132 unsigned int streaming
;
1133 unsigned long flags
;
1135 if (type
!= video
->type
)
1138 mutex_lock(&video
->stream_lock
);
1140 /* Make sure we're not streaming yet. */
1141 mutex_lock(&vfh
->queue
.lock
);
1142 streaming
= vfh
->queue
.streaming
;
1143 mutex_unlock(&vfh
->queue
.lock
);
1148 /* Update the pipeline state. */
1149 if (video
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1150 state
= ISP_PIPELINE_STREAM_OUTPUT
1151 | ISP_PIPELINE_QUEUE_OUTPUT
;
1153 state
= ISP_PIPELINE_STREAM_INPUT
1154 | ISP_PIPELINE_QUEUE_INPUT
;
1156 spin_lock_irqsave(&pipe
->lock
, flags
);
1157 pipe
->state
&= ~state
;
1158 spin_unlock_irqrestore(&pipe
->lock
, flags
);
1160 /* Stop the stream. */
1161 omap3isp_pipeline_set_stream(pipe
, ISP_PIPELINE_STREAM_STOPPED
);
1162 omap3isp_video_queue_streamoff(&vfh
->queue
);
1163 video
->queue
= NULL
;
1164 video
->streaming
= 0;
1166 if (video
->isp
->pdata
->set_constraints
)
1167 video
->isp
->pdata
->set_constraints(video
->isp
, false);
1168 media_entity_pipeline_stop(&video
->video
.entity
);
1171 mutex_unlock(&video
->stream_lock
);
1176 isp_video_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*input
)
1178 if (input
->index
> 0)
1181 strlcpy(input
->name
, "camera", sizeof(input
->name
));
1182 input
->type
= V4L2_INPUT_TYPE_CAMERA
;
1188 isp_video_g_input(struct file
*file
, void *fh
, unsigned int *input
)
1196 isp_video_s_input(struct file
*file
, void *fh
, unsigned int input
)
1198 return input
== 0 ? 0 : -EINVAL
;
1201 static const struct v4l2_ioctl_ops isp_video_ioctl_ops
= {
1202 .vidioc_querycap
= isp_video_querycap
,
1203 .vidioc_g_fmt_vid_cap
= isp_video_get_format
,
1204 .vidioc_s_fmt_vid_cap
= isp_video_set_format
,
1205 .vidioc_try_fmt_vid_cap
= isp_video_try_format
,
1206 .vidioc_g_fmt_vid_out
= isp_video_get_format
,
1207 .vidioc_s_fmt_vid_out
= isp_video_set_format
,
1208 .vidioc_try_fmt_vid_out
= isp_video_try_format
,
1209 .vidioc_cropcap
= isp_video_cropcap
,
1210 .vidioc_g_crop
= isp_video_get_crop
,
1211 .vidioc_s_crop
= isp_video_set_crop
,
1212 .vidioc_g_parm
= isp_video_get_param
,
1213 .vidioc_s_parm
= isp_video_set_param
,
1214 .vidioc_reqbufs
= isp_video_reqbufs
,
1215 .vidioc_querybuf
= isp_video_querybuf
,
1216 .vidioc_qbuf
= isp_video_qbuf
,
1217 .vidioc_dqbuf
= isp_video_dqbuf
,
1218 .vidioc_streamon
= isp_video_streamon
,
1219 .vidioc_streamoff
= isp_video_streamoff
,
1220 .vidioc_enum_input
= isp_video_enum_input
,
1221 .vidioc_g_input
= isp_video_g_input
,
1222 .vidioc_s_input
= isp_video_s_input
,
1225 /* -----------------------------------------------------------------------------
1226 * V4L2 file operations
1229 static int isp_video_open(struct file
*file
)
1231 struct isp_video
*video
= video_drvdata(file
);
1232 struct isp_video_fh
*handle
;
1235 handle
= kzalloc(sizeof(*handle
), GFP_KERNEL
);
1239 v4l2_fh_init(&handle
->vfh
, &video
->video
);
1240 v4l2_fh_add(&handle
->vfh
);
1242 /* If this is the first user, initialise the pipeline. */
1243 if (omap3isp_get(video
->isp
) == NULL
) {
1248 ret
= omap3isp_pipeline_pm_use(&video
->video
.entity
, 1);
1250 omap3isp_put(video
->isp
);
1254 omap3isp_video_queue_init(&handle
->queue
, video
->type
,
1255 &isp_video_queue_ops
, video
->isp
->dev
,
1256 sizeof(struct isp_buffer
));
1258 memset(&handle
->format
, 0, sizeof(handle
->format
));
1259 handle
->format
.type
= video
->type
;
1260 handle
->timeperframe
.denominator
= 1;
1262 handle
->video
= video
;
1263 file
->private_data
= &handle
->vfh
;
1267 v4l2_fh_del(&handle
->vfh
);
1274 static int isp_video_release(struct file
*file
)
1276 struct isp_video
*video
= video_drvdata(file
);
1277 struct v4l2_fh
*vfh
= file
->private_data
;
1278 struct isp_video_fh
*handle
= to_isp_video_fh(vfh
);
1280 /* Disable streaming and free the buffers queue resources. */
1281 isp_video_streamoff(file
, vfh
, video
->type
);
1283 mutex_lock(&handle
->queue
.lock
);
1284 omap3isp_video_queue_cleanup(&handle
->queue
);
1285 mutex_unlock(&handle
->queue
.lock
);
1287 omap3isp_pipeline_pm_use(&video
->video
.entity
, 0);
1289 /* Release the file handle. */
1292 file
->private_data
= NULL
;
1294 omap3isp_put(video
->isp
);
1299 static unsigned int isp_video_poll(struct file
*file
, poll_table
*wait
)
1301 struct isp_video_fh
*vfh
= to_isp_video_fh(file
->private_data
);
1302 struct isp_video_queue
*queue
= &vfh
->queue
;
1304 return omap3isp_video_queue_poll(queue
, file
, wait
);
1307 static int isp_video_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1309 struct isp_video_fh
*vfh
= to_isp_video_fh(file
->private_data
);
1311 return omap3isp_video_queue_mmap(&vfh
->queue
, vma
);
1314 static struct v4l2_file_operations isp_video_fops
= {
1315 .owner
= THIS_MODULE
,
1316 .unlocked_ioctl
= video_ioctl2
,
1317 .open
= isp_video_open
,
1318 .release
= isp_video_release
,
1319 .poll
= isp_video_poll
,
1320 .mmap
= isp_video_mmap
,
1323 /* -----------------------------------------------------------------------------
1327 static const struct isp_video_operations isp_video_dummy_ops
= {
1330 int omap3isp_video_init(struct isp_video
*video
, const char *name
)
1332 const char *direction
;
1335 switch (video
->type
) {
1336 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1337 direction
= "output";
1338 video
->pad
.flags
= MEDIA_PAD_FL_SINK
;
1340 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1341 direction
= "input";
1342 video
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1343 video
->video
.vfl_dir
= VFL_DIR_TX
;
1350 ret
= media_entity_init(&video
->video
.entity
, 1, &video
->pad
, 0);
1354 mutex_init(&video
->mutex
);
1355 atomic_set(&video
->active
, 0);
1357 spin_lock_init(&video
->pipe
.lock
);
1358 mutex_init(&video
->stream_lock
);
1360 /* Initialize the video device. */
1361 if (video
->ops
== NULL
)
1362 video
->ops
= &isp_video_dummy_ops
;
1364 video
->video
.fops
= &isp_video_fops
;
1365 snprintf(video
->video
.name
, sizeof(video
->video
.name
),
1366 "OMAP3 ISP %s %s", name
, direction
);
1367 video
->video
.vfl_type
= VFL_TYPE_GRABBER
;
1368 video
->video
.release
= video_device_release_empty
;
1369 video
->video
.ioctl_ops
= &isp_video_ioctl_ops
;
1370 video
->pipe
.stream_state
= ISP_PIPELINE_STREAM_STOPPED
;
1372 video_set_drvdata(&video
->video
, video
);
1377 void omap3isp_video_cleanup(struct isp_video
*video
)
1379 media_entity_cleanup(&video
->video
.entity
);
1380 mutex_destroy(&video
->stream_lock
);
1381 mutex_destroy(&video
->mutex
);
1384 int omap3isp_video_register(struct isp_video
*video
, struct v4l2_device
*vdev
)
1388 video
->video
.v4l2_dev
= vdev
;
1390 ret
= video_register_device(&video
->video
, VFL_TYPE_GRABBER
, -1);
1392 dev_err(video
->isp
->dev
,
1393 "%s: could not register video device (%d)\n",
1399 void omap3isp_video_unregister(struct isp_video
*video
)
1401 if (video_is_registered(&video
->video
))
1402 video_unregister_device(&video
->video
);