blob: 9ade7359ebca58310fca387552a4204c3e9f5950 [file] [log] [blame]
Laurent Pinchartad614ac2011-02-12 18:05:06 -03001/*
2 * ispvideo.c
3 *
4 * TI OMAP3 ISP - Generic video node
5 *
6 * Copyright (C) 2009-2010 Nokia Corporation
7 *
8 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 * Sakari Ailus <sakari.ailus@iki.fi>
10 *
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.
14 *
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.
19 *
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
24 */
25
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>
39
40#include "ispvideo.h"
41#include "isp.h"
42
43
44/* -----------------------------------------------------------------------------
45 * Helper functions
46 */
47
48static struct isp_format_info formats[] = {
49 { V4L2_MBUS_FMT_Y8_1X8, V4L2_MBUS_FMT_Y8_1X8,
50 V4L2_MBUS_FMT_Y8_1X8, V4L2_PIX_FMT_GREY, 8, },
Michael Jones5782f972011-03-29 05:19:08 -030051 { V4L2_MBUS_FMT_Y10_1X10, V4L2_MBUS_FMT_Y10_1X10,
52 V4L2_MBUS_FMT_Y10_1X10, V4L2_PIX_FMT_Y10, 10, },
53 { V4L2_MBUS_FMT_Y12_1X12, V4L2_MBUS_FMT_Y10_1X10,
54 V4L2_MBUS_FMT_Y12_1X12, V4L2_PIX_FMT_Y12, 12, },
55 { V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_MBUS_FMT_SBGGR8_1X8,
56 V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_PIX_FMT_SBGGR8, 8, },
57 { V4L2_MBUS_FMT_SGBRG8_1X8, V4L2_MBUS_FMT_SGBRG8_1X8,
58 V4L2_MBUS_FMT_SGBRG8_1X8, V4L2_PIX_FMT_SGBRG8, 8, },
59 { V4L2_MBUS_FMT_SGRBG8_1X8, V4L2_MBUS_FMT_SGRBG8_1X8,
60 V4L2_MBUS_FMT_SGRBG8_1X8, V4L2_PIX_FMT_SGRBG8, 8, },
61 { V4L2_MBUS_FMT_SRGGB8_1X8, V4L2_MBUS_FMT_SRGGB8_1X8,
62 V4L2_MBUS_FMT_SRGGB8_1X8, V4L2_PIX_FMT_SRGGB8, 8, },
Laurent Pinchartad614ac2011-02-12 18:05:06 -030063 { V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
64 V4L2_MBUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10DPCM8, 8, },
65 { V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_MBUS_FMT_SBGGR10_1X10,
66 V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_PIX_FMT_SBGGR10, 10, },
67 { V4L2_MBUS_FMT_SGBRG10_1X10, V4L2_MBUS_FMT_SGBRG10_1X10,
68 V4L2_MBUS_FMT_SGBRG10_1X10, V4L2_PIX_FMT_SGBRG10, 10, },
69 { V4L2_MBUS_FMT_SGRBG10_1X10, V4L2_MBUS_FMT_SGRBG10_1X10,
70 V4L2_MBUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10, 10, },
71 { V4L2_MBUS_FMT_SRGGB10_1X10, V4L2_MBUS_FMT_SRGGB10_1X10,
72 V4L2_MBUS_FMT_SRGGB10_1X10, V4L2_PIX_FMT_SRGGB10, 10, },
73 { V4L2_MBUS_FMT_SBGGR12_1X12, V4L2_MBUS_FMT_SBGGR10_1X10,
74 V4L2_MBUS_FMT_SBGGR12_1X12, V4L2_PIX_FMT_SBGGR12, 12, },
75 { V4L2_MBUS_FMT_SGBRG12_1X12, V4L2_MBUS_FMT_SGBRG10_1X10,
76 V4L2_MBUS_FMT_SGBRG12_1X12, V4L2_PIX_FMT_SGBRG12, 12, },
77 { V4L2_MBUS_FMT_SGRBG12_1X12, V4L2_MBUS_FMT_SGRBG10_1X10,
78 V4L2_MBUS_FMT_SGRBG12_1X12, V4L2_PIX_FMT_SGRBG12, 12, },
79 { V4L2_MBUS_FMT_SRGGB12_1X12, V4L2_MBUS_FMT_SRGGB10_1X10,
80 V4L2_MBUS_FMT_SRGGB12_1X12, V4L2_PIX_FMT_SRGGB12, 12, },
81 { V4L2_MBUS_FMT_UYVY8_1X16, V4L2_MBUS_FMT_UYVY8_1X16,
82 V4L2_MBUS_FMT_UYVY8_1X16, V4L2_PIX_FMT_UYVY, 16, },
83 { V4L2_MBUS_FMT_YUYV8_1X16, V4L2_MBUS_FMT_YUYV8_1X16,
84 V4L2_MBUS_FMT_YUYV8_1X16, V4L2_PIX_FMT_YUYV, 16, },
85};
86
87const struct isp_format_info *
88omap3isp_video_format_info(enum v4l2_mbus_pixelcode code)
89{
90 unsigned int i;
91
92 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
93 if (formats[i].code == code)
94 return &formats[i];
95 }
96
97 return NULL;
98}
99
100/*
101 * isp_video_mbus_to_pix - Convert v4l2_mbus_framefmt to v4l2_pix_format
102 * @video: ISP video instance
103 * @mbus: v4l2_mbus_framefmt format (input)
104 * @pix: v4l2_pix_format format (output)
105 *
106 * Fill the output pix structure with information from the input mbus format.
107 * The bytesperline and sizeimage fields are computed from the requested bytes
108 * per line value in the pix format and information from the video instance.
109 *
110 * Return the number of padding bytes at end of line.
111 */
112static unsigned int isp_video_mbus_to_pix(const struct isp_video *video,
113 const struct v4l2_mbus_framefmt *mbus,
114 struct v4l2_pix_format *pix)
115{
116 unsigned int bpl = pix->bytesperline;
117 unsigned int min_bpl;
118 unsigned int i;
119
120 memset(pix, 0, sizeof(*pix));
121 pix->width = mbus->width;
122 pix->height = mbus->height;
123
124 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
125 if (formats[i].code == mbus->code)
126 break;
127 }
128
129 if (WARN_ON(i == ARRAY_SIZE(formats)))
130 return 0;
131
132 min_bpl = pix->width * ALIGN(formats[i].bpp, 8) / 8;
133
134 /* Clamp the requested bytes per line value. If the maximum bytes per
135 * line value is zero, the module doesn't support user configurable line
136 * sizes. Override the requested value with the minimum in that case.
137 */
138 if (video->bpl_max)
139 bpl = clamp(bpl, min_bpl, video->bpl_max);
140 else
141 bpl = min_bpl;
142
143 if (!video->bpl_zero_padding || bpl != min_bpl)
144 bpl = ALIGN(bpl, video->bpl_alignment);
145
146 pix->pixelformat = formats[i].pixelformat;
147 pix->bytesperline = bpl;
148 pix->sizeimage = pix->bytesperline * pix->height;
149 pix->colorspace = mbus->colorspace;
150 pix->field = mbus->field;
151
152 return bpl - min_bpl;
153}
154
155static void isp_video_pix_to_mbus(const struct v4l2_pix_format *pix,
156 struct v4l2_mbus_framefmt *mbus)
157{
158 unsigned int i;
159
160 memset(mbus, 0, sizeof(*mbus));
161 mbus->width = pix->width;
162 mbus->height = pix->height;
163
164 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
165 if (formats[i].pixelformat == pix->pixelformat)
166 break;
167 }
168
169 if (WARN_ON(i == ARRAY_SIZE(formats)))
170 return;
171
172 mbus->code = formats[i].code;
173 mbus->colorspace = pix->colorspace;
174 mbus->field = pix->field;
175}
176
177static struct v4l2_subdev *
178isp_video_remote_subdev(struct isp_video *video, u32 *pad)
179{
180 struct media_pad *remote;
181
182 remote = media_entity_remote_source(&video->pad);
183
184 if (remote == NULL ||
185 media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
186 return NULL;
187
188 if (pad)
189 *pad = remote->index;
190
191 return media_entity_to_v4l2_subdev(remote->entity);
192}
193
194/* Return a pointer to the ISP video instance at the far end of the pipeline. */
195static struct isp_video *
196isp_video_far_end(struct isp_video *video)
197{
198 struct media_entity_graph graph;
199 struct media_entity *entity = &video->video.entity;
200 struct media_device *mdev = entity->parent;
201 struct isp_video *far_end = NULL;
202
203 mutex_lock(&mdev->graph_mutex);
204 media_entity_graph_walk_start(&graph, entity);
205
206 while ((entity = media_entity_graph_walk_next(&graph))) {
207 if (entity == &video->video.entity)
208 continue;
209
210 if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
211 continue;
212
213 far_end = to_isp_video(media_entity_to_video_device(entity));
214 if (far_end->type != video->type)
215 break;
216
217 far_end = NULL;
218 }
219
220 mutex_unlock(&mdev->graph_mutex);
221 return far_end;
222}
223
224/*
225 * Validate a pipeline by checking both ends of all links for format
226 * discrepancies.
227 *
228 * Compute the minimum time per frame value as the maximum of time per frame
229 * limits reported by every block in the pipeline.
230 *
231 * Return 0 if all formats match, or -EPIPE if at least one link is found with
232 * different formats on its two ends.
233 */
234static int isp_video_validate_pipeline(struct isp_pipeline *pipe)
235{
236 struct isp_device *isp = pipe->output->isp;
237 struct v4l2_subdev_format fmt_source;
238 struct v4l2_subdev_format fmt_sink;
239 struct media_pad *pad;
240 struct v4l2_subdev *subdev;
241 int ret;
242
243 pipe->max_rate = pipe->l3_ick;
244
245 subdev = isp_video_remote_subdev(pipe->output, NULL);
246 if (subdev == NULL)
247 return -EPIPE;
248
249 while (1) {
250 /* Retrieve the sink format */
251 pad = &subdev->entity.pads[0];
252 if (!(pad->flags & MEDIA_PAD_FL_SINK))
253 break;
254
255 fmt_sink.pad = pad->index;
256 fmt_sink.which = V4L2_SUBDEV_FORMAT_ACTIVE;
257 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_sink);
258 if (ret < 0 && ret != -ENOIOCTLCMD)
259 return -EPIPE;
260
261 /* Update the maximum frame rate */
262 if (subdev == &isp->isp_res.subdev)
263 omap3isp_resizer_max_rate(&isp->isp_res,
264 &pipe->max_rate);
265
266 /* Check ccdc maximum data rate when data comes from sensor
267 * TODO: Include ccdc rate in pipe->max_rate and compare the
268 * total pipe rate with the input data rate from sensor.
269 */
270 if (subdev == &isp->isp_ccdc.subdev && pipe->input == NULL) {
271 unsigned int rate = UINT_MAX;
272
273 omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
274 if (isp->isp_ccdc.vpcfg.pixelclk > rate)
275 return -ENOSPC;
276 }
277
278 /* Retrieve the source format */
279 pad = media_entity_remote_source(pad);
280 if (pad == NULL ||
281 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
282 break;
283
284 subdev = media_entity_to_v4l2_subdev(pad->entity);
285
286 fmt_source.pad = pad->index;
287 fmt_source.which = V4L2_SUBDEV_FORMAT_ACTIVE;
288 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_source);
289 if (ret < 0 && ret != -ENOIOCTLCMD)
290 return -EPIPE;
291
292 /* Check if the two ends match */
293 if (fmt_source.format.code != fmt_sink.format.code ||
294 fmt_source.format.width != fmt_sink.format.width ||
295 fmt_source.format.height != fmt_sink.format.height)
296 return -EPIPE;
297 }
298
299 return 0;
300}
301
302static int
303__isp_video_get_format(struct isp_video *video, struct v4l2_format *format)
304{
305 struct v4l2_subdev_format fmt;
306 struct v4l2_subdev *subdev;
307 u32 pad;
308 int ret;
309
310 subdev = isp_video_remote_subdev(video, &pad);
311 if (subdev == NULL)
312 return -EINVAL;
313
314 mutex_lock(&video->mutex);
315
316 fmt.pad = pad;
317 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
318 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
319 if (ret == -ENOIOCTLCMD)
320 ret = -EINVAL;
321
322 mutex_unlock(&video->mutex);
323
324 if (ret)
325 return ret;
326
327 format->type = video->type;
328 return isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
329}
330
331static int
332isp_video_check_format(struct isp_video *video, struct isp_video_fh *vfh)
333{
334 struct v4l2_format format;
335 int ret;
336
337 memcpy(&format, &vfh->format, sizeof(format));
338 ret = __isp_video_get_format(video, &format);
339 if (ret < 0)
340 return ret;
341
342 if (vfh->format.fmt.pix.pixelformat != format.fmt.pix.pixelformat ||
343 vfh->format.fmt.pix.height != format.fmt.pix.height ||
344 vfh->format.fmt.pix.width != format.fmt.pix.width ||
345 vfh->format.fmt.pix.bytesperline != format.fmt.pix.bytesperline ||
346 vfh->format.fmt.pix.sizeimage != format.fmt.pix.sizeimage)
347 return -EINVAL;
348
349 return ret;
350}
351
352/* -----------------------------------------------------------------------------
353 * IOMMU management
354 */
355
356#define IOMMU_FLAG (IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_8)
357
358/*
359 * ispmmu_vmap - Wrapper for Virtual memory mapping of a scatter gather list
360 * @dev: Device pointer specific to the OMAP3 ISP.
361 * @sglist: Pointer to source Scatter gather list to allocate.
362 * @sglen: Number of elements of the scatter-gatter list.
363 *
364 * Returns a resulting mapped device address by the ISP MMU, or -ENOMEM if
365 * we ran out of memory.
366 */
367static dma_addr_t
368ispmmu_vmap(struct isp_device *isp, const struct scatterlist *sglist, int sglen)
369{
370 struct sg_table *sgt;
371 u32 da;
372
373 sgt = kmalloc(sizeof(*sgt), GFP_KERNEL);
374 if (sgt == NULL)
375 return -ENOMEM;
376
377 sgt->sgl = (struct scatterlist *)sglist;
378 sgt->nents = sglen;
379 sgt->orig_nents = sglen;
380
381 da = iommu_vmap(isp->iommu, 0, sgt, IOMMU_FLAG);
382 if (IS_ERR_VALUE(da))
383 kfree(sgt);
384
385 return da;
386}
387
388/*
389 * ispmmu_vunmap - Unmap a device address from the ISP MMU
390 * @dev: Device pointer specific to the OMAP3 ISP.
391 * @da: Device address generated from a ispmmu_vmap call.
392 */
393static void ispmmu_vunmap(struct isp_device *isp, dma_addr_t da)
394{
395 struct sg_table *sgt;
396
397 sgt = iommu_vunmap(isp->iommu, (u32)da);
398 kfree(sgt);
399}
400
401/* -----------------------------------------------------------------------------
402 * Video queue operations
403 */
404
405static void isp_video_queue_prepare(struct isp_video_queue *queue,
406 unsigned int *nbuffers, unsigned int *size)
407{
408 struct isp_video_fh *vfh =
409 container_of(queue, struct isp_video_fh, queue);
410 struct isp_video *video = vfh->video;
411
412 *size = vfh->format.fmt.pix.sizeimage;
413 if (*size == 0)
414 return;
415
416 *nbuffers = min(*nbuffers, video->capture_mem / PAGE_ALIGN(*size));
417}
418
419static void isp_video_buffer_cleanup(struct isp_video_buffer *buf)
420{
421 struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
422 struct isp_buffer *buffer = to_isp_buffer(buf);
423 struct isp_video *video = vfh->video;
424
425 if (buffer->isp_addr) {
426 ispmmu_vunmap(video->isp, buffer->isp_addr);
427 buffer->isp_addr = 0;
428 }
429}
430
431static int isp_video_buffer_prepare(struct isp_video_buffer *buf)
432{
433 struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
434 struct isp_buffer *buffer = to_isp_buffer(buf);
435 struct isp_video *video = vfh->video;
436 unsigned long addr;
437
438 addr = ispmmu_vmap(video->isp, buf->sglist, buf->sglen);
439 if (IS_ERR_VALUE(addr))
440 return -EIO;
441
442 if (!IS_ALIGNED(addr, 32)) {
443 dev_dbg(video->isp->dev, "Buffer address must be "
444 "aligned to 32 bytes boundary.\n");
445 ispmmu_vunmap(video->isp, buffer->isp_addr);
446 return -EINVAL;
447 }
448
449 buf->vbuf.bytesused = vfh->format.fmt.pix.sizeimage;
450 buffer->isp_addr = addr;
451 return 0;
452}
453
454/*
455 * isp_video_buffer_queue - Add buffer to streaming queue
456 * @buf: Video buffer
457 *
458 * In memory-to-memory mode, start streaming on the pipeline if buffers are
459 * queued on both the input and the output, if the pipeline isn't already busy.
460 * If the pipeline is busy, it will be restarted in the output module interrupt
461 * handler.
462 */
463static void isp_video_buffer_queue(struct isp_video_buffer *buf)
464{
465 struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
466 struct isp_buffer *buffer = to_isp_buffer(buf);
467 struct isp_video *video = vfh->video;
468 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
469 enum isp_pipeline_state state;
470 unsigned long flags;
471 unsigned int empty;
472 unsigned int start;
473
474 empty = list_empty(&video->dmaqueue);
475 list_add_tail(&buffer->buffer.irqlist, &video->dmaqueue);
476
477 if (empty) {
478 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
479 state = ISP_PIPELINE_QUEUE_OUTPUT;
480 else
481 state = ISP_PIPELINE_QUEUE_INPUT;
482
483 spin_lock_irqsave(&pipe->lock, flags);
484 pipe->state |= state;
485 video->ops->queue(video, buffer);
486 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_QUEUED;
487
488 start = isp_pipeline_ready(pipe);
489 if (start)
490 pipe->state |= ISP_PIPELINE_STREAM;
491 spin_unlock_irqrestore(&pipe->lock, flags);
492
493 if (start)
494 omap3isp_pipeline_set_stream(pipe,
495 ISP_PIPELINE_STREAM_SINGLESHOT);
496 }
497}
498
499static const struct isp_video_queue_operations isp_video_queue_ops = {
500 .queue_prepare = &isp_video_queue_prepare,
501 .buffer_prepare = &isp_video_buffer_prepare,
502 .buffer_queue = &isp_video_buffer_queue,
503 .buffer_cleanup = &isp_video_buffer_cleanup,
504};
505
506/*
507 * omap3isp_video_buffer_next - Complete the current buffer and return the next
508 * @video: ISP video object
509 * @error: Whether an error occured during capture
510 *
511 * Remove the current video buffer from the DMA queue and fill its timestamp,
512 * field count and state fields before waking up its completion handler.
513 *
514 * The buffer state is set to VIDEOBUF_DONE if no error occured (@error is 0)
515 * or VIDEOBUF_ERROR otherwise (@error is non-zero).
516 *
517 * The DMA queue is expected to contain at least one buffer.
518 *
519 * Return a pointer to the next buffer in the DMA queue, or NULL if the queue is
520 * empty.
521 */
522struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video,
523 unsigned int error)
524{
525 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
526 struct isp_video_queue *queue = video->queue;
527 enum isp_pipeline_state state;
528 struct isp_video_buffer *buf;
529 unsigned long flags;
530 struct timespec ts;
531
532 spin_lock_irqsave(&queue->irqlock, flags);
533 if (WARN_ON(list_empty(&video->dmaqueue))) {
534 spin_unlock_irqrestore(&queue->irqlock, flags);
535 return NULL;
536 }
537
538 buf = list_first_entry(&video->dmaqueue, struct isp_video_buffer,
539 irqlist);
540 list_del(&buf->irqlist);
541 spin_unlock_irqrestore(&queue->irqlock, flags);
542
543 ktime_get_ts(&ts);
544 buf->vbuf.timestamp.tv_sec = ts.tv_sec;
545 buf->vbuf.timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
546
547 /* Do frame number propagation only if this is the output video node.
548 * Frame number either comes from the CSI receivers or it gets
549 * incremented here if H3A is not active.
550 * Note: There is no guarantee that the output buffer will finish
551 * first, so the input number might lag behind by 1 in some cases.
552 */
553 if (video == pipe->output && !pipe->do_propagation)
554 buf->vbuf.sequence = atomic_inc_return(&pipe->frame_number);
555 else
556 buf->vbuf.sequence = atomic_read(&pipe->frame_number);
557
558 buf->state = error ? ISP_BUF_STATE_ERROR : ISP_BUF_STATE_DONE;
559
560 wake_up(&buf->wait);
561
562 if (list_empty(&video->dmaqueue)) {
563 if (queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
564 state = ISP_PIPELINE_QUEUE_OUTPUT
565 | ISP_PIPELINE_STREAM;
566 else
567 state = ISP_PIPELINE_QUEUE_INPUT
568 | ISP_PIPELINE_STREAM;
569
570 spin_lock_irqsave(&pipe->lock, flags);
571 pipe->state &= ~state;
572 if (video->pipe.stream_state == ISP_PIPELINE_STREAM_CONTINUOUS)
573 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
574 spin_unlock_irqrestore(&pipe->lock, flags);
575 return NULL;
576 }
577
578 if (queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->input != NULL) {
579 spin_lock_irqsave(&pipe->lock, flags);
580 pipe->state &= ~ISP_PIPELINE_STREAM;
581 spin_unlock_irqrestore(&pipe->lock, flags);
582 }
583
584 buf = list_first_entry(&video->dmaqueue, struct isp_video_buffer,
585 irqlist);
586 buf->state = ISP_BUF_STATE_ACTIVE;
587 return to_isp_buffer(buf);
588}
589
590/*
591 * omap3isp_video_resume - Perform resume operation on the buffers
592 * @video: ISP video object
593 * @continuous: Pipeline is in single shot mode if 0 or continous mode otherwise
594 *
595 * This function is intended to be used on suspend/resume scenario. It
596 * requests video queue layer to discard buffers marked as DONE if it's in
597 * continuous mode and requests ISP modules to queue again the ACTIVE buffer
598 * if there's any.
599 */
600void omap3isp_video_resume(struct isp_video *video, int continuous)
601{
602 struct isp_buffer *buf = NULL;
603
604 if (continuous && video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
605 omap3isp_video_queue_discard_done(video->queue);
606
607 if (!list_empty(&video->dmaqueue)) {
608 buf = list_first_entry(&video->dmaqueue,
609 struct isp_buffer, buffer.irqlist);
610 video->ops->queue(video, buf);
611 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_QUEUED;
612 } else {
613 if (continuous)
614 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
615 }
616}
617
618/* -----------------------------------------------------------------------------
619 * V4L2 ioctls
620 */
621
622static int
623isp_video_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
624{
625 struct isp_video *video = video_drvdata(file);
626
627 strlcpy(cap->driver, ISP_VIDEO_DRIVER_NAME, sizeof(cap->driver));
628 strlcpy(cap->card, video->video.name, sizeof(cap->card));
629 strlcpy(cap->bus_info, "media", sizeof(cap->bus_info));
630 cap->version = ISP_VIDEO_DRIVER_VERSION;
631
632 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
633 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
634 else
635 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
636
637 return 0;
638}
639
640static int
641isp_video_get_format(struct file *file, void *fh, struct v4l2_format *format)
642{
643 struct isp_video_fh *vfh = to_isp_video_fh(fh);
644 struct isp_video *video = video_drvdata(file);
645
646 if (format->type != video->type)
647 return -EINVAL;
648
649 mutex_lock(&video->mutex);
650 *format = vfh->format;
651 mutex_unlock(&video->mutex);
652
653 return 0;
654}
655
656static int
657isp_video_set_format(struct file *file, void *fh, struct v4l2_format *format)
658{
659 struct isp_video_fh *vfh = to_isp_video_fh(fh);
660 struct isp_video *video = video_drvdata(file);
661 struct v4l2_mbus_framefmt fmt;
662
663 if (format->type != video->type)
664 return -EINVAL;
665
666 mutex_lock(&video->mutex);
667
668 /* Fill the bytesperline and sizeimage fields by converting to media bus
669 * format and back to pixel format.
670 */
671 isp_video_pix_to_mbus(&format->fmt.pix, &fmt);
672 isp_video_mbus_to_pix(video, &fmt, &format->fmt.pix);
673
674 vfh->format = *format;
675
676 mutex_unlock(&video->mutex);
677 return 0;
678}
679
680static int
681isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format)
682{
683 struct isp_video *video = video_drvdata(file);
684 struct v4l2_subdev_format fmt;
685 struct v4l2_subdev *subdev;
686 u32 pad;
687 int ret;
688
689 if (format->type != video->type)
690 return -EINVAL;
691
692 subdev = isp_video_remote_subdev(video, &pad);
693 if (subdev == NULL)
694 return -EINVAL;
695
696 isp_video_pix_to_mbus(&format->fmt.pix, &fmt.format);
697
698 fmt.pad = pad;
699 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
700 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
701 if (ret)
702 return ret == -ENOIOCTLCMD ? -EINVAL : ret;
703
704 isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
705 return 0;
706}
707
708static int
709isp_video_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap)
710{
711 struct isp_video *video = video_drvdata(file);
712 struct v4l2_subdev *subdev;
713 int ret;
714
715 subdev = isp_video_remote_subdev(video, NULL);
716 if (subdev == NULL)
717 return -EINVAL;
718
719 mutex_lock(&video->mutex);
720 ret = v4l2_subdev_call(subdev, video, cropcap, cropcap);
721 mutex_unlock(&video->mutex);
722
723 return ret == -ENOIOCTLCMD ? -EINVAL : ret;
724}
725
726static int
727isp_video_get_crop(struct file *file, void *fh, struct v4l2_crop *crop)
728{
729 struct isp_video *video = video_drvdata(file);
730 struct v4l2_subdev_format format;
731 struct v4l2_subdev *subdev;
732 u32 pad;
733 int ret;
734
735 subdev = isp_video_remote_subdev(video, &pad);
736 if (subdev == NULL)
737 return -EINVAL;
738
739 /* Try the get crop operation first and fallback to get format if not
740 * implemented.
741 */
742 ret = v4l2_subdev_call(subdev, video, g_crop, crop);
743 if (ret != -ENOIOCTLCMD)
744 return ret;
745
746 format.pad = pad;
747 format.which = V4L2_SUBDEV_FORMAT_ACTIVE;
748 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &format);
749 if (ret < 0)
750 return ret == -ENOIOCTLCMD ? -EINVAL : ret;
751
752 crop->c.left = 0;
753 crop->c.top = 0;
754 crop->c.width = format.format.width;
755 crop->c.height = format.format.height;
756
757 return 0;
758}
759
760static int
761isp_video_set_crop(struct file *file, void *fh, struct v4l2_crop *crop)
762{
763 struct isp_video *video = video_drvdata(file);
764 struct v4l2_subdev *subdev;
765 int ret;
766
767 subdev = isp_video_remote_subdev(video, NULL);
768 if (subdev == NULL)
769 return -EINVAL;
770
771 mutex_lock(&video->mutex);
772 ret = v4l2_subdev_call(subdev, video, s_crop, crop);
773 mutex_unlock(&video->mutex);
774
775 return ret == -ENOIOCTLCMD ? -EINVAL : ret;
776}
777
778static int
779isp_video_get_param(struct file *file, void *fh, struct v4l2_streamparm *a)
780{
781 struct isp_video_fh *vfh = to_isp_video_fh(fh);
782 struct isp_video *video = video_drvdata(file);
783
784 if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
785 video->type != a->type)
786 return -EINVAL;
787
788 memset(a, 0, sizeof(*a));
789 a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
790 a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
791 a->parm.output.timeperframe = vfh->timeperframe;
792
793 return 0;
794}
795
796static int
797isp_video_set_param(struct file *file, void *fh, struct v4l2_streamparm *a)
798{
799 struct isp_video_fh *vfh = to_isp_video_fh(fh);
800 struct isp_video *video = video_drvdata(file);
801
802 if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
803 video->type != a->type)
804 return -EINVAL;
805
806 if (a->parm.output.timeperframe.denominator == 0)
807 a->parm.output.timeperframe.denominator = 1;
808
809 vfh->timeperframe = a->parm.output.timeperframe;
810
811 return 0;
812}
813
814static int
815isp_video_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *rb)
816{
817 struct isp_video_fh *vfh = to_isp_video_fh(fh);
818
819 return omap3isp_video_queue_reqbufs(&vfh->queue, rb);
820}
821
822static int
823isp_video_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
824{
825 struct isp_video_fh *vfh = to_isp_video_fh(fh);
826
827 return omap3isp_video_queue_querybuf(&vfh->queue, b);
828}
829
830static int
831isp_video_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
832{
833 struct isp_video_fh *vfh = to_isp_video_fh(fh);
834
835 return omap3isp_video_queue_qbuf(&vfh->queue, b);
836}
837
838static int
839isp_video_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
840{
841 struct isp_video_fh *vfh = to_isp_video_fh(fh);
842
843 return omap3isp_video_queue_dqbuf(&vfh->queue, b,
844 file->f_flags & O_NONBLOCK);
845}
846
847/*
848 * Stream management
849 *
850 * Every ISP pipeline has a single input and a single output. The input can be
851 * either a sensor or a video node. The output is always a video node.
852 *
853 * As every pipeline has an output video node, the ISP video objects at the
854 * pipeline output stores the pipeline state. It tracks the streaming state of
855 * both the input and output, as well as the availability of buffers.
856 *
857 * In sensor-to-memory mode, frames are always available at the pipeline input.
858 * Starting the sensor usually requires I2C transfers and must be done in
859 * interruptible context. The pipeline is started and stopped synchronously
860 * to the stream on/off commands. All modules in the pipeline will get their
861 * subdev set stream handler called. The module at the end of the pipeline must
862 * delay starting the hardware until buffers are available at its output.
863 *
864 * In memory-to-memory mode, starting/stopping the stream requires
865 * synchronization between the input and output. ISP modules can't be stopped
866 * in the middle of a frame, and at least some of the modules seem to become
867 * busy as soon as they're started, even if they don't receive a frame start
868 * event. For that reason frames need to be processed in single-shot mode. The
869 * driver needs to wait until a frame is completely processed and written to
870 * memory before restarting the pipeline for the next frame. Pipelined
871 * processing might be possible but requires more testing.
872 *
873 * Stream start must be delayed until buffers are available at both the input
874 * and output. The pipeline must be started in the videobuf queue callback with
875 * the buffers queue spinlock held. The modules subdev set stream operation must
876 * not sleep.
877 */
878static int
879isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
880{
881 struct isp_video_fh *vfh = to_isp_video_fh(fh);
882 struct isp_video *video = video_drvdata(file);
883 enum isp_pipeline_state state;
884 struct isp_pipeline *pipe;
885 struct isp_video *far_end;
886 unsigned long flags;
887 int ret;
888
889 if (type != video->type)
890 return -EINVAL;
891
892 mutex_lock(&video->stream_lock);
893
894 if (video->streaming) {
895 mutex_unlock(&video->stream_lock);
896 return -EBUSY;
897 }
898
899 /* Start streaming on the pipeline. No link touching an entity in the
900 * pipeline can be activated or deactivated once streaming is started.
901 */
902 pipe = video->video.entity.pipe
903 ? to_isp_pipeline(&video->video.entity) : &video->pipe;
904 media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
905
906 /* Verify that the currently configured format matches the output of
907 * the connected subdev.
908 */
909 ret = isp_video_check_format(video, vfh);
910 if (ret < 0)
911 goto error;
912
913 video->bpl_padding = ret;
914 video->bpl_value = vfh->format.fmt.pix.bytesperline;
915
916 /* Find the ISP video node connected at the far end of the pipeline and
917 * update the pipeline.
918 */
919 far_end = isp_video_far_end(video);
920
921 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
922 state = ISP_PIPELINE_STREAM_OUTPUT | ISP_PIPELINE_IDLE_OUTPUT;
923 pipe->input = far_end;
924 pipe->output = video;
925 } else {
926 if (far_end == NULL) {
927 ret = -EPIPE;
928 goto error;
929 }
930
931 state = ISP_PIPELINE_STREAM_INPUT | ISP_PIPELINE_IDLE_INPUT;
932 pipe->input = video;
933 pipe->output = far_end;
934 }
935
Laurent Pinchart4b0ec192011-03-03 10:05:22 -0300936 if (video->isp->pdata->set_constraints)
937 video->isp->pdata->set_constraints(video->isp, true);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300938 pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
939
940 /* Validate the pipeline and update its state. */
941 ret = isp_video_validate_pipeline(pipe);
942 if (ret < 0)
943 goto error;
944
945 spin_lock_irqsave(&pipe->lock, flags);
946 pipe->state &= ~ISP_PIPELINE_STREAM;
947 pipe->state |= state;
948 spin_unlock_irqrestore(&pipe->lock, flags);
949
950 /* Set the maximum time per frame as the value requested by userspace.
951 * This is a soft limit that can be overridden if the hardware doesn't
952 * support the request limit.
953 */
954 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
955 pipe->max_timeperframe = vfh->timeperframe;
956
957 video->queue = &vfh->queue;
958 INIT_LIST_HEAD(&video->dmaqueue);
959 atomic_set(&pipe->frame_number, -1);
960
961 ret = omap3isp_video_queue_streamon(&vfh->queue);
962 if (ret < 0)
963 goto error;
964
965 /* In sensor-to-memory mode, the stream can be started synchronously
966 * to the stream on command. In memory-to-memory mode, it will be
967 * started when buffers are queued on both the input and output.
968 */
969 if (pipe->input == NULL) {
970 ret = omap3isp_pipeline_set_stream(pipe,
971 ISP_PIPELINE_STREAM_CONTINUOUS);
972 if (ret < 0)
973 goto error;
974 spin_lock_irqsave(&video->queue->irqlock, flags);
975 if (list_empty(&video->dmaqueue))
976 video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
977 spin_unlock_irqrestore(&video->queue->irqlock, flags);
978 }
979
980error:
981 if (ret < 0) {
982 omap3isp_video_queue_streamoff(&vfh->queue);
Laurent Pinchart4b0ec192011-03-03 10:05:22 -0300983 if (video->isp->pdata->set_constraints)
984 video->isp->pdata->set_constraints(video->isp, false);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300985 media_entity_pipeline_stop(&video->video.entity);
986 video->queue = NULL;
987 }
988
989 if (!ret)
990 video->streaming = 1;
991
992 mutex_unlock(&video->stream_lock);
993 return ret;
994}
995
996static int
997isp_video_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
998{
999 struct isp_video_fh *vfh = to_isp_video_fh(fh);
1000 struct isp_video *video = video_drvdata(file);
1001 struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
1002 enum isp_pipeline_state state;
1003 unsigned int streaming;
1004 unsigned long flags;
1005
1006 if (type != video->type)
1007 return -EINVAL;
1008
1009 mutex_lock(&video->stream_lock);
1010
1011 /* Make sure we're not streaming yet. */
1012 mutex_lock(&vfh->queue.lock);
1013 streaming = vfh->queue.streaming;
1014 mutex_unlock(&vfh->queue.lock);
1015
1016 if (!streaming)
1017 goto done;
1018
1019 /* Update the pipeline state. */
1020 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1021 state = ISP_PIPELINE_STREAM_OUTPUT
1022 | ISP_PIPELINE_QUEUE_OUTPUT;
1023 else
1024 state = ISP_PIPELINE_STREAM_INPUT
1025 | ISP_PIPELINE_QUEUE_INPUT;
1026
1027 spin_lock_irqsave(&pipe->lock, flags);
1028 pipe->state &= ~state;
1029 spin_unlock_irqrestore(&pipe->lock, flags);
1030
1031 /* Stop the stream. */
1032 omap3isp_pipeline_set_stream(pipe, ISP_PIPELINE_STREAM_STOPPED);
1033 omap3isp_video_queue_streamoff(&vfh->queue);
1034 video->queue = NULL;
1035 video->streaming = 0;
1036
Laurent Pinchart4b0ec192011-03-03 10:05:22 -03001037 if (video->isp->pdata->set_constraints)
1038 video->isp->pdata->set_constraints(video->isp, false);
Laurent Pinchartad614ac2011-02-12 18:05:06 -03001039 media_entity_pipeline_stop(&video->video.entity);
1040
1041done:
1042 mutex_unlock(&video->stream_lock);
1043 return 0;
1044}
1045
1046static int
1047isp_video_enum_input(struct file *file, void *fh, struct v4l2_input *input)
1048{
1049 if (input->index > 0)
1050 return -EINVAL;
1051
1052 strlcpy(input->name, "camera", sizeof(input->name));
1053 input->type = V4L2_INPUT_TYPE_CAMERA;
1054
1055 return 0;
1056}
1057
1058static int
1059isp_video_g_input(struct file *file, void *fh, unsigned int *input)
1060{
1061 *input = 0;
1062
1063 return 0;
1064}
1065
1066static int
1067isp_video_s_input(struct file *file, void *fh, unsigned int input)
1068{
1069 return input == 0 ? 0 : -EINVAL;
1070}
1071
1072static const struct v4l2_ioctl_ops isp_video_ioctl_ops = {
1073 .vidioc_querycap = isp_video_querycap,
1074 .vidioc_g_fmt_vid_cap = isp_video_get_format,
1075 .vidioc_s_fmt_vid_cap = isp_video_set_format,
1076 .vidioc_try_fmt_vid_cap = isp_video_try_format,
1077 .vidioc_g_fmt_vid_out = isp_video_get_format,
1078 .vidioc_s_fmt_vid_out = isp_video_set_format,
1079 .vidioc_try_fmt_vid_out = isp_video_try_format,
1080 .vidioc_cropcap = isp_video_cropcap,
1081 .vidioc_g_crop = isp_video_get_crop,
1082 .vidioc_s_crop = isp_video_set_crop,
1083 .vidioc_g_parm = isp_video_get_param,
1084 .vidioc_s_parm = isp_video_set_param,
1085 .vidioc_reqbufs = isp_video_reqbufs,
1086 .vidioc_querybuf = isp_video_querybuf,
1087 .vidioc_qbuf = isp_video_qbuf,
1088 .vidioc_dqbuf = isp_video_dqbuf,
1089 .vidioc_streamon = isp_video_streamon,
1090 .vidioc_streamoff = isp_video_streamoff,
1091 .vidioc_enum_input = isp_video_enum_input,
1092 .vidioc_g_input = isp_video_g_input,
1093 .vidioc_s_input = isp_video_s_input,
1094};
1095
1096/* -----------------------------------------------------------------------------
1097 * V4L2 file operations
1098 */
1099
1100static int isp_video_open(struct file *file)
1101{
1102 struct isp_video *video = video_drvdata(file);
1103 struct isp_video_fh *handle;
1104 int ret = 0;
1105
1106 handle = kzalloc(sizeof(*handle), GFP_KERNEL);
1107 if (handle == NULL)
1108 return -ENOMEM;
1109
1110 v4l2_fh_init(&handle->vfh, &video->video);
1111 v4l2_fh_add(&handle->vfh);
1112
1113 /* If this is the first user, initialise the pipeline. */
1114 if (omap3isp_get(video->isp) == NULL) {
1115 ret = -EBUSY;
1116 goto done;
1117 }
1118
1119 ret = omap3isp_pipeline_pm_use(&video->video.entity, 1);
1120 if (ret < 0) {
1121 omap3isp_put(video->isp);
1122 goto done;
1123 }
1124
1125 omap3isp_video_queue_init(&handle->queue, video->type,
1126 &isp_video_queue_ops, video->isp->dev,
1127 sizeof(struct isp_buffer));
1128
1129 memset(&handle->format, 0, sizeof(handle->format));
1130 handle->format.type = video->type;
1131 handle->timeperframe.denominator = 1;
1132
1133 handle->video = video;
1134 file->private_data = &handle->vfh;
1135
1136done:
1137 if (ret < 0) {
1138 v4l2_fh_del(&handle->vfh);
1139 kfree(handle);
1140 }
1141
1142 return ret;
1143}
1144
1145static int isp_video_release(struct file *file)
1146{
1147 struct isp_video *video = video_drvdata(file);
1148 struct v4l2_fh *vfh = file->private_data;
1149 struct isp_video_fh *handle = to_isp_video_fh(vfh);
1150
1151 /* Disable streaming and free the buffers queue resources. */
1152 isp_video_streamoff(file, vfh, video->type);
1153
1154 mutex_lock(&handle->queue.lock);
1155 omap3isp_video_queue_cleanup(&handle->queue);
1156 mutex_unlock(&handle->queue.lock);
1157
1158 omap3isp_pipeline_pm_use(&video->video.entity, 0);
1159
1160 /* Release the file handle. */
1161 v4l2_fh_del(vfh);
1162 kfree(handle);
1163 file->private_data = NULL;
1164
1165 omap3isp_put(video->isp);
1166
1167 return 0;
1168}
1169
1170static unsigned int isp_video_poll(struct file *file, poll_table *wait)
1171{
1172 struct isp_video_fh *vfh = to_isp_video_fh(file->private_data);
1173 struct isp_video_queue *queue = &vfh->queue;
1174
1175 return omap3isp_video_queue_poll(queue, file, wait);
1176}
1177
1178static int isp_video_mmap(struct file *file, struct vm_area_struct *vma)
1179{
1180 struct isp_video_fh *vfh = to_isp_video_fh(file->private_data);
1181
1182 return omap3isp_video_queue_mmap(&vfh->queue, vma);
1183}
1184
1185static struct v4l2_file_operations isp_video_fops = {
1186 .owner = THIS_MODULE,
1187 .unlocked_ioctl = video_ioctl2,
1188 .open = isp_video_open,
1189 .release = isp_video_release,
1190 .poll = isp_video_poll,
1191 .mmap = isp_video_mmap,
1192};
1193
1194/* -----------------------------------------------------------------------------
1195 * ISP video core
1196 */
1197
1198static const struct isp_video_operations isp_video_dummy_ops = {
1199};
1200
1201int omap3isp_video_init(struct isp_video *video, const char *name)
1202{
1203 const char *direction;
1204 int ret;
1205
1206 switch (video->type) {
1207 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1208 direction = "output";
1209 video->pad.flags = MEDIA_PAD_FL_SINK;
1210 break;
1211 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1212 direction = "input";
1213 video->pad.flags = MEDIA_PAD_FL_SOURCE;
1214 break;
1215
1216 default:
1217 return -EINVAL;
1218 }
1219
1220 ret = media_entity_init(&video->video.entity, 1, &video->pad, 0);
1221 if (ret < 0)
1222 return ret;
1223
1224 mutex_init(&video->mutex);
1225 atomic_set(&video->active, 0);
1226
1227 spin_lock_init(&video->pipe.lock);
1228 mutex_init(&video->stream_lock);
1229
1230 /* Initialize the video device. */
1231 if (video->ops == NULL)
1232 video->ops = &isp_video_dummy_ops;
1233
1234 video->video.fops = &isp_video_fops;
1235 snprintf(video->video.name, sizeof(video->video.name),
1236 "OMAP3 ISP %s %s", name, direction);
1237 video->video.vfl_type = VFL_TYPE_GRABBER;
1238 video->video.release = video_device_release_empty;
1239 video->video.ioctl_ops = &isp_video_ioctl_ops;
1240 video->pipe.stream_state = ISP_PIPELINE_STREAM_STOPPED;
1241
1242 video_set_drvdata(&video->video, video);
1243
1244 return 0;
1245}
1246
1247int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev)
1248{
1249 int ret;
1250
1251 video->video.v4l2_dev = vdev;
1252
1253 ret = video_register_device(&video->video, VFL_TYPE_GRABBER, -1);
1254 if (ret < 0)
1255 printk(KERN_ERR "%s: could not register video device (%d)\n",
1256 __func__, ret);
1257
1258 return ret;
1259}
1260
1261void omap3isp_video_unregister(struct isp_video *video)
1262{
1263 if (video_is_registered(&video->video)) {
1264 media_entity_cleanup(&video->video.entity);
1265 video_unregister_device(&video->video);
1266 }
1267}