]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00169387 add user space memory allocation for v4l2.
authorLiu Xiaowen <b37945@freescale.com>
Mon, 5 Dec 2011 05:45:25 +0000 (13:45 +0800)
committerLothar Waßmann <LW@KARO-electronics.de>
Fri, 24 May 2013 06:33:33 +0000 (08:33 +0200)
add user space memory allocation for kernel v4l2 interface in ics.

Signed-off-by: Liu Xiaowen <b37945@freescale.com>
drivers/media/video/mxc/capture/mxc_v4l2_capture.c
drivers/media/video/mxc/capture/mxc_v4l2_capture.h

index 229e3f6fe42ccf4c421a08a01e0c50c77b27741c..a6045061f505ee72595262f3a92aa4ba9df3c54c 100644 (file)
@@ -297,6 +297,36 @@ static int mxc_v4l2_buffer_status(cam_data *cam, struct v4l2_buffer *buf)
        return 0;
 }
 
+static int mxc_v4l2_release_bufs(cam_data *cam)
+{
+       pr_debug("In MVC:mxc_v4l2_release_bufs\n");
+       return 0;
+}
+
+static int mxc_v4l2_prepare_bufs(cam_data *cam, struct v4l2_buffer *buf)
+{
+       pr_debug("In MVC:mxc_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: mxc_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;
+}
+
 /***************************************************************************
  * Functions for handling the video stream.
  **************************************************************************/
@@ -1200,6 +1230,10 @@ static int mxc_v4l2_s_param(cam_data *cam, struct v4l2_streamparm *parm)
                        currentparm.parm.capture.timeperframe.denominator,
                        parm->parm.capture.timeperframe.denominator);
 
+       if (parm->parm.capture.capturemode == currentparm.parm.capture.capturemode) {
+               return 0;
+       }
+
        /* This will change any camera settings needed. */
        ipu_csi_enable_mclk_if(cam->ipu, CSI_MCLK_I2C, cam->csi, true, true);
        err = vidioc_int_s_parm(cam->sensor, parm);
@@ -1813,8 +1847,7 @@ static long mxc_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;
@@ -1822,13 +1855,15 @@ static long mxc_v4l_do_ioctl(struct file *file,
                }
 
                mxc_streamoff(cam);
-               mxc_free_frame_buf(cam);
+               if (req->memory & V4L2_MEMORY_MMAP)
+                       mxc_free_frame_buf(cam);
                cam->enc_counter = 0;
                INIT_LIST_HEAD(&cam->ready_q);
                INIT_LIST_HEAD(&cam->working_q);
                INIT_LIST_HEAD(&cam->done_q);
 
-               retval = mxc_allocate_frame_buf(cam, req->count);
+               if (req->memory & V4L2_MEMORY_MMAP)
+                       retval = mxc_allocate_frame_buf(cam, req->count);
                break;
        }
 
@@ -1848,11 +1883,19 @@ static long mxc_v4l_do_ioctl(struct file *file,
                        break;
                }
 
-               memset(buf, 0, sizeof(buf));
-               buf->index = index;
+               if (buf->memory & V4L2_MEMORY_MMAP) {
+                       memset(buf, 0, sizeof(buf));
+                       buf->index = index;
+               }
 
                down(&cam->param_lock);
-               retval = mxc_v4l2_buffer_status(cam, buf);
+               if (buf->memory & V4L2_MEMORY_USERPTR) {
+                       mxc_v4l2_release_bufs(cam);
+                       retval = mxc_v4l2_prepare_bufs(cam, buf);
+               }
+
+               if (buf->memory & V4L2_MEMORY_MMAP)
+                       retval = mxc_v4l2_buffer_status(cam, buf);
                up(&cam->param_lock);
                break;
        }
@@ -1907,7 +1950,6 @@ static long mxc_v4l_do_ioctl(struct file *file,
                }
 
                retval = mxc_v4l_dqueue(cam, buf);
-
                break;
        }
 
index 4de53aa964d8692469ec302b376c4c9dd5e2c446..d04b3d75544928e292ba431a14be3ade9fd740e1 100644 (file)
@@ -36,7 +36,7 @@
 
 #include <media/v4l2-dev.h>
 
-#define FRAME_NUM 3
+#define FRAME_NUM 10
 
 /*!
  * v4l2 frame structure.