1 /****************************************************************************
3 * Filename: cpia2_v4l.c
5 * Copyright 2001, STMicrolectronics, Inc.
6 * Contact: steve.miller@st.com
7 * Copyright 2001,2005, Scott J. Bertin <scottbertin@yahoo.com>
10 * This is a USB driver for CPia2 based video cameras.
11 * The infrastructure of this driver is based on the cpia usb driver by
12 * Jochen Scharrlach and Johannes Erdfeldt.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Stripped of 2.4 stuff ready for main kernel submit by
29 * Alan Cox <alan@lxorguk.ukuu.org.uk>
30 ****************************************************************************/
32 #include <linux/version.h>
35 #include <linux/module.h>
36 #include <linux/time.h>
37 #include <linux/sched.h>
38 #include <linux/slab.h>
39 #include <linux/init.h>
40 #include <linux/videodev.h>
41 #include <media/v4l2-ioctl.h>
47 //#define _CPIA2_DEBUG_
49 #define MAKE_STRING_1(x) #x
50 #define MAKE_STRING(x) MAKE_STRING_1(x)
52 static int video_nr = -1;
53 module_param(video_nr, int, 0);
54 MODULE_PARM_DESC(video_nr,"video device to register (0=/dev/video0, etc)");
56 static int buffer_size = 68*1024;
57 module_param(buffer_size, int, 0);
58 MODULE_PARM_DESC(buffer_size, "Size for each frame buffer in bytes (default 68k)");
60 static int num_buffers = 3;
61 module_param(num_buffers, int, 0);
62 MODULE_PARM_DESC(num_buffers, "Number of frame buffers (1-"
63 MAKE_STRING(VIDEO_MAX_FRAME) ", default 3)");
65 static int alternate = DEFAULT_ALT;
66 module_param(alternate, int, 0);
67 MODULE_PARM_DESC(alternate, "USB Alternate (" MAKE_STRING(USBIF_ISO_1) "-"
68 MAKE_STRING(USBIF_ISO_6) ", default "
69 MAKE_STRING(DEFAULT_ALT) ")");
71 static int flicker_freq = 60;
72 module_param(flicker_freq, int, 0);
73 MODULE_PARM_DESC(flicker_freq, "Flicker frequency (" MAKE_STRING(50) "or"
74 MAKE_STRING(60) ", default "
77 static int flicker_mode = NEVER_FLICKER;
78 module_param(flicker_mode, int, 0);
79 MODULE_PARM_DESC(flicker_mode,
80 "Flicker supression (" MAKE_STRING(NEVER_FLICKER) "or"
81 MAKE_STRING(ANTI_FLICKER_ON) ", default "
82 MAKE_STRING(NEVER_FLICKER) ")");
84 MODULE_AUTHOR("Steve Miller (STMicroelectronics) <steve.miller@st.com>");
85 MODULE_DESCRIPTION("V4L-driver for STMicroelectronics CPiA2 based cameras");
86 MODULE_SUPPORTED_DEVICE("video");
87 MODULE_LICENSE("GPL");
89 #define ABOUT "V4L-Driver for Vision CPiA2 based cameras"
91 struct control_menu_info {
96 static struct control_menu_info framerate_controls[] =
98 { CPIA2_VP_FRAMERATE_6_25, "6.25 fps" },
99 { CPIA2_VP_FRAMERATE_7_5, "7.5 fps" },
100 { CPIA2_VP_FRAMERATE_12_5, "12.5 fps" },
101 { CPIA2_VP_FRAMERATE_15, "15 fps" },
102 { CPIA2_VP_FRAMERATE_25, "25 fps" },
103 { CPIA2_VP_FRAMERATE_30, "30 fps" },
105 #define NUM_FRAMERATE_CONTROLS (ARRAY_SIZE(framerate_controls))
107 static struct control_menu_info flicker_controls[] =
109 { NEVER_FLICKER, "Off" },
110 { FLICKER_50, "50 Hz" },
111 { FLICKER_60, "60 Hz" },
113 #define NUM_FLICKER_CONTROLS (ARRAY_SIZE(flicker_controls))
115 static struct control_menu_info lights_controls[] =
122 #define NUM_LIGHTS_CONTROLS (ARRAY_SIZE(lights_controls))
123 #define GPIO_LIGHTS_MASK 192
125 static struct v4l2_queryctrl controls[] = {
127 .id = V4L2_CID_BRIGHTNESS,
128 .type = V4L2_CTRL_TYPE_INTEGER,
129 .name = "Brightness",
133 .default_value = DEFAULT_BRIGHTNESS,
136 .id = V4L2_CID_CONTRAST,
137 .type = V4L2_CTRL_TYPE_INTEGER,
142 .default_value = DEFAULT_CONTRAST,
145 .id = V4L2_CID_SATURATION,
146 .type = V4L2_CTRL_TYPE_INTEGER,
147 .name = "Saturation",
151 .default_value = DEFAULT_SATURATION,
154 .id = V4L2_CID_HFLIP,
155 .type = V4L2_CTRL_TYPE_BOOLEAN,
156 .name = "Mirror Horizontally",
163 .id = V4L2_CID_VFLIP,
164 .type = V4L2_CTRL_TYPE_BOOLEAN,
165 .name = "Flip Vertically",
172 .id = CPIA2_CID_TARGET_KB,
173 .type = V4L2_CTRL_TYPE_INTEGER,
178 .default_value = DEFAULT_TARGET_KB,
181 .id = CPIA2_CID_GPIO,
182 .type = V4L2_CTRL_TYPE_INTEGER,
190 .id = CPIA2_CID_FLICKER_MODE,
191 .type = V4L2_CTRL_TYPE_MENU,
192 .name = "Flicker Reduction",
194 .maximum = NUM_FLICKER_CONTROLS-1,
199 .id = CPIA2_CID_FRAMERATE,
200 .type = V4L2_CTRL_TYPE_MENU,
203 .maximum = NUM_FRAMERATE_CONTROLS-1,
205 .default_value = NUM_FRAMERATE_CONTROLS-1,
208 .id = CPIA2_CID_USB_ALT,
209 .type = V4L2_CTRL_TYPE_INTEGER,
210 .name = "USB Alternate",
211 .minimum = USBIF_ISO_1,
212 .maximum = USBIF_ISO_6,
214 .default_value = DEFAULT_ALT,
217 .id = CPIA2_CID_LIGHTS,
218 .type = V4L2_CTRL_TYPE_MENU,
221 .maximum = NUM_LIGHTS_CONTROLS-1,
226 .id = CPIA2_CID_RESET_CAMERA,
227 .type = V4L2_CTRL_TYPE_BUTTON,
228 .name = "Reset Camera",
235 #define NUM_CONTROLS (ARRAY_SIZE(controls))
238 /******************************************************************************
242 *****************************************************************************/
243 static int cpia2_open(struct file *file)
245 struct camera_data *cam = video_drvdata(file);
249 ERR("Internal error, camera_data not found!\n");
253 if(mutex_lock_interruptible(&cam->busy_lock))
261 if (cam->open_count > 0) {
265 if (cpia2_allocate_buffers(cam)) {
270 /* reset the camera */
271 if (cpia2_reset_camera(cam) < 0) {
281 struct cpia2_fh *fh = kmalloc(sizeof(*fh),GFP_KERNEL);
286 file->private_data = fh;
287 fh->prio = V4L2_PRIORITY_UNSET;
288 v4l2_prio_open(&cam->prio, &fh->prio);
294 cpia2_dbg_dump_registers(cam);
297 mutex_unlock(&cam->busy_lock);
301 /******************************************************************************
305 *****************************************************************************/
306 static int cpia2_close(struct file *file)
308 struct video_device *dev = video_devdata(file);
309 struct camera_data *cam = video_get_drvdata(dev);
310 struct cpia2_fh *fh = file->private_data;
312 mutex_lock(&cam->busy_lock);
315 (cam->open_count == 1
316 || fh->prio == V4L2_PRIORITY_RECORD
318 cpia2_usb_stream_stop(cam);
320 if(cam->open_count == 1) {
321 /* save camera state for later open */
322 cpia2_save_camera_state(cam);
324 cpia2_set_low_power(cam);
325 cpia2_free_buffers(cam);
332 v4l2_prio_close(&cam->prio,&fh->prio);
333 file->private_data = NULL;
337 if (--cam->open_count == 0) {
338 cpia2_free_buffers(cam);
340 video_unregister_device(dev);
341 mutex_unlock(&cam->busy_lock);
347 mutex_unlock(&cam->busy_lock);
352 /******************************************************************************
356 *****************************************************************************/
357 static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
360 struct camera_data *cam = video_drvdata(file);
361 int noblock = file->f_flags&O_NONBLOCK;
363 struct cpia2_fh *fh = file->private_data;
369 if(fh->prio != V4L2_PRIORITY_RECORD) {
373 return cpia2_read(cam, buf, count, noblock);
377 /******************************************************************************
381 *****************************************************************************/
382 static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
384 struct camera_data *cam = video_drvdata(filp);
385 struct cpia2_fh *fh = filp->private_data;
391 if(fh->prio != V4L2_PRIORITY_RECORD) {
395 return cpia2_poll(cam, filp, wait);
399 /******************************************************************************
403 *****************************************************************************/
404 static int ioctl_cap_query(void *arg, struct camera_data *cam)
406 struct video_capability *vc;
410 if (cam->params.pnp_id.product == 0x151)
411 strcpy(vc->name, "QX5 Microscope");
413 strcpy(vc->name, "CPiA2 Camera");
415 vc->type = VID_TYPE_CAPTURE | VID_TYPE_MJPEG_ENCODER;
418 vc->minwidth = 176; /* VIDEOSIZE_QCIF */
420 switch (cam->params.version.sensor_flags) {
421 case CPIA2_VP_SENSOR_FLAGS_500:
422 vc->maxwidth = STV_IMAGE_VGA_COLS;
423 vc->maxheight = STV_IMAGE_VGA_ROWS;
425 case CPIA2_VP_SENSOR_FLAGS_410:
426 vc->maxwidth = STV_IMAGE_CIF_COLS;
427 vc->maxheight = STV_IMAGE_CIF_ROWS;
436 /******************************************************************************
440 *****************************************************************************/
441 static int ioctl_get_channel(void *arg)
444 struct video_channel *v;
451 strcpy(v->name, "Camera");
454 v->type = VIDEO_TYPE_CAMERA;
460 /******************************************************************************
464 *****************************************************************************/
465 static int ioctl_set_channel(void *arg)
467 struct video_channel *v;
471 if (retval == 0 && v->channel != 0)
477 /******************************************************************************
479 * ioctl_set_image_prop
481 *****************************************************************************/
482 static int ioctl_set_image_prop(void *arg, struct camera_data *cam)
484 struct video_picture *vp;
488 /* brightness, color, contrast need no check 0-65535 */
489 memcpy(&cam->vp, vp, sizeof(*vp));
491 /* update cam->params.colorParams */
492 cam->params.color_params.brightness = vp->brightness / 256;
493 cam->params.color_params.saturation = vp->colour / 256;
494 cam->params.color_params.contrast = vp->contrast / 256;
496 DBG("Requested params: bright 0x%X, sat 0x%X, contrast 0x%X\n",
497 cam->params.color_params.brightness,
498 cam->params.color_params.saturation,
499 cam->params.color_params.contrast);
501 cpia2_set_color_params(cam);
506 static int sync(struct camera_data *cam, int frame_nr)
508 struct framebuf *frame = &cam->buffers[frame_nr];
511 if (frame->status == FRAME_READY)
514 if (!cam->streaming) {
515 frame->status = FRAME_READY;
520 mutex_unlock(&cam->busy_lock);
521 wait_event_interruptible(cam->wq_stream,
523 frame->status == FRAME_READY);
524 mutex_lock(&cam->busy_lock);
525 if (signal_pending(current))
532 /******************************************************************************
534 * ioctl_set_window_size
536 *****************************************************************************/
537 static int ioctl_set_window_size(void *arg, struct camera_data *cam,
540 /* copy_from_user, check validity, copy to internal structure */
541 struct video_window *vw;
545 if (vw->clipcount != 0) /* clipping not supported */
548 if (vw->clips != NULL) /* clipping not supported */
551 /* Ensure that only this process can change the format. */
552 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
556 cam->pixelformat = V4L2_PIX_FMT_JPEG;
558 /* Be sure to supply the Huffman tables, this isn't MJPEG */
559 cam->params.compression.inhibit_htables = 0;
561 /* we set the video window to something smaller or equal to what
562 * is requested by the user???
564 DBG("Requested width = %d, height = %d\n", vw->width, vw->height);
565 if (vw->width != cam->vw.width || vw->height != cam->vw.height) {
566 cam->vw.width = vw->width;
567 cam->vw.height = vw->height;
568 cam->params.roi.width = vw->width;
569 cam->params.roi.height = vw->height;
570 cpia2_set_format(cam);
573 for (frame = 0; frame < cam->num_frames; ++frame) {
574 if (cam->buffers[frame].status == FRAME_READING)
575 if ((err = sync(cam, frame)) < 0)
578 cam->buffers[frame].status = FRAME_EMPTY;
584 /******************************************************************************
588 *****************************************************************************/
589 static int ioctl_get_mbuf(void *arg, struct camera_data *cam)
591 struct video_mbuf *vm;
595 memset(vm, 0, sizeof(*vm));
596 vm->size = cam->frame_size*cam->num_frames;
597 vm->frames = cam->num_frames;
598 for (i = 0; i < cam->num_frames; i++)
599 vm->offsets[i] = cam->frame_size * i;
604 /******************************************************************************
608 *****************************************************************************/
609 static int ioctl_mcapture(void *arg, struct camera_data *cam,
612 struct video_mmap *vm;
616 if (vm->frame < 0 || vm->frame >= cam->num_frames)
620 video_size = cpia2_match_video_size(vm->width, vm->height);
621 if (cam->video_size < 0) {
625 /* Ensure that only this process can change the format. */
626 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
630 if (video_size != cam->video_size) {
631 cam->video_size = video_size;
632 cam->params.roi.width = vm->width;
633 cam->params.roi.height = vm->height;
634 cpia2_set_format(cam);
637 if (cam->buffers[vm->frame].status == FRAME_READING)
638 if ((err=sync(cam, vm->frame)) < 0)
641 cam->buffers[vm->frame].status = FRAME_EMPTY;
643 return cpia2_usb_stream_start(cam,cam->params.camera_state.stream_mode);
646 /******************************************************************************
650 *****************************************************************************/
651 static int ioctl_sync(void *arg, struct camera_data *cam)
657 if (frame < 0 || frame >= cam->num_frames)
660 return sync(cam, frame);
664 /******************************************************************************
668 *****************************************************************************/
670 static int ioctl_set_gpio(void *arg, struct camera_data *cam)
674 gpio_val = *(__u32*) arg;
676 if (gpio_val &~ 0xFFU)
679 return cpia2_set_gpio(cam, (unsigned char)gpio_val);
682 /******************************************************************************
686 * V4L2 device capabilities
688 *****************************************************************************/
690 static int ioctl_querycap(void *arg, struct camera_data *cam)
692 struct v4l2_capability *vc = arg;
694 memset(vc, 0, sizeof(*vc));
695 strcpy(vc->driver, "cpia2");
697 if (cam->params.pnp_id.product == 0x151)
698 strcpy(vc->card, "QX5 Microscope");
700 strcpy(vc->card, "CPiA2 Camera");
701 switch (cam->params.pnp_id.device_type) {
703 strcat(vc->card, " (672/");
706 strcat(vc->card, " (676/");
709 strcat(vc->card, " (???/");
712 switch (cam->params.version.sensor_flags) {
713 case CPIA2_VP_SENSOR_FLAGS_404:
714 strcat(vc->card, "404)");
716 case CPIA2_VP_SENSOR_FLAGS_407:
717 strcat(vc->card, "407)");
719 case CPIA2_VP_SENSOR_FLAGS_409:
720 strcat(vc->card, "409)");
722 case CPIA2_VP_SENSOR_FLAGS_410:
723 strcat(vc->card, "410)");
725 case CPIA2_VP_SENSOR_FLAGS_500:
726 strcat(vc->card, "500)");
729 strcat(vc->card, "???)");
733 if (usb_make_path(cam->dev, vc->bus_info, sizeof(vc->bus_info)) <0)
734 memset(vc->bus_info,0, sizeof(vc->bus_info));
736 vc->version = KERNEL_VERSION(CPIA2_MAJ_VER, CPIA2_MIN_VER,
739 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
746 /******************************************************************************
750 * V4L2 input get/set/enumerate
752 *****************************************************************************/
754 static int ioctl_input(unsigned int ioclt_nr,void *arg,struct camera_data *cam)
756 struct v4l2_input *i = arg;
758 if(ioclt_nr != VIDIOC_G_INPUT) {
763 memset(i, 0, sizeof(*i));
764 strcpy(i->name, "Camera");
765 i->type = V4L2_INPUT_TYPE_CAMERA;
770 /******************************************************************************
774 * V4L2 format enumerate
776 *****************************************************************************/
778 static int ioctl_enum_fmt(void *arg,struct camera_data *cam)
780 struct v4l2_fmtdesc *f = arg;
781 int index = f->index;
783 if (index < 0 || index > 1)
786 memset(f, 0, sizeof(*f));
788 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
789 f->flags = V4L2_FMT_FLAG_COMPRESSED;
792 strcpy(f->description, "MJPEG");
793 f->pixelformat = V4L2_PIX_FMT_MJPEG;
796 strcpy(f->description, "JPEG");
797 f->pixelformat = V4L2_PIX_FMT_JPEG;
806 /******************************************************************************
812 *****************************************************************************/
814 static int ioctl_try_fmt(void *arg,struct camera_data *cam)
816 struct v4l2_format *f = arg;
818 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
821 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG &&
822 f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG)
825 f->fmt.pix.field = V4L2_FIELD_NONE;
826 f->fmt.pix.bytesperline = 0;
827 f->fmt.pix.sizeimage = cam->frame_size;
828 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
831 switch (cpia2_match_video_size(f->fmt.pix.width, f->fmt.pix.height)) {
833 f->fmt.pix.width = 640;
834 f->fmt.pix.height = 480;
837 f->fmt.pix.width = 352;
838 f->fmt.pix.height = 288;
841 f->fmt.pix.width = 320;
842 f->fmt.pix.height = 240;
844 case VIDEOSIZE_288_216:
845 f->fmt.pix.width = 288;
846 f->fmt.pix.height = 216;
848 case VIDEOSIZE_256_192:
849 f->fmt.pix.width = 256;
850 f->fmt.pix.height = 192;
852 case VIDEOSIZE_224_168:
853 f->fmt.pix.width = 224;
854 f->fmt.pix.height = 168;
856 case VIDEOSIZE_192_144:
857 f->fmt.pix.width = 192;
858 f->fmt.pix.height = 144;
862 f->fmt.pix.width = 176;
863 f->fmt.pix.height = 144;
870 /******************************************************************************
876 *****************************************************************************/
878 static int ioctl_set_fmt(void *arg,struct camera_data *cam, struct cpia2_fh *fh)
880 struct v4l2_format *f = arg;
883 err = ioctl_try_fmt(arg, cam);
887 /* Ensure that only this process can change the format. */
888 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
893 cam->pixelformat = f->fmt.pix.pixelformat;
895 /* NOTE: This should be set to 1 for MJPEG, but some apps don't handle
896 * the missing Huffman table properly. */
897 cam->params.compression.inhibit_htables = 0;
898 /*f->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG;*/
900 /* we set the video window to something smaller or equal to what
901 * is requested by the user???
903 DBG("Requested width = %d, height = %d\n",
904 f->fmt.pix.width, f->fmt.pix.height);
905 if (f->fmt.pix.width != cam->vw.width ||
906 f->fmt.pix.height != cam->vw.height) {
907 cam->vw.width = f->fmt.pix.width;
908 cam->vw.height = f->fmt.pix.height;
909 cam->params.roi.width = f->fmt.pix.width;
910 cam->params.roi.height = f->fmt.pix.height;
911 cpia2_set_format(cam);
914 for (frame = 0; frame < cam->num_frames; ++frame) {
915 if (cam->buffers[frame].status == FRAME_READING)
916 if ((err = sync(cam, frame)) < 0)
919 cam->buffers[frame].status = FRAME_EMPTY;
925 /******************************************************************************
931 *****************************************************************************/
933 static int ioctl_get_fmt(void *arg,struct camera_data *cam)
935 struct v4l2_format *f = arg;
937 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
940 f->fmt.pix.width = cam->vw.width;
941 f->fmt.pix.height = cam->vw.height;
942 f->fmt.pix.pixelformat = cam->pixelformat;
943 f->fmt.pix.field = V4L2_FIELD_NONE;
944 f->fmt.pix.bytesperline = 0;
945 f->fmt.pix.sizeimage = cam->frame_size;
946 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
952 /******************************************************************************
956 * V4L2 query cropping capabilities
957 * NOTE: cropping is currently disabled
959 *****************************************************************************/
961 static int ioctl_cropcap(void *arg,struct camera_data *cam)
963 struct v4l2_cropcap *c = arg;
965 if (c->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
970 c->bounds.width = cam->vw.width;
971 c->bounds.height = cam->vw.height;
974 c->defrect.width = cam->vw.width;
975 c->defrect.height = cam->vw.height;
976 c->pixelaspect.numerator = 1;
977 c->pixelaspect.denominator = 1;
982 /******************************************************************************
986 * V4L2 query possible control variables
988 *****************************************************************************/
990 static int ioctl_queryctrl(void *arg,struct camera_data *cam)
992 struct v4l2_queryctrl *c = arg;
995 for(i=0; i<NUM_CONTROLS; ++i) {
996 if(c->id == controls[i].id) {
997 memcpy(c, controls+i, sizeof(*c));
1002 if(i == NUM_CONTROLS)
1005 /* Some devices have additional limitations */
1007 case V4L2_CID_BRIGHTNESS:
1009 * Don't let the register be set to zero - bug in VP4
1010 * flash of full brightness
1012 if (cam->params.pnp_id.device_type == DEVICE_STV_672)
1015 case V4L2_CID_VFLIP:
1017 if(cam->params.pnp_id.device_type == DEVICE_STV_672)
1018 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1020 case CPIA2_CID_FRAMERATE:
1021 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
1022 cam->params.version.sensor_flags==CPIA2_VP_SENSOR_FLAGS_500){
1024 for(i=0; i<c->maximum; ++i) {
1025 if(framerate_controls[i].value ==
1026 CPIA2_VP_FRAMERATE_15) {
1028 c->default_value = i;
1033 case CPIA2_CID_FLICKER_MODE:
1034 // Flicker control only valid for 672.
1035 if(cam->params.pnp_id.device_type != DEVICE_STV_672)
1036 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1038 case CPIA2_CID_LIGHTS:
1039 // Light control only valid for the QX5 Microscope.
1040 if(cam->params.pnp_id.product != 0x151)
1041 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1050 /******************************************************************************
1054 * V4L2 query possible control variables
1056 *****************************************************************************/
1058 static int ioctl_querymenu(void *arg,struct camera_data *cam)
1060 struct v4l2_querymenu *m = arg;
1062 memset(m->name, 0, sizeof(m->name));
1066 case CPIA2_CID_FLICKER_MODE:
1067 if(m->index < 0 || m->index >= NUM_FLICKER_CONTROLS)
1070 strcpy(m->name, flicker_controls[m->index].name);
1072 case CPIA2_CID_FRAMERATE:
1074 int maximum = NUM_FRAMERATE_CONTROLS - 1;
1075 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
1076 cam->params.version.sensor_flags==CPIA2_VP_SENSOR_FLAGS_500){
1079 for(i=0; i<maximum; ++i) {
1080 if(framerate_controls[i].value ==
1081 CPIA2_VP_FRAMERATE_15)
1085 if(m->index < 0 || m->index > maximum)
1088 strcpy(m->name, framerate_controls[m->index].name);
1091 case CPIA2_CID_LIGHTS:
1092 if(m->index < 0 || m->index >= NUM_LIGHTS_CONTROLS)
1095 strcpy(m->name, lights_controls[m->index].name);
1104 /******************************************************************************
1108 * V4L2 get the value of a control variable
1110 *****************************************************************************/
1112 static int ioctl_g_ctrl(void *arg,struct camera_data *cam)
1114 struct v4l2_control *c = arg;
1117 case V4L2_CID_BRIGHTNESS:
1118 cpia2_do_command(cam, CPIA2_CMD_GET_VP_BRIGHTNESS,
1120 c->value = cam->params.color_params.brightness;
1122 case V4L2_CID_CONTRAST:
1123 cpia2_do_command(cam, CPIA2_CMD_GET_CONTRAST,
1125 c->value = cam->params.color_params.contrast;
1127 case V4L2_CID_SATURATION:
1128 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SATURATION,
1130 c->value = cam->params.color_params.saturation;
1132 case V4L2_CID_HFLIP:
1133 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS,
1135 c->value = (cam->params.vp_params.user_effects &
1136 CPIA2_VP_USER_EFFECTS_MIRROR) != 0;
1138 case V4L2_CID_VFLIP:
1139 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS,
1141 c->value = (cam->params.vp_params.user_effects &
1142 CPIA2_VP_USER_EFFECTS_FLIP) != 0;
1144 case CPIA2_CID_TARGET_KB:
1145 c->value = cam->params.vc_params.target_kb;
1147 case CPIA2_CID_GPIO:
1148 cpia2_do_command(cam, CPIA2_CMD_GET_VP_GPIO_DATA,
1150 c->value = cam->params.vp_params.gpio_data;
1152 case CPIA2_CID_FLICKER_MODE:
1155 cpia2_do_command(cam, CPIA2_CMD_GET_FLICKER_MODES,
1157 if(cam->params.flicker_control.cam_register &
1158 CPIA2_VP_FLICKER_MODES_NEVER_FLICKER) {
1159 mode = NEVER_FLICKER;
1161 if(cam->params.flicker_control.cam_register &
1162 CPIA2_VP_FLICKER_MODES_50HZ) {
1168 for(i=0; i<NUM_FLICKER_CONTROLS; i++) {
1169 if(flicker_controls[i].value == mode) {
1174 if(i == NUM_FLICKER_CONTROLS)
1178 case CPIA2_CID_FRAMERATE:
1180 int maximum = NUM_FRAMERATE_CONTROLS - 1;
1182 for(i=0; i<= maximum; i++) {
1183 if(cam->params.vp_params.frame_rate ==
1184 framerate_controls[i].value)
1192 case CPIA2_CID_USB_ALT:
1193 c->value = cam->params.camera_state.stream_mode;
1195 case CPIA2_CID_LIGHTS:
1198 cpia2_do_command(cam, CPIA2_CMD_GET_VP_GPIO_DATA,
1200 for(i=0; i<NUM_LIGHTS_CONTROLS; i++) {
1201 if((cam->params.vp_params.gpio_data&GPIO_LIGHTS_MASK) ==
1202 lights_controls[i].value) {
1206 if(i == NUM_LIGHTS_CONTROLS)
1211 case CPIA2_CID_RESET_CAMERA:
1217 DBG("Get control id:%d, value:%d\n", c->id, c->value);
1222 /******************************************************************************
1226 * V4L2 set the value of a control variable
1228 *****************************************************************************/
1230 static int ioctl_s_ctrl(void *arg,struct camera_data *cam)
1232 struct v4l2_control *c = arg;
1236 DBG("Set control id:%d, value:%d\n", c->id, c->value);
1238 /* Check that the value is in range */
1239 for(i=0; i<NUM_CONTROLS; i++) {
1240 if(c->id == controls[i].id) {
1241 if(c->value < controls[i].minimum ||
1242 c->value > controls[i].maximum) {
1248 if(i == NUM_CONTROLS)
1252 case V4L2_CID_BRIGHTNESS:
1253 cpia2_set_brightness(cam, c->value);
1255 case V4L2_CID_CONTRAST:
1256 cpia2_set_contrast(cam, c->value);
1258 case V4L2_CID_SATURATION:
1259 cpia2_set_saturation(cam, c->value);
1261 case V4L2_CID_HFLIP:
1262 cpia2_set_property_mirror(cam, c->value);
1264 case V4L2_CID_VFLIP:
1265 cpia2_set_property_flip(cam, c->value);
1267 case CPIA2_CID_TARGET_KB:
1268 retval = cpia2_set_target_kb(cam, c->value);
1270 case CPIA2_CID_GPIO:
1271 retval = cpia2_set_gpio(cam, c->value);
1273 case CPIA2_CID_FLICKER_MODE:
1274 retval = cpia2_set_flicker_mode(cam,
1275 flicker_controls[c->value].value);
1277 case CPIA2_CID_FRAMERATE:
1278 retval = cpia2_set_fps(cam, framerate_controls[c->value].value);
1280 case CPIA2_CID_USB_ALT:
1281 retval = cpia2_usb_change_streaming_alternate(cam, c->value);
1283 case CPIA2_CID_LIGHTS:
1284 retval = cpia2_set_gpio(cam, lights_controls[c->value].value);
1286 case CPIA2_CID_RESET_CAMERA:
1287 cpia2_usb_stream_pause(cam);
1288 cpia2_reset_camera(cam);
1289 cpia2_usb_stream_resume(cam);
1298 /******************************************************************************
1302 * V4L2 get the JPEG compression parameters
1304 *****************************************************************************/
1306 static int ioctl_g_jpegcomp(void *arg,struct camera_data *cam)
1308 struct v4l2_jpegcompression *parms = arg;
1310 memset(parms, 0, sizeof(*parms));
1312 parms->quality = 80; // TODO: Can this be made meaningful?
1314 parms->jpeg_markers = V4L2_JPEG_MARKER_DQT | V4L2_JPEG_MARKER_DRI;
1315 if(!cam->params.compression.inhibit_htables) {
1316 parms->jpeg_markers |= V4L2_JPEG_MARKER_DHT;
1319 parms->APPn = cam->APPn;
1320 parms->APP_len = cam->APP_len;
1321 if(cam->APP_len > 0) {
1322 memcpy(parms->APP_data, cam->APP_data, cam->APP_len);
1323 parms->jpeg_markers |= V4L2_JPEG_MARKER_APP;
1326 parms->COM_len = cam->COM_len;
1327 if(cam->COM_len > 0) {
1328 memcpy(parms->COM_data, cam->COM_data, cam->COM_len);
1329 parms->jpeg_markers |= JPEG_MARKER_COM;
1332 DBG("G_JPEGCOMP APP_len:%d COM_len:%d\n",
1333 parms->APP_len, parms->COM_len);
1338 /******************************************************************************
1342 * V4L2 set the JPEG compression parameters
1343 * NOTE: quality and some jpeg_markers are ignored.
1345 *****************************************************************************/
1347 static int ioctl_s_jpegcomp(void *arg,struct camera_data *cam)
1349 struct v4l2_jpegcompression *parms = arg;
1351 DBG("S_JPEGCOMP APP_len:%d COM_len:%d\n",
1352 parms->APP_len, parms->COM_len);
1354 cam->params.compression.inhibit_htables =
1355 !(parms->jpeg_markers & V4L2_JPEG_MARKER_DHT);
1357 if(parms->APP_len != 0) {
1358 if(parms->APP_len > 0 &&
1359 parms->APP_len <= sizeof(cam->APP_data) &&
1360 parms->APPn >= 0 && parms->APPn <= 15) {
1361 cam->APPn = parms->APPn;
1362 cam->APP_len = parms->APP_len;
1363 memcpy(cam->APP_data, parms->APP_data, parms->APP_len);
1365 LOG("Bad APPn Params n=%d len=%d\n",
1366 parms->APPn, parms->APP_len);
1373 if(parms->COM_len != 0) {
1374 if(parms->COM_len > 0 &&
1375 parms->COM_len <= sizeof(cam->COM_data)) {
1376 cam->COM_len = parms->COM_len;
1377 memcpy(cam->COM_data, parms->COM_data, parms->COM_len);
1379 LOG("Bad COM_len=%d\n", parms->COM_len);
1387 /******************************************************************************
1391 * V4L2 Initiate memory mapping.
1392 * NOTE: The user's request is ignored. For now the buffers are fixed.
1394 *****************************************************************************/
1396 static int ioctl_reqbufs(void *arg,struct camera_data *cam)
1398 struct v4l2_requestbuffers *req = arg;
1400 if(req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1401 req->memory != V4L2_MEMORY_MMAP)
1404 DBG("REQBUFS requested:%d returning:%d\n", req->count, cam->num_frames);
1405 req->count = cam->num_frames;
1406 memset(&req->reserved, 0, sizeof(req->reserved));
1411 /******************************************************************************
1415 * V4L2 Query memory buffer status.
1417 *****************************************************************************/
1419 static int ioctl_querybuf(void *arg,struct camera_data *cam)
1421 struct v4l2_buffer *buf = arg;
1423 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1424 buf->index > cam->num_frames)
1427 buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
1428 buf->length = cam->frame_size;
1430 buf->memory = V4L2_MEMORY_MMAP;
1433 buf->flags = V4L2_BUF_FLAG_MAPPED;
1437 switch (cam->buffers[buf->index].status) {
1442 buf->flags = V4L2_BUF_FLAG_QUEUED;
1445 buf->bytesused = cam->buffers[buf->index].length;
1446 buf->timestamp = cam->buffers[buf->index].timestamp;
1447 buf->sequence = cam->buffers[buf->index].seq;
1448 buf->flags = V4L2_BUF_FLAG_DONE;
1452 DBG("QUERYBUF index:%d offset:%d flags:%d seq:%d bytesused:%d\n",
1453 buf->index, buf->m.offset, buf->flags, buf->sequence,
1459 /******************************************************************************
1463 * V4L2 User is freeing buffer
1465 *****************************************************************************/
1467 static int ioctl_qbuf(void *arg,struct camera_data *cam)
1469 struct v4l2_buffer *buf = arg;
1471 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1472 buf->memory != V4L2_MEMORY_MMAP ||
1473 buf->index > cam->num_frames)
1476 DBG("QBUF #%d\n", buf->index);
1478 if(cam->buffers[buf->index].status == FRAME_READY)
1479 cam->buffers[buf->index].status = FRAME_EMPTY;
1484 /******************************************************************************
1486 * find_earliest_filled_buffer
1488 * Helper for ioctl_dqbuf. Find the next ready buffer.
1490 *****************************************************************************/
1492 static int find_earliest_filled_buffer(struct camera_data *cam)
1496 for (i=0; i<cam->num_frames; i++) {
1497 if(cam->buffers[i].status == FRAME_READY) {
1501 /* find which buffer is earlier */
1502 struct timeval *tv1, *tv2;
1503 tv1 = &cam->buffers[i].timestamp;
1504 tv2 = &cam->buffers[found].timestamp;
1505 if(tv1->tv_sec < tv2->tv_sec ||
1506 (tv1->tv_sec == tv2->tv_sec &&
1507 tv1->tv_usec < tv2->tv_usec))
1515 /******************************************************************************
1519 * V4L2 User is asking for a filled buffer.
1521 *****************************************************************************/
1523 static int ioctl_dqbuf(void *arg,struct camera_data *cam, struct file *file)
1525 struct v4l2_buffer *buf = arg;
1528 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1529 buf->memory != V4L2_MEMORY_MMAP)
1532 frame = find_earliest_filled_buffer(cam);
1534 if(frame < 0 && file->f_flags&O_NONBLOCK)
1538 /* Wait for a frame to become available */
1539 struct framebuf *cb=cam->curbuff;
1540 mutex_unlock(&cam->busy_lock);
1541 wait_event_interruptible(cam->wq_stream,
1543 (cb=cam->curbuff)->status == FRAME_READY);
1544 mutex_lock(&cam->busy_lock);
1545 if (signal_pending(current))
1546 return -ERESTARTSYS;
1554 buf->bytesused = cam->buffers[buf->index].length;
1555 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE;
1556 buf->field = V4L2_FIELD_NONE;
1557 buf->timestamp = cam->buffers[buf->index].timestamp;
1558 buf->sequence = cam->buffers[buf->index].seq;
1559 buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
1560 buf->length = cam->frame_size;
1563 memset(&buf->timecode, 0, sizeof(buf->timecode));
1565 DBG("DQBUF #%d status:%d seq:%d length:%d\n", buf->index,
1566 cam->buffers[buf->index].status, buf->sequence, buf->bytesused);
1571 /******************************************************************************
1575 *****************************************************************************/
1576 static long cpia2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
1578 struct camera_data *cam = video_drvdata(file);
1584 /* make this _really_ smp-safe */
1585 if (mutex_lock_interruptible(&cam->busy_lock))
1586 return -ERESTARTSYS;
1588 if (!cam->present) {
1589 mutex_unlock(&cam->busy_lock);
1593 /* Priority check */
1596 case VIDIOCMCAPTURE:
1599 struct cpia2_fh *fh = file->private_data;
1600 retval = v4l2_prio_check(&cam->prio, &fh->prio);
1602 mutex_unlock(&cam->busy_lock);
1610 struct cpia2_fh *fh = file->private_data;
1611 if(fh->prio != V4L2_PRIORITY_RECORD) {
1612 mutex_unlock(&cam->busy_lock);
1622 case VIDIOCGCAP: /* query capabilities */
1623 retval = ioctl_cap_query(arg, cam);
1626 case VIDIOCGCHAN: /* get video source - we are a camera, nothing else */
1627 retval = ioctl_get_channel(arg);
1629 case VIDIOCSCHAN: /* set video source - we are a camera, nothing else */
1630 retval = ioctl_set_channel(arg);
1632 case VIDIOCGPICT: /* image properties */
1633 memcpy(arg, &cam->vp, sizeof(struct video_picture));
1636 retval = ioctl_set_image_prop(arg, cam);
1638 case VIDIOCGWIN: /* get/set capture window */
1639 memcpy(arg, &cam->vw, sizeof(struct video_window));
1642 retval = ioctl_set_window_size(arg, cam, file->private_data);
1644 case VIDIOCGMBUF: /* mmap interface */
1645 retval = ioctl_get_mbuf(arg, cam);
1647 case VIDIOCMCAPTURE:
1648 retval = ioctl_mcapture(arg, cam, file->private_data);
1651 retval = ioctl_sync(arg, cam);
1653 /* pointless to implement overlay with this camera */
1661 /* tuner interface - we have none */
1669 /* audio interface - we have none */
1675 /* CPIA2 extension to Video4Linux API */
1676 case CPIA2_IOC_SET_GPIO:
1677 retval = ioctl_set_gpio(arg, cam);
1679 case VIDIOC_QUERYCAP:
1680 retval = ioctl_querycap(arg,cam);
1683 case VIDIOC_ENUMINPUT:
1684 case VIDIOC_G_INPUT:
1685 case VIDIOC_S_INPUT:
1686 retval = ioctl_input(cmd, arg, cam);
1689 case VIDIOC_ENUM_FMT:
1690 retval = ioctl_enum_fmt(arg,cam);
1692 case VIDIOC_TRY_FMT:
1693 retval = ioctl_try_fmt(arg,cam);
1696 retval = ioctl_get_fmt(arg,cam);
1699 retval = ioctl_set_fmt(arg,cam,file->private_data);
1702 case VIDIOC_CROPCAP:
1703 retval = ioctl_cropcap(arg,cam);
1707 // TODO: I think cropping can be implemented - SJB
1711 case VIDIOC_QUERYCTRL:
1712 retval = ioctl_queryctrl(arg,cam);
1714 case VIDIOC_QUERYMENU:
1715 retval = ioctl_querymenu(arg,cam);
1718 retval = ioctl_g_ctrl(arg,cam);
1721 retval = ioctl_s_ctrl(arg,cam);
1724 case VIDIOC_G_JPEGCOMP:
1725 retval = ioctl_g_jpegcomp(arg,cam);
1727 case VIDIOC_S_JPEGCOMP:
1728 retval = ioctl_s_jpegcomp(arg,cam);
1731 case VIDIOC_G_PRIORITY:
1733 struct cpia2_fh *fh = file->private_data;
1734 *(enum v4l2_priority*)arg = fh->prio;
1737 case VIDIOC_S_PRIORITY:
1739 struct cpia2_fh *fh = file->private_data;
1740 enum v4l2_priority prio;
1741 prio = *(enum v4l2_priority*)arg;
1742 if(cam->streaming &&
1744 fh->prio == V4L2_PRIORITY_RECORD) {
1745 /* Can't drop record priority while streaming */
1747 } else if(prio == V4L2_PRIORITY_RECORD &&
1749 v4l2_prio_max(&cam->prio) == V4L2_PRIORITY_RECORD) {
1750 /* Only one program can record at a time */
1753 retval = v4l2_prio_change(&cam->prio, &fh->prio, prio);
1758 case VIDIOC_REQBUFS:
1759 retval = ioctl_reqbufs(arg,cam);
1761 case VIDIOC_QUERYBUF:
1762 retval = ioctl_querybuf(arg,cam);
1765 retval = ioctl_qbuf(arg,cam);
1768 retval = ioctl_dqbuf(arg,cam,file);
1770 case VIDIOC_STREAMON:
1773 DBG("VIDIOC_STREAMON, streaming=%d\n", cam->streaming);
1775 if(!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1778 if(!cam->streaming) {
1779 retval = cpia2_usb_stream_start(cam,
1780 cam->params.camera_state.stream_mode);
1787 case VIDIOC_STREAMOFF:
1790 DBG("VIDIOC_STREAMOFF, streaming=%d\n", cam->streaming);
1792 if(!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1795 if(cam->streaming) {
1796 retval = cpia2_usb_stream_stop(cam);
1804 case VIDIOC_ENUMOUTPUT:
1805 case VIDIOC_G_OUTPUT:
1806 case VIDIOC_S_OUTPUT:
1807 case VIDIOC_G_MODULATOR:
1808 case VIDIOC_S_MODULATOR:
1810 case VIDIOC_ENUMAUDIO:
1811 case VIDIOC_G_AUDIO:
1812 case VIDIOC_S_AUDIO:
1814 case VIDIOC_ENUMAUDOUT:
1815 case VIDIOC_G_AUDOUT:
1816 case VIDIOC_S_AUDOUT:
1818 case VIDIOC_ENUMSTD:
1819 case VIDIOC_QUERYSTD:
1823 case VIDIOC_G_TUNER:
1824 case VIDIOC_S_TUNER:
1825 case VIDIOC_G_FREQUENCY:
1826 case VIDIOC_S_FREQUENCY:
1828 case VIDIOC_OVERLAY:
1837 retval = -ENOIOCTLCMD;
1841 mutex_unlock(&cam->busy_lock);
1845 static long cpia2_ioctl(struct file *file,
1846 unsigned int cmd, unsigned long arg)
1848 return video_usercopy(file, cmd, arg, cpia2_do_ioctl);
1851 /******************************************************************************
1855 *****************************************************************************/
1856 static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
1858 struct camera_data *cam = video_drvdata(file);
1861 /* Priority check */
1862 struct cpia2_fh *fh = file->private_data;
1863 if(fh->prio != V4L2_PRIORITY_RECORD) {
1867 retval = cpia2_remap_buffer(cam, area);
1874 /******************************************************************************
1876 * reset_camera_struct_v4l
1878 * Sets all values to the defaults
1879 *****************************************************************************/
1880 static void reset_camera_struct_v4l(struct camera_data *cam)
1883 * Fill in the v4l structures. video_cap is filled in inside the VIDIOCCAP
1884 * Ioctl. Here, just do the window and picture stucts.
1886 cam->vp.palette = (u16) VIDEO_PALETTE_RGB24; /* Is this right? */
1887 cam->vp.brightness = (u16) cam->params.color_params.brightness * 256;
1888 cam->vp.colour = (u16) cam->params.color_params.saturation * 256;
1889 cam->vp.contrast = (u16) cam->params.color_params.contrast * 256;
1893 cam->vw.width = cam->params.roi.width;
1894 cam->vw.height = cam->params.roi.height;
1896 cam->vw.clipcount = 0;
1898 cam->frame_size = buffer_size;
1899 cam->num_frames = num_buffers;
1902 cam->params.flicker_control.flicker_mode_req = flicker_mode;
1903 cam->params.flicker_control.mains_frequency = flicker_freq;
1906 cam->params.camera_state.stream_mode = alternate;
1908 cam->pixelformat = V4L2_PIX_FMT_JPEG;
1909 v4l2_prio_init(&cam->prio);
1914 * The v4l video device structure initialized for this device
1916 static const struct v4l2_file_operations fops_template = {
1917 .owner = THIS_MODULE,
1919 .release = cpia2_close,
1920 .read = cpia2_v4l_read,
1921 .poll = cpia2_v4l_poll,
1922 .ioctl = cpia2_ioctl,
1926 static struct video_device cpia2_template = {
1927 /* I could not find any place for the old .initialize initializer?? */
1928 .name= "CPiA2 Camera",
1930 .fops= &fops_template,
1931 .release= video_device_release,
1934 /******************************************************************************
1936 * cpia2_register_camera
1938 *****************************************************************************/
1939 int cpia2_register_camera(struct camera_data *cam)
1941 cam->vdev = video_device_alloc();
1945 memcpy(cam->vdev, &cpia2_template, sizeof(cpia2_template));
1946 video_set_drvdata(cam->vdev, cam);
1948 reset_camera_struct_v4l(cam);
1950 /* register v4l device */
1951 if (video_register_device(cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
1952 ERR("video_register_device failed\n");
1953 video_device_release(cam->vdev);
1960 /******************************************************************************
1962 * cpia2_unregister_camera
1964 *****************************************************************************/
1965 void cpia2_unregister_camera(struct camera_data *cam)
1967 if (!cam->open_count) {
1968 video_unregister_device(cam->vdev);
1970 LOG("/dev/video%d removed while open, "
1971 "deferring video_unregister_device\n",
1976 /******************************************************************************
1980 * Make sure that all user-supplied parameters are sensible
1981 *****************************************************************************/
1982 static void __init check_parameters(void)
1984 if(buffer_size < PAGE_SIZE) {
1985 buffer_size = PAGE_SIZE;
1986 LOG("buffer_size too small, setting to %d\n", buffer_size);
1987 } else if(buffer_size > 1024*1024) {
1988 /* arbitrary upper limiit */
1989 buffer_size = 1024*1024;
1990 LOG("buffer_size ridiculously large, setting to %d\n",
1993 buffer_size += PAGE_SIZE-1;
1994 buffer_size &= ~(PAGE_SIZE-1);
1997 if(num_buffers < 1) {
1999 LOG("num_buffers too small, setting to %d\n", num_buffers);
2000 } else if(num_buffers > VIDEO_MAX_FRAME) {
2001 num_buffers = VIDEO_MAX_FRAME;
2002 LOG("num_buffers too large, setting to %d\n", num_buffers);
2005 if(alternate < USBIF_ISO_1 || alternate > USBIF_ISO_6) {
2006 alternate = DEFAULT_ALT;
2007 LOG("alternate specified is invalid, using %d\n", alternate);
2010 if (flicker_mode != NEVER_FLICKER && flicker_mode != ANTI_FLICKER_ON) {
2011 flicker_mode = NEVER_FLICKER;
2012 LOG("Flicker mode specified is invalid, using %d\n",
2016 if (flicker_freq != FLICKER_50 && flicker_freq != FLICKER_60) {
2017 flicker_freq = FLICKER_60;
2018 LOG("Flicker mode specified is invalid, using %d\n",
2022 if(video_nr < -1 || video_nr > 64) {
2024 LOG("invalid video_nr specified, must be -1 to 64\n");
2027 DBG("Using %d buffers, each %d bytes, alternate=%d\n",
2028 num_buffers, buffer_size, alternate);
2031 /************ Module Stuff ***************/
2034 /******************************************************************************
2036 * cpia2_init/module_init
2038 *****************************************************************************/
2039 static int __init cpia2_init(void)
2041 LOG("%s v%d.%d.%d\n",
2042 ABOUT, CPIA2_MAJ_VER, CPIA2_MIN_VER, CPIA2_PATCH_VER);
2049 /******************************************************************************
2051 * cpia2_exit/module_exit
2053 *****************************************************************************/
2054 static void __exit cpia2_exit(void)
2056 cpia2_usb_cleanup();
2057 schedule_timeout(2 * HZ);
2060 module_init(cpia2_init);
2061 module_exit(cpia2_exit);