40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/kernel.h>
43 #include <linux/version.h>
44 #include <linux/errno.h>
45 #include <linux/slab.h>
46 #include <linux/kref.h>
48 #include <linux/usb.h>
49 #include <media/v4l2-common.h>
50 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)
51 #include <media/v4l2-ioctl.h>
57 int dev_stk0408_check_device(
struct usb_stk11xx *dev);
58 int dev_stk0408_select_input(
struct usb_stk11xx *dev,
int input);
59 int dev_stk0408_write0(
struct usb_stk11xx *dev,
int mask,
int val);
79 STK_INFO(
"Initialize USB2.0 Syntek Capture device\n");
91 dev_stk0408_write0(dev, 7, 4);
92 dev_stk0408_write0(dev, 7, 4);
93 dev_stk0408_write0(dev, 7, 6);
94 dev_stk0408_write0(dev, 7, 7);
95 dev_stk0408_write0(dev, 7, 6);
96 dev_stk0408_write0(dev, 7, 4);
97 dev_stk0408_write0(dev, 7, 5);
101 dev_stk0408_write0(dev, 7, 4);
102 dev_stk0408_write0(dev, 7, 4);
103 dev_stk0408_write0(dev, 7, 5);
130 dev_stk0408_write0(dev, 0x07f, 0x004);
131 dev_stk0408_write0(dev, 0x07f, 0x004);
132 dev_stk0408_write0(dev, 0x07f, 0x006);
133 dev_stk0408_write0(dev, 0x07f, 0x007);
134 dev_stk0408_write0(dev, 0x07f, 0x006);
135 dev_stk0408_write0(dev, 0x07f, 0x004);
136 dev_stk0408_write0(dev, 0x07f, 0x005);
137 dev_stk0408_write0(dev, 0x07f, 0x004);
138 dev_stk0408_write0(dev, 0x07f, 0x004);
139 dev_stk0408_write0(dev, 0x07f, 0x005);
140 dev_stk0408_write0(dev, 0x07f, 0x004);
141 dev_stk0408_write0(dev, 0x07f, 0x006);
142 dev_stk0408_write0(dev, 0x07f, 0x007);
143 dev_stk0408_write0(dev, 0x07f, 0x006);
144 dev_stk0408_write0(dev, 0x07f, 0x006);
145 dev_stk0408_write0(dev, 0x07f, 0x007);
146 dev_stk0408_write0(dev, 0x07f, 0x006);
147 dev_stk0408_write0(dev, 0x07f, 0x004);
148 dev_stk0408_write0(dev, 0x07f, 0x005);
149 dev_stk0408_write0(dev, 0x07f, 0x004);
150 dev_stk0408_write0(dev, 0x07f, 0x004);
151 dev_stk0408_write0(dev, 0x07f, 0x005);
152 dev_stk0408_write0(dev, 0x07f, 0x004);
153 dev_stk0408_write0(dev, 0x07f, 0x004);
154 dev_stk0408_write0(dev, 0x07f, 0x005);
155 dev_stk0408_write0(dev, 0x07f, 0x004);
156 dev_stk0408_write0(dev, 0x07f, 0x004);
157 dev_stk0408_write0(dev, 0x07f, 0x005);
167 STK_INFO(
"Syntek USB2.0 Capture device is ready\n");
172 int dev_stk0408_write0(
struct usb_stk11xx *dev,
int mask,
int val)
184 int dev_stk0408_write_208(
struct usb_stk11xx *dev,
int val)
195 retok = dev_stk0408_check_device(dev);
207 int dev_stk0408_write_saa(
struct usb_stk11xx *dev,
int reg,
int val)
219 retok = dev_stk0408_check_device(dev);
230 int dev_stk0408_set_resolution(
struct usb_stk11xx *dev)
326 static const int ids[] = {
327 0x203,0x00d,0x00f,0x103,0x018,0x01b,0x01c,0x01a,0x019,
328 0x300,0x350,0x351,0x352,0x353,0x300,0x018,0x202,0x110,
329 0x111,0x112,0x113,0x114,0x115,0x116,0x117
332 const int values[] = {
333 0x04a,0x000,0x002,0x000,0x000,0x00e,0x046,0x014,0x000,
334 0x012,0x02d,0x001,0x000,0x000,0x080,0x010,0x00f,
371 asize = ARRAY_SIZE(values);
373 for(i=0; i<asize; i++) {
430 dev_stk0408_write_saa(dev, 0x02, 0x80);
431 dev_stk0408_write_208(dev,0x09);
432 dev_stk0408_write_saa(dev, 0x09, 0x00);
439 dev_stk0408_write_saa(dev, 0x02, 0x80);
440 dev_stk0408_write_208(dev,0x09);
441 dev_stk0408_write_saa(dev, 0x09, 0x00);
491 dev_stk0408_write_saa(dev, 0x02, 0x80);
492 dev_stk0408_write_208(dev,0x09);
493 dev_stk0408_write_saa(dev, 0x09, 0x00);
497 if ((step == 4 )|| (step == 6))
499 dev_stk0408_write_saa(dev, 0x02, 0x80);
500 dev_stk0408_write_208(dev,0x09);
501 dev_stk0408_write_saa(dev, 0x09, 0x00);
502 dev_stk0408_write_208(dev,0x0e);
503 dev_stk0408_write_saa(dev, 0x0e, 0x01);
505 dev_stk0408_set_resolution(dev);
515 dev_stk0408_write_208(dev,0x0e);
516 dev_stk0408_write_saa(dev, 0x0e, 0x01);
518 dev_stk0408_set_resolution( dev);
567 int dev_stk0408_select_input(
struct usb_stk11xx *dev,
int input)
611 value = value & 0x7f;
650 int dev_stk0408_check_device(
struct usb_stk11xx *dev)
656 for (i=0; i < retry; i++) {
662 if (value == 0x04 || value == 0x01)
667 STK_ERROR(
"Check device return error (0x0201 = %02X) !\n", value);
694 static const int registers[] = {
695 0x01,0x03,0x04,0x05,0x06,0x07,0x08,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,
696 0x13,0x15,0x16,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,
697 0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b };
699 const int values[] = {
700 0x08,0x33,0x00,0x00,0xe9,0x0d,
702 0x80,0x47,0x40,0x00,0x01,0x2a,0x00,0x0c,0xe7,
703 0x00,0x00,0x00,0x02,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
704 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x55,0xff,0xff,0xff,0x40,0x54,
708 asize = ARRAY_SIZE(values);
710 for(i=0; i<asize; i++) {
711 retok = dev_stk0408_write_saa(dev, registers[i], values[i]);
714 STK_ERROR(
"Load default sensor settings fail !\n");
761 dev_stk0408_write_saa(dev, 0x0d, (dev->
vsettings.
colour - 32768) >> 8);
763 dev_stk0408_write_saa(dev, 0x0c, (dev->
vsettings.
hue) >> 9);
804 int value_116, value_117;
871 void stk11xx_copy_uvyv(uint8_t *src, uint8_t *rgb,
875 const int hfactor,
const int vfactor,
876 bool order,
bool field)
878 int width = image->
x;
879 int height = image->
y;
883 uint8_t *line1 = NULL;
884 uint8_t *line2 = NULL;
886 static uint8_t *prev=0;
901 for ( y=0; y < height/2; y++)
907 line1 = rgb + (y*width*4);
908 line2 = rgb + (y*width*4) + width*2;
912 line1 = rgb + (y*width*4) + width*2;
913 line2 = rgb + (y*width*4);
918 line1 = rgb + (y*width*2);
922 if (order && hfactor == 1)
924 memcpy(line1,src,width*2);
929 for ( x = 0; x < width*2; x+=4)
945 src += (4 * hfactor);
951 memcpy(line2,prev,width*2);
954 else if (vfactor == 2)
957 else if (vfactor == 4)
972 #define CLAMP(x) x < 0 ? 0 : x > 255 ? 255 : x
974 void stk11xx_copy_rgb(uint8_t *src, uint8_t *rgb,
977 const int hflip,
const int vflip,
978 const int hfactor,
const int vfactor,
979 bool order,
bool four,
bool field)
982 int width = image->
x;
983 int height = image->
y;
990 uint8_t *line1 = NULL;
991 uint8_t *line2 = NULL;
993 static uint8_t *prev=0;
1001 prev += width * step;
1005 for ( y=0; y < height/2; y++)
1011 line1 = rgb + (y * width * step * 2);
1012 line2 = rgb + (y * width * step * 2) + width * step;
1016 line1 = rgb + (y * width * step * 2) + width * step;
1017 line2 = rgb + (y * width * step * 2);
1022 line1 = rgb + (y * width * step);
1026 for ( x = 0; x < width*step; x+=step)
1037 int c = src[off ? 3 : 1];
1038 int d = src[0] - 128;
1039 int e = src[2] - 128;
1041 int R = ((298*c + 409 * e + 128) >>8);
1042 int G = ((298*c - 100 * d - 208 * e + 128)>>8);
1043 int B = ((298*c + 516 * d + 128)>>8);
1066 src += (4 * hfactor);
1079 for ( x = 0; x < width * step; x++ )
1081 line2[x] = (*prev++);
1083 prev += width * step;
1105 framebuf = dev->read_frame;
1107 if (framebuf == NULL)
1110 image = dev->image_data;
1111 STK_DEBUG(
"fill image %d\n", dev->fill_image);
1113 image += dev->images[dev->fill_image].
offset;
1115 data = framebuf->data;
1116 odd = framebuf->odd;
1118 switch (dev->resolution) {
1135 case STK11XX_640x480:
1137 case STK11XX_720x576:
1147 case STK11XX_PALETTE_RGB24:
1148 stk11xx_copy_rgb(data, image, &dev->image, &dev->view, dev->
vsettings.
hflip, dev->
vsettings.
vflip, hfactor, vfactor,
false,
false,odd);
1150 case STK11XX_PALETTE_RGB32:
1151 stk11xx_copy_rgb(data, image, &dev->image, &dev->view, dev->
vsettings.
hflip, dev->
vsettings.
vflip, hfactor, vfactor,
false,
true,odd);
1153 case STK11XX_PALETTE_BGR24:
1154 stk11xx_copy_rgb(data, image, &dev->image, &dev->view, dev->
vsettings.
hflip, dev->
vsettings.
vflip, hfactor, vfactor,
true,
false,odd);
1156 case STK11XX_PALETTE_BGR32:
1157 stk11xx_copy_rgb(data, image, &dev->image, &dev->view, dev->
vsettings.
hflip, dev->
vsettings.
vflip, hfactor, vfactor,
true,
true,odd);
1160 case STK11XX_PALETTE_UYVY:
1163 case STK11XX_PALETTE_YUYV:
int dev_stk0408_initialize_device(struct usb_stk11xx *dev)
This function initializes the device.
int dev_stk0408_camera_asleep(struct usb_stk11xx *dev)
Wake-up the camera.
const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES]
int dev_stk11xx_camera_off(struct usb_stk11xx *dev)
This function switchs off the camera.
int dev_stk11xx_camera_on(struct usb_stk11xx *dev)
This function switchs on the camera.
int dev_stk11xx_camera_settings(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.
int dev_stk0408_camera_settings(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.
#define STK_DEBUG(str, args...)
#define STK_ERROR(str, args...)
int dev_stk0408_init_camera(struct usb_stk11xx *dev)
This function initializes the device for the stream.
struct stk11xx_video vsettings
int dev_stk11xx_check_device(struct usb_stk11xx *dev, int nbr)
This function permits to check the device in reading the register 0x0201.
int dev_stk0408_sensor_settings(struct usb_stk11xx *dev)
This function sets the default sensor settings.
int dev_stk0408_reconf_camera(struct usb_stk11xx *dev)
Reconfigure the camera before the stream.
int usb_stk11xx_set_feature(struct usb_stk11xx *dev, int index)
Send the message SET_FEATURE and choose the interface.
int dev_stk0408_stop_stream(struct usb_stk11xx *dev)
This function sets the device to stop the stream.
int dev_stk0408_configure_device(struct usb_stk11xx *dev, int step)
This function configures the device.
int dev_stk0408_start_stream(struct usb_stk11xx *dev)
This function sets the device to start the stream.
#define STK_INFO(str, args...)
int usb_stk11xx_write_registry(struct usb_stk11xx *dev, __u16 index, __u16 value)
Write a 16-bits value to a 16-bits register.
int usb_stk11xx_read_registry(struct usb_stk11xx *dev, __u16 index, int *value)
Read a 16-bits value from a 16-bits register.
Driver for Syntek USB video camera.
Driver for Syntek USB video camera.
int dev_stk0408_set_camera_quality(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.
int dev_stk0408_set_camera_fps(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.