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>
19 #include <linux/gfp.h>
23 #define MAX_BRIGHTNESS 108
24 #define MAX_CONTRAST 108
25 #define MAX_SATURATION 108
26 #define MAX_SHARPNESS 108
27 #define MAX_WHITEBAL 372
33 #define DRIVER_VERSION "v1.4"
34 #define DRIVER_DESC "Konica Webcam driver"
53 #define MAX_FRAME_SIZE SIZE_320X240
55 static struct usbvideo *cams;
57 #ifdef CONFIG_USB_DEBUG
59 #define DEBUG(n, format, arg...) \
61 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
64 #define DEBUG(n, arg...)
65 static const int debug;
69 /* Some default values for initial camera settings,
70 can be set by modprobe */
73 static int speed = 6; /* Speed (fps) 0 (slowest) to 6 (fastest) */
74 static int brightness = MAX_BRIGHTNESS/2;
75 static int contrast = MAX_CONTRAST/2;
76 static int saturation = MAX_SATURATION/2;
77 static int sharpness = MAX_SHARPNESS/2;
78 static int whitebal = 3*(MAX_WHITEBAL/4);
80 static const int spd_to_iface[] = { 1, 0, 3, 2, 4, 5, 6 };
82 /* These FPS speeds are from the windows config box. They are
83 * indexed on size (0-2) and speed (0-6). Divide by 3 to get the
87 static const int spd_to_fps[][7] = { { 24, 40, 48, 60, 72, 80, 100 },
88 { 24, 40, 48, 60, 72, 80, 100 },
89 { 18, 30, 36, 45, 54, 60, 75 },
90 { 6, 10, 12, 15, 18, 21, 25 } };
98 static const struct cam_size camera_sizes[] = { { 160, 120, 0x7 },
104 u8 brightness; /* camera uses 0 - 9, x11 for real value */
105 u8 contrast; /* as above */
106 u8 saturation; /* as above */
107 u8 sharpness; /* as above */
108 u8 white_bal; /* 0 - 33, x11 for real value */
109 u8 speed; /* Stored as 0 - 6, used as index in spd_to_* (above) */
110 u8 size; /* Frame Size */
113 struct urb *sts_urb[USBVIDEO_NUMSBUF];
114 u8 sts_buf[USBVIDEO_NUMSBUF][FRAMES_PER_DESC];
115 struct urb *last_data_urb;
117 int cur_frame_size; /* number of bytes in current frame size */
118 int maxline; /* number of lines per frame */
119 int yplanesz; /* Number of bytes in the Y plane */
120 unsigned int buttonsts:1;
122 struct input_dev *input;
123 char input_physname[64];
128 #define konicawc_set_misc(uvd, req, value, index) konicawc_ctrl_msg(uvd, USB_DIR_OUT, req, value, index, NULL, 0)
129 #define konicawc_get_misc(uvd, req, value, index, buf, sz) konicawc_ctrl_msg(uvd, USB_DIR_IN, req, value, index, buf, sz)
130 #define konicawc_set_value(uvd, value, index) konicawc_ctrl_msg(uvd, USB_DIR_OUT, 2, value, index, NULL, 0)
133 static int konicawc_ctrl_msg(struct uvd *uvd, u8 dir, u8 request, u16 value, u16 index, void *buf, int len)
135 int retval = usb_control_msg(uvd->dev,
136 dir ? usb_rcvctrlpipe(uvd->dev, 0) : usb_sndctrlpipe(uvd->dev, 0),
137 request, 0x40 | dir, value, index, buf, len, 1000);
138 return retval < 0 ? retval : 0;
142 static inline void konicawc_camera_on(struct uvd *uvd)
144 DEBUG(0, "camera on");
145 konicawc_set_misc(uvd, 0x2, 1, 0x0b);
149 static inline void konicawc_camera_off(struct uvd *uvd)
151 DEBUG(0, "camera off");
152 konicawc_set_misc(uvd, 0x2, 0, 0x0b);
156 static void konicawc_set_camera_size(struct uvd *uvd)
158 struct konicawc *cam = (struct konicawc *)uvd->user_data;
160 konicawc_set_misc(uvd, 0x2, camera_sizes[cam->size].cmd, 0x08);
161 cam->width = camera_sizes[cam->size].width;
162 cam->height = camera_sizes[cam->size].height;
163 cam->yplanesz = cam->height * cam->width;
164 cam->cur_frame_size = (cam->yplanesz * 3) / 2;
165 cam->maxline = cam->yplanesz / 256;
166 uvd->videosize = VIDEOSIZE(cam->width, cam->height);
170 static int konicawc_setup_on_open(struct uvd *uvd)
172 struct konicawc *cam = (struct konicawc *)uvd->user_data;
174 DEBUG(1, "setting brightness to %d (%d)", cam->brightness,
175 cam->brightness * 11);
176 konicawc_set_value(uvd, cam->brightness, SetBrightness);
177 DEBUG(1, "setting white balance to %d (%d)", cam->white_bal,
178 cam->white_bal * 11);
179 konicawc_set_value(uvd, cam->white_bal, SetWhitebal);
180 DEBUG(1, "setting contrast to %d (%d)", cam->contrast,
182 konicawc_set_value(uvd, cam->contrast, SetContrast);
183 DEBUG(1, "setting saturation to %d (%d)", cam->saturation,
184 cam->saturation * 11);
185 konicawc_set_value(uvd, cam->saturation, SetSaturation);
186 DEBUG(1, "setting sharpness to %d (%d)", cam->sharpness,
187 cam->sharpness * 11);
188 konicawc_set_value(uvd, cam->sharpness, SetSharpness);
189 konicawc_set_camera_size(uvd);
196 static void konicawc_adjust_picture(struct uvd *uvd)
198 struct konicawc *cam = (struct konicawc *)uvd->user_data;
200 konicawc_camera_off(uvd);
201 DEBUG(1, "new brightness: %d", uvd->vpic.brightness);
202 uvd->vpic.brightness = (uvd->vpic.brightness > MAX_BRIGHTNESS) ? MAX_BRIGHTNESS : uvd->vpic.brightness;
203 if(cam->brightness != uvd->vpic.brightness / 11) {
204 cam->brightness = uvd->vpic.brightness / 11;
205 DEBUG(1, "setting brightness to %d (%d)", cam->brightness,
206 cam->brightness * 11);
207 konicawc_set_value(uvd, cam->brightness, SetBrightness);
210 DEBUG(1, "new contrast: %d", uvd->vpic.contrast);
211 uvd->vpic.contrast = (uvd->vpic.contrast > MAX_CONTRAST) ? MAX_CONTRAST : uvd->vpic.contrast;
212 if(cam->contrast != uvd->vpic.contrast / 11) {
213 cam->contrast = uvd->vpic.contrast / 11;
214 DEBUG(1, "setting contrast to %d (%d)", cam->contrast,
216 konicawc_set_value(uvd, cam->contrast, SetContrast);
218 konicawc_camera_on(uvd);
223 static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev)
225 struct input_dev *input_dev;
228 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
229 strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
231 cam->input = input_dev = input_allocate_device();
234 "Not enough memory for camera's input device\n");
238 input_dev->name = "Konicawc snapshot button";
239 input_dev->phys = cam->input_physname;
240 usb_to_input_id(dev, &input_dev->id);
241 input_dev->dev.parent = &dev->dev;
243 input_dev->evbit[0] = BIT_MASK(EV_KEY);
244 input_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA);
246 error = input_register_device(cam->input);
249 "Failed to register camera's input device, err: %d\n",
251 input_free_device(cam->input);
256 static void konicawc_unregister_input(struct konicawc *cam)
259 input_unregister_device(cam->input);
264 static void konicawc_report_buttonstat(struct konicawc *cam)
267 input_report_key(cam->input, KEY_CAMERA, cam->buttonsts);
268 input_sync(cam->input);
274 static inline void konicawc_register_input(struct konicawc *cam, struct usb_device *dev) { }
275 static inline void konicawc_unregister_input(struct konicawc *cam) { }
276 static inline void konicawc_report_buttonstat(struct konicawc *cam) { }
278 #endif /* CONFIG_INPUT */
280 static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct urb *stsurb)
284 unsigned char *status = stsurb->transfer_buffer;
285 int keep = 0, discard = 0, bad = 0;
286 struct konicawc *cam = (struct konicawc *)uvd->user_data;
288 for (i = 0; i < dataurb->number_of_packets; i++) {
289 int button = cam->buttonsts;
291 int n = dataurb->iso_frame_desc[i].actual_length;
292 int st = dataurb->iso_frame_desc[i].status;
293 cdata = dataurb->transfer_buffer +
294 dataurb->iso_frame_desc[i].offset;
296 /* Detect and ignore errored packets */
298 DEBUG(1, "Data error: packet=%d. len=%d. status=%d.",
300 uvd->stats.iso_err_count++;
304 /* Detect and ignore empty packets */
306 uvd->stats.iso_skip_count++;
310 /* See what the status data said about the packet */
311 sts = *(status+stsurb->iso_frame_desc[i].offset);
313 /* sts: 0x80-0xff: frame start with frame number (ie 0-7f)
315 * bit 0 0: keep packet
316 * 1: drop packet (padding data)
318 * bit 4 0 button not clicked
320 * button is used to `take a picture' (in software)
324 button = !!(sts & 0x40);
328 /* work out the button status, but don't do
329 anything with it for now */
331 if(button != cam->buttonsts) {
332 DEBUG(2, "button: %sclicked", button ? "" : "un");
333 cam->buttonsts = button;
334 konicawc_report_buttonstat(cam);
337 if(sts == 0x01) { /* drop frame */
342 if((sts > 0x01) && (sts < 0x80)) {
343 dev_info(&uvd->dev->dev, "unknown status %2.2x\n",
348 if(!sts && cam->lastframe == -2) {
349 DEBUG(2, "dropping frame looking for image start");
354 if(sts & 0x80) { /* frame start */
355 unsigned char marker[] = { 0, 0xff, 0, 0x00 };
357 if(cam->lastframe == -2) {
358 DEBUG(2, "found initial image");
362 marker[3] = sts & 0x7F;
363 RingQueue_Enqueue(&uvd->dp, marker, 4);
367 totlen += n; /* Little local accounting */
368 RingQueue_Enqueue(&uvd->dp, cdata, n);
370 DEBUG(8, "finished: keep = %d discard = %d bad = %d added %d bytes",
371 keep, discard, bad, totlen);
376 static void resubmit_urb(struct uvd *uvd, struct urb *urb)
379 for (i = 0; i < FRAMES_PER_DESC; i++) {
380 urb->iso_frame_desc[i].status = 0;
384 ret = usb_submit_urb(urb, GFP_ATOMIC);
385 DEBUG(3, "submitting urb of length %d", urb->transfer_buffer_length);
387 err("usb_submit_urb error (%d)", ret);
392 static void konicawc_isoc_irq(struct urb *urb)
394 struct uvd *uvd = urb->context;
395 struct konicawc *cam = (struct konicawc *)uvd->user_data;
397 /* We don't want to do anything if we are about to be removed! */
398 if (!CAMERA_IS_OPERATIONAL(uvd))
401 if (!uvd->streaming) {
402 DEBUG(1, "Not streaming, but interrupt!");
406 DEBUG(3, "got frame %d len = %d buflen =%d", urb->start_frame, urb->actual_length, urb->transfer_buffer_length);
408 uvd->stats.urb_count++;
410 if (urb->transfer_buffer_length > 32) {
411 cam->last_data_urb = urb;
414 /* Copy the data received into ring queue */
415 if(cam->last_data_urb) {
417 if(urb->start_frame != cam->last_data_urb->start_frame)
418 err("Lost sync on frames");
419 else if (!urb->status && !cam->last_data_urb->status)
420 len = konicawc_compress_iso(uvd, cam->last_data_urb, urb);
422 resubmit_urb(uvd, cam->last_data_urb);
423 resubmit_urb(uvd, urb);
424 cam->last_data_urb = NULL;
425 uvd->stats.urb_length = len;
426 uvd->stats.data_count += len;
428 RingQueue_WakeUpInterruptible(&uvd->dp);
435 static int konicawc_start_data(struct uvd *uvd)
437 struct usb_device *dev = uvd->dev;
439 struct konicawc *cam = (struct konicawc *)uvd->user_data;
441 struct usb_interface *intf;
442 struct usb_host_interface *interface = NULL;
444 intf = usb_ifnum_to_if(dev, uvd->iface);
446 interface = usb_altnum_to_altsetting(intf,
447 spd_to_iface[cam->speed]);
450 pktsz = le16_to_cpu(interface->endpoint[1].desc.wMaxPacketSize);
451 DEBUG(1, "pktsz = %d", pktsz);
452 if (!CAMERA_IS_OPERATIONAL(uvd)) {
453 err("Camera is not operational");
457 konicawc_camera_on(uvd);
458 /* Alternate interface 1 is is the biggest frame size */
459 i = usb_set_interface(dev, uvd->iface, uvd->ifaceAltActive);
461 err("usb_set_interface error");
466 /* We double buffer the Iso lists */
467 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
469 struct urb *urb = uvd->sbuf[i].urb;
472 urb->pipe = usb_rcvisocpipe(dev, uvd->video_endp);
474 urb->transfer_flags = URB_ISO_ASAP;
475 urb->transfer_buffer = uvd->sbuf[i].data;
476 urb->complete = konicawc_isoc_irq;
477 urb->number_of_packets = FRAMES_PER_DESC;
478 urb->transfer_buffer_length = pktsz * FRAMES_PER_DESC;
479 for (j=k=0; j < FRAMES_PER_DESC; j++, k += pktsz) {
480 urb->iso_frame_desc[j].offset = k;
481 urb->iso_frame_desc[j].length = pktsz;
484 urb = cam->sts_urb[i];
487 urb->pipe = usb_rcvisocpipe(dev, uvd->video_endp-1);
489 urb->transfer_flags = URB_ISO_ASAP;
490 urb->transfer_buffer = cam->sts_buf[i];
491 urb->complete = konicawc_isoc_irq;
492 urb->number_of_packets = FRAMES_PER_DESC;
493 urb->transfer_buffer_length = FRAMES_PER_DESC;
494 for (j=0; j < FRAMES_PER_DESC; j++) {
495 urb->iso_frame_desc[j].offset = j;
496 urb->iso_frame_desc[j].length = 1;
500 cam->last_data_urb = NULL;
502 /* Submit all URBs */
503 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
504 errFlag = usb_submit_urb(cam->sts_urb[i], GFP_KERNEL);
506 err("usb_submit_isoc(%d) ret %d", i, errFlag);
508 errFlag = usb_submit_urb(uvd->sbuf[i].urb, GFP_KERNEL);
510 err ("usb_submit_isoc(%d) ret %d", i, errFlag);
514 DEBUG(1, "streaming=1 video_endp=$%02x", uvd->video_endp);
519 static void konicawc_stop_data(struct uvd *uvd)
522 struct konicawc *cam;
524 if ((uvd == NULL) || (!uvd->streaming) || (uvd->dev == NULL))
527 konicawc_camera_off(uvd);
529 cam = (struct konicawc *)uvd->user_data;
530 cam->last_data_urb = NULL;
532 /* Unschedule all of the iso td's */
533 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
534 usb_kill_urb(uvd->sbuf[i].urb);
535 usb_kill_urb(cam->sts_urb[i]);
538 if (!uvd->remove_pending) {
539 /* Set packet size to 0 */
540 j = usb_set_interface(uvd->dev, uvd->iface, uvd->ifaceAltInactive);
542 err("usb_set_interface() error %d.", j);
549 static void konicawc_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame)
551 struct konicawc *cam = (struct konicawc *)uvd->user_data;
552 int maxline = cam->maxline;
553 int yplanesz = cam->yplanesz;
555 assert(frame != NULL);
557 DEBUG(5, "maxline = %d yplanesz = %d", maxline, yplanesz);
558 DEBUG(3, "Frame state = %d", frame->scanstate);
560 if(frame->scanstate == ScanState_Scanning) {
564 DEBUG(3, "Searching for marker, queue len = %d", RingQueue_GetLength(&uvd->dp));
565 while(RingQueue_GetLength(&uvd->dp) >= 4) {
566 if ((RING_QUEUE_PEEK(&uvd->dp, 0) == 0x00) &&
567 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xff) &&
568 (RING_QUEUE_PEEK(&uvd->dp, 2) == 0x00) &&
569 (RING_QUEUE_PEEK(&uvd->dp, 3) < 0x80)) {
570 curframe = RING_QUEUE_PEEK(&uvd->dp, 3);
571 if(cam->lastframe >= 0) {
572 fdrops = (0x80 + curframe - cam->lastframe) & 0x7F;
575 dev_info(&uvd->dev->dev,
583 cam->lastframe = curframe;
585 frame->scanstate = ScanState_Lines;
586 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 4);
589 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 1);
593 DEBUG(2, "dropped %d bytes looking for new frame", drop);
596 if(frame->scanstate == ScanState_Scanning)
599 /* Try to move data from queue into frame buffer
600 * We get data in blocks of 384 bytes made up of:
602 * This needs to be written out as a Y plane, a U plane and a V plane.
605 while ( frame->curline < maxline && (RingQueue_GetLength(&uvd->dp) >= 384)) {
607 RingQueue_Dequeue(&uvd->dp, frame->data + (frame->curline * 256), 256);
609 RingQueue_Dequeue(&uvd->dp, frame->data + yplanesz + (frame->curline * 64), 64);
611 RingQueue_Dequeue(&uvd->dp, frame->data + (5 * yplanesz)/4 + (frame->curline * 64), 64);
612 frame->seqRead_Length += 384;
615 /* See if we filled the frame */
616 if (frame->curline == maxline) {
617 DEBUG(5, "got whole frame");
619 frame->frameState = FrameState_Done_Hold;
622 uvd->stats.frame_num++;
627 static int konicawc_find_fps(int size, int fps)
632 DEBUG(1, "konica_find_fps: size = %d fps = %d", size, fps);
633 if(fps <= spd_to_fps[size][0])
636 if(fps >= spd_to_fps[size][MAX_SPEED])
639 for(i = 0; i < MAX_SPEED; i++) {
640 if((fps >= spd_to_fps[size][i]) && (fps <= spd_to_fps[size][i+1])) {
641 DEBUG(2, "fps %d between %d and %d", fps, i, i+1);
642 if( (fps - spd_to_fps[size][i]) < (spd_to_fps[size][i+1] - fps))
652 static int konicawc_set_video_mode(struct uvd *uvd, struct video_window *vw)
654 struct konicawc *cam = (struct konicawc *)uvd->user_data;
655 int newspeed = cam->speed;
662 DEBUG(2, "trying to find size %d,%d", x, y);
663 for(newsize = 0; newsize <= MAX_FRAME_SIZE; newsize++) {
664 if((camera_sizes[newsize].width == x) && (camera_sizes[newsize].height == y))
671 if(newsize > MAX_FRAME_SIZE) {
672 DEBUG(1, "couldn't find size %d,%d", x, y);
677 DEBUG(1, "trying to set fps to %d", fps);
678 newspeed = konicawc_find_fps(newsize, fps);
679 DEBUG(1, "find_fps returned %d (%d)", newspeed, spd_to_fps[newsize][newspeed]);
682 if(newspeed > MAX_SPEED)
685 DEBUG(1, "setting size to %d speed to %d", newsize, newspeed);
686 if((newsize == cam->size) && (newspeed == cam->speed)) {
687 DEBUG(1, "Nothing to do");
690 DEBUG(0, "setting to %dx%d @ %d fps", camera_sizes[newsize].width,
691 camera_sizes[newsize].height, spd_to_fps[newsize][newspeed]/3);
693 konicawc_stop_data(uvd);
694 uvd->ifaceAltActive = spd_to_iface[newspeed];
695 DEBUG(1, "new interface = %d", uvd->ifaceAltActive);
696 cam->speed = newspeed;
698 if(cam->size != newsize) {
700 konicawc_set_camera_size(uvd);
703 /* Flush the input queue and clear any current frame in progress */
705 RingQueue_Flush(&uvd->dp);
707 if(uvd->curframe != -1) {
708 uvd->frame[uvd->curframe].curline = 0;
709 uvd->frame[uvd->curframe].seqRead_Length = 0;
710 uvd->frame[uvd->curframe].seqRead_Index = 0;
713 konicawc_start_data(uvd);
718 static int konicawc_calculate_fps(struct uvd *uvd)
720 struct konicawc *cam = uvd->user_data;
721 return spd_to_fps[cam->size][cam->speed]/3;
725 static void konicawc_configure_video(struct uvd *uvd)
727 struct konicawc *cam = (struct konicawc *)uvd->user_data;
730 memset(&uvd->vpic, 0, sizeof(uvd->vpic));
731 memset(&uvd->vpic_old, 0x55, sizeof(uvd->vpic_old));
733 RESTRICT_TO_RANGE(brightness, 0, MAX_BRIGHTNESS);
734 RESTRICT_TO_RANGE(contrast, 0, MAX_CONTRAST);
735 RESTRICT_TO_RANGE(saturation, 0, MAX_SATURATION);
736 RESTRICT_TO_RANGE(sharpness, 0, MAX_SHARPNESS);
737 RESTRICT_TO_RANGE(whitebal, 0, MAX_WHITEBAL);
739 cam->brightness = brightness / 11;
740 cam->contrast = contrast / 11;
741 cam->saturation = saturation / 11;
742 cam->sharpness = sharpness / 11;
743 cam->white_bal = whitebal / 11;
745 uvd->vpic.colour = 108;
747 uvd->vpic.brightness = brightness;
748 uvd->vpic.contrast = contrast;
749 uvd->vpic.whiteness = whitebal;
751 uvd->vpic.palette = VIDEO_PALETTE_YUV420P;
753 memset(&uvd->vcap, 0, sizeof(uvd->vcap));
754 strcpy(uvd->vcap.name, "Konica Webcam");
755 uvd->vcap.type = VID_TYPE_CAPTURE;
756 uvd->vcap.channels = 1;
757 uvd->vcap.audios = 0;
758 uvd->vcap.minwidth = camera_sizes[SIZE_160X120].width;
759 uvd->vcap.minheight = camera_sizes[SIZE_160X120].height;
760 uvd->vcap.maxwidth = camera_sizes[SIZE_320X240].width;
761 uvd->vcap.maxheight = camera_sizes[SIZE_320X240].height;
763 memset(&uvd->vchan, 0, sizeof(uvd->vchan));
764 uvd->vchan.flags = 0 ;
765 uvd->vchan.tuners = 0;
766 uvd->vchan.channel = 0;
767 uvd->vchan.type = VIDEO_TYPE_CAMERA;
768 strcpy(uvd->vchan.name, "Camera");
771 DEBUG(1, "device init");
772 if(!konicawc_get_misc(uvd, 0x3, 0, 0x10, buf, 2))
773 DEBUG(2, "3,10 -> %2.2x %2.2x", buf[0], buf[1]);
774 if(!konicawc_get_misc(uvd, 0x3, 0, 0x10, buf, 2))
775 DEBUG(2, "3,10 -> %2.2x %2.2x", buf[0], buf[1]);
776 if(konicawc_set_misc(uvd, 0x2, 0, 0xd))
777 DEBUG(2, "2,0,d failed");
778 DEBUG(1, "setting initial values");
781 static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id *devid)
783 struct usb_device *dev = interface_to_usbdev(intf);
784 struct uvd *uvd = NULL;
786 int actInterface=-1, inactInterface=-1, maxPS=0;
787 unsigned char video_ep = 0;
789 DEBUG(1, "konicawc_probe(%p)", intf);
791 /* We don't handle multi-config cameras */
792 if (dev->descriptor.bNumConfigurations != 1)
795 dev_info(&intf->dev, "Konica Webcam (rev. 0x%04x)\n",
796 le16_to_cpu(dev->descriptor.bcdDevice));
797 RESTRICT_TO_RANGE(speed, 0, MAX_SPEED);
799 /* Validate found interface: must have one ISO endpoint */
800 nas = intf->num_altsetting;
802 err("Incorrect number of alternate settings (%d) for this camera!", nas);
805 /* Validate all alternate settings */
806 for (ix=0; ix < nas; ix++) {
807 const struct usb_host_interface *interface;
808 const struct usb_endpoint_descriptor *endpoint;
810 interface = &intf->altsetting[ix];
811 i = interface->desc.bAlternateSetting;
812 if (interface->desc.bNumEndpoints != 2) {
813 err("Interface %d. has %u. endpoints!",
814 interface->desc.bInterfaceNumber,
815 (unsigned)(interface->desc.bNumEndpoints));
818 endpoint = &interface->endpoint[1].desc;
819 DEBUG(1, "found endpoint: addr: 0x%2.2x maxps = 0x%4.4x",
820 endpoint->bEndpointAddress, le16_to_cpu(endpoint->wMaxPacketSize));
822 video_ep = endpoint->bEndpointAddress;
823 else if (video_ep != endpoint->bEndpointAddress) {
824 err("Alternate settings have different endpoint addresses!");
827 if (!usb_endpoint_xfer_isoc(endpoint)) {
828 err("Interface %d. has non-ISO endpoint!",
829 interface->desc.bInterfaceNumber);
832 if (usb_endpoint_dir_out(endpoint)) {
833 err("Interface %d. has ISO OUT endpoint!",
834 interface->desc.bInterfaceNumber);
837 if (le16_to_cpu(endpoint->wMaxPacketSize) == 0) {
838 if (inactInterface < 0)
841 err("More than one inactive alt. setting!");
845 if (i == spd_to_iface[speed]) {
846 /* This one is the requested one */
850 if (le16_to_cpu(endpoint->wMaxPacketSize) > maxPS)
851 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
853 if(actInterface == -1) {
854 err("Cant find required endpoint");
858 DEBUG(1, "Selecting requested active setting=%d. maxPS=%d.", actInterface, maxPS);
860 uvd = usbvideo_AllocateDevice(cams);
862 struct konicawc *cam = (struct konicawc *)(uvd->user_data);
863 /* Here uvd is a fully allocated uvd object */
864 for(i = 0; i < USBVIDEO_NUMSBUF; i++) {
865 cam->sts_urb[i] = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
866 if(cam->sts_urb[i] == NULL) {
868 usb_free_urb(cam->sts_urb[i]);
870 err("can't allocate urbs");
875 RESTRICT_TO_RANGE(size, SIZE_160X120, SIZE_320X240);
876 cam->width = camera_sizes[size].width;
877 cam->height = camera_sizes[size].height;
883 uvd->iface = intf->altsetting->desc.bInterfaceNumber;
884 uvd->ifaceAltInactive = inactInterface;
885 uvd->ifaceAltActive = actInterface;
886 uvd->video_endp = video_ep;
887 uvd->iso_packet_len = maxPS;
888 uvd->paletteBits = 1L << VIDEO_PALETTE_YUV420P;
889 uvd->defaultPalette = VIDEO_PALETTE_YUV420P;
890 uvd->canvas = VIDEOSIZE(320, 240);
891 uvd->videosize = VIDEOSIZE(cam->width, cam->height);
893 /* Initialize konicawc specific data */
894 konicawc_configure_video(uvd);
896 i = usbvideo_RegisterVideoDevice(uvd);
897 uvd->max_frame_size = (320 * 240 * 3)/2;
899 err("usbvideo_RegisterVideoDevice() failed.");
903 konicawc_register_input(cam, dev);
907 usb_set_intfdata (intf, uvd);
914 static void konicawc_free_uvd(struct uvd *uvd)
917 struct konicawc *cam = (struct konicawc *)uvd->user_data;
919 konicawc_unregister_input(cam);
921 for (i = 0; i < USBVIDEO_NUMSBUF; i++) {
922 usb_free_urb(cam->sts_urb[i]);
923 cam->sts_urb[i] = NULL;
928 static struct usb_device_id id_table[] = {
929 { USB_DEVICE(0x04c8, 0x0720) }, /* Intel YC 76 */
930 { } /* Terminating entry */
934 static int __init konicawc_init(void)
936 struct usbvideo_cb cbTbl;
937 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
939 memset(&cbTbl, 0, sizeof(cbTbl));
940 cbTbl.probe = konicawc_probe;
941 cbTbl.setupOnOpen = konicawc_setup_on_open;
942 cbTbl.processData = konicawc_process_isoc;
943 cbTbl.getFPS = konicawc_calculate_fps;
944 cbTbl.setVideoMode = konicawc_set_video_mode;
945 cbTbl.startDataPump = konicawc_start_data;
946 cbTbl.stopDataPump = konicawc_stop_data;
947 cbTbl.adjustPicture = konicawc_adjust_picture;
948 cbTbl.userFree = konicawc_free_uvd;
949 return usbvideo_register(
952 sizeof(struct konicawc),
960 static void __exit konicawc_cleanup(void)
962 usbvideo_Deregister(&cams);
966 MODULE_DEVICE_TABLE(usb, id_table);
968 MODULE_LICENSE("GPL");
969 MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>");
970 MODULE_DESCRIPTION(DRIVER_DESC);
971 module_param(speed, int, 0);
972 MODULE_PARM_DESC(speed, "Initial speed: 0 (slowest) - 6 (fastest)");
973 module_param(size, int, 0);
974 MODULE_PARM_DESC(size, "Initial Size 0: 160x120 1: 160x136 2: 176x144 3: 320x240");
975 module_param(brightness, int, 0);
976 MODULE_PARM_DESC(brightness, "Initial brightness 0 - 108");
977 module_param(contrast, int, 0);
978 MODULE_PARM_DESC(contrast, "Initial contrast 0 - 108");
979 module_param(saturation, int, 0);
980 MODULE_PARM_DESC(saturation, "Initial saturation 0 - 108");
981 module_param(sharpness, int, 0);
982 MODULE_PARM_DESC(sharpness, "Initial brightness 0 - 108");
983 module_param(whitebal, int, 0);
984 MODULE_PARM_DESC(whitebal, "Initial white balance 0 - 363");
986 #ifdef CONFIG_USB_DEBUG
987 module_param(debug, int, S_IRUGO | S_IWUSR);
988 MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)");
991 module_init(konicawc_init);
992 module_exit(konicawc_cleanup);