]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00234387 mx6sl: csi/v4l2: add V4L2_MEMORY_USERPTR support
authorRobby Cai <R63905@freescale.com>
Tue, 20 Nov 2012 08:52:04 +0000 (16:52 +0800)
committerLothar Waßmann <LW@KARO-electronics.de>
Fri, 24 May 2013 06:35:45 +0000 (08:35 +0200)
Add V4L2_MEMORY_USERPTR support for csi v4l2 capture
Support V4L2_MEMORY_USERPTR and V4L2_MEMORY_MMAP now

Signed-off-by: Robby Cai <R63905@freescale.com>
drivers/media/video/mxc/capture/csi_v4l2_capture.c

index d8a956c557eb2d14234ebe168d8737195c9d8a29..54b073e6970b2efb0fbd3a8252287a6f171aec81 100644 (file)
@@ -449,6 +449,36 @@ static int csi_v4l2_buffer_status(cam_data *cam, struct v4l2_buffer *buf)
        return 0;
 }
 
+static int csi_v4l2_release_bufs(cam_data *cam)
+{
+       pr_debug("In MVC:csi_v4l2_release_bufs\n");
+       return 0;
+}
+
+static int csi_v4l2_prepare_bufs(cam_data *cam, struct v4l2_buffer *buf)
+{
+       pr_debug("In MVC:csi_v4l2_prepare_bufs\n");
+
+       if (buf->index < 0 || buf->index >= FRAME_NUM || buf->length <
+                       PAGE_ALIGN(cam->v2f.fmt.pix.sizeimage)) {
+               pr_err("ERROR: v4l2 capture: csi_v4l2_prepare_bufs buffers "
+                       "not allocated,index=%d, length=%d\n", buf->index,
+                       buf->length);
+               return -EINVAL;
+       }
+
+       cam->frame[buf->index].buffer.index = buf->index;
+       cam->frame[buf->index].buffer.flags = V4L2_BUF_FLAG_MAPPED;
+       cam->frame[buf->index].buffer.length = buf->length;
+       cam->frame[buf->index].buffer.m.offset = cam->frame[buf->index].paddress
+               = buf->m.offset;
+       cam->frame[buf->index].buffer.type = buf->type;
+       cam->frame[buf->index].buffer.memory = V4L2_MEMORY_USERPTR;
+       cam->frame[buf->index].index = buf->index;
+
+       return 0;
+}
+
 /*!
  * Indicates whether the palette is supported.
  *
@@ -1164,8 +1194,7 @@ static long csi_v4l_do_ioctl(struct file *file,
                        req->count = FRAME_NUM;
                }
 
-               if ((req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
-                               (req->memory != V4L2_MEMORY_MMAP)) {
+               if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
                        pr_err("ERROR: v4l2 capture: VIDIOC_REQBUFS: "
                                        "wrong buffer type\n");
                        retval = -EINVAL;
@@ -1173,12 +1202,14 @@ static long csi_v4l_do_ioctl(struct file *file,
                }
 
                csi_streamoff(cam);
-               csi_free_frame_buf(cam);
+               if (req->memory & V4L2_MEMORY_MMAP)
+                       csi_free_frame_buf(cam);
                cam->skip_frame = 0;
                INIT_LIST_HEAD(&cam->ready_q);
                INIT_LIST_HEAD(&cam->working_q);
                INIT_LIST_HEAD(&cam->done_q);
-               retval = csi_allocate_frame_buf(cam, req->count);
+               if (req->memory & V4L2_MEMORY_MMAP)
+                       retval = csi_allocate_frame_buf(cam, req->count);
                break;
        }
 
@@ -1192,9 +1223,19 @@ static long csi_v4l_do_ioctl(struct file *file,
                        break;
                }
 
-               memset(buf, 0, sizeof(buf));
-               buf->index = index;
-               retval = csi_v4l2_buffer_status(cam, buf);
+               if (buf->memory & V4L2_MEMORY_MMAP) {
+                       memset(buf, 0, sizeof(buf));
+                       buf->index = index;
+               }
+
+               down(&cam->param_lock);
+               if (buf->memory & V4L2_MEMORY_USERPTR) {
+                       csi_v4l2_release_bufs(cam);
+                       retval = csi_v4l2_prepare_bufs(cam, buf);
+               }
+               if (buf->memory & V4L2_MEMORY_MMAP)
+                       retval = csi_v4l2_buffer_status(cam, buf);
+               up(&cam->param_lock);
                break;
        }