Use dentry_path() to create full path to inode object
[pohmelfs.git] / drivers / media / video / cpia2 / cpia2_v4l.c
blob077eb1db80a1b4d926c77cac24c979ab255982a0
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>
9 * Description:
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 #define CPIA_VERSION "3.0.1"
34 #include <linux/module.h>
35 #include <linux/time.h>
36 #include <linux/sched.h>
37 #include <linux/slab.h>
38 #include <linux/init.h>
39 #include <linux/videodev2.h>
40 #include <linux/stringify.h>
41 #include <media/v4l2-ioctl.h>
43 #include "cpia2.h"
44 #include "cpia2dev.h"
46 static int video_nr = -1;
47 module_param(video_nr, int, 0);
48 MODULE_PARM_DESC(video_nr,"video device to register (0=/dev/video0, etc)");
50 static int buffer_size = 68*1024;
51 module_param(buffer_size, int, 0);
52 MODULE_PARM_DESC(buffer_size, "Size for each frame buffer in bytes (default 68k)");
54 static int num_buffers = 3;
55 module_param(num_buffers, int, 0);
56 MODULE_PARM_DESC(num_buffers, "Number of frame buffers (1-"
57 __stringify(VIDEO_MAX_FRAME) ", default 3)");
59 static int alternate = DEFAULT_ALT;
60 module_param(alternate, int, 0);
61 MODULE_PARM_DESC(alternate, "USB Alternate (" __stringify(USBIF_ISO_1) "-"
62 __stringify(USBIF_ISO_6) ", default "
63 __stringify(DEFAULT_ALT) ")");
65 static int flicker_freq = 60;
66 module_param(flicker_freq, int, 0);
67 MODULE_PARM_DESC(flicker_freq, "Flicker frequency (" __stringify(50) "or"
68 __stringify(60) ", default "
69 __stringify(60) ")");
71 static int flicker_mode = NEVER_FLICKER;
72 module_param(flicker_mode, int, 0);
73 MODULE_PARM_DESC(flicker_mode,
74 "Flicker supression (" __stringify(NEVER_FLICKER) "or"
75 __stringify(ANTI_FLICKER_ON) ", default "
76 __stringify(NEVER_FLICKER) ")");
78 MODULE_AUTHOR("Steve Miller (STMicroelectronics) <steve.miller@st.com>");
79 MODULE_DESCRIPTION("V4L-driver for STMicroelectronics CPiA2 based cameras");
80 MODULE_SUPPORTED_DEVICE("video");
81 MODULE_LICENSE("GPL");
82 MODULE_VERSION(CPIA_VERSION);
84 #define ABOUT "V4L-Driver for Vision CPiA2 based cameras"
86 struct control_menu_info {
87 int value;
88 char name[32];
91 static struct control_menu_info framerate_controls[] =
93 { CPIA2_VP_FRAMERATE_6_25, "6.25 fps" },
94 { CPIA2_VP_FRAMERATE_7_5, "7.5 fps" },
95 { CPIA2_VP_FRAMERATE_12_5, "12.5 fps" },
96 { CPIA2_VP_FRAMERATE_15, "15 fps" },
97 { CPIA2_VP_FRAMERATE_25, "25 fps" },
98 { CPIA2_VP_FRAMERATE_30, "30 fps" },
100 #define NUM_FRAMERATE_CONTROLS (ARRAY_SIZE(framerate_controls))
102 static struct control_menu_info flicker_controls[] =
104 { NEVER_FLICKER, "Off" },
105 { FLICKER_50, "50 Hz" },
106 { FLICKER_60, "60 Hz" },
108 #define NUM_FLICKER_CONTROLS (ARRAY_SIZE(flicker_controls))
110 static struct control_menu_info lights_controls[] =
112 { 0, "Off" },
113 { 64, "Top" },
114 { 128, "Bottom" },
115 { 192, "Both" },
117 #define NUM_LIGHTS_CONTROLS (ARRAY_SIZE(lights_controls))
118 #define GPIO_LIGHTS_MASK 192
120 static struct v4l2_queryctrl controls[] = {
122 .id = V4L2_CID_BRIGHTNESS,
123 .type = V4L2_CTRL_TYPE_INTEGER,
124 .name = "Brightness",
125 .minimum = 0,
126 .maximum = 255,
127 .step = 1,
128 .default_value = DEFAULT_BRIGHTNESS,
131 .id = V4L2_CID_CONTRAST,
132 .type = V4L2_CTRL_TYPE_INTEGER,
133 .name = "Contrast",
134 .minimum = 0,
135 .maximum = 255,
136 .step = 1,
137 .default_value = DEFAULT_CONTRAST,
140 .id = V4L2_CID_SATURATION,
141 .type = V4L2_CTRL_TYPE_INTEGER,
142 .name = "Saturation",
143 .minimum = 0,
144 .maximum = 255,
145 .step = 1,
146 .default_value = DEFAULT_SATURATION,
149 .id = V4L2_CID_HFLIP,
150 .type = V4L2_CTRL_TYPE_BOOLEAN,
151 .name = "Mirror Horizontally",
152 .minimum = 0,
153 .maximum = 1,
154 .step = 1,
155 .default_value = 0,
158 .id = V4L2_CID_VFLIP,
159 .type = V4L2_CTRL_TYPE_BOOLEAN,
160 .name = "Flip Vertically",
161 .minimum = 0,
162 .maximum = 1,
163 .step = 1,
164 .default_value = 0,
167 .id = CPIA2_CID_TARGET_KB,
168 .type = V4L2_CTRL_TYPE_INTEGER,
169 .name = "Target KB",
170 .minimum = 0,
171 .maximum = 255,
172 .step = 1,
173 .default_value = DEFAULT_TARGET_KB,
176 .id = CPIA2_CID_GPIO,
177 .type = V4L2_CTRL_TYPE_INTEGER,
178 .name = "GPIO",
179 .minimum = 0,
180 .maximum = 255,
181 .step = 1,
182 .default_value = 0,
185 .id = CPIA2_CID_FLICKER_MODE,
186 .type = V4L2_CTRL_TYPE_MENU,
187 .name = "Flicker Reduction",
188 .minimum = 0,
189 .maximum = NUM_FLICKER_CONTROLS-1,
190 .step = 1,
191 .default_value = 0,
194 .id = CPIA2_CID_FRAMERATE,
195 .type = V4L2_CTRL_TYPE_MENU,
196 .name = "Framerate",
197 .minimum = 0,
198 .maximum = NUM_FRAMERATE_CONTROLS-1,
199 .step = 1,
200 .default_value = NUM_FRAMERATE_CONTROLS-1,
203 .id = CPIA2_CID_USB_ALT,
204 .type = V4L2_CTRL_TYPE_INTEGER,
205 .name = "USB Alternate",
206 .minimum = USBIF_ISO_1,
207 .maximum = USBIF_ISO_6,
208 .step = 1,
209 .default_value = DEFAULT_ALT,
212 .id = CPIA2_CID_LIGHTS,
213 .type = V4L2_CTRL_TYPE_MENU,
214 .name = "Lights",
215 .minimum = 0,
216 .maximum = NUM_LIGHTS_CONTROLS-1,
217 .step = 1,
218 .default_value = 0,
221 .id = CPIA2_CID_RESET_CAMERA,
222 .type = V4L2_CTRL_TYPE_BUTTON,
223 .name = "Reset Camera",
224 .minimum = 0,
225 .maximum = 0,
226 .step = 0,
227 .default_value = 0,
230 #define NUM_CONTROLS (ARRAY_SIZE(controls))
233 /******************************************************************************
235 * cpia2_open
237 *****************************************************************************/
238 static int cpia2_open(struct file *file)
240 struct camera_data *cam = video_drvdata(file);
241 struct cpia2_fh *fh;
243 if (!cam) {
244 ERR("Internal error, camera_data not found!\n");
245 return -ENODEV;
248 if (!cam->present)
249 return -ENODEV;
251 if (cam->open_count == 0) {
252 if (cpia2_allocate_buffers(cam))
253 return -ENOMEM;
255 /* reset the camera */
256 if (cpia2_reset_camera(cam) < 0)
257 return -EIO;
259 cam->APP_len = 0;
260 cam->COM_len = 0;
263 fh = kmalloc(sizeof(*fh), GFP_KERNEL);
264 if (!fh)
265 return -ENOMEM;
266 file->private_data = fh;
267 fh->prio = V4L2_PRIORITY_UNSET;
268 v4l2_prio_open(&cam->prio, &fh->prio);
269 fh->mmapped = 0;
271 ++cam->open_count;
273 cpia2_dbg_dump_registers(cam);
274 return 0;
277 /******************************************************************************
279 * cpia2_close
281 *****************************************************************************/
282 static int cpia2_close(struct file *file)
284 struct video_device *dev = video_devdata(file);
285 struct camera_data *cam = video_get_drvdata(dev);
286 struct cpia2_fh *fh = file->private_data;
288 if (cam->present &&
289 (cam->open_count == 1 || fh->prio == V4L2_PRIORITY_RECORD)) {
290 cpia2_usb_stream_stop(cam);
292 if (cam->open_count == 1) {
293 /* save camera state for later open */
294 cpia2_save_camera_state(cam);
296 cpia2_set_low_power(cam);
297 cpia2_free_buffers(cam);
301 if (fh->mmapped)
302 cam->mmapped = 0;
303 v4l2_prio_close(&cam->prio, fh->prio);
304 file->private_data = NULL;
305 kfree(fh);
307 if (--cam->open_count == 0) {
308 cpia2_free_buffers(cam);
309 if (!cam->present) {
310 video_unregister_device(dev);
311 kfree(cam);
312 return 0;
316 return 0;
319 /******************************************************************************
321 * cpia2_v4l_read
323 *****************************************************************************/
324 static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
325 loff_t *off)
327 struct camera_data *cam = video_drvdata(file);
328 int noblock = file->f_flags&O_NONBLOCK;
330 struct cpia2_fh *fh = file->private_data;
332 if(!cam)
333 return -EINVAL;
335 /* Priority check */
336 if(fh->prio != V4L2_PRIORITY_RECORD) {
337 return -EBUSY;
340 return cpia2_read(cam, buf, count, noblock);
344 /******************************************************************************
346 * cpia2_v4l_poll
348 *****************************************************************************/
349 static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
351 struct camera_data *cam = video_drvdata(filp);
352 struct cpia2_fh *fh = filp->private_data;
354 if(!cam)
355 return POLLERR;
357 /* Priority check */
358 if(fh->prio != V4L2_PRIORITY_RECORD) {
359 return POLLERR;
362 return cpia2_poll(cam, filp, wait);
366 static int sync(struct camera_data *cam, int frame_nr)
368 struct framebuf *frame = &cam->buffers[frame_nr];
370 while (1) {
371 if (frame->status == FRAME_READY)
372 return 0;
374 if (!cam->streaming) {
375 frame->status = FRAME_READY;
376 frame->length = 0;
377 return 0;
380 mutex_unlock(&cam->v4l2_lock);
381 wait_event_interruptible(cam->wq_stream,
382 !cam->streaming ||
383 frame->status == FRAME_READY);
384 mutex_lock(&cam->v4l2_lock);
385 if (signal_pending(current))
386 return -ERESTARTSYS;
387 if(!cam->present)
388 return -ENOTTY;
392 /******************************************************************************
394 * ioctl_set_gpio
396 *****************************************************************************/
398 static long cpia2_default(struct file *file, void *fh, bool valid_prio,
399 int cmd, void *arg)
401 struct camera_data *cam = video_drvdata(file);
402 __u32 gpio_val;
404 if (cmd != CPIA2_CID_GPIO)
405 return -EINVAL;
407 gpio_val = *(__u32*) arg;
409 if (gpio_val &~ 0xFFU)
410 return -EINVAL;
412 return cpia2_set_gpio(cam, (unsigned char)gpio_val);
415 /******************************************************************************
417 * ioctl_querycap
419 * V4L2 device capabilities
421 *****************************************************************************/
423 static int cpia2_querycap(struct file *file, void *fh, struct v4l2_capability *vc)
425 struct camera_data *cam = video_drvdata(file);
427 strcpy(vc->driver, "cpia2");
429 if (cam->params.pnp_id.product == 0x151)
430 strcpy(vc->card, "QX5 Microscope");
431 else
432 strcpy(vc->card, "CPiA2 Camera");
433 switch (cam->params.pnp_id.device_type) {
434 case DEVICE_STV_672:
435 strcat(vc->card, " (672/");
436 break;
437 case DEVICE_STV_676:
438 strcat(vc->card, " (676/");
439 break;
440 default:
441 strcat(vc->card, " (XXX/");
442 break;
444 switch (cam->params.version.sensor_flags) {
445 case CPIA2_VP_SENSOR_FLAGS_404:
446 strcat(vc->card, "404)");
447 break;
448 case CPIA2_VP_SENSOR_FLAGS_407:
449 strcat(vc->card, "407)");
450 break;
451 case CPIA2_VP_SENSOR_FLAGS_409:
452 strcat(vc->card, "409)");
453 break;
454 case CPIA2_VP_SENSOR_FLAGS_410:
455 strcat(vc->card, "410)");
456 break;
457 case CPIA2_VP_SENSOR_FLAGS_500:
458 strcat(vc->card, "500)");
459 break;
460 default:
461 strcat(vc->card, "XXX)");
462 break;
465 if (usb_make_path(cam->dev, vc->bus_info, sizeof(vc->bus_info)) <0)
466 memset(vc->bus_info,0, sizeof(vc->bus_info));
468 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
469 V4L2_CAP_READWRITE |
470 V4L2_CAP_STREAMING;
472 return 0;
475 /******************************************************************************
477 * ioctl_input
479 * V4L2 input get/set/enumerate
481 *****************************************************************************/
483 static int cpia2_enum_input(struct file *file, void *fh, struct v4l2_input *i)
485 if (i->index)
486 return -EINVAL;
487 strcpy(i->name, "Camera");
488 i->type = V4L2_INPUT_TYPE_CAMERA;
489 return 0;
492 static int cpia2_g_input(struct file *file, void *fh, unsigned int *i)
494 *i = 0;
495 return 0;
498 static int cpia2_s_input(struct file *file, void *fh, unsigned int i)
500 return i ? -EINVAL : 0;
503 /******************************************************************************
505 * ioctl_enum_fmt
507 * V4L2 format enumerate
509 *****************************************************************************/
511 static int cpia2_enum_fmt_vid_cap(struct file *file, void *fh,
512 struct v4l2_fmtdesc *f)
514 int index = f->index;
516 if (index < 0 || index > 1)
517 return -EINVAL;
519 memset(f, 0, sizeof(*f));
520 f->index = index;
521 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
522 f->flags = V4L2_FMT_FLAG_COMPRESSED;
523 switch(index) {
524 case 0:
525 strcpy(f->description, "MJPEG");
526 f->pixelformat = V4L2_PIX_FMT_MJPEG;
527 break;
528 case 1:
529 strcpy(f->description, "JPEG");
530 f->pixelformat = V4L2_PIX_FMT_JPEG;
531 break;
532 default:
533 return -EINVAL;
536 return 0;
539 /******************************************************************************
541 * ioctl_try_fmt
543 * V4L2 format try
545 *****************************************************************************/
547 static int cpia2_try_fmt_vid_cap(struct file *file, void *fh,
548 struct v4l2_format *f)
550 struct camera_data *cam = video_drvdata(file);
552 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG &&
553 f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG)
554 return -EINVAL;
556 f->fmt.pix.field = V4L2_FIELD_NONE;
557 f->fmt.pix.bytesperline = 0;
558 f->fmt.pix.sizeimage = cam->frame_size;
559 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
560 f->fmt.pix.priv = 0;
562 switch (cpia2_match_video_size(f->fmt.pix.width, f->fmt.pix.height)) {
563 case VIDEOSIZE_VGA:
564 f->fmt.pix.width = 640;
565 f->fmt.pix.height = 480;
566 break;
567 case VIDEOSIZE_CIF:
568 f->fmt.pix.width = 352;
569 f->fmt.pix.height = 288;
570 break;
571 case VIDEOSIZE_QVGA:
572 f->fmt.pix.width = 320;
573 f->fmt.pix.height = 240;
574 break;
575 case VIDEOSIZE_288_216:
576 f->fmt.pix.width = 288;
577 f->fmt.pix.height = 216;
578 break;
579 case VIDEOSIZE_256_192:
580 f->fmt.pix.width = 256;
581 f->fmt.pix.height = 192;
582 break;
583 case VIDEOSIZE_224_168:
584 f->fmt.pix.width = 224;
585 f->fmt.pix.height = 168;
586 break;
587 case VIDEOSIZE_192_144:
588 f->fmt.pix.width = 192;
589 f->fmt.pix.height = 144;
590 break;
591 case VIDEOSIZE_QCIF:
592 default:
593 f->fmt.pix.width = 176;
594 f->fmt.pix.height = 144;
595 break;
598 return 0;
601 /******************************************************************************
603 * ioctl_set_fmt
605 * V4L2 format set
607 *****************************************************************************/
609 static int cpia2_s_fmt_vid_cap(struct file *file, void *_fh,
610 struct v4l2_format *f)
612 struct camera_data *cam = video_drvdata(file);
613 struct cpia2_fh *fh = _fh;
614 int err, frame;
616 err = v4l2_prio_check(&cam->prio, fh->prio);
617 if (err)
618 return err;
619 err = cpia2_try_fmt_vid_cap(file, _fh, f);
620 if(err != 0)
621 return err;
623 /* Ensure that only this process can change the format. */
624 err = v4l2_prio_change(&cam->prio, &fh->prio, V4L2_PRIORITY_RECORD);
625 if(err != 0) {
626 return err;
629 cam->pixelformat = f->fmt.pix.pixelformat;
631 /* NOTE: This should be set to 1 for MJPEG, but some apps don't handle
632 * the missing Huffman table properly. */
633 cam->params.compression.inhibit_htables = 0;
634 /*f->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG;*/
636 /* we set the video window to something smaller or equal to what
637 * is requested by the user???
639 DBG("Requested width = %d, height = %d\n",
640 f->fmt.pix.width, f->fmt.pix.height);
641 if (f->fmt.pix.width != cam->width ||
642 f->fmt.pix.height != cam->height) {
643 cam->width = f->fmt.pix.width;
644 cam->height = f->fmt.pix.height;
645 cam->params.roi.width = f->fmt.pix.width;
646 cam->params.roi.height = f->fmt.pix.height;
647 cpia2_set_format(cam);
650 for (frame = 0; frame < cam->num_frames; ++frame) {
651 if (cam->buffers[frame].status == FRAME_READING)
652 if ((err = sync(cam, frame)) < 0)
653 return err;
655 cam->buffers[frame].status = FRAME_EMPTY;
658 return 0;
661 /******************************************************************************
663 * ioctl_get_fmt
665 * V4L2 format get
667 *****************************************************************************/
669 static int cpia2_g_fmt_vid_cap(struct file *file, void *fh,
670 struct v4l2_format *f)
672 struct camera_data *cam = video_drvdata(file);
674 f->fmt.pix.width = cam->width;
675 f->fmt.pix.height = cam->height;
676 f->fmt.pix.pixelformat = cam->pixelformat;
677 f->fmt.pix.field = V4L2_FIELD_NONE;
678 f->fmt.pix.bytesperline = 0;
679 f->fmt.pix.sizeimage = cam->frame_size;
680 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
681 f->fmt.pix.priv = 0;
683 return 0;
686 /******************************************************************************
688 * ioctl_cropcap
690 * V4L2 query cropping capabilities
691 * NOTE: cropping is currently disabled
693 *****************************************************************************/
695 static int cpia2_cropcap(struct file *file, void *fh, struct v4l2_cropcap *c)
697 struct camera_data *cam = video_drvdata(file);
699 if (c->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
700 return -EINVAL;
702 c->bounds.left = 0;
703 c->bounds.top = 0;
704 c->bounds.width = cam->width;
705 c->bounds.height = cam->height;
706 c->defrect.left = 0;
707 c->defrect.top = 0;
708 c->defrect.width = cam->width;
709 c->defrect.height = cam->height;
710 c->pixelaspect.numerator = 1;
711 c->pixelaspect.denominator = 1;
713 return 0;
716 /******************************************************************************
718 * ioctl_queryctrl
720 * V4L2 query possible control variables
722 *****************************************************************************/
724 static int cpia2_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *c)
726 struct camera_data *cam = video_drvdata(file);
727 int i;
729 for(i=0; i<NUM_CONTROLS; ++i) {
730 if(c->id == controls[i].id) {
731 memcpy(c, controls+i, sizeof(*c));
732 break;
736 if(i == NUM_CONTROLS)
737 return -EINVAL;
739 /* Some devices have additional limitations */
740 switch(c->id) {
741 case V4L2_CID_BRIGHTNESS:
742 /***
743 * Don't let the register be set to zero - bug in VP4
744 * flash of full brightness
745 ***/
746 if (cam->params.pnp_id.device_type == DEVICE_STV_672)
747 c->minimum = 1;
748 break;
749 case V4L2_CID_VFLIP:
750 // VP5 Only
751 if(cam->params.pnp_id.device_type == DEVICE_STV_672)
752 c->flags |= V4L2_CTRL_FLAG_DISABLED;
753 break;
754 case CPIA2_CID_FRAMERATE:
755 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
756 cam->params.version.sensor_flags==CPIA2_VP_SENSOR_FLAGS_500){
757 // Maximum 15fps
758 for(i=0; i<c->maximum; ++i) {
759 if(framerate_controls[i].value ==
760 CPIA2_VP_FRAMERATE_15) {
761 c->maximum = i;
762 c->default_value = i;
766 break;
767 case CPIA2_CID_FLICKER_MODE:
768 // Flicker control only valid for 672.
769 if(cam->params.pnp_id.device_type != DEVICE_STV_672)
770 c->flags |= V4L2_CTRL_FLAG_DISABLED;
771 break;
772 case CPIA2_CID_LIGHTS:
773 // Light control only valid for the QX5 Microscope.
774 if(cam->params.pnp_id.product != 0x151)
775 c->flags |= V4L2_CTRL_FLAG_DISABLED;
776 break;
777 default:
778 break;
781 return 0;
784 /******************************************************************************
786 * ioctl_querymenu
788 * V4L2 query possible control variables
790 *****************************************************************************/
792 static int cpia2_querymenu(struct file *file, void *fh, struct v4l2_querymenu *m)
794 struct camera_data *cam = video_drvdata(file);
796 switch(m->id) {
797 case CPIA2_CID_FLICKER_MODE:
798 if (m->index >= NUM_FLICKER_CONTROLS)
799 return -EINVAL;
801 strcpy(m->name, flicker_controls[m->index].name);
802 break;
803 case CPIA2_CID_FRAMERATE:
805 int maximum = NUM_FRAMERATE_CONTROLS - 1;
806 if(cam->params.pnp_id.device_type == DEVICE_STV_672 &&
807 cam->params.version.sensor_flags==CPIA2_VP_SENSOR_FLAGS_500){
808 // Maximum 15fps
809 int i;
810 for(i=0; i<maximum; ++i) {
811 if(framerate_controls[i].value ==
812 CPIA2_VP_FRAMERATE_15)
813 maximum = i;
816 if (m->index > maximum)
817 return -EINVAL;
819 strcpy(m->name, framerate_controls[m->index].name);
820 break;
822 case CPIA2_CID_LIGHTS:
823 if (m->index >= NUM_LIGHTS_CONTROLS)
824 return -EINVAL;
826 strcpy(m->name, lights_controls[m->index].name);
827 break;
828 default:
829 return -EINVAL;
832 return 0;
835 /******************************************************************************
837 * ioctl_g_ctrl
839 * V4L2 get the value of a control variable
841 *****************************************************************************/
843 static int cpia2_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
845 struct camera_data *cam = video_drvdata(file);
847 switch(c->id) {
848 case V4L2_CID_BRIGHTNESS:
849 cpia2_do_command(cam, CPIA2_CMD_GET_VP_BRIGHTNESS,
850 TRANSFER_READ, 0);
851 c->value = cam->params.color_params.brightness;
852 break;
853 case V4L2_CID_CONTRAST:
854 cpia2_do_command(cam, CPIA2_CMD_GET_CONTRAST,
855 TRANSFER_READ, 0);
856 c->value = cam->params.color_params.contrast;
857 break;
858 case V4L2_CID_SATURATION:
859 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SATURATION,
860 TRANSFER_READ, 0);
861 c->value = cam->params.color_params.saturation;
862 break;
863 case V4L2_CID_HFLIP:
864 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS,
865 TRANSFER_READ, 0);
866 c->value = (cam->params.vp_params.user_effects &
867 CPIA2_VP_USER_EFFECTS_MIRROR) != 0;
868 break;
869 case V4L2_CID_VFLIP:
870 cpia2_do_command(cam, CPIA2_CMD_GET_USER_EFFECTS,
871 TRANSFER_READ, 0);
872 c->value = (cam->params.vp_params.user_effects &
873 CPIA2_VP_USER_EFFECTS_FLIP) != 0;
874 break;
875 case CPIA2_CID_TARGET_KB:
876 c->value = cam->params.vc_params.target_kb;
877 break;
878 case CPIA2_CID_GPIO:
879 cpia2_do_command(cam, CPIA2_CMD_GET_VP_GPIO_DATA,
880 TRANSFER_READ, 0);
881 c->value = cam->params.vp_params.gpio_data;
882 break;
883 case CPIA2_CID_FLICKER_MODE:
885 int i, mode;
886 cpia2_do_command(cam, CPIA2_CMD_GET_FLICKER_MODES,
887 TRANSFER_READ, 0);
888 if(cam->params.flicker_control.cam_register &
889 CPIA2_VP_FLICKER_MODES_NEVER_FLICKER) {
890 mode = NEVER_FLICKER;
891 } else {
892 if(cam->params.flicker_control.cam_register &
893 CPIA2_VP_FLICKER_MODES_50HZ) {
894 mode = FLICKER_50;
895 } else {
896 mode = FLICKER_60;
899 for(i=0; i<NUM_FLICKER_CONTROLS; i++) {
900 if(flicker_controls[i].value == mode) {
901 c->value = i;
902 break;
905 if(i == NUM_FLICKER_CONTROLS)
906 return -EINVAL;
907 break;
909 case CPIA2_CID_FRAMERATE:
911 int maximum = NUM_FRAMERATE_CONTROLS - 1;
912 int i;
913 for(i=0; i<= maximum; i++) {
914 if(cam->params.vp_params.frame_rate ==
915 framerate_controls[i].value)
916 break;
918 if(i > maximum)
919 return -EINVAL;
920 c->value = i;
921 break;
923 case CPIA2_CID_USB_ALT:
924 c->value = cam->params.camera_state.stream_mode;
925 break;
926 case CPIA2_CID_LIGHTS:
928 int i;
929 cpia2_do_command(cam, CPIA2_CMD_GET_VP_GPIO_DATA,
930 TRANSFER_READ, 0);
931 for(i=0; i<NUM_LIGHTS_CONTROLS; i++) {
932 if((cam->params.vp_params.gpio_data&GPIO_LIGHTS_MASK) ==
933 lights_controls[i].value) {
934 break;
937 if(i == NUM_LIGHTS_CONTROLS)
938 return -EINVAL;
939 c->value = i;
940 break;
942 case CPIA2_CID_RESET_CAMERA:
943 return -EINVAL;
944 default:
945 return -EINVAL;
948 DBG("Get control id:%d, value:%d\n", c->id, c->value);
950 return 0;
953 /******************************************************************************
955 * ioctl_s_ctrl
957 * V4L2 set the value of a control variable
959 *****************************************************************************/
961 static int cpia2_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
963 struct camera_data *cam = video_drvdata(file);
964 int i;
965 int retval = 0;
967 DBG("Set control id:%d, value:%d\n", c->id, c->value);
969 /* Check that the value is in range */
970 for(i=0; i<NUM_CONTROLS; i++) {
971 if(c->id == controls[i].id) {
972 if(c->value < controls[i].minimum ||
973 c->value > controls[i].maximum) {
974 return -EINVAL;
976 break;
979 if(i == NUM_CONTROLS)
980 return -EINVAL;
982 switch(c->id) {
983 case V4L2_CID_BRIGHTNESS:
984 cpia2_set_brightness(cam, c->value);
985 break;
986 case V4L2_CID_CONTRAST:
987 cpia2_set_contrast(cam, c->value);
988 break;
989 case V4L2_CID_SATURATION:
990 cpia2_set_saturation(cam, c->value);
991 break;
992 case V4L2_CID_HFLIP:
993 cpia2_set_property_mirror(cam, c->value);
994 break;
995 case V4L2_CID_VFLIP:
996 cpia2_set_property_flip(cam, c->value);
997 break;
998 case CPIA2_CID_TARGET_KB:
999 retval = cpia2_set_target_kb(cam, c->value);
1000 break;
1001 case CPIA2_CID_GPIO:
1002 retval = cpia2_set_gpio(cam, c->value);
1003 break;
1004 case CPIA2_CID_FLICKER_MODE:
1005 retval = cpia2_set_flicker_mode(cam,
1006 flicker_controls[c->value].value);
1007 break;
1008 case CPIA2_CID_FRAMERATE:
1009 retval = cpia2_set_fps(cam, framerate_controls[c->value].value);
1010 break;
1011 case CPIA2_CID_USB_ALT:
1012 retval = cpia2_usb_change_streaming_alternate(cam, c->value);
1013 break;
1014 case CPIA2_CID_LIGHTS:
1015 retval = cpia2_set_gpio(cam, lights_controls[c->value].value);
1016 break;
1017 case CPIA2_CID_RESET_CAMERA:
1018 cpia2_usb_stream_pause(cam);
1019 cpia2_reset_camera(cam);
1020 cpia2_usb_stream_resume(cam);
1021 break;
1022 default:
1023 retval = -EINVAL;
1026 return retval;
1029 /******************************************************************************
1031 * ioctl_g_jpegcomp
1033 * V4L2 get the JPEG compression parameters
1035 *****************************************************************************/
1037 static int cpia2_g_jpegcomp(struct file *file, void *fh, struct v4l2_jpegcompression *parms)
1039 struct camera_data *cam = video_drvdata(file);
1041 memset(parms, 0, sizeof(*parms));
1043 parms->quality = 80; // TODO: Can this be made meaningful?
1045 parms->jpeg_markers = V4L2_JPEG_MARKER_DQT | V4L2_JPEG_MARKER_DRI;
1046 if(!cam->params.compression.inhibit_htables) {
1047 parms->jpeg_markers |= V4L2_JPEG_MARKER_DHT;
1050 parms->APPn = cam->APPn;
1051 parms->APP_len = cam->APP_len;
1052 if(cam->APP_len > 0) {
1053 memcpy(parms->APP_data, cam->APP_data, cam->APP_len);
1054 parms->jpeg_markers |= V4L2_JPEG_MARKER_APP;
1057 parms->COM_len = cam->COM_len;
1058 if(cam->COM_len > 0) {
1059 memcpy(parms->COM_data, cam->COM_data, cam->COM_len);
1060 parms->jpeg_markers |= JPEG_MARKER_COM;
1063 DBG("G_JPEGCOMP APP_len:%d COM_len:%d\n",
1064 parms->APP_len, parms->COM_len);
1066 return 0;
1069 /******************************************************************************
1071 * ioctl_s_jpegcomp
1073 * V4L2 set the JPEG compression parameters
1074 * NOTE: quality and some jpeg_markers are ignored.
1076 *****************************************************************************/
1078 static int cpia2_s_jpegcomp(struct file *file, void *fh, struct v4l2_jpegcompression *parms)
1080 struct camera_data *cam = video_drvdata(file);
1082 DBG("S_JPEGCOMP APP_len:%d COM_len:%d\n",
1083 parms->APP_len, parms->COM_len);
1085 cam->params.compression.inhibit_htables =
1086 !(parms->jpeg_markers & V4L2_JPEG_MARKER_DHT);
1088 if(parms->APP_len != 0) {
1089 if(parms->APP_len > 0 &&
1090 parms->APP_len <= sizeof(cam->APP_data) &&
1091 parms->APPn >= 0 && parms->APPn <= 15) {
1092 cam->APPn = parms->APPn;
1093 cam->APP_len = parms->APP_len;
1094 memcpy(cam->APP_data, parms->APP_data, parms->APP_len);
1095 } else {
1096 LOG("Bad APPn Params n=%d len=%d\n",
1097 parms->APPn, parms->APP_len);
1098 return -EINVAL;
1100 } else {
1101 cam->APP_len = 0;
1104 if(parms->COM_len != 0) {
1105 if(parms->COM_len > 0 &&
1106 parms->COM_len <= sizeof(cam->COM_data)) {
1107 cam->COM_len = parms->COM_len;
1108 memcpy(cam->COM_data, parms->COM_data, parms->COM_len);
1109 } else {
1110 LOG("Bad COM_len=%d\n", parms->COM_len);
1111 return -EINVAL;
1115 return 0;
1118 /******************************************************************************
1120 * ioctl_reqbufs
1122 * V4L2 Initiate memory mapping.
1123 * NOTE: The user's request is ignored. For now the buffers are fixed.
1125 *****************************************************************************/
1127 static int cpia2_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *req)
1129 struct camera_data *cam = video_drvdata(file);
1131 if(req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1132 req->memory != V4L2_MEMORY_MMAP)
1133 return -EINVAL;
1135 DBG("REQBUFS requested:%d returning:%d\n", req->count, cam->num_frames);
1136 req->count = cam->num_frames;
1137 memset(&req->reserved, 0, sizeof(req->reserved));
1139 return 0;
1142 /******************************************************************************
1144 * ioctl_querybuf
1146 * V4L2 Query memory buffer status.
1148 *****************************************************************************/
1150 static int cpia2_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1152 struct camera_data *cam = video_drvdata(file);
1154 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1155 buf->index > cam->num_frames)
1156 return -EINVAL;
1158 buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
1159 buf->length = cam->frame_size;
1161 buf->memory = V4L2_MEMORY_MMAP;
1163 if(cam->mmapped)
1164 buf->flags = V4L2_BUF_FLAG_MAPPED;
1165 else
1166 buf->flags = 0;
1168 switch (cam->buffers[buf->index].status) {
1169 case FRAME_EMPTY:
1170 case FRAME_ERROR:
1171 case FRAME_READING:
1172 buf->bytesused = 0;
1173 buf->flags = V4L2_BUF_FLAG_QUEUED;
1174 break;
1175 case FRAME_READY:
1176 buf->bytesused = cam->buffers[buf->index].length;
1177 buf->timestamp = cam->buffers[buf->index].timestamp;
1178 buf->sequence = cam->buffers[buf->index].seq;
1179 buf->flags = V4L2_BUF_FLAG_DONE;
1180 break;
1183 DBG("QUERYBUF index:%d offset:%d flags:%d seq:%d bytesused:%d\n",
1184 buf->index, buf->m.offset, buf->flags, buf->sequence,
1185 buf->bytesused);
1187 return 0;
1190 /******************************************************************************
1192 * ioctl_qbuf
1194 * V4L2 User is freeing buffer
1196 *****************************************************************************/
1198 static int cpia2_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1200 struct camera_data *cam = video_drvdata(file);
1202 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1203 buf->memory != V4L2_MEMORY_MMAP ||
1204 buf->index > cam->num_frames)
1205 return -EINVAL;
1207 DBG("QBUF #%d\n", buf->index);
1209 if(cam->buffers[buf->index].status == FRAME_READY)
1210 cam->buffers[buf->index].status = FRAME_EMPTY;
1212 return 0;
1215 /******************************************************************************
1217 * find_earliest_filled_buffer
1219 * Helper for ioctl_dqbuf. Find the next ready buffer.
1221 *****************************************************************************/
1223 static int find_earliest_filled_buffer(struct camera_data *cam)
1225 int i;
1226 int found = -1;
1227 for (i=0; i<cam->num_frames; i++) {
1228 if(cam->buffers[i].status == FRAME_READY) {
1229 if(found < 0) {
1230 found = i;
1231 } else {
1232 /* find which buffer is earlier */
1233 struct timeval *tv1, *tv2;
1234 tv1 = &cam->buffers[i].timestamp;
1235 tv2 = &cam->buffers[found].timestamp;
1236 if(tv1->tv_sec < tv2->tv_sec ||
1237 (tv1->tv_sec == tv2->tv_sec &&
1238 tv1->tv_usec < tv2->tv_usec))
1239 found = i;
1243 return found;
1246 /******************************************************************************
1248 * ioctl_dqbuf
1250 * V4L2 User is asking for a filled buffer.
1252 *****************************************************************************/
1254 static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1256 struct camera_data *cam = video_drvdata(file);
1257 int frame;
1259 if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1260 buf->memory != V4L2_MEMORY_MMAP)
1261 return -EINVAL;
1263 frame = find_earliest_filled_buffer(cam);
1265 if(frame < 0 && file->f_flags&O_NONBLOCK)
1266 return -EAGAIN;
1268 if(frame < 0) {
1269 /* Wait for a frame to become available */
1270 struct framebuf *cb=cam->curbuff;
1271 mutex_unlock(&cam->v4l2_lock);
1272 wait_event_interruptible(cam->wq_stream,
1273 !cam->present ||
1274 (cb=cam->curbuff)->status == FRAME_READY);
1275 mutex_lock(&cam->v4l2_lock);
1276 if (signal_pending(current))
1277 return -ERESTARTSYS;
1278 if(!cam->present)
1279 return -ENOTTY;
1280 frame = cb->num;
1284 buf->index = frame;
1285 buf->bytesused = cam->buffers[buf->index].length;
1286 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE;
1287 buf->field = V4L2_FIELD_NONE;
1288 buf->timestamp = cam->buffers[buf->index].timestamp;
1289 buf->sequence = cam->buffers[buf->index].seq;
1290 buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
1291 buf->length = cam->frame_size;
1292 buf->input = 0;
1293 buf->reserved = 0;
1294 memset(&buf->timecode, 0, sizeof(buf->timecode));
1296 DBG("DQBUF #%d status:%d seq:%d length:%d\n", buf->index,
1297 cam->buffers[buf->index].status, buf->sequence, buf->bytesused);
1299 return 0;
1302 static int cpia2_g_priority(struct file *file, void *_fh, enum v4l2_priority *p)
1304 struct cpia2_fh *fh = _fh;
1306 *p = fh->prio;
1307 return 0;
1310 static int cpia2_s_priority(struct file *file, void *_fh, enum v4l2_priority prio)
1312 struct camera_data *cam = video_drvdata(file);
1313 struct cpia2_fh *fh = _fh;
1315 if (cam->streaming && prio != fh->prio &&
1316 fh->prio == V4L2_PRIORITY_RECORD)
1317 /* Can't drop record priority while streaming */
1318 return -EBUSY;
1320 if (prio == V4L2_PRIORITY_RECORD && prio != fh->prio &&
1321 v4l2_prio_max(&cam->prio) == V4L2_PRIORITY_RECORD)
1322 /* Only one program can record at a time */
1323 return -EBUSY;
1324 return v4l2_prio_change(&cam->prio, &fh->prio, prio);
1327 static int cpia2_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
1329 struct camera_data *cam = video_drvdata(file);
1331 DBG("VIDIOC_STREAMON, streaming=%d\n", cam->streaming);
1332 if (!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1333 return -EINVAL;
1335 if (!cam->streaming)
1336 return cpia2_usb_stream_start(cam,
1337 cam->params.camera_state.stream_mode);
1338 return -EINVAL;
1341 static int cpia2_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
1343 struct camera_data *cam = video_drvdata(file);
1345 DBG("VIDIOC_STREAMOFF, streaming=%d\n", cam->streaming);
1346 if (!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1347 return -EINVAL;
1349 if (cam->streaming)
1350 return cpia2_usb_stream_stop(cam);
1351 return -EINVAL;
1354 /******************************************************************************
1356 * cpia2_mmap
1358 *****************************************************************************/
1359 static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
1361 struct camera_data *cam = video_drvdata(file);
1362 int retval;
1364 /* Priority check */
1365 struct cpia2_fh *fh = file->private_data;
1366 if(fh->prio != V4L2_PRIORITY_RECORD) {
1367 return -EBUSY;
1370 retval = cpia2_remap_buffer(cam, area);
1372 if(!retval)
1373 fh->mmapped = 1;
1374 return retval;
1377 /******************************************************************************
1379 * reset_camera_struct_v4l
1381 * Sets all values to the defaults
1382 *****************************************************************************/
1383 static void reset_camera_struct_v4l(struct camera_data *cam)
1385 cam->width = cam->params.roi.width;
1386 cam->height = cam->params.roi.height;
1388 cam->frame_size = buffer_size;
1389 cam->num_frames = num_buffers;
1391 /* FlickerModes */
1392 cam->params.flicker_control.flicker_mode_req = flicker_mode;
1393 cam->params.flicker_control.mains_frequency = flicker_freq;
1395 /* streamMode */
1396 cam->params.camera_state.stream_mode = alternate;
1398 cam->pixelformat = V4L2_PIX_FMT_JPEG;
1399 v4l2_prio_init(&cam->prio);
1402 static const struct v4l2_ioctl_ops cpia2_ioctl_ops = {
1403 .vidioc_querycap = cpia2_querycap,
1404 .vidioc_enum_input = cpia2_enum_input,
1405 .vidioc_g_input = cpia2_g_input,
1406 .vidioc_s_input = cpia2_s_input,
1407 .vidioc_enum_fmt_vid_cap = cpia2_enum_fmt_vid_cap,
1408 .vidioc_g_fmt_vid_cap = cpia2_g_fmt_vid_cap,
1409 .vidioc_s_fmt_vid_cap = cpia2_s_fmt_vid_cap,
1410 .vidioc_try_fmt_vid_cap = cpia2_try_fmt_vid_cap,
1411 .vidioc_queryctrl = cpia2_queryctrl,
1412 .vidioc_querymenu = cpia2_querymenu,
1413 .vidioc_g_ctrl = cpia2_g_ctrl,
1414 .vidioc_s_ctrl = cpia2_s_ctrl,
1415 .vidioc_g_jpegcomp = cpia2_g_jpegcomp,
1416 .vidioc_s_jpegcomp = cpia2_s_jpegcomp,
1417 .vidioc_cropcap = cpia2_cropcap,
1418 .vidioc_reqbufs = cpia2_reqbufs,
1419 .vidioc_querybuf = cpia2_querybuf,
1420 .vidioc_qbuf = cpia2_qbuf,
1421 .vidioc_dqbuf = cpia2_dqbuf,
1422 .vidioc_streamon = cpia2_streamon,
1423 .vidioc_streamoff = cpia2_streamoff,
1424 .vidioc_g_priority = cpia2_g_priority,
1425 .vidioc_s_priority = cpia2_s_priority,
1426 .vidioc_default = cpia2_default,
1429 /***
1430 * The v4l video device structure initialized for this device
1431 ***/
1432 static const struct v4l2_file_operations cpia2_fops = {
1433 .owner = THIS_MODULE,
1434 .open = cpia2_open,
1435 .release = cpia2_close,
1436 .read = cpia2_v4l_read,
1437 .poll = cpia2_v4l_poll,
1438 .unlocked_ioctl = video_ioctl2,
1439 .mmap = cpia2_mmap,
1442 static struct video_device cpia2_template = {
1443 /* I could not find any place for the old .initialize initializer?? */
1444 .name = "CPiA2 Camera",
1445 .fops = &cpia2_fops,
1446 .ioctl_ops = &cpia2_ioctl_ops,
1447 .release = video_device_release,
1450 /******************************************************************************
1452 * cpia2_register_camera
1454 *****************************************************************************/
1455 int cpia2_register_camera(struct camera_data *cam)
1457 cam->vdev = video_device_alloc();
1458 if(!cam->vdev)
1459 return -ENOMEM;
1461 memcpy(cam->vdev, &cpia2_template, sizeof(cpia2_template));
1462 video_set_drvdata(cam->vdev, cam);
1463 cam->vdev->lock = &cam->v4l2_lock;
1465 reset_camera_struct_v4l(cam);
1467 /* register v4l device */
1468 if (video_register_device(cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
1469 ERR("video_register_device failed\n");
1470 video_device_release(cam->vdev);
1471 return -ENODEV;
1474 return 0;
1477 /******************************************************************************
1479 * cpia2_unregister_camera
1481 *****************************************************************************/
1482 void cpia2_unregister_camera(struct camera_data *cam)
1484 if (!cam->open_count) {
1485 video_unregister_device(cam->vdev);
1486 } else {
1487 LOG("%s removed while open, deferring "
1488 "video_unregister_device\n",
1489 video_device_node_name(cam->vdev));
1493 /******************************************************************************
1495 * check_parameters
1497 * Make sure that all user-supplied parameters are sensible
1498 *****************************************************************************/
1499 static void __init check_parameters(void)
1501 if(buffer_size < PAGE_SIZE) {
1502 buffer_size = PAGE_SIZE;
1503 LOG("buffer_size too small, setting to %d\n", buffer_size);
1504 } else if(buffer_size > 1024*1024) {
1505 /* arbitrary upper limiit */
1506 buffer_size = 1024*1024;
1507 LOG("buffer_size ridiculously large, setting to %d\n",
1508 buffer_size);
1509 } else {
1510 buffer_size += PAGE_SIZE-1;
1511 buffer_size &= ~(PAGE_SIZE-1);
1514 if(num_buffers < 1) {
1515 num_buffers = 1;
1516 LOG("num_buffers too small, setting to %d\n", num_buffers);
1517 } else if(num_buffers > VIDEO_MAX_FRAME) {
1518 num_buffers = VIDEO_MAX_FRAME;
1519 LOG("num_buffers too large, setting to %d\n", num_buffers);
1522 if(alternate < USBIF_ISO_1 || alternate > USBIF_ISO_6) {
1523 alternate = DEFAULT_ALT;
1524 LOG("alternate specified is invalid, using %d\n", alternate);
1527 if (flicker_mode != NEVER_FLICKER && flicker_mode != ANTI_FLICKER_ON) {
1528 flicker_mode = NEVER_FLICKER;
1529 LOG("Flicker mode specified is invalid, using %d\n",
1530 flicker_mode);
1533 if (flicker_freq != FLICKER_50 && flicker_freq != FLICKER_60) {
1534 flicker_freq = FLICKER_60;
1535 LOG("Flicker mode specified is invalid, using %d\n",
1536 flicker_freq);
1539 if(video_nr < -1 || video_nr > 64) {
1540 video_nr = -1;
1541 LOG("invalid video_nr specified, must be -1 to 64\n");
1544 DBG("Using %d buffers, each %d bytes, alternate=%d\n",
1545 num_buffers, buffer_size, alternate);
1548 /************ Module Stuff ***************/
1551 /******************************************************************************
1553 * cpia2_init/module_init
1555 *****************************************************************************/
1556 static int __init cpia2_init(void)
1558 LOG("%s v%s\n",
1559 ABOUT, CPIA_VERSION);
1560 check_parameters();
1561 cpia2_usb_init();
1562 return 0;
1566 /******************************************************************************
1568 * cpia2_exit/module_exit
1570 *****************************************************************************/
1571 static void __exit cpia2_exit(void)
1573 cpia2_usb_cleanup();
1574 schedule_timeout(2 * HZ);
1577 module_init(cpia2_init);
1578 module_exit(cpia2_exit);