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@redhat.com>
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 <media/v4l2-ioctl.h>
46 //#define _CPIA2_DEBUG_
48 #define MAKE_STRING_1(x) #x
49 #define MAKE_STRING(x) MAKE_STRING_1(x)
51 static int video_nr = -1;
52 module_param(video_nr, int, 0);
53 MODULE_PARM_DESC(video_nr,"video device to register (0=/dev/video0, etc)");
55 static int buffer_size = 68*1024;
56 module_param(buffer_size, int, 0);
57 MODULE_PARM_DESC(buffer_size, "Size for each frame buffer in bytes (default 68k)");
59 static int num_buffers = 3;
60 module_param(num_buffers, int, 0);
61 MODULE_PARM_DESC(num_buffers, "Number of frame buffers (1-"
62 MAKE_STRING(VIDEO_MAX_FRAME) ", default 3)");
64 static int alternate = DEFAULT_ALT;
65 module_param(alternate, int, 0);
66 MODULE_PARM_DESC(alternate, "USB Alternate (" MAKE_STRING(USBIF_ISO_1) "-"
67 MAKE_STRING(USBIF_ISO_6) ", default "
68 MAKE_STRING(DEFAULT_ALT) ")");
70 static int flicker_freq = 60;
71 module_param(flicker_freq, int, 0);
72 MODULE_PARM_DESC(flicker_freq, "Flicker frequency (" MAKE_STRING(50) "or"
73 MAKE_STRING(60) ", default "
76 static int flicker_mode = NEVER_FLICKER;
77 module_param(flicker_mode, int, 0);
78 MODULE_PARM_DESC(flicker_mode,
79 "Flicker supression (" MAKE_STRING(NEVER_FLICKER) "or"
80 MAKE_STRING(ANTI_FLICKER_ON) ", default "
81 MAKE_STRING(NEVER_FLICKER) ")");
83 MODULE_AUTHOR("Steve Miller (STMicroelectronics) <steve.miller@st.com>");
84 MODULE_DESCRIPTION("V4L-driver for STMicroelectronics CPiA2 based cameras");
85 MODULE_SUPPORTED_DEVICE("video");
86 MODULE_LICENSE("GPL");
88 #define ABOUT "V4L-Driver for Vision CPiA2 based cameras"
90 struct control_menu_info {
95 static struct control_menu_info framerate_controls[] =
97 { CPIA2_VP_FRAMERATE_6_25, "6.25 fps" },
98 { CPIA2_VP_FRAMERATE_7_5, "7.5 fps" },
99 { CPIA2_VP_FRAMERATE_12_5, "12.5 fps" },
100 { CPIA2_VP_FRAMERATE_15, "15 fps" },
101 { CPIA2_VP_FRAMERATE_25, "25 fps" },
102 { CPIA2_VP_FRAMERATE_30, "30 fps" },
104 #define NUM_FRAMERATE_CONTROLS (ARRAY_SIZE(framerate_controls))
106 static struct control_menu_info flicker_controls[] =
108 { NEVER_FLICKER, "Off" },
109 { FLICKER_50, "50 Hz" },
110 { FLICKER_60, "60 Hz" },
112 #define NUM_FLICKER_CONTROLS (ARRAY_SIZE(flicker_controls))
114 static struct control_menu_info lights_controls[] =
121 #define NUM_LIGHTS_CONTROLS (ARRAY_SIZE(lights_controls))
122 #define GPIO_LIGHTS_MASK 192
124 static struct v4l2_queryctrl controls[] = {
126 .id = V4L2_CID_BRIGHTNESS,
127 .type = V4L2_CTRL_TYPE_INTEGER,
128 .name = "Brightness",
132 .default_value = DEFAULT_BRIGHTNESS,
135 .id = V4L2_CID_CONTRAST,
136 .type = V4L2_CTRL_TYPE_INTEGER,
141 .default_value = DEFAULT_CONTRAST,
144 .id = V4L2_CID_SATURATION,
145 .type = V4L2_CTRL_TYPE_INTEGER,
146 .name = "Saturation",
150 .default_value = DEFAULT_SATURATION,
153 .id = V4L2_CID_HFLIP,
154 .type = V4L2_CTRL_TYPE_BOOLEAN,
155 .name = "Mirror Horizontally",
162 .id = V4L2_CID_VFLIP,
163 .type = V4L2_CTRL_TYPE_BOOLEAN,
164 .name = "Flip Vertically",
171 .id = CPIA2_CID_TARGET_KB,
172 .type = V4L2_CTRL_TYPE_INTEGER,
177 .default_value = DEFAULT_TARGET_KB,
180 .id = CPIA2_CID_GPIO,
181 .type = V4L2_CTRL_TYPE_INTEGER,
189 .id = CPIA2_CID_FLICKER_MODE,
190 .type = V4L2_CTRL_TYPE_MENU,
191 .name = "Flicker Reduction",
193 .maximum = NUM_FLICKER_CONTROLS-1,
198 .id = CPIA2_CID_FRAMERATE,
199 .type = V4L2_CTRL_TYPE_MENU,
202 .maximum = NUM_FRAMERATE_CONTROLS-1,
204 .default_value = NUM_FRAMERATE_CONTROLS-1,
207 .id = CPIA2_CID_USB_ALT,
208 .type = V4L2_CTRL_TYPE_INTEGER,
209 .name = "USB Alternate",
210 .minimum = USBIF_ISO_1,
211 .maximum = USBIF_ISO_6,
213 .default_value = DEFAULT_ALT,
216 .id = CPIA2_CID_LIGHTS,
217 .type = V4L2_CTRL_TYPE_MENU,
220 .maximum = NUM_LIGHTS_CONTROLS-1,
225 .id = CPIA2_CID_RESET_CAMERA,
226 .type = V4L2_CTRL_TYPE_BUTTON,
227 .name = "Reset Camera",
234 #define NUM_CONTROLS (ARRAY_SIZE(controls))
237 /******************************************************************************
241 *****************************************************************************/
242 static int cpia2_open(struct inode *inode, struct file *file)
244 struct video_device *dev = video_devdata(file);
245 struct camera_data *cam = video_get_drvdata(dev);
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 inode *inode, 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 video_device *dev = video_devdata(file);
361 struct camera_data *cam = video_get_drvdata(dev);
362 int noblock = file->f_flags&O_NONBLOCK;
364 struct cpia2_fh *fh = file->private_data;
370 if(fh->prio != V4L2_PRIORITY_RECORD) {
374 return cpia2_read(cam, buf, count, noblock);
378 /******************************************************************************
382 *****************************************************************************/
383 static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
385 struct video_device *dev = video_devdata(filp);
386 struct camera_data *cam = video_get_drvdata(dev);
388 struct cpia2_fh *fh = filp->private_data;
394 if(fh->prio != V4L2_PRIORITY_RECORD) {
398 return cpia2_poll(cam, filp, wait);
402 /******************************************************************************
406 *****************************************************************************/
407 static int ioctl_cap_query(void *arg, struct camera_data *cam)
409 struct video_capability *vc;
413 if (cam->params.pnp_id.product == 0x151)
414 strcpy(vc->name, "QX5 Microscope");
416 strcpy(vc->name, "CPiA2 Camera");
418 vc->type = VID_TYPE_CAPTURE | VID_TYPE_MJPEG_ENCODER;
421 vc->minwidth = 176; /* VIDEOSIZE_QCIF */
423 switch (cam->params.version.sensor_flags) {
424 case CPIA2_VP_SENSOR_FLAGS_500:
425 vc->maxwidth = STV_IMAGE_VGA_COLS;
426 vc->maxheight = STV_IMAGE_VGA_ROWS;
428 case CPIA2_VP_SENSOR_FLAGS_410:
429 vc->maxwidth = STV_IMAGE_CIF_COLS;
430 vc->maxheight = STV_IMAGE_CIF_ROWS;
439 /******************************************************************************
443 *****************************************************************************/
444 static int ioctl_get_channel(void *arg)
447 struct video_channel *v;
454 strcpy(v->name, "Camera");
457 v->type = VIDEO_TYPE_CAMERA;
463 /******************************************************************************
467 *****************************************************************************/
468 static int ioctl_set_channel(void *arg)
470 struct video_channel *v;
474 if (retval == 0 && v->channel != 0)
480 /******************************************************************************
482 * ioctl_set_image_prop
484 *****************************************************************************/
485 static int ioctl_set_image_prop(void *arg, struct camera_data *cam)
487 struct video_picture *vp;
491 /* brightness, color, contrast need no check 0-65535 */
492 memcpy(&cam->vp, vp, sizeof(*vp));
494 /* update cam->params.colorParams */
495 cam->params.color_params.brightness = vp->brightness / 256;
496 cam->params.color_params.saturation = vp->colour / 256;
497 cam->params.color_params.contrast = vp->contrast / 256;
499 DBG("Requested params: bright 0x%X, sat 0x%X, contrast 0x%X\n",
500 cam->params.color_params.brightness,
501 cam->params.color_params.saturation,
502 cam->params.color_params.contrast);
504 cpia2_set_color_params(cam);
509 static int sync(struct camera_data *cam, int frame_nr)
511 struct framebuf *frame = &cam->buffers[frame_nr];
514 if (frame->status == FRAME_READY)
517 if (!cam->streaming) {
518 frame->status = FRAME_READY;
523 mutex_unlock(&cam->busy_lock);
524 wait_event_interruptible(cam->wq_stream,
526 frame->status == FRAME_READY);
527 mutex_lock(&cam->busy_lock);
528 if (signal_pending(current))
535 /******************************************************************************
537 * ioctl_set_window_size
539 *****************************************************************************/
540 static int ioctl_set_window_size(void *arg, struct camera_data *cam,
543 /* copy_from_user, check validity, copy to internal structure */
544 struct video_window *vw;
548 if (vw->clipcount != 0) /* clipping not supported */
551 if (vw->clips != NULL) /* clipping not supported */
554 /* Ensure that only this process can change the format. */
555 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
559 cam->pixelformat = V4L2_PIX_FMT_JPEG;
561 /* Be sure to supply the Huffman tables, this isn't MJPEG */
562 cam->params.compression.inhibit_htables = 0;
564 /* we set the video window to something smaller or equal to what
565 * is requested by the user???
567 DBG("Requested width = %d, height = %d\n", vw->width, vw->height);
568 if (vw->width != cam->vw.width || vw->height != cam->vw.height) {
569 cam->vw.width = vw->width;
570 cam->vw.height = vw->height;
571 cam->params.roi.width = vw->width;
572 cam->params.roi.height = vw->height;
573 cpia2_set_format(cam);
576 for (frame = 0; frame < cam->num_frames; ++frame) {
577 if (cam->buffers[frame].status == FRAME_READING)
578 if ((err = sync(cam, frame)) < 0)
581 cam->buffers[frame].status = FRAME_EMPTY;
587 /******************************************************************************
591 *****************************************************************************/
592 static int ioctl_get_mbuf(void *arg, struct camera_data *cam)
594 struct video_mbuf *vm;
598 memset(vm, 0, sizeof(*vm));
599 vm->size = cam->frame_size*cam->num_frames;
600 vm->frames = cam->num_frames;
601 for (i = 0; i < cam->num_frames; i++)
602 vm->offsets[i] = cam->frame_size * i;
607 /******************************************************************************
611 *****************************************************************************/
612 static int ioctl_mcapture(void *arg, struct camera_data *cam,
615 struct video_mmap *vm;
619 if (vm->frame < 0 || vm->frame >= cam->num_frames)
623 video_size = cpia2_match_video_size(vm->width, vm->height);
624 if (cam->video_size < 0) {
628 /* Ensure that only this process can change the format. */
629 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
633 if (video_size != cam->video_size) {
634 cam->video_size = video_size;
635 cam->params.roi.width = vm->width;
636 cam->params.roi.height = vm->height;
637 cpia2_set_format(cam);
640 if (cam->buffers[vm->frame].status == FRAME_READING)
641 if ((err=sync(cam, vm->frame)) < 0)
644 cam->buffers[vm->frame].status = FRAME_EMPTY;
646 return cpia2_usb_stream_start(cam,cam->params.camera_state.stream_mode);
649 /******************************************************************************
653 *****************************************************************************/
654 static int ioctl_sync(void *arg, struct camera_data *cam)
660 if (frame < 0 || frame >= cam->num_frames)
663 return sync(cam, frame);
667 /******************************************************************************
671 *****************************************************************************/
673 static int ioctl_set_gpio(void *arg, struct camera_data *cam)
677 gpio_val = *(__u32*) arg;
679 if (gpio_val &~ 0xFFU)
682 return cpia2_set_gpio(cam, (unsigned char)gpio_val);
685 /******************************************************************************
689 * V4L2 device capabilities
691 *****************************************************************************/
693 static int ioctl_querycap(void *arg, struct camera_data *cam)
695 struct v4l2_capability *vc = arg;
697 memset(vc, 0, sizeof(*vc));
698 strcpy(vc->driver, "cpia2");
700 if (cam->params.pnp_id.product == 0x151)
701 strcpy(vc->card, "QX5 Microscope");
703 strcpy(vc->card, "CPiA2 Camera");
704 switch (cam->params.pnp_id.device_type) {
706 strcat(vc->card, " (672/");
709 strcat(vc->card, " (676/");
712 strcat(vc->card, " (???/");
715 switch (cam->params.version.sensor_flags) {
716 case CPIA2_VP_SENSOR_FLAGS_404:
717 strcat(vc->card, "404)");
719 case CPIA2_VP_SENSOR_FLAGS_407:
720 strcat(vc->card, "407)");
722 case CPIA2_VP_SENSOR_FLAGS_409:
723 strcat(vc->card, "409)");
725 case CPIA2_VP_SENSOR_FLAGS_410:
726 strcat(vc->card, "410)");
728 case CPIA2_VP_SENSOR_FLAGS_500:
729 strcat(vc->card, "500)");
732 strcat(vc->card, "???)");
736 if (usb_make_path(cam->dev, vc->bus_info, sizeof(vc->bus_info)) <0)
737 memset(vc->bus_info,0, sizeof(vc->bus_info));
739 vc->version = KERNEL_VERSION(CPIA2_MAJ_VER, CPIA2_MIN_VER,
742 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
749 /******************************************************************************
753 * V4L2 input get/set/enumerate
755 *****************************************************************************/
757 static int ioctl_input(unsigned int ioclt_nr,void *arg,struct camera_data *cam)
759 struct v4l2_input *i = arg;
761 if(ioclt_nr != VIDIOC_G_INPUT) {
766 memset(i, 0, sizeof(*i));
767 strcpy(i->name, "Camera");
768 i->type = V4L2_INPUT_TYPE_CAMERA;
773 /******************************************************************************
777 * V4L2 format enumerate
779 *****************************************************************************/
781 static int ioctl_enum_fmt(void *arg,struct camera_data *cam)
783 struct v4l2_fmtdesc *f = arg;
784 int index = f->index;
786 if (index < 0 || index > 1)
789 memset(f, 0, sizeof(*f));
791 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
792 f->flags = V4L2_FMT_FLAG_COMPRESSED;
795 strcpy(f->description, "MJPEG");
796 f->pixelformat = V4L2_PIX_FMT_MJPEG;
799 strcpy(f->description, "JPEG");
800 f->pixelformat = V4L2_PIX_FMT_JPEG;
809 /******************************************************************************
815 *****************************************************************************/
817 static int ioctl_try_fmt(void *arg,struct camera_data *cam)
819 struct v4l2_format *f = arg;
821 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
824 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG &&
825 f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG)
828 f->fmt.pix.field = V4L2_FIELD_NONE;
829 f->fmt.pix.bytesperline = 0;
830 f->fmt.pix.sizeimage = cam->frame_size;
831 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
834 switch (cpia2_match_video_size(f->fmt.pix.width, f->fmt.pix.height)) {
836 f->fmt.pix.width = 640;
837 f->fmt.pix.height = 480;
840 f->fmt.pix.width = 352;
841 f->fmt.pix.height = 288;
844 f->fmt.pix.width = 320;
845 f->fmt.pix.height = 240;
847 case VIDEOSIZE_288_216:
848 f->fmt.pix.width = 288;
849 f->fmt.pix.height = 216;
851 case VIDEOSIZE_256_192:
852 f->fmt.pix.width = 256;
853 f->fmt.pix.height = 192;
855 case VIDEOSIZE_224_168:
856 f->fmt.pix.width = 224;
857 f->fmt.pix.height = 168;
859 case VIDEOSIZE_192_144:
860 f->fmt.pix.width = 192;
861 f->fmt.pix.height = 144;
865 f->fmt.pix.width = 176;
866 f->fmt.pix.height = 144;
873 /******************************************************************************
879 *****************************************************************************/
881 static int ioctl_set_fmt(void *arg,struct camera_data *cam, struct cpia2_fh *fh)
883 struct v4l2_format *f = arg;
886 err = ioctl_try_fmt(arg, cam);
890 /* Ensure that only this process can change the format. */
891 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
896 cam->pixelformat = f->fmt.pix.pixelformat;
898 /* NOTE: This should be set to 1 for MJPEG, but some apps don't handle
899 * the missing Huffman table properly. */
900 cam->params.compression.inhibit_htables = 0;
901 /*f->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG;*/
903 /* we set the video window to something smaller or equal to what
904 * is requested by the user???
906 DBG("Requested width = %d, height = %d\n",
907 f->fmt.pix.width, f->fmt.pix.height);
908 if (f->fmt.pix.width != cam->vw.width ||
909 f->fmt.pix.height != cam->vw.height) {
910 cam->vw.width = f->fmt.pix.width;
911 cam->vw.height = f->fmt.pix.height;
912 cam->params.roi.width = f->fmt.pix.width;
913 cam->params.roi.height = f->fmt.pix.height;
914 cpia2_set_format(cam);
917 for (frame = 0; frame < cam->num_frames; ++frame) {
918 if (cam->buffers[frame].status == FRAME_READING)
919 if ((err = sync(cam, frame)) < 0)
922 cam->buffers[frame].status = FRAME_EMPTY;
928 /******************************************************************************
934 *****************************************************************************/
936 static int ioctl_get_fmt(void *arg,struct camera_data *cam)
938 struct v4l2_format *f = arg;
940 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
943 f->fmt.pix.width = cam->vw.width;
944 f->fmt.pix.height = cam->vw.height;
945 f->fmt.pix.pixelformat = cam->pixelformat;
946 f->fmt.pix.field = V4L2_FIELD_NONE;
947 f->fmt.pix.bytesperline = 0;
948 f->fmt.pix.sizeimage = cam->frame_size;
949 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
955 /******************************************************************************
959 * V4L2 query cropping capabilities
960 * NOTE: cropping is currently disabled
962 *****************************************************************************/
964 static int ioctl_cropcap(void *arg,struct camera_data *cam)
966 struct v4l2_cropcap *c = arg;
968 if (c->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
973 c->bounds.width = cam->vw.width;
974 c->bounds.height = cam->vw.height;
977 c->defrect.width = cam->vw.width;
978 c->defrect.height = cam->vw.height;
979 c->pixelaspect.numerator = 1;
980 c->pixelaspect.denominator = 1;
985 /******************************************************************************
989 * V4L2 query possible control variables
991 *****************************************************************************/
993 static int ioctl_queryctrl(void *arg,struct camera_data *cam)
995 struct v4l2_queryctrl *c = arg;
998 for(i=0; i<NUM_CONTROLS; ++i) {
999 if(c->id == controls[i].id) {
1000 memcpy(c, controls+i, sizeof(*c));
1005 if(i == NUM_CONTROLS)
1008 /* Some devices have additional limitations */
1010 case V4L2_CID_BRIGHTNESS:
1012 * Don't let the register be set to zero - bug in VP4
1013 * flash of full brightness
1015 if (cam->params.pnp_id.device_type == DEVICE_STV_672)
1018 case V4L2_CID_VFLIP:
1020 if(cam->params.pnp_id.device_type == DEVICE_STV_672)
1021 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1023 case CPIA2_CID_FRAMERATE:
1024 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
1025 cam->params.version.sensor_flags==CPIA2_VP_SENSOR_FLAGS_500){
1028 for(i=0; i<c->maximum; ++i) {
1029 if(framerate_controls[i].value ==
1030 CPIA2_VP_FRAMERATE_15) {
1032 c->default_value = i;
1037 case CPIA2_CID_FLICKER_MODE:
1038 // Flicker control only valid for 672.
1039 if(cam->params.pnp_id.device_type != DEVICE_STV_672)
1040 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1042 case CPIA2_CID_LIGHTS:
1043 // Light control only valid for the QX5 Microscope.
1044 if(cam->params.pnp_id.product != 0x151)
1045 c->flags |= V4L2_CTRL_FLAG_DISABLED;
1054 /******************************************************************************
1058 * V4L2 query possible control variables
1060 *****************************************************************************/
1062 static int ioctl_querymenu(void *arg,struct camera_data *cam)
1064 struct v4l2_querymenu *m = arg;
1066 memset(m->name, 0, sizeof(m->name));
1070 case CPIA2_CID_FLICKER_MODE:
1071 if(m->index < 0 || m->index >= NUM_FLICKER_CONTROLS)
1074 strcpy(m->name, flicker_controls[m->index].name);
1076 case CPIA2_CID_FRAMERATE:
1078 int maximum = NUM_FRAMERATE_CONTROLS - 1;
1079 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
1080 cam->params.version.sensor_flags==CPIA2_VP_SENSOR_FLAGS_500){
1083 for(i=0; i<maximum; ++i) {
1084 if(framerate_controls[i].value ==
1085 CPIA2_VP_FRAMERATE_15)
1089 if(m->index < 0 || m->index > maximum)
1092 strcpy(m->name, framerate_controls[m->index].name);
1095 case CPIA2_CID_LIGHTS:
1096 if(m->index < 0 || m->index >= NUM_LIGHTS_CONTROLS)
1099 strcpy(m->name, lights_controls[m->index].name);
1108 /******************************************************************************
1112 * V4L2 get the value of a control variable
1114 *****************************************************************************/
1116 static int ioctl_g_ctrl(void *arg,struct camera_data *cam)
1118 struct v4l2_control *c = arg;
1121 case V4L2_CID_BRIGHTNESS:
1122 cpia2_do_command(cam, CPIA2_CMD_GET_VP_BRIGHTNESS,
1124 c->value = cam->params.color_params.brightness;
1126 case V4L2_CID_CONTRAST:
1127 cpia2_do_command(cam, CPIA2_CMD_GET_CONTRAST,
1129 c->value = cam->params.color_params.contrast;
1131 case V4L2_CID_SATURATION:
1132 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SATURATION,
1134 c->value = cam->params.color_params.saturation;
1136 case V4L2_CID_HFLIP:
1137 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS,
1139 c->value = (cam->params.vp_params.user_effects &
1140 CPIA2_VP_USER_EFFECTS_MIRROR) != 0;
1142 case V4L2_CID_VFLIP:
1143 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS,
1145 c->value = (cam->params.vp_params.user_effects &
1146 CPIA2_VP_USER_EFFECTS_FLIP) != 0;
1148 case CPIA2_CID_TARGET_KB:
1149 c->value = cam->params.vc_params.target_kb;
1151 case CPIA2_CID_GPIO:
1152 cpia2_do_command(cam, CPIA2_CMD_GET_VP_GPIO_DATA,
1154 c->value = cam->params.vp_params.gpio_data;
1156 case CPIA2_CID_FLICKER_MODE:
1159 cpia2_do_command(cam, CPIA2_CMD_GET_FLICKER_MODES,
1161 if(cam->params.flicker_control.cam_register &
1162 CPIA2_VP_FLICKER_MODES_NEVER_FLICKER) {
1163 mode = NEVER_FLICKER;
1165 if(cam->params.flicker_control.cam_register &
1166 CPIA2_VP_FLICKER_MODES_50HZ) {
1172 for(i=0; i<NUM_FLICKER_CONTROLS; i++) {
1173 if(flicker_controls[i].value == mode) {
1178 if(i == NUM_FLICKER_CONTROLS)
1182 case CPIA2_CID_FRAMERATE:
1184 int maximum = NUM_FRAMERATE_CONTROLS - 1;
1186 for(i=0; i<= maximum; i++) {
1187 if(cam->params.vp_params.frame_rate ==
1188 framerate_controls[i].value)
1196 case CPIA2_CID_USB_ALT:
1197 c->value = cam->params.camera_state.stream_mode;
1199 case CPIA2_CID_LIGHTS:
1202 cpia2_do_command(cam, CPIA2_CMD_GET_VP_GPIO_DATA,
1204 for(i=0; i<NUM_LIGHTS_CONTROLS; i++) {
1205 if((cam->params.vp_params.gpio_data&GPIO_LIGHTS_MASK) ==
1206 lights_controls[i].value) {
1210 if(i == NUM_LIGHTS_CONTROLS)
1215 case CPIA2_CID_RESET_CAMERA:
1221 DBG("Get control id:%d, value:%d\n", c->id, c->value);
1226 /******************************************************************************
1230 * V4L2 set the value of a control variable
1232 *****************************************************************************/
1234 static int ioctl_s_ctrl(void *arg,struct camera_data *cam)
1236 struct v4l2_control *c = arg;
1240 DBG("Set control id:%d, value:%d\n", c->id, c->value);
1242 /* Check that the value is in range */
1243 for(i=0; i<NUM_CONTROLS; i++) {
1244 if(c->id == controls[i].id) {
1245 if(c->value < controls[i].minimum ||
1246 c->value > controls[i].maximum) {
1252 if(i == NUM_CONTROLS)
1256 case V4L2_CID_BRIGHTNESS:
1257 cpia2_set_brightness(cam, c->value);
1259 case V4L2_CID_CONTRAST:
1260 cpia2_set_contrast(cam, c->value);
1262 case V4L2_CID_SATURATION:
1263 cpia2_set_saturation(cam, c->value);
1265 case V4L2_CID_HFLIP:
1266 cpia2_set_property_mirror(cam, c->value);
1268 case V4L2_CID_VFLIP:
1269 cpia2_set_property_flip(cam, c->value);
1271 case CPIA2_CID_TARGET_KB:
1272 retval = cpia2_set_target_kb(cam, c->value);
1274 case CPIA2_CID_GPIO:
1275 retval = cpia2_set_gpio(cam, c->value);
1277 case CPIA2_CID_FLICKER_MODE:
1278 retval = cpia2_set_flicker_mode(cam,
1279 flicker_controls[c->value].value);
1281 case CPIA2_CID_FRAMERATE:
1282 retval = cpia2_set_fps(cam, framerate_controls[c->value].value);
1284 case CPIA2_CID_USB_ALT:
1285 retval = cpia2_usb_change_streaming_alternate(cam, c->value);
1287 case CPIA2_CID_LIGHTS:
1288 retval = cpia2_set_gpio(cam, lights_controls[c->value].value);
1290 case CPIA2_CID_RESET_CAMERA:
1291 cpia2_usb_stream_pause(cam);
1292 cpia2_reset_camera(cam);
1293 cpia2_usb_stream_resume(cam);
1302 /******************************************************************************
1306 * V4L2 get the JPEG compression parameters
1308 *****************************************************************************/
1310 static int ioctl_g_jpegcomp(void *arg,struct camera_data *cam)
1312 struct v4l2_jpegcompression *parms = arg;
1314 memset(parms, 0, sizeof(*parms));
1316 parms->quality = 80; // TODO: Can this be made meaningful?
1318 parms->jpeg_markers = V4L2_JPEG_MARKER_DQT | V4L2_JPEG_MARKER_DRI;
1319 if(!cam->params.compression.inhibit_htables) {
1320 parms->jpeg_markers |= V4L2_JPEG_MARKER_DHT;
1323 parms->APPn = cam->APPn;
1324 parms->APP_len = cam->APP_len;
1325 if(cam->APP_len > 0) {
1326 memcpy(parms->APP_data, cam->APP_data, cam->APP_len);
1327 parms->jpeg_markers |= V4L2_JPEG_MARKER_APP;
1330 parms->COM_len = cam->COM_len;
1331 if(cam->COM_len > 0) {
1332 memcpy(parms->COM_data, cam->COM_data, cam->COM_len);
1333 parms->jpeg_markers |= JPEG_MARKER_COM;
1336 DBG("G_JPEGCOMP APP_len:%d COM_len:%d\n",
1337 parms->APP_len, parms->COM_len);
1342 /******************************************************************************
1346 * V4L2 set the JPEG compression parameters
1347 * NOTE: quality and some jpeg_markers are ignored.
1349 *****************************************************************************/
1351 static int ioctl_s_jpegcomp(void *arg,struct camera_data *cam)
1353 struct v4l2_jpegcompression *parms = arg;
1355 DBG("S_JPEGCOMP APP_len:%d COM_len:%d\n",
1356 parms->APP_len, parms->COM_len);
1358 cam->params.compression.inhibit_htables =
1359 !(parms->jpeg_markers & V4L2_JPEG_MARKER_DHT);
1361 if(parms->APP_len != 0) {
1362 if(parms->APP_len > 0 &&
1363 parms->APP_len <= sizeof(cam->APP_data) &&
1364 parms->APPn >= 0 && parms->APPn <= 15) {
1365 cam->APPn = parms->APPn;
1366 cam->APP_len = parms->APP_len;
1367 memcpy(cam->APP_data, parms->APP_data, parms->APP_len);
1369 LOG("Bad APPn Params n=%d len=%d\n",
1370 parms->APPn, parms->APP_len);
1377 if(parms->COM_len != 0) {
1378 if(parms->COM_len > 0 &&
1379 parms->COM_len <= sizeof(cam->COM_data)) {
1380 cam->COM_len = parms->COM_len;
1381 memcpy(cam->COM_data, parms->COM_data, parms->COM_len);
1383 LOG("Bad COM_len=%d\n", parms->COM_len);
1391 /******************************************************************************
1395 * V4L2 Initiate memory mapping.
1396 * NOTE: The user's request is ignored. For now the buffers are fixed.
1398 *****************************************************************************/
1400 static int ioctl_reqbufs(void *arg,struct camera_data *cam)
1402 struct v4l2_requestbuffers *req = arg;
1404 if(req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1405 req->memory != V4L2_MEMORY_MMAP)
1408 DBG("REQBUFS requested:%d returning:%d\n", req->count, cam->num_frames);
1409 req->count = cam->num_frames;
1410 memset(&req->reserved, 0, sizeof(req->reserved));
1415 /******************************************************************************
1419 * V4L2 Query memory buffer status.
1421 *****************************************************************************/
1423 static int ioctl_querybuf(void *arg,struct camera_data *cam)
1425 struct v4l2_buffer *buf = arg;
1427 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1428 buf->index > cam->num_frames)
1431 buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
1432 buf->length = cam->frame_size;
1434 buf->memory = V4L2_MEMORY_MMAP;
1437 buf->flags = V4L2_BUF_FLAG_MAPPED;
1441 switch (cam->buffers[buf->index].status) {
1446 buf->flags = V4L2_BUF_FLAG_QUEUED;
1449 buf->bytesused = cam->buffers[buf->index].length;
1450 buf->timestamp = cam->buffers[buf->index].timestamp;
1451 buf->sequence = cam->buffers[buf->index].seq;
1452 buf->flags = V4L2_BUF_FLAG_DONE;
1456 DBG("QUERYBUF index:%d offset:%d flags:%d seq:%d bytesused:%d\n",
1457 buf->index, buf->m.offset, buf->flags, buf->sequence,
1463 /******************************************************************************
1467 * V4L2 User is freeing buffer
1469 *****************************************************************************/
1471 static int ioctl_qbuf(void *arg,struct camera_data *cam)
1473 struct v4l2_buffer *buf = arg;
1475 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1476 buf->memory != V4L2_MEMORY_MMAP ||
1477 buf->index > cam->num_frames)
1480 DBG("QBUF #%d\n", buf->index);
1482 if(cam->buffers[buf->index].status == FRAME_READY)
1483 cam->buffers[buf->index].status = FRAME_EMPTY;
1488 /******************************************************************************
1490 * find_earliest_filled_buffer
1492 * Helper for ioctl_dqbuf. Find the next ready buffer.
1494 *****************************************************************************/
1496 static int find_earliest_filled_buffer(struct camera_data *cam)
1500 for (i=0; i<cam->num_frames; i++) {
1501 if(cam->buffers[i].status == FRAME_READY) {
1505 /* find which buffer is earlier */
1506 struct timeval *tv1, *tv2;
1507 tv1 = &cam->buffers[i].timestamp;
1508 tv2 = &cam->buffers[found].timestamp;
1509 if(tv1->tv_sec < tv2->tv_sec ||
1510 (tv1->tv_sec == tv2->tv_sec &&
1511 tv1->tv_usec < tv2->tv_usec))
1519 /******************************************************************************
1523 * V4L2 User is asking for a filled buffer.
1525 *****************************************************************************/
1527 static int ioctl_dqbuf(void *arg,struct camera_data *cam, struct file *file)
1529 struct v4l2_buffer *buf = arg;
1532 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1533 buf->memory != V4L2_MEMORY_MMAP)
1536 frame = find_earliest_filled_buffer(cam);
1538 if(frame < 0 && file->f_flags&O_NONBLOCK)
1542 /* Wait for a frame to become available */
1543 struct framebuf *cb=cam->curbuff;
1544 mutex_unlock(&cam->busy_lock);
1545 wait_event_interruptible(cam->wq_stream,
1547 (cb=cam->curbuff)->status == FRAME_READY);
1548 mutex_lock(&cam->busy_lock);
1549 if (signal_pending(current))
1550 return -ERESTARTSYS;
1558 buf->bytesused = cam->buffers[buf->index].length;
1559 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE;
1560 buf->field = V4L2_FIELD_NONE;
1561 buf->timestamp = cam->buffers[buf->index].timestamp;
1562 buf->sequence = cam->buffers[buf->index].seq;
1563 buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
1564 buf->length = cam->frame_size;
1567 memset(&buf->timecode, 0, sizeof(buf->timecode));
1569 DBG("DQBUF #%d status:%d seq:%d length:%d\n", buf->index,
1570 cam->buffers[buf->index].status, buf->sequence, buf->bytesused);
1575 /******************************************************************************
1579 *****************************************************************************/
1580 static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1581 unsigned int ioctl_nr, void *arg)
1583 struct video_device *dev = video_devdata(file);
1584 struct camera_data *cam = video_get_drvdata(dev);
1590 /* make this _really_ smp-safe */
1591 if (mutex_lock_interruptible(&cam->busy_lock))
1592 return -ERESTARTSYS;
1594 if (!cam->present) {
1595 mutex_unlock(&cam->busy_lock);
1599 /* Priority check */
1602 case VIDIOCMCAPTURE:
1605 struct cpia2_fh *fh = file->private_data;
1606 retval = v4l2_prio_check(&cam->prio, &fh->prio);
1608 mutex_unlock(&cam->busy_lock);
1616 struct cpia2_fh *fh = file->private_data;
1617 if(fh->prio != V4L2_PRIORITY_RECORD) {
1618 mutex_unlock(&cam->busy_lock);
1628 case VIDIOCGCAP: /* query capabilities */
1629 retval = ioctl_cap_query(arg, cam);
1632 case VIDIOCGCHAN: /* get video source - we are a camera, nothing else */
1633 retval = ioctl_get_channel(arg);
1635 case VIDIOCSCHAN: /* set video source - we are a camera, nothing else */
1636 retval = ioctl_set_channel(arg);
1638 case VIDIOCGPICT: /* image properties */
1639 memcpy(arg, &cam->vp, sizeof(struct video_picture));
1642 retval = ioctl_set_image_prop(arg, cam);
1644 case VIDIOCGWIN: /* get/set capture window */
1645 memcpy(arg, &cam->vw, sizeof(struct video_window));
1648 retval = ioctl_set_window_size(arg, cam, file->private_data);
1650 case VIDIOCGMBUF: /* mmap interface */
1651 retval = ioctl_get_mbuf(arg, cam);
1653 case VIDIOCMCAPTURE:
1654 retval = ioctl_mcapture(arg, cam, file->private_data);
1657 retval = ioctl_sync(arg, cam);
1659 /* pointless to implement overlay with this camera */
1667 /* tuner interface - we have none */
1675 /* audio interface - we have none */
1681 /* CPIA2 extension to Video4Linux API */
1682 case CPIA2_IOC_SET_GPIO:
1683 retval = ioctl_set_gpio(arg, cam);
1685 case VIDIOC_QUERYCAP:
1686 retval = ioctl_querycap(arg,cam);
1689 case VIDIOC_ENUMINPUT:
1690 case VIDIOC_G_INPUT:
1691 case VIDIOC_S_INPUT:
1692 retval = ioctl_input(ioctl_nr, arg,cam);
1695 case VIDIOC_ENUM_FMT:
1696 retval = ioctl_enum_fmt(arg,cam);
1698 case VIDIOC_TRY_FMT:
1699 retval = ioctl_try_fmt(arg,cam);
1702 retval = ioctl_get_fmt(arg,cam);
1705 retval = ioctl_set_fmt(arg,cam,file->private_data);
1708 case VIDIOC_CROPCAP:
1709 retval = ioctl_cropcap(arg,cam);
1713 // TODO: I think cropping can be implemented - SJB
1717 case VIDIOC_QUERYCTRL:
1718 retval = ioctl_queryctrl(arg,cam);
1720 case VIDIOC_QUERYMENU:
1721 retval = ioctl_querymenu(arg,cam);
1724 retval = ioctl_g_ctrl(arg,cam);
1727 retval = ioctl_s_ctrl(arg,cam);
1730 case VIDIOC_G_JPEGCOMP:
1731 retval = ioctl_g_jpegcomp(arg,cam);
1733 case VIDIOC_S_JPEGCOMP:
1734 retval = ioctl_s_jpegcomp(arg,cam);
1737 case VIDIOC_G_PRIORITY:
1739 struct cpia2_fh *fh = file->private_data;
1740 *(enum v4l2_priority*)arg = fh->prio;
1743 case VIDIOC_S_PRIORITY:
1745 struct cpia2_fh *fh = file->private_data;
1746 enum v4l2_priority prio;
1747 prio = *(enum v4l2_priority*)arg;
1748 if(cam->streaming &&
1750 fh->prio == V4L2_PRIORITY_RECORD) {
1751 /* Can't drop record priority while streaming */
1753 } else if(prio == V4L2_PRIORITY_RECORD &&
1755 v4l2_prio_max(&cam->prio) == V4L2_PRIORITY_RECORD) {
1756 /* Only one program can record at a time */
1759 retval = v4l2_prio_change(&cam->prio, &fh->prio, prio);
1764 case VIDIOC_REQBUFS:
1765 retval = ioctl_reqbufs(arg,cam);
1767 case VIDIOC_QUERYBUF:
1768 retval = ioctl_querybuf(arg,cam);
1771 retval = ioctl_qbuf(arg,cam);
1774 retval = ioctl_dqbuf(arg,cam,file);
1776 case VIDIOC_STREAMON:
1779 DBG("VIDIOC_STREAMON, streaming=%d\n", cam->streaming);
1781 if(!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1784 if(!cam->streaming) {
1785 retval = cpia2_usb_stream_start(cam,
1786 cam->params.camera_state.stream_mode);
1793 case VIDIOC_STREAMOFF:
1796 DBG("VIDIOC_STREAMOFF, streaming=%d\n", cam->streaming);
1798 if(!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1801 if(cam->streaming) {
1802 retval = cpia2_usb_stream_stop(cam);
1810 case VIDIOC_ENUMOUTPUT:
1811 case VIDIOC_G_OUTPUT:
1812 case VIDIOC_S_OUTPUT:
1813 case VIDIOC_G_MODULATOR:
1814 case VIDIOC_S_MODULATOR:
1816 case VIDIOC_ENUMAUDIO:
1817 case VIDIOC_G_AUDIO:
1818 case VIDIOC_S_AUDIO:
1820 case VIDIOC_ENUMAUDOUT:
1821 case VIDIOC_G_AUDOUT:
1822 case VIDIOC_S_AUDOUT:
1824 case VIDIOC_ENUMSTD:
1825 case VIDIOC_QUERYSTD:
1829 case VIDIOC_G_TUNER:
1830 case VIDIOC_S_TUNER:
1831 case VIDIOC_G_FREQUENCY:
1832 case VIDIOC_S_FREQUENCY:
1834 case VIDIOC_OVERLAY:
1843 retval = -ENOIOCTLCMD;
1847 mutex_unlock(&cam->busy_lock);
1851 static int cpia2_ioctl(struct inode *inode, struct file *file,
1852 unsigned int ioctl_nr, unsigned long iarg)
1854 return video_usercopy(inode, file, ioctl_nr, iarg, cpia2_do_ioctl);
1857 /******************************************************************************
1861 *****************************************************************************/
1862 static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
1865 struct video_device *dev = video_devdata(file);
1866 struct camera_data *cam = video_get_drvdata(dev);
1868 /* Priority check */
1869 struct cpia2_fh *fh = file->private_data;
1870 if(fh->prio != V4L2_PRIORITY_RECORD) {
1874 retval = cpia2_remap_buffer(cam, area);
1881 /******************************************************************************
1883 * reset_camera_struct_v4l
1885 * Sets all values to the defaults
1886 *****************************************************************************/
1887 static void reset_camera_struct_v4l(struct camera_data *cam)
1890 * Fill in the v4l structures. video_cap is filled in inside the VIDIOCCAP
1891 * Ioctl. Here, just do the window and picture stucts.
1893 cam->vp.palette = (u16) VIDEO_PALETTE_RGB24; /* Is this right? */
1894 cam->vp.brightness = (u16) cam->params.color_params.brightness * 256;
1895 cam->vp.colour = (u16) cam->params.color_params.saturation * 256;
1896 cam->vp.contrast = (u16) cam->params.color_params.contrast * 256;
1900 cam->vw.width = cam->params.roi.width;
1901 cam->vw.height = cam->params.roi.height;
1903 cam->vw.clipcount = 0;
1905 cam->frame_size = buffer_size;
1906 cam->num_frames = num_buffers;
1909 cam->params.flicker_control.flicker_mode_req = flicker_mode;
1910 cam->params.flicker_control.mains_frequency = flicker_freq;
1913 cam->params.camera_state.stream_mode = alternate;
1915 cam->pixelformat = V4L2_PIX_FMT_JPEG;
1916 v4l2_prio_init(&cam->prio);
1921 * The v4l video device structure initialized for this device
1923 static const struct file_operations fops_template = {
1924 .owner = THIS_MODULE,
1926 .release = cpia2_close,
1927 .read = cpia2_v4l_read,
1928 .poll = cpia2_v4l_poll,
1929 .ioctl = cpia2_ioctl,
1930 .llseek = no_llseek,
1931 #ifdef CONFIG_COMPAT
1932 .compat_ioctl = v4l_compat_ioctl32,
1937 static struct video_device cpia2_template = {
1938 /* I could not find any place for the old .initialize initializer?? */
1939 .name= "CPiA2 Camera",
1941 .fops= &fops_template,
1942 .release= video_device_release,
1945 /******************************************************************************
1947 * cpia2_register_camera
1949 *****************************************************************************/
1950 int cpia2_register_camera(struct camera_data *cam)
1952 cam->vdev = video_device_alloc();
1956 memcpy(cam->vdev, &cpia2_template, sizeof(cpia2_template));
1957 video_set_drvdata(cam->vdev, cam);
1959 reset_camera_struct_v4l(cam);
1961 /* register v4l device */
1962 if (video_register_device
1963 (cam->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
1964 ERR("video_register_device failed\n");
1965 video_device_release(cam->vdev);
1972 /******************************************************************************
1974 * cpia2_unregister_camera
1976 *****************************************************************************/
1977 void cpia2_unregister_camera(struct camera_data *cam)
1979 if (!cam->open_count) {
1980 video_unregister_device(cam->vdev);
1982 LOG("/dev/video%d removed while open, "
1983 "deferring video_unregister_device\n",
1988 /******************************************************************************
1992 * Make sure that all user-supplied parameters are sensible
1993 *****************************************************************************/
1994 static void __init check_parameters(void)
1996 if(buffer_size < PAGE_SIZE) {
1997 buffer_size = PAGE_SIZE;
1998 LOG("buffer_size too small, setting to %d\n", buffer_size);
1999 } else if(buffer_size > 1024*1024) {
2000 /* arbitrary upper limiit */
2001 buffer_size = 1024*1024;
2002 LOG("buffer_size ridiculously large, setting to %d\n",
2005 buffer_size += PAGE_SIZE-1;
2006 buffer_size &= ~(PAGE_SIZE-1);
2009 if(num_buffers < 1) {
2011 LOG("num_buffers too small, setting to %d\n", num_buffers);
2012 } else if(num_buffers > VIDEO_MAX_FRAME) {
2013 num_buffers = VIDEO_MAX_FRAME;
2014 LOG("num_buffers too large, setting to %d\n", num_buffers);
2017 if(alternate < USBIF_ISO_1 || alternate > USBIF_ISO_6) {
2018 alternate = DEFAULT_ALT;
2019 LOG("alternate specified is invalid, using %d\n", alternate);
2022 if (flicker_mode != NEVER_FLICKER && flicker_mode != ANTI_FLICKER_ON) {
2023 flicker_mode = NEVER_FLICKER;
2024 LOG("Flicker mode specified is invalid, using %d\n",
2028 if (flicker_freq != FLICKER_50 && flicker_freq != FLICKER_60) {
2029 flicker_freq = FLICKER_60;
2030 LOG("Flicker mode specified is invalid, using %d\n",
2034 if(video_nr < -1 || video_nr > 64) {
2036 LOG("invalid video_nr specified, must be -1 to 64\n");
2039 DBG("Using %d buffers, each %d bytes, alternate=%d\n",
2040 num_buffers, buffer_size, alternate);
2043 /************ Module Stuff ***************/
2046 /******************************************************************************
2048 * cpia2_init/module_init
2050 *****************************************************************************/
2051 static int __init cpia2_init(void)
2053 LOG("%s v%d.%d.%d\n",
2054 ABOUT, CPIA2_MAJ_VER, CPIA2_MIN_VER, CPIA2_PATCH_VER);
2061 /******************************************************************************
2063 * cpia2_exit/module_exit
2065 *****************************************************************************/
2066 static void __exit cpia2_exit(void)
2068 cpia2_usb_cleanup();
2069 schedule_timeout(2 * HZ);
2072 module_init(cpia2_init);
2073 module_exit(cpia2_exit);