2 * stk-webcam.c : Driver for Syntek 1125 USB webcam controller
4 * Copyright (C) 2006 Nicolas VIVIEN
5 * Copyright 2007 Jaime Velasco Juan <jsagarribay@gmail.com>
7 * Some parts are inspired from cafe_ccic.c
8 * Copyright 2006-2007 Jonathan Corbet
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/errno.h>
29 #include <linux/slab.h>
30 #include <linux/kref.h>
32 #include <linux/usb.h>
33 #include <linux/videodev2.h>
34 #include <media/v4l2-common.h>
35 #include <linux/vmalloc.h>
36 #include <linux/version.h>
38 #include "stk-webcam.h"
42 module_param(hflip
, bool, 0444);
43 MODULE_PARM_DESC(hflip
, "Horizontal image flip (mirror). Defaults to 1");
46 module_param(vflip
, bool, 0444);
47 MODULE_PARM_DESC(vflip
, "Vertical image flip. Defaults to 1");
50 module_param(debug
, int, 0444);
51 MODULE_PARM_DESC(debug
, "Debug v4l ioctls. Defaults to 0");
53 MODULE_LICENSE("GPL");
54 MODULE_AUTHOR("Jaime Velasco Juan <jsagarribay@gmail.com> and Nicolas VIVIEN");
55 MODULE_DESCRIPTION("Syntek DC1125 webcam driver");
59 /* Some cameras have audio interfaces, we aren't interested in those */
60 static struct usb_device_id stkwebcam_table
[] = {
61 { USB_DEVICE_AND_INTERFACE_INFO(0x174f, 0xa311, 0xff, 0xff, 0xff) },
62 { USB_DEVICE_AND_INTERFACE_INFO(0x05e1, 0x0501, 0xff, 0xff, 0xff) },
65 MODULE_DEVICE_TABLE(usb
, stkwebcam_table
);
67 void stk_camera_cleanup(struct kref
*kref
)
69 struct stk_camera
*dev
= to_stk_camera(kref
);
71 STK_INFO("Syntek USB2.0 Camera release resources"
72 " video device /dev/video%d\n", dev
->vdev
.minor
);
73 video_unregister_device(&dev
->vdev
);
74 dev
->vdev
.priv
= NULL
;
76 if (dev
->sio_bufs
!= NULL
|| dev
->isobufs
!= NULL
)
77 STK_ERROR("We are leaking memory\n");
78 usb_put_intf(dev
->interface
);
86 int stk_camera_write_reg(struct stk_camera
*dev
, u16 index
, u8 value
)
88 struct usb_device
*udev
= dev
->udev
;
91 ret
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
93 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
105 int stk_camera_read_reg(struct stk_camera
*dev
, u16 index
, int *value
)
107 struct usb_device
*udev
= dev
->udev
;
110 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
112 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
124 static int stk_start_stream(struct stk_camera
*dev
)
128 int value_116
, value_117
;
130 if (!is_present(dev
))
132 if (!is_memallocd(dev
) || !is_initialised(dev
)) {
133 STK_ERROR("FIXME: Buffers are not allocated\n");
136 ret
= usb_set_interface(dev
->udev
, 0, 5);
139 STK_ERROR("usb_set_interface failed !\n");
140 if (stk_sensor_wakeup(dev
))
141 STK_ERROR("error awaking the sensor\n");
143 stk_camera_read_reg(dev
, 0x0116, &value_116
);
144 stk_camera_read_reg(dev
, 0x0117, &value_117
);
146 stk_camera_write_reg(dev
, 0x0116, 0x0000);
147 stk_camera_write_reg(dev
, 0x0117, 0x0000);
149 stk_camera_read_reg(dev
, 0x0100, &value
); // read 0x21
150 stk_camera_write_reg(dev
, 0x0100, value
| 0x80);
152 stk_camera_write_reg(dev
, 0x0116, value_116
);
153 stk_camera_write_reg(dev
, 0x0117, value_117
);
154 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
155 if (dev
->isobufs
[i
].urb
) {
156 ret
= usb_submit_urb(dev
->isobufs
[i
].urb
, GFP_KERNEL
);
157 atomic_inc(&dev
->urbs_used
);
166 static int stk_stop_stream(struct stk_camera
*dev
)
170 if (is_present(dev
)) {
171 stk_camera_read_reg(dev
, 0x0100, &value
);
172 stk_camera_write_reg(dev
, 0x0100, value
& ~0x80);
173 if (dev
->isobufs
!= NULL
) {
174 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
175 if (dev
->isobufs
[i
].urb
)
176 usb_kill_urb(dev
->isobufs
[i
].urb
);
179 unset_streaming(dev
);
181 if (usb_set_interface(dev
->udev
, 0, 0))
182 STK_ERROR("usb_set_interface failed !\n");
183 if (stk_sensor_sleep(dev
))
184 STK_ERROR("error suspending the sensor\n");
190 * This seems to be the shortest init sequence we
191 * must do in order to find the sensor
192 * Bit 5 of reg. 0x0000 here is important, when reset to 0 the sensor
193 * is also reset. Maybe powers down it?
194 * Rest of values don't make a difference
197 static struct regval stk1125_initvals
[] = {
198 //TODO: What means this sequence?
227 static int stk_initialise(struct stk_camera
*dev
)
231 if (!is_present(dev
))
233 if (is_initialised(dev
))
235 rv
= stk1125_initvals
;
236 while (rv
->reg
!= 0xffff) {
237 ret
= stk_camera_write_reg(dev
, rv
->reg
, rv
->val
);
242 if (stk_sensor_init(dev
) == 0) {
243 set_initialised(dev
);
249 /* sysfs functions */
250 /*FIXME cleanup this */
252 static ssize_t
show_brightness(struct device
*class,
253 struct device_attribute
*attr
, char *buf
)
255 struct video_device
*vdev
= to_video_device(class);
256 struct stk_camera
*dev
= vdev_to_camera(vdev
);
258 return sprintf(buf
, "%X\n", dev
->vsettings
.brightness
);
261 static ssize_t
store_brightness(struct device
*class,
262 struct device_attribute
*attr
, const char *buf
, size_t count
)
268 struct video_device
*vdev
= to_video_device(class);
269 struct stk_camera
*dev
= vdev_to_camera(vdev
);
271 value
= simple_strtoul(buf
, &endp
, 16);
273 dev
->vsettings
.brightness
= (int) value
;
275 ret
= stk_sensor_set_brightness(dev
, value
>> 8);
282 static ssize_t
show_hflip(struct device
*class,
283 struct device_attribute
*attr
, char *buf
)
285 struct video_device
*vdev
= to_video_device(class);
286 struct stk_camera
*dev
= vdev_to_camera(vdev
);
288 return sprintf(buf
, "%d\n", dev
->vsettings
.hflip
);
291 static ssize_t
store_hflip(struct device
*class,
292 struct device_attribute
*attr
, const char *buf
, size_t count
)
294 struct video_device
*vdev
= to_video_device(class);
295 struct stk_camera
*dev
= vdev_to_camera(vdev
);
297 if (strncmp(buf
, "1", 1) == 0)
298 dev
->vsettings
.hflip
= 1;
299 else if (strncmp(buf
, "0", 1) == 0)
300 dev
->vsettings
.hflip
= 0;
307 static ssize_t
show_vflip(struct device
*class,
308 struct device_attribute
*attr
, char *buf
)
310 struct video_device
*vdev
= to_video_device(class);
311 struct stk_camera
*dev
= vdev_to_camera(vdev
);
313 return sprintf(buf
, "%d\n", dev
->vsettings
.vflip
);
316 static ssize_t
store_vflip(struct device
*class,
317 struct device_attribute
*attr
, const char *buf
, size_t count
)
319 struct video_device
*vdev
= to_video_device(class);
320 struct stk_camera
*dev
= vdev_to_camera(vdev
);
322 if (strncmp(buf
, "1", 1) == 0)
323 dev
->vsettings
.vflip
= 1;
324 else if (strncmp(buf
, "0", 1) == 0)
325 dev
->vsettings
.vflip
= 0;
333 static ssize_t
store_shack(struct device
*class,
334 struct device_attribute
*attr
, const char *buf
, size_t count
)
340 struct video_device
*vdev
= to_video_device(class);
341 struct stk_camera
*dev
= vdev_to_camera(vdev
);
343 reg
= simple_strtoul(buf
, &endp
, 16);
344 value
= simple_strtoul(endp
+1, NULL
, 16);
346 stk_sensor_outb(dev
, reg
, value
);
351 static ssize_t
store_chack(struct device
*class,
352 struct device_attribute
*attr
, const char *buf
, size_t count
)
358 struct video_device
*vdev
= to_video_device(class);
359 struct stk_camera
*dev
= vdev_to_camera(vdev
);
361 reg
= simple_strtoul(buf
, &endp
, 16);
362 value
= simple_strtoul(endp
+1, NULL
, 16);
364 stk_camera_write_reg(dev
, reg
, value
);
369 static DEVICE_ATTR(shack
, S_IWUGO
, NULL
, store_shack
);
370 static DEVICE_ATTR(chack
, S_IWUGO
, NULL
, store_chack
);
373 static DEVICE_ATTR(brightness
, S_IRUGO
| S_IWUGO
, show_brightness
, store_brightness
);
374 static DEVICE_ATTR(hflip
, S_IRUGO
| S_IWUGO
, show_hflip
, store_hflip
);
375 static DEVICE_ATTR(vflip
, S_IRUGO
| S_IWUGO
, show_vflip
, store_vflip
);
377 static int stk_create_sysfs_files(struct video_device
*vdev
)
381 ret
= video_device_create_file(vdev
, &dev_attr_brightness
);
382 ret
+= video_device_create_file(vdev
, &dev_attr_hflip
);
383 ret
+= video_device_create_file(vdev
, &dev_attr_vflip
);
385 ret
+= video_device_create_file(vdev
, &dev_attr_shack
);
386 ret
+= video_device_create_file(vdev
, &dev_attr_chack
);
391 static void stk_remove_sysfs_files(struct video_device
*vdev
)
393 video_device_remove_file(vdev
, &dev_attr_brightness
);
394 video_device_remove_file(vdev
, &dev_attr_hflip
);
395 video_device_remove_file(vdev
, &dev_attr_vflip
);
397 video_device_remove_file(vdev
, &dev_attr_shack
);
398 video_device_remove_file(vdev
, &dev_attr_chack
);
403 /* *********************************************** */
405 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
406 static inline int list_is_singular(const struct list_head
*head
)
408 return !list_empty(head
) && (head
->next
== head
->prev
);
413 * This function is called as an URB transfert is complete (Isochronous pipe).
414 * So, the traitement is done in interrupt time, so it has be fast, not crash,
415 * and not stall. Neat.
417 static void stk_isoc_handler(struct urb
*urb
)
424 unsigned char *fill
= NULL
;
425 unsigned char *iso_buf
= NULL
;
427 struct stk_camera
*dev
;
428 struct stk_sio_buffer
*fb
;
430 dev
= (struct stk_camera
*) urb
->context
;
433 STK_ERROR("isoc_handler called with NULL device !\n");
437 if (urb
->status
== -ENOENT
|| urb
->status
== -ECONNRESET
438 || urb
->status
== -ESHUTDOWN
) {
439 STK_DEBUG("URB unlinked synchronuously !\n");
440 atomic_dec(&dev
->urbs_used
);
444 spin_lock_irqsave(&dev
->spinlock
, flags
);
446 if (urb
->status
!= -EINPROGRESS
&& urb
->status
!= 0) {
447 STK_ERROR("isoc_handler: urb->status == %d\n", urb
->status
);
451 if (list_empty(&dev
->sio_avail
)) {
452 /*FIXME Stop streaming after a while */
453 (void) (printk_ratelimit() &&
454 STK_ERROR("isoc_handler without available buffer!\n"));
457 fb
= list_first_entry(&dev
->sio_avail
,
458 struct stk_sio_buffer
, list
);
459 fill
= fb
->buffer
+ fb
->v4lbuf
.bytesused
;
462 for (i
=0; i
<urb
->number_of_packets
; i
++) {
463 if (urb
->iso_frame_desc
[i
].status
!= 0) {
464 if (urb
->iso_frame_desc
[i
].status
!= -EXDEV
)
465 STK_ERROR("Frame %d has error %d\n", i
,
466 urb
->iso_frame_desc
[i
].status
);
469 framelen
= urb
->iso_frame_desc
[i
].actual_length
;
470 iso_buf
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
473 continue; /* no data */
475 // we found something informational from there
476 // the isoc frames have to type of headers
477 // type1: 00 xx 00 00 or 20 xx 00 00
478 // type2: 80 xx 00 00 00 00 00 00 or a0 xx 00 00 00 00 00 00
479 // xx is a sequencer which has never been seen over 0x3f
480 // imho data written down looks like bayer, i see similarities
481 // after every 640 bytes
482 if (*iso_buf
& 0x80) {
485 STK_DEBUG("New frame %d bytes\n", framelen
);
486 #ifdef STK_PARTIAL_FRAMES
487 if (fb
->v4lbuf
.bytesused
!= 0)
488 fb
->v4lbuf
.bytesused
= dev
->frame_size
;
490 /* This marks a new frame */
491 if (fb
->v4lbuf
.bytesused
!= 0
492 && fb
->v4lbuf
.bytesused
!= dev
->frame_size
) {
493 (void ) (printk_ratelimit() &&
494 STK_ERROR("frame %d, "
495 "bytesused=%d, skipping\n",
496 i
, fb
->v4lbuf
.bytesused
));
497 fb
->v4lbuf
.bytesused
= 0;
500 else if (fb
->v4lbuf
.bytesused
== dev
->frame_size
) {
501 if (list_is_singular(&dev
->sio_avail
)) {
502 /* Always reuse the last buffer */
503 fb
->v4lbuf
.bytesused
= 0;
507 list_move_tail(dev
->sio_avail
.next
,
509 wake_up(&dev
->wait_frame
);
510 fb
= list_first_entry(&dev
->sio_avail
,
511 struct stk_sio_buffer
, list
);
512 fb
->v4lbuf
.bytesused
= 0;
520 STK_DEBUG("Got %d bytes\n", framelen
);
523 // Our buffer is full !!!
524 if (framelen
+ fb
->v4lbuf
.bytesused
> dev
->frame_size
) {
525 (void) (printk_ratelimit() &&
526 STK_ERROR("Frame buffer overflow, lost sync\n"));
531 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
532 memcpy(fill
, iso_buf
, framelen
);
533 spin_lock_irqsave(&dev
->spinlock
, flags
);
536 // New size of our buffer
537 fb
->v4lbuf
.bytesused
+= framelen
;
541 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
542 urb
->dev
= dev
->udev
;
543 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
545 STK_ERROR("Error (%d) re-submitting urb in stk_isoc_handler.\n",
550 /* -------------------------------------------- */
552 static int stk_prepare_iso(struct stk_camera
*dev
)
557 struct usb_device
*udev
;
564 STK_ERROR("isobufs already allocated. Bad\n");
566 dev
->isobufs
= kzalloc(MAX_ISO_BUFS
* sizeof(*dev
->isobufs
),
568 if (dev
->isobufs
== NULL
) {
569 STK_ERROR("Unable to allocate iso buffers\n");
572 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
573 if (dev
->isobufs
[i
].data
== NULL
) {
574 kbuf
= kzalloc(ISO_BUFFER_SIZE
, GFP_KERNEL
);
576 STK_ERROR("Failed to allocate iso buffer %d\n",
580 dev
->isobufs
[i
].data
= kbuf
;
583 STK_ERROR("isobuf data already allocated\n");
585 if (dev
->isobufs
[i
].urb
== NULL
) {
586 urb
= usb_alloc_urb(ISO_FRAMES_PER_DESC
, GFP_KERNEL
);
588 STK_ERROR("Failed to allocate URB %d\n", i
);
591 dev
->isobufs
[i
].urb
= urb
;
594 STK_ERROR("Killing URB\n");
595 usb_kill_urb(dev
->isobufs
[i
].urb
);
596 urb
= dev
->isobufs
[i
].urb
;
600 urb
->pipe
= usb_rcvisocpipe(udev
, dev
->isoc_ep
);
601 urb
->transfer_flags
= URB_ISO_ASAP
;
602 urb
->transfer_buffer
= dev
->isobufs
[i
].data
;
603 urb
->transfer_buffer_length
= ISO_BUFFER_SIZE
;
604 urb
->complete
= stk_isoc_handler
;
606 urb
->start_frame
= 0;
607 urb
->number_of_packets
= ISO_FRAMES_PER_DESC
;
609 for (j
=0; j
<ISO_FRAMES_PER_DESC
; j
++) {
610 urb
->iso_frame_desc
[j
].offset
= j
* ISO_MAX_FRAME_SIZE
;
611 urb
->iso_frame_desc
[j
].length
= ISO_MAX_FRAME_SIZE
;
618 for (i
=0; i
<MAX_ISO_BUFS
&& dev
->isobufs
[i
].data
; i
++)
619 kfree(dev
->isobufs
[i
].data
);
620 for (i
=0; i
<MAX_ISO_BUFS
&& dev
->isobufs
[i
].urb
; i
++)
621 usb_free_urb(dev
->isobufs
[i
].urb
);
627 static void stk_clean_iso(struct stk_camera
*dev
)
631 if (dev
== NULL
|| dev
->isobufs
== NULL
)
634 // Unlinking ISOC buffers
635 for (i
=0; i
<MAX_ISO_BUFS
; i
++) {
638 urb
= dev
->isobufs
[i
].urb
;
640 if (atomic_read(&dev
->urbs_used
))
643 STK_DEBUG("URBS already unlinked\n");
646 if (dev
->isobufs
[i
].data
)
647 kfree(dev
->isobufs
[i
].data
);
651 unset_memallocd(dev
);
654 static int stk_setup_siobuf(struct stk_camera
*dev
, int index
)
656 struct stk_sio_buffer
*buf
= dev
->sio_bufs
+ index
;
657 INIT_LIST_HEAD(&buf
->list
);
658 buf
->v4lbuf
.length
= PAGE_ALIGN(dev
->frame_size
);
659 buf
->buffer
= vmalloc_user(buf
->v4lbuf
.length
);
660 if (buf
->buffer
== NULL
)
664 buf
->v4lbuf
.index
= index
;
665 buf
->v4lbuf
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
666 buf
->v4lbuf
.field
= V4L2_FIELD_NONE
;
667 buf
->v4lbuf
.memory
= V4L2_MEMORY_MMAP
;
668 buf
->v4lbuf
.m
.offset
= 2*index
*buf
->v4lbuf
.length
;
672 static int stk_free_sio_buffers(struct stk_camera
*dev
)
677 if (dev
->n_sbufs
== 0 || dev
->sio_bufs
== NULL
)
680 * If any buffers are mapped, we cannot free them at all.
682 for (i
= 0; i
< dev
->n_sbufs
; i
++) {
683 if (dev
->sio_bufs
[i
].mapcount
> 0) {
690 spin_lock_irqsave(&dev
->spinlock
, flags
);
691 INIT_LIST_HEAD(&dev
->sio_avail
);
692 INIT_LIST_HEAD(&dev
->sio_full
);
693 nbufs
= dev
->n_sbufs
;
695 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
696 for (i
= 0; i
< nbufs
; i
++) {
697 if (dev
->sio_bufs
[i
].buffer
!= NULL
)
698 vfree(dev
->sio_bufs
[i
].buffer
);
700 kfree(dev
->sio_bufs
);
701 dev
->sio_bufs
= NULL
;
705 static int stk_prepare_sio_buffers(struct stk_camera
*dev
, unsigned n_sbufs
)
708 if (dev
->sio_bufs
!= NULL
) {
709 STK_ERROR("sio_bufs already allocated\n");
712 dev
->sio_bufs
= kzalloc(n_sbufs
* sizeof(struct stk_sio_buffer
),
714 if (dev
->sio_bufs
== NULL
)
716 for (i
=0; i
< n_sbufs
; i
++) {
717 if (stk_setup_siobuf(dev
, i
))
718 return (dev
->n_sbufs
> 1)? 0 : -ENOMEM
;
725 static int stk_allocate_buffers(struct stk_camera
*dev
, unsigned n_sbufs
)
728 err
= stk_prepare_iso(dev
);
733 err
= stk_prepare_sio_buffers(dev
, n_sbufs
);
735 stk_free_sio_buffers(dev
);
741 static void stk_free_buffers(struct stk_camera
*dev
)
744 stk_free_sio_buffers(dev
);
746 /* -------------------------------------------- */
748 /* v4l file operations */
750 static int v4l_stk_open(struct inode
*inode
, struct file
*fp
)
752 struct stk_camera
*dev
;
753 struct video_device
*vdev
;
755 vdev
= video_devdata(fp
);
756 dev
= vdev_to_camera(vdev
);
758 if (dev
== NULL
|| !is_present(dev
))
760 fp
->private_data
= vdev
;
761 kref_get(&dev
->kref
);
762 usb_autopm_get_interface(dev
->interface
);
767 static int v4l_stk_release(struct inode
*inode
, struct file
*fp
)
769 struct stk_camera
*dev
;
770 struct video_device
*vdev
;
772 vdev
= video_devdata(fp
);
774 STK_ERROR("v4l_release called w/o video devdata\n");
777 dev
= vdev_to_camera(vdev
);
779 STK_ERROR("v4l_release called on removed device\n");
783 if (dev
->owner
!= fp
) {
784 usb_autopm_put_interface(dev
->interface
);
785 kref_put(&dev
->kref
, stk_camera_cleanup
);
789 // Stop the video stream
790 stk_stop_stream(dev
);
792 stk_free_buffers(dev
);
796 usb_autopm_put_interface(dev
->interface
);
797 kref_put(&dev
->kref
, stk_camera_cleanup
);
802 static ssize_t
v4l_stk_read(struct file
*fp
, char __user
*buf
,
803 size_t count
, loff_t
*f_pos
)
808 struct stk_camera
*dev
;
809 struct video_device
*vdev
;
810 struct stk_sio_buffer
*sbuf
;
812 vdev
= video_devdata(fp
);
815 dev
= vdev_to_camera(vdev
);
820 if (!is_present(dev
))
822 if (dev
->owner
&& dev
->owner
!= fp
)
825 if (!is_streaming(dev
)) {
826 if (stk_initialise(dev
)
827 || stk_allocate_buffers(dev
, 3)
828 || stk_start_stream(dev
))
830 spin_lock_irqsave(&dev
->spinlock
, flags
);
831 for (i
= 0; i
< dev
->n_sbufs
; i
++) {
832 list_add_tail(&dev
->sio_bufs
[i
].list
, &dev
->sio_avail
);
833 dev
->sio_bufs
[i
].v4lbuf
.flags
= V4L2_BUF_FLAG_QUEUED
;
835 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
838 if (fp
->f_flags
& O_NONBLOCK
&& list_empty(&dev
->sio_full
))
840 ret
= wait_event_interruptible(dev
->wait_frame
,
841 !list_empty(&dev
->sio_full
) || !is_present(dev
));
844 if (!is_present(dev
))
847 if (count
+ *f_pos
> dev
->frame_size
)
848 count
= dev
->frame_size
- *f_pos
;
849 spin_lock_irqsave(&dev
->spinlock
, flags
);
850 if (list_empty(&dev
->sio_full
)) {
851 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
852 STK_ERROR("BUG: No siobufs ready\n");
855 sbuf
= list_first_entry(&dev
->sio_full
, struct stk_sio_buffer
, list
);
856 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
858 if (copy_to_user(buf
, sbuf
->buffer
+ *f_pos
, count
))
863 if (*f_pos
>= dev
->frame_size
) {
865 spin_lock_irqsave(&dev
->spinlock
, flags
);
866 list_move_tail(&sbuf
->list
, &dev
->sio_avail
);
867 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
872 static unsigned int v4l_stk_poll(struct file
*fp
, poll_table
*wait
)
874 struct stk_camera
*dev
;
875 struct video_device
*vdev
;
877 vdev
= video_devdata(fp
);
882 dev
= vdev_to_camera(vdev
);
886 poll_wait(fp
, &dev
->wait_frame
, wait
);
888 if (!is_present(dev
))
891 if (!list_empty(&dev
->sio_full
))
892 return (POLLIN
| POLLRDNORM
);
898 static void stk_v4l_vm_open(struct vm_area_struct
*vma
)
900 struct stk_sio_buffer
*sbuf
= vma
->vm_private_data
;
903 static void stk_v4l_vm_close(struct vm_area_struct
*vma
)
905 struct stk_sio_buffer
*sbuf
= vma
->vm_private_data
;
907 if (sbuf
->mapcount
== 0)
908 sbuf
->v4lbuf
.flags
&= ~V4L2_BUF_FLAG_MAPPED
;
910 static struct vm_operations_struct stk_v4l_vm_ops
= {
911 .open
= stk_v4l_vm_open
,
912 .close
= stk_v4l_vm_close
915 static int v4l_stk_mmap(struct file
*fp
, struct vm_area_struct
*vma
)
919 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
920 struct stk_camera
*dev
;
921 struct video_device
*vdev
;
922 struct stk_sio_buffer
*sbuf
= NULL
;
924 if (!(vma
->vm_flags
& VM_WRITE
) || !(vma
->vm_flags
& VM_SHARED
))
927 vdev
= video_devdata(fp
);
928 dev
= vdev_to_camera(vdev
);
930 for (i
=0; i
< dev
->n_sbufs
; i
++) {
931 if (dev
->sio_bufs
[i
].v4lbuf
.m
.offset
== offset
) {
932 sbuf
= dev
->sio_bufs
+ i
;
938 ret
= remap_vmalloc_range(vma
, sbuf
->buffer
, 0);
941 vma
->vm_flags
|= VM_DONTEXPAND
;
942 vma
->vm_private_data
= sbuf
;
943 vma
->vm_ops
= &stk_v4l_vm_ops
;
944 sbuf
->v4lbuf
.flags
|= V4L2_BUF_FLAG_MAPPED
;
945 stk_v4l_vm_open(vma
);
949 /* v4l ioctl handlers */
952 /* From videodev.c *****************************************
953 Handles calls to the obsoleted V4L1 API
954 Due to the nature of VIDIOCGMBUF, each driver that supports
955 V4L1 should implement its own handler for this ioctl.
956 ***********************************************************/
957 static int stk_vidiocgmbuf(struct file
*filp
,
958 void *priv
, struct video_mbuf
*vm
)
961 struct stk_camera
*dev
= priv
;
963 memset(vm
, 0, sizeof(*vm
));
965 vm
->size
= dev
->n_sbufs
* dev
->image_size
;
966 vm
->frames
= dev
->n_sbufs
;
968 for (i
=0; i
<dev
->n_sbufs
; i
++)
969 vm
->offsets
[i
] = i
* dev
->image_size
;
975 static int stk_vidioc_querycap(struct file
*filp
,
976 void *priv
, struct v4l2_capability
*cap
)
978 strcpy(cap
->driver
, "stk");
979 strcpy(cap
->card
, "stk");
980 cap
->version
= DRIVER_VERSION_NUM
;
982 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
983 | V4L2_CAP_READWRITE
| V4L2_CAP_STREAMING
;
987 static int stk_vidioc_enum_input(struct file
*filp
,
988 void *priv
, struct v4l2_input
*input
)
990 if (input
->index
!= 0)
993 strcpy(input
->name
, "Syntek USB Camera");
994 input
->type
= V4L2_INPUT_TYPE_CAMERA
;
999 static int stk_vidioc_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
1006 static int stk_vidioc_s_input(struct file
*filp
, void *priv
, unsigned int i
)
1015 static int stk_vidioc_s_std(struct file
*filp
, void *priv
, v4l2_std_id
*a
)
1020 /* List of all V4Lv2 controls supported by the driver */
1021 static struct v4l2_queryctrl stk_controls
[] = {
1023 .id
= V4L2_CID_BRIGHTNESS
,
1024 .type
= V4L2_CTRL_TYPE_INTEGER
,
1025 .name
= "Brightness",
1029 .default_value
= 0x6000,
1031 /*TODO: get more controls to work */
1034 static int stk_vidioc_queryctrl(struct file
*filp
,
1035 void *priv
, struct v4l2_queryctrl
*c
)
1039 nbr
= ARRAY_SIZE(stk_controls
);
1041 for (i
=0; i
<nbr
; i
++) {
1042 if (stk_controls
[i
].id
== c
->id
) {
1043 STK_DEBUG("VIDIOC_QUERYCTRL found\n");
1044 memcpy(c
, &stk_controls
[i
],
1045 sizeof(struct v4l2_queryctrl
));
1052 static int stk_vidioc_g_ctrl(struct file
*filp
,
1053 void *priv
, struct v4l2_control
*c
)
1055 struct stk_camera
*dev
= priv
;
1057 case V4L2_CID_BRIGHTNESS
:
1058 c
->value
= dev
->vsettings
.brightness
;
1066 static int stk_vidioc_s_ctrl(struct file
*filp
,
1067 void *priv
, struct v4l2_control
*c
)
1069 struct stk_camera
*dev
= priv
;
1071 case V4L2_CID_BRIGHTNESS
:
1072 dev
->vsettings
.brightness
= c
->value
;
1073 return stk_sensor_set_brightness(dev
, c
->value
>> 8);
1081 static int stk_vidioc_enum_fmt_cap(struct file
*filp
,
1082 void *priv
, struct v4l2_fmtdesc
*fmtd
)
1086 switch (fmtd
->index
) {
1088 fmtd
->pixelformat
= V4L2_PIX_FMT_RGB565
;
1089 strcpy(fmtd
->description
, "r5g6b5");
1092 fmtd
->pixelformat
= V4L2_PIX_FMT_RGB565X
;
1093 strcpy(fmtd
->description
, "r5g6b5BE");
1096 fmtd
->pixelformat
= V4L2_PIX_FMT_UYVY
;
1097 strcpy(fmtd
->description
, "yuv4:2:2");
1100 fmtd
->pixelformat
= V4L2_PIX_FMT_SBGGR8
;
1101 strcpy(fmtd
->description
, "Raw bayer");
1104 fmtd
->pixelformat
= V4L2_PIX_FMT_YUYV
;
1105 strcpy(fmtd
->description
, "yuv4:2:2");
1113 static struct stk_size
{
1118 { .w
= 1280, .h
= 1024, .m
= MODE_SXGA
, },
1119 { .w
= 640, .h
= 480, .m
= MODE_VGA
, },
1120 { .w
= 352, .h
= 288, .m
= MODE_CIF
, },
1121 { .w
= 320, .h
= 240, .m
= MODE_QVGA
, },
1122 { .w
= 176, .h
= 144, .m
= MODE_QCIF
, },
1125 static int stk_vidioc_g_fmt_cap(struct file
*filp
,
1126 void *priv
, struct v4l2_format
*f
)
1128 struct v4l2_pix_format
*pix_format
= &f
->fmt
.pix
;
1129 struct stk_camera
*dev
= priv
;
1132 for (i
= 0; i
< ARRAY_SIZE(stk_sizes
)
1133 && stk_sizes
[i
].m
!= dev
->vsettings
.mode
;
1135 if (i
== ARRAY_SIZE(stk_sizes
)) {
1136 STK_ERROR("ERROR: mode invalid\n");
1139 pix_format
->width
= stk_sizes
[i
].w
;
1140 pix_format
->height
= stk_sizes
[i
].h
;
1141 pix_format
->field
= V4L2_FIELD_NONE
;
1142 pix_format
->colorspace
= V4L2_COLORSPACE_SRGB
;
1143 pix_format
->priv
= 0;
1144 pix_format
->pixelformat
= dev
->vsettings
.palette
;
1145 if (dev
->vsettings
.palette
== V4L2_PIX_FMT_SBGGR8
)
1146 pix_format
->bytesperline
= pix_format
->width
;
1148 pix_format
->bytesperline
= 2 * pix_format
->width
;
1149 pix_format
->sizeimage
= pix_format
->bytesperline
1150 * pix_format
->height
;
1154 static int stk_vidioc_try_fmt_cap(struct file
*filp
,
1155 void *priv
, struct v4l2_format
*fmtd
)
1158 switch (fmtd
->fmt
.pix
.pixelformat
) {
1159 case V4L2_PIX_FMT_RGB565
:
1160 case V4L2_PIX_FMT_RGB565X
:
1161 case V4L2_PIX_FMT_UYVY
:
1162 case V4L2_PIX_FMT_YUYV
:
1163 case V4L2_PIX_FMT_SBGGR8
:
1168 for (i
= 1; i
< ARRAY_SIZE(stk_sizes
); i
++) {
1169 if (fmtd
->fmt
.pix
.width
> stk_sizes
[i
].w
)
1172 if (i
== ARRAY_SIZE(stk_sizes
)
1173 || (abs(fmtd
->fmt
.pix
.width
- stk_sizes
[i
-1].w
)
1174 < abs(fmtd
->fmt
.pix
.width
- stk_sizes
[i
].w
))) {
1175 fmtd
->fmt
.pix
.height
= stk_sizes
[i
-1].h
;
1176 fmtd
->fmt
.pix
.width
= stk_sizes
[i
-1].w
;
1177 fmtd
->fmt
.pix
.priv
= i
- 1;
1179 fmtd
->fmt
.pix
.height
= stk_sizes
[i
].h
;
1180 fmtd
->fmt
.pix
.width
= stk_sizes
[i
].w
;
1181 fmtd
->fmt
.pix
.priv
= i
;
1184 fmtd
->fmt
.pix
.field
= V4L2_FIELD_NONE
;
1185 fmtd
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SRGB
;
1186 if (fmtd
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_SBGGR8
)
1187 fmtd
->fmt
.pix
.bytesperline
= fmtd
->fmt
.pix
.width
;
1189 fmtd
->fmt
.pix
.bytesperline
= 2 * fmtd
->fmt
.pix
.width
;
1190 fmtd
->fmt
.pix
.sizeimage
= fmtd
->fmt
.pix
.bytesperline
1191 * fmtd
->fmt
.pix
.height
;
1195 static int stk_setup_format(struct stk_camera
*dev
)
1199 if (dev
->vsettings
.palette
== V4L2_PIX_FMT_SBGGR8
)
1203 while (stk_sizes
[i
].m
!= dev
->vsettings
.mode
1204 && i
< ARRAY_SIZE(stk_sizes
))
1206 if (i
== ARRAY_SIZE(stk_sizes
)) {
1207 STK_ERROR("Something is broken in %s\n", __FUNCTION__
);
1210 /* This registers controls some timings, not sure of what. */
1211 stk_camera_write_reg(dev
, 0x001b, 0x0e);
1212 if (dev
->vsettings
.mode
== MODE_SXGA
)
1213 stk_camera_write_reg(dev
, 0x001c, 0x0e);
1215 stk_camera_write_reg(dev
, 0x001c, 0x46);
1217 * Registers 0x0115 0x0114 are the size of each line (bytes),
1218 * regs 0x0117 0x0116 are the heigth of the image.
1220 stk_camera_write_reg(dev
, 0x0115,
1221 ((stk_sizes
[i
].w
* depth
) >> 8) & 0xff);
1222 stk_camera_write_reg(dev
, 0x0114,
1223 (stk_sizes
[i
].w
* depth
) & 0xff);
1224 stk_camera_write_reg(dev
, 0x0117,
1225 (stk_sizes
[i
].h
>> 8) & 0xff);
1226 stk_camera_write_reg(dev
, 0x0116,
1227 stk_sizes
[i
].h
& 0xff);
1228 return stk_sensor_configure(dev
);
1231 static int stk_vidioc_s_fmt_cap(struct file
*filp
,
1232 void *priv
, struct v4l2_format
*fmtd
)
1235 struct stk_camera
*dev
= priv
;
1239 if (!is_present(dev
))
1241 if (is_streaming(dev
))
1243 if (dev
->owner
&& dev
->owner
!= filp
)
1245 ret
= stk_vidioc_try_fmt_cap(filp
, priv
, fmtd
);
1250 dev
->vsettings
.palette
= fmtd
->fmt
.pix
.pixelformat
;
1251 stk_free_buffers(dev
);
1252 dev
->frame_size
= fmtd
->fmt
.pix
.sizeimage
;
1253 dev
->vsettings
.mode
= stk_sizes
[fmtd
->fmt
.pix
.priv
].m
;
1255 // Select the new video mode
1256 stk_initialise(dev
);
1257 return stk_setup_format(dev
);
1260 static int stk_vidioc_reqbufs(struct file
*filp
,
1261 void *priv
, struct v4l2_requestbuffers
*rb
)
1263 struct stk_camera
*dev
= priv
;
1267 if (rb
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1269 if (rb
->memory
!= V4L2_MEMORY_MMAP
)
1271 if (is_streaming(dev
)
1272 || (dev
->owner
&& dev
->owner
!= filp
))
1276 /*FIXME If they ask for zero, we must stop streaming and free */
1279 /* Arbitrary limit */
1280 else if (rb
->count
> 5)
1283 stk_allocate_buffers(dev
, rb
->count
);
1284 rb
->count
= dev
->n_sbufs
;
1288 static int stk_vidioc_querybuf(struct file
*filp
,
1289 void *priv
, struct v4l2_buffer
*buf
)
1292 struct stk_camera
*dev
= priv
;
1293 struct stk_sio_buffer
*sbuf
;
1295 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1300 if (index
< 0 || index
>= dev
->n_sbufs
)
1302 sbuf
= dev
->sio_bufs
+ buf
->index
;
1303 *buf
= sbuf
->v4lbuf
;
1307 static int stk_vidioc_qbuf(struct file
*filp
,
1308 void *priv
, struct v4l2_buffer
*buf
)
1310 struct stk_camera
*dev
= priv
;
1311 struct stk_sio_buffer
*sbuf
;
1312 unsigned long flags
;
1313 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1316 if (buf
->memory
!= V4L2_MEMORY_MMAP
)
1319 if (buf
->index
< 0 || buf
->index
>= dev
->n_sbufs
)
1321 sbuf
= dev
->sio_bufs
+ buf
->index
;
1322 if (sbuf
->v4lbuf
.flags
& V4L2_BUF_FLAG_QUEUED
) {
1325 sbuf
->v4lbuf
.flags
|= V4L2_BUF_FLAG_QUEUED
;
1326 sbuf
->v4lbuf
.flags
&= ~V4L2_BUF_FLAG_DONE
;
1327 spin_lock_irqsave(&dev
->spinlock
, flags
);
1328 list_add_tail(&sbuf
->list
, &dev
->sio_avail
);
1329 *buf
= sbuf
->v4lbuf
;
1330 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1334 static int stk_vidioc_dqbuf(struct file
*filp
,
1335 void *priv
, struct v4l2_buffer
*buf
)
1337 struct stk_camera
*dev
= priv
;
1338 struct stk_sio_buffer
*sbuf
;
1339 unsigned long flags
;
1342 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
1343 || !is_streaming(dev
))
1346 if (filp
->f_flags
& O_NONBLOCK
&& list_empty(&dev
->sio_full
))
1347 return -EWOULDBLOCK
;
1348 ret
= wait_event_interruptible(dev
->wait_frame
,
1349 !list_empty(&dev
->sio_full
) || !is_present(dev
));
1352 if (!is_present(dev
))
1355 spin_lock_irqsave(&dev
->spinlock
, flags
);
1356 sbuf
= list_first_entry(&dev
->sio_full
, struct stk_sio_buffer
, list
);
1357 list_del_init(&sbuf
->list
);
1358 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1359 sbuf
->v4lbuf
.flags
&= ~V4L2_BUF_FLAG_QUEUED
;
1360 sbuf
->v4lbuf
.flags
|= V4L2_BUF_FLAG_DONE
;
1361 sbuf
->v4lbuf
.sequence
= ++dev
->sequence
;
1362 do_gettimeofday(&sbuf
->v4lbuf
.timestamp
);
1364 *buf
= sbuf
->v4lbuf
;
1368 static int stk_vidioc_streamon(struct file
*filp
,
1369 void *priv
, enum v4l2_buf_type type
)
1371 struct stk_camera
*dev
= priv
;
1372 if (is_streaming(dev
))
1374 if (dev
->sio_bufs
== NULL
)
1377 return stk_start_stream(dev
);
1380 static int stk_vidioc_streamoff(struct file
*filp
,
1381 void *priv
, enum v4l2_buf_type type
)
1383 struct stk_camera
*dev
= priv
;
1384 unsigned long flags
;
1386 stk_stop_stream(dev
);
1387 spin_lock_irqsave(&dev
->spinlock
, flags
);
1388 INIT_LIST_HEAD(&dev
->sio_avail
);
1389 INIT_LIST_HEAD(&dev
->sio_full
);
1390 for (i
=0; i
<dev
->n_sbufs
; i
++) {
1391 INIT_LIST_HEAD(&dev
->sio_bufs
[i
].list
);
1392 dev
->sio_bufs
[i
].v4lbuf
.flags
= 0;
1394 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1399 static int stk_vidioc_g_parm(struct file
*filp
,
1400 void *priv
, struct v4l2_streamparm
*sp
)
1402 if (sp
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1405 sp
->parm
.capture
.capability
= 0;
1406 sp
->parm
.capture
.capturemode
= 0;
1407 /*FIXME This is not correct */
1408 sp
->parm
.capture
.timeperframe
.numerator
= 1;
1409 sp
->parm
.capture
.timeperframe
.denominator
= 30;
1410 sp
->parm
.capture
.readbuffers
= 2;
1411 sp
->parm
.capture
.extendedmode
= 0;
1415 static struct file_operations v4l_stk_fops
= {
1416 .owner
= THIS_MODULE
,
1417 .open
= v4l_stk_open
,
1418 .release
= v4l_stk_release
,
1419 .read
= v4l_stk_read
,
1420 .poll
= v4l_stk_poll
,
1421 .mmap
= v4l_stk_mmap
,
1422 .ioctl
= video_ioctl2
,
1423 #ifdef CONFIG_COMPAT
1424 .compat_ioctl
= v4l_compat_ioctl32
,
1429 static void stk_v4l_dev_release(struct video_device
*vd
)
1433 static struct video_device stk_v4l_data
= {
1434 .name
= "stkwebcam",
1435 .type
= VFL_TYPE_GRABBER
,
1436 .type2
= VID_TYPE_CAPTURE
,
1438 .tvnorms
= V4L2_STD_UNKNOWN
,
1439 .current_norm
= V4L2_STD_UNKNOWN
,
1440 .fops
= &v4l_stk_fops
,
1441 .release
= stk_v4l_dev_release
,
1442 // .vidiocgmbuf = stk_vidiocgmbuf,
1444 .vidioc_querycap
= stk_vidioc_querycap
,
1445 .vidioc_enum_fmt_cap
= stk_vidioc_enum_fmt_cap
,
1446 .vidioc_try_fmt_cap
= stk_vidioc_try_fmt_cap
,
1447 .vidioc_s_fmt_cap
= stk_vidioc_s_fmt_cap
,
1448 .vidioc_g_fmt_cap
= stk_vidioc_g_fmt_cap
,
1449 .vidioc_enum_input
= stk_vidioc_enum_input
,
1450 .vidioc_s_input
= stk_vidioc_s_input
,
1451 .vidioc_g_input
= stk_vidioc_g_input
,
1452 .vidioc_s_std
= stk_vidioc_s_std
,
1453 .vidioc_reqbufs
= stk_vidioc_reqbufs
,
1454 .vidioc_querybuf
= stk_vidioc_querybuf
,
1455 .vidioc_qbuf
= stk_vidioc_qbuf
,
1456 .vidioc_dqbuf
= stk_vidioc_dqbuf
,
1457 .vidioc_streamon
= stk_vidioc_streamon
,
1458 .vidioc_streamoff
= stk_vidioc_streamoff
,
1459 .vidioc_queryctrl
= stk_vidioc_queryctrl
,
1460 .vidioc_g_ctrl
= stk_vidioc_g_ctrl
,
1461 .vidioc_s_ctrl
= stk_vidioc_s_ctrl
,
1462 .vidioc_g_parm
= stk_vidioc_g_parm
,
1466 static int stk_register_video_device(struct stk_camera
*dev
)
1470 dev
->vdev
= stk_v4l_data
;
1471 dev
->vdev
.debug
= debug
;
1472 dev
->vdev
.dev
= &dev
->interface
->dev
;
1473 dev
->vdev
.priv
= dev
;
1474 err
= video_register_device(&dev
->vdev
, VFL_TYPE_GRABBER
, -1);
1476 STK_ERROR("v4l registration failed\n");
1478 STK_INFO("Syntek USB2.0 Camera is now controlling video device"
1479 " /dev/video%d\n", dev
->vdev
.minor
);
1486 static int stk_camera_probe(struct usb_interface
*interface
,
1487 const struct usb_device_id
*id
)
1492 struct stk_camera
*dev
= NULL
;
1493 struct usb_device
*udev
= interface_to_usbdev(interface
);
1494 struct usb_host_interface
*iface_desc
;
1495 struct usb_endpoint_descriptor
*endpoint
;
1497 dev
= kzalloc(sizeof(struct stk_camera
), GFP_KERNEL
);
1499 STK_ERROR("Out of memory !\n");
1503 kref_init(&dev
->kref
);
1504 spin_lock_init(&dev
->spinlock
);
1505 init_waitqueue_head(&dev
->wait_frame
);
1508 dev
->interface
= interface
;
1509 usb_get_intf(interface
);
1511 dev
->vsettings
.vflip
= vflip
;
1512 dev
->vsettings
.hflip
= hflip
;
1516 /* Set up the endpoint information
1517 * use only the first isoc-in endpoint
1518 * for the current alternate setting */
1519 iface_desc
= interface
->cur_altsetting
;
1521 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
1522 endpoint
= &iface_desc
->endpoint
[i
].desc
;
1525 && ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == USB_DIR_IN
)
1526 && ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) == USB_ENDPOINT_XFER_ISOC
)) {
1527 /* we found an isoc in endpoint */
1528 dev
->isoc_ep
= (endpoint
->bEndpointAddress
& 0xF);
1532 if (!dev
->isoc_ep
) {
1533 STK_ERROR("Could not find isoc-in endpoint");
1534 kref_put(&dev
->kref
, stk_camera_cleanup
);
1538 dev
->vsettings
.brightness
= 0x7fff;
1539 dev
->vsettings
.palette
= V4L2_PIX_FMT_RGB565
;
1540 dev
->vsettings
.mode
= MODE_VGA
;
1541 dev
->frame_size
= 640*480*2;
1543 INIT_LIST_HEAD(&dev
->sio_avail
);
1544 INIT_LIST_HEAD(&dev
->sio_full
);
1546 usb_set_intfdata(interface
, dev
);
1548 err
= stk_register_video_device(dev
);
1550 kref_put(&dev
->kref
, stk_camera_cleanup
);
1554 stk_create_sysfs_files(&dev
->vdev
);
1555 usb_autopm_enable(dev
->interface
);
1560 static void stk_camera_disconnect(struct usb_interface
*interface
)
1562 struct stk_camera
*dev
= usb_get_intfdata(interface
);
1564 usb_set_intfdata(interface
, NULL
);
1567 // Alert waiting processes
1568 wake_up_interruptible(&dev
->wait_frame
);
1569 // Remove the entries in the sys filesystem
1570 stk_remove_sysfs_files(&dev
->vdev
);
1572 // Decrement kernel reference
1573 kref_put(&dev
->kref
, stk_camera_cleanup
);
1577 int stk_camera_suspend(struct usb_interface
*intf
, pm_message_t message
)
1579 struct stk_camera
*dev
= usb_get_intfdata(intf
);
1580 if (is_streaming(dev
)) {
1581 stk_stop_stream(dev
);
1582 /* yes, this is ugly */
1588 int stk_camera_resume(struct usb_interface
*intf
)
1590 struct stk_camera
*dev
= usb_get_intfdata(intf
);
1591 if (!is_initialised(dev
))
1593 unset_initialised(dev
);
1594 stk_initialise(dev
);
1595 stk_setup_format(dev
);
1596 if (is_streaming(dev
))
1597 stk_start_stream(dev
);
1602 static struct usb_driver stk_camera_driver
= {
1603 .name
= "stkwebcam",
1604 .probe
= stk_camera_probe
,
1605 .disconnect
= stk_camera_disconnect
,
1606 .id_table
= stkwebcam_table
,
1608 .suspend
= stk_camera_suspend
,
1609 .resume
= stk_camera_resume
,
1614 static int __init
stk_camera_init(void)
1618 result
= usb_register(&stk_camera_driver
);
1620 STK_ERROR("usb_register failed ! Error number %d\n", result
);
1626 static void __exit
stk_camera_exit(void)
1628 usb_deregister(&stk_camera_driver
);
1631 module_init(stk_camera_init
);
1632 module_exit(stk_camera_exit
);