]> git.hungrycats.org Git - linux/commitdiff
Port the MotionEye driver to the new video4linux API.
authorStelian Pop <stelian@popies.net>
Thu, 14 Mar 2002 18:20:21 +0000 (19:20 +0100)
committerLinus Torvalds <torvalds@penguin.transmeta.com>
Thu, 14 Mar 2002 18:20:21 +0000 (19:20 +0100)
drivers/media/video/meye.c
drivers/media/video/meye.h

index e03e6f4595cbe20a5434180291954f100f372580..7634bc4f907f0ef4fbfa5825a834fd9ef3540a7d 100644 (file)
@@ -868,124 +868,108 @@ out:
 /* video4linux integration                                                  */
 /****************************************************************************/
 
-static int meye_open(struct video_device *dev, int flags) {
-       int i;
+static int meye_open(struct inode *inode, struct file *file) {
+       int i, err;
 
-       down(&meye.lock);
-       if (meye.open_count) {
-               up(&meye.lock);
-               return -EBUSY;
-       }
-       meye.open_count++;
+       err = video_exclusive_open(inode,file);
+       if (err < 0)
+               return err;
+                       
        if (mchip_dma_alloc()) {
                printk(KERN_ERR "meye: mchip framebuffer allocation failed\n");
-               up(&meye.lock);
+               video_exclusive_release(inode,file);
                return -ENOBUFS;
        }
        mchip_hic_stop();
        meye_initq(&meye.grabq);
        for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
                meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
-       up(&meye.lock);
        return 0;
 }
 
-static void meye_close(struct video_device *dev) {
-       down(&meye.lock);
-       meye.open_count--;
+static int meye_release(struct inode *inode, struct file *file) {
        mchip_hic_stop();
-       up(&meye.lock);
+       video_exclusive_release(inode,file);
+       return 0;
 }
 
-static int meye_ioctl(struct video_device *dev, unsigned int cmd, void *arg) {
+static int meye_ioctl(struct inode *inode, struct file *file,
+                     unsigned int cmd, void *arg) {
 
        switch (cmd) {
 
        case VIDIOCGCAP: {
-               struct video_capability b;
-               strcpy(b.name,meye.video_dev.name);
-               b.type = VID_TYPE_CAPTURE;
-               b.channels = 1;
-               b.audios = 0;
-               b.maxwidth = 640;
-               b.maxheight = 480;
-               b.minwidth = 320;
-               b.minheight = 240;
-               if(copy_to_user(arg,&b,sizeof(b)))
-                       return -EFAULT;
+               struct video_capability *b = arg;
+               strcpy(b->name,meye.video_dev.name);
+               b->type = VID_TYPE_CAPTURE;
+               b->channels = 1;
+               b->audios = 0;
+               b->maxwidth = 640;
+               b->maxheight = 480;
+               b->minwidth = 320;
+               b->minheight = 240;
                break;
        }
 
        case VIDIOCGCHAN: {
-               struct video_channel v;
-               if(copy_from_user(&v, arg,sizeof(v)))
-                       return -EFAULT;
-               v.flags = 0;
-               v.tuners = 0;
-               v.type = VIDEO_TYPE_CAMERA;
-               if (v.channel != 0)
+               struct video_channel *v = arg;
+               v->flags = 0;
+               v->tuners = 0;
+               v->type = VIDEO_TYPE_CAMERA;
+               if (v->channel != 0)
                        return -EINVAL;
-               strcpy(v.name,"Camera");
-               if(copy_to_user(arg,&v,sizeof(v)))
-                       return -EFAULT;
+               strcpy(v->name,"Camera");
                break;
        }
 
        case VIDIOCSCHAN: {
-               struct video_channel v;
-               if(copy_from_user(&v, arg,sizeof(v)))
-                       return -EFAULT;
-               if (v.channel != 0)
+               struct video_channel *v = arg;
+               if (v->channel != 0)
                        return -EINVAL;
                break;
        }
 
        case VIDIOCGPICT: {
-               struct video_picture p = meye.picture;
-               if(copy_to_user(arg, &p, sizeof(p)))
-                       return -EFAULT;
+               struct video_picture *p = arg;
+               *p = meye.picture;
                break;
        }
 
        case VIDIOCSPICT: {
-               struct video_picture p;
-               if(copy_from_user(&p, arg,sizeof(p)))
-                       return -EFAULT;
-               if (p.depth != 2)
+               struct video_picture *p = arg;
+               if (p->depth != 2)
                        return -EINVAL;
-               if (p.palette != VIDEO_PALETTE_YUV422)
+               if (p->palette != VIDEO_PALETTE_YUV422)
                        return -EINVAL;
                down(&meye.lock);
                sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 
-                                     p.brightness >> 10);
+                                     p->brightness >> 10);
                sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE, 
-                                     p.hue >> 10);
+                                     p->hue >> 10);
                sonypi_camera_command(SONYPI_COMMAND_SETCAMERACOLOR, 
-                                     p.colour >> 10);
+                                     p->colour >> 10);
                sonypi_camera_command(SONYPI_COMMAND_SETCAMERACONTRAST, 
-                                     p.contrast >> 10);
-               memcpy(&meye.picture, &p, sizeof(p));
+                                     p->contrast >> 10);
+               meye.picture = *p;
                up(&meye.lock);
                break;
        }
 
        case VIDIOCSYNC: {
-               int i;
+               int *i = arg;
                DECLARE_WAITQUEUE(wait, current);
 
-               if(copy_from_user((void *)&i,arg,sizeof(int)))
-                       return -EFAULT;
-               if (i < 0 || i >= gbuffers)
+               if (*i < 0 || *i >= gbuffers)
                        return -EINVAL;
 
-               switch (meye.grab_buffer[i].state) {
+               switch (meye.grab_buffer[*i].state) {
 
                case MEYE_BUF_UNUSED:
                        return -EINVAL;
                case MEYE_BUF_USING:
                        add_wait_queue(&meye.grabq.proc_list, &wait);
                        current->state = TASK_INTERRUPTIBLE;
-                       while (meye.grab_buffer[i].state == MEYE_BUF_USING) {
+                       while (meye.grab_buffer[*i].state == MEYE_BUF_USING) {
                                schedule();
                                if(signal_pending(current)) {
                                        remove_wait_queue(&meye.grabq.proc_list, &wait);
@@ -997,36 +981,34 @@ static int meye_ioctl(struct video_device *dev, unsigned int cmd, void *arg) {
                        current->state = TASK_RUNNING;
                        /* fall through */
                case MEYE_BUF_DONE:
-                       meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
+                       meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
                }
                break;
        }
 
        case VIDIOCMCAPTURE: {
-               struct video_mmap vm;
+               struct video_mmap *vm = arg;
                int restart = 0;
 
-               if(copy_from_user((void *) &vm, (void *) arg, sizeof(vm)))
-                       return -EFAULT;
-               if (vm.frame >= gbuffers || vm.frame < 0)
+               if (vm->frame >= gbuffers || vm->frame < 0)
                        return -EINVAL;
-               if (vm.format != VIDEO_PALETTE_YUV422)
+               if (vm->format != VIDEO_PALETTE_YUV422)
                        return -EINVAL;
-               if (vm.height * vm.width * 2 > gbufsize)
+               if (vm->height * vm->width * 2 > gbufsize)
                        return -EINVAL;
                if (!meye.grab_fbuffer)
                        return -EINVAL;
-               if (meye.grab_buffer[vm.frame].state != MEYE_BUF_UNUSED)
+               if (meye.grab_buffer[vm->frame].state != MEYE_BUF_UNUSED)
                        return -EBUSY;
 
                down(&meye.lock);
-               if (vm.width == 640 && vm.height == 480) {
+               if (vm->width == 640 && vm->height == 480) {
                        if (meye.params.subsample) {
                                meye.params.subsample = 0;
                                restart = 1;
                        }
                }
-               else if (vm.width == 320 && vm.height == 240) {
+               else if (vm->width == 320 && vm->height == 240) {
                        if (!meye.params.subsample) {
                                meye.params.subsample = 1;
                                restart = 1;
@@ -1039,49 +1021,45 @@ static int meye_ioctl(struct video_device *dev, unsigned int cmd, void *arg) {
 
                if (restart || meye.mchip_mode != MCHIP_HIC_MODE_CONT_OUT)
                        mchip_continuous_start();
-               meye.grab_buffer[vm.frame].state = MEYE_BUF_USING;
-               meye_pushq(&meye.grabq, vm.frame);
+               meye.grab_buffer[vm->frame].state = MEYE_BUF_USING;
+               meye_pushq(&meye.grabq, vm->frame);
                up(&meye.lock);
                break;
        }
 
        case VIDIOCGMBUF: {
-               struct video_mbuf vm;
+               struct video_mbuf *vm = arg;
                int i;
 
-               memset(&vm, 0 , sizeof(vm));
-               vm.size = gbufsize * gbuffers;
-               vm.frames = gbuffers;
+               memset(vm, 0 , sizeof(*vm));
+               vm->size = gbufsize * gbuffers;
+               vm->frames = gbuffers;
                for (i = 0; i < gbuffers; i++)
-                       vm.offsets[i] = i * gbufsize;
-               if(copy_to_user((void *)arg, (void *)&vm, sizeof(vm)))
-                       return -EFAULT;
+                       vm->offsets[i] = i * gbufsize;
                break;
        }
 
        case MEYEIOC_G_PARAMS: {
-               if (copy_to_user(arg, &meye.params, sizeof(meye.params)))
-                       return -EFAULT;
+               struct meye_params *p = arg;
+               *p = meye.params;
                break;
        }
 
        case MEYEIOC_S_PARAMS: {
-               struct meye_params jp;
-               if (copy_from_user(&jp, arg, sizeof(jp)))
-                       return -EFAULT;
-               if (jp.subsample > 1)
+               struct meye_params *jp = arg;
+               if (jp->subsample > 1)
                        return -EINVAL;
-               if (jp.quality > 10)
+               if (jp->quality > 10)
                        return -EINVAL;
-               if (jp.sharpness > 63 || jp.agc > 63 || jp.picture > 63)
+               if (jp->sharpness > 63 || jp->agc > 63 || jp->picture > 63)
                        return -EINVAL;
-               if (jp.framerate > 31)
+               if (jp->framerate > 31)
                        return -EINVAL;
                down(&meye.lock);
-               if (meye.params.subsample != jp.subsample ||
-                   meye.params.quality != jp.quality)
+               if (meye.params.subsample != jp->subsample ||
+                   meye.params.quality != jp->quality)
                        mchip_hic_stop();       /* need restart */
-               memcpy(&meye.params, &jp, sizeof(jp));
+               meye.params = *jp;
                sonypi_camera_command(SONYPI_COMMAND_SETCAMERASHARPNESS,
                                      meye.params.sharpness);
                sonypi_camera_command(SONYPI_COMMAND_SETCAMERAAGC,
@@ -1093,48 +1071,43 @@ static int meye_ioctl(struct video_device *dev, unsigned int cmd, void *arg) {
        }
 
        case MEYEIOC_QBUF_CAPT: {
-               int nb;
-
-               if (copy_from_user((void *) &nb, (void *) arg, sizeof(int)))
-                       return -EFAULT;
+               int *nb = arg;
 
                if (!meye.grab_fbuffer) 
                        return -EINVAL;
-               if (nb >= gbuffers)
+               if (*nb >= gbuffers)
                        return -EINVAL;
-               if (nb < 0) {
+               if (*nb < 0) {
                        /* stop capture */
                        mchip_hic_stop();
                        return 0;
                }
-               if (meye.grab_buffer[nb].state != MEYE_BUF_UNUSED)
+               if (meye.grab_buffer[*nb].state != MEYE_BUF_UNUSED)
                        return -EBUSY;
                down(&meye.lock);
                if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP)
                        mchip_cont_compression_start();
-               meye.grab_buffer[nb].state = MEYE_BUF_USING;
-               meye_pushq(&meye.grabq, nb);
+               meye.grab_buffer[*nb].state = MEYE_BUF_USING;
+               meye_pushq(&meye.grabq, *nb);
                up(&meye.lock);
                break;
        }
 
        case MEYEIOC_SYNC: {
-               int i;
+               int *i = arg;
                DECLARE_WAITQUEUE(wait, current);
 
-               if(copy_from_user((void *)&i,arg,sizeof(int)))
-                       return -EFAULT;
-               if (i < 0 || i >= gbuffers)
+               if (*i < 0 || *i >= gbuffers)
                        return -EINVAL;
 
-               switch (meye.grab_buffer[i].state) {
+               switch (meye.grab_buffer[*i].state) {
 
                case MEYE_BUF_UNUSED:
                        return -EINVAL;
                case MEYE_BUF_USING:
                        add_wait_queue(&meye.grabq.proc_list, &wait);
                        current->state = TASK_INTERRUPTIBLE;
-                       while (meye.grab_buffer[i].state == MEYE_BUF_USING) {
+                       while (meye.grab_buffer[*i].state == MEYE_BUF_USING) {
                                schedule();
                                if(signal_pending(current)) {
                                        remove_wait_queue(&meye.grabq.proc_list, &wait);
@@ -1146,11 +1119,9 @@ static int meye_ioctl(struct video_device *dev, unsigned int cmd, void *arg) {
                        current->state = TASK_RUNNING;
                        /* fall through */
                case MEYE_BUF_DONE:
-                       meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
+                       meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
                }
-               i = meye.grab_buffer[i].size;
-               if (copy_to_user(arg, (void *)&i, sizeof(int)))
-                       return -EFAULT;
+               *i = meye.grab_buffer[*i].size;
                break;
        }
 
@@ -1172,7 +1143,7 @@ static int meye_ioctl(struct video_device *dev, unsigned int cmd, void *arg) {
        }
 
        case MEYEIOC_STILLJCAPT: {
-               int len = -1;
+               int *len = arg;
 
                if (!meye.grab_fbuffer) 
                        return -EINVAL;
@@ -1180,14 +1151,13 @@ static int meye_ioctl(struct video_device *dev, unsigned int cmd, void *arg) {
                        return -EBUSY;
                down(&meye.lock);
                meye.grab_buffer[0].state = MEYE_BUF_USING;
-               while (len == -1) {
+               *len = -1;
+               while (*len == -1) {
                        mchip_take_picture();
-                       len = mchip_compress_frame(meye.grab_fbuffer, gbufsize);
+                       *len = mchip_compress_frame(meye.grab_fbuffer, gbufsize);
                }
                meye.grab_buffer[0].state = MEYE_BUF_DONE;
                up(&meye.lock);
-               if (copy_to_user(arg, (void *)&len, sizeof(int)))
-                       return -EFAULT;
                break;
        }
 
@@ -1199,10 +1169,10 @@ static int meye_ioctl(struct video_device *dev, unsigned int cmd, void *arg) {
        return 0;
 }
 
-static int meye_mmap(struct vm_area_struct *vma, struct video_device *dev, const char *adr, 
-                    unsigned long size) {
-       unsigned long start=(unsigned long) adr;
-       unsigned long page,pos;
+static int meye_mmap(struct file *file, struct vm_area_struct *vma) {
+       unsigned long start = vma->vm_start;
+       unsigned long size  = vma->vm_end - vma->vm_start;
+       unsigned long page, pos;
 
        down(&meye.lock);
        if (size > gbuffers * gbufsize) {
@@ -1234,15 +1204,22 @@ static int meye_mmap(struct vm_area_struct *vma, struct video_device *dev, const
        return 0;
 }
 
+static struct file_operations meye_fops = {
+       owner:          THIS_MODULE,
+       open:           meye_open,
+       release:        meye_release,
+       mmap:           meye_mmap,
+       ioctl:          video_generic_ioctl,
+       llseek:         no_llseek,
+};
+
 static struct video_device meye_template = {
        owner:          THIS_MODULE,
        name:           "meye",
        type:           VID_TYPE_CAPTURE,
        hardware:       VID_HARDWARE_MEYE,
-       open:           meye_open,
-       close:          meye_close,
-       ioctl:          meye_ioctl,
-       mmap:           meye_mmap,
+       fops:           &meye_fops,
+       kernel_ioctl:   meye_ioctl,
 };
 
 static int __devinit meye_probe(struct pci_dev *pcidev, 
index 750ad5479ebcd56fdb0d5ac34794cbdc8930563a..ca093d2fbd65711087d131a404fda9875bb8a088 100644 (file)
@@ -29,7 +29,7 @@
 #define _MEYE_PRIV_H_
 
 #define MEYE_DRIVER_MAJORVERSION       1
-#define MEYE_DRIVER_MINORVERSION       2
+#define MEYE_DRIVER_MINORVERSION       3
 
 /****************************************************************************/
 /* Motion JPEG chip registers                                               */
@@ -300,7 +300,6 @@ struct meye {
        struct meye_grab_buffer grab_buffer[MEYE_MAX_BUFNBRS];
 
        /* other */
-       unsigned int open_count;        /* open() count */
        struct semaphore lock;          /* semaphore for open/mmap... */
 
        struct meye_queue grabq;        /* queue for buffers to be grabbed */