[BKPATCH 2.5] Port the MotionEye camera driver to the new v4l API.

Stelian Pop (stelian.pop@fr.alcove.com)
Thu, 14 Mar 2002 17:23:42 +0100


The attached BK patch ports the MotionEye camera driver to the
new Gerd's video4linux API.

Linus, please apply.

Stelian.

You can import this changeset into BK by piping this whole message to
'| bk receive [path to repository]' or apply the patch as usual.

===================================================================

ChangeSet@1.474, 2002-03-14 17:20:21+01:00, stelian@popies.net
Port the MotionEye driver to the new video4linux API.

meye.c | 223 +++++++++++++++++++++++++++++------------------------------------
meye.h | 3
2 files changed, 101 insertions(+), 125 deletions(-)

diff -Nru a/drivers/media/video/meye.c b/drivers/media/video/meye.c
--- a/drivers/media/video/meye.c Thu Mar 14 17:20:57 2002
+++ b/drivers/media/video/meye.c Thu Mar 14 17:20:57 2002
@@ -868,124 +868,108 @@
/* 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)
- return -EINVAL;
- strcpy(v.name,"Camera");
- if(copy_to_user(arg,&v,sizeof(v)))
- return -EFAULT;
+ 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");
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 @@
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 @@

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 @@
}

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 @@
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 @@
}

case MEYEIOC_STILLJCAPT: {
- int len = -1;
+ int *len = arg;

if (!meye.grab_fbuffer)
return -EINVAL;
@@ -1180,14 +1151,13 @@
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 @@
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 @@
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,
diff -Nru a/drivers/media/video/meye.h b/drivers/media/video/meye.h
--- a/drivers/media/video/meye.h Thu Mar 14 17:20:57 2002
+++ b/drivers/media/video/meye.h Thu Mar 14 17:20:57 2002
@@ -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_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 */

===================================================================

This BitKeeper patch contains the following changesets:
+
## Wrapped with gzip_uu ##

begin 664 bkpatch2803
M'XL(`.K-D#P``\U8>X_:2!+_V_X4O1LIFK#`N-OM%W.@S`9V%UWFH7E$BO96
MJ+$;<`*V8QLF<\=]]ZU^8`Q,YI&]DW82T79UU:^KJJNJ7?T*W18\[QA%R><Q
M2\Q7Z+>T*#M&EF8Q+]H)+X%TE:9`.IZE"WY<QDF<+H\_\SSA\^-YG"R_MDC;
M,8'MDI7A#*UX7G0,W+8K2GF?\8YQ-?CU]OWIE6EVN^C=C"53?LU+U.V:99JO
MV#PJWK)R-D^3=IFSI%CPDK7#=+&N6-?$L@C\<[!G6XZ[QJY%O76((XP9Q3RR
M"/5=ND7+>#)=QD_`V=@F-O&)LR8.M6VSCW";>A19Y-BRCS%%V.L0JT/P3Q;N
M6!;2;GJ[=0_ZB:"69?Z,_K=FO#-#=)GF)2IG')VE99PF@WN.HCP&_\):DI[P
M.[2*(YY2N0_H]'+8-O^)B&-[CG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=0DS43^@Y[I
M72*N$HV;WX;7H[.+_NW[`?15HD/MZ$P1STW1P<F^KF/4VT:@"_]L6,4SD&03
MU]ETJ5,.*\2A:NU@=@YG,O\,TTDZ4L]-\[\GYK_$3E"]$U1DN"&T!+[7E<H@
MK>XP1WJ);<_8?/SB9O:]%S?/O'DR]>U*.TNSMY.\S>9ANN+/@\8^]@#:7A//
M=BQUG?FR6QS4(G^K&QQUD_;<&YS9]]S@V+)&R]]7$9_$"5=UJW\U_#"X&IT-
ISR^NX.%Z>'%NV,`N3Z[J=CN<\?!SL5QT7<^+`N:-S3\!F%B.VE07````
`
end

-- 
Stelian Pop <stelian.pop@fr.alcove.com>
Alcove - http://www.alcove.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/