V4L/DVB (6260): Fix Kconfig dependency
[safe/jmp/linux-2.6] / drivers / media / video / vivi.c
index 582c6ba..01c9776 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/pci.h>
 #include <linux/random.h>
 #include <linux/version.h>
+#include <linux/mutex.h>
 #include <linux/videodev2.h>
 #include <linux/dma-mapping.h>
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
@@ -32,7 +33,7 @@
 #include <linux/videodev.h>
 #endif
 #include <linux/interrupt.h>
-#include <media/video-buf.h>
+#include <media/videobuf-vmalloc.h>
 #include <media/v4l2-common.h>
 #include <linux/kthread.h>
 #include <linux/highmem.h>
@@ -144,7 +145,6 @@ struct vivi_buffer {
        struct videobuf_buffer vb;
 
        struct vivi_fmt        *fmt;
-
 };
 
 struct vivi_dmaqueue {
@@ -165,7 +165,7 @@ static LIST_HEAD(vivi_devlist);
 struct vivi_dev {
        struct list_head           vivi_devlist;
 
-       struct semaphore           lock;
+       struct mutex               lock;
 
        int                        users;
 
@@ -325,27 +325,22 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
        int hmax  = buf->vb.height;
        int wmax  = buf->vb.width;
        struct timeval ts;
-       char *tmpbuf;
-
-       if (buf->vb.dma.varea) {
-               tmpbuf=kmalloc (wmax*2, GFP_KERNEL);
-       } else {
-               tmpbuf=buf->vb.dma.vmalloc;
-       }
+       char *tmpbuf = kmalloc(wmax*2,GFP_KERNEL);
+       void *vbuf=videobuf_to_vmalloc (&buf->vb);
 
+       if (!tmpbuf)
+               return;
 
        for (h=0;h<hmax;h++) {
-               if (buf->vb.dma.varea) {
-                       gen_line(tmpbuf,0,wmax,hmax,h,dev->timestr);
-                       /* FIXME: replacing to __copy_to_user */
-                       if (copy_to_user(buf->vb.dma.varea+pos,tmpbuf,wmax*2)!=0)
-                               dprintk(2,"vivifill copy_to_user failed.\n");
-               } else {
-                       gen_line(tmpbuf,pos,wmax,hmax,h,dev->timestr);
-               }
+               gen_line(tmpbuf,0,wmax,hmax,h,dev->timestr);
+               /* FIXME: replacing to __copy_to_user */
+               if (copy_to_user(vbuf+pos,tmpbuf,wmax*2)!=0)
+                       dprintk(2,"vivifill copy_to_user failed.\n");
                pos += wmax*2;
        }
 
+       kfree(tmpbuf);
+
        /* Updates stream time */
 
        dev->us+=jiffies_to_usecs(jiffies-dev->jiffies);
@@ -368,7 +363,7 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
                        dev->h,dev->m,dev->s,(dev->us+500)/1000);
 
        dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr,
-                       (unsigned long)buf->vb.dma.varea,pos);
+                       (unsigned long)tmpbuf,pos);
 
        /* Advice that buffer was filled */
        buf->vb.state = STATE_DONE;
@@ -596,8 +591,12 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
 
        if (0 == *count)
                *count = 32;
+
        while (*size * *count > vid_limit * 1024 * 1024)
                (*count)--;
+
+       dprintk(1,"%s, count=%d, size=%d\n",__FUNCTION__,*count, *size);
+
        return 0;
 }
 
@@ -608,10 +607,8 @@ static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
        if (in_interrupt())
                BUG();
 
-
        videobuf_waiton(&buf->vb,0,0);
-       videobuf_dma_unmap(vq, &buf->vb.dma);
-       videobuf_dma_free(&buf->vb.dma);
+       videobuf_vmalloc_free(&buf->vb);
        buf->vb.state = STATE_NEEDS_INIT;
 }
 
@@ -625,7 +622,7 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
        struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb);
        int rc, init_buffer = 0;
 
-//     dprintk(1,"%s, field=%d\n",__FUNCTION__,field);
+       dprintk(1,"%s, field=%d\n",__FUNCTION__,field);
 
        BUG_ON(NULL == fh->fmt);
        if (fh->width  < 48 || fh->width  > norm_maxw() ||
@@ -717,17 +714,11 @@ static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb
        free_buffer(vq,buf);
 }
 
-
 static struct videobuf_queue_ops vivi_video_qops = {
        .buf_setup      = buffer_setup,
        .buf_prepare    = buffer_prepare,
        .buf_queue      = buffer_queue,
        .buf_release    = buffer_release,
-
-       /* Non-pci handling routines */
-//     .vb_map_sg      = vivi_map_sg,
-//     .vb_dma_sync_sg = vivi_dma_sync_sg,
-//     .vb_unmap_sg    = vivi_unmap_sg,
 };
 
 /* ------------------------------------------------------------------
@@ -738,16 +729,16 @@ static struct videobuf_queue_ops vivi_video_qops = {
 static int res_get(struct vivi_dev *dev, struct vivi_fh *fh)
 {
        /* is it free? */
-       down(&dev->lock);
+       mutex_lock(&dev->lock);
        if (dev->resources) {
                /* no, someone else uses it */
-               up(&dev->lock);
+               mutex_unlock(&dev->lock);
                return 0;
        }
        /* it's free, grab it */
        dev->resources =1;
        dprintk(1,"res: get\n");
-       up(&dev->lock);
+       mutex_unlock(&dev->lock);
        return 1;
 }
 
@@ -758,10 +749,10 @@ static int res_locked(struct vivi_dev *dev)
 
 static void res_free(struct vivi_dev *dev, struct vivi_fh *fh)
 {
-       down(&dev->lock);
+       mutex_lock(&dev->lock);
        dev->resources = 0;
        dprintk(1,"res: put\n");
-       up(&dev->lock);
+       mutex_lock(&dev->lock);
 }
 
 /* ------------------------------------------------------------------
@@ -903,25 +894,8 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
 static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
 {
        struct vivi_fh  *fh=priv;
-       struct videobuf_queue *q=&fh->vb_vidq;
-       struct v4l2_requestbuffers req;
-       unsigned int i;
-       int ret;
-
-       req.type   = q->type;
-       req.count  = 8;
-       req.memory = V4L2_MEMORY_MMAP;
-       ret = videobuf_reqbufs(q,&req);
-       if (ret < 0)
-               return (ret);
 
-       mbuf->frames = req.count;
-       mbuf->size   = 0;
-       for (i = 0; i < mbuf->frames; i++) {
-               mbuf->offsets[i]  = q->bufs[i]->boff;
-               mbuf->size       += q->bufs[i]->bsize;
-       }
-       return (0);
+       return videobuf_cgmbuf (&fh->vb_vidq, mbuf, 8);
 }
 #endif
 
@@ -1105,7 +1079,7 @@ static int vivi_open(struct inode *inode, struct file *file)
        sprintf(dev->timestr,"%02d:%02d:%02d:%03d",
                        dev->h,dev->m,dev->s,(dev->us+500)/1000);
 
-       videobuf_queue_init(&fh->vb_vidq, &vivi_video_qops,
+       videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops,
                        NULL, NULL,
                        fh->type,
                        V4L2_FIELD_INTERLACED,
@@ -1122,7 +1096,7 @@ vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
        if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) {
                if (res_locked(fh->dev))
                        return -EBUSY;
-               return videobuf_read_one(&fh->vb_vidq, data, count, ppos,
+               return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0,
                                        file->f_flags & O_NONBLOCK);
        }
        return 0;
@@ -1148,9 +1122,8 @@ vivi_poll(struct file *file, struct poll_table_struct *wait)
        } else {
                dprintk(1,"poll: read() interface\n");
                /* read() capture */
-               buf = (struct vivi_buffer*)fh->vb_vidq.read_buf;
-               if (NULL == buf)
-                       return POLLERR;
+               return videobuf_poll_stream(file, &fh-> vb_vidq,
+                                           wait);
        }
        poll_wait(file, &buf->vb.done, wait);
        if (buf->vb.state == STATE_DONE ||
@@ -1204,7 +1177,7 @@ static const struct file_operations vivi_fops = {
        .read           = vivi_read,
        .poll           = vivi_poll,
        .ioctl          = video_ioctl2, /* V4L2 ioctl handler */
-       .mmap           = vivi_mmap,
+       .mmap           = vivi_mmap,
        .llseek         = no_llseek,
 };
 
@@ -1260,7 +1233,7 @@ static int __init vivi_init(void)
        init_waitqueue_head(&dev->vidq.wq);
 
        /* initialize locks */
-       init_MUTEX(&dev->lock);
+       mutex_init(&dev->lock);
 
        dev->vidq.timeout.function = vivi_vid_timeout;
        dev->vidq.timeout.data     = (unsigned long)dev;