2 * stk-webcam.c : Driver for Syntek 1125 USB webcam controller
4 * Copyright (C) 2006 Nicolas VIVIEN
5 * Copyright 2007-2008 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/vmalloc.h>
34 #include <linux/videodev2.h>
35 #include <media/v4l2-common.h>
37 #include "stk-webcam.h"
41 module_param(hflip
, bool, 0444);
42 MODULE_PARM_DESC(hflip
, "Horizontal image flip (mirror). Defaults to 1");
45 module_param(vflip
, bool, 0444);
46 MODULE_PARM_DESC(vflip
, "Vertical image flip. Defaults to 1");
49 module_param(debug
, int, 0444);
50 MODULE_PARM_DESC(debug
, "Debug v4l ioctls. Defaults to 0");
52 MODULE_LICENSE("GPL");
53 MODULE_AUTHOR("Jaime Velasco Juan <jsagarribay@gmail.com> and Nicolas VIVIEN");
54 MODULE_DESCRIPTION("Syntek DC1125 webcam driver");
58 /* Some cameras have audio interfaces, we aren't interested in those */
59 static struct usb_device_id stkwebcam_table
[] = {
60 { USB_DEVICE_AND_INTERFACE_INFO(0x174f, 0xa311, 0xff, 0xff, 0xff) },
61 { USB_DEVICE_AND_INTERFACE_INFO(0x05e1, 0x0501, 0xff, 0xff, 0xff) },
64 MODULE_DEVICE_TABLE(usb
, stkwebcam_table
);
66 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
67 void stk_camera_cleanup(struct kref
*kref
)
69 static void stk_camera_cleanup(struct kref
*kref
)
70 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
72 struct stk_camera
*dev
= to_stk_camera(kref
);
74 STK_INFO("Syntek USB2.0 Camera release resources"
75 " video device /dev/video%d\n", dev
->vdev
.minor
);
76 video_unregister_device(&dev
->vdev
);
77 dev
->vdev
.priv
= NULL
;
79 if (dev
->sio_bufs
!= NULL
|| dev
->isobufs
!= NULL
)
80 STK_ERROR("We are leaking memory\n");
81 usb_put_intf(dev
->interface
);
89 int stk_camera_write_reg(struct stk_camera
*dev
, u16 index
, u8 value
)
91 struct usb_device
*udev
= dev
->udev
;
94 ret
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
96 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
108 int stk_camera_read_reg(struct stk_camera
*dev
, u16 index
, int *value
)
110 struct usb_device
*udev
= dev
->udev
;
113 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
115 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
127 static int stk_start_stream(struct stk_camera
*dev
)
131 int value_116
, value_117
;
133 if (!is_present(dev
))
135 if (!is_memallocd(dev
) || !is_initialised(dev
)) {
136 STK_ERROR("FIXME: Buffers are not allocated\n");
139 ret
= usb_set_interface(dev
->udev
, 0, 5);
142 STK_ERROR("usb_set_interface failed !\n");
143 if (stk_sensor_wakeup(dev
))
144 STK_ERROR("error awaking the sensor\n");
146 stk_camera_read_reg(dev
, 0x0116, &value_116
);
147 stk_camera_read_reg(dev
, 0x0117, &value_117
);
149 stk_camera_write_reg(dev
, 0x0116, 0x0000);
150 stk_camera_write_reg(dev
, 0x0117, 0x0000);
152 stk_camera_read_reg(dev
, 0x0100, &value
);
153 stk_camera_write_reg(dev
, 0x0100, value
| 0x80);
155 stk_camera_write_reg(dev
, 0x0116, value_116
);
156 stk_camera_write_reg(dev
, 0x0117, value_117
);
157 for (i
= 0; i
< MAX_ISO_BUFS
; i
++) {
158 if (dev
->isobufs
[i
].urb
) {
159 ret
= usb_submit_urb(dev
->isobufs
[i
].urb
, GFP_KERNEL
);
160 atomic_inc(&dev
->urbs_used
);
169 static int stk_stop_stream(struct stk_camera
*dev
)
173 if (is_present(dev
)) {
174 stk_camera_read_reg(dev
, 0x0100, &value
);
175 stk_camera_write_reg(dev
, 0x0100, value
& ~0x80);
176 if (dev
->isobufs
!= NULL
) {
177 for (i
= 0; i
< MAX_ISO_BUFS
; i
++) {
178 if (dev
->isobufs
[i
].urb
)
179 usb_kill_urb(dev
->isobufs
[i
].urb
);
182 unset_streaming(dev
);
184 if (usb_set_interface(dev
->udev
, 0, 0))
185 STK_ERROR("usb_set_interface failed !\n");
186 if (stk_sensor_sleep(dev
))
187 STK_ERROR("error suspending the sensor\n");
193 * This seems to be the shortest init sequence we
194 * must do in order to find the sensor
195 * Bit 5 of reg. 0x0000 here is important, when reset to 0 the sensor
196 * is also reset. Maybe powers down it?
197 * Rest of values don't make a difference
200 static struct regval stk1125_initvals
[] = {
201 /*TODO: What means this sequence? */
230 static int stk_initialise(struct stk_camera
*dev
)
234 if (!is_present(dev
))
236 if (is_initialised(dev
))
238 rv
= stk1125_initvals
;
239 while (rv
->reg
!= 0xffff) {
240 ret
= stk_camera_write_reg(dev
, rv
->reg
, rv
->val
);
245 if (stk_sensor_init(dev
) == 0) {
246 set_initialised(dev
);
252 /* sysfs functions */
253 /*FIXME cleanup this */
255 static ssize_t
show_brightness(struct device
*class,
256 struct device_attribute
*attr
, char *buf
)
258 struct video_device
*vdev
= to_video_device(class);
259 struct stk_camera
*dev
= vdev_to_camera(vdev
);
261 return sprintf(buf
, "%X\n", dev
->vsettings
.brightness
);
264 static ssize_t
store_brightness(struct device
*class,
265 struct device_attribute
*attr
, const char *buf
, size_t count
)
271 struct video_device
*vdev
= to_video_device(class);
272 struct stk_camera
*dev
= vdev_to_camera(vdev
);
274 value
= simple_strtoul(buf
, &endp
, 16);
276 dev
->vsettings
.brightness
= (int) value
;
278 ret
= stk_sensor_set_brightness(dev
, value
>> 8);
285 static ssize_t
show_hflip(struct device
*class,
286 struct device_attribute
*attr
, char *buf
)
288 struct video_device
*vdev
= to_video_device(class);
289 struct stk_camera
*dev
= vdev_to_camera(vdev
);
291 return sprintf(buf
, "%d\n", dev
->vsettings
.hflip
);
294 static ssize_t
store_hflip(struct device
*class,
295 struct device_attribute
*attr
, const char *buf
, size_t count
)
297 struct video_device
*vdev
= to_video_device(class);
298 struct stk_camera
*dev
= vdev_to_camera(vdev
);
300 if (strncmp(buf
, "1", 1) == 0)
301 dev
->vsettings
.hflip
= 1;
302 else if (strncmp(buf
, "0", 1) == 0)
303 dev
->vsettings
.hflip
= 0;
310 static ssize_t
show_vflip(struct device
*class,
311 struct device_attribute
*attr
, char *buf
)
313 struct video_device
*vdev
= to_video_device(class);
314 struct stk_camera
*dev
= vdev_to_camera(vdev
);
316 return sprintf(buf
, "%d\n", dev
->vsettings
.vflip
);
319 static ssize_t
store_vflip(struct device
*class,
320 struct device_attribute
*attr
, const char *buf
, size_t count
)
322 struct video_device
*vdev
= to_video_device(class);
323 struct stk_camera
*dev
= vdev_to_camera(vdev
);
325 if (strncmp(buf
, "1", 1) == 0)
326 dev
->vsettings
.vflip
= 1;
327 else if (strncmp(buf
, "0", 1) == 0)
328 dev
->vsettings
.vflip
= 0;
335 static DEVICE_ATTR(brightness
, S_IRUGO
| S_IWUGO
,
336 show_brightness
, store_brightness
);
337 static DEVICE_ATTR(hflip
, S_IRUGO
| S_IWUGO
, show_hflip
, store_hflip
);
338 static DEVICE_ATTR(vflip
, S_IRUGO
| S_IWUGO
, show_vflip
, store_vflip
);
340 static int stk_create_sysfs_files(struct video_device
*vdev
)
344 ret
= video_device_create_file(vdev
, &dev_attr_brightness
);
345 ret
+= video_device_create_file(vdev
, &dev_attr_hflip
);
346 ret
+= video_device_create_file(vdev
, &dev_attr_vflip
);
350 static void stk_remove_sysfs_files(struct video_device
*vdev
)
352 video_device_remove_file(vdev
, &dev_attr_brightness
);
353 video_device_remove_file(vdev
, &dev_attr_hflip
);
354 video_device_remove_file(vdev
, &dev_attr_vflip
);
358 /* *********************************************** */
360 * This function is called as an URB transfert is complete (Isochronous pipe).
361 * So, the traitement is done in interrupt time, so it has be fast, not crash,
362 * and not stall. Neat.
364 static void stk_isoc_handler(struct urb
*urb
)
371 unsigned char *fill
= NULL
;
372 unsigned char *iso_buf
= NULL
;
374 struct stk_camera
*dev
;
375 struct stk_sio_buffer
*fb
;
377 dev
= (struct stk_camera
*) urb
->context
;
380 STK_ERROR("isoc_handler called with NULL device !\n");
384 if (urb
->status
== -ENOENT
|| urb
->status
== -ECONNRESET
385 || urb
->status
== -ESHUTDOWN
) {
386 atomic_dec(&dev
->urbs_used
);
390 spin_lock_irqsave(&dev
->spinlock
, flags
);
392 if (urb
->status
!= -EINPROGRESS
&& urb
->status
!= 0) {
393 STK_ERROR("isoc_handler: urb->status == %d\n", urb
->status
);
397 if (list_empty(&dev
->sio_avail
)) {
398 /*FIXME Stop streaming after a while */
399 (void) (printk_ratelimit() &&
400 STK_ERROR("isoc_handler without available buffer!\n"));
403 fb
= list_first_entry(&dev
->sio_avail
,
404 struct stk_sio_buffer
, list
);
405 fill
= fb
->buffer
+ fb
->v4lbuf
.bytesused
;
407 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
408 if (urb
->iso_frame_desc
[i
].status
!= 0) {
409 if (urb
->iso_frame_desc
[i
].status
!= -EXDEV
)
410 STK_ERROR("Frame %d has error %d\n", i
,
411 urb
->iso_frame_desc
[i
].status
);
414 framelen
= urb
->iso_frame_desc
[i
].actual_length
;
415 iso_buf
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
418 continue; /* no data */
421 * we found something informational from there
422 * the isoc frames have to type of headers
423 * type1: 00 xx 00 00 or 20 xx 00 00
424 * type2: 80 xx 00 00 00 00 00 00 or a0 xx 00 00 00 00 00 00
425 * xx is a sequencer which has never been seen over 0x3f
426 * imho data written down looks like bayer, i see similarities
427 * after every 640 bytes
429 if (*iso_buf
& 0x80) {
432 /* This marks a new frame */
433 if (fb
->v4lbuf
.bytesused
!= 0
434 && fb
->v4lbuf
.bytesused
!= dev
->frame_size
) {
435 (void) (printk_ratelimit() &&
436 STK_ERROR("frame %d, "
437 "bytesused=%d, skipping\n",
438 i
, fb
->v4lbuf
.bytesused
));
439 fb
->v4lbuf
.bytesused
= 0;
441 } else if (fb
->v4lbuf
.bytesused
== dev
->frame_size
) {
442 list_move_tail(dev
->sio_avail
.next
,
444 wake_up(&dev
->wait_frame
);
445 if (list_empty(&dev
->sio_avail
)) {
446 (void) (printk_ratelimit() &&
447 STK_ERROR("No buffer available\n"));
450 fb
= list_first_entry(&dev
->sio_avail
,
451 struct stk_sio_buffer
, list
);
452 fb
->v4lbuf
.bytesused
= 0;
460 /* Our buffer is full !!! */
461 if (framelen
+ fb
->v4lbuf
.bytesused
> dev
->frame_size
) {
462 (void) (printk_ratelimit() &&
463 STK_ERROR("Frame buffer overflow, lost sync\n"));
464 /*FIXME Do something here? */
467 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
468 memcpy(fill
, iso_buf
, framelen
);
469 spin_lock_irqsave(&dev
->spinlock
, flags
);
472 /* New size of our buffer */
473 fb
->v4lbuf
.bytesused
+= framelen
;
477 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
478 urb
->dev
= dev
->udev
;
479 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
481 STK_ERROR("Error (%d) re-submitting urb in stk_isoc_handler.\n",
486 /* -------------------------------------------- */
488 static int stk_prepare_iso(struct stk_camera
*dev
)
493 struct usb_device
*udev
;
500 STK_ERROR("isobufs already allocated. Bad\n");
502 dev
->isobufs
= kzalloc(MAX_ISO_BUFS
* sizeof(*dev
->isobufs
),
504 if (dev
->isobufs
== NULL
) {
505 STK_ERROR("Unable to allocate iso buffers\n");
508 for (i
= 0; i
< MAX_ISO_BUFS
; i
++) {
509 if (dev
->isobufs
[i
].data
== NULL
) {
510 kbuf
= kzalloc(ISO_BUFFER_SIZE
, GFP_KERNEL
);
512 STK_ERROR("Failed to allocate iso buffer %d\n",
516 dev
->isobufs
[i
].data
= kbuf
;
518 STK_ERROR("isobuf data already allocated\n");
519 if (dev
->isobufs
[i
].urb
== NULL
) {
520 urb
= usb_alloc_urb(ISO_FRAMES_PER_DESC
, GFP_KERNEL
);
522 STK_ERROR("Failed to allocate URB %d\n", i
);
525 dev
->isobufs
[i
].urb
= urb
;
527 STK_ERROR("Killing URB\n");
528 usb_kill_urb(dev
->isobufs
[i
].urb
);
529 urb
= dev
->isobufs
[i
].urb
;
533 urb
->pipe
= usb_rcvisocpipe(udev
, dev
->isoc_ep
);
534 urb
->transfer_flags
= URB_ISO_ASAP
;
535 urb
->transfer_buffer
= dev
->isobufs
[i
].data
;
536 urb
->transfer_buffer_length
= ISO_BUFFER_SIZE
;
537 urb
->complete
= stk_isoc_handler
;
539 urb
->start_frame
= 0;
540 urb
->number_of_packets
= ISO_FRAMES_PER_DESC
;
542 for (j
= 0; j
< ISO_FRAMES_PER_DESC
; j
++) {
543 urb
->iso_frame_desc
[j
].offset
= j
* ISO_MAX_FRAME_SIZE
;
544 urb
->iso_frame_desc
[j
].length
= ISO_MAX_FRAME_SIZE
;
551 for (i
= 0; i
< MAX_ISO_BUFS
&& dev
->isobufs
[i
].data
; i
++)
552 kfree(dev
->isobufs
[i
].data
);
553 for (i
= 0; i
< MAX_ISO_BUFS
&& dev
->isobufs
[i
].urb
; i
++)
554 usb_free_urb(dev
->isobufs
[i
].urb
);
560 static void stk_clean_iso(struct stk_camera
*dev
)
564 if (dev
== NULL
|| dev
->isobufs
== NULL
)
567 for (i
= 0; i
< MAX_ISO_BUFS
; i
++) {
570 urb
= dev
->isobufs
[i
].urb
;
572 if (atomic_read(&dev
->urbs_used
))
576 kfree(dev
->isobufs
[i
].data
);
580 unset_memallocd(dev
);
583 static int stk_setup_siobuf(struct stk_camera
*dev
, int index
)
585 struct stk_sio_buffer
*buf
= dev
->sio_bufs
+ index
;
586 INIT_LIST_HEAD(&buf
->list
);
587 buf
->v4lbuf
.length
= PAGE_ALIGN(dev
->frame_size
);
588 buf
->buffer
= vmalloc_user(buf
->v4lbuf
.length
);
589 if (buf
->buffer
== NULL
)
593 buf
->v4lbuf
.index
= index
;
594 buf
->v4lbuf
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
595 buf
->v4lbuf
.field
= V4L2_FIELD_NONE
;
596 buf
->v4lbuf
.memory
= V4L2_MEMORY_MMAP
;
597 buf
->v4lbuf
.m
.offset
= 2*index
*buf
->v4lbuf
.length
;
601 static int stk_free_sio_buffers(struct stk_camera
*dev
)
606 if (dev
->n_sbufs
== 0 || dev
->sio_bufs
== NULL
)
609 * If any buffers are mapped, we cannot free them at all.
611 for (i
= 0; i
< dev
->n_sbufs
; i
++) {
612 if (dev
->sio_bufs
[i
].mapcount
> 0)
618 spin_lock_irqsave(&dev
->spinlock
, flags
);
619 INIT_LIST_HEAD(&dev
->sio_avail
);
620 INIT_LIST_HEAD(&dev
->sio_full
);
621 nbufs
= dev
->n_sbufs
;
623 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
624 for (i
= 0; i
< nbufs
; i
++) {
625 if (dev
->sio_bufs
[i
].buffer
!= NULL
)
626 vfree(dev
->sio_bufs
[i
].buffer
);
628 kfree(dev
->sio_bufs
);
629 dev
->sio_bufs
= NULL
;
633 static int stk_prepare_sio_buffers(struct stk_camera
*dev
, unsigned n_sbufs
)
636 if (dev
->sio_bufs
!= NULL
)
637 STK_ERROR("sio_bufs already allocated\n");
639 dev
->sio_bufs
= kzalloc(n_sbufs
* sizeof(struct stk_sio_buffer
),
641 if (dev
->sio_bufs
== NULL
)
643 for (i
= 0; i
< n_sbufs
; i
++) {
644 if (stk_setup_siobuf(dev
, i
))
645 return (dev
->n_sbufs
> 1)? 0 : -ENOMEM
;
652 static int stk_allocate_buffers(struct stk_camera
*dev
, unsigned n_sbufs
)
655 err
= stk_prepare_iso(dev
);
660 err
= stk_prepare_sio_buffers(dev
, n_sbufs
);
662 stk_free_sio_buffers(dev
);
668 static void stk_free_buffers(struct stk_camera
*dev
)
671 stk_free_sio_buffers(dev
);
673 /* -------------------------------------------- */
675 /* v4l file operations */
677 static int v4l_stk_open(struct inode
*inode
, struct file
*fp
)
679 struct stk_camera
*dev
;
680 struct video_device
*vdev
;
682 vdev
= video_devdata(fp
);
683 dev
= vdev_to_camera(vdev
);
685 if (dev
== NULL
|| !is_present(dev
))
687 fp
->private_data
= vdev
;
688 kref_get(&dev
->kref
);
689 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
691 usb_autopm_get_interface(dev
->interface
);
692 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
697 static int v4l_stk_release(struct inode
*inode
, struct file
*fp
)
699 struct stk_camera
*dev
;
700 struct video_device
*vdev
;
702 vdev
= video_devdata(fp
);
704 STK_ERROR("v4l_release called w/o video devdata\n");
707 dev
= vdev_to_camera(vdev
);
709 STK_ERROR("v4l_release called on removed device\n");
713 if (dev
->owner
!= fp
) {
714 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
716 usb_autopm_put_interface(dev
->interface
);
717 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
718 kref_put(&dev
->kref
, stk_camera_cleanup
);
722 stk_stop_stream(dev
);
724 stk_free_buffers(dev
);
728 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
730 usb_autopm_put_interface(dev
->interface
);
731 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
732 kref_put(&dev
->kref
, stk_camera_cleanup
);
737 static ssize_t
v4l_stk_read(struct file
*fp
, char __user
*buf
,
738 size_t count
, loff_t
*f_pos
)
743 struct stk_camera
*dev
;
744 struct video_device
*vdev
;
745 struct stk_sio_buffer
*sbuf
;
747 vdev
= video_devdata(fp
);
750 dev
= vdev_to_camera(vdev
);
755 if (!is_present(dev
))
757 if (dev
->owner
&& dev
->owner
!= fp
)
760 if (!is_streaming(dev
)) {
761 if (stk_initialise(dev
)
762 || stk_allocate_buffers(dev
, 3)
763 || stk_start_stream(dev
))
765 spin_lock_irqsave(&dev
->spinlock
, flags
);
766 for (i
= 0; i
< dev
->n_sbufs
; i
++) {
767 list_add_tail(&dev
->sio_bufs
[i
].list
, &dev
->sio_avail
);
768 dev
->sio_bufs
[i
].v4lbuf
.flags
= V4L2_BUF_FLAG_QUEUED
;
770 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
773 if (fp
->f_flags
& O_NONBLOCK
&& list_empty(&dev
->sio_full
))
775 ret
= wait_event_interruptible(dev
->wait_frame
,
776 !list_empty(&dev
->sio_full
) || !is_present(dev
));
779 if (!is_present(dev
))
782 if (count
+ *f_pos
> dev
->frame_size
)
783 count
= dev
->frame_size
- *f_pos
;
784 spin_lock_irqsave(&dev
->spinlock
, flags
);
785 if (list_empty(&dev
->sio_full
)) {
786 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
787 STK_ERROR("BUG: No siobufs ready\n");
790 sbuf
= list_first_entry(&dev
->sio_full
, struct stk_sio_buffer
, list
);
791 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
793 if (copy_to_user(buf
, sbuf
->buffer
+ *f_pos
, count
))
798 if (*f_pos
>= dev
->frame_size
) {
800 spin_lock_irqsave(&dev
->spinlock
, flags
);
801 list_move_tail(&sbuf
->list
, &dev
->sio_avail
);
802 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
807 static unsigned int v4l_stk_poll(struct file
*fp
, poll_table
*wait
)
809 struct stk_camera
*dev
;
810 struct video_device
*vdev
;
812 vdev
= video_devdata(fp
);
817 dev
= vdev_to_camera(vdev
);
821 poll_wait(fp
, &dev
->wait_frame
, wait
);
823 if (!is_present(dev
))
826 if (!list_empty(&dev
->sio_full
))
827 return (POLLIN
| POLLRDNORM
);
833 static void stk_v4l_vm_open(struct vm_area_struct
*vma
)
835 struct stk_sio_buffer
*sbuf
= vma
->vm_private_data
;
838 static void stk_v4l_vm_close(struct vm_area_struct
*vma
)
840 struct stk_sio_buffer
*sbuf
= vma
->vm_private_data
;
842 if (sbuf
->mapcount
== 0)
843 sbuf
->v4lbuf
.flags
&= ~V4L2_BUF_FLAG_MAPPED
;
845 static struct vm_operations_struct stk_v4l_vm_ops
= {
846 .open
= stk_v4l_vm_open
,
847 .close
= stk_v4l_vm_close
850 static int v4l_stk_mmap(struct file
*fp
, struct vm_area_struct
*vma
)
854 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
855 struct stk_camera
*dev
;
856 struct video_device
*vdev
;
857 struct stk_sio_buffer
*sbuf
= NULL
;
859 if (!(vma
->vm_flags
& VM_WRITE
) || !(vma
->vm_flags
& VM_SHARED
))
862 vdev
= video_devdata(fp
);
863 dev
= vdev_to_camera(vdev
);
865 for (i
= 0; i
< dev
->n_sbufs
; i
++) {
866 if (dev
->sio_bufs
[i
].v4lbuf
.m
.offset
== offset
) {
867 sbuf
= dev
->sio_bufs
+ i
;
873 ret
= remap_vmalloc_range(vma
, sbuf
->buffer
, 0);
876 vma
->vm_flags
|= VM_DONTEXPAND
;
877 vma
->vm_private_data
= sbuf
;
878 vma
->vm_ops
= &stk_v4l_vm_ops
;
879 sbuf
->v4lbuf
.flags
|= V4L2_BUF_FLAG_MAPPED
;
880 stk_v4l_vm_open(vma
);
884 /* v4l ioctl handlers */
886 static int stk_vidioc_querycap(struct file
*filp
,
887 void *priv
, struct v4l2_capability
*cap
)
889 strcpy(cap
->driver
, "stk");
890 strcpy(cap
->card
, "stk");
891 cap
->version
= DRIVER_VERSION_NUM
;
893 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
894 | V4L2_CAP_READWRITE
| V4L2_CAP_STREAMING
;
898 static int stk_vidioc_enum_input(struct file
*filp
,
899 void *priv
, struct v4l2_input
*input
)
901 if (input
->index
!= 0)
904 strcpy(input
->name
, "Syntek USB Camera");
905 input
->type
= V4L2_INPUT_TYPE_CAMERA
;
910 static int stk_vidioc_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
916 static int stk_vidioc_s_input(struct file
*filp
, void *priv
, unsigned int i
)
925 static int stk_vidioc_s_std(struct file
*filp
, void *priv
, v4l2_std_id
*a
)
930 /* List of all V4Lv2 controls supported by the driver */
931 static struct v4l2_queryctrl stk_controls
[] = {
933 .id
= V4L2_CID_BRIGHTNESS
,
934 .type
= V4L2_CTRL_TYPE_INTEGER
,
935 .name
= "Brightness",
939 .default_value
= 0x6000,
941 /*TODO: get more controls to work */
944 static int stk_vidioc_queryctrl(struct file
*filp
,
945 void *priv
, struct v4l2_queryctrl
*c
)
949 nbr
= ARRAY_SIZE(stk_controls
);
951 for (i
= 0; i
< nbr
; i
++) {
952 if (stk_controls
[i
].id
== c
->id
) {
953 memcpy(c
, &stk_controls
[i
],
954 sizeof(struct v4l2_queryctrl
));
961 static int stk_vidioc_g_ctrl(struct file
*filp
,
962 void *priv
, struct v4l2_control
*c
)
964 struct stk_camera
*dev
= priv
;
966 case V4L2_CID_BRIGHTNESS
:
967 c
->value
= dev
->vsettings
.brightness
;
975 static int stk_vidioc_s_ctrl(struct file
*filp
,
976 void *priv
, struct v4l2_control
*c
)
978 struct stk_camera
*dev
= priv
;
980 case V4L2_CID_BRIGHTNESS
:
981 dev
->vsettings
.brightness
= c
->value
;
982 return stk_sensor_set_brightness(dev
, c
->value
>> 8);
990 static int stk_vidioc_enum_fmt_cap(struct file
*filp
,
991 void *priv
, struct v4l2_fmtdesc
*fmtd
)
995 switch (fmtd
->index
) {
997 fmtd
->pixelformat
= V4L2_PIX_FMT_RGB565
;
998 strcpy(fmtd
->description
, "r5g6b5");
1001 fmtd
->pixelformat
= V4L2_PIX_FMT_RGB565X
;
1002 strcpy(fmtd
->description
, "r5g6b5BE");
1005 fmtd
->pixelformat
= V4L2_PIX_FMT_UYVY
;
1006 strcpy(fmtd
->description
, "yuv4:2:2");
1009 fmtd
->pixelformat
= V4L2_PIX_FMT_SBGGR8
;
1010 strcpy(fmtd
->description
, "Raw bayer");
1012 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1015 fmtd
->pixelformat
= V4L2_PIX_FMT_YUYV
;
1016 strcpy(fmtd
->description
, "yuv4:2:2");
1018 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1025 static struct stk_size
{
1030 { .w
= 1280, .h
= 1024, .m
= MODE_SXGA
, },
1031 { .w
= 640, .h
= 480, .m
= MODE_VGA
, },
1032 { .w
= 352, .h
= 288, .m
= MODE_CIF
, },
1033 { .w
= 320, .h
= 240, .m
= MODE_QVGA
, },
1034 { .w
= 176, .h
= 144, .m
= MODE_QCIF
, },
1037 static int stk_vidioc_g_fmt_cap(struct file
*filp
,
1038 void *priv
, struct v4l2_format
*f
)
1040 struct v4l2_pix_format
*pix_format
= &f
->fmt
.pix
;
1041 struct stk_camera
*dev
= priv
;
1044 for (i
= 0; i
< ARRAY_SIZE(stk_sizes
)
1045 && stk_sizes
[i
].m
!= dev
->vsettings
.mode
;
1047 if (i
== ARRAY_SIZE(stk_sizes
)) {
1048 STK_ERROR("ERROR: mode invalid\n");
1051 pix_format
->width
= stk_sizes
[i
].w
;
1052 pix_format
->height
= stk_sizes
[i
].h
;
1053 pix_format
->field
= V4L2_FIELD_NONE
;
1054 pix_format
->colorspace
= V4L2_COLORSPACE_SRGB
;
1055 pix_format
->priv
= 0;
1056 pix_format
->pixelformat
= dev
->vsettings
.palette
;
1057 if (dev
->vsettings
.palette
== V4L2_PIX_FMT_SBGGR8
)
1058 pix_format
->bytesperline
= pix_format
->width
;
1060 pix_format
->bytesperline
= 2 * pix_format
->width
;
1061 pix_format
->sizeimage
= pix_format
->bytesperline
1062 * pix_format
->height
;
1066 static int stk_vidioc_try_fmt_cap(struct file
*filp
,
1067 void *priv
, struct v4l2_format
*fmtd
)
1070 switch (fmtd
->fmt
.pix
.pixelformat
) {
1071 case V4L2_PIX_FMT_RGB565
:
1072 case V4L2_PIX_FMT_RGB565X
:
1073 case V4L2_PIX_FMT_UYVY
:
1074 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1076 case V4L2_PIX_FMT_YUYV
:
1077 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1078 case V4L2_PIX_FMT_SBGGR8
:
1083 for (i
= 1; i
< ARRAY_SIZE(stk_sizes
); i
++) {
1084 if (fmtd
->fmt
.pix
.width
> stk_sizes
[i
].w
)
1087 if (i
== ARRAY_SIZE(stk_sizes
)
1088 || (abs(fmtd
->fmt
.pix
.width
- stk_sizes
[i
-1].w
)
1089 < abs(fmtd
->fmt
.pix
.width
- stk_sizes
[i
].w
))) {
1090 fmtd
->fmt
.pix
.height
= stk_sizes
[i
-1].h
;
1091 fmtd
->fmt
.pix
.width
= stk_sizes
[i
-1].w
;
1092 fmtd
->fmt
.pix
.priv
= i
- 1;
1094 fmtd
->fmt
.pix
.height
= stk_sizes
[i
].h
;
1095 fmtd
->fmt
.pix
.width
= stk_sizes
[i
].w
;
1096 fmtd
->fmt
.pix
.priv
= i
;
1099 fmtd
->fmt
.pix
.field
= V4L2_FIELD_NONE
;
1100 fmtd
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SRGB
;
1101 if (fmtd
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_SBGGR8
)
1102 fmtd
->fmt
.pix
.bytesperline
= fmtd
->fmt
.pix
.width
;
1104 fmtd
->fmt
.pix
.bytesperline
= 2 * fmtd
->fmt
.pix
.width
;
1105 fmtd
->fmt
.pix
.sizeimage
= fmtd
->fmt
.pix
.bytesperline
1106 * fmtd
->fmt
.pix
.height
;
1110 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1112 static int stk_setup_format(struct stk_camera
*dev
)
1116 if (dev
->vsettings
.palette
== V4L2_PIX_FMT_SBGGR8
)
1120 while (stk_sizes
[i
].m
!= dev
->vsettings
.mode
1121 && i
< ARRAY_SIZE(stk_sizes
))
1123 if (i
== ARRAY_SIZE(stk_sizes
)) {
1124 STK_ERROR("Something is broken in %s\n", __FUNCTION__
);
1127 /* This registers controls some timings, not sure of what. */
1128 stk_camera_write_reg(dev
, 0x001b, 0x0e);
1129 if (dev
->vsettings
.mode
== MODE_SXGA
)
1130 stk_camera_write_reg(dev
, 0x001c, 0x0e);
1132 stk_camera_write_reg(dev
, 0x001c, 0x46);
1134 * Registers 0x0115 0x0114 are the size of each line (bytes),
1135 * regs 0x0117 0x0116 are the heigth of the image.
1137 stk_camera_write_reg(dev
, 0x0115,
1138 ((stk_sizes
[i
].w
* depth
) >> 8) & 0xff);
1139 stk_camera_write_reg(dev
, 0x0114,
1140 (stk_sizes
[i
].w
* depth
) & 0xff);
1141 stk_camera_write_reg(dev
, 0x0117,
1142 (stk_sizes
[i
].h
>> 8) & 0xff);
1143 stk_camera_write_reg(dev
, 0x0116,
1144 stk_sizes
[i
].h
& 0xff);
1145 return stk_sensor_configure(dev
);
1148 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1149 static int stk_vidioc_s_fmt_cap(struct file
*filp
,
1150 void *priv
, struct v4l2_format
*fmtd
)
1153 struct stk_camera
*dev
= priv
;
1157 if (!is_present(dev
))
1159 if (is_streaming(dev
))
1161 if (dev
->owner
&& dev
->owner
!= filp
)
1163 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1166 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1167 ret
= stk_vidioc_try_fmt_cap(filp
, priv
, fmtd
);
1170 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1173 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1175 dev
->vsettings
.palette
= fmtd
->fmt
.pix
.pixelformat
;
1176 stk_free_buffers(dev
);
1177 dev
->frame_size
= fmtd
->fmt
.pix
.sizeimage
;
1178 dev
->vsettings
.mode
= stk_sizes
[fmtd
->fmt
.pix
.priv
].m
;
1180 stk_initialise(dev
);
1181 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1182 /* This registers controls some timings, not sure of what. */
1183 stk_camera_write_reg(dev
, 0x001b, 0x0e);
1184 if (dev
->vsettings
.mode
== MODE_SXGA
)
1185 stk_camera_write_reg(dev
, 0x001c, 0x0e);
1187 stk_camera_write_reg(dev
, 0x001c, 0x46);
1189 * Registers 0x0115 0x0114 are the size of each line (bytes),
1190 * regs 0x0117 0x0116 are the heigth of the image.
1192 stk_camera_write_reg(dev
, 0x0115,
1193 (fmtd
->fmt
.pix
.bytesperline
>> 8) & 0xff);
1194 stk_camera_write_reg(dev
, 0x0114,
1195 fmtd
->fmt
.pix
.bytesperline
& 0xff);
1196 stk_camera_write_reg(dev
, 0x0117,
1197 (fmtd
->fmt
.pix
.height
>> 8) & 0xff);
1198 stk_camera_write_reg(dev
, 0x0116,
1199 fmtd
->fmt
.pix
.height
& 0xff);
1200 return stk_sensor_configure(dev
);
1202 return stk_setup_format(dev
);
1203 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1206 static int stk_vidioc_reqbufs(struct file
*filp
,
1207 void *priv
, struct v4l2_requestbuffers
*rb
)
1209 struct stk_camera
*dev
= priv
;
1213 if (rb
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1215 if (rb
->memory
!= V4L2_MEMORY_MMAP
)
1217 if (is_streaming(dev
)
1218 || (dev
->owner
&& dev
->owner
!= filp
))
1222 /*FIXME If they ask for zero, we must stop streaming and free */
1225 /* Arbitrary limit */
1226 else if (rb
->count
> 5)
1229 stk_allocate_buffers(dev
, rb
->count
);
1230 rb
->count
= dev
->n_sbufs
;
1234 static int stk_vidioc_querybuf(struct file
*filp
,
1235 void *priv
, struct v4l2_buffer
*buf
)
1238 struct stk_camera
*dev
= priv
;
1239 struct stk_sio_buffer
*sbuf
;
1241 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1246 if (index
< 0 || index
>= dev
->n_sbufs
)
1248 sbuf
= dev
->sio_bufs
+ buf
->index
;
1249 *buf
= sbuf
->v4lbuf
;
1253 static int stk_vidioc_qbuf(struct file
*filp
,
1254 void *priv
, struct v4l2_buffer
*buf
)
1256 struct stk_camera
*dev
= priv
;
1257 struct stk_sio_buffer
*sbuf
;
1258 unsigned long flags
;
1259 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1262 if (buf
->memory
!= V4L2_MEMORY_MMAP
)
1265 if (buf
->index
< 0 || buf
->index
>= dev
->n_sbufs
)
1267 sbuf
= dev
->sio_bufs
+ buf
->index
;
1268 if (sbuf
->v4lbuf
.flags
& V4L2_BUF_FLAG_QUEUED
)
1270 sbuf
->v4lbuf
.flags
|= V4L2_BUF_FLAG_QUEUED
;
1271 sbuf
->v4lbuf
.flags
&= ~V4L2_BUF_FLAG_DONE
;
1272 spin_lock_irqsave(&dev
->spinlock
, flags
);
1273 list_add_tail(&sbuf
->list
, &dev
->sio_avail
);
1274 *buf
= sbuf
->v4lbuf
;
1275 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1279 static int stk_vidioc_dqbuf(struct file
*filp
,
1280 void *priv
, struct v4l2_buffer
*buf
)
1282 struct stk_camera
*dev
= priv
;
1283 struct stk_sio_buffer
*sbuf
;
1284 unsigned long flags
;
1287 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
1288 || !is_streaming(dev
))
1291 if (filp
->f_flags
& O_NONBLOCK
&& list_empty(&dev
->sio_full
))
1292 return -EWOULDBLOCK
;
1293 ret
= wait_event_interruptible(dev
->wait_frame
,
1294 !list_empty(&dev
->sio_full
) || !is_present(dev
));
1297 if (!is_present(dev
))
1300 spin_lock_irqsave(&dev
->spinlock
, flags
);
1301 sbuf
= list_first_entry(&dev
->sio_full
, struct stk_sio_buffer
, list
);
1302 list_del_init(&sbuf
->list
);
1303 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1304 sbuf
->v4lbuf
.flags
&= ~V4L2_BUF_FLAG_QUEUED
;
1305 sbuf
->v4lbuf
.flags
|= V4L2_BUF_FLAG_DONE
;
1306 sbuf
->v4lbuf
.sequence
= ++dev
->sequence
;
1307 do_gettimeofday(&sbuf
->v4lbuf
.timestamp
);
1309 *buf
= sbuf
->v4lbuf
;
1313 static int stk_vidioc_streamon(struct file
*filp
,
1314 void *priv
, enum v4l2_buf_type type
)
1316 struct stk_camera
*dev
= priv
;
1317 if (is_streaming(dev
))
1319 if (dev
->sio_bufs
== NULL
)
1322 return stk_start_stream(dev
);
1325 static int stk_vidioc_streamoff(struct file
*filp
,
1326 void *priv
, enum v4l2_buf_type type
)
1328 struct stk_camera
*dev
= priv
;
1329 unsigned long flags
;
1331 stk_stop_stream(dev
);
1332 spin_lock_irqsave(&dev
->spinlock
, flags
);
1333 INIT_LIST_HEAD(&dev
->sio_avail
);
1334 INIT_LIST_HEAD(&dev
->sio_full
);
1335 for (i
= 0; i
< dev
->n_sbufs
; i
++) {
1336 INIT_LIST_HEAD(&dev
->sio_bufs
[i
].list
);
1337 dev
->sio_bufs
[i
].v4lbuf
.flags
= 0;
1339 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1344 static int stk_vidioc_g_parm(struct file
*filp
,
1345 void *priv
, struct v4l2_streamparm
*sp
)
1347 if (sp
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1350 sp
->parm
.capture
.capability
= 0;
1351 sp
->parm
.capture
.capturemode
= 0;
1352 /*FIXME This is not correct */
1353 sp
->parm
.capture
.timeperframe
.numerator
= 1;
1354 sp
->parm
.capture
.timeperframe
.denominator
= 30;
1355 sp
->parm
.capture
.readbuffers
= 2;
1356 sp
->parm
.capture
.extendedmode
= 0;
1360 static struct file_operations v4l_stk_fops
= {
1361 .owner
= THIS_MODULE
,
1362 .open
= v4l_stk_open
,
1363 .release
= v4l_stk_release
,
1364 .read
= v4l_stk_read
,
1365 .poll
= v4l_stk_poll
,
1366 .mmap
= v4l_stk_mmap
,
1367 .ioctl
= video_ioctl2
,
1368 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1370 #ifdef CONFIG_COMPAT
1371 .compat_ioctl
= v4l_compat_ioctl32
,
1373 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1377 static void stk_v4l_dev_release(struct video_device
*vd
)
1381 static struct video_device stk_v4l_data
= {
1382 .name
= "stkwebcam",
1383 .type
= VFL_TYPE_GRABBER
,
1384 .type2
= VID_TYPE_CAPTURE
,
1386 .tvnorms
= V4L2_STD_UNKNOWN
,
1387 .current_norm
= V4L2_STD_UNKNOWN
,
1388 .fops
= &v4l_stk_fops
,
1389 .release
= stk_v4l_dev_release
,
1391 .vidioc_querycap
= stk_vidioc_querycap
,
1392 .vidioc_enum_fmt_cap
= stk_vidioc_enum_fmt_cap
,
1393 .vidioc_try_fmt_cap
= stk_vidioc_try_fmt_cap
,
1394 .vidioc_s_fmt_cap
= stk_vidioc_s_fmt_cap
,
1395 .vidioc_g_fmt_cap
= stk_vidioc_g_fmt_cap
,
1396 .vidioc_enum_input
= stk_vidioc_enum_input
,
1397 .vidioc_s_input
= stk_vidioc_s_input
,
1398 .vidioc_g_input
= stk_vidioc_g_input
,
1399 .vidioc_s_std
= stk_vidioc_s_std
,
1400 .vidioc_reqbufs
= stk_vidioc_reqbufs
,
1401 .vidioc_querybuf
= stk_vidioc_querybuf
,
1402 .vidioc_qbuf
= stk_vidioc_qbuf
,
1403 .vidioc_dqbuf
= stk_vidioc_dqbuf
,
1404 .vidioc_streamon
= stk_vidioc_streamon
,
1405 .vidioc_streamoff
= stk_vidioc_streamoff
,
1406 .vidioc_queryctrl
= stk_vidioc_queryctrl
,
1407 .vidioc_g_ctrl
= stk_vidioc_g_ctrl
,
1408 .vidioc_s_ctrl
= stk_vidioc_s_ctrl
,
1409 .vidioc_g_parm
= stk_vidioc_g_parm
,
1413 static int stk_register_video_device(struct stk_camera
*dev
)
1417 dev
->vdev
= stk_v4l_data
;
1418 dev
->vdev
.debug
= debug
;
1419 dev
->vdev
.dev
= &dev
->interface
->dev
;
1420 dev
->vdev
.priv
= dev
;
1421 err
= video_register_device(&dev
->vdev
, VFL_TYPE_GRABBER
, -1);
1423 STK_ERROR("v4l registration failed\n");
1425 STK_INFO("Syntek USB2.0 Camera is now controlling video device"
1426 " /dev/video%d\n", dev
->vdev
.minor
);
1433 static int stk_camera_probe(struct usb_interface
*interface
,
1434 const struct usb_device_id
*id
)
1439 struct stk_camera
*dev
= NULL
;
1440 struct usb_device
*udev
= interface_to_usbdev(interface
);
1441 struct usb_host_interface
*iface_desc
;
1442 struct usb_endpoint_descriptor
*endpoint
;
1444 dev
= kzalloc(sizeof(struct stk_camera
), GFP_KERNEL
);
1446 STK_ERROR("Out of memory !\n");
1450 kref_init(&dev
->kref
);
1451 spin_lock_init(&dev
->spinlock
);
1452 init_waitqueue_head(&dev
->wait_frame
);
1455 dev
->interface
= interface
;
1456 usb_get_intf(interface
);
1458 dev
->vsettings
.vflip
= vflip
;
1459 dev
->vsettings
.hflip
= hflip
;
1463 /* Set up the endpoint information
1464 * use only the first isoc-in endpoint
1465 * for the current alternate setting */
1466 iface_desc
= interface
->cur_altsetting
;
1468 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
1469 endpoint
= &iface_desc
->endpoint
[i
].desc
;
1472 && ((endpoint
->bEndpointAddress
1473 & USB_ENDPOINT_DIR_MASK
) == USB_DIR_IN
)
1474 && ((endpoint
->bmAttributes
1475 & USB_ENDPOINT_XFERTYPE_MASK
) == USB_ENDPOINT_XFER_ISOC
)) {
1476 /* we found an isoc in endpoint */
1477 dev
->isoc_ep
= (endpoint
->bEndpointAddress
& 0xF);
1481 if (!dev
->isoc_ep
) {
1482 STK_ERROR("Could not find isoc-in endpoint");
1483 kref_put(&dev
->kref
, stk_camera_cleanup
);
1486 dev
->vsettings
.brightness
= 0x7fff;
1487 dev
->vsettings
.palette
= V4L2_PIX_FMT_RGB565
;
1488 dev
->vsettings
.mode
= MODE_VGA
;
1489 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1490 dev
->frame_size
= 640*480*2;
1492 dev
->frame_size
= 640 * 480 * 2;
1493 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1495 INIT_LIST_HEAD(&dev
->sio_avail
);
1496 INIT_LIST_HEAD(&dev
->sio_full
);
1498 usb_set_intfdata(interface
, dev
);
1500 err
= stk_register_video_device(dev
);
1502 kref_put(&dev
->kref
, stk_camera_cleanup
);
1506 stk_create_sysfs_files(&dev
->vdev
);
1507 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1509 usb_autopm_enable(dev
->interface
);
1510 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1515 static void stk_camera_disconnect(struct usb_interface
*interface
)
1517 struct stk_camera
*dev
= usb_get_intfdata(interface
);
1519 usb_set_intfdata(interface
, NULL
);
1522 wake_up_interruptible(&dev
->wait_frame
);
1523 stk_remove_sysfs_files(&dev
->vdev
);
1525 kref_put(&dev
->kref
, stk_camera_cleanup
);
1528 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1531 int stk_camera_suspend(struct usb_interface
*intf
, pm_message_t message
)
1533 struct stk_camera
*dev
= usb_get_intfdata(intf
);
1534 if (is_streaming(dev
)) {
1535 stk_stop_stream(dev
);
1536 /* yes, this is ugly */
1542 int stk_camera_resume(struct usb_interface
*intf
)
1544 struct stk_camera
*dev
= usb_get_intfdata(intf
);
1545 if (!is_initialised(dev
))
1547 unset_initialised(dev
);
1548 stk_initialise(dev
);
1549 stk_setup_format(dev
);
1550 if (is_streaming(dev
))
1551 stk_start_stream(dev
);
1556 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1557 static struct usb_driver stk_camera_driver
= {
1558 .name
= "stkwebcam",
1559 .probe
= stk_camera_probe
,
1560 .disconnect
= stk_camera_disconnect
,
1561 .id_table
= stkwebcam_table
,
1562 <<<<<<< HEAD
:drivers
/media
/video
/stk
-webcam
.c
1565 .suspend
= stk_camera_suspend
,
1566 .resume
= stk_camera_resume
,
1568 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/stk
-webcam
.c
1572 static int __init
stk_camera_init(void)
1576 result
= usb_register(&stk_camera_driver
);
1578 STK_ERROR("usb_register failed ! Error number %d\n", result
);
1584 static void __exit
stk_camera_exit(void)
1586 usb_deregister(&stk_camera_driver
);
1589 module_init(stk_camera_init
);
1590 module_exit(stk_camera_exit
);