[media] davinci: vpif capture: size up the memory for the buffers from the buffer...
authorManjunath Hadli <manjunath.hadli@ti.com>
Fri, 13 Apr 2012 07:49:34 +0000 (04:49 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 30 Jul 2012 22:04:32 +0000 (19:04 -0300)
Size up the memory for the buffers from the buffer pool allocated in board
file.  Then adjust the reqbuf count depending the available memory.

Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/davinci/vpif_capture.c
drivers/media/video/davinci/vpif_capture.h

index bce31ea55dc4f15e7b231b0e0416084034a40220..d126fb6d74b6b73c1273500ba109f9ce61959a0a 100644 (file)
@@ -217,6 +217,23 @@ static int vpif_buffer_setup(struct videobuf_queue *q, unsigned int *count,
        /* Calculate the size of the buffer */
        *size = config_params.channel_bufsize[ch->channel_id];
 
+       /*
+        * Checking if the buffer size exceeds the available buffer
+        * ycmux_mode = 0 means 1 channel mode HD and
+        * ycmux_mode = 1 means 2 channels mode SD
+        */
+       if (ch->vpifparams.std_info.ycmux_mode == 0) {
+               if (config_params.video_limit[ch->channel_id])
+                       while (*size * *count > (config_params.video_limit[0]
+                                               + config_params.video_limit[1]))
+                               (*count)--;
+       } else {
+               if (config_params.video_limit[ch->channel_id])
+                       while (*size * *count >
+                               config_params.video_limit[ch->channel_id])
+                               (*count)--;
+       }
+
        if (*count < config_params.min_numbuffers)
                *count = config_params.min_numbuffers;
        return 0;
@@ -890,7 +907,7 @@ static int vpif_reqbufs(struct file *file, void *priv,
                }
        }
 
-       if (V4L2_BUF_TYPE_VIDEO_CAPTURE != reqbuf->type)
+       if (V4L2_BUF_TYPE_VIDEO_CAPTURE != reqbuf->type || !vpif_dev)
                return -EINVAL;
 
        index = VPIF_VIDEO_INDEX;
@@ -902,7 +919,7 @@ static int vpif_reqbufs(struct file *file, void *priv,
 
        /* Initialize videobuf queue as per the buffer type */
        videobuf_queue_dma_contig_init(&common->buffer_queue,
-                                           &video_qops, NULL,
+                                           &video_qops, vpif_dev,
                                            &common->irqlock,
                                            reqbuf->type,
                                            common->fmt.fmt.pix.field,
@@ -2171,6 +2188,7 @@ static __init int vpif_probe(struct platform_device *pdev)
        struct video_device *vfd;
        struct resource *res;
        int subdev_count;
+       size_t size;
 
        vpif_dev = &pdev->dev;
 
@@ -2225,6 +2243,23 @@ static __init int vpif_probe(struct platform_device *pdev)
                ch->video_dev = vfd;
        }
 
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res) {
+               size = resource_size(res);
+               /* The resources are divided into two equal memory and when we
+                * have HD output we can add them together
+                */
+               for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
+                       ch = vpif_obj.dev[j];
+                       ch->channel_id = j;
+                       /* only enabled if second resource exists */
+                       config_params.video_limit[ch->channel_id] = 0;
+                       if (size)
+                               config_params.video_limit[ch->channel_id] =
+                                                                       size/2;
+               }
+       }
+
        for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
                ch = vpif_obj.dev[j];
                ch->channel_id = j;
index a693d4ebda557ea0ee972813f8a5877d40e79efb..8095910f02c1ceacf12e5d3b802ef3887888ee22 100644 (file)
@@ -151,6 +151,7 @@ struct vpif_config_params {
        u32 min_bufsize[VPIF_CAPTURE_NUM_CHANNELS];
        u32 channel_bufsize[VPIF_CAPTURE_NUM_CHANNELS];
        u8 default_device[VPIF_CAPTURE_NUM_CHANNELS];
+       u32 video_limit[VPIF_CAPTURE_NUM_CHANNELS];
        u8 max_device_type;
 };
 /* Struct which keeps track of the line numbers for the sliced vbi service */