2 * SPCA506 chip based cameras function
3 * M Xhaard 15/04/2004 based on different work Mark Taylor and others
4 * and my own snoopy file on a pv-321c donate by a german compagny
5 * "Firma Frank Gmbh" from Saarbruecken
7 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define MODULE_NAME "spca506"
28 #define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
29 static const char version[] = "2.1.7";
31 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
32 MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
33 MODULE_LICENSE("GPL");
35 /* specific webcam descriptor */
37 struct gspca_dev gspca_dev; /* !! must be the first item */
40 __u8 tmpbuf[640 * 480 * 3]; /* YYUV per line */
41 __u8 tmpbuf2[640 * 480 * 2]; /* YUYV */
43 unsigned char brightness;
44 unsigned char contrast;
51 /* V4L2 controls supported by the driver */
52 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
53 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
54 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
55 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
56 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
57 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
58 static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
59 static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
61 static struct ctrl sd_ctrls[] = {
62 #define SD_BRIGHTNESS 0
65 .id = V4L2_CID_BRIGHTNESS,
66 .type = V4L2_CTRL_TYPE_INTEGER,
71 .default_value = 0x80,
73 .set = sd_setbrightness,
74 .get = sd_getbrightness,
79 .id = V4L2_CID_CONTRAST,
80 .type = V4L2_CTRL_TYPE_INTEGER,
85 .default_value = 0x47,
87 .set = sd_setcontrast,
88 .get = sd_getcontrast,
93 .id = V4L2_CID_SATURATION,
94 .type = V4L2_CTRL_TYPE_INTEGER,
99 .default_value = 0x40,
108 .type = V4L2_CTRL_TYPE_INTEGER,
120 static struct v4l2_pix_format vga_mode[] = {
121 {160, 120, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
122 .bytesperline = 160 * 2,
123 .sizeimage = 160 * 120 * 2,
124 .colorspace = V4L2_COLORSPACE_SRGB,
126 {176, 144, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
127 .bytesperline = 176 * 2,
128 .sizeimage = 176 * 144 * 2,
129 .colorspace = V4L2_COLORSPACE_SRGB,
131 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
132 .bytesperline = 320 * 2,
133 .sizeimage = 320 * 240 * 2,
134 .colorspace = V4L2_COLORSPACE_SRGB,
136 {352, 288, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
137 .bytesperline = 352 * 2,
138 .sizeimage = 352 * 288 * 2,
139 .colorspace = V4L2_COLORSPACE_SRGB,
141 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
142 .bytesperline = 640 * 2,
143 .sizeimage = 640 * 480 * 2,
144 .colorspace = V4L2_COLORSPACE_SRGB,
148 #define SPCA50X_OFFSET_DATA 10
150 #define SAA7113_bright 0x0a /* defaults 0x80 */
151 #define SAA7113_contrast 0x0b /* defaults 0x47 */
152 #define SAA7113_saturation 0x0c /* defaults 0x40 */
153 #define SAA7113_hue 0x0d /* defaults 0x00 */
154 #define SAA7113_I2C_BASE_WRITE 0x4a
156 /* read 'len' bytes to gspca_dev->usb_buf */
157 static void reg_r(struct gspca_dev *gspca_dev,
162 usb_control_msg(gspca_dev->dev,
163 usb_rcvctrlpipe(gspca_dev->dev, 0),
165 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
167 index, gspca_dev->usb_buf, length,
171 static void reg_w(struct usb_device *dev,
177 usb_sndctrlpipe(dev, 0),
179 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
184 static void spca506_Initi2c(struct gspca_dev *gspca_dev)
186 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
189 static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
194 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
195 reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
197 reg_r(gspca_dev, 0x07, 0x0003, 2);
198 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
203 static int spca506_ReadI2c(struct gspca_dev *gspca_dev, __u16 reg)
207 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
208 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
209 reg_w(gspca_dev->dev, 0x07, 0x01, 0x0002);
211 reg_r(gspca_dev, 0x07, 0x0003, 2);
212 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
217 reg_r(gspca_dev, 0x07, 0x0000, 1);
218 return gspca_dev->usb_buf[0];
221 static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
225 struct sd *sd = (struct sd *) gspca_dev;
226 /* fixme: check if channel == 0..3 and 6..9 (8 values) */
229 __u8 videomask = 0x00;
231 PDEBUG(D_STREAM, "** Open Set Norme **");
232 spca506_Initi2c(gspca_dev);
233 /* NTSC bit0 -> 1(525 l) PAL SECAM bit0 -> 0 (625 l) */
234 /* Composite channel bit1 -> 1 S-video bit 1 -> 0 */
235 /* and exclude SAA7113 reserved channel set default 0 otherwise */
236 if (norme & V4L2_STD_NTSC)
238 if (channel == 4 || channel == 5 || channel > 9)
242 videomask = (0x48 | setbit0 | setbit1);
243 reg_w(gspca_dev->dev, 0x08, videomask, 0x0000);
244 spca506_WriteI2c(gspca_dev, (0xc0 | (channel & 0x0F)), 0x02);
246 if (norme & V4L2_STD_NTSC)
247 spca506_WriteI2c(gspca_dev, 0x33, 0x0e);
248 /* Chrominance Control NTSC N */
249 else if (norme & V4L2_STD_SECAM)
250 spca506_WriteI2c(gspca_dev, 0x53, 0x0e);
251 /* Chrominance Control SECAM */
253 spca506_WriteI2c(gspca_dev, 0x03, 0x0e);
254 /* Chrominance Control PAL BGHIV */
257 sd->channel = channel;
258 PDEBUG(D_STREAM, "Set Video Byte to 0x%2x", videomask);
259 PDEBUG(D_STREAM, "Set Norme: %08x Channel %d", norme, channel);
262 static void spca506_GetNormeInput(struct gspca_dev *gspca_dev,
263 __u16 *norme, __u16 *channel)
265 struct sd *sd = (struct sd *) gspca_dev;
267 /* Read the register is not so good value change so
268 we use your own copy in spca50x struct */
270 *channel = sd->channel;
271 PDEBUG(D_STREAM, "Get Norme: %d Channel %d", *norme, *channel);
274 static void spca506_Setsize(struct gspca_dev *gspca_dev, __u16 code,
275 __u16 xmult, __u16 ymult)
277 struct usb_device *dev = gspca_dev->dev;
279 PDEBUG(D_STREAM, "** SetSize **");
280 reg_w(dev, 0x04, (0x18 | (code & 0x07)), 0x0000);
281 /* Soft snap 0x40 Hard 0x41 */
282 reg_w(dev, 0x04, 0x41, 0x0001);
283 reg_w(dev, 0x04, 0x00, 0x0002);
285 reg_w(dev, 0x04, 0x00, 0x0003);
288 reg_w(dev, 0x04, 0x00, 0x0004);
290 reg_w(dev, 0x04, 0x01, 0x0005);
292 reg_w(dev, 0x04, xmult, 0x0006);
294 reg_w(dev, 0x04, ymult, 0x0007);
296 reg_w(dev, 0x04, 0x00, 0x0008);
298 reg_w(dev, 0x04, 0x00, 0x0009);
300 reg_w(dev, 0x04, 0x21, 0x000a);
302 reg_w(dev, 0x04, 0x00, 0x000b);
305 /* this function is called at probe time */
306 static int sd_config(struct gspca_dev *gspca_dev,
307 const struct usb_device_id *id)
309 struct sd *sd = (struct sd *) gspca_dev;
312 cam = &gspca_dev->cam;
313 cam->dev_name = (char *) id->driver_info;
315 cam->cam_mode = vga_mode;
316 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
317 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
318 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
319 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
320 sd->hue = sd_ctrls[SD_HUE].qctrl.default_value;
324 /* this function is called at open time */
325 static int sd_open(struct gspca_dev *gspca_dev)
327 struct usb_device *dev = gspca_dev->dev;
329 reg_w(dev, 0x03, 0x00, 0x0004);
330 reg_w(dev, 0x03, 0xFF, 0x0003);
331 reg_w(dev, 0x03, 0x00, 0x0000);
332 reg_w(dev, 0x03, 0x1c, 0x0001);
333 reg_w(dev, 0x03, 0x18, 0x0001);
334 /* Init on PAL and composite input0 */
335 spca506_SetNormeInput(gspca_dev, 0, 0);
336 reg_w(dev, 0x03, 0x1c, 0x0001);
337 reg_w(dev, 0x03, 0x18, 0x0001);
338 reg_w(dev, 0x05, 0x00, 0x0000);
339 reg_w(dev, 0x05, 0xef, 0x0001);
340 reg_w(dev, 0x05, 0x00, 0x00c1);
341 reg_w(dev, 0x05, 0x00, 0x00c2);
342 reg_w(dev, 0x06, 0x18, 0x0002);
343 reg_w(dev, 0x06, 0xf5, 0x0011);
344 reg_w(dev, 0x06, 0x02, 0x0012);
345 reg_w(dev, 0x06, 0xfb, 0x0013);
346 reg_w(dev, 0x06, 0x00, 0x0014);
347 reg_w(dev, 0x06, 0xa4, 0x0051);
348 reg_w(dev, 0x06, 0x40, 0x0052);
349 reg_w(dev, 0x06, 0x71, 0x0053);
350 reg_w(dev, 0x06, 0x40, 0x0054);
351 /************************************************/
352 reg_w(dev, 0x03, 0x00, 0x0004);
353 reg_w(dev, 0x03, 0x00, 0x0003);
354 reg_w(dev, 0x03, 0x00, 0x0004);
355 reg_w(dev, 0x03, 0xFF, 0x0003);
356 reg_w(dev, 0x02, 0x00, 0x0000);
357 reg_w(dev, 0x03, 0x60, 0x0000);
358 reg_w(dev, 0x03, 0x18, 0x0001);
359 /* for a better reading mx :) */
360 /*sdca506_WriteI2c(value,register) */
361 spca506_Initi2c(gspca_dev);
362 spca506_WriteI2c(gspca_dev, 0x08, 0x01);
363 spca506_WriteI2c(gspca_dev, 0xc0, 0x02);
364 /* input composite video */
365 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
366 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
367 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
368 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
369 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
370 spca506_WriteI2c(gspca_dev, 0x98, 0x08);
371 spca506_WriteI2c(gspca_dev, 0x03, 0x09);
372 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
373 spca506_WriteI2c(gspca_dev, 0x47, 0x0b);
374 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
375 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
376 spca506_WriteI2c(gspca_dev, 0x03, 0x0e); /* Chroma Pal adjust */
377 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
378 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
379 spca506_WriteI2c(gspca_dev, 0x0c, 0x11);
380 spca506_WriteI2c(gspca_dev, 0xb8, 0x12);
381 spca506_WriteI2c(gspca_dev, 0x01, 0x13);
382 spca506_WriteI2c(gspca_dev, 0x00, 0x14);
383 spca506_WriteI2c(gspca_dev, 0x00, 0x15);
384 spca506_WriteI2c(gspca_dev, 0x00, 0x16);
385 spca506_WriteI2c(gspca_dev, 0x00, 0x17);
386 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
387 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
388 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
389 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
390 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
391 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
392 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
393 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
394 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
395 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
396 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
397 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
398 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
399 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
400 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
401 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
402 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
403 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
404 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
405 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
406 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
407 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
408 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
409 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
410 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
411 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
412 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
413 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
414 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
415 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
416 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
417 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
418 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
419 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
420 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
421 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
422 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
423 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
424 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
425 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
426 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
427 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
428 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
429 PDEBUG(D_STREAM, "** Close Init *");
433 static void sd_start(struct gspca_dev *gspca_dev)
435 struct usb_device *dev = gspca_dev->dev;
439 /**************************************/
440 reg_w(dev, 0x03, 0x00, 0x0004);
441 reg_w(dev, 0x03, 0x00, 0x0003);
442 reg_w(dev, 0x03, 0x00, 0x0004);
443 reg_w(dev, 0x03, 0xFF, 0x0003);
444 reg_w(dev, 0x02, 0x00, 0x0000);
445 reg_w(dev, 0x03, 0x60, 0x0000);
446 reg_w(dev, 0x03, 0x18, 0x0001);
448 /*sdca506_WriteI2c(value,register) */
449 spca506_Initi2c(gspca_dev);
450 spca506_WriteI2c(gspca_dev, 0x08, 0x01); /* Increment Delay */
451 /* spca506_WriteI2c(gspca_dev, 0xc0, 0x02); * Analog Input Control 1 */
452 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
453 /* Analog Input Control 2 */
454 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
455 /* Analog Input Control 3 */
456 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
457 /* Analog Input Control 4 */
458 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
459 /* Horizontal Sync Start 0xe9-0x0d */
460 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
461 /* Horizontal Sync Stop 0x0d-0xf0 */
463 spca506_WriteI2c(gspca_dev, 0x98, 0x08); /* Sync Control */
465 spca506_WriteI2c(gspca_dev, 0x03, 0x09); /* Luminance Control */
466 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
467 /* Luminance Brightness */
468 spca506_WriteI2c(gspca_dev, 0x47, 0x0b); /* Luminance Contrast */
469 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
470 /* Chrominance Saturation */
471 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
472 /* Chrominance Hue Control */
473 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
474 /* Chrominance Gain Control */
475 /**************************************/
476 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
477 /* Format/Delay Control */
478 spca506_WriteI2c(gspca_dev, 0x0c, 0x11); /* Output Control 1 */
479 spca506_WriteI2c(gspca_dev, 0xb8, 0x12); /* Output Control 2 */
480 spca506_WriteI2c(gspca_dev, 0x01, 0x13); /* Output Control 3 */
481 spca506_WriteI2c(gspca_dev, 0x00, 0x14); /* reserved */
482 spca506_WriteI2c(gspca_dev, 0x00, 0x15); /* VGATE START */
483 spca506_WriteI2c(gspca_dev, 0x00, 0x16); /* VGATE STOP */
484 spca506_WriteI2c(gspca_dev, 0x00, 0x17); /* VGATE Control (MSB) */
485 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
486 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
487 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
488 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
489 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
490 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
491 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
492 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
493 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
494 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
495 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
496 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
497 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
498 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
499 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
500 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
501 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
502 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
503 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
504 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
505 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
506 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
507 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
508 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
509 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
510 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
511 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
512 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
513 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
514 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
515 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
516 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
517 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
518 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
519 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
520 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
521 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
522 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
523 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
524 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
525 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
526 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
527 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
528 /**************************************/
529 reg_w(dev, 0x05, 0x00, 0x0003);
530 reg_w(dev, 0x05, 0x00, 0x0004);
531 reg_w(dev, 0x03, 0x10, 0x0001);
532 reg_w(dev, 0x03, 0x78, 0x0000);
533 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
535 spca506_Setsize(gspca_dev, 0, 0x10, 0x10);
538 spca506_Setsize(gspca_dev, 1, 0x1a, 0x1a);
541 spca506_Setsize(gspca_dev, 2, 0x1c, 0x1c);
544 spca506_Setsize(gspca_dev, 4, 0x34, 0x34);
548 spca506_Setsize(gspca_dev, 5, 0x40, 0x40);
552 /* compress setting and size */
554 reg_w(dev, 0x02, 0x01, 0x0000);
555 reg_w(dev, 0x03, 0x12, 0x0000);
556 reg_r(gspca_dev, 0x04, 0x0001, 2);
557 PDEBUG(D_STREAM, "webcam started");
558 spca506_GetNormeInput(gspca_dev, &norme, &channel);
559 spca506_SetNormeInput(gspca_dev, norme, channel);
562 static void sd_stopN(struct gspca_dev *gspca_dev)
564 struct usb_device *dev = gspca_dev->dev;
566 reg_w(dev, 0x02, 0x00, 0x0000);
567 reg_w(dev, 0x03, 0x00, 0x0004);
568 reg_w(dev, 0x03, 0x00, 0x0003);
571 static void sd_stop0(struct gspca_dev *gspca_dev)
575 static void sd_close(struct gspca_dev *gspca_dev)
579 /* convert YYUV per line to YUYV (YUV 4:2:2) */
580 static void yyuv_decode(unsigned char *out,
585 unsigned char *Ui, *Vi, *yi, *yi1;
590 for (i = height / 2; --i >= 0; ) {
591 out1 = out + width * 2; /* next line */
595 for (j = width / 2; --j >= 0; ) {
596 *out++ = 128 + *yi++;
598 *out++ = 128 + *yi++;
601 *out1++ = 128 + *yi1++;
602 *out1++ = 128 + *Ui++;
603 *out1++ = 128 + *yi1++;
604 *out1++ = 128 + *Vi++;
611 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
612 struct gspca_frame *frame, /* target */
613 __u8 *data, /* isoc packet */
614 int len) /* iso packet length */
616 struct sd *sd = (struct sd *) gspca_dev;
619 case 0: /* start of frame */
620 if (gspca_dev->last_packet_type == FIRST_PACKET) {
621 yyuv_decode(sd->tmpbuf2, sd->tmpbuf,
624 frame = gspca_frame_add(gspca_dev,
632 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
634 data += SPCA50X_OFFSET_DATA;
635 len -= SPCA50X_OFFSET_DATA;
637 memcpy(sd->tmpbuf, data, len);
642 case 0xff: /* drop */
643 /* gspca_dev->last_packet_type = DISCARD_PACKET; */
648 memcpy(&sd->tmpbuf[sd->buflen], data, len);
652 static void setbrightness(struct gspca_dev *gspca_dev)
654 struct sd *sd = (struct sd *) gspca_dev;
656 spca506_Initi2c(gspca_dev);
657 spca506_WriteI2c(gspca_dev, sd->brightness, SAA7113_bright);
658 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
661 static void getbrightness(struct gspca_dev *gspca_dev)
663 struct sd *sd = (struct sd *) gspca_dev;
665 sd->brightness = spca506_ReadI2c(gspca_dev, SAA7113_bright);
668 static void setcontrast(struct gspca_dev *gspca_dev)
670 struct sd *sd = (struct sd *) gspca_dev;
672 spca506_Initi2c(gspca_dev);
673 spca506_WriteI2c(gspca_dev, sd->contrast, SAA7113_contrast);
674 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
677 static void getcontrast(struct gspca_dev *gspca_dev)
679 struct sd *sd = (struct sd *) gspca_dev;
681 sd->contrast = spca506_ReadI2c(gspca_dev, SAA7113_contrast);
684 static void setcolors(struct gspca_dev *gspca_dev)
686 struct sd *sd = (struct sd *) gspca_dev;
688 spca506_Initi2c(gspca_dev);
689 spca506_WriteI2c(gspca_dev, sd->colors, SAA7113_saturation);
690 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
693 static void getcolors(struct gspca_dev *gspca_dev)
695 struct sd *sd = (struct sd *) gspca_dev;
697 sd->colors = spca506_ReadI2c(gspca_dev, SAA7113_saturation);
700 static void sethue(struct gspca_dev *gspca_dev)
702 struct sd *sd = (struct sd *) gspca_dev;
704 spca506_Initi2c(gspca_dev);
705 spca506_WriteI2c(gspca_dev, sd->hue, SAA7113_hue);
706 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
709 static void gethue(struct gspca_dev *gspca_dev)
711 struct sd *sd = (struct sd *) gspca_dev;
713 sd->hue = spca506_ReadI2c(gspca_dev, SAA7113_hue);
716 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
718 struct sd *sd = (struct sd *) gspca_dev;
720 sd->brightness = val;
721 if (gspca_dev->streaming)
722 setbrightness(gspca_dev);
726 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
728 struct sd *sd = (struct sd *) gspca_dev;
730 getbrightness(gspca_dev);
731 *val = sd->brightness;
735 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
737 struct sd *sd = (struct sd *) gspca_dev;
740 if (gspca_dev->streaming)
741 setcontrast(gspca_dev);
745 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
747 struct sd *sd = (struct sd *) gspca_dev;
749 getcontrast(gspca_dev);
754 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
756 struct sd *sd = (struct sd *) gspca_dev;
759 if (gspca_dev->streaming)
760 setcolors(gspca_dev);
764 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
766 struct sd *sd = (struct sd *) gspca_dev;
768 getcolors(gspca_dev);
773 static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
775 struct sd *sd = (struct sd *) gspca_dev;
778 if (gspca_dev->streaming)
783 static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
785 struct sd *sd = (struct sd *) gspca_dev;
792 /* sub-driver description */
793 static struct sd_desc sd_desc = {
796 .nctrls = ARRAY_SIZE(sd_ctrls),
803 .pkt_scan = sd_pkt_scan,
806 /* -- module initialisation -- */
807 #define DVNM(name) .driver_info = (kernel_ulong_t) name
808 static __devinitdata struct usb_device_id device_table[] = {
809 {USB_DEVICE(0x06e1, 0xa190), DVNM("ADS Instant VCD")},
810 /* {USB_DEVICE(0x0733, 0x0430), DVNM("UsbGrabber PV321c")}, */
811 {USB_DEVICE(0x0734, 0x043b), DVNM("3DeMon USB Capture aka")},
812 {USB_DEVICE(0x99fa, 0x8988), DVNM("Grandtec V.cap")},
815 MODULE_DEVICE_TABLE(usb, device_table);
817 /* -- device connect -- */
818 static int sd_probe(struct usb_interface *intf,
819 const struct usb_device_id *id)
821 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
825 static struct usb_driver sd_driver = {
827 .id_table = device_table,
829 .disconnect = gspca_disconnect,
832 /* -- module insert / remove -- */
833 static int __init sd_mod_init(void)
835 if (usb_register(&sd_driver) < 0)
837 PDEBUG(D_PROBE, "v%s registered", version);
840 static void __exit sd_mod_exit(void)
842 usb_deregister(&sd_driver);
843 PDEBUG(D_PROBE, "deregistered");
846 module_init(sd_mod_init);
847 module_exit(sd_mod_exit);