3 * @author Nicolas VIVIEN
7 * @brief Driver for Syntek 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
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>
42 #include <linux/usb.h>
43 #include <media/v4l2-common.h>
50 * Number of frame per second by default
52 static int default_fps
= -1;
56 * Enable / Disable horizontal flip image
58 static int default_hflip
= -1;
62 * Enable / Disable vertical flip image
64 static int default_vflip
= -1;
67 * @var default_brightness
70 static int default_brightness
= -1;
73 * @var default_whiteness
76 static int default_whiteness
= -1;
79 * @var default_contrast
82 static int default_contrast
= -1;
88 static int default_colour
= -1;
93 * Define all the hotplug supported devices by this driver
95 static struct usb_device_id stk11xx_table
[] = {
96 { USB_DEVICE(USB_SYNTEK1_VENDOR_ID
, USB_STK_A311_PRODUCT_ID
) },
97 { USB_DEVICE(USB_SYNTEK1_VENDOR_ID
, USB_STK_A821_PRODUCT_ID
) },
98 { USB_DEVICE(USB_SYNTEK1_VENDOR_ID
, USB_STK_6A31_PRODUCT_ID
) },
99 { USB_DEVICE(USB_SYNTEK1_VENDOR_ID
, USB_STK_6A33_PRODUCT_ID
) },
101 { USB_DEVICE(USB_SYNTEK2_VENDOR_ID
, USB_STK_0501_PRODUCT_ID
) },
106 MODULE_DEVICE_TABLE(usb
, stk11xx_table
); /**< Define the supported devices */
111 * @param dev Device structure
113 * @returns 0 if all is OK
115 * @brief Initilize an isochronous pipe.
117 * This function permits to initialize an URB transfert (or isochronous pipe).
119 int usb_stk11xx_isoc_init(struct usb_stk11xx
*dev
)
124 struct usb_device
*udev
;
129 if (dev
->isoc_init_ok
)
134 STK_DEBUG("usb_stk11xx_isoc_init()\n");
136 // Allocate URB structure
137 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
138 urb
= usb_alloc_urb(ISO_FRAMES_PER_DESC
, GFP_KERNEL
);
141 STK_ERROR("Failed to allocate URB %d\n", i
);
146 dev
->isobuf
[i
].urb
= urb
;
151 if (dev
->isobuf
[i
].urb
!= NULL
)
152 usb_free_urb(dev
->isobuf
[i
].urb
);
154 dev
->isobuf
[i
].urb
= NULL
;
161 // Init URB structure
162 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
163 urb
= dev
->isobuf
[i
].urb
;
167 urb
->pipe
= usb_rcvisocpipe(udev
, dev
->isoc_in_endpointAddr
);
168 urb
->transfer_flags
= URB_ISO_ASAP
;
169 urb
->transfer_buffer
= dev
->isobuf
[i
].data
;
170 urb
->transfer_buffer_length
= ISO_BUFFER_SIZE
;
171 urb
->complete
= usb_stk11xx_isoc_handler
;
173 urb
->start_frame
= 0;
174 urb
->number_of_packets
= ISO_FRAMES_PER_DESC
;
176 for (j
=0; j
<ISO_FRAMES_PER_DESC
; j
++) {
177 urb
->iso_frame_desc
[j
].offset
= j
* ISO_MAX_FRAME_SIZE
;
178 urb
->iso_frame_desc
[j
].length
= ISO_MAX_FRAME_SIZE
; //dev->isoc_in_size;
182 STK_DEBUG("dev->isoc_in_size = %X\n", dev
->isoc_in_size
);
183 STK_DEBUG("dev->isoc_in_endpointAddr = %X\n", dev
->isoc_in_endpointAddr
);
186 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
187 ret
= usb_submit_urb(dev
->isobuf
[i
].urb
, GFP_KERNEL
);
190 STK_ERROR("isoc_init() submit_urb %d failed with error %d\n", i
, ret
);
192 STK_DEBUG("URB 0x%p submitted.\n", dev
->isobuf
[i
].urb
);
196 STK_ERROR("ENOMEM\n");
199 STK_ERROR("ENODEV\n");
202 STK_ERROR("ENXIO\n");
205 STK_ERROR("EINVAL\n");
208 STK_ERROR("EAGAIN\n");
211 STK_ERROR("EFBIG\n");
214 STK_ERROR("EPIPE\n");
217 STK_ERROR("EMSGSIZE\n");
223 dev
->isoc_init_ok
= 1;
230 * @param urb URB structure
232 * @brief ISOC handler
234 * This function is called as an URB transfert is complete (Isochronous pipe).
235 * So, the traitement is done in interrupt time, so it has be fast, not crash,
236 * ans not stall. Neat.
238 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
239 void usb_stk11xx_isoc_handler(struct urb
*urb
, struct pt_regs
*regs
)
241 void usb_stk11xx_isoc_handler(struct urb
*urb
)
252 unsigned char *fill
= NULL
;
253 unsigned char *iso_buf
= NULL
;
255 struct usb_stk11xx
*dev
;
256 struct stk11xx_frame_buf
*framebuf
;
258 STK_STREAM("Isoc handler\n");
260 dev
= (struct usb_stk11xx
*) urb
->context
;
263 STK_ERROR("isoc_handler called with NULL device !\n");
267 if (urb
->status
== -ENOENT
|| urb
->status
== -ECONNRESET
) {
268 STK_DEBUG("URB unlinked synchronuously !\n");
272 if (urb
->status
!= -EINPROGRESS
&& urb
->status
!= 0) {
277 switch(urb
->status
) {
279 errmsg
= "Buffer error (overrun)";
283 errmsg
= "Stalled (device not responding)";
287 errmsg
= "Babble (bad cable?)";
291 errmsg
= "Bit-stuff error (bad cable?)";
295 errmsg
= "CRC/Timeout (could be anything)";
299 errmsg
= "NAK (device does not respond)";
303 STK_ERROR("isoc_handler() called with status %d [%s].\n", urb
->status
, errmsg
);
307 wake_up_interruptible(&dev
->wait_frame
);
309 urb
->dev
= dev
->udev
;
310 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
313 STK_ERROR("Error (%d) re-submitting urb in stk11xx_isoc_handler.\n", ret
);
319 framebuf
= dev
->fill_frame
;
321 if (framebuf
== NULL
) {
322 STK_ERROR("isoc_handler without valid fill frame !\n");
324 wake_up_interruptible(&dev
->wait_frame
);
326 urb
->dev
= dev
->udev
;
327 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
330 STK_ERROR("Error (%d) re-submitting urb in stk11xx_isoc_handler.\n", ret
);
336 fill
= framebuf
->data
+ framebuf
->filled
;
339 // Reset ISOC error counter
340 dev
->visoc_errors
= 0;
343 for (i
=0; i
<urb
->number_of_packets
; i
++) {
344 framestatus
= urb
->iso_frame_desc
[i
].status
;
345 framelen
= urb
->iso_frame_desc
[i
].actual_length
;
346 iso_buf
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
348 if (framestatus
== 0) {
352 // we found something informational from there
353 // the isoc frames have to type of headers
354 // type1: 00 xx 00 00 or 20 xx 00 00
355 // type2: 80 xx 00 00 00 00 00 00 or a0 xx 00 00 00 00 00 00
356 // xx is a sequencer which has never been seen over 0x3f
358 // imho data written down looks like bayer, i see similarities after
360 if (*iso_buf
& 0x80) {
364 // Our buffer is full !!!
365 if (framelen
- skip
+ framebuf
->filled
> dev
->frame_size
) {
366 STK_ERROR("Frame buffer overflow !\n");
371 memcpy(fill
, iso_buf
+ skip
, framelen
- skip
);
372 fill
+= framelen
- skip
;
375 // New size of our buffer
376 framebuf
->filled
+= framelen
- skip
;
379 STK_STREAM("URB : Length = %d - Skip = %d - Buffer size = %d\n",
380 framelen
, skip
, framebuf
->filled
);
382 // Data is always follow by a frame with a length '4'
384 if (framebuf
->filled
> 0) {
385 // Our buffer has enough data ?
386 if (framebuf
->filled
< dev
->frame_size
)
389 // If there are errors, we skip a frame...
390 if (framebuf
->errors
== 0) {
391 if (stk11xx_next_frame(dev
))
392 dev
->vframes_dumped
++;
395 dev
->vframes_error
++;
398 framebuf
= dev
->fill_frame
;
399 framebuf
->filled
= 0;
400 framebuf
->errors
= 0;
401 fill
= framebuf
->data
;
406 STK_ERROR("Iso frame %d of USB has error %d\n", i
, framestatus
);
411 wake_up_interruptible(&dev
->wait_frame
);
413 urb
->dev
= dev
->udev
;
415 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
418 STK_ERROR("Error (%d) re-submitting urb in stk11xx_isoc_handler.\n", ret
);
424 * @param dev Device structure
426 * @brief Clean-up all the ISOC buffers
428 * This function permits to clean-up all the ISOC buffers.
430 void usb_stk11xx_isoc_cleanup(struct usb_stk11xx
*dev
)
434 STK_DEBUG("Isoc cleanup\n");
439 if (dev
->isoc_init_ok
== 0)
442 // Unlinking ISOC buffers
443 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
446 urb
= dev
->isobuf
[i
].urb
;
449 if (dev
->isoc_init_ok
)
453 dev
->isobuf
[i
].urb
= NULL
;
458 dev
->isoc_init_ok
= 0;
464 * @param dev Device structure
465 * @param index Choice of the interface
467 * @returns 0 if all is OK
469 * @brief Send the message SET_FEATURE and choose the interface
471 * This function permits to send the message SET_FEATURE on the USB bus.
473 int usb_stk11xx_set_feature(struct usb_stk11xx
*dev
, int index
)
476 struct usb_device
*udev
= dev
->udev
;
478 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
480 USB_TYPE_STANDARD
| USB_DIR_OUT
| USB_RECIP_DEVICE
,
481 USB_DEVICE_REMOTE_WAKEUP
,
488 STK_ERROR("SET FEATURE fail !\n");
490 STK_DEBUG("SET FEATURE\n");
497 * @param dev Device structure
499 * @returns 0 if all is OK
501 * @brief Send the message SET_CONFIGURATION
503 * This function permits to send the message SET_CONFIGURATION on the USB bus.
505 int usb_stk11xx_set_configuration(struct usb_stk11xx
*dev
)
508 struct usb_device
*udev
= dev
->udev
;
510 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
511 USB_REQ_SET_CONFIGURATION
,
512 USB_TYPE_STANDARD
| USB_DIR_OUT
| USB_RECIP_DEVICE
,
514 udev
->config
[0].desc
.bConfigurationValue
,
520 STK_ERROR("SET CONFIGURATION fail !\n");
522 STK_DEBUG("SET CONFIGURATION %d\n", udev
->config
[0].desc
.bConfigurationValue
);
533 * @returns 0 if all is OK
535 * @brief Write a 16-bits value to a 16-bits register
537 * This function permits to write a 16-bits value to a 16-bits register on the USB bus.
539 int usb_stk11xx_write_registry(struct usb_stk11xx
*dev
, __u16 index
, __u16 value
)
542 struct usb_device
*udev
= dev
->udev
;
544 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
546 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
554 STK_ERROR("Write registry fails %02X = %02X", index
, value
);
565 * @returns 0 if all is OK
567 * @brief Read a 16-bits value from a 16-bits register
569 * This function permits to read a 16-bits value from a 16-bits register on the USB bus.
571 int usb_stk11xx_read_registry(struct usb_stk11xx
*dev
, __u16 index
, int *value
)
575 struct usb_device
*udev
= dev
->udev
;
579 result
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
581 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
589 STK_ERROR("Read registry fails %02X", index
);
598 * @returns 0 if all is OK
600 * @brief Set the default value about the video settings.
602 * This function permits to set the video settings for each video camera model.
605 static int usb_stk11xx_default_settings(struct usb_stk11xx
*dev
)
607 switch (dev
->webcam_model
) {
608 case SYNTEK_STK_M811
:
609 case SYNTEK_STK_A311
:
610 dev
->vsettings
.fps
= (default_fps
== -1) ? 25 : default_fps
;
611 dev
->vsettings
.vflip
= (default_vflip
== -1) ? 1 : default_vflip
;
612 dev
->vsettings
.hflip
= (default_hflip
== -1) ? 1 : default_hflip
;
614 dev
->vsettings
.brightness
= (default_brightness
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_brightness
;
615 dev
->vsettings
.whiteness
= (default_whiteness
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_whiteness
;
616 dev
->vsettings
.contrast
= (default_contrast
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_contrast
;
617 dev
->vsettings
.colour
= (default_colour
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour
;
620 case SYNTEK_STK_A821
:
621 dev
->vsettings
.fps
= (default_fps
== -1) ? 25 : default_fps
;
622 dev
->vsettings
.vflip
= (default_vflip
== -1) ? 0 : default_vflip
;
623 dev
->vsettings
.hflip
= (default_hflip
== -1) ? 0 : default_hflip
;
625 dev
->vsettings
.brightness
= (default_brightness
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_brightness
;
626 dev
->vsettings
.whiteness
= (default_whiteness
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_whiteness
;
627 dev
->vsettings
.contrast
= (default_contrast
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_contrast
;
628 dev
->vsettings
.colour
= (default_colour
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour
;
631 case SYNTEK_STK_6A31
:
632 case SYNTEK_STK_6A33
:
633 dev
->vsettings
.fps
= (default_fps
== -1) ? 25 : default_fps
;
634 dev
->vsettings
.vflip
= (default_vflip
== -1) ? 0 : default_vflip
;
635 dev
->vsettings
.hflip
= (default_hflip
== -1) ? 0 : default_hflip
;
637 dev
->vsettings
.brightness
= (default_brightness
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_brightness
;
638 dev
->vsettings
.whiteness
= (default_whiteness
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_whiteness
;
639 dev
->vsettings
.contrast
= (default_contrast
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_contrast
;
640 dev
->vsettings
.colour
= (default_colour
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour
;
643 case SYNTEK_STK_6A54
:
644 dev
->vsettings
.fps
= (default_fps
== -1) ? 25 : default_fps
;
645 dev
->vsettings
.vflip
= (default_vflip
== -1) ? 0 : default_vflip
;
646 dev
->vsettings
.hflip
= (default_hflip
== -1) ? 0 : default_hflip
;
648 dev
->vsettings
.brightness
= (default_brightness
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_brightness
;
649 dev
->vsettings
.whiteness
= (default_whiteness
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_whiteness
;
650 dev
->vsettings
.contrast
= (default_contrast
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_contrast
;
651 dev
->vsettings
.colour
= (default_colour
== -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour
;
666 * @returns 0 if all is OK
668 * @brief Load the driver
670 * This function detects the device and allocate the buffers for the device
671 * and the video interface.
673 static int usb_stk11xx_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
)
685 struct usb_stk11xx
*dev
= NULL
;
686 struct usb_device
*udev
= interface_to_usbdev(interface
);
687 struct usb_host_interface
*iface_desc
;
688 struct usb_endpoint_descriptor
*endpoint
;
691 // Get USB VendorID and ProductID
692 vendor_id
= le16_to_cpu(udev
->descriptor
.idVendor
);
693 product_id
= le16_to_cpu(udev
->descriptor
.idProduct
);
695 // Check if we can handle this device
696 STK_DEBUG("Probe function called with VendorID=%04X, ProductID=%04X and InterfaceNumber=%d\n",
697 vendor_id
, product_id
, interface
->cur_altsetting
->desc
.bInterfaceNumber
);
699 // The interface are probed one by one.
700 // We are interested in the video interface (always the interface '0')
701 // The interfaces '1' or '2' (if presents) are the audio control.
702 if (interface
->cur_altsetting
->desc
.bInterfaceNumber
> 0)
706 if (vendor_id
== USB_SYNTEK1_VENDOR_ID
) {
707 switch (product_id
) {
708 case USB_STK_A311_PRODUCT_ID
:
709 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
710 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0xA311.\n");
711 webcam_model
= SYNTEK_STK_A311
;
712 webcam_type
= STK11XX_SXGA
;
715 case USB_STK_A821_PRODUCT_ID
:
716 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
717 STK_INFO("Syntek AVStream USB2.0 VGA WebCam - Product ID 0xA821.\n");
718 webcam_model
= SYNTEK_STK_A821
;
719 webcam_type
= STK11XX_VGA
;
722 case USB_STK_6A31_PRODUCT_ID
:
723 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
724 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x6A31.\n");
725 webcam_model
= SYNTEK_STK_6A31
;
726 webcam_type
= STK11XX_VGA
;
729 case USB_STK_6A33_PRODUCT_ID
:
730 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
731 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x6A33.\n");
732 webcam_model
= SYNTEK_STK_6A33
;
733 webcam_type
= STK11XX_VGA
;
736 case USB_STK_6A54_PRODUCT_ID
:
737 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
738 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x6A54.\n");
739 webcam_model
= SYNTEK_STK_6A54
;
740 webcam_type
= STK11XX_VGA
;
744 STK_ERROR("usb_stk11xx_probe failed ! Camera product 0x%04X is not supported.\n",
745 le16_to_cpu(udev
->descriptor
.idProduct
));
749 else if (vendor_id
== USB_SYNTEK2_VENDOR_ID
) {
750 switch (product_id
) {
751 case USB_STK_0501_PRODUCT_ID
:
752 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
753 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x0501.\n");
754 webcam_model
= SYNTEK_STK_M811
;
755 webcam_type
= STK11XX_SXGA
;
759 STK_ERROR("usb_stk11xx_probe failed ! Camera product 0x%04X is not supported.\n",
760 le16_to_cpu(udev
->descriptor
.idProduct
));
767 // Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device
768 dev
= kzalloc(sizeof(struct usb_stk11xx
), GFP_KERNEL
);
771 STK_ERROR("Out of memory !\n");
775 // Init mutexes, spinlock, etc.
776 init_MUTEX(&dev
->mutex
);
777 spin_lock_init(&dev
->spinlock
);
778 init_waitqueue_head(&dev
->wait_frame
);
781 dev
->webcam_model
= webcam_model
;
782 dev
->webcam_type
= webcam_type
;
784 dev
->interface
= interface
;
786 // Read the product release
787 dev
->release
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
788 STK_INFO("Release: %04x\n", dev
->release
);
790 // How many interfaces (1 or 3) ?
791 bNumInterfaces
= udev
->config
->desc
.bNumInterfaces
;
792 STK_INFO("Number of interfaces : %d\n", bNumInterfaces
);
797 dev
->len_per_image
= PAGE_ALIGN((1280 * 1024 * 4));
800 // Switch on the camera (to detect size of buffers)
801 dev_stk11xx_camera_on(dev
);
804 // Set up the endpoint information
805 // use only the first int-in and isoc-in endpoints
806 // for the current alternate setting
807 iface_desc
= interface
->cur_altsetting
;
809 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
810 endpoint
= &iface_desc
->endpoint
[i
].desc
;
812 if (!dev
->int_in_endpointAddr
813 && ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == USB_DIR_IN
)
814 && ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) == USB_ENDPOINT_XFER_INT
)) {
815 // we found an interrupt in endpoint
816 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
818 dev
->int_in_size
= buffer_size
;
819 dev
->int_in_endpointAddr
= (endpoint
->bEndpointAddress
& 0xf);
822 if (!dev
->isoc_in_endpointAddr
823 && ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == USB_DIR_IN
)
824 && ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) == USB_ENDPOINT_XFER_ISOC
)) {
825 // we found an isoc in endpoint
826 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
828 dev
->isoc_in_size
= buffer_size
;
829 dev
->isoc_in_endpointAddr
= (endpoint
->bEndpointAddress
& 0xf);
833 if (!(dev
->int_in_endpointAddr
&& dev
->isoc_in_endpointAddr
)) {
834 STK_ERROR("Could not find both int-in and isoc-in endpoints");
843 dev_stk11xx_camera_off(dev
);
845 // Initialize the video device
846 dev
->vdev
= video_device_alloc();
853 // Initialize the camera
854 dev_stk11xx_initialize_device(dev
);
856 // Register the video device
857 err
= v4l_stk11xx_register_video_device(dev
);
864 // Create the entries in the sys filesystem
865 stk11xx_create_sysfs_files(dev
->vdev
);
867 // Save our data pointer in this interface device
868 usb_set_intfdata(interface
, dev
);
870 // Default settings video device
871 usb_stk11xx_default_settings(dev
);
881 * @brief This function is called when the device is disconnected
882 * or when the kernel module is unloaded.
884 static void usb_stk11xx_disconnect(struct usb_interface
*interface
)
886 struct usb_stk11xx
*dev
= usb_get_intfdata(interface
);
888 STK_INFO("Syntek USB2.0 Camera disconnected\n");
890 usb_set_intfdata(interface
, NULL
);
892 // We got unplugged; this is signalled by an EPIPE error code
894 STK_INFO("Disconnected while webcam is in use !\n");
895 dev
->error_status
= EPIPE
;
898 // Alert waiting processes
899 wake_up_interruptible(&dev
->wait_frame
);
901 // Wait until device is closed
905 // Unregister the video device
906 v4l_stk11xx_unregister_video_device(dev
);
908 // Remove the entries in the sys filesystem
909 stk11xx_remove_sysfs_files(dev
->vdev
);
914 * @var usb_stk11xx_driver
916 * This variable contains some callback
918 static struct usb_driver usb_stk11xx_driver
= {
919 .name
= "usb_stk11xx_driver",
920 .probe
= usb_stk11xx_probe
,
921 .disconnect
= usb_stk11xx_disconnect
,
922 .id_table
= stk11xx_table
,
928 * Module parameter to set frame per second
934 * Module parameter to enable/disable the horizontal flip process
936 static int hflip
= -1;
940 * Module parameter to enable/disable the vertical flip process
942 static int vflip
= -1;
946 * Module parameter to set the brightness
948 static int brightness
= -1;
952 * Module parameter to set the whiteness
954 static int whiteness
= -1;
958 * Module parameter to set the contrast
960 static int contrast
= -1;
964 * Module parameter to set the colour
966 static int colour
= -1;
969 module_param(fps
, int, 0444); /**< @brief Module frame per second parameter */
970 module_param(hflip
, int, 0444); /**< @brief Module horizontal flip process */
971 module_param(vflip
, int, 0444); /**< @brief Module vertical flip process */
973 module_param(brightness
, int, 0444); /**< @brief Module brightness */
974 module_param(whiteness
, int, 0444); /**< @brief Module whiteness */
975 module_param(contrast
, int, 0444); /**< @brief Module contrast */
976 module_param(colour
, int, 0444); /**< @brief Module colour */
980 * @returns 0 if all is OK
982 * @brief Initialize the driver.
984 * This function is called at first.
985 * This function permits to define the default values from the command line.
987 static int __init
usb_stk11xx_init(void)
992 STK_INFO("Syntek USB2.0 webcam driver startup\n");
994 // Frame per second parameter
996 if (fps
< 9 || fps
> 30) {
997 STK_ERROR("Framerate out of bounds [10-30] !\n");
1004 // Horizontal flip value
1005 if ((hflip
== 0) || (hflip
== 1)) {
1006 STK_DEBUG("Set horizontal flip = %d\n", hflip
);
1008 default_hflip
= hflip
;
1011 // Vertical flip value
1012 if ((vflip
== 0) || (vflip
== 1)) {
1013 STK_DEBUG("Set vertical flip = %d\n", vflip
);
1015 default_vflip
= vflip
;
1019 if (brightness
> -1) {
1020 STK_DEBUG("Set brightness = 0x%X\n", brightness
);
1022 default_brightness
= 0xffff & brightness
;
1026 if (whiteness
> -1) {
1027 STK_DEBUG("Set whiteness = 0x%X\n", whiteness
);
1029 default_whiteness
= 0xffff & whiteness
;
1033 if (contrast
> -1) {
1034 STK_DEBUG("Set contrast = 0x%X\n", contrast
);
1036 default_contrast
= 0xffff & contrast
;
1041 STK_DEBUG("Set colour = 0x%X\n", colour
);
1043 default_colour
= 0xffff & colour
;
1047 // Register the driver with the USB subsystem
1048 result
= usb_register(&usb_stk11xx_driver
);
1051 STK_ERROR("usb_register failed ! Error number %d\n", result
);
1053 STK_INFO(DRIVER_VERSION
" : " DRIVER_DESC
"\n");
1060 * @brief Close the driver
1062 * This function is called at last when you unload the driver.
1064 static void __exit
usb_stk11xx_exit(void)
1066 STK_INFO("usb_stk11xx_exit: Syntek USB2.0 webcam driver shutdown\n");
1068 // Deregister this driver with the USB subsystem
1069 usb_deregister(&usb_stk11xx_driver
);
1073 module_init(usb_stk11xx_init
); /**< @brief Module initialize */
1074 module_exit(usb_stk11xx_exit
); /**< @brief Module exit */
1077 MODULE_PARM_DESC(fps
, "Frames per second [5-30]"); /**< @brief Description of 'fps' parameter */
1078 MODULE_PARM_DESC(hflip
, "Horizontal image flip"); /**< @brief Description of 'hflip' parameter */
1079 MODULE_PARM_DESC(vflip
, "Vertical image flip"); /**< @brief Description of 'vflip' parameter */
1080 MODULE_PARM_DESC(brightness
, "Brightness setting"); /**< @brief Description of 'brightness' parameter */
1081 MODULE_PARM_DESC(whiteness
, "Whiteness setting"); /**< @brief Description of 'whiteness' parameter */
1082 MODULE_PARM_DESC(colour
, "Colour setting"); /**< @brief Description of 'colour' parameter */
1083 MODULE_PARM_DESC(contrast
, "Contrast setting"); /**< @brief Description of 'contrast' parameter */
1086 MODULE_LICENSE("GPL"); /**< @brief Driver is under licence GPL */
1087 MODULE_AUTHOR(DRIVER_AUTHOR
); /**< @brief Driver is written by Nicolas VIVIEN */
1088 MODULE_DESCRIPTION(DRIVER_DESC
); /**< @brief Define the description of the driver */
1089 MODULE_SUPPORTED_DEVICE(DRIVER_SUPPORT
); /**< @brief List of supported device */