2 * konicawc.c - konica webcam driver
4 * Author: Simon Evans <spse@secret.org.uk>
6 * Copyright (C) 2002 Simon Evans
10 * Driver for USB webcams based on Konica chipset. This
11 * chipset is used in Intel YC76 camera.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/usb/input.h>
22 #define MAX_BRIGHTNESS 108
23 #define MAX_CONTRAST 108
24 #define MAX_SATURATION 108
25 #define MAX_SHARPNESS 108
26 #define MAX_WHITEBAL 372
32 #define DRIVER_VERSION "v1.4"
33 #define DRIVER_DESC "Konica Webcam driver"
52 #define MAX_FRAME_SIZE SIZE_320X240
54 static struct usbvideo *cams;
56 #ifdef CONFIG_USB_DEBUG
58 #define DEBUG(n, format, arg...) \
60 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __FUNCTION__ , ## arg); \
63 #define DEBUG(n, arg...)
64 static const int debug = 0;
68 /* Some default values for initial camera settings,
69 can be set by modprobe */
72 static int speed = 6; /* Speed (fps) 0 (slowest) to 6 (fastest) */
73 static int brightness = MAX_BRIGHTNESS/2;
74 static int contrast = MAX_CONTRAST/2;
75 static int saturation = MAX_SATURATION/2;
76 static int sharpness = MAX_SHARPNESS/2;
77 static int whitebal = 3*(MAX_WHITEBAL/4);
79 static const int spd_to_iface[] = { 1, 0, 3, 2, 4, 5, 6 };
81 /* These FPS speeds are from the windows config box. They are
82 * indexed on size (0-2) and speed (0-6). Divide by 3 to get the
86 static const int spd_to_fps[][7] = { { 24, 40, 48, 60, 72, 80, 100 },
87 { 24, 40, 48, 60, 72, 80, 100 },
88 { 18, 30, 36, 45, 54, 60, 75 },
89 { 6, 10, 12, 15, 18, 21, 25 } };
97 static const struct cam_size camera_sizes[] = { { 160, 120, 0x7 },
103 u8 brightness; /* camera uses 0 - 9, x11 for real value */
104 u8 contrast; /* as above */
105 u8 saturation; /* as above */
106 u8 sharpness; /* as above */
107 u8 white_bal; /* 0 - 33, x11 for real value */
108 u8 speed; /* Stored as 0 - 6, used as index in spd_to_* (above) */
109 u8 size; /* Frame Size */
112 struct urb *sts_urb[USBVIDEO_NUMSBUF];
113 u8 sts_buf[USBVIDEO_NUMSBUF][FRAMES_PER_DESC];
114 struct urb *last_data_urb;
116 int cur_frame_size; /* number of bytes in current frame size */
117 int maxline; /* number of lines per frame */
118 int yplanesz; /* Number of bytes in the Y plane */
119 unsigned int buttonsts:1;
121 struct input_dev *input;
122 char input_physname[64];
127 #define konicawc_set_misc(uvd, req, value, index) konicawc_ctrl_msg(uvd, USB_DIR_OUT, req, value, index, NULL, 0)
128 #define konicawc_get_misc(uvd, req, value, index, buf, sz) konicawc_ctrl_msg(uvd, USB_DIR_IN, req, value, index, buf, sz)
129 #define konicawc_set_value(uvd, value, index) konicawc_ctrl_msg(uvd, USB_DIR_OUT, 2, value, index, NULL, 0)
132 static int konicawc_ctrl_msg(struct uvd *uvd, u8 dir, u8 request, u16 value, u16 index, void *buf, int len)
134 int retval = usb_control_msg(uvd->dev,
135 dir ? usb_rcvctrlpipe(uvd->dev, 0) : usb_sndctrlpipe(uvd->dev, 0),
136 request, 0x40 | dir, value, index, buf, len, 1000);
137 return retval < 0 ? retval : 0;
141 static inline void konicawc_camera_on(struct uvd *uvd)
143 DEBUG(0, "camera on");
144 konicawc_set_misc(uvd, 0x2, 1, 0x0b);
148 static inline void konicawc_camera_off(struct uvd *uvd)
150 DEBUG(0, "camera off");
151 konicawc_set_misc(uvd, 0x2, 0, 0x0b);
155 static void konicawc_set_camera_size(struct uvd *uvd)
157 struct konicawc *cam = (struct konicawc *)uvd->user_data;
159 konicawc_set_misc(uvd, 0x2, camera_sizes[cam->size].cmd, 0x08);
160 cam->width = camera_sizes[cam->size].width;
161 cam->height = camera_sizes[cam->size].height;
162 cam->yplanesz = cam->height * cam->width;
163 cam->cur_frame_size = (cam->yplanesz * 3) / 2;
164 cam->maxline = cam->yplanesz / 256;
165 uvd->videosize = VIDEOSIZE(cam->width, cam->height);
169 static int konicawc_setup_on_open(struct uvd *uvd)
171 struct konicawc *cam = (struct konicawc *)uvd->user_data;
173 DEBUG(1, "setting brightness to %d (%d)", cam->brightness,
174 cam->brightness * 11);
175 konicawc_set_value(uvd, cam->brightness, SetBrightness);
176 DEBUG(1, "setting white balance to %d (%d)", cam->white_bal,
177 cam->white_bal * 11);
178 konicawc_set_value(uvd, cam->white_bal, SetWhitebal);
179 DEBUG(1, "setting contrast to %d (%d)", cam->contrast,
181 konicawc_set_value(uvd, cam->contrast, SetContrast);
182 DEBUG(1, "setting saturation to %d (%d)", cam->saturation,
183 cam->saturation * 11);
184 konicawc_set_value(uvd, cam->saturation, SetSaturation);
185 DEBUG(1, "setting sharpness to %d (%d)", cam->sharpness,
186 cam->sharpness * 11);
187 konicawc_set_value(uvd, cam->sharpness, SetSharpness);
188 konicawc_set_camera_size(uvd);
195 static void konicawc_adjust_picture(struct uvd *uvd)
197 struct konicawc *cam = (struct konicawc *)uvd->user_data;
199 konicawc_camera_off(uvd);
200 DEBUG(1, "new brightness: %d", uvd->vpic.brightness);
201 uvd->vpic.brightness = (uvd->vpic.brightness > MAX_BRIGHTNESS) ? MAX_BRIGHTNESS : uvd->vpic.brightness;
202 if(cam->brightness != uvd->vpic.brightness / 11) {
203 cam->brightness = uvd->vpic.brightness / 11;
204 DEBUG(1, "setting brightness to %d (%d)", cam->brightness,
205 cam->brightness * 11);
206 konicawc_set_value(uvd, cam->brightness, SetBrightness);
209 DEBUG(1, "new contrast: %d", uvd->vpic.contrast);
210 uvd->vpic.contrast = (uvd->vpic.contrast > MAX_CONTRAST) ? MAX_CONTRAST : uvd->vpic.contrast;
211 if(cam->contrast != uvd->vpic.contrast / 11) {
212 cam->contrast = uvd->vpic.contrast / 11;
213 DEBUG(1, "setting contrast to %d (%d)", cam->contrast,
215 konicawc_set_value(uvd, cam->contrast, SetContrast);
217 konicawc_camera_on(uvd);
222 static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev)
224 struct input_dev *input_dev;
226 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
227 strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
229 cam->input = input_dev = input_allocate_device();
231 warn("Not enough memory for camera's input device\n");
235 input_dev->name = "Konicawc snapshot button";
236 input_dev->phys = cam->input_physname;
237 usb_to_input_id(dev, &input_dev->id);
238 input_dev->cdev.dev = &dev->dev;
240 input_dev->evbit[0] = BIT(EV_KEY);
241 input_dev->keybit[LONG(BTN_0)] = BIT(BTN_0);
243 input_dev->private = cam;
245 input_register_device(cam->input);
248 static void konicawc_unregister_input(struct konicawc *cam)
251 input_unregister_device(cam->input);
256 static void konicawc_report_buttonstat(struct konicawc *cam)
259 input_report_key(cam->input, BTN_0, cam->buttonsts);
260 input_sync(cam->input);
266 static inline void konicawc_register_input(struct konicawc *cam, struct usb_device *dev) { }
267 static inline void konicawc_unregister_input(struct konicawc *cam) { }
268 static inline void konicawc_report_buttonstat(struct konicawc *cam) { }
270 #endif /* CONFIG_INPUT */
272 static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct urb *stsurb)
276 unsigned char *status = stsurb->transfer_buffer;
277 int keep = 0, discard = 0, bad = 0;
278 struct konicawc *cam = (struct konicawc *)uvd->user_data;
280 for (i = 0; i < dataurb->number_of_packets; i++) {
281 int button = cam->buttonsts;
283 int n = dataurb->iso_frame_desc[i].actual_length;
284 int st = dataurb->iso_frame_desc[i].status;
285 cdata = dataurb->transfer_buffer +
286 dataurb->iso_frame_desc[i].offset;
288 /* Detect and ignore errored packets */
290 DEBUG(1, "Data error: packet=%d. len=%d. status=%d.",
292 uvd->stats.iso_err_count++;
296 /* Detect and ignore empty packets */
298 uvd->stats.iso_skip_count++;
302 /* See what the status data said about the packet */
303 sts = *(status+stsurb->iso_frame_desc[i].offset);
305 /* sts: 0x80-0xff: frame start with frame number (ie 0-7f)
307 * bit 0 0: keep packet
308 * 1: drop packet (padding data)
310 * bit 4 0 button not clicked
312 * button is used to `take a picture' (in software)
316 button = !!(sts & 0x40);
320 /* work out the button status, but don't do
321 anything with it for now */
323 if(button != cam->buttonsts) {
324 DEBUG(2, "button: %sclicked", button ? "" : "un");
325 cam->buttonsts = button;
326 konicawc_report_buttonstat(cam);
329 if(sts == 0x01) { /* drop frame */
334 if((sts > 0x01) && (sts < 0x80)) {
335 info("unknown status %2.2x", sts);
339 if(!sts && cam->lastframe == -2) {
340 DEBUG(2, "dropping frame looking for image start");
345 if(sts & 0x80) { /* frame start */
346 unsigned char marker[] = { 0, 0xff, 0, 0x00 };
348 if(cam->lastframe == -2) {
349 DEBUG(2, "found initial image");
353 marker[3] = sts & 0x7F;
354 RingQueue_Enqueue(&uvd->dp, marker, 4);
358 totlen += n; /* Little local accounting */
359 RingQueue_Enqueue(&uvd->dp, cdata, n);
361 DEBUG(8, "finished: keep = %d discard = %d bad = %d added %d bytes",
362 keep, discard, bad, totlen);
367 static void resubmit_urb(struct uvd *uvd, struct urb *urb)
370 for (i = 0; i < FRAMES_PER_DESC; i++) {
371 urb->iso_frame_desc[i].status = 0;
375 ret = usb_submit_urb(urb, GFP_ATOMIC);
376 DEBUG(3, "submitting urb of length %d", urb->transfer_buffer_length);
378 err("usb_submit_urb error (%d)", ret);
383 static void konicawc_isoc_irq(struct urb *urb, struct pt_regs *regs)
385 struct uvd *uvd = urb->context;
386 struct konicawc *cam = (struct konicawc *)uvd->user_data;
388 /* We don't want to do anything if we are about to be removed! */
389 if (!CAMERA_IS_OPERATIONAL(uvd))
392 if (!uvd->streaming) {
393 DEBUG(1, "Not streaming, but interrupt!");
397 DEBUG(3, "got frame %d len = %d buflen =%d", urb->start_frame, urb->actual_length, urb->transfer_buffer_length);
399 uvd->stats.urb_count++;
401 if (urb->transfer_buffer_length > 32) {
402 cam->last_data_urb = urb;
405 /* Copy the data received into ring queue */
406 if(cam->last_data_urb) {
408 if(urb->start_frame != cam->last_data_urb->start_frame)
409 err("Lost sync on frames");
410 else if (!urb->status && !cam->last_data_urb->status)
411 len = konicawc_compress_iso(uvd, cam->last_data_urb, urb);
413 resubmit_urb(uvd, cam->last_data_urb);
414 resubmit_urb(uvd, urb);
415 cam->last_data_urb = NULL;
416 uvd->stats.urb_length = len;
417 uvd->stats.data_count += len;
419 RingQueue_WakeUpInterruptible(&uvd->dp);
426 static int konicawc_start_data(struct uvd *uvd)
428 struct usb_device *dev = uvd->dev;
430 struct konicawc *cam = (struct konicawc *)uvd->user_data;
432 struct usb_interface *intf;
433 struct usb_host_interface *interface = NULL;
435 intf = usb_ifnum_to_if(dev, uvd->iface);
437 interface = usb_altnum_to_altsetting(intf,
438 spd_to_iface[cam->speed]);
441 pktsz = le16_to_cpu(interface->endpoint[1].desc.wMaxPacketSize);
442 DEBUG(1, "pktsz = %d", pktsz);
443 if (!CAMERA_IS_OPERATIONAL(uvd)) {
444 err("Camera is not operational");
448 konicawc_camera_on(uvd);
449 /* Alternate interface 1 is is the biggest frame size */
450 i = usb_set_interface(dev, uvd->iface, uvd->ifaceAltActive);
452 err("usb_set_interface error");
457 /* We double buffer the Iso lists */
458 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
460 struct urb *urb = uvd->sbuf[i].urb;
463 urb->pipe = usb_rcvisocpipe(dev, uvd->video_endp);
465 urb->transfer_flags = URB_ISO_ASAP;
466 urb->transfer_buffer = uvd->sbuf[i].data;
467 urb->complete = konicawc_isoc_irq;
468 urb->number_of_packets = FRAMES_PER_DESC;
469 urb->transfer_buffer_length = pktsz * FRAMES_PER_DESC;
470 for (j=k=0; j < FRAMES_PER_DESC; j++, k += pktsz) {
471 urb->iso_frame_desc[j].offset = k;
472 urb->iso_frame_desc[j].length = pktsz;
475 urb = cam->sts_urb[i];
478 urb->pipe = usb_rcvisocpipe(dev, uvd->video_endp-1);
480 urb->transfer_flags = URB_ISO_ASAP;
481 urb->transfer_buffer = cam->sts_buf[i];
482 urb->complete = konicawc_isoc_irq;
483 urb->number_of_packets = FRAMES_PER_DESC;
484 urb->transfer_buffer_length = FRAMES_PER_DESC;
485 for (j=0; j < FRAMES_PER_DESC; j++) {
486 urb->iso_frame_desc[j].offset = j;
487 urb->iso_frame_desc[j].length = 1;
491 cam->last_data_urb = NULL;
493 /* Submit all URBs */
494 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
495 errFlag = usb_submit_urb(cam->sts_urb[i], GFP_KERNEL);
497 err("usb_submit_isoc(%d) ret %d", i, errFlag);
499 errFlag = usb_submit_urb(uvd->sbuf[i].urb, GFP_KERNEL);
501 err ("usb_submit_isoc(%d) ret %d", i, errFlag);
505 DEBUG(1, "streaming=1 video_endp=$%02x", uvd->video_endp);
510 static void konicawc_stop_data(struct uvd *uvd)
513 struct konicawc *cam;
515 if ((uvd == NULL) || (!uvd->streaming) || (uvd->dev == NULL))
518 konicawc_camera_off(uvd);
520 cam = (struct konicawc *)uvd->user_data;
521 cam->last_data_urb = NULL;
523 /* Unschedule all of the iso td's */
524 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
525 usb_kill_urb(uvd->sbuf[i].urb);
526 usb_kill_urb(cam->sts_urb[i]);
529 if (!uvd->remove_pending) {
530 /* Set packet size to 0 */
531 j = usb_set_interface(uvd->dev, uvd->iface, uvd->ifaceAltInactive);
533 err("usb_set_interface() error %d.", j);
540 static void konicawc_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame)
542 struct konicawc *cam = (struct konicawc *)uvd->user_data;
543 int maxline = cam->maxline;
544 int yplanesz = cam->yplanesz;
546 assert(frame != NULL);
548 DEBUG(5, "maxline = %d yplanesz = %d", maxline, yplanesz);
549 DEBUG(3, "Frame state = %d", frame->scanstate);
551 if(frame->scanstate == ScanState_Scanning) {
555 DEBUG(3, "Searching for marker, queue len = %d", RingQueue_GetLength(&uvd->dp));
556 while(RingQueue_GetLength(&uvd->dp) >= 4) {
557 if ((RING_QUEUE_PEEK(&uvd->dp, 0) == 0x00) &&
558 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xff) &&
559 (RING_QUEUE_PEEK(&uvd->dp, 2) == 0x00) &&
560 (RING_QUEUE_PEEK(&uvd->dp, 3) < 0x80)) {
561 curframe = RING_QUEUE_PEEK(&uvd->dp, 3);
562 if(cam->lastframe >= 0) {
563 fdrops = (0x80 + curframe - cam->lastframe) & 0x7F;
566 info("Dropped %d frames (%d -> %d)", fdrops,
567 cam->lastframe, curframe);
570 cam->lastframe = curframe;
572 frame->scanstate = ScanState_Lines;
573 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 4);
576 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 1);
580 DEBUG(2, "dropped %d bytes looking for new frame", drop);
583 if(frame->scanstate == ScanState_Scanning)
586 /* Try to move data from queue into frame buffer
587 * We get data in blocks of 384 bytes made up of:
589 * This needs to be written out as a Y plane, a U plane and a V plane.
592 while ( frame->curline < maxline && (RingQueue_GetLength(&uvd->dp) >= 384)) {
594 RingQueue_Dequeue(&uvd->dp, frame->data + (frame->curline * 256), 256);
596 RingQueue_Dequeue(&uvd->dp, frame->data + yplanesz + (frame->curline * 64), 64);
598 RingQueue_Dequeue(&uvd->dp, frame->data + (5 * yplanesz)/4 + (frame->curline * 64), 64);
599 frame->seqRead_Length += 384;
602 /* See if we filled the frame */
603 if (frame->curline == maxline) {
604 DEBUG(5, "got whole frame");
606 frame->frameState = FrameState_Done_Hold;
609 uvd->stats.frame_num++;
614 static int konicawc_find_fps(int size, int fps)
619 DEBUG(1, "konica_find_fps: size = %d fps = %d", size, fps);
620 if(fps <= spd_to_fps[size][0])
623 if(fps >= spd_to_fps[size][MAX_SPEED])
626 for(i = 0; i < MAX_SPEED; i++) {
627 if((fps >= spd_to_fps[size][i]) && (fps <= spd_to_fps[size][i+1])) {
628 DEBUG(2, "fps %d between %d and %d", fps, i, i+1);
629 if( (fps - spd_to_fps[size][i]) < (spd_to_fps[size][i+1] - fps))
639 static int konicawc_set_video_mode(struct uvd *uvd, struct video_window *vw)
641 struct konicawc *cam = (struct konicawc *)uvd->user_data;
642 int newspeed = cam->speed;
649 DEBUG(2, "trying to find size %d,%d", x, y);
650 for(newsize = 0; newsize <= MAX_FRAME_SIZE; newsize++) {
651 if((camera_sizes[newsize].width == x) && (camera_sizes[newsize].height == y))
658 if(newsize > MAX_FRAME_SIZE) {
659 DEBUG(1, "couldn't find size %d,%d", x, y);
664 DEBUG(1, "trying to set fps to %d", fps);
665 newspeed = konicawc_find_fps(newsize, fps);
666 DEBUG(1, "find_fps returned %d (%d)", newspeed, spd_to_fps[newsize][newspeed]);
669 if(newspeed > MAX_SPEED)
672 DEBUG(1, "setting size to %d speed to %d", newsize, newspeed);
673 if((newsize == cam->size) && (newspeed == cam->speed)) {
674 DEBUG(1, "Nothing to do");
677 DEBUG(0, "setting to %dx%d @ %d fps", camera_sizes[newsize].width,
678 camera_sizes[newsize].height, spd_to_fps[newsize][newspeed]/3);
680 konicawc_stop_data(uvd);
681 uvd->ifaceAltActive = spd_to_iface[newspeed];
682 DEBUG(1, "new interface = %d", uvd->ifaceAltActive);
683 cam->speed = newspeed;
685 if(cam->size != newsize) {
687 konicawc_set_camera_size(uvd);
690 /* Flush the input queue and clear any current frame in progress */
692 RingQueue_Flush(&uvd->dp);
694 if(uvd->curframe != -1) {
695 uvd->frame[uvd->curframe].curline = 0;
696 uvd->frame[uvd->curframe].seqRead_Length = 0;
697 uvd->frame[uvd->curframe].seqRead_Index = 0;
700 konicawc_start_data(uvd);
705 static int konicawc_calculate_fps(struct uvd *uvd)
707 struct konicawc *cam = uvd->user_data;
708 return spd_to_fps[cam->size][cam->speed]/3;
712 static void konicawc_configure_video(struct uvd *uvd)
714 struct konicawc *cam = (struct konicawc *)uvd->user_data;
717 memset(&uvd->vpic, 0, sizeof(uvd->vpic));
718 memset(&uvd->vpic_old, 0x55, sizeof(uvd->vpic_old));
720 RESTRICT_TO_RANGE(brightness, 0, MAX_BRIGHTNESS);
721 RESTRICT_TO_RANGE(contrast, 0, MAX_CONTRAST);
722 RESTRICT_TO_RANGE(saturation, 0, MAX_SATURATION);
723 RESTRICT_TO_RANGE(sharpness, 0, MAX_SHARPNESS);
724 RESTRICT_TO_RANGE(whitebal, 0, MAX_WHITEBAL);
726 cam->brightness = brightness / 11;
727 cam->contrast = contrast / 11;
728 cam->saturation = saturation / 11;
729 cam->sharpness = sharpness / 11;
730 cam->white_bal = whitebal / 11;
732 uvd->vpic.colour = 108;
734 uvd->vpic.brightness = brightness;
735 uvd->vpic.contrast = contrast;
736 uvd->vpic.whiteness = whitebal;
738 uvd->vpic.palette = VIDEO_PALETTE_YUV420P;
740 memset(&uvd->vcap, 0, sizeof(uvd->vcap));
741 strcpy(uvd->vcap.name, "Konica Webcam");
742 uvd->vcap.type = VID_TYPE_CAPTURE;
743 uvd->vcap.channels = 1;
744 uvd->vcap.audios = 0;
745 uvd->vcap.minwidth = camera_sizes[SIZE_160X120].width;
746 uvd->vcap.minheight = camera_sizes[SIZE_160X120].height;
747 uvd->vcap.maxwidth = camera_sizes[SIZE_320X240].width;
748 uvd->vcap.maxheight = camera_sizes[SIZE_320X240].height;
750 memset(&uvd->vchan, 0, sizeof(uvd->vchan));
751 uvd->vchan.flags = 0 ;
752 uvd->vchan.tuners = 0;
753 uvd->vchan.channel = 0;
754 uvd->vchan.type = VIDEO_TYPE_CAMERA;
755 strcpy(uvd->vchan.name, "Camera");
758 DEBUG(1, "device init");
759 if(!konicawc_get_misc(uvd, 0x3, 0, 0x10, buf, 2))
760 DEBUG(2, "3,10 -> %2.2x %2.2x", buf[0], buf[1]);
761 if(!konicawc_get_misc(uvd, 0x3, 0, 0x10, buf, 2))
762 DEBUG(2, "3,10 -> %2.2x %2.2x", buf[0], buf[1]);
763 if(konicawc_set_misc(uvd, 0x2, 0, 0xd))
764 DEBUG(2, "2,0,d failed");
765 DEBUG(1, "setting initial values");
768 static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id *devid)
770 struct usb_device *dev = interface_to_usbdev(intf);
771 struct uvd *uvd = NULL;
773 int actInterface=-1, inactInterface=-1, maxPS=0;
774 unsigned char video_ep = 0;
776 DEBUG(1, "konicawc_probe(%p)", intf);
778 /* We don't handle multi-config cameras */
779 if (dev->descriptor.bNumConfigurations != 1)
782 info("Konica Webcam (rev. 0x%04x)", le16_to_cpu(dev->descriptor.bcdDevice));
783 RESTRICT_TO_RANGE(speed, 0, MAX_SPEED);
785 /* Validate found interface: must have one ISO endpoint */
786 nas = intf->num_altsetting;
788 err("Incorrect number of alternate settings (%d) for this camera!", nas);
791 /* Validate all alternate settings */
792 for (ix=0; ix < nas; ix++) {
793 const struct usb_host_interface *interface;
794 const struct usb_endpoint_descriptor *endpoint;
796 interface = &intf->altsetting[ix];
797 i = interface->desc.bAlternateSetting;
798 if (interface->desc.bNumEndpoints != 2) {
799 err("Interface %d. has %u. endpoints!",
800 interface->desc.bInterfaceNumber,
801 (unsigned)(interface->desc.bNumEndpoints));
804 endpoint = &interface->endpoint[1].desc;
805 DEBUG(1, "found endpoint: addr: 0x%2.2x maxps = 0x%4.4x",
806 endpoint->bEndpointAddress, le16_to_cpu(endpoint->wMaxPacketSize));
808 video_ep = endpoint->bEndpointAddress;
809 else if (video_ep != endpoint->bEndpointAddress) {
810 err("Alternate settings have different endpoint addresses!");
813 if ((endpoint->bmAttributes & 0x03) != 0x01) {
814 err("Interface %d. has non-ISO endpoint!",
815 interface->desc.bInterfaceNumber);
818 if ((endpoint->bEndpointAddress & 0x80) == 0) {
819 err("Interface %d. has ISO OUT endpoint!",
820 interface->desc.bInterfaceNumber);
823 if (le16_to_cpu(endpoint->wMaxPacketSize) == 0) {
824 if (inactInterface < 0)
827 err("More than one inactive alt. setting!");
831 if (i == spd_to_iface[speed]) {
832 /* This one is the requested one */
836 if (le16_to_cpu(endpoint->wMaxPacketSize) > maxPS)
837 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
839 if(actInterface == -1) {
840 err("Cant find required endpoint");
844 DEBUG(1, "Selecting requested active setting=%d. maxPS=%d.", actInterface, maxPS);
846 uvd = usbvideo_AllocateDevice(cams);
848 struct konicawc *cam = (struct konicawc *)(uvd->user_data);
849 /* Here uvd is a fully allocated uvd object */
850 for(i = 0; i < USBVIDEO_NUMSBUF; i++) {
851 cam->sts_urb[i] = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
852 if(cam->sts_urb[i] == NULL) {
854 usb_free_urb(cam->sts_urb[i]);
856 err("can't allocate urbs");
861 RESTRICT_TO_RANGE(size, SIZE_160X120, SIZE_320X240);
862 cam->width = camera_sizes[size].width;
863 cam->height = camera_sizes[size].height;
869 uvd->iface = intf->altsetting->desc.bInterfaceNumber;
870 uvd->ifaceAltInactive = inactInterface;
871 uvd->ifaceAltActive = actInterface;
872 uvd->video_endp = video_ep;
873 uvd->iso_packet_len = maxPS;
874 uvd->paletteBits = 1L << VIDEO_PALETTE_YUV420P;
875 uvd->defaultPalette = VIDEO_PALETTE_YUV420P;
876 uvd->canvas = VIDEOSIZE(320, 240);
877 uvd->videosize = VIDEOSIZE(cam->width, cam->height);
879 /* Initialize konicawc specific data */
880 konicawc_configure_video(uvd);
882 i = usbvideo_RegisterVideoDevice(uvd);
883 uvd->max_frame_size = (320 * 240 * 3)/2;
885 err("usbvideo_RegisterVideoDevice() failed.");
889 konicawc_register_input(cam, dev);
893 usb_set_intfdata (intf, uvd);
900 static void konicawc_free_uvd(struct uvd *uvd)
903 struct konicawc *cam = (struct konicawc *)uvd->user_data;
905 konicawc_unregister_input(cam);
907 for (i = 0; i < USBVIDEO_NUMSBUF; i++) {
908 usb_free_urb(cam->sts_urb[i]);
909 cam->sts_urb[i] = NULL;
914 static struct usb_device_id id_table[] = {
915 { USB_DEVICE(0x04c8, 0x0720) }, /* Intel YC 76 */
916 { } /* Terminating entry */
920 static int __init konicawc_init(void)
922 struct usbvideo_cb cbTbl;
923 info(DRIVER_DESC " " DRIVER_VERSION);
924 memset(&cbTbl, 0, sizeof(cbTbl));
925 cbTbl.probe = konicawc_probe;
926 cbTbl.setupOnOpen = konicawc_setup_on_open;
927 cbTbl.processData = konicawc_process_isoc;
928 cbTbl.getFPS = konicawc_calculate_fps;
929 cbTbl.setVideoMode = konicawc_set_video_mode;
930 cbTbl.startDataPump = konicawc_start_data;
931 cbTbl.stopDataPump = konicawc_stop_data;
932 cbTbl.adjustPicture = konicawc_adjust_picture;
933 cbTbl.userFree = konicawc_free_uvd;
934 return usbvideo_register(
937 sizeof(struct konicawc),
945 static void __exit konicawc_cleanup(void)
947 usbvideo_Deregister(&cams);
951 MODULE_DEVICE_TABLE(usb, id_table);
953 MODULE_LICENSE("GPL");
954 MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>");
955 MODULE_DESCRIPTION(DRIVER_DESC);
956 module_param(speed, int, 0);
957 MODULE_PARM_DESC(speed, "Initial speed: 0 (slowest) - 6 (fastest)");
958 module_param(size, int, 0);
959 MODULE_PARM_DESC(size, "Initial Size 0: 160x120 1: 160x136 2: 176x144 3: 320x240");
960 module_param(brightness, int, 0);
961 MODULE_PARM_DESC(brightness, "Initial brightness 0 - 108");
962 module_param(contrast, int, 0);
963 MODULE_PARM_DESC(contrast, "Initial contrast 0 - 108");
964 module_param(saturation, int, 0);
965 MODULE_PARM_DESC(saturation, "Initial saturation 0 - 108");
966 module_param(sharpness, int, 0);
967 MODULE_PARM_DESC(sharpness, "Initial brightness 0 - 108");
968 module_param(whitebal, int, 0);
969 MODULE_PARM_DESC(whitebal, "Initial white balance 0 - 363");
971 #ifdef CONFIG_USB_DEBUG
972 module_param(debug, int, S_IRUGO | S_IWUSR);
973 MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)");
976 module_init(konicawc_init);
977 module_exit(konicawc_cleanup);