[media] v4l: omap4iss: Enable DMABUF support
[firefly-linux-kernel-4.4.55.git] / drivers / staging / media / omap4iss / iss_video.c
1 /*
2  * TI OMAP4 ISS V4L2 Driver - Generic video node
3  *
4  * Copyright (C) 2012 Texas Instruments, Inc.
5  *
6  * Author: Sergio Aguirre <sergio.a.aguirre@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13
14 #include <asm/cacheflush.h>
15 #include <linux/clk.h>
16 #include <linux/mm.h>
17 #include <linux/pagemap.h>
18 #include <linux/sched.h>
19 #include <linux/slab.h>
20 #include <linux/vmalloc.h>
21 #include <linux/module.h>
22 #include <media/v4l2-dev.h>
23 #include <media/v4l2-ioctl.h>
24
25 #include "iss_video.h"
26 #include "iss.h"
27
28 static unsigned debug;
29 module_param(debug, uint, 0644);
30 MODULE_PARM_DESC(debug, "activates debug info");
31
32 /* -----------------------------------------------------------------------------
33  * Helper functions
34  */
35
36 static struct iss_format_info formats[] = {
37         { MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y8_1X8,
38           MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y8_1X8,
39           V4L2_PIX_FMT_GREY, 8, "Greyscale 8 bpp", },
40         { MEDIA_BUS_FMT_Y10_1X10, MEDIA_BUS_FMT_Y10_1X10,
41           MEDIA_BUS_FMT_Y10_1X10, MEDIA_BUS_FMT_Y8_1X8,
42           V4L2_PIX_FMT_Y10, 10, "Greyscale 10 bpp", },
43         { MEDIA_BUS_FMT_Y12_1X12, MEDIA_BUS_FMT_Y10_1X10,
44           MEDIA_BUS_FMT_Y12_1X12, MEDIA_BUS_FMT_Y8_1X8,
45           V4L2_PIX_FMT_Y12, 12, "Greyscale 12 bpp", },
46         { MEDIA_BUS_FMT_SBGGR8_1X8, MEDIA_BUS_FMT_SBGGR8_1X8,
47           MEDIA_BUS_FMT_SBGGR8_1X8, MEDIA_BUS_FMT_SBGGR8_1X8,
48           V4L2_PIX_FMT_SBGGR8, 8, "BGGR Bayer 8 bpp", },
49         { MEDIA_BUS_FMT_SGBRG8_1X8, MEDIA_BUS_FMT_SGBRG8_1X8,
50           MEDIA_BUS_FMT_SGBRG8_1X8, MEDIA_BUS_FMT_SGBRG8_1X8,
51           V4L2_PIX_FMT_SGBRG8, 8, "GBRG Bayer 8 bpp", },
52         { MEDIA_BUS_FMT_SGRBG8_1X8, MEDIA_BUS_FMT_SGRBG8_1X8,
53           MEDIA_BUS_FMT_SGRBG8_1X8, MEDIA_BUS_FMT_SGRBG8_1X8,
54           V4L2_PIX_FMT_SGRBG8, 8, "GRBG Bayer 8 bpp", },
55         { MEDIA_BUS_FMT_SRGGB8_1X8, MEDIA_BUS_FMT_SRGGB8_1X8,
56           MEDIA_BUS_FMT_SRGGB8_1X8, MEDIA_BUS_FMT_SRGGB8_1X8,
57           V4L2_PIX_FMT_SRGGB8, 8, "RGGB Bayer 8 bpp", },
58         { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8,
59           MEDIA_BUS_FMT_SGRBG10_1X10, 0,
60           V4L2_PIX_FMT_SGRBG10DPCM8, 8, "GRBG Bayer 10 bpp DPCM8",  },
61         { MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR10_1X10,
62           MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR8_1X8,
63           V4L2_PIX_FMT_SBGGR10, 10, "BGGR Bayer 10 bpp", },
64         { MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG10_1X10,
65           MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG8_1X8,
66           V4L2_PIX_FMT_SGBRG10, 10, "GBRG Bayer 10 bpp", },
67         { MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG10_1X10,
68           MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG8_1X8,
69           V4L2_PIX_FMT_SGRBG10, 10, "GRBG Bayer 10 bpp", },
70         { MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB10_1X10,
71           MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB8_1X8,
72           V4L2_PIX_FMT_SRGGB10, 10, "RGGB Bayer 10 bpp", },
73         { MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR10_1X10,
74           MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR8_1X8,
75           V4L2_PIX_FMT_SBGGR12, 12, "BGGR Bayer 12 bpp", },
76         { MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG10_1X10,
77           MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG8_1X8,
78           V4L2_PIX_FMT_SGBRG12, 12, "GBRG Bayer 12 bpp", },
79         { MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG10_1X10,
80           MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG8_1X8,
81           V4L2_PIX_FMT_SGRBG12, 12, "GRBG Bayer 12 bpp", },
82         { MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB10_1X10,
83           MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB8_1X8,
84           V4L2_PIX_FMT_SRGGB12, 12, "RGGB Bayer 12 bpp", },
85         { MEDIA_BUS_FMT_UYVY8_1X16, MEDIA_BUS_FMT_UYVY8_1X16,
86           MEDIA_BUS_FMT_UYVY8_1X16, 0,
87           V4L2_PIX_FMT_UYVY, 16, "YUV 4:2:2 (UYVY)", },
88         { MEDIA_BUS_FMT_YUYV8_1X16, MEDIA_BUS_FMT_YUYV8_1X16,
89           MEDIA_BUS_FMT_YUYV8_1X16, 0,
90           V4L2_PIX_FMT_YUYV, 16, "YUV 4:2:2 (YUYV)", },
91         { MEDIA_BUS_FMT_YUYV8_1_5X8, MEDIA_BUS_FMT_YUYV8_1_5X8,
92           MEDIA_BUS_FMT_YUYV8_1_5X8, 0,
93           V4L2_PIX_FMT_NV12, 8, "YUV 4:2:0 (NV12)", },
94 };
95
96 const struct iss_format_info *
97 omap4iss_video_format_info(u32 code)
98 {
99         unsigned int i;
100
101         for (i = 0; i < ARRAY_SIZE(formats); ++i) {
102                 if (formats[i].code == code)
103                         return &formats[i];
104         }
105
106         return NULL;
107 }
108
109 /*
110  * iss_video_mbus_to_pix - Convert v4l2_mbus_framefmt to v4l2_pix_format
111  * @video: ISS video instance
112  * @mbus: v4l2_mbus_framefmt format (input)
113  * @pix: v4l2_pix_format format (output)
114  *
115  * Fill the output pix structure with information from the input mbus format.
116  * The bytesperline and sizeimage fields are computed from the requested bytes
117  * per line value in the pix format and information from the video instance.
118  *
119  * Return the number of padding bytes at end of line.
120  */
121 static unsigned int iss_video_mbus_to_pix(const struct iss_video *video,
122                                           const struct v4l2_mbus_framefmt *mbus,
123                                           struct v4l2_pix_format *pix)
124 {
125         unsigned int bpl = pix->bytesperline;
126         unsigned int min_bpl;
127         unsigned int i;
128
129         memset(pix, 0, sizeof(*pix));
130         pix->width = mbus->width;
131         pix->height = mbus->height;
132
133         /* Skip the last format in the loop so that it will be selected if no
134          * match is found.
135          */
136         for (i = 0; i < ARRAY_SIZE(formats) - 1; ++i) {
137                 if (formats[i].code == mbus->code)
138                         break;
139         }
140
141         min_bpl = pix->width * ALIGN(formats[i].bpp, 8) / 8;
142
143         /* Clamp the requested bytes per line value. If the maximum bytes per
144          * line value is zero, the module doesn't support user configurable line
145          * sizes. Override the requested value with the minimum in that case.
146          */
147         if (video->bpl_max)
148                 bpl = clamp(bpl, min_bpl, video->bpl_max);
149         else
150                 bpl = min_bpl;
151
152         if (!video->bpl_zero_padding || bpl != min_bpl)
153                 bpl = ALIGN(bpl, video->bpl_alignment);
154
155         pix->pixelformat = formats[i].pixelformat;
156         pix->bytesperline = bpl;
157         pix->sizeimage = pix->bytesperline * pix->height;
158         pix->colorspace = mbus->colorspace;
159         pix->field = mbus->field;
160
161         /* FIXME: Special case for NV12! We should make this nicer... */
162         if (pix->pixelformat == V4L2_PIX_FMT_NV12)
163                 pix->sizeimage += (pix->bytesperline * pix->height) / 2;
164
165         return bpl - min_bpl;
166 }
167
168 static void iss_video_pix_to_mbus(const struct v4l2_pix_format *pix,
169                                   struct v4l2_mbus_framefmt *mbus)
170 {
171         unsigned int i;
172
173         memset(mbus, 0, sizeof(*mbus));
174         mbus->width = pix->width;
175         mbus->height = pix->height;
176
177         for (i = 0; i < ARRAY_SIZE(formats); ++i) {
178                 if (formats[i].pixelformat == pix->pixelformat)
179                         break;
180         }
181
182         if (WARN_ON(i == ARRAY_SIZE(formats)))
183                 return;
184
185         mbus->code = formats[i].code;
186         mbus->colorspace = pix->colorspace;
187         mbus->field = pix->field;
188 }
189
190 static struct v4l2_subdev *
191 iss_video_remote_subdev(struct iss_video *video, u32 *pad)
192 {
193         struct media_pad *remote;
194
195         remote = media_entity_remote_pad(&video->pad);
196
197         if (remote == NULL ||
198             media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
199                 return NULL;
200
201         if (pad)
202                 *pad = remote->index;
203
204         return media_entity_to_v4l2_subdev(remote->entity);
205 }
206
207 /* Return a pointer to the ISS video instance at the far end of the pipeline. */
208 static struct iss_video *
209 iss_video_far_end(struct iss_video *video)
210 {
211         struct media_entity_graph graph;
212         struct media_entity *entity = &video->video.entity;
213         struct media_device *mdev = entity->parent;
214         struct iss_video *far_end = NULL;
215
216         mutex_lock(&mdev->graph_mutex);
217         media_entity_graph_walk_start(&graph, entity);
218
219         while ((entity = media_entity_graph_walk_next(&graph))) {
220                 if (entity == &video->video.entity)
221                         continue;
222
223                 if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
224                         continue;
225
226                 far_end = to_iss_video(media_entity_to_video_device(entity));
227                 if (far_end->type != video->type)
228                         break;
229
230                 far_end = NULL;
231         }
232
233         mutex_unlock(&mdev->graph_mutex);
234         return far_end;
235 }
236
237 static int
238 __iss_video_get_format(struct iss_video *video,
239                        struct v4l2_mbus_framefmt *format)
240 {
241         struct v4l2_subdev_format fmt;
242         struct v4l2_subdev *subdev;
243         u32 pad;
244         int ret;
245
246         subdev = iss_video_remote_subdev(video, &pad);
247         if (subdev == NULL)
248                 return -EINVAL;
249
250         memset(&fmt, 0, sizeof(fmt));
251         fmt.pad = pad;
252         fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
253
254         mutex_lock(&video->mutex);
255         ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
256         mutex_unlock(&video->mutex);
257
258         if (ret)
259                 return ret;
260
261         *format = fmt.format;
262         return 0;
263 }
264
265 static int
266 iss_video_check_format(struct iss_video *video, struct iss_video_fh *vfh)
267 {
268         struct v4l2_mbus_framefmt format;
269         struct v4l2_pix_format pixfmt;
270         int ret;
271
272         ret = __iss_video_get_format(video, &format);
273         if (ret < 0)
274                 return ret;
275
276         pixfmt.bytesperline = 0;
277         ret = iss_video_mbus_to_pix(video, &format, &pixfmt);
278
279         if (vfh->format.fmt.pix.pixelformat != pixfmt.pixelformat ||
280             vfh->format.fmt.pix.height != pixfmt.height ||
281             vfh->format.fmt.pix.width != pixfmt.width ||
282             vfh->format.fmt.pix.bytesperline != pixfmt.bytesperline ||
283             vfh->format.fmt.pix.sizeimage != pixfmt.sizeimage)
284                 return -EINVAL;
285
286         return ret;
287 }
288
289 /* -----------------------------------------------------------------------------
290  * Video queue operations
291  */
292
293 static int iss_video_queue_setup(struct vb2_queue *vq,
294                                  const struct v4l2_format *fmt,
295                                  unsigned int *count, unsigned int *num_planes,
296                                  unsigned int sizes[], void *alloc_ctxs[])
297 {
298         struct iss_video_fh *vfh = vb2_get_drv_priv(vq);
299         struct iss_video *video = vfh->video;
300
301         /* Revisit multi-planar support for NV12 */
302         *num_planes = 1;
303
304         sizes[0] = vfh->format.fmt.pix.sizeimage;
305         if (sizes[0] == 0)
306                 return -EINVAL;
307
308         alloc_ctxs[0] = video->alloc_ctx;
309
310         *count = min(*count, video->capture_mem / PAGE_ALIGN(sizes[0]));
311
312         return 0;
313 }
314
315 static void iss_video_buf_cleanup(struct vb2_buffer *vb)
316 {
317         struct iss_buffer *buffer = container_of(vb, struct iss_buffer, vb);
318
319         if (buffer->iss_addr)
320                 buffer->iss_addr = 0;
321 }
322
323 static int iss_video_buf_prepare(struct vb2_buffer *vb)
324 {
325         struct iss_video_fh *vfh = vb2_get_drv_priv(vb->vb2_queue);
326         struct iss_buffer *buffer = container_of(vb, struct iss_buffer, vb);
327         struct iss_video *video = vfh->video;
328         unsigned long size = vfh->format.fmt.pix.sizeimage;
329         dma_addr_t addr;
330
331         if (vb2_plane_size(vb, 0) < size)
332                 return -ENOBUFS;
333
334         addr = vb2_dma_contig_plane_dma_addr(vb, 0);
335         if (!IS_ALIGNED(addr, 32)) {
336                 dev_dbg(video->iss->dev,
337                         "Buffer address must be aligned to 32 bytes boundary.\n");
338                 return -EINVAL;
339         }
340
341         vb2_set_plane_payload(vb, 0, size);
342         buffer->iss_addr = addr;
343         return 0;
344 }
345
346 static void iss_video_buf_queue(struct vb2_buffer *vb)
347 {
348         struct iss_video_fh *vfh = vb2_get_drv_priv(vb->vb2_queue);
349         struct iss_video *video = vfh->video;
350         struct iss_buffer *buffer = container_of(vb, struct iss_buffer, vb);
351         struct iss_pipeline *pipe = to_iss_pipeline(&video->video.entity);
352         unsigned long flags;
353         bool empty;
354
355         spin_lock_irqsave(&video->qlock, flags);
356
357         /* Mark the buffer is faulty and give it back to the queue immediately
358          * if the video node has registered an error. vb2 will perform the same
359          * check when preparing the buffer, but that is inherently racy, so we
360          * need to handle the race condition with an authoritative check here.
361          */
362         if (unlikely(video->error)) {
363                 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
364                 spin_unlock_irqrestore(&video->qlock, flags);
365                 return;
366         }
367
368         empty = list_empty(&video->dmaqueue);
369         list_add_tail(&buffer->list, &video->dmaqueue);
370
371         spin_unlock_irqrestore(&video->qlock, flags);
372
373         if (empty) {
374                 enum iss_pipeline_state state;
375                 unsigned int start;
376
377                 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
378                         state = ISS_PIPELINE_QUEUE_OUTPUT;
379                 else
380                         state = ISS_PIPELINE_QUEUE_INPUT;
381
382                 spin_lock_irqsave(&pipe->lock, flags);
383                 pipe->state |= state;
384                 video->ops->queue(video, buffer);
385                 video->dmaqueue_flags |= ISS_VIDEO_DMAQUEUE_QUEUED;
386
387                 start = iss_pipeline_ready(pipe);
388                 if (start)
389                         pipe->state |= ISS_PIPELINE_STREAM;
390                 spin_unlock_irqrestore(&pipe->lock, flags);
391
392                 if (start)
393                         omap4iss_pipeline_set_stream(pipe,
394                                                 ISS_PIPELINE_STREAM_SINGLESHOT);
395         }
396 }
397
398 static const struct vb2_ops iss_video_vb2ops = {
399         .queue_setup    = iss_video_queue_setup,
400         .buf_prepare    = iss_video_buf_prepare,
401         .buf_queue      = iss_video_buf_queue,
402         .buf_cleanup    = iss_video_buf_cleanup,
403 };
404
405 /*
406  * omap4iss_video_buffer_next - Complete the current buffer and return the next
407  * @video: ISS video object
408  *
409  * Remove the current video buffer from the DMA queue and fill its timestamp,
410  * field count and state fields before waking up its completion handler.
411  *
412  * For capture video nodes, the buffer state is set to VB2_BUF_STATE_DONE if no
413  * error has been flagged in the pipeline, or to VB2_BUF_STATE_ERROR otherwise.
414  *
415  * The DMA queue is expected to contain at least one buffer.
416  *
417  * Return a pointer to the next buffer in the DMA queue, or NULL if the queue is
418  * empty.
419  */
420 struct iss_buffer *omap4iss_video_buffer_next(struct iss_video *video)
421 {
422         struct iss_pipeline *pipe = to_iss_pipeline(&video->video.entity);
423         enum iss_pipeline_state state;
424         struct iss_buffer *buf;
425         unsigned long flags;
426         struct timespec ts;
427
428         spin_lock_irqsave(&video->qlock, flags);
429         if (WARN_ON(list_empty(&video->dmaqueue))) {
430                 spin_unlock_irqrestore(&video->qlock, flags);
431                 return NULL;
432         }
433
434         buf = list_first_entry(&video->dmaqueue, struct iss_buffer,
435                                list);
436         list_del(&buf->list);
437         spin_unlock_irqrestore(&video->qlock, flags);
438
439         ktime_get_ts(&ts);
440         buf->vb.v4l2_buf.timestamp.tv_sec = ts.tv_sec;
441         buf->vb.v4l2_buf.timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
442
443         /* Do frame number propagation only if this is the output video node.
444          * Frame number either comes from the CSI receivers or it gets
445          * incremented here if H3A is not active.
446          * Note: There is no guarantee that the output buffer will finish
447          * first, so the input number might lag behind by 1 in some cases.
448          */
449         if (video == pipe->output && !pipe->do_propagation)
450                 buf->vb.v4l2_buf.sequence =
451                         atomic_inc_return(&pipe->frame_number);
452         else
453                 buf->vb.v4l2_buf.sequence = atomic_read(&pipe->frame_number);
454
455         vb2_buffer_done(&buf->vb, pipe->error ?
456                         VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
457         pipe->error = false;
458
459         spin_lock_irqsave(&video->qlock, flags);
460         if (list_empty(&video->dmaqueue)) {
461                 spin_unlock_irqrestore(&video->qlock, flags);
462                 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
463                         state = ISS_PIPELINE_QUEUE_OUTPUT
464                               | ISS_PIPELINE_STREAM;
465                 else
466                         state = ISS_PIPELINE_QUEUE_INPUT
467                               | ISS_PIPELINE_STREAM;
468
469                 spin_lock_irqsave(&pipe->lock, flags);
470                 pipe->state &= ~state;
471                 if (video->pipe.stream_state == ISS_PIPELINE_STREAM_CONTINUOUS)
472                         video->dmaqueue_flags |= ISS_VIDEO_DMAQUEUE_UNDERRUN;
473                 spin_unlock_irqrestore(&pipe->lock, flags);
474                 return NULL;
475         }
476
477         if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->input != NULL) {
478                 spin_lock(&pipe->lock);
479                 pipe->state &= ~ISS_PIPELINE_STREAM;
480                 spin_unlock(&pipe->lock);
481         }
482
483         buf = list_first_entry(&video->dmaqueue, struct iss_buffer,
484                                list);
485         spin_unlock_irqrestore(&video->qlock, flags);
486         buf->vb.state = VB2_BUF_STATE_ACTIVE;
487         return buf;
488 }
489
490 /*
491  * omap4iss_video_cancel_stream - Cancel stream on a video node
492  * @video: ISS video object
493  *
494  * Cancelling a stream mark all buffers on the video node as erroneous and makes
495  * sure no new buffer can be queued.
496  */
497 void omap4iss_video_cancel_stream(struct iss_video *video)
498 {
499         unsigned long flags;
500
501         spin_lock_irqsave(&video->qlock, flags);
502
503         while (!list_empty(&video->dmaqueue)) {
504                 struct iss_buffer *buf;
505
506                 buf = list_first_entry(&video->dmaqueue, struct iss_buffer,
507                                        list);
508                 list_del(&buf->list);
509                 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
510         }
511
512         vb2_queue_error(video->queue);
513         video->error = true;
514
515         spin_unlock_irqrestore(&video->qlock, flags);
516 }
517
518 /* -----------------------------------------------------------------------------
519  * V4L2 ioctls
520  */
521
522 static int
523 iss_video_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
524 {
525         struct iss_video *video = video_drvdata(file);
526
527         strlcpy(cap->driver, ISS_VIDEO_DRIVER_NAME, sizeof(cap->driver));
528         strlcpy(cap->card, video->video.name, sizeof(cap->card));
529         strlcpy(cap->bus_info, "media", sizeof(cap->bus_info));
530
531         if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
532                 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
533         else
534                 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
535
536         cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
537                           | V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT;
538
539         return 0;
540 }
541
542 static int
543 iss_video_enum_format(struct file *file, void *fh, struct v4l2_fmtdesc *f)
544 {
545         struct iss_video *video = video_drvdata(file);
546         struct v4l2_mbus_framefmt format;
547         unsigned int index = f->index;
548         unsigned int i;
549         int ret;
550
551         if (f->type != video->type)
552                 return -EINVAL;
553
554         ret = __iss_video_get_format(video, &format);
555         if (ret < 0)
556                 return ret;
557
558         for (i = 0; i < ARRAY_SIZE(formats); ++i) {
559                 const struct iss_format_info *info = &formats[i];
560
561                 if (format.code != info->code)
562                         continue;
563
564                 if (index == 0) {
565                         f->pixelformat = info->pixelformat;
566                         strlcpy(f->description, info->description,
567                                 sizeof(f->description));
568                         return 0;
569                 }
570
571                 index--;
572         }
573
574         return -EINVAL;
575 }
576
577 static int
578 iss_video_get_format(struct file *file, void *fh, struct v4l2_format *format)
579 {
580         struct iss_video_fh *vfh = to_iss_video_fh(fh);
581         struct iss_video *video = video_drvdata(file);
582
583         if (format->type != video->type)
584                 return -EINVAL;
585
586         mutex_lock(&video->mutex);
587         *format = vfh->format;
588         mutex_unlock(&video->mutex);
589
590         return 0;
591 }
592
593 static int
594 iss_video_set_format(struct file *file, void *fh, struct v4l2_format *format)
595 {
596         struct iss_video_fh *vfh = to_iss_video_fh(fh);
597         struct iss_video *video = video_drvdata(file);
598         struct v4l2_mbus_framefmt fmt;
599
600         if (format->type != video->type)
601                 return -EINVAL;
602
603         mutex_lock(&video->mutex);
604
605         /* Fill the bytesperline and sizeimage fields by converting to media bus
606          * format and back to pixel format.
607          */
608         iss_video_pix_to_mbus(&format->fmt.pix, &fmt);
609         iss_video_mbus_to_pix(video, &fmt, &format->fmt.pix);
610
611         vfh->format = *format;
612
613         mutex_unlock(&video->mutex);
614         return 0;
615 }
616
617 static int
618 iss_video_try_format(struct file *file, void *fh, struct v4l2_format *format)
619 {
620         struct iss_video *video = video_drvdata(file);
621         struct v4l2_subdev_format fmt;
622         struct v4l2_subdev *subdev;
623         u32 pad;
624         int ret;
625
626         if (format->type != video->type)
627                 return -EINVAL;
628
629         subdev = iss_video_remote_subdev(video, &pad);
630         if (subdev == NULL)
631                 return -EINVAL;
632
633         iss_video_pix_to_mbus(&format->fmt.pix, &fmt.format);
634
635         fmt.pad = pad;
636         fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
637         ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
638         if (ret)
639                 return ret;
640
641         iss_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix);
642         return 0;
643 }
644
645 static int
646 iss_video_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap)
647 {
648         struct iss_video *video = video_drvdata(file);
649         struct v4l2_subdev *subdev;
650         int ret;
651
652         subdev = iss_video_remote_subdev(video, NULL);
653         if (subdev == NULL)
654                 return -EINVAL;
655
656         mutex_lock(&video->mutex);
657         ret = v4l2_subdev_call(subdev, video, cropcap, cropcap);
658         mutex_unlock(&video->mutex);
659
660         return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
661 }
662
663 static int
664 iss_video_get_crop(struct file *file, void *fh, struct v4l2_crop *crop)
665 {
666         struct iss_video *video = video_drvdata(file);
667         struct v4l2_subdev_format format;
668         struct v4l2_subdev *subdev;
669         u32 pad;
670         int ret;
671
672         subdev = iss_video_remote_subdev(video, &pad);
673         if (subdev == NULL)
674                 return -EINVAL;
675
676         /* Try the get crop operation first and fallback to get format if not
677          * implemented.
678          */
679         ret = v4l2_subdev_call(subdev, video, g_crop, crop);
680         if (ret != -ENOIOCTLCMD)
681                 return ret;
682
683         format.pad = pad;
684         format.which = V4L2_SUBDEV_FORMAT_ACTIVE;
685         ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &format);
686         if (ret < 0)
687                 return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
688
689         crop->c.left = 0;
690         crop->c.top = 0;
691         crop->c.width = format.format.width;
692         crop->c.height = format.format.height;
693
694         return 0;
695 }
696
697 static int
698 iss_video_set_crop(struct file *file, void *fh, const struct v4l2_crop *crop)
699 {
700         struct iss_video *video = video_drvdata(file);
701         struct v4l2_subdev *subdev;
702         int ret;
703
704         subdev = iss_video_remote_subdev(video, NULL);
705         if (subdev == NULL)
706                 return -EINVAL;
707
708         mutex_lock(&video->mutex);
709         ret = v4l2_subdev_call(subdev, video, s_crop, crop);
710         mutex_unlock(&video->mutex);
711
712         return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
713 }
714
715 static int
716 iss_video_get_param(struct file *file, void *fh, struct v4l2_streamparm *a)
717 {
718         struct iss_video_fh *vfh = to_iss_video_fh(fh);
719         struct iss_video *video = video_drvdata(file);
720
721         if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
722             video->type != a->type)
723                 return -EINVAL;
724
725         memset(a, 0, sizeof(*a));
726         a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
727         a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
728         a->parm.output.timeperframe = vfh->timeperframe;
729
730         return 0;
731 }
732
733 static int
734 iss_video_set_param(struct file *file, void *fh, struct v4l2_streamparm *a)
735 {
736         struct iss_video_fh *vfh = to_iss_video_fh(fh);
737         struct iss_video *video = video_drvdata(file);
738
739         if (video->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
740             video->type != a->type)
741                 return -EINVAL;
742
743         if (a->parm.output.timeperframe.denominator == 0)
744                 a->parm.output.timeperframe.denominator = 1;
745
746         vfh->timeperframe = a->parm.output.timeperframe;
747
748         return 0;
749 }
750
751 static int
752 iss_video_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *rb)
753 {
754         struct iss_video_fh *vfh = to_iss_video_fh(fh);
755
756         return vb2_reqbufs(&vfh->queue, rb);
757 }
758
759 static int
760 iss_video_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
761 {
762         struct iss_video_fh *vfh = to_iss_video_fh(fh);
763
764         return vb2_querybuf(&vfh->queue, b);
765 }
766
767 static int
768 iss_video_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
769 {
770         struct iss_video_fh *vfh = to_iss_video_fh(fh);
771
772         return vb2_qbuf(&vfh->queue, b);
773 }
774
775 static int
776 iss_video_expbuf(struct file *file, void *fh, struct v4l2_exportbuffer *e)
777 {
778         struct iss_video_fh *vfh = to_iss_video_fh(fh);
779
780         return vb2_expbuf(&vfh->queue, e);
781 }
782
783 static int
784 iss_video_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
785 {
786         struct iss_video_fh *vfh = to_iss_video_fh(fh);
787
788         return vb2_dqbuf(&vfh->queue, b, file->f_flags & O_NONBLOCK);
789 }
790
791 /*
792  * Stream management
793  *
794  * Every ISS pipeline has a single input and a single output. The input can be
795  * either a sensor or a video node. The output is always a video node.
796  *
797  * As every pipeline has an output video node, the ISS video objects at the
798  * pipeline output stores the pipeline state. It tracks the streaming state of
799  * both the input and output, as well as the availability of buffers.
800  *
801  * In sensor-to-memory mode, frames are always available at the pipeline input.
802  * Starting the sensor usually requires I2C transfers and must be done in
803  * interruptible context. The pipeline is started and stopped synchronously
804  * to the stream on/off commands. All modules in the pipeline will get their
805  * subdev set stream handler called. The module at the end of the pipeline must
806  * delay starting the hardware until buffers are available at its output.
807  *
808  * In memory-to-memory mode, starting/stopping the stream requires
809  * synchronization between the input and output. ISS modules can't be stopped
810  * in the middle of a frame, and at least some of the modules seem to become
811  * busy as soon as they're started, even if they don't receive a frame start
812  * event. For that reason frames need to be processed in single-shot mode. The
813  * driver needs to wait until a frame is completely processed and written to
814  * memory before restarting the pipeline for the next frame. Pipelined
815  * processing might be possible but requires more testing.
816  *
817  * Stream start must be delayed until buffers are available at both the input
818  * and output. The pipeline must be started in the videobuf queue callback with
819  * the buffers queue spinlock held. The modules subdev set stream operation must
820  * not sleep.
821  */
822 static int
823 iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
824 {
825         struct iss_video_fh *vfh = to_iss_video_fh(fh);
826         struct iss_video *video = video_drvdata(file);
827         struct media_entity_graph graph;
828         struct media_entity *entity;
829         enum iss_pipeline_state state;
830         struct iss_pipeline *pipe;
831         struct iss_video *far_end;
832         unsigned long flags;
833         int ret;
834
835         if (type != video->type)
836                 return -EINVAL;
837
838         mutex_lock(&video->stream_lock);
839
840         /* Start streaming on the pipeline. No link touching an entity in the
841          * pipeline can be activated or deactivated once streaming is started.
842          */
843         pipe = video->video.entity.pipe
844              ? to_iss_pipeline(&video->video.entity) : &video->pipe;
845         pipe->external = NULL;
846         pipe->external_rate = 0;
847         pipe->external_bpp = 0;
848         pipe->entities = 0;
849
850         if (video->iss->pdata->set_constraints)
851                 video->iss->pdata->set_constraints(video->iss, true);
852
853         ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
854         if (ret < 0)
855                 goto err_media_entity_pipeline_start;
856
857         entity = &video->video.entity;
858         media_entity_graph_walk_start(&graph, entity);
859         while ((entity = media_entity_graph_walk_next(&graph)))
860                 pipe->entities |= 1 << entity->id;
861
862         /* Verify that the currently configured format matches the output of
863          * the connected subdev.
864          */
865         ret = iss_video_check_format(video, vfh);
866         if (ret < 0)
867                 goto err_iss_video_check_format;
868
869         video->bpl_padding = ret;
870         video->bpl_value = vfh->format.fmt.pix.bytesperline;
871
872         /* Find the ISS video node connected at the far end of the pipeline and
873          * update the pipeline.
874          */
875         far_end = iss_video_far_end(video);
876
877         if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
878                 state = ISS_PIPELINE_STREAM_OUTPUT | ISS_PIPELINE_IDLE_OUTPUT;
879                 pipe->input = far_end;
880                 pipe->output = video;
881         } else {
882                 if (far_end == NULL) {
883                         ret = -EPIPE;
884                         goto err_iss_video_check_format;
885                 }
886
887                 state = ISS_PIPELINE_STREAM_INPUT | ISS_PIPELINE_IDLE_INPUT;
888                 pipe->input = video;
889                 pipe->output = far_end;
890         }
891
892         spin_lock_irqsave(&pipe->lock, flags);
893         pipe->state &= ~ISS_PIPELINE_STREAM;
894         pipe->state |= state;
895         spin_unlock_irqrestore(&pipe->lock, flags);
896
897         /* Set the maximum time per frame as the value requested by userspace.
898          * This is a soft limit that can be overridden if the hardware doesn't
899          * support the request limit.
900          */
901         if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
902                 pipe->max_timeperframe = vfh->timeperframe;
903
904         video->queue = &vfh->queue;
905         INIT_LIST_HEAD(&video->dmaqueue);
906         video->error = false;
907         atomic_set(&pipe->frame_number, -1);
908
909         ret = vb2_streamon(&vfh->queue, type);
910         if (ret < 0)
911                 goto err_iss_video_check_format;
912
913         /* In sensor-to-memory mode, the stream can be started synchronously
914          * to the stream on command. In memory-to-memory mode, it will be
915          * started when buffers are queued on both the input and output.
916          */
917         if (pipe->input == NULL) {
918                 unsigned long flags;
919
920                 ret = omap4iss_pipeline_set_stream(pipe,
921                                               ISS_PIPELINE_STREAM_CONTINUOUS);
922                 if (ret < 0)
923                         goto err_omap4iss_set_stream;
924                 spin_lock_irqsave(&video->qlock, flags);
925                 if (list_empty(&video->dmaqueue))
926                         video->dmaqueue_flags |= ISS_VIDEO_DMAQUEUE_UNDERRUN;
927                 spin_unlock_irqrestore(&video->qlock, flags);
928         }
929
930         mutex_unlock(&video->stream_lock);
931         return 0;
932
933 err_omap4iss_set_stream:
934         vb2_streamoff(&vfh->queue, type);
935 err_iss_video_check_format:
936         media_entity_pipeline_stop(&video->video.entity);
937 err_media_entity_pipeline_start:
938         if (video->iss->pdata->set_constraints)
939                 video->iss->pdata->set_constraints(video->iss, false);
940         video->queue = NULL;
941
942         mutex_unlock(&video->stream_lock);
943         return ret;
944 }
945
946 static int
947 iss_video_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
948 {
949         struct iss_video_fh *vfh = to_iss_video_fh(fh);
950         struct iss_video *video = video_drvdata(file);
951         struct iss_pipeline *pipe = to_iss_pipeline(&video->video.entity);
952         enum iss_pipeline_state state;
953         unsigned long flags;
954
955         if (type != video->type)
956                 return -EINVAL;
957
958         mutex_lock(&video->stream_lock);
959
960         if (!vb2_is_streaming(&vfh->queue))
961                 goto done;
962
963         /* Update the pipeline state. */
964         if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
965                 state = ISS_PIPELINE_STREAM_OUTPUT
966                       | ISS_PIPELINE_QUEUE_OUTPUT;
967         else
968                 state = ISS_PIPELINE_STREAM_INPUT
969                       | ISS_PIPELINE_QUEUE_INPUT;
970
971         spin_lock_irqsave(&pipe->lock, flags);
972         pipe->state &= ~state;
973         spin_unlock_irqrestore(&pipe->lock, flags);
974
975         /* Stop the stream. */
976         omap4iss_pipeline_set_stream(pipe, ISS_PIPELINE_STREAM_STOPPED);
977         vb2_streamoff(&vfh->queue, type);
978         video->queue = NULL;
979
980         if (video->iss->pdata->set_constraints)
981                 video->iss->pdata->set_constraints(video->iss, false);
982         media_entity_pipeline_stop(&video->video.entity);
983
984 done:
985         mutex_unlock(&video->stream_lock);
986         return 0;
987 }
988
989 static int
990 iss_video_enum_input(struct file *file, void *fh, struct v4l2_input *input)
991 {
992         if (input->index > 0)
993                 return -EINVAL;
994
995         strlcpy(input->name, "camera", sizeof(input->name));
996         input->type = V4L2_INPUT_TYPE_CAMERA;
997
998         return 0;
999 }
1000
1001 static int
1002 iss_video_g_input(struct file *file, void *fh, unsigned int *input)
1003 {
1004         *input = 0;
1005
1006         return 0;
1007 }
1008
1009 static int
1010 iss_video_s_input(struct file *file, void *fh, unsigned int input)
1011 {
1012         return input == 0 ? 0 : -EINVAL;
1013 }
1014
1015 static const struct v4l2_ioctl_ops iss_video_ioctl_ops = {
1016         .vidioc_querycap                = iss_video_querycap,
1017         .vidioc_enum_fmt_vid_cap        = iss_video_enum_format,
1018         .vidioc_g_fmt_vid_cap           = iss_video_get_format,
1019         .vidioc_s_fmt_vid_cap           = iss_video_set_format,
1020         .vidioc_try_fmt_vid_cap         = iss_video_try_format,
1021         .vidioc_g_fmt_vid_out           = iss_video_get_format,
1022         .vidioc_s_fmt_vid_out           = iss_video_set_format,
1023         .vidioc_try_fmt_vid_out         = iss_video_try_format,
1024         .vidioc_cropcap                 = iss_video_cropcap,
1025         .vidioc_g_crop                  = iss_video_get_crop,
1026         .vidioc_s_crop                  = iss_video_set_crop,
1027         .vidioc_g_parm                  = iss_video_get_param,
1028         .vidioc_s_parm                  = iss_video_set_param,
1029         .vidioc_reqbufs                 = iss_video_reqbufs,
1030         .vidioc_querybuf                = iss_video_querybuf,
1031         .vidioc_qbuf                    = iss_video_qbuf,
1032         .vidioc_expbuf                  = iss_video_expbuf,
1033         .vidioc_dqbuf                   = iss_video_dqbuf,
1034         .vidioc_streamon                = iss_video_streamon,
1035         .vidioc_streamoff               = iss_video_streamoff,
1036         .vidioc_enum_input              = iss_video_enum_input,
1037         .vidioc_g_input                 = iss_video_g_input,
1038         .vidioc_s_input                 = iss_video_s_input,
1039 };
1040
1041 /* -----------------------------------------------------------------------------
1042  * V4L2 file operations
1043  */
1044
1045 static int iss_video_open(struct file *file)
1046 {
1047         struct iss_video *video = video_drvdata(file);
1048         struct iss_video_fh *handle;
1049         struct vb2_queue *q;
1050         int ret = 0;
1051
1052         handle = kzalloc(sizeof(*handle), GFP_KERNEL);
1053         if (handle == NULL)
1054                 return -ENOMEM;
1055
1056         video->video.debug = debug;
1057
1058         v4l2_fh_init(&handle->vfh, &video->video);
1059         v4l2_fh_add(&handle->vfh);
1060
1061         /* If this is the first user, initialise the pipeline. */
1062         if (omap4iss_get(video->iss) == NULL) {
1063                 ret = -EBUSY;
1064                 goto done;
1065         }
1066
1067         ret = omap4iss_pipeline_pm_use(&video->video.entity, 1);
1068         if (ret < 0) {
1069                 omap4iss_put(video->iss);
1070                 goto done;
1071         }
1072
1073         video->alloc_ctx = vb2_dma_contig_init_ctx(video->iss->dev);
1074         if (IS_ERR(video->alloc_ctx)) {
1075                 ret = PTR_ERR(video->alloc_ctx);
1076                 omap4iss_put(video->iss);
1077                 goto done;
1078         }
1079
1080         q = &handle->queue;
1081
1082         q->type = video->type;
1083         q->io_modes = VB2_MMAP | VB2_DMABUF;
1084         q->drv_priv = handle;
1085         q->ops = &iss_video_vb2ops;
1086         q->mem_ops = &vb2_dma_contig_memops;
1087         q->buf_struct_size = sizeof(struct iss_buffer);
1088         q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1089
1090         ret = vb2_queue_init(q);
1091         if (ret) {
1092                 omap4iss_put(video->iss);
1093                 goto done;
1094         }
1095
1096         memset(&handle->format, 0, sizeof(handle->format));
1097         handle->format.type = video->type;
1098         handle->timeperframe.denominator = 1;
1099
1100         handle->video = video;
1101         file->private_data = &handle->vfh;
1102
1103 done:
1104         if (ret < 0) {
1105                 v4l2_fh_del(&handle->vfh);
1106                 kfree(handle);
1107         }
1108
1109         return ret;
1110 }
1111
1112 static int iss_video_release(struct file *file)
1113 {
1114         struct iss_video *video = video_drvdata(file);
1115         struct v4l2_fh *vfh = file->private_data;
1116         struct iss_video_fh *handle = to_iss_video_fh(vfh);
1117
1118         /* Disable streaming and free the buffers queue resources. */
1119         iss_video_streamoff(file, vfh, video->type);
1120
1121         omap4iss_pipeline_pm_use(&video->video.entity, 0);
1122
1123         /* Release the videobuf2 queue */
1124         vb2_queue_release(&handle->queue);
1125
1126         /* Release the file handle. */
1127         v4l2_fh_del(vfh);
1128         kfree(handle);
1129         file->private_data = NULL;
1130
1131         omap4iss_put(video->iss);
1132
1133         return 0;
1134 }
1135
1136 static unsigned int iss_video_poll(struct file *file, poll_table *wait)
1137 {
1138         struct iss_video_fh *vfh = to_iss_video_fh(file->private_data);
1139
1140         return vb2_poll(&vfh->queue, file, wait);
1141 }
1142
1143 static int iss_video_mmap(struct file *file, struct vm_area_struct *vma)
1144 {
1145         struct iss_video_fh *vfh = to_iss_video_fh(file->private_data);
1146
1147         return vb2_mmap(&vfh->queue, vma);
1148 }
1149
1150 static struct v4l2_file_operations iss_video_fops = {
1151         .owner = THIS_MODULE,
1152         .unlocked_ioctl = video_ioctl2,
1153         .open = iss_video_open,
1154         .release = iss_video_release,
1155         .poll = iss_video_poll,
1156         .mmap = iss_video_mmap,
1157 };
1158
1159 /* -----------------------------------------------------------------------------
1160  * ISS video core
1161  */
1162
1163 static const struct iss_video_operations iss_video_dummy_ops = {
1164 };
1165
1166 int omap4iss_video_init(struct iss_video *video, const char *name)
1167 {
1168         const char *direction;
1169         int ret;
1170
1171         switch (video->type) {
1172         case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1173                 direction = "output";
1174                 video->pad.flags = MEDIA_PAD_FL_SINK;
1175                 break;
1176         case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1177                 direction = "input";
1178                 video->pad.flags = MEDIA_PAD_FL_SOURCE;
1179                 break;
1180
1181         default:
1182                 return -EINVAL;
1183         }
1184
1185         ret = media_entity_init(&video->video.entity, 1, &video->pad, 0);
1186         if (ret < 0)
1187                 return ret;
1188
1189         spin_lock_init(&video->qlock);
1190         mutex_init(&video->mutex);
1191         atomic_set(&video->active, 0);
1192
1193         spin_lock_init(&video->pipe.lock);
1194         mutex_init(&video->stream_lock);
1195
1196         /* Initialize the video device. */
1197         if (video->ops == NULL)
1198                 video->ops = &iss_video_dummy_ops;
1199
1200         video->video.fops = &iss_video_fops;
1201         snprintf(video->video.name, sizeof(video->video.name),
1202                  "OMAP4 ISS %s %s", name, direction);
1203         video->video.vfl_type = VFL_TYPE_GRABBER;
1204         video->video.release = video_device_release_empty;
1205         video->video.ioctl_ops = &iss_video_ioctl_ops;
1206         video->pipe.stream_state = ISS_PIPELINE_STREAM_STOPPED;
1207
1208         video_set_drvdata(&video->video, video);
1209
1210         return 0;
1211 }
1212
1213 void omap4iss_video_cleanup(struct iss_video *video)
1214 {
1215         media_entity_cleanup(&video->video.entity);
1216         mutex_destroy(&video->stream_lock);
1217         mutex_destroy(&video->mutex);
1218 }
1219
1220 int omap4iss_video_register(struct iss_video *video, struct v4l2_device *vdev)
1221 {
1222         int ret;
1223
1224         video->video.v4l2_dev = vdev;
1225
1226         ret = video_register_device(&video->video, VFL_TYPE_GRABBER, -1);
1227         if (ret < 0)
1228                 dev_err(video->iss->dev,
1229                         "%s: could not register video device (%d)\n",
1230                         __func__, ret);
1231
1232         return ret;
1233 }
1234
1235 void omap4iss_video_unregister(struct iss_video *video)
1236 {
1237         video_unregister_device(&video->video);
1238 }