Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / drivers / media / video / omap3isp / ispvideo.c
blob912ac071b104ff324e61fe72f35eac966d4bc7ff
1 /*
2 * ispvideo.c
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
23 * 02110-1301 USA
26 #include <asm/cacheflush.h>
27 #include <linux/clk.h>
28 #include <linux/mm.h>
29 #include <linux/pagemap.h>
30 #include <linux/scatterlist.h>
31 #include <linux/sched.h>
32 #include <linux/slab.h>
33 #include <linux/vmalloc.h>
34 #include <media/v4l2-dev.h>
35 #include <media/v4l2-ioctl.h>
36 #include <plat/iommu.h>
37 #include <plat/iovmm.h>
38 #include <plat/omap-pm.h>
40 #include "ispvideo.h"
41 #include "isp.h"
44 /* -----------------------------------------------------------------------------
45 * Helper functions
48 static struct isp_format_info formats[] = {
49 { V4L2_MBUS_FMT_Y8_1X8, V4L2_MBUS_FMT_Y8_1X8,
50 V4L2_MBUS_FMT_Y8_1X8, V4L2_MBUS_FMT_Y8_1X8,
51 V4L2_PIX_FMT_GREY, 8, },
52 { V4L2_MBUS_FMT_Y10_1X10, V4L2_MBUS_FMT_Y10_1X10,
53 V4L2_MBUS_FMT_Y10_1X10, V4L2_MBUS_FMT_Y8_1X8,
54 V4L2_PIX_FMT_Y10, 10, },
55 { V4L2_MBUS_FMT_Y12_1X12, V4L2_MBUS_FMT_Y10_1X10,
56 V4L2_MBUS_FMT_Y12_1X12, V4L2_MBUS_FMT_Y8_1X8,
57 V4L2_PIX_FMT_Y12, 12, },
58 { V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_MBUS_FMT_SBGGR8_1X8,
59 V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_MBUS_FMT_SBGGR8_1X8,
60 V4L2_PIX_FMT_SBGGR8, 8, },
61 { V4L2_MBUS_FMT_SGBRG8_1X8, V4L2_MBUS_FMT_SGBRG8_1X8,
62 V4L2_MBUS_FMT_SGBRG8_1X8, V4L2_MBUS_FMT_SGBRG8_1X8,
63 V4L2_PIX_FMT_SGBRG8, 8, },
64 { V4L2_MBUS_FMT_SGRBG8_1X8, V4L2_MBUS_FMT_SGRBG8_1X8,
65 V4L2_MBUS_FMT_SGRBG8_1X8, V4L2_MBUS_FMT_SGRBG8_1X8,
66 V4L2_PIX_FMT_SGRBG8, 8, },
67 { V4L2_MBUS_FMT_SRGGB8_1X8, V4L2_MBUS_FMT_SRGGB8_1X8,
68 V4L2_MBUS_FMT_SRGGB8_1X8, V4L2_MBUS_FMT_SRGGB8_1X8,
69 V4L2_PIX_FMT_SRGGB8, 8, },
70 { V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
71 V4L2_MBUS_FMT_SGRBG10_1X10, 0,
72 V4L2_PIX_FMT_SGRBG10DPCM8, 8, },
73 { V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_MBUS_FMT_SBGGR10_1X10,
74 V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_MBUS_FMT_SBGGR8_1X8,
75 V4L2_PIX_FMT_SBGGR10, 10, },
76 { V4L2_MBUS_FMT_SGBRG10_1X10, V4L2_MBUS_FMT_SGBRG10_1X10,
77 V4L2_MBUS_FMT_SGBRG10_1X10, V4L2_MBUS_FMT_SGBRG8_1X8,
78 V4L2_PIX_FMT_SGBRG10, 10, },
79 { V4L2_MBUS_FMT_SGRBG10_1X10, V4L2_MBUS_FMT_SGRBG10_1X10,
80 V4L2_MBUS_FMT_SGRBG10_1X10, V4L2_MBUS_FMT_SGRBG8_1X8,
81 V4L2_PIX_FMT_SGRBG10, 10, },
82 { V4L2_MBUS_FMT_SRGGB10_1X10, V4L2_MBUS_FMT_SRGGB10_1X10,
83 V4L2_MBUS_FMT_SRGGB10_1X10, V4L2_MBUS_FMT_SRGGB8_1X8,
84 V4L2_PIX_FMT_SRGGB10, 10, },
85 { V4L2_MBUS_FMT_SBGGR12_1X12, V4L2_MBUS_FMT_SBGGR10_1X10,
86 V4L2_MBUS_FMT_SBGGR12_1X12, V4L2_MBUS_FMT_SBGGR8_1X8,
87 V4L2_PIX_FMT_SBGGR12, 12, },
88 { V4L2_MBUS_FMT_SGBRG12_1X12, V4L2_MBUS_FMT_SGBRG10_1X10,
89 V4L2_MBUS_FMT_SGBRG12_1X12, V4L2_MBUS_FMT_SGBRG8_1X8,
90 V4L2_PIX_FMT_SGBRG12, 12, },
91 { V4L2_MBUS_FMT_SGRBG12_1X12, V4L2_MBUS_FMT_SGRBG10_1X10,
92 V4L2_MBUS_FMT_SGRBG12_1X12, V4L2_MBUS_FMT_SGRBG8_1X8,
93 V4L2_PIX_FMT_SGRBG12, 12, },
94 { V4L2_MBUS_FMT_SRGGB12_1X12, V4L2_MBUS_FMT_SRGGB10_1X10,
95 V4L2_MBUS_FMT_SRGGB12_1X12, V4L2_MBUS_FMT_SRGGB8_1X8,
96 V4L2_PIX_FMT_SRGGB12, 12, },
97 { V4L2_MBUS_FMT_UYVY8_1X16, V4L2_MBUS_FMT_UYVY8_1X16,
98 V4L2_MBUS_FMT_UYVY8_1X16, 0,
99 V4L2_PIX_FMT_UYVY, 16, },
100 { V4L2_MBUS_FMT_YUYV8_1X16, V4L2_MBUS_FMT_YUYV8_1X16,
101 V4L2_MBUS_FMT_YUYV8_1X16, 0,
102 V4L2_PIX_FMT_YUYV, 16, },
105 const struct isp_format_info *
106 omap3isp_video_format_info(enum v4l2_mbus_pixelcode code)
108 unsigned int i;
110 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
111 if (formats[i].code == code)
112 return &formats[i];
115 return NULL;
119 * Decide whether desired output pixel code can be obtained with
120 * the lane shifter by shifting the input pixel code.
121 * @in: input pixelcode to shifter
122 * @out: output pixelcode from shifter
123 * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0]
125 * return true if the combination is possible
126 * return false otherwise
128 static bool isp_video_is_shiftable(enum v4l2_mbus_pixelcode in,
129 enum v4l2_mbus_pixelcode out,
130 unsigned int additional_shift)
132 const struct isp_format_info *in_info, *out_info;
134 if (in == out)
135 return true;
137 in_info = omap3isp_video_format_info(in);
138 out_info = omap3isp_video_format_info(out);
140 if ((in_info->flavor == 0) || (out_info->flavor == 0))
141 return false;
143 if (in_info->flavor != out_info->flavor)
144 return false;
146 return in_info->bpp - out_info->bpp + additional_shift <= 6;
150 * isp_video_mbus_to_pix - Convert v4l2_mbus_framefmt to v4l2_pix_format
151 * @video: ISP video instance
152 * @mbus: v4l2_mbus_framefmt format (input)
153 * @pix: v4l2_pix_format format (output)
155 * Fill the output pix structure with information from the input mbus format.
156 * The bytesperline and sizeimage fields are computed from the requested bytes
157 * per line value in the pix format and information from the video instance.
159 * Return the number of padding bytes at end of line.
161 static unsigned int isp_video_mbus_to_pix(const struct isp_video *video,
162 const struct v4l2_mbus_framefmt *mbus,
163 struct v4l2_pix_format *pix)
165 unsigned int bpl = pix->bytesperline;
166 unsigned int min_bpl;
167 unsigned int i;
169 memset(pix, 0, sizeof(*pix));
170 pix->width = mbus->width;
171 pix->height = mbus->height;
173 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
174 if (formats[i].code == mbus->code)
175 break;
178 if (WARN_ON(i == ARRAY_SIZE(formats)))
179 return 0;
181 min_bpl = pix->width * ALIGN(formats[i].bpp, 8) / 8;
183 /* Clamp the requested bytes per line value. If the maximum bytes per
184 * line value is zero, the module doesn't support user configurable line
185 * sizes. Override the requested value with the minimum in that case.
187 if (video->bpl_max)
188 bpl = clamp(bpl, min_bpl, video->bpl_max);
189 else
190 bpl = min_bpl;
192 if (!video->bpl_zero_padding || bpl != min_bpl)
193 bpl = ALIGN(bpl, video->bpl_alignment);
195 pix->pixelformat = formats[i].pixelformat;
196 pix->bytesperline = bpl;
197 pix->sizeimage = pix->bytesperline * pix->height;
198 pix->colorspace = mbus->colorspace;
199 pix->field = mbus->field;
201 return bpl - min_bpl;
204 static void isp_video_pix_to_mbus(const struct v4l2_pix_format *pix,
205 struct v4l2_mbus_framefmt *mbus)
207 unsigned int i;
209 memset(mbus, 0, sizeof(*mbus));
210 mbus->width = pix->width;
211 mbus->height = pix->height;
213 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
214 if (formats[i].pixelformat == pix->pixelformat)
215 break;
218 if (WARN_ON(i == ARRAY_SIZE(formats)))
219 return;
221 mbus->code = formats[i].code;
222 mbus->colorspace = pix->colorspace;
223 mbus->field = pix->field;
226 static struct v4l2_subdev *
227 isp_video_remote_subdev(struct isp_video *video, u32 *pad)
229 struct media_pad *remote;
231 remote = media_entity_remote_source(&video->pad);
233 if (remote == NULL ||
234 media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
235 return NULL;
237 if (pad)
238 *pad = remote->index;
240 return media_entity_to_v4l2_subdev(remote->entity);
243 /* Return a pointer to the ISP video instance at the far end of the pipeline. */
244 static struct isp_video *
245 isp_video_far_end(struct isp_video *video)
247 struct media_entity_graph graph;
248 struct media_entity *entity = &video->video.entity;
249 struct media_device *mdev = entity->parent;
250 struct isp_video *far_end = NULL;
252 mutex_lock(&mdev->graph_mutex);
253 media_entity_graph_walk_start(&graph, entity);
255 while ((entity = media_entity_graph_walk_next(&graph))) {
256 if (entity == &video->video.entity)
257 continue;
259 if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
260 continue;
262 far_end = to_isp_video(media_entity_to_video_device(entity));
263 if (far_end->type != video->type)
264 break;
266 far_end = NULL;
269 mutex_unlock(&mdev->graph_mutex);
270 return far_end;
274 * Validate a pipeline by checking both ends of all links for format
275 * discrepancies.
277 * Compute the minimum time per frame value as the maximum of time per frame
278 * limits reported by every block in the pipeline.
280 * Return 0 if all formats match, or -EPIPE if at least one link is found with
281 * different formats on its two ends.
283 static int isp_video_validate_pipeline(struct isp_pipeline *pipe)
285 struct isp_device *isp = pipe->output->isp;
286 struct v4l2_subdev_format fmt_source;
287 struct v4l2_subdev_format fmt_sink;
288 struct media_pad *pad;
289 struct v4l2_subdev *subdev;
290 int ret;
292 pipe->max_rate = pipe->l3_ick;
294 subdev = isp_video_remote_subdev(pipe->output, NULL);
295 if (subdev == NULL)
296 return -EPIPE;
298 while (1) {
299 unsigned int shifter_link;
300 /* Retrieve the sink format */
301 pad = &subdev->entity.pads[0];
302 if (!(pad->flags & MEDIA_PAD_FL_SINK))
303 break;
305 fmt_sink.pad = pad->index;
306 fmt_sink.which = V4L2_SUBDEV_FORMAT_ACTIVE;
307 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_sink);
308 if (ret < 0 && ret != -ENOIOCTLCMD)
309 return -EPIPE;
311 /* Update the maximum frame rate */
312 if (subdev == &isp->isp_res.subdev)
313 omap3isp_resizer_max_rate(&isp->isp_res,
314 &pipe->max_rate);
316 /* Check ccdc maximum data rate when data comes from sensor
317 * TODO: Include ccdc rate in pipe->max_rate and compare the
318 * total pipe rate with the input data rate from sensor.
320 if (subdev == &isp->isp_ccdc.subdev && pipe->input == NULL) {
321 unsigned int rate = UINT_MAX;
323 omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
324 if (isp->isp_ccdc.vpcfg.pixelclk > rate)
325 return -ENOSPC;
328 /* If sink pad is on CCDC, the link has the lane shifter
329 * in the middle of it. */
330 shifter_link = subdev == &isp->isp_ccdc.subdev;
332 /* Retrieve the source format */
333 pad = media_entity_remote_source(pad);
334 if (pad == NULL ||
335 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
336 break;
338 subdev = media_entity_to_v4l2_subdev(pad->entity);
340 fmt_source.pad = pad->index;
341 fmt_source.which = V4L2_SUBDEV_FORMAT_ACTIVE;
342 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_source);
343 if (ret < 0 && ret != -ENOIOCTLCMD)
344 return -EPIPE;
346 /* Check if the two ends match */
347 if (fmt_source.format.width != fmt_sink.format.width ||
348 fmt_source.format.height != fmt_sink.format.height)
349 return -EPIPE;
351 if (shifter_link) {
352 unsigned int parallel_shift = 0;
353 if (isp->isp_ccdc.input == CCDC_INPUT_PARALLEL) {
354 struct isp_parallel_platform_data *pdata =
355 &((struct isp_v4l2_subdevs_group *)
356 subdev->host_priv)->bus.parallel;
357 parallel_shift = pdata->data_lane_shift * 2;
359 if (!isp_video_is_shiftable(fmt_source.format.code,
360 fmt_sink.format.code,
361 parallel_shift))
362 return -EPIPE;
363 } else if (fmt_source.format.code != fmt_sink.format.code)
364 return -EPIPE;
367 return 0;
370 static int
371 __isp_video_get_format(struct isp_video *video, struct v4l2_format *format)
373 struct v4l2_subdev_format fmt;
374 struct v4l2_subdev *subdev;
375 u32 pad;
376 int ret;
378 subdev = isp_video_remote_subdev(video, &pad);
379 if (subdev == NULL)
380 return -EINVAL;
382 mutex_lock(&video->mutex);
384 fmt.pad = pad;
385 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
386 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
387 if (ret == -ENOIOCTLCMD)
388 ret = -EINVAL;
390 mutex_unlock(&video->mutex);
392 if (ret)
393 return ret;
395 format->type = video->type;
396 return isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
399 static int
400 isp_video_check_format(struct isp_video *video, struct isp_video_fh *vfh)
402 struct v4l2_format format;
403 int ret;
405 memcpy(&format, &vfh->format, sizeof(format));
406 ret = __isp_video_get_format(video, &format);
407 if (ret < 0)
408 return ret;
410 if (vfh->format.fmt.pix.pixelformat != format.fmt.pix.pixelformat ||
411 vfh->format.fmt.pix.height != format.fmt.pix.height ||
412 vfh->format.fmt.pix.width != format.fmt.pix.width ||
413 vfh->format.fmt.pix.bytesperline != format.fmt.pix.bytesperline ||
414 vfh->format.fmt.pix.sizeimage != format.fmt.pix.sizeimage)
415 return -EINVAL;
417 return ret;
420 /* -----------------------------------------------------------------------------
421 * IOMMU management
424 #define IOMMU_FLAG (IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_8)
427 * ispmmu_vmap - Wrapper for Virtual memory mapping of a scatter gather list
428 * @dev: Device pointer specific to the OMAP3 ISP.
429 * @sglist: Pointer to source Scatter gather list to allocate.
430 * @sglen: Number of elements of the scatter-gatter list.
432 * Returns a resulting mapped device address by the ISP MMU, or -ENOMEM if
433 * we ran out of memory.
435 static dma_addr_t
436 ispmmu_vmap(struct isp_device *isp, const struct scatterlist *sglist, int sglen)
438 struct sg_table *sgt;
439 u32 da;
441 sgt = kmalloc(sizeof(*sgt), GFP_KERNEL);
442 if (sgt == NULL)
443 return -ENOMEM;
445 sgt->sgl = (struct scatterlist *)sglist;
446 sgt->nents = sglen;
447 sgt->orig_nents = sglen;
449 da = omap_iommu_vmap(isp->domain, isp->iommu, 0, sgt, IOMMU_FLAG);
450 if (IS_ERR_VALUE(da))
451 kfree(sgt);
453 return da;
457 * ispmmu_vunmap - Unmap a device address from the ISP MMU
458 * @dev: Device pointer specific to the OMAP3 ISP.
459 * @da: Device address generated from a ispmmu_vmap call.
461 static void ispmmu_vunmap(struct isp_device *isp, dma_addr_t da)
463 struct sg_table *sgt;
465 sgt = omap_iommu_vunmap(isp->domain, isp->iommu, (u32)da);
466 kfree(sgt);
469 /* -----------------------------------------------------------------------------
470 * Video queue operations
473 static void isp_video_queue_prepare(struct isp_video_queue *queue,
474 unsigned int *nbuffers, unsigned int *size)
476 struct isp_video_fh *vfh =
477 container_of(queue, struct isp_video_fh, queue);
478 struct isp_video *video = vfh->video;
480 *size = vfh->format.fmt.pix.sizeimage;
481 if (*size == 0)
482 return;
484 *nbuffers = min(*nbuffers, video->capture_mem / PAGE_ALIGN(*size));
487 static void isp_video_buffer_cleanup(struct isp_video_buffer *buf)
489 struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
490 struct isp_buffer *buffer = to_isp_buffer(buf);
491 struct isp_video *video = vfh->video;
493 if (buffer->isp_addr) {
494 ispmmu_vunmap(video->isp, buffer->isp_addr);
495 buffer->isp_addr = 0;
499 static int isp_video_buffer_prepare(struct isp_video_buffer *buf)
501 struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
502 struct isp_buffer *buffer = to_isp_buffer(buf);
503 struct isp_video *video = vfh->video;
504 unsigned long addr;
506 addr = ispmmu_vmap(video->isp, buf->sglist, buf->sglen);
507 if (IS_ERR_VALUE(addr))
508 return -EIO;
510 if (!IS_ALIGNED(addr, 32)) {
511 dev_dbg(video->isp->dev, "Buffer address must be "
512 "aligned to 32 bytes boundary.\n");
513 ispmmu_vunmap(video->isp, buffer->isp_addr);
514 return -EINVAL;
517 buf->vbuf.bytesused = vfh->format.fmt.pix.sizeimage;
518 buffer->isp_addr = addr;
519 return 0;
523 * isp_video_buffer_queue - Add buffer to streaming queue
524 * @buf: Video buffer
526 * In memory-to-memory mode, start streaming on the pipeline if buffers are
527 * queued on both the input and the output, if the pipeline isn't already busy.
528 * If the pipeline is busy, it will be restarted in the output module interrupt
529 * handler.
531 static void isp_video_buffer_queue(struct isp_video_buffer *buf)
533 struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
534 struct isp_buffer *buffer = to_isp_buffer(buf);
535 struct isp_video *video = vfh->video;
536 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
537 enum isp_pipeline_state state;
538 unsigned long flags;
539 unsigned int empty;
540 unsigned int start;
542 empty = list_empty(&video->dmaqueue);
543 list_add_tail(&buffer->buffer.irqlist, &video->dmaqueue);
545 if (empty) {
546 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
547 state = ISP_PIPELINE_QUEUE_OUTPUT;
548 else
549 state = ISP_PIPELINE_QUEUE_INPUT;
551 spin_lock_irqsave(&pipe->lock, flags);
552 pipe->state |= state;
553 video->ops->queue(video, buffer);
554 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_QUEUED;
556 start = isp_pipeline_ready(pipe);
557 if (start)
558 pipe->state |= ISP_PIPELINE_STREAM;
559 spin_unlock_irqrestore(&pipe->lock, flags);
561 if (start)
562 omap3isp_pipeline_set_stream(pipe,
563 ISP_PIPELINE_STREAM_SINGLESHOT);
567 static const struct isp_video_queue_operations isp_video_queue_ops = {
568 .queue_prepare = &isp_video_queue_prepare,
569 .buffer_prepare = &isp_video_buffer_prepare,
570 .buffer_queue = &isp_video_buffer_queue,
571 .buffer_cleanup = &isp_video_buffer_cleanup,
575 * omap3isp_video_buffer_next - Complete the current buffer and return the next
576 * @video: ISP video object
577 * @error: Whether an error occurred during capture
579 * Remove the current video buffer from the DMA queue and fill its timestamp,
580 * field count and state fields before waking up its completion handler.
582 * The buffer state is set to VIDEOBUF_DONE if no error occurred (@error is 0)
583 * or VIDEOBUF_ERROR otherwise (@error is non-zero).
585 * The DMA queue is expected to contain at least one buffer.
587 * Return a pointer to the next buffer in the DMA queue, or NULL if the queue is
588 * empty.
590 struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video,
591 unsigned int error)
593 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
594 struct isp_video_queue *queue = video->queue;
595 enum isp_pipeline_state state;
596 struct isp_video_buffer *buf;
597 unsigned long flags;
598 struct timespec ts;
600 spin_lock_irqsave(&queue->irqlock, flags);
601 if (WARN_ON(list_empty(&video->dmaqueue))) {
602 spin_unlock_irqrestore(&queue->irqlock, flags);
603 return NULL;
606 buf = list_first_entry(&video->dmaqueue, struct isp_video_buffer,
607 irqlist);
608 list_del(&buf->irqlist);
609 spin_unlock_irqrestore(&queue->irqlock, flags);
611 ktime_get_ts(&ts);
612 buf->vbuf.timestamp.tv_sec = ts.tv_sec;
613 buf->vbuf.timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
615 /* Do frame number propagation only if this is the output video node.
616 * Frame number either comes from the CSI receivers or it gets
617 * incremented here if H3A is not active.
618 * Note: There is no guarantee that the output buffer will finish
619 * first, so the input number might lag behind by 1 in some cases.
621 if (video == pipe->output && !pipe->do_propagation)
622 buf->vbuf.sequence = atomic_inc_return(&pipe->frame_number);
623 else
624 buf->vbuf.sequence = atomic_read(&pipe->frame_number);
626 buf->state = error ? ISP_BUF_STATE_ERROR : ISP_BUF_STATE_DONE;
628 wake_up(&buf->wait);
630 if (list_empty(&video->dmaqueue)) {
631 if (queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
632 state = ISP_PIPELINE_QUEUE_OUTPUT
633 | ISP_PIPELINE_STREAM;
634 else
635 state = ISP_PIPELINE_QUEUE_INPUT
636 | ISP_PIPELINE_STREAM;
638 spin_lock_irqsave(&pipe->lock, flags);
639 pipe->state &= ~state;
640 if (video->pipe.stream_state == ISP_PIPELINE_STREAM_CONTINUOUS)
641 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
642 spin_unlock_irqrestore(&pipe->lock, flags);
643 return NULL;
646 if (queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->input != NULL) {
647 spin_lock_irqsave(&pipe->lock, flags);
648 pipe->state &= ~ISP_PIPELINE_STREAM;
649 spin_unlock_irqrestore(&pipe->lock, flags);
652 buf = list_first_entry(&video->dmaqueue, struct isp_video_buffer,
653 irqlist);
654 buf->state = ISP_BUF_STATE_ACTIVE;
655 return to_isp_buffer(buf);
659 * omap3isp_video_resume - Perform resume operation on the buffers
660 * @video: ISP video object
661 * @continuous: Pipeline is in single shot mode if 0 or continuous mode otherwise
663 * This function is intended to be used on suspend/resume scenario. It
664 * requests video queue layer to discard buffers marked as DONE if it's in
665 * continuous mode and requests ISP modules to queue again the ACTIVE buffer
666 * if there's any.
668 void omap3isp_video_resume(struct isp_video *video, int continuous)
670 struct isp_buffer *buf = NULL;
672 if (continuous && video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
673 omap3isp_video_queue_discard_done(video->queue);
675 if (!list_empty(&video->dmaqueue)) {
676 buf = list_first_entry(&video->dmaqueue,
677 struct isp_buffer, buffer.irqlist);
678 video->ops->queue(video, buf);
679 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_QUEUED;
680 } else {
681 if (continuous)
682 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
686 /* -----------------------------------------------------------------------------
687 * V4L2 ioctls
690 static int
691 isp_video_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
693 struct isp_video *video = video_drvdata(file);
695 strlcpy(cap->driver, ISP_VIDEO_DRIVER_NAME, sizeof(cap->driver));
696 strlcpy(cap->card, video->video.name, sizeof(cap->card));
697 strlcpy(cap->bus_info, "media", sizeof(cap->bus_info));
699 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
700 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
701 else
702 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
704 return 0;
707 static int
708 isp_video_get_format(struct file *file, void *fh, struct v4l2_format *format)
710 struct isp_video_fh *vfh = to_isp_video_fh(fh);
711 struct isp_video *video = video_drvdata(file);
713 if (format->type != video->type)
714 return -EINVAL;
716 mutex_lock(&video->mutex);
717 *format = vfh->format;
718 mutex_unlock(&video->mutex);
720 return 0;
723 static int
724 isp_video_set_format(struct file *file, void *fh, struct v4l2_format *format)
726 struct isp_video_fh *vfh = to_isp_video_fh(fh);
727 struct isp_video *video = video_drvdata(file);
728 struct v4l2_mbus_framefmt fmt;
730 if (format->type != video->type)
731 return -EINVAL;
733 mutex_lock(&video->mutex);
735 /* Fill the bytesperline and sizeimage fields by converting to media bus
736 * format and back to pixel format.
738 isp_video_pix_to_mbus(&format->fmt.pix, &fmt);
739 isp_video_mbus_to_pix(video, &fmt, &format->fmt.pix);
741 vfh->format = *format;
743 mutex_unlock(&video->mutex);
744 return 0;
747 static int
748 isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format)
750 struct isp_video *video = video_drvdata(file);
751 struct v4l2_subdev_format fmt;
752 struct v4l2_subdev *subdev;
753 u32 pad;
754 int ret;
756 if (format->type != video->type)
757 return -EINVAL;
759 subdev = isp_video_remote_subdev(video, &pad);
760 if (subdev == NULL)
761 return -EINVAL;
763 isp_video_pix_to_mbus(&format->fmt.pix, &fmt.format);
765 fmt.pad = pad;
766 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
767 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
768 if (ret)
769 return ret == -ENOIOCTLCMD ? -EINVAL : ret;
771 isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
772 return 0;
775 static int
776 isp_video_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap)
778 struct isp_video *video = video_drvdata(file);
779 struct v4l2_subdev *subdev;
780 int ret;
782 subdev = isp_video_remote_subdev(video, NULL);
783 if (subdev == NULL)
784 return -EINVAL;
786 mutex_lock(&video->mutex);
787 ret = v4l2_subdev_call(subdev, video, cropcap, cropcap);
788 mutex_unlock(&video->mutex);
790 return ret == -ENOIOCTLCMD ? -EINVAL : ret;
793 static int
794 isp_video_get_crop(struct file *file, void *fh, struct v4l2_crop *crop)
796 struct isp_video *video = video_drvdata(file);
797 struct v4l2_subdev_format format;
798 struct v4l2_subdev *subdev;
799 u32 pad;
800 int ret;
802 subdev = isp_video_remote_subdev(video, &pad);
803 if (subdev == NULL)
804 return -EINVAL;
806 /* Try the get crop operation first and fallback to get format if not
807 * implemented.
809 ret = v4l2_subdev_call(subdev, video, g_crop, crop);
810 if (ret != -ENOIOCTLCMD)
811 return ret;
813 format.pad = pad;
814 format.which = V4L2_SUBDEV_FORMAT_ACTIVE;
815 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &format);
816 if (ret < 0)
817 return ret == -ENOIOCTLCMD ? -EINVAL : ret;
819 crop->c.left = 0;
820 crop->c.top = 0;
821 crop->c.width = format.format.width;
822 crop->c.height = format.format.height;
824 return 0;
827 static int
828 isp_video_set_crop(struct file *file, void *fh, struct v4l2_crop *crop)
830 struct isp_video *video = video_drvdata(file);
831 struct v4l2_subdev *subdev;
832 int ret;
834 subdev = isp_video_remote_subdev(video, NULL);
835 if (subdev == NULL)
836 return -EINVAL;
838 mutex_lock(&video->mutex);
839 ret = v4l2_subdev_call(subdev, video, s_crop, crop);
840 mutex_unlock(&video->mutex);
842 return ret == -ENOIOCTLCMD ? -EINVAL : ret;
845 static int
846 isp_video_get_param(struct file *file, void *fh, struct v4l2_streamparm *a)
848 struct isp_video_fh *vfh = to_isp_video_fh(fh);
849 struct isp_video *video = video_drvdata(file);
851 if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
852 video->type != a->type)
853 return -EINVAL;
855 memset(a, 0, sizeof(*a));
856 a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
857 a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
858 a->parm.output.timeperframe = vfh->timeperframe;
860 return 0;
863 static int
864 isp_video_set_param(struct file *file, void *fh, struct v4l2_streamparm *a)
866 struct isp_video_fh *vfh = to_isp_video_fh(fh);
867 struct isp_video *video = video_drvdata(file);
869 if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
870 video->type != a->type)
871 return -EINVAL;
873 if (a->parm.output.timeperframe.denominator == 0)
874 a->parm.output.timeperframe.denominator = 1;
876 vfh->timeperframe = a->parm.output.timeperframe;
878 return 0;
881 static int
882 isp_video_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *rb)
884 struct isp_video_fh *vfh = to_isp_video_fh(fh);
886 return omap3isp_video_queue_reqbufs(&vfh->queue, rb);
889 static int
890 isp_video_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
892 struct isp_video_fh *vfh = to_isp_video_fh(fh);
894 return omap3isp_video_queue_querybuf(&vfh->queue, b);
897 static int
898 isp_video_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
900 struct isp_video_fh *vfh = to_isp_video_fh(fh);
902 return omap3isp_video_queue_qbuf(&vfh->queue, b);
905 static int
906 isp_video_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
908 struct isp_video_fh *vfh = to_isp_video_fh(fh);
910 return omap3isp_video_queue_dqbuf(&vfh->queue, b,
911 file->f_flags & O_NONBLOCK);
915 * Stream management
917 * Every ISP pipeline has a single input and a single output. The input can be
918 * either a sensor or a video node. The output is always a video node.
920 * As every pipeline has an output video node, the ISP video objects at the
921 * pipeline output stores the pipeline state. It tracks the streaming state of
922 * both the input and output, as well as the availability of buffers.
924 * In sensor-to-memory mode, frames are always available at the pipeline input.
925 * Starting the sensor usually requires I2C transfers and must be done in
926 * interruptible context. The pipeline is started and stopped synchronously
927 * to the stream on/off commands. All modules in the pipeline will get their
928 * subdev set stream handler called. The module at the end of the pipeline must
929 * delay starting the hardware until buffers are available at its output.
931 * In memory-to-memory mode, starting/stopping the stream requires
932 * synchronization between the input and output. ISP modules can't be stopped
933 * in the middle of a frame, and at least some of the modules seem to become
934 * busy as soon as they're started, even if they don't receive a frame start
935 * event. For that reason frames need to be processed in single-shot mode. The
936 * driver needs to wait until a frame is completely processed and written to
937 * memory before restarting the pipeline for the next frame. Pipelined
938 * processing might be possible but requires more testing.
940 * Stream start must be delayed until buffers are available at both the input
941 * and output. The pipeline must be started in the videobuf queue callback with
942 * the buffers queue spinlock held. The modules subdev set stream operation must
943 * not sleep.
945 static int
946 isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
948 struct isp_video_fh *vfh = to_isp_video_fh(fh);
949 struct isp_video *video = video_drvdata(file);
950 enum isp_pipeline_state state;
951 struct isp_pipeline *pipe;
952 struct isp_video *far_end;
953 unsigned long flags;
954 int ret;
956 if (type != video->type)
957 return -EINVAL;
959 mutex_lock(&video->stream_lock);
961 if (video->streaming) {
962 mutex_unlock(&video->stream_lock);
963 return -EBUSY;
966 /* Start streaming on the pipeline. No link touching an entity in the
967 * pipeline can be activated or deactivated once streaming is started.
969 pipe = video->video.entity.pipe
970 ? to_isp_pipeline(&video->video.entity) : &video->pipe;
971 media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
973 /* Verify that the currently configured format matches the output of
974 * the connected subdev.
976 ret = isp_video_check_format(video, vfh);
977 if (ret < 0)
978 goto error;
980 video->bpl_padding = ret;
981 video->bpl_value = vfh->format.fmt.pix.bytesperline;
983 /* Find the ISP video node connected at the far end of the pipeline and
984 * update the pipeline.
986 far_end = isp_video_far_end(video);
988 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
989 state = ISP_PIPELINE_STREAM_OUTPUT | ISP_PIPELINE_IDLE_OUTPUT;
990 pipe->input = far_end;
991 pipe->output = video;
992 } else {
993 if (far_end == NULL) {
994 ret = -EPIPE;
995 goto error;
998 state = ISP_PIPELINE_STREAM_INPUT | ISP_PIPELINE_IDLE_INPUT;
999 pipe->input = video;
1000 pipe->output = far_end;
1003 if (video->isp->pdata->set_constraints)
1004 video->isp->pdata->set_constraints(video->isp, true);
1005 pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
1007 /* Validate the pipeline and update its state. */
1008 ret = isp_video_validate_pipeline(pipe);
1009 if (ret < 0)
1010 goto error;
1012 spin_lock_irqsave(&pipe->lock, flags);
1013 pipe->state &= ~ISP_PIPELINE_STREAM;
1014 pipe->state |= state;
1015 spin_unlock_irqrestore(&pipe->lock, flags);
1017 /* Set the maximum time per frame as the value requested by userspace.
1018 * This is a soft limit that can be overridden if the hardware doesn't
1019 * support the request limit.
1021 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1022 pipe->max_timeperframe = vfh->timeperframe;
1024 video->queue = &vfh->queue;
1025 INIT_LIST_HEAD(&video->dmaqueue);
1026 atomic_set(&pipe->frame_number, -1);
1028 ret = omap3isp_video_queue_streamon(&vfh->queue);
1029 if (ret < 0)
1030 goto error;
1032 /* In sensor-to-memory mode, the stream can be started synchronously
1033 * to the stream on command. In memory-to-memory mode, it will be
1034 * started when buffers are queued on both the input and output.
1036 if (pipe->input == NULL) {
1037 ret = omap3isp_pipeline_set_stream(pipe,
1038 ISP_PIPELINE_STREAM_CONTINUOUS);
1039 if (ret < 0)
1040 goto error;
1041 spin_lock_irqsave(&video->queue->irqlock, flags);
1042 if (list_empty(&video->dmaqueue))
1043 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
1044 spin_unlock_irqrestore(&video->queue->irqlock, flags);
1047 error:
1048 if (ret < 0) {
1049 omap3isp_video_queue_streamoff(&vfh->queue);
1050 if (video->isp->pdata->set_constraints)
1051 video->isp->pdata->set_constraints(video->isp, false);
1052 media_entity_pipeline_stop(&video->video.entity);
1053 video->queue = NULL;
1056 if (!ret)
1057 video->streaming = 1;
1059 mutex_unlock(&video->stream_lock);
1060 return ret;
1063 static int
1064 isp_video_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
1066 struct isp_video_fh *vfh = to_isp_video_fh(fh);
1067 struct isp_video *video = video_drvdata(file);
1068 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
1069 enum isp_pipeline_state state;
1070 unsigned int streaming;
1071 unsigned long flags;
1073 if (type != video->type)
1074 return -EINVAL;
1076 mutex_lock(&video->stream_lock);
1078 /* Make sure we're not streaming yet. */
1079 mutex_lock(&vfh->queue.lock);
1080 streaming = vfh->queue.streaming;
1081 mutex_unlock(&vfh->queue.lock);
1083 if (!streaming)
1084 goto done;
1086 /* Update the pipeline state. */
1087 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1088 state = ISP_PIPELINE_STREAM_OUTPUT
1089 | ISP_PIPELINE_QUEUE_OUTPUT;
1090 else
1091 state = ISP_PIPELINE_STREAM_INPUT
1092 | ISP_PIPELINE_QUEUE_INPUT;
1094 spin_lock_irqsave(&pipe->lock, flags);
1095 pipe->state &= ~state;
1096 spin_unlock_irqrestore(&pipe->lock, flags);
1098 /* Stop the stream. */
1099 omap3isp_pipeline_set_stream(pipe, ISP_PIPELINE_STREAM_STOPPED);
1100 omap3isp_video_queue_streamoff(&vfh->queue);
1101 video->queue = NULL;
1102 video->streaming = 0;
1104 if (video->isp->pdata->set_constraints)
1105 video->isp->pdata->set_constraints(video->isp, false);
1106 media_entity_pipeline_stop(&video->video.entity);
1108 done:
1109 mutex_unlock(&video->stream_lock);
1110 return 0;
1113 static int
1114 isp_video_enum_input(struct file *file, void *fh, struct v4l2_input *input)
1116 if (input->index > 0)
1117 return -EINVAL;
1119 strlcpy(input->name, "camera", sizeof(input->name));
1120 input->type = V4L2_INPUT_TYPE_CAMERA;
1122 return 0;
1125 static int
1126 isp_video_g_input(struct file *file, void *fh, unsigned int *input)
1128 *input = 0;
1130 return 0;
1133 static int
1134 isp_video_s_input(struct file *file, void *fh, unsigned int input)
1136 return input == 0 ? 0 : -EINVAL;
1139 static const struct v4l2_ioctl_ops isp_video_ioctl_ops = {
1140 .vidioc_querycap = isp_video_querycap,
1141 .vidioc_g_fmt_vid_cap = isp_video_get_format,
1142 .vidioc_s_fmt_vid_cap = isp_video_set_format,
1143 .vidioc_try_fmt_vid_cap = isp_video_try_format,
1144 .vidioc_g_fmt_vid_out = isp_video_get_format,
1145 .vidioc_s_fmt_vid_out = isp_video_set_format,
1146 .vidioc_try_fmt_vid_out = isp_video_try_format,
1147 .vidioc_cropcap = isp_video_cropcap,
1148 .vidioc_g_crop = isp_video_get_crop,
1149 .vidioc_s_crop = isp_video_set_crop,
1150 .vidioc_g_parm = isp_video_get_param,
1151 .vidioc_s_parm = isp_video_set_param,
1152 .vidioc_reqbufs = isp_video_reqbufs,
1153 .vidioc_querybuf = isp_video_querybuf,
1154 .vidioc_qbuf = isp_video_qbuf,
1155 .vidioc_dqbuf = isp_video_dqbuf,
1156 .vidioc_streamon = isp_video_streamon,
1157 .vidioc_streamoff = isp_video_streamoff,
1158 .vidioc_enum_input = isp_video_enum_input,
1159 .vidioc_g_input = isp_video_g_input,
1160 .vidioc_s_input = isp_video_s_input,
1163 /* -----------------------------------------------------------------------------
1164 * V4L2 file operations
1167 static int isp_video_open(struct file *file)
1169 struct isp_video *video = video_drvdata(file);
1170 struct isp_video_fh *handle;
1171 int ret = 0;
1173 handle = kzalloc(sizeof(*handle), GFP_KERNEL);
1174 if (handle == NULL)
1175 return -ENOMEM;
1177 v4l2_fh_init(&handle->vfh, &video->video);
1178 v4l2_fh_add(&handle->vfh);
1180 /* If this is the first user, initialise the pipeline. */
1181 if (omap3isp_get(video->isp) == NULL) {
1182 ret = -EBUSY;
1183 goto done;
1186 ret = omap3isp_pipeline_pm_use(&video->video.entity, 1);
1187 if (ret < 0) {
1188 omap3isp_put(video->isp);
1189 goto done;
1192 omap3isp_video_queue_init(&handle->queue, video->type,
1193 &isp_video_queue_ops, video->isp->dev,
1194 sizeof(struct isp_buffer));
1196 memset(&handle->format, 0, sizeof(handle->format));
1197 handle->format.type = video->type;
1198 handle->timeperframe.denominator = 1;
1200 handle->video = video;
1201 file->private_data = &handle->vfh;
1203 done:
1204 if (ret < 0) {
1205 v4l2_fh_del(&handle->vfh);
1206 kfree(handle);
1209 return ret;
1212 static int isp_video_release(struct file *file)
1214 struct isp_video *video = video_drvdata(file);
1215 struct v4l2_fh *vfh = file->private_data;
1216 struct isp_video_fh *handle = to_isp_video_fh(vfh);
1218 /* Disable streaming and free the buffers queue resources. */
1219 isp_video_streamoff(file, vfh, video->type);
1221 mutex_lock(&handle->queue.lock);
1222 omap3isp_video_queue_cleanup(&handle->queue);
1223 mutex_unlock(&handle->queue.lock);
1225 omap3isp_pipeline_pm_use(&video->video.entity, 0);
1227 /* Release the file handle. */
1228 v4l2_fh_del(vfh);
1229 kfree(handle);
1230 file->private_data = NULL;
1232 omap3isp_put(video->isp);
1234 return 0;
1237 static unsigned int isp_video_poll(struct file *file, poll_table *wait)
1239 struct isp_video_fh *vfh = to_isp_video_fh(file->private_data);
1240 struct isp_video_queue *queue = &vfh->queue;
1242 return omap3isp_video_queue_poll(queue, file, wait);
1245 static int isp_video_mmap(struct file *file, struct vm_area_struct *vma)
1247 struct isp_video_fh *vfh = to_isp_video_fh(file->private_data);
1249 return omap3isp_video_queue_mmap(&vfh->queue, vma);
1252 static struct v4l2_file_operations isp_video_fops = {
1253 .owner = THIS_MODULE,
1254 .unlocked_ioctl = video_ioctl2,
1255 .open = isp_video_open,
1256 .release = isp_video_release,
1257 .poll = isp_video_poll,
1258 .mmap = isp_video_mmap,
1261 /* -----------------------------------------------------------------------------
1262 * ISP video core
1265 static const struct isp_video_operations isp_video_dummy_ops = {
1268 int omap3isp_video_init(struct isp_video *video, const char *name)
1270 const char *direction;
1271 int ret;
1273 switch (video->type) {
1274 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1275 direction = "output";
1276 video->pad.flags = MEDIA_PAD_FL_SINK;
1277 break;
1278 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1279 direction = "input";
1280 video->pad.flags = MEDIA_PAD_FL_SOURCE;
1281 break;
1283 default:
1284 return -EINVAL;
1287 ret = media_entity_init(&video->video.entity, 1, &video->pad, 0);
1288 if (ret < 0)
1289 return ret;
1291 mutex_init(&video->mutex);
1292 atomic_set(&video->active, 0);
1294 spin_lock_init(&video->pipe.lock);
1295 mutex_init(&video->stream_lock);
1297 /* Initialize the video device. */
1298 if (video->ops == NULL)
1299 video->ops = &isp_video_dummy_ops;
1301 video->video.fops = &isp_video_fops;
1302 snprintf(video->video.name, sizeof(video->video.name),
1303 "OMAP3 ISP %s %s", name, direction);
1304 video->video.vfl_type = VFL_TYPE_GRABBER;
1305 video->video.release = video_device_release_empty;
1306 video->video.ioctl_ops = &isp_video_ioctl_ops;
1307 video->pipe.stream_state = ISP_PIPELINE_STREAM_STOPPED;
1309 video_set_drvdata(&video->video, video);
1311 return 0;
1314 int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev)
1316 int ret;
1318 video->video.v4l2_dev = vdev;
1320 ret = video_register_device(&video->video, VFL_TYPE_GRABBER, -1);
1321 if (ret < 0)
1322 printk(KERN_ERR "%s: could not register video device (%d)\n",
1323 __func__, ret);
1325 return ret;
1328 void omap3isp_video_unregister(struct isp_video *video)
1330 if (video_is_registered(&video->video)) {
1331 media_entity_cleanup(&video->video.entity);
1332 video_unregister_device(&video->video);