3 * @author Nicolas VIVIEN
7 * @brief Driver for Microdia USB video camera
9 * @note Copyright (C) Nicolas VIVIEN
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * $Date: 2007-12-08 11:34:45 +0100 (sam, 08 déc 2007) $
30 * $Author: nicklas79 $
31 * $HeadURL: https://syntekdriver.svn.sourceforge.net/svnroot/syntekdriver/trunk/driver/microdia-usb.c $
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/version.h>
38 #include <linux/errno.h>
39 #include <linux/slab.h>
40 #include <linux/kref.h>
41 #include <linux/debugfs.h>
42 #include <linux/stat.h>
44 #include <linux/usb.h>
45 #include <media/v4l2-common.h>
51 * Module parameter to set frame per second
57 * Module parameter to enable/disable the horizontal flip process
63 * Module parameter to enable/disable the vertical flip process
69 * Module parameter to set the brightness
71 static int brightness
= MICRODIA_PERCENT(50, 0xFFFF);
75 * Module parameter to set the whiteness
77 static int whiteness
= MICRODIA_PERCENT(20, 0xFFFF);
81 * Module parameter to set the contrast
83 static int contrast
= MICRODIA_PERCENT(50, 0xFFFF);
87 * Module parameter to set the exposure
89 static int exposure
= MICRODIA_PERCENT(20, 0xFFFF);
93 * Name of our directory in debugfs
95 static const char * debug_dir_name
= "microdia";
98 * @var debug_file_name
99 * Name of our debug file in debugfs
101 static const char * debug_file_name
= "debug_level";
105 * Dentry for our debug dir (for cleanup)
107 static struct dentry
* debug_dir
;
111 * Dentry for our debug file (for cleanup)
113 static struct dentry
* debug_file
;
117 * Level at which we do debugging
119 static __u8 debug_level
= 0;
123 * @var microdia_table
124 * Define all the hotplug supported devices by this driver
126 static struct usb_device_id microdia_table
[] = {
127 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_6027_PRODUCT_ID
) },
128 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_608F_PRODUCT_ID
) },
129 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_60FE_PRODUCT_ID
) },
130 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_6242_PRODUCT_ID
) },
131 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_6253_PRODUCT_ID
) },
132 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_6260_PRODUCT_ID
) },
133 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_6270_PRODUCT_ID
) },
134 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_62C0_PRODUCT_ID
) },
135 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_613B_PRODUCT_ID
) },
136 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_613C_PRODUCT_ID
) },
137 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_624F_PRODUCT_ID
) },
138 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_627B_PRODUCT_ID
) },
139 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_62C0_PRODUCT_ID
) },
140 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_8105_PRODUCT_ID
) },
141 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_624E_PRODUCT_ID
) },
142 { USB_DEVICE(USB_MICRODIA_VENDOR_ID
, USB_UDIA_6128_PRODUCT_ID
) },
147 MODULE_DEVICE_TABLE(usb
, microdia_table
); /**< Define the supported devices */
152 * @param dev Device structure
154 * @returns 0 if all is OK
156 * @brief Initilize an isochronous pipe.
158 * This function permits to initialize an URB transfert (or isochronous pipe).
160 int usb_microdia_isoc_init(struct usb_microdia
*dev
)
164 __u16 iso_max_frame_size
;
166 struct usb_device
*udev
;
171 if (dev
->isoc_init_ok
)
176 UDIA_DEBUG("usb_microdia_isoc_init()\n");
178 // Allocate URB structure
179 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
180 urb
= usb_alloc_urb(ISO_FRAMES_PER_DESC
, GFP_KERNEL
);
183 UDIA_ERROR("Failed to allocate URB %d\n", i
);
188 dev
->isobuf
[i
].urb
= urb
;
193 if (dev
->isobuf
[i
].urb
!= NULL
)
194 usb_free_urb(dev
->isobuf
[i
].urb
);
196 dev
->isobuf
[i
].urb
= NULL
;
204 // iso_max_frame_size should be the endpoints maximum packetsize * the highbandwidth multiplier.
206 iso_max_frame_size
= max_packet_sz(le16_to_cpu(dev
->isoc_in_size
)) * hb_multiplier(le16_to_cpu(dev
->isoc_in_size
));
208 // Init URB structure
209 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
210 urb
= dev
->isobuf
[i
].urb
;
214 urb
->pipe
= usb_rcvisocpipe(udev
, dev
->isoc_in_endpointAddr
);
215 urb
->transfer_flags
= URB_ISO_ASAP
;
216 urb
->transfer_buffer
= dev
->isobuf
[i
].data
;
217 urb
->transfer_buffer_length
= iso_max_frame_size
* ISO_FRAMES_PER_DESC
;
218 urb
->complete
= usb_microdia_isoc_handler
;
220 urb
->start_frame
= 0;
221 urb
->number_of_packets
= ISO_FRAMES_PER_DESC
;
223 for (j
=0; j
<ISO_FRAMES_PER_DESC
; j
++) {
224 urb
->iso_frame_desc
[j
].offset
= j
* iso_max_frame_size
;
225 urb
->iso_frame_desc
[j
].length
= iso_max_frame_size
; //dev->isoc_in_size;
229 UDIA_DEBUG("dev->isoc_in_size = %X\n", dev
->isoc_in_size
);
230 UDIA_DEBUG("dev->isoc_in_endpointAddr = %X\n", dev
->isoc_in_endpointAddr
);
233 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
234 ret
= usb_submit_urb(dev
->isobuf
[i
].urb
, GFP_KERNEL
);
237 UDIA_ERROR("isoc_init() submit_urb %d failed with error %d\n", i
, ret
);
239 UDIA_DEBUG("URB 0x%p submitted.\n", dev
->isobuf
[i
].urb
);
243 UDIA_ERROR("ENOMEM\n");
246 UDIA_ERROR("ENODEV\n");
249 UDIA_ERROR("ENXIO\n");
252 UDIA_ERROR("EINVAL\n");
255 UDIA_ERROR("EAGAIN\n");
258 UDIA_ERROR("EFBIG\n");
261 UDIA_ERROR("EPIPE\n");
264 UDIA_ERROR("EMSGSIZE\n");
270 dev
->isoc_init_ok
= 1;
277 * @param urb URB structure
279 * @brief ISOC handler
281 * This function is called as an URB transfert is complete (Isochronous pipe).
282 * So, the traitement is done in interrupt time, so it has be fast, not crash,
283 * ans not stall. Neat.
285 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
286 void usb_microdia_isoc_handler(struct urb
*urb
, struct pt_regs
*regs
)
288 void usb_microdia_isoc_handler(struct urb
*urb
)
299 unsigned char *fill
= NULL
;
300 unsigned char *iso_buf
= NULL
;
302 struct usb_microdia
*dev
;
303 struct microdia_frame_buf
*framebuf
;
305 unsigned char frame_header
[] = {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96};
307 UDIA_STREAM("Isoc handler\n");
309 dev
= (struct usb_microdia
*) urb
->context
;
312 UDIA_ERROR("isoc_handler called with NULL device !\n");
316 if (urb
->status
== -ENOENT
|| urb
->status
== -ECONNRESET
) {
317 UDIA_DEBUG("URB unlinked synchronuously !\n");
321 if (urb
->status
!= -EINPROGRESS
&& urb
->status
!= 0) {
326 switch(urb
->status
) {
328 errmsg
= "Buffer error (overrun)";
332 errmsg
= "Stalled (device not responding)";
336 errmsg
= "Babble (bad cable?)";
340 errmsg
= "Bit-stuff error (bad cable?)";
344 errmsg
= "CRC/Timeout (could be anything)";
348 errmsg
= "NAK (device does not respond)";
352 UDIA_ERROR("isoc_handler() called with status %d [%s].\n", urb
->status
, errmsg
);
356 wake_up_interruptible(&dev
->wait_frame
);
358 urb
->dev
= dev
->udev
;
359 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
362 UDIA_ERROR("Error (%d) re-submitting urb in microdia_isoc_handler.\n", ret
);
368 framebuf
= dev
->fill_frame
;
370 if (framebuf
== NULL
) {
371 UDIA_ERROR("isoc_handler without valid fill frame !\n");
373 wake_up_interruptible(&dev
->wait_frame
);
375 urb
->dev
= dev
->udev
;
376 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
379 UDIA_ERROR("Error (%d) re-submitting urb in microdia_isoc_handler.\n", ret
);
385 fill
= framebuf
->data
+ framebuf
->filled
;
388 // Reset ISOC error counter
389 dev
->visoc_errors
= 0;
392 for (i
=0; i
<urb
->number_of_packets
; i
++) {
393 framestatus
= urb
->iso_frame_desc
[i
].status
;
394 framelen
= urb
->iso_frame_desc
[i
].actual_length
;
395 iso_buf
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
397 if (framestatus
== 0) {
398 // By default, I keep all packet.
399 // So I don't skip byte !
403 // For microdia devices, data are isoc packet with site > 0.
405 if (memcmp(iso_buf
, frame_header
, 6) == 0) {
406 if ((framebuf
->filled
== dev
->frame_size
+ (dev
->frame_size
/2)) && framebuf
->errors
== 0) {
407 if (microdia_next_frame(dev
)) {
408 dev
->vframes_dumped
++;
411 dev
->vframes_error
++;
414 framebuf
= dev
->fill_frame
;
415 framebuf
->filled
= 0;
416 framebuf
->errors
= 0;
417 fill
= framebuf
->data
;
420 // Our buffer is full !!!
421 if (framelen
- skip
+ framebuf
->filled
> dev
->frame_size
+ (dev
->frame_size
/2)) {
422 UDIA_ERROR("Frame buffer overflow !\n");
427 memcpy(fill
, iso_buf
+ skip
, framelen
- skip
);
428 fill
+= framelen
- skip
;
431 // New size of our buffer
432 framebuf
->filled
+= framelen
- skip
;
435 UDIA_STREAM("URB : Length = %d - Skip = %d - Buffer size = %d\n",
436 framelen
, skip
, framebuf
->filled
);
439 UDIA_ERROR("Iso frame %d of USB has error %d\n", i
, framestatus
);
444 wake_up_interruptible(&dev
->wait_frame
);
446 urb
->dev
= dev
->udev
;
448 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
451 UDIA_ERROR("Error (%d) re-submitting urb in microdia_isoc_handler.\n", ret
);
457 * @param dev Device structure
459 * @brief Clean-up all the ISOC buffers
461 * This function permits to clean-up all the ISOC buffers.
463 void usb_microdia_isoc_cleanup(struct usb_microdia
*dev
)
467 UDIA_DEBUG("Isoc cleanup\n");
472 if (dev
->isoc_init_ok
== 0)
475 // Unlinking ISOC buffers
476 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
479 urb
= dev
->isobuf
[i
].urb
;
482 if (dev
->isoc_init_ok
)
486 dev
->isobuf
[i
].urb
= NULL
;
491 dev
->isoc_init_ok
= 0;
497 * @param dev Device structure
498 * @param index Choice of the interface
500 * @returns 0 if all is OK
502 * @brief Send the message SET_FEATURE and choose the interface
504 * This function permits to send the message SET_FEATURE on the USB bus.
506 int usb_microdia_set_feature(struct usb_microdia
*dev
, int index
)
509 struct usb_device
*udev
= dev
->udev
;
511 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
513 USB_TYPE_STANDARD
| USB_DIR_OUT
| USB_RECIP_DEVICE
,
514 USB_DEVICE_REMOTE_WAKEUP
,
521 UDIA_ERROR("SET FEATURE fail !\n");
523 UDIA_DEBUG("SET FEATURE\n");
530 * @param dev Device structure
532 * @returns 0 if all is OK
534 * @brief Send the message SET_CONFIGURATION
536 * This function permits to send the message SET_CONFIGURATION on the USB bus.
538 int usb_microdia_set_configuration(struct usb_microdia
*dev
)
541 struct usb_device
*udev
= dev
->udev
;
543 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
544 USB_REQ_SET_CONFIGURATION
,
545 USB_TYPE_STANDARD
| USB_DIR_OUT
| USB_RECIP_DEVICE
,
547 udev
->config
[0].desc
.bConfigurationValue
,
553 UDIA_ERROR("SET CONFIGURATION fail !\n");
555 UDIA_DEBUG("SET CONFIGURATION %d\n", udev
->config
[0].desc
.bConfigurationValue
);
562 * @param dev Device structure
563 * @param value register to write to
565 * @param length number of bytes
567 * @returns 0 if all is OK
569 * @brief Write a 16-bit value to a 16-bit register
571 * This function permits to write a 16-bit value to a 16-bit register on the USB bus.
573 int usb_microdia_control_write(struct usb_microdia
*dev
, __u16 value
, __u8
*data
, __u16 length
)
576 struct usb_device
*udev
= dev
->udev
;
578 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
580 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_INTERFACE
,
588 UDIA_ERROR("Write register failed index = %02X", value
);
600 * @returns 0 if all is OK
602 * @brief Write a series of 16-bit "commands" using the same buffer
604 int usb_microdia_control_write_multi(struct usb_microdia
*dev
, __u16
*commands
, __u8
*data
,
605 __u16 cmdlen
, __u16 datalen
)
609 for(i
= 0; i
< cmdlen
; i
++) {
610 result
= usb_microdia_control_write(dev
, commands
[i
], data
, datalen
);
620 * @param dev Device structure
621 * @param index register to read from
623 * @param length number of bytes
625 * @returns 0 if all is OK
627 * @brief Read a 16-bit value from a 16-bit register
629 * This function permits to read a 16-bit value from a 16-bit register on the USB bus.
631 int usb_microdia_control_read(struct usb_microdia
*dev
, __u16 index
, __u8
*data
, __u16 length
)
635 struct usb_device
*udev
= dev
->udev
;
639 result
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
641 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_INTERFACE
,
649 UDIA_ERROR("Read register failed %02X", index
);
658 * @returns 0 if all is OK
660 * @brief Set the default value about the video settings.
662 * This function permits to set the video settings for each video camera model.
665 static int usb_microdia_default_settings(struct usb_microdia
*dev
)
667 switch (dev
->webcam_model
) {
669 dev
->vsettings
.fps
= fps
;
670 dev
->vsettings
.vflip
= vflip
;
671 dev
->vsettings
.hflip
= hflip
;
673 dev
->vsettings
.brightness
= brightness
& 0xffff;
674 dev
->vsettings
.contrast
= contrast
& 0xffff;
675 dev
->vsettings
.whiteness
= whiteness
& 0xffff;
676 dev
->vsettings
.exposure
= exposure
& 0xffff;
685 extern int microdia_627b_initialize(struct usb_microdia
*dev
);
686 extern int microdia_627b_start_stream(struct usb_microdia
*dev
);
687 extern int microdia_627b_stop_stream(struct usb_microdia
*dev
);
688 extern int microdia_624f_initialize(struct usb_microdia
*dev
);
689 extern int microdia_624e_initialize(struct usb_microdia
*dev
);
690 extern int microdia_6128_initialize(struct usb_microdia
*dev
);
691 extern int microdia_6270_initialize(struct usb_microdia
*dev
);
692 extern int microdia_624f_stop_stream(struct usb_microdia
*dev
);
693 extern int microdia_624f_start_stream(struct usb_microdia
*dev
);
694 extern int microdia_624f_set_exposure(struct usb_microdia
*dev
);
695 extern int microdia_6128_start_stream(struct usb_microdia
*dev
);
696 extern int microdia_6128_stop_stream(struct usb_microdia
*dev
);
697 extern int microdia_624e_start_stream(struct usb_microdia
*dev
);
698 extern int microdia_624e_stop_stream(struct usb_microdia
*dev
);
699 extern int microdia_6242_start_stream(struct usb_microdia
*dev
);
700 extern int microdia_6242_stop_stream(struct usb_microdia
*dev
);
701 extern int microdia_6260_initialize(struct usb_microdia
*dev
);
702 extern int microdia_6260_start_stream(struct usb_microdia
*dev
);
703 extern int microdia_6260_stop_stream(struct usb_microdia
*dev
);
704 extern int microdia_6270_start_stream(struct usb_microdia
*dev
);
705 extern int microdia_6270_stop_stream(struct usb_microdia
*dev
);
706 extern int microdia_6270_set_exposure(struct usb_microdia
*dev
);
713 * @returns 0 if all is OK
715 * @brief Load the driver
717 * This function detects the device and allocate the buffers for the device
718 * and the video interface.
720 static int usb_microdia_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
)
731 int (*initialize
)(struct usb_microdia
*) = NULL
;
732 int (*stop_stream
)(struct usb_microdia
*) = NULL
;
733 int (*start_stream
)(struct usb_microdia
*) = NULL
;
734 int (*set_exposure
)(struct usb_microdia
*) = NULL
;
736 struct usb_microdia
*dev
= NULL
;
737 struct usb_device
*udev
= interface_to_usbdev(interface
);
738 struct usb_host_interface
*iface_desc
;
739 struct usb_endpoint_descriptor
*endpoint
;
742 // Get USB VendorID and ProductID
743 vendor_id
= le16_to_cpu(udev
->descriptor
.idVendor
);
744 product_id
= le16_to_cpu(udev
->descriptor
.idProduct
);
746 // Check if we can handle this device
747 UDIA_DEBUG("Probe function called with VendorID=%04X, ProductID=%04X and InterfaceNumber=%d\n",
748 vendor_id
, product_id
, interface
->cur_altsetting
->desc
.bInterfaceNumber
);
750 // The interface are probed one by one.
751 // We are interested in the video interface (always the interface '0')
752 // The interfaces '1' or '2' (if presents) are the audio control.
753 if (interface
->cur_altsetting
->desc
.bInterfaceNumber
> 0)
757 if (vendor_id
== USB_MICRODIA_VENDOR_ID
) {
758 switch (product_id
) {
759 case USB_UDIA_6027_PRODUCT_ID
:
760 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 6027.\n");
761 webcam_model
= MICRODIA_6027
;
762 webcam_type
= MICRODIA_VGA
;
765 case USB_UDIA_608F_PRODUCT_ID
:
766 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 608F.\n");
767 webcam_model
= MICRODIA_608F
;
768 webcam_type
= MICRODIA_VGA
;
771 case USB_UDIA_60FE_PRODUCT_ID
:
772 webcam_model
= MICRODIA_60FE
;
773 webcam_type
= MICRODIA_VGA
;
776 case USB_UDIA_6242_PRODUCT_ID
:
777 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 6242.\n");
778 webcam_model
= MICRODIA_6242
;
779 webcam_type
= MICRODIA_VGA
;
780 initialize
= microdia_624e_initialize
;
781 start_stream
= microdia_6242_start_stream
;
782 stop_stream
= microdia_6242_stop_stream
;
785 case USB_UDIA_6253_PRODUCT_ID
:
786 webcam_model
= MICRODIA_6253
;
787 webcam_type
= MICRODIA_VGA
;
790 case USB_UDIA_6260_PRODUCT_ID
:
791 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 6260.\n");
792 webcam_model
= MICRODIA_6260
;
793 webcam_type
= MICRODIA_VGA
;
794 initialize
= microdia_6260_initialize
;
795 start_stream
= microdia_6260_start_stream
;
796 stop_stream
= microdia_6260_stop_stream
;
799 case USB_UDIA_6270_PRODUCT_ID
:
800 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 6270.\n");
801 webcam_model
= MICRODIA_6270
;
802 webcam_type
= MICRODIA_VGA
;
803 initialize
= microdia_6270_initialize
;
804 start_stream
= microdia_6270_start_stream
;
805 stop_stream
= microdia_6270_stop_stream
;
806 set_exposure
= microdia_6270_set_exposure
;
809 case USB_UDIA_60C0_PRODUCT_ID
:
810 webcam_model
= MICRODIA_60C0
;
811 webcam_type
= MICRODIA_VGA
;
814 case USB_UDIA_613B_PRODUCT_ID
:
815 webcam_model
= MICRODIA_613B
;
816 webcam_type
= MICRODIA_VGA
;
819 case USB_UDIA_613C_PRODUCT_ID
:
820 webcam_model
= MICRODIA_613C
;
821 webcam_type
= MICRODIA_VGA
;
824 case USB_UDIA_624F_PRODUCT_ID
:
825 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 624F.\n");
826 webcam_model
= MICRODIA_624F
;
827 webcam_type
= MICRODIA_VGA
;
828 initialize
= microdia_624f_initialize
;
829 start_stream
= microdia_624f_start_stream
;
830 stop_stream
= microdia_624f_stop_stream
;
831 set_exposure
= microdia_624f_set_exposure
;
834 case USB_UDIA_627B_PRODUCT_ID
:
835 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 627B.\n");
836 webcam_model
= MICRODIA_627B
;
837 webcam_type
= MICRODIA_VGA
;
838 initialize
= microdia_627b_initialize
;
839 start_stream
= microdia_627b_start_stream
;
840 stop_stream
= microdia_627b_stop_stream
;
843 case USB_UDIA_62C0_PRODUCT_ID
:
844 webcam_model
= MICRODIA_62C0
;
845 webcam_type
= MICRODIA_VGA
;
848 case USB_UDIA_8105_PRODUCT_ID
:
849 webcam_model
= MICRODIA_8105
;
850 webcam_type
= MICRODIA_VGA
;
853 case USB_UDIA_624E_PRODUCT_ID
:
854 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 624E.\n");
855 webcam_model
= MICRODIA_624E
;
856 webcam_type
= MICRODIA_SXGA
;
857 initialize
= microdia_624e_initialize
;
858 start_stream
= microdia_624e_start_stream
;
859 stop_stream
= microdia_624e_stop_stream
;
862 case USB_UDIA_6128_PRODUCT_ID
:
863 UDIA_INFO("Microdia USB2.0 Webcam - Product ID 6128.\n");
864 webcam_model
= MICRODIA_6128
;
865 webcam_type
= MICRODIA_SXGA
;
866 initialize
= microdia_6128_initialize
;
867 start_stream
= microdia_6128_start_stream
;
868 stop_stream
= microdia_6128_stop_stream
;
872 UDIA_ERROR("usb_microdia_probe failed ! Camera product 0x%04X is not supported.\n",
873 le16_to_cpu(udev
->descriptor
.idProduct
));
880 // Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device
881 dev
= kzalloc(sizeof(struct usb_microdia
), GFP_KERNEL
);
884 UDIA_ERROR("Out of memory !\n");
888 // Init mutexes, spinlock, etc.
889 init_MUTEX(&dev
->mutex
);
890 spin_lock_init(&dev
->spinlock
);
891 init_waitqueue_head(&dev
->wait_frame
);
894 dev
->webcam_model
= webcam_model
;
895 dev
->webcam_type
= webcam_type
;
896 dev
->initialize
= initialize
;
897 dev
->stop_stream
= stop_stream
;
898 dev
->start_stream
= start_stream
;
899 dev
->set_exposure
= set_exposure
;
901 dev
->interface
= interface
;
903 // Read the product release
904 dev
->release
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
905 UDIA_INFO("Release: %04x\n", dev
->release
);
907 // How many interfaces (1 or 3) ?
908 bNumInterfaces
= udev
->config
->desc
.bNumInterfaces
;
909 UDIA_INFO("Number of interfaces : %d\n", bNumInterfaces
);
914 dev
->len_per_image
= PAGE_ALIGN((1280 * 1024 * 4));
917 // Switch on the camera (to detect size of buffers)
918 dev_microdia_camera_on(dev
);
921 // Set up the endpoint information
922 // use only the first int-in and isoc-in endpoints
923 // for the current alternate setting
924 iface_desc
= interface
->cur_altsetting
;
926 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
927 endpoint
= &iface_desc
->endpoint
[i
].desc
;
929 if (!dev
->int_in_endpointAddr
930 && ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == USB_DIR_IN
)
931 && ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) == USB_ENDPOINT_XFER_INT
)) {
932 // we found an interrupt in endpoint
933 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
935 dev
->int_in_size
= buffer_size
;
936 dev
->int_in_endpointAddr
= (endpoint
->bEndpointAddress
& 0xf);
939 if (!dev
->isoc_in_endpointAddr
940 && ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == USB_DIR_IN
)
941 && ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) == USB_ENDPOINT_XFER_ISOC
)) {
942 // we found an isoc in endpoint
943 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
945 dev
->isoc_in_size
= buffer_size
;
946 dev
->isoc_in_endpointAddr
= (endpoint
->bEndpointAddress
& 0xf);
950 if (!(dev
->int_in_endpointAddr
&& dev
->isoc_in_endpointAddr
)) {
951 UDIA_ERROR("Could not find both int-in and isoc-in endpoints");
960 dev_microdia_camera_off(dev
);
962 // Initialize the video device
963 dev
->vdev
= video_device_alloc();
970 // Initialize the camera
971 dev_microdia_initialize_device(dev
);
973 // Register the video device
974 err
= v4l_microdia_register_video_device(dev
);
977 video_device_release(dev
->vdev
); // Oops release video dev
982 // Create the entries in the sys filesystem
983 microdia_create_sysfs_files(dev
->vdev
);
985 // Save our data pointer in this interface device
986 usb_set_intfdata(interface
, dev
);
988 // Default settings video device
989 usb_microdia_default_settings(dev
);
999 * @brief This function is called when the device is disconnected
1000 * or when the kernel module is unloaded.
1002 static void usb_microdia_disconnect(struct usb_interface
*interface
)
1004 struct usb_microdia
*dev
= usb_get_intfdata(interface
);
1006 UDIA_INFO("Microdia USB2.0 Camera disconnected\n");
1008 usb_set_intfdata(interface
, NULL
);
1010 // We got unplugged; this is signalled by an EPIPE error code
1012 UDIA_INFO("Disconnected while webcam is in use !\n");
1013 dev
->error_status
= EPIPE
;
1016 // Alert waiting processes
1017 wake_up_interruptible(&dev
->wait_frame
);
1019 // Wait until device is closed
1023 // Remove the entries in the sys filesystem
1024 microdia_remove_sysfs_files(dev
->vdev
);
1026 // Unregister the video device
1027 v4l_microdia_unregister_video_device(dev
);
1032 * @var usb_microdia_driver
1034 * This variable contains some callback
1036 static struct usb_driver usb_microdia_driver
= {
1037 .name
= "usb_microdia_driver",
1038 .probe
= usb_microdia_probe
,
1039 .disconnect
= usb_microdia_disconnect
,
1040 .id_table
= microdia_table
,
1043 module_param(fps
, int, 0444); /**< @brief Module frame per second parameter */
1044 module_param(hflip
, int, 0444); /**< @brief Module horizontal flip process */
1045 module_param(vflip
, int, 0444); /**< @brief Module vertical flip process */
1047 module_param(brightness
, int, 0444); /**< @brief Module brightness */
1048 module_param(whiteness
, int, 0444); /**< @brief Module whiteness */
1049 module_param(contrast
, int, 0444); /**< @brief Module contrast */
1050 module_param(exposure
, int, 0444); /**< @brief Module exposure */
1054 * @returns 0 if all is OK
1056 * @brief Initialize the driver.
1058 * This function is called at first.
1059 * This function permits to define the default values from the command line.
1061 static int __init
usb_microdia_init(void)
1066 UDIA_INFO("Microdia USB2.0 webcam driver startup\n");
1068 debug_dir
= debugfs_create_dir(debug_dir_name
, NULL
);
1070 debug_file
= debugfs_create_u8(debug_file_name
, S_IRUGO
| S_IWUGO
,
1071 debug_dir
, &debug_level
);
1073 if(fps
< 10 || fps
> 30) {
1074 UDIA_WARNING("Framerate out of bounds [10-30]! Defaulting to 25\n");
1078 if(vflip
!= 0 && vflip
!= 1) {
1079 UDIA_WARNING("Vertical flip should be 0 or 1! Defaulting to 0\n");
1083 if(hflip
!= 0 && hflip
!= 1) {
1084 UDIA_WARNING("Horizontal flip should be 0 or 1! Defaulting to 0\n");
1088 // Register the driver with the USB subsystem
1089 result
= usb_register(&usb_microdia_driver
);
1092 UDIA_ERROR("usb_register failed ! Error number %d\n", result
);
1094 UDIA_INFO(DRIVER_VERSION
" : " DRIVER_DESC
"\n");
1101 * @brief Close the driver
1103 * This function is called at last when you unload the driver.
1105 static void __exit
usb_microdia_exit(void)
1107 UDIA_INFO("usb_microdia_exit: Microdia USB2.0 webcam driver shutdown\n");
1110 debugfs_remove(debug_file
);
1112 debugfs_remove(debug_dir
);
1114 // Deregister this driver with the USB subsystem
1115 usb_deregister(&usb_microdia_driver
);
1119 module_init(usb_microdia_init
); /**< @brief Module initialize */
1120 module_exit(usb_microdia_exit
); /**< @brief Module exit */
1123 MODULE_PARM_DESC(fps
, "Frames per second [10-30]"); /**< @brief Description of 'fps' parameter */
1124 MODULE_PARM_DESC(hflip
, "Horizontal image flip"); /**< @brief Description of 'hflip' parameter */
1125 MODULE_PARM_DESC(vflip
, "Vertical image flip"); /**< @brief Description of 'vflip' parameter */
1126 MODULE_PARM_DESC(brightness
, "Brightness setting"); /**< @brief Description of 'brightness' parameter */
1127 MODULE_PARM_DESC(whiteness
, "Whiteness setting"); /**< @brief Description of 'whiteness' parameter */
1128 MODULE_PARM_DESC(exposure
, "Exposure setting"); /**< @brief Description of 'exposure' parameter */
1129 MODULE_PARM_DESC(contrast
, "Contrast setting"); /**< @brief Description of 'contrast' parameter */
1132 MODULE_LICENSE("GPL"); /**< @brief Driver is under licence GPL */
1133 MODULE_AUTHOR(DRIVER_AUTHOR
); /**< @brief Driver is written by Nicolas VIVIEN */
1134 MODULE_DESCRIPTION(DRIVER_DESC
); /**< @brief Define the description of the driver */
1135 MODULE_SUPPORTED_DEVICE(DRIVER_SUPPORT
); /**< @brief List of supported device */