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 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29 MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
30 MODULE_LICENSE("GPL");
32 /* specific webcam descriptor */
34 struct gspca_dev gspca_dev; /* !! must be the first item */
37 __u8 tmpbuf[640 * 480 * 3]; /* YYUV per line */
38 __u8 tmpbuf2[640 * 480 * 2]; /* YUYV */
40 unsigned char brightness;
41 unsigned char contrast;
48 /* V4L2 controls supported by the driver */
49 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
50 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
51 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
52 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
53 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
54 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
55 static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
56 static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
58 static struct ctrl sd_ctrls[] = {
59 #define SD_BRIGHTNESS 0
62 .id = V4L2_CID_BRIGHTNESS,
63 .type = V4L2_CTRL_TYPE_INTEGER,
68 .default_value = 0x80,
70 .set = sd_setbrightness,
71 .get = sd_getbrightness,
76 .id = V4L2_CID_CONTRAST,
77 .type = V4L2_CTRL_TYPE_INTEGER,
82 .default_value = 0x47,
84 .set = sd_setcontrast,
85 .get = sd_getcontrast,
90 .id = V4L2_CID_SATURATION,
91 .type = V4L2_CTRL_TYPE_INTEGER,
96 .default_value = 0x40,
105 .type = V4L2_CTRL_TYPE_INTEGER,
117 static struct v4l2_pix_format vga_mode[] = {
118 {160, 120, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
119 .bytesperline = 160 * 2,
120 .sizeimage = 160 * 120 * 2,
121 .colorspace = V4L2_COLORSPACE_SRGB,
123 {176, 144, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
124 .bytesperline = 176 * 2,
125 .sizeimage = 176 * 144 * 2,
126 .colorspace = V4L2_COLORSPACE_SRGB,
128 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
129 .bytesperline = 320 * 2,
130 .sizeimage = 320 * 240 * 2,
131 .colorspace = V4L2_COLORSPACE_SRGB,
133 {352, 288, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
134 .bytesperline = 352 * 2,
135 .sizeimage = 352 * 288 * 2,
136 .colorspace = V4L2_COLORSPACE_SRGB,
138 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
139 .bytesperline = 640 * 2,
140 .sizeimage = 640 * 480 * 2,
141 .colorspace = V4L2_COLORSPACE_SRGB,
145 #define SPCA50X_OFFSET_DATA 10
147 #define SAA7113_bright 0x0a /* defaults 0x80 */
148 #define SAA7113_contrast 0x0b /* defaults 0x47 */
149 #define SAA7113_saturation 0x0c /* defaults 0x40 */
150 #define SAA7113_hue 0x0d /* defaults 0x00 */
151 #define SAA7113_I2C_BASE_WRITE 0x4a
153 /* read 'len' bytes to gspca_dev->usb_buf */
154 static void reg_r(struct gspca_dev *gspca_dev,
159 usb_control_msg(gspca_dev->dev,
160 usb_rcvctrlpipe(gspca_dev->dev, 0),
162 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
164 index, gspca_dev->usb_buf, length,
168 static void reg_w(struct usb_device *dev,
174 usb_sndctrlpipe(dev, 0),
176 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
181 static void spca506_Initi2c(struct gspca_dev *gspca_dev)
183 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
186 static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
191 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
192 reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
194 reg_r(gspca_dev, 0x07, 0x0003, 2);
195 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
200 static int spca506_ReadI2c(struct gspca_dev *gspca_dev, __u16 reg)
204 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
205 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
206 reg_w(gspca_dev->dev, 0x07, 0x01, 0x0002);
208 reg_r(gspca_dev, 0x07, 0x0003, 2);
209 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
214 reg_r(gspca_dev, 0x07, 0x0000, 1);
215 return gspca_dev->usb_buf[0];
218 static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
222 struct sd *sd = (struct sd *) gspca_dev;
223 /* fixme: check if channel == 0..3 and 6..9 (8 values) */
226 __u8 videomask = 0x00;
228 PDEBUG(D_STREAM, "** Open Set Norme **");
229 spca506_Initi2c(gspca_dev);
230 /* NTSC bit0 -> 1(525 l) PAL SECAM bit0 -> 0 (625 l) */
231 /* Composite channel bit1 -> 1 S-video bit 1 -> 0 */
232 /* and exclude SAA7113 reserved channel set default 0 otherwise */
233 if (norme & V4L2_STD_NTSC)
235 if (channel == 4 || channel == 5 || channel > 9)
239 videomask = (0x48 | setbit0 | setbit1);
240 reg_w(gspca_dev->dev, 0x08, videomask, 0x0000);
241 spca506_WriteI2c(gspca_dev, (0xc0 | (channel & 0x0F)), 0x02);
243 if (norme & V4L2_STD_NTSC)
244 spca506_WriteI2c(gspca_dev, 0x33, 0x0e);
245 /* Chrominance Control NTSC N */
246 else if (norme & V4L2_STD_SECAM)
247 spca506_WriteI2c(gspca_dev, 0x53, 0x0e);
248 /* Chrominance Control SECAM */
250 spca506_WriteI2c(gspca_dev, 0x03, 0x0e);
251 /* Chrominance Control PAL BGHIV */
254 sd->channel = channel;
255 PDEBUG(D_STREAM, "Set Video Byte to 0x%2x", videomask);
256 PDEBUG(D_STREAM, "Set Norme: %08x Channel %d", norme, channel);
259 static void spca506_GetNormeInput(struct gspca_dev *gspca_dev,
260 __u16 *norme, __u16 *channel)
262 struct sd *sd = (struct sd *) gspca_dev;
264 /* Read the register is not so good value change so
265 we use your own copy in spca50x struct */
267 *channel = sd->channel;
268 PDEBUG(D_STREAM, "Get Norme: %d Channel %d", *norme, *channel);
271 static void spca506_Setsize(struct gspca_dev *gspca_dev, __u16 code,
272 __u16 xmult, __u16 ymult)
274 struct usb_device *dev = gspca_dev->dev;
276 PDEBUG(D_STREAM, "** SetSize **");
277 reg_w(dev, 0x04, (0x18 | (code & 0x07)), 0x0000);
278 /* Soft snap 0x40 Hard 0x41 */
279 reg_w(dev, 0x04, 0x41, 0x0001);
280 reg_w(dev, 0x04, 0x00, 0x0002);
282 reg_w(dev, 0x04, 0x00, 0x0003);
285 reg_w(dev, 0x04, 0x00, 0x0004);
287 reg_w(dev, 0x04, 0x01, 0x0005);
289 reg_w(dev, 0x04, xmult, 0x0006);
291 reg_w(dev, 0x04, ymult, 0x0007);
293 reg_w(dev, 0x04, 0x00, 0x0008);
295 reg_w(dev, 0x04, 0x00, 0x0009);
297 reg_w(dev, 0x04, 0x21, 0x000a);
299 reg_w(dev, 0x04, 0x00, 0x000b);
302 /* this function is called at probe time */
303 static int sd_config(struct gspca_dev *gspca_dev,
304 const struct usb_device_id *id)
306 struct sd *sd = (struct sd *) gspca_dev;
309 cam = &gspca_dev->cam;
311 cam->cam_mode = vga_mode;
312 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
313 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
314 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
315 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
316 sd->hue = sd_ctrls[SD_HUE].qctrl.default_value;
320 /* this function is called at open time */
321 static int sd_open(struct gspca_dev *gspca_dev)
323 struct usb_device *dev = gspca_dev->dev;
325 reg_w(dev, 0x03, 0x00, 0x0004);
326 reg_w(dev, 0x03, 0xFF, 0x0003);
327 reg_w(dev, 0x03, 0x00, 0x0000);
328 reg_w(dev, 0x03, 0x1c, 0x0001);
329 reg_w(dev, 0x03, 0x18, 0x0001);
330 /* Init on PAL and composite input0 */
331 spca506_SetNormeInput(gspca_dev, 0, 0);
332 reg_w(dev, 0x03, 0x1c, 0x0001);
333 reg_w(dev, 0x03, 0x18, 0x0001);
334 reg_w(dev, 0x05, 0x00, 0x0000);
335 reg_w(dev, 0x05, 0xef, 0x0001);
336 reg_w(dev, 0x05, 0x00, 0x00c1);
337 reg_w(dev, 0x05, 0x00, 0x00c2);
338 reg_w(dev, 0x06, 0x18, 0x0002);
339 reg_w(dev, 0x06, 0xf5, 0x0011);
340 reg_w(dev, 0x06, 0x02, 0x0012);
341 reg_w(dev, 0x06, 0xfb, 0x0013);
342 reg_w(dev, 0x06, 0x00, 0x0014);
343 reg_w(dev, 0x06, 0xa4, 0x0051);
344 reg_w(dev, 0x06, 0x40, 0x0052);
345 reg_w(dev, 0x06, 0x71, 0x0053);
346 reg_w(dev, 0x06, 0x40, 0x0054);
347 /************************************************/
348 reg_w(dev, 0x03, 0x00, 0x0004);
349 reg_w(dev, 0x03, 0x00, 0x0003);
350 reg_w(dev, 0x03, 0x00, 0x0004);
351 reg_w(dev, 0x03, 0xFF, 0x0003);
352 reg_w(dev, 0x02, 0x00, 0x0000);
353 reg_w(dev, 0x03, 0x60, 0x0000);
354 reg_w(dev, 0x03, 0x18, 0x0001);
355 /* for a better reading mx :) */
356 /*sdca506_WriteI2c(value,register) */
357 spca506_Initi2c(gspca_dev);
358 spca506_WriteI2c(gspca_dev, 0x08, 0x01);
359 spca506_WriteI2c(gspca_dev, 0xc0, 0x02);
360 /* input composite video */
361 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
362 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
363 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
364 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
365 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
366 spca506_WriteI2c(gspca_dev, 0x98, 0x08);
367 spca506_WriteI2c(gspca_dev, 0x03, 0x09);
368 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
369 spca506_WriteI2c(gspca_dev, 0x47, 0x0b);
370 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
371 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
372 spca506_WriteI2c(gspca_dev, 0x03, 0x0e); /* Chroma Pal adjust */
373 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
374 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
375 spca506_WriteI2c(gspca_dev, 0x0c, 0x11);
376 spca506_WriteI2c(gspca_dev, 0xb8, 0x12);
377 spca506_WriteI2c(gspca_dev, 0x01, 0x13);
378 spca506_WriteI2c(gspca_dev, 0x00, 0x14);
379 spca506_WriteI2c(gspca_dev, 0x00, 0x15);
380 spca506_WriteI2c(gspca_dev, 0x00, 0x16);
381 spca506_WriteI2c(gspca_dev, 0x00, 0x17);
382 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
383 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
384 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
385 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
386 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
387 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
388 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
389 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
390 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
391 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
392 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
393 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
394 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
395 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
396 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
397 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
398 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
399 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
400 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
401 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
402 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
403 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
404 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
405 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
406 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
407 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
408 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
409 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
410 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
411 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
412 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
413 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
414 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
415 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
416 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
417 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
418 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
419 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
420 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
421 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
422 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
423 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
424 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
425 PDEBUG(D_STREAM, "** Close Init *");
429 static void sd_start(struct gspca_dev *gspca_dev)
431 struct usb_device *dev = gspca_dev->dev;
435 /**************************************/
436 reg_w(dev, 0x03, 0x00, 0x0004);
437 reg_w(dev, 0x03, 0x00, 0x0003);
438 reg_w(dev, 0x03, 0x00, 0x0004);
439 reg_w(dev, 0x03, 0xFF, 0x0003);
440 reg_w(dev, 0x02, 0x00, 0x0000);
441 reg_w(dev, 0x03, 0x60, 0x0000);
442 reg_w(dev, 0x03, 0x18, 0x0001);
444 /*sdca506_WriteI2c(value,register) */
445 spca506_Initi2c(gspca_dev);
446 spca506_WriteI2c(gspca_dev, 0x08, 0x01); /* Increment Delay */
447 /* spca506_WriteI2c(gspca_dev, 0xc0, 0x02); * Analog Input Control 1 */
448 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
449 /* Analog Input Control 2 */
450 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
451 /* Analog Input Control 3 */
452 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
453 /* Analog Input Control 4 */
454 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
455 /* Horizontal Sync Start 0xe9-0x0d */
456 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
457 /* Horizontal Sync Stop 0x0d-0xf0 */
459 spca506_WriteI2c(gspca_dev, 0x98, 0x08); /* Sync Control */
461 spca506_WriteI2c(gspca_dev, 0x03, 0x09); /* Luminance Control */
462 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
463 /* Luminance Brightness */
464 spca506_WriteI2c(gspca_dev, 0x47, 0x0b); /* Luminance Contrast */
465 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
466 /* Chrominance Saturation */
467 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
468 /* Chrominance Hue Control */
469 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
470 /* Chrominance Gain Control */
471 /**************************************/
472 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
473 /* Format/Delay Control */
474 spca506_WriteI2c(gspca_dev, 0x0c, 0x11); /* Output Control 1 */
475 spca506_WriteI2c(gspca_dev, 0xb8, 0x12); /* Output Control 2 */
476 spca506_WriteI2c(gspca_dev, 0x01, 0x13); /* Output Control 3 */
477 spca506_WriteI2c(gspca_dev, 0x00, 0x14); /* reserved */
478 spca506_WriteI2c(gspca_dev, 0x00, 0x15); /* VGATE START */
479 spca506_WriteI2c(gspca_dev, 0x00, 0x16); /* VGATE STOP */
480 spca506_WriteI2c(gspca_dev, 0x00, 0x17); /* VGATE Control (MSB) */
481 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
482 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
483 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
484 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
485 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
486 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
487 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
488 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
489 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
490 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
491 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
492 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
493 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
494 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
495 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
496 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
497 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
498 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
499 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
500 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
501 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
502 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
503 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
504 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
505 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
506 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
507 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
508 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
509 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
510 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
511 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
512 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
513 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
514 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
515 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
516 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
517 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
518 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
519 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
520 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
521 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
522 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
523 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
524 /**************************************/
525 reg_w(dev, 0x05, 0x00, 0x0003);
526 reg_w(dev, 0x05, 0x00, 0x0004);
527 reg_w(dev, 0x03, 0x10, 0x0001);
528 reg_w(dev, 0x03, 0x78, 0x0000);
529 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
531 spca506_Setsize(gspca_dev, 0, 0x10, 0x10);
534 spca506_Setsize(gspca_dev, 1, 0x1a, 0x1a);
537 spca506_Setsize(gspca_dev, 2, 0x1c, 0x1c);
540 spca506_Setsize(gspca_dev, 4, 0x34, 0x34);
544 spca506_Setsize(gspca_dev, 5, 0x40, 0x40);
548 /* compress setting and size */
550 reg_w(dev, 0x02, 0x01, 0x0000);
551 reg_w(dev, 0x03, 0x12, 0x0000);
552 reg_r(gspca_dev, 0x04, 0x0001, 2);
553 PDEBUG(D_STREAM, "webcam started");
554 spca506_GetNormeInput(gspca_dev, &norme, &channel);
555 spca506_SetNormeInput(gspca_dev, norme, channel);
558 static void sd_stopN(struct gspca_dev *gspca_dev)
560 struct usb_device *dev = gspca_dev->dev;
562 reg_w(dev, 0x02, 0x00, 0x0000);
563 reg_w(dev, 0x03, 0x00, 0x0004);
564 reg_w(dev, 0x03, 0x00, 0x0003);
567 static void sd_stop0(struct gspca_dev *gspca_dev)
571 static void sd_close(struct gspca_dev *gspca_dev)
575 /* convert YYUV per line to YUYV (YUV 4:2:2) */
576 static void yyuv_decode(unsigned char *out,
581 unsigned char *Ui, *Vi, *yi, *yi1;
586 for (i = height / 2; --i >= 0; ) {
587 out1 = out + width * 2; /* next line */
591 for (j = width / 2; --j >= 0; ) {
592 *out++ = 128 + *yi++;
594 *out++ = 128 + *yi++;
597 *out1++ = 128 + *yi1++;
598 *out1++ = 128 + *Ui++;
599 *out1++ = 128 + *yi1++;
600 *out1++ = 128 + *Vi++;
607 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
608 struct gspca_frame *frame, /* target */
609 __u8 *data, /* isoc packet */
610 int len) /* iso packet length */
612 struct sd *sd = (struct sd *) gspca_dev;
615 case 0: /* start of frame */
616 if (gspca_dev->last_packet_type == FIRST_PACKET) {
617 yyuv_decode(sd->tmpbuf2, sd->tmpbuf,
620 frame = gspca_frame_add(gspca_dev,
628 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
630 data += SPCA50X_OFFSET_DATA;
631 len -= SPCA50X_OFFSET_DATA;
633 memcpy(sd->tmpbuf, data, len);
638 case 0xff: /* drop */
639 /* gspca_dev->last_packet_type = DISCARD_PACKET; */
644 memcpy(&sd->tmpbuf[sd->buflen], data, len);
648 static void setbrightness(struct gspca_dev *gspca_dev)
650 struct sd *sd = (struct sd *) gspca_dev;
652 spca506_Initi2c(gspca_dev);
653 spca506_WriteI2c(gspca_dev, sd->brightness, SAA7113_bright);
654 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
657 static void getbrightness(struct gspca_dev *gspca_dev)
659 struct sd *sd = (struct sd *) gspca_dev;
661 sd->brightness = spca506_ReadI2c(gspca_dev, SAA7113_bright);
664 static void setcontrast(struct gspca_dev *gspca_dev)
666 struct sd *sd = (struct sd *) gspca_dev;
668 spca506_Initi2c(gspca_dev);
669 spca506_WriteI2c(gspca_dev, sd->contrast, SAA7113_contrast);
670 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
673 static void getcontrast(struct gspca_dev *gspca_dev)
675 struct sd *sd = (struct sd *) gspca_dev;
677 sd->contrast = spca506_ReadI2c(gspca_dev, SAA7113_contrast);
680 static void setcolors(struct gspca_dev *gspca_dev)
682 struct sd *sd = (struct sd *) gspca_dev;
684 spca506_Initi2c(gspca_dev);
685 spca506_WriteI2c(gspca_dev, sd->colors, SAA7113_saturation);
686 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
689 static void getcolors(struct gspca_dev *gspca_dev)
691 struct sd *sd = (struct sd *) gspca_dev;
693 sd->colors = spca506_ReadI2c(gspca_dev, SAA7113_saturation);
696 static void sethue(struct gspca_dev *gspca_dev)
698 struct sd *sd = (struct sd *) gspca_dev;
700 spca506_Initi2c(gspca_dev);
701 spca506_WriteI2c(gspca_dev, sd->hue, SAA7113_hue);
702 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
705 static void gethue(struct gspca_dev *gspca_dev)
707 struct sd *sd = (struct sd *) gspca_dev;
709 sd->hue = spca506_ReadI2c(gspca_dev, SAA7113_hue);
712 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
714 struct sd *sd = (struct sd *) gspca_dev;
716 sd->brightness = val;
717 if (gspca_dev->streaming)
718 setbrightness(gspca_dev);
722 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
724 struct sd *sd = (struct sd *) gspca_dev;
726 getbrightness(gspca_dev);
727 *val = sd->brightness;
731 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
733 struct sd *sd = (struct sd *) gspca_dev;
736 if (gspca_dev->streaming)
737 setcontrast(gspca_dev);
741 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
743 struct sd *sd = (struct sd *) gspca_dev;
745 getcontrast(gspca_dev);
750 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
752 struct sd *sd = (struct sd *) gspca_dev;
755 if (gspca_dev->streaming)
756 setcolors(gspca_dev);
760 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
762 struct sd *sd = (struct sd *) gspca_dev;
764 getcolors(gspca_dev);
769 static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
771 struct sd *sd = (struct sd *) gspca_dev;
774 if (gspca_dev->streaming)
779 static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
781 struct sd *sd = (struct sd *) gspca_dev;
788 /* sub-driver description */
789 static struct sd_desc sd_desc = {
792 .nctrls = ARRAY_SIZE(sd_ctrls),
799 .pkt_scan = sd_pkt_scan,
802 /* -- module initialisation -- */
803 #define DVNM(name) .driver_info = (kernel_ulong_t) name
804 static __devinitdata struct usb_device_id device_table[] = {
805 {USB_DEVICE(0x06e1, 0xa190), DVNM("ADS Instant VCD")},
806 /* {USB_DEVICE(0x0733, 0x0430), DVNM("UsbGrabber PV321c")}, */
807 {USB_DEVICE(0x0734, 0x043b), DVNM("3DeMon USB Capture aka")},
808 {USB_DEVICE(0x99fa, 0x8988), DVNM("Grandtec V.cap")},
811 MODULE_DEVICE_TABLE(usb, device_table);
813 /* -- device connect -- */
814 static int sd_probe(struct usb_interface *intf,
815 const struct usb_device_id *id)
817 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
821 static struct usb_driver sd_driver = {
823 .id_table = device_table,
825 .disconnect = gspca_disconnect,
828 /* -- module insert / remove -- */
829 static int __init sd_mod_init(void)
831 if (usb_register(&sd_driver) < 0)
833 PDEBUG(D_PROBE, "registered");
836 static void __exit sd_mod_exit(void)
838 usb_deregister(&sd_driver);
839 PDEBUG(D_PROBE, "deregistered");
842 module_init(sd_mod_init);
843 module_exit(sd_mod_exit);