34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/kernel.h>
37#include <linux/version.h>
38#include <linux/errno.h>
39#include <linux/slab.h>
40#include <linux/kref.h>
41#include <linux/vmalloc.h>
46#include <media/v4l2-common.h>
47#include <media/v4l2-ioctl.h>
86 .default_value = 0x7f00,
95 .default_value = 0x7f00,
100 .name =
"Saturation",
104 .default_value = 0x7f00,
113 .default_value = 0x7f00,
122 .default_value = 0x7f00,
127 .name =
"Flip Horizontally",
136 .name =
"Flip Vertically",
173 switch (
dev->webcam_type) {
205 switch (
dev->webcam_type) {
207 for (
i=0,
find=0;
i<=STK11XX_1280x1024;
i++) {
214 for (
i=0,
find=0;
i<=STK11XX_640x480;
i++) {
221 for (
i=0,
find=0;
i<=STK11XX_720x576;
i++) {
247 dev->frame_size =
dev->image.x *
dev->image.y;
250 switch (
dev->resolution) {
253 case STK11XX_160x120:
254 case STK11XX_213x160:
255 case STK11XX_320x240:
256 case STK11XX_640x480:
259 dev->frame_size =
dev->image.x *
dev->image.y;
262 case STK11XX_720x576:
263 case STK11XX_800x600:
264 case STK11XX_1024x768:
265 case STK11XX_1280x1024:
268 dev->frame_size =
dev->image.x *
dev->image.y;
275 switch (
dev->vsettings.palette) {
276 case STK11XX_PALETTE_RGB24:
277 case STK11XX_PALETTE_BGR24:
278 dev->view_size = 3 *
dev->view.x *
dev->view.y;
279 dev->image_size = 3 *
dev->frame_size;
282 case STK11XX_PALETTE_RGB32:
283 case STK11XX_PALETTE_BGR32:
284 dev->view_size = 3 *
dev->view.x *
dev->view.y;
285 dev->image_size = 4 *
dev->frame_size;
288 case STK11XX_PALETTE_UYVY:
289 case STK11XX_PALETTE_YUYV:
290 dev->view_size = 2 *
dev->view.x *
dev->view.y;
291 dev->image_size = 2 *
dev->frame_size;
319 STK_ERROR(
"Device not initialized !!!\n");
326 STK_DEBUG(
"Device is busy, someone is using the device\n");
335 STK_ERROR(
"Failed to allocate buffer memory !\n");
346 dev->error_status = 0;
347 dev->visoc_errors = 0;
348 dev->vframes_error = 0;
349 dev->vframes_dumped = 0;
350 dev->vsettings.hue = 0xffff;
351 dev->vsettings.whiteness = 0xffff;
352 dev->vsettings.depth = 24;
353 dev->vsettings.palette = STK11XX_PALETTE_BGR24;
367 STK_ERROR(
"Failed to init ISOC stuff !\n");
384 fp->private_data = vdev;
408 STK_ERROR(
"v4l_release called on closed device\n");
472 if (
dev->image_read_pos == 0) {
475 while (
dev->full_frames ==
NULL) {
476 if (
dev->error_status) {
480 return -
dev->error_status ;
527 dev->image_read_pos = 0;
563 if (
dev->error_status)
602 for (
i=0;
i<
dev->nbuffers;
i++) {
621 STK_ERROR(
"Wrong size (%lu) needed to be len_per_image=%d or total_size=%lu\n",
627 else if (
size >
dev->len_per_image)
673#if (CONFIG_STK11XX_DEBUG == 1)
701 if (
dev->webcam_model != SYNTEK_STK_0408) {
704 strlcpy(
i->name,
"USB",
sizeof(
i->name));
712 strlcpy(
i->name,
"Input1",
sizeof(
i->name));
715 strlcpy(
i->name,
"Input2",
sizeof(
i->name));
718 strlcpy(
i->name,
"Input3",
sizeof(
i->name));
721 strlcpy(
i->name,
"Input4",
sizeof(
i->name));
734 return dev->vsettings.input;
749 dev->vsettings.input =
i->index + 1;
761 STK_DEBUG(
"VIDIOC_QUERYCTRL id = %d\n",
c->id);
772 c->default_value =
dev->vsettings.default_brightness;
775 c->default_value =
dev->vsettings.default_whiteness;
778 c->default_value =
dev->vsettings.default_colour;
781 c->default_value =
dev->vsettings.default_contrast;
784 c->default_value =
dev->vsettings.default_hflip;
787 c->default_value =
dev->vsettings.default_vflip;
807 c->value =
dev->vsettings.brightness;
811 c->value =
dev->vsettings.whiteness;
815 c->value =
dev->vsettings.hue;
819 c->value =
dev->vsettings.colour;
823 c->value =
dev->vsettings.contrast;
827 c->value =
dev->vsettings.hflip;
831 c->value =
dev->vsettings.vflip;
845 STK_DEBUG(
"SET CTRL id=%d value=%d\n",
c->id,
c->value);
849 dev->vsettings.brightness = (0xff00 &
c->value);
853 dev->vsettings.hue = (0xff00 &
c->value);
857 dev->vsettings.colour = (0xff00 &
c->value);
861 dev->vsettings.contrast = (0xff00 &
c->value);
865 dev->vsettings.hflip =
c->value ? 1: 0;
869 dev->vsettings.vflip =
c->value ? 1: 0;
959 switch (
dev->vsettings.palette) {
960 case STK11XX_PALETTE_RGB24:
966 case STK11XX_PALETTE_RGB32:
972 case STK11XX_PALETTE_BGR24:
978 case STK11XX_PALETTE_BGR32:
984 case STK11XX_PALETTE_UYVY:
990 case STK11XX_PALETTE_YUYV:
1015 switch (
dev->webcam_type) {
1056 fmtd->fmt.pix.priv = 0;
1058 switch (
fmtd->fmt.pix.pixelformat) {
1061 dev->vsettings.depth = 24;
1062 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 3;
1063 fmtd->fmt.pix.bytesperline = 3 *
fmtd->fmt.pix.width;
1068 dev->vsettings.depth = 32;
1069 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 4;
1070 fmtd->fmt.pix.bytesperline = 4 *
fmtd->fmt.pix.width;
1075 dev->vsettings.depth = 16;
1076 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 2;
1077 fmtd->fmt.pix.bytesperline = 2 *
fmtd->fmt.pix.width;
1097 fmtd->fmt.pix.priv = 0;
1099 switch (
fmtd->fmt.pix.pixelformat) {
1101 dev->vsettings.depth = 24;
1102 dev->vsettings.palette = STK11XX_PALETTE_RGB24;
1103 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 3;
1104 fmtd->fmt.pix.bytesperline = 3 *
fmtd->fmt.pix.width;
1108 dev->vsettings.depth = 32;
1109 dev->vsettings.palette = STK11XX_PALETTE_RGB32;
1110 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 4;
1111 fmtd->fmt.pix.bytesperline = 4 *
fmtd->fmt.pix.width;
1115 dev->vsettings.depth = 24;
1116 dev->vsettings.palette = STK11XX_PALETTE_BGR24;
1117 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 3;
1118 fmtd->fmt.pix.bytesperline = 3 *
fmtd->fmt.pix.width;
1122 dev->vsettings.depth = 32;
1123 dev->vsettings.palette = STK11XX_PALETTE_BGR32;
1124 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 4;
1125 fmtd->fmt.pix.bytesperline = 4 *
fmtd->fmt.pix.width;
1129 dev->vsettings.depth = 16;
1130 dev->vsettings.palette = STK11XX_PALETTE_UYVY;
1131 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 2;
1132 fmtd->fmt.pix.bytesperline = 2 *
fmtd->fmt.pix.width;
1136 dev->vsettings.depth = 16;
1137 dev->vsettings.palette = STK11XX_PALETTE_YUYV;
1138 fmtd->fmt.pix.sizeimage =
fmtd->fmt.pix.width *
fmtd->fmt.pix.height * 2;
1139 fmtd->fmt.pix.bytesperline = 2 *
fmtd->fmt.pix.width;
1146 STK_DEBUG(
"Set width=%d, height=%d\n",
fmtd->fmt.pix.width,
fmtd->fmt.pix.height);
1161 STK_ERROR(
"Select video mode failed !\n");
1218 if (
std->index != 0)
1238 nbuffers =
rb->count;
1242 else if (nbuffers >
dev->nbuffers)
1243 nbuffers =
dev->nbuffers;
1245 rb->count =
dev->nbuffers;
1271 buf->m.offset = index *
dev->len_per_image;
1272 buf->bytesused =
dev->view_size;
1275 buf->length =
dev->len_per_image;
1291 if (
buf->index < 0 ||
buf->index >=
dev->nbuffers)
1311 while (
dev->full_frames ==
NULL) {
1312 if (
dev->error_status) {
1316 return -
dev->error_status;
1333 STK_DEBUG(
"VIDIOC_DQBUF : frame ready.\n");
1340 buf->index =
dev->fill_image;
1341 buf->bytesused =
dev->view_size;
1347 buf->m.offset =
dev->fill_image *
dev->len_per_image;
1348 buf->length =
dev->len_per_image;
1379 sp->parm.capture.capability = 0;
1380 sp->parm.capture.capturemode = 0;
1381 sp->parm.capture.timeperframe.numerator = 1;
1382 sp->parm.capture.timeperframe.denominator = 30;
1383 sp->parm.capture.readbuffers = 2;
1384 sp->parm.capture.extendedmode = 0;
1461 unsigned int cmd,
unsigned long arg)
1470 STK_DEBUG(
"v4l_stk11xx_ioctl %02X\n", (
unsigned char)
cmd);
1503 dev->vdev->parent = &
dev->interface->dev;
1506 dev->vdev->minor = -1;
1515 STK_INFO(
"Syntek USB2.0 Camera is now controlling video device /dev/video%d\n",
dev->vdev->minor);
1532 STK_INFO(
"Syntek USB2.0 Camera release resources video device /dev/video%d\n",
dev->vdev->minor);
1554#if defined(CONFIG_COMPAT) && defined(v4l_compat_ioctl32)
int stk11xx_reset_buffers(struct usb_stk11xx *dev)
Reset all ISOC buffers.
int stk11xx_handle_frame(struct usb_stk11xx *dev)
Handler frame.
int stk11xx_free_buffers(struct usb_stk11xx *dev)
Release all buffers.
void stk11xx_next_image(struct usb_stk11xx *dev)
Prepare the next image.
int stk11xx_allocate_buffers(struct usb_stk11xx *dev)
Allocate all ISOC buffers.
int stk11xx_clear_buffers(struct usb_stk11xx *dev)
Clear current buffers.
int dev_stk11xx_camera_asleep(struct usb_stk11xx *dev)
Wake-up the camera.
int dev_stk11xx_reconf_camera(struct usb_stk11xx *dev)
Reconfigure the camera before the stream.
int dev_stk11xx_camera_off(struct usb_stk11xx *dev)
This function switchs off the camera.
int dev_stk11xx_stop_stream(struct usb_stk11xx *dev)
This function sets the device to stop the stream.
int dev_stk11xx_camera_settings(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.
int dev_stk11xx_start_stream(struct usb_stk11xx *dev)
This function sets the device to start the stream.
int dev_stk11xx_init_camera(struct usb_stk11xx *dev)
This function initializes the device for the stream.
int dev_stk11xx_camera_on(struct usb_stk11xx *dev)
This function switchs on the camera.
void usb_stk11xx_isoc_cleanup(struct usb_stk11xx *dev)
Clean-up all the ISOC buffers.
int usb_stk11xx_isoc_init(struct usb_stk11xx *dev)
Initilize an isochronous pipe.
static struct v4l2_file_operations v4l_stk11xx_fops
static unsigned int v4l_stk11xx_poll(struct file *fp, poll_table *wait)
Polling function.
static int v4l_stk11xx_mmap(struct file *fp, struct vm_area_struct *vma)
Memory map.
static struct v4l2_queryctrl stk11xx_controls[]
int v4l_stk11xx_register_video_device(struct usb_stk11xx *dev)
Register the video device.
int v4l_stk11xx_select_video_mode(struct usb_stk11xx *dev, int width, int height)
Select a video mode.
int v4l_stk11xx_unregister_video_device(struct usb_stk11xx *dev)
Unregister the video device.
const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES]
static int v4l_stk11xx_open(struct file *fp)
Open the video device.
static long v4l_stk11xx_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
Manage IOCTL.
static long v4l_stk11xx_do_ioctl(struct file *fp, unsigned int cmd, void __user *arg)
Manage IOCTL.
static int v4l_stk11xx_release(struct file *fp)
Release an opened file.
static ssize_t v4l_stk11xx_read(struct file *fp, char __user *buf, size_t count, loff_t *f_pos)
Read the video device.
Driver for Syntek USB video camera.
#define STK_ERROR(str, args...)
#define STK_INFO(str, args...)
#define STK_STREAM(str, args...)
#define STK_DEBUG(str, args...)
#define STK11XX_MAX_IMAGES
#define DRIVER_VERSION_NUM