60 #include <linux/errno.h>
63 #include <linux/module.h>
64 #include <linux/poll.h>
65 #include <linux/slab.h>
66 #ifdef CONFIG_USB_PWC_INPUT_EVDEV
71 #include <linux/kernel.h>
83 { USB_DEVICE(0x0471, 0x0302) },
84 { USB_DEVICE(0x0471, 0x0303) },
85 { USB_DEVICE(0x0471, 0x0304) },
86 { USB_DEVICE(0x0471, 0x0307) },
87 { USB_DEVICE(0x0471, 0x0308) },
88 { USB_DEVICE(0x0471, 0x030C) },
89 { USB_DEVICE(0x0471, 0x0310) },
90 { USB_DEVICE(0x0471, 0x0311) },
91 { USB_DEVICE(0x0471, 0x0312) },
92 { USB_DEVICE(0x0471, 0x0313) },
93 { USB_DEVICE(0x0471, 0x0329) },
94 { USB_DEVICE(0x069A, 0x0001) },
95 { USB_DEVICE(0x046D, 0x08B0) },
96 { USB_DEVICE(0x046D, 0x08B1) },
97 { USB_DEVICE(0x046D, 0x08B2) },
98 { USB_DEVICE(0x046D, 0x08B3) },
99 { USB_DEVICE(0x046D, 0x08B4) },
100 { USB_DEVICE(0x046D, 0x08B5) },
101 { USB_DEVICE(0x046D, 0x08B6) },
102 { USB_DEVICE(0x046D, 0x08B7) },
103 { USB_DEVICE(0x046D, 0x08B8) },
104 { USB_DEVICE(0x055D, 0x9000) },
105 { USB_DEVICE(0x055D, 0x9001) },
106 { USB_DEVICE(0x055D, 0x9002) },
107 { USB_DEVICE(0x041E, 0x400C) },
108 { USB_DEVICE(0x041E, 0x4011) },
109 { USB_DEVICE(0x04CC, 0x8116) },
110 { USB_DEVICE(0x06BE, 0x8116) },
111 { USB_DEVICE(0x0d81, 0x1910) },
112 { USB_DEVICE(0x0d81, 0x1900) },
119 static void pwc_isoc_cleanup(
struct pwc_device *pdev);
121 static struct usb_driver pwc_driver = {
122 .name =
"Philips webcam",
123 .id_table = pwc_device_table,
124 .probe = usb_pwc_probe,
125 .disconnect = usb_pwc_disconnect,
128 #define MAX_DEV_HINTS 20
129 #define MAX_ISOC_ERRORS 20
131 #ifdef CONFIG_USB_PWC_DEBUG
134 static int power_save = -1;
135 static int leds[2] = { 100, 0 };
149 .name =
"Philips Webcam",
160 unsigned long flags = 0;
174 static void pwc_snapshot_button(
struct pwc_device *pdev,
int down)
179 PWC_TRACE(
"Snapshot button released.\n");
182 #ifdef CONFIG_USB_PWC_INPUT_EVDEV
183 if (pdev->button_dev) {
184 input_report_key(pdev->button_dev,
KEY_CAMERA, down);
185 input_sync(pdev->button_dev);
190 static void pwc_frame_complete(
struct pwc_device *pdev)
198 if (pdev->
type == 730) {
199 unsigned char *
ptr = (
unsigned char *)fbuf->
data;
201 if (ptr[1] == 1 && ptr[0] & 0x10) {
202 PWC_TRACE(
"Hyundai CMOS sensor bug. Dropping frame.\n");
205 if ((ptr[0] ^ pdev->
vmirror) & 0x01) {
206 pwc_snapshot_button(pdev, ptr[0] & 0x01);
208 if ((ptr[0] ^ pdev->
vmirror) & 0x02) {
226 }
else if (pdev->
type == 740 || pdev->
type == 720) {
227 unsigned char *ptr = (
unsigned char *)fbuf->
data;
229 pwc_snapshot_button(pdev, ptr[0] & 0x01);
241 " discarded.\n", fbuf->
filled);
256 static void pwc_isoc_handler(
struct urb *
urb)
260 unsigned char *iso_buf =
NULL;
264 PWC_DEBUG_OPEN(
"URB (%p) unlinked %ssynchronuously.\n", urb, urb->status == -
ENOENT ?
"" :
"a");
271 if (urb->status != 0) {
275 switch(urb->status) {
276 case -
ENOSR: errmsg =
"Buffer error (overrun)";
break;
277 case -
EPIPE: errmsg =
"Stalled (device not responding)";
break;
278 case -
EOVERFLOW: errmsg =
"Babble (bad cable?)";
break;
279 case -
EPROTO: errmsg =
"Bit-stuff error (bad cable?)";
break;
280 case -
EILSEQ: errmsg =
"CRC/Timeout (could be anything)";
break;
281 case -
ETIME: errmsg =
"Device does not respond";
break;
283 PWC_ERROR(
"pwc_isoc_handler() called with status %d [%s].\n",
284 urb->status, errmsg);
288 PWC_ERROR(
"Too many ISOC errors, bailing out.\n");
307 for (i = 0; i < urb->number_of_packets; i++) {
308 fst = urb->iso_frame_desc[
i].status;
309 flen = urb->iso_frame_desc[
i].actual_length;
310 iso_buf = urb->transfer_buffer + urb->iso_frame_desc[
i].offset;
312 PWC_ERROR(
"Iso frame %d has error %d\n", i, fst);
315 if (flen > 0 && pdev->
vsync) {
318 if (pdev->
vsync == 1) {
334 if (flen < pdev->vlast_packet_size) {
336 if (pdev->
vsync == 2)
337 pwc_frame_complete(pdev);
351 PWC_ERROR(
"Error (%d) re-submitting urb in pwc_isoc_handler.\n", i);
355 static int pwc_isoc_init(
struct pwc_device *pdev)
357 struct usb_device *
udev;
361 struct usb_host_interface *idesc =
NULL;
375 pdev->
vframes, &compression, 1);
386 for (i = 0; i < idesc->desc.bNumEndpoints; i++) {
387 if ((idesc->endpoint[i].desc.bEndpointAddress & 0xF) == pdev->
vendpoint) {
394 PWC_ERROR(
"Failed to find packet size for video endpoint in current alternate setting.\n");
401 if (ret == -
ENOSPC && compression < 3) {
412 PWC_ERROR(
"Failed to allocate urb %d\n", i);
413 pwc_isoc_cleanup(pdev);
421 urb->pipe = usb_rcvisocpipe(udev, pdev->
vendpoint);
422 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
427 if (urb->transfer_buffer ==
NULL) {
428 PWC_ERROR(
"Failed to allocate urb buffer %d\n", i);
429 pwc_isoc_cleanup(pdev);
433 urb->complete = pwc_isoc_handler;
435 urb->start_frame = 0;
446 if (ret == -
ENOSPC && compression < 3) {
448 pwc_isoc_cleanup(pdev);
452 PWC_ERROR(
"isoc_init() submit_urb %d failed with error %d\n", i, ret);
453 pwc_isoc_cleanup(pdev);
464 static void pwc_iso_stop(
struct pwc_device *pdev)
477 static void pwc_iso_free(
struct pwc_device *pdev)
485 if (pdev->
urbs[i]->transfer_buffer) {
487 pdev->
urbs[i]->transfer_buffer_length,
488 pdev->
urbs[i]->transfer_buffer,
489 pdev->
urbs[i]->transfer_dma);
498 static void pwc_isoc_cleanup(
struct pwc_device *pdev)
510 static void pwc_cleanup_queued_bufs(
struct pwc_device *pdev)
512 unsigned long flags = 0;
526 #ifdef CONFIG_USB_PWC_DEBUG
527 static const char *pwc_sensor_type_to_string(
unsigned int sensor_type)
529 switch(sensor_type) {
531 return "Hyundai CMOS sensor";
533 return "Sony CCD sensor + TDA8787";
535 return "Sony CCD sensor + Exas 98L59";
537 return "Sony CCD sensor + ADI 9804";
539 return "Sharp CCD sensor + TDA8787";
541 return "Sharp CCD sensor + Exas 98L59";
543 return "Sharp CCD sensor + ADI 9804";
545 return "UPA 1021 sensor";
549 return "PAL MR sensor";
551 return "unknown type of sensor";
573 unsigned int *nbuffers,
unsigned int *nplanes,
574 unsigned int sizes[],
void *alloc_ctxs[])
576 struct pwc_device *pdev = vb2_get_drv_priv(vq);
605 static int buffer_prepare(
struct vb2_buffer *vb)
616 static int buffer_finish(
struct vb2_buffer *vb)
629 static void buffer_cleanup(
struct vb2_buffer *vb)
636 static void buffer_queue(
struct vb2_buffer *vb)
640 unsigned long flags = 0;
653 static int start_streaming(
struct vb2_queue *vq,
unsigned int count)
655 struct pwc_device *pdev = vb2_get_drv_priv(vq);
667 r = pwc_isoc_init(pdev);
673 pwc_cleanup_queued_bufs(pdev);
680 static int stop_streaming(
struct vb2_queue *vq)
682 struct pwc_device *pdev = vb2_get_drv_priv(vq);
689 pwc_isoc_cleanup(pdev);
692 pwc_cleanup_queued_bufs(pdev);
698 static struct vb2_ops pwc_vb_queue_ops = {
701 .buf_prepare = buffer_prepare,
702 .buf_finish = buffer_finish,
703 .buf_cleanup = buffer_cleanup,
704 .buf_queue = buffer_queue,
720 struct usb_device *udev = interface_to_usbdev(intf);
729 vendor_id =
le16_to_cpu(udev->descriptor.idVendor);
730 product_id =
le16_to_cpu(udev->descriptor.idProduct);
734 vendor_id, product_id,
735 intf->altsetting->desc.bInterfaceNumber);
741 if (intf->altsetting->desc.bInterfaceNumber > 0)
744 if (vendor_id == 0x0471) {
745 switch (product_id) {
747 PWC_INFO(
"Philips PCA645VC USB webcam detected.\n");
748 name =
"Philips 645 webcam";
752 PWC_INFO(
"Philips PCA646VC USB webcam detected.\n");
753 name =
"Philips 646 webcam";
757 PWC_INFO(
"Askey VC010 type 2 USB webcam detected.\n");
758 name =
"Askey VC010 webcam";
762 PWC_INFO(
"Philips PCVC675K (Vesta) USB webcam detected.\n");
763 name =
"Philips 675 webcam";
767 PWC_INFO(
"Philips PCVC680K (Vesta Pro) USB webcam detected.\n");
768 name =
"Philips 680 webcam";
772 PWC_INFO(
"Philips PCVC690K (Vesta Pro Scan) USB webcam detected.\n");
773 name =
"Philips 690 webcam";
777 PWC_INFO(
"Philips PCVC730K (ToUCam Fun)/PCVC830 (ToUCam II) USB webcam detected.\n");
778 name =
"Philips 730 webcam";
782 PWC_INFO(
"Philips PCVC740K (ToUCam Pro)/PCVC840 (ToUCam II) USB webcam detected.\n");
783 name =
"Philips 740 webcam";
787 PWC_INFO(
"Philips PCVC750K (ToUCam Pro Scan) USB webcam detected.\n");
788 name =
"Philips 750 webcam";
792 PWC_INFO(
"Philips PCVC720K/40 (ToUCam XS) USB webcam detected.\n");
793 name =
"Philips 720K/40 webcam";
797 PWC_INFO(
"Philips SPC 900NC USB webcam detected.\n");
798 name =
"Philips SPC 900NC webcam";
806 else if (vendor_id == 0x069A) {
809 PWC_INFO(
"Askey VC010 type 1 USB webcam detected.\n");
810 name =
"Askey VC010 webcam";
818 else if (vendor_id == 0x046d) {
821 PWC_INFO(
"Logitech QuickCam Pro 3000 USB webcam detected.\n");
822 name =
"Logitech QuickCam Pro 3000";
826 PWC_INFO(
"Logitech QuickCam Notebook Pro USB webcam detected.\n");
827 name =
"Logitech QuickCam Notebook Pro";
831 PWC_INFO(
"Logitech QuickCam 4000 Pro USB webcam detected.\n");
832 name =
"Logitech QuickCam Pro 4000";
834 if (my_power_save == -1)
838 PWC_INFO(
"Logitech QuickCam Zoom USB webcam detected.\n");
839 name =
"Logitech QuickCam Zoom";
843 PWC_INFO(
"Logitech QuickCam Zoom (new model) USB webcam detected.\n");
844 name =
"Logitech QuickCam Zoom";
846 if (my_power_save == -1)
850 PWC_INFO(
"Logitech QuickCam Orbit/Sphere USB webcam detected.\n");
851 name =
"Logitech QuickCam Orbit";
853 if (my_power_save == -1)
858 PWC_INFO(
"Logitech/Cisco VT Camera webcam detected.\n");
859 name =
"Cisco VT Camera";
863 PWC_INFO(
"Logitech ViewPort AV 100 webcam detected.\n");
864 name =
"Logitech ViewPort AV 100";
868 PWC_INFO(
"Logitech QuickCam detected (reserved ID).\n");
869 name =
"Logitech QuickCam (res.)";
877 else if (vendor_id == 0x055d) {
884 PWC_INFO(
"Samsung MPC-C10 USB webcam detected.\n");
885 name =
"Samsung MPC-C10";
889 PWC_INFO(
"Samsung MPC-C30 USB webcam detected.\n");
890 name =
"Samsung MPC-C30";
894 PWC_INFO(
"Samsung SNC-35E (v3.0) USB webcam detected.\n");
895 name =
"Samsung MPC-C30";
903 else if (vendor_id == 0x041e) {
906 PWC_INFO(
"Creative Labs Webcam 5 detected.\n");
907 name =
"Creative Labs Webcam 5";
909 if (my_power_save == -1)
913 PWC_INFO(
"Creative Labs Webcam Pro Ex detected.\n");
914 name =
"Creative Labs Webcam Pro Ex";
922 else if (vendor_id == 0x04cc) {
925 PWC_INFO(
"Sotec Afina Eye USB webcam detected.\n");
926 name =
"Sotec Afina Eye";
934 else if (vendor_id == 0x06be) {
938 PWC_INFO(
"AME Co. Afina Eye USB webcam detected.\n");
939 name =
"AME Co. Afina Eye";
948 else if (vendor_id == 0x0d81) {
951 PWC_INFO(
"Visionite VCS-UC300 USB webcam detected.\n");
952 name =
"Visionite VCS-UC300";
956 PWC_INFO(
"Visionite VCS-UM100 USB webcam detected.\n");
957 name =
"Visionite VCS-UM100";
968 if (my_power_save == -1)
971 memset(serial_number, 0, 30);
972 usb_string(udev, udev->descriptor.iSerialNumber, serial_number, 29);
975 if (udev->descriptor.bNumConfigurations > 1)
976 PWC_WARNING(
"Warning: more than 1 configuration available.\n");
981 PWC_ERROR(
"Oops, could not allocate memory for pwc_device.\n");
1001 pdev->
vb_queue.ops = &pwc_vb_queue_ops;
1006 memcpy(&pdev->
vdev, &pwc_template,
sizeof(pwc_template));
1011 video_set_drvdata(&pdev->
vdev, pdev);
1019 PWC_ERROR(
"Oops, could not allocate memory for pwc_device.\n");
1024 #ifdef CONFIG_USB_PWC_DEBUG
1029 pwc_sensor_type_to_string(rc), rc);
1045 PWC_ERROR(
"Failed to register v4l2 controls (%d).\n", rc);
1053 pdev->
v4l2_dev.release = pwc_video_release;
1056 PWC_ERROR(
"Failed to register v4l2-device (%d).\n", rc);
1057 goto err_free_controls;
1066 PWC_ERROR(
"Failed to register as video device (%d).\n", rc);
1067 goto err_unregister_v4l2_dev;
1069 PWC_INFO(
"Registered as %s.\n", video_device_node_name(&pdev->
vdev));
1071 #ifdef CONFIG_USB_PWC_INPUT_EVDEV
1073 pdev->button_dev = input_allocate_device();
1074 if (!pdev->button_dev) {
1075 PWC_ERROR(
"Err, insufficient memory for webcam snapshot button device.");
1077 goto err_video_unreg;
1080 usb_make_path(udev, pdev->button_phys,
sizeof(pdev->button_phys));
1081 strlcat(pdev->button_phys,
"/input0",
sizeof(pdev->button_phys));
1083 pdev->button_dev->name =
"PWC snapshot button";
1084 pdev->button_dev->phys = pdev->button_phys;
1085 usb_to_input_id(pdev->
udev, &pdev->button_dev->id);
1086 pdev->button_dev->dev.parent = &pdev->
udev->dev;
1090 rc = input_register_device(pdev->button_dev);
1092 input_free_device(pdev->button_dev);
1093 pdev->button_dev =
NULL;
1094 goto err_video_unreg;
1102 err_unregister_v4l2_dev:
1122 pwc_isoc_cleanup(pdev);
1124 pwc_cleanup_queued_bufs(pdev);
1131 #ifdef CONFIG_USB_PWC_INPUT_EVDEV
1132 if (pdev->button_dev)
1133 input_unregister_device(pdev->button_dev);
1144 static unsigned int leds_nargs;
1146 #ifdef CONFIG_USB_PWC_DEBUG
1152 #ifdef CONFIG_USB_PWC_DEBUG