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 */
36 unsigned char brightness;
37 unsigned char contrast;
44 /* V4L2 controls supported by the driver */
45 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
46 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
47 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
48 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
49 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
50 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
51 static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
52 static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
54 static struct ctrl sd_ctrls[] = {
55 #define SD_BRIGHTNESS 0
58 .id = V4L2_CID_BRIGHTNESS,
59 .type = V4L2_CTRL_TYPE_INTEGER,
64 .default_value = 0x80,
66 .set = sd_setbrightness,
67 .get = sd_getbrightness,
72 .id = V4L2_CID_CONTRAST,
73 .type = V4L2_CTRL_TYPE_INTEGER,
78 .default_value = 0x47,
80 .set = sd_setcontrast,
81 .get = sd_getcontrast,
86 .id = V4L2_CID_SATURATION,
87 .type = V4L2_CTRL_TYPE_INTEGER,
92 .default_value = 0x40,
101 .type = V4L2_CTRL_TYPE_INTEGER,
113 static const struct v4l2_pix_format vga_mode[] = {
114 {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
116 .sizeimage = 160 * 120 * 3 / 2,
117 .colorspace = V4L2_COLORSPACE_SRGB,
119 {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
121 .sizeimage = 176 * 144 * 3 / 2,
122 .colorspace = V4L2_COLORSPACE_SRGB,
124 {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
126 .sizeimage = 320 * 240 * 3 / 2,
127 .colorspace = V4L2_COLORSPACE_SRGB,
129 {352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
131 .sizeimage = 352 * 288 * 3 / 2,
132 .colorspace = V4L2_COLORSPACE_SRGB,
134 {640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
136 .sizeimage = 640 * 480 * 3 / 2,
137 .colorspace = V4L2_COLORSPACE_SRGB,
141 #define SPCA50X_OFFSET_DATA 10
143 #define SAA7113_bright 0x0a /* defaults 0x80 */
144 #define SAA7113_contrast 0x0b /* defaults 0x47 */
145 #define SAA7113_saturation 0x0c /* defaults 0x40 */
146 #define SAA7113_hue 0x0d /* defaults 0x00 */
147 #define SAA7113_I2C_BASE_WRITE 0x4a
149 /* read 'len' bytes to gspca_dev->usb_buf */
150 static void reg_r(struct gspca_dev *gspca_dev,
155 usb_control_msg(gspca_dev->dev,
156 usb_rcvctrlpipe(gspca_dev->dev, 0),
158 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
160 index, gspca_dev->usb_buf, length,
164 static void reg_w(struct usb_device *dev,
170 usb_sndctrlpipe(dev, 0),
172 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
177 static void spca506_Initi2c(struct gspca_dev *gspca_dev)
179 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
182 static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
187 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
188 reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
190 reg_r(gspca_dev, 0x07, 0x0003, 2);
191 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
196 static int spca506_ReadI2c(struct gspca_dev *gspca_dev, __u16 reg)
200 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
201 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
202 reg_w(gspca_dev->dev, 0x07, 0x01, 0x0002);
204 reg_r(gspca_dev, 0x07, 0x0003, 2);
205 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
210 reg_r(gspca_dev, 0x07, 0x0000, 1);
211 return gspca_dev->usb_buf[0];
214 static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
218 struct sd *sd = (struct sd *) gspca_dev;
219 /* fixme: check if channel == 0..3 and 6..9 (8 values) */
222 __u8 videomask = 0x00;
224 PDEBUG(D_STREAM, "** Open Set Norme **");
225 spca506_Initi2c(gspca_dev);
226 /* NTSC bit0 -> 1(525 l) PAL SECAM bit0 -> 0 (625 l) */
227 /* Composite channel bit1 -> 1 S-video bit 1 -> 0 */
228 /* and exclude SAA7113 reserved channel set default 0 otherwise */
229 if (norme & V4L2_STD_NTSC)
231 if (channel == 4 || channel == 5 || channel > 9)
235 videomask = (0x48 | setbit0 | setbit1);
236 reg_w(gspca_dev->dev, 0x08, videomask, 0x0000);
237 spca506_WriteI2c(gspca_dev, (0xc0 | (channel & 0x0F)), 0x02);
239 if (norme & V4L2_STD_NTSC)
240 spca506_WriteI2c(gspca_dev, 0x33, 0x0e);
241 /* Chrominance Control NTSC N */
242 else if (norme & V4L2_STD_SECAM)
243 spca506_WriteI2c(gspca_dev, 0x53, 0x0e);
244 /* Chrominance Control SECAM */
246 spca506_WriteI2c(gspca_dev, 0x03, 0x0e);
247 /* Chrominance Control PAL BGHIV */
250 sd->channel = channel;
251 PDEBUG(D_STREAM, "Set Video Byte to 0x%2x", videomask);
252 PDEBUG(D_STREAM, "Set Norme: %08x Channel %d", norme, channel);
255 static void spca506_GetNormeInput(struct gspca_dev *gspca_dev,
256 __u16 *norme, __u16 *channel)
258 struct sd *sd = (struct sd *) gspca_dev;
260 /* Read the register is not so good value change so
261 we use your own copy in spca50x struct */
263 *channel = sd->channel;
264 PDEBUG(D_STREAM, "Get Norme: %d Channel %d", *norme, *channel);
267 static void spca506_Setsize(struct gspca_dev *gspca_dev, __u16 code,
268 __u16 xmult, __u16 ymult)
270 struct usb_device *dev = gspca_dev->dev;
272 PDEBUG(D_STREAM, "** SetSize **");
273 reg_w(dev, 0x04, (0x18 | (code & 0x07)), 0x0000);
274 /* Soft snap 0x40 Hard 0x41 */
275 reg_w(dev, 0x04, 0x41, 0x0001);
276 reg_w(dev, 0x04, 0x00, 0x0002);
278 reg_w(dev, 0x04, 0x00, 0x0003);
281 reg_w(dev, 0x04, 0x00, 0x0004);
283 reg_w(dev, 0x04, 0x01, 0x0005);
285 reg_w(dev, 0x04, xmult, 0x0006);
287 reg_w(dev, 0x04, ymult, 0x0007);
289 reg_w(dev, 0x04, 0x00, 0x0008);
291 reg_w(dev, 0x04, 0x00, 0x0009);
293 reg_w(dev, 0x04, 0x21, 0x000a);
295 reg_w(dev, 0x04, 0x00, 0x000b);
298 /* this function is called at probe time */
299 static int sd_config(struct gspca_dev *gspca_dev,
300 const struct usb_device_id *id)
302 struct sd *sd = (struct sd *) gspca_dev;
305 cam = &gspca_dev->cam;
306 cam->cam_mode = vga_mode;
307 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
308 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
309 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
310 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
311 sd->hue = sd_ctrls[SD_HUE].qctrl.default_value;
315 /* this function is called at probe and resume time */
316 static int sd_init(struct gspca_dev *gspca_dev)
318 struct usb_device *dev = gspca_dev->dev;
320 reg_w(dev, 0x03, 0x00, 0x0004);
321 reg_w(dev, 0x03, 0xFF, 0x0003);
322 reg_w(dev, 0x03, 0x00, 0x0000);
323 reg_w(dev, 0x03, 0x1c, 0x0001);
324 reg_w(dev, 0x03, 0x18, 0x0001);
325 /* Init on PAL and composite input0 */
326 spca506_SetNormeInput(gspca_dev, 0, 0);
327 reg_w(dev, 0x03, 0x1c, 0x0001);
328 reg_w(dev, 0x03, 0x18, 0x0001);
329 reg_w(dev, 0x05, 0x00, 0x0000);
330 reg_w(dev, 0x05, 0xef, 0x0001);
331 reg_w(dev, 0x05, 0x00, 0x00c1);
332 reg_w(dev, 0x05, 0x00, 0x00c2);
333 reg_w(dev, 0x06, 0x18, 0x0002);
334 reg_w(dev, 0x06, 0xf5, 0x0011);
335 reg_w(dev, 0x06, 0x02, 0x0012);
336 reg_w(dev, 0x06, 0xfb, 0x0013);
337 reg_w(dev, 0x06, 0x00, 0x0014);
338 reg_w(dev, 0x06, 0xa4, 0x0051);
339 reg_w(dev, 0x06, 0x40, 0x0052);
340 reg_w(dev, 0x06, 0x71, 0x0053);
341 reg_w(dev, 0x06, 0x40, 0x0054);
342 /************************************************/
343 reg_w(dev, 0x03, 0x00, 0x0004);
344 reg_w(dev, 0x03, 0x00, 0x0003);
345 reg_w(dev, 0x03, 0x00, 0x0004);
346 reg_w(dev, 0x03, 0xFF, 0x0003);
347 reg_w(dev, 0x02, 0x00, 0x0000);
348 reg_w(dev, 0x03, 0x60, 0x0000);
349 reg_w(dev, 0x03, 0x18, 0x0001);
350 /* for a better reading mx :) */
351 /*sdca506_WriteI2c(value,register) */
352 spca506_Initi2c(gspca_dev);
353 spca506_WriteI2c(gspca_dev, 0x08, 0x01);
354 spca506_WriteI2c(gspca_dev, 0xc0, 0x02);
355 /* input composite video */
356 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
357 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
358 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
359 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
360 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
361 spca506_WriteI2c(gspca_dev, 0x98, 0x08);
362 spca506_WriteI2c(gspca_dev, 0x03, 0x09);
363 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
364 spca506_WriteI2c(gspca_dev, 0x47, 0x0b);
365 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
366 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
367 spca506_WriteI2c(gspca_dev, 0x03, 0x0e); /* Chroma Pal adjust */
368 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
369 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
370 spca506_WriteI2c(gspca_dev, 0x0c, 0x11);
371 spca506_WriteI2c(gspca_dev, 0xb8, 0x12);
372 spca506_WriteI2c(gspca_dev, 0x01, 0x13);
373 spca506_WriteI2c(gspca_dev, 0x00, 0x14);
374 spca506_WriteI2c(gspca_dev, 0x00, 0x15);
375 spca506_WriteI2c(gspca_dev, 0x00, 0x16);
376 spca506_WriteI2c(gspca_dev, 0x00, 0x17);
377 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
378 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
379 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
380 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
381 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
382 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
383 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
384 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
385 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
386 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
387 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
388 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
389 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
390 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
391 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
392 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
393 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
394 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
395 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
396 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
397 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
398 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
399 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
400 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
401 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
402 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
403 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
404 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
405 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
406 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
407 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
408 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
409 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
410 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
411 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
412 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
413 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
414 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
415 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
416 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
417 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
418 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
419 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
420 PDEBUG(D_STREAM, "** Close Init *");
424 static int sd_start(struct gspca_dev *gspca_dev)
426 struct usb_device *dev = gspca_dev->dev;
430 /**************************************/
431 reg_w(dev, 0x03, 0x00, 0x0004);
432 reg_w(dev, 0x03, 0x00, 0x0003);
433 reg_w(dev, 0x03, 0x00, 0x0004);
434 reg_w(dev, 0x03, 0xFF, 0x0003);
435 reg_w(dev, 0x02, 0x00, 0x0000);
436 reg_w(dev, 0x03, 0x60, 0x0000);
437 reg_w(dev, 0x03, 0x18, 0x0001);
439 /*sdca506_WriteI2c(value,register) */
440 spca506_Initi2c(gspca_dev);
441 spca506_WriteI2c(gspca_dev, 0x08, 0x01); /* Increment Delay */
442 /* spca506_WriteI2c(gspca_dev, 0xc0, 0x02); * Analog Input Control 1 */
443 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
444 /* Analog Input Control 2 */
445 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
446 /* Analog Input Control 3 */
447 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
448 /* Analog Input Control 4 */
449 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
450 /* Horizontal Sync Start 0xe9-0x0d */
451 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
452 /* Horizontal Sync Stop 0x0d-0xf0 */
454 spca506_WriteI2c(gspca_dev, 0x98, 0x08); /* Sync Control */
456 spca506_WriteI2c(gspca_dev, 0x03, 0x09); /* Luminance Control */
457 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
458 /* Luminance Brightness */
459 spca506_WriteI2c(gspca_dev, 0x47, 0x0b); /* Luminance Contrast */
460 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
461 /* Chrominance Saturation */
462 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
463 /* Chrominance Hue Control */
464 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
465 /* Chrominance Gain Control */
466 /**************************************/
467 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
468 /* Format/Delay Control */
469 spca506_WriteI2c(gspca_dev, 0x0c, 0x11); /* Output Control 1 */
470 spca506_WriteI2c(gspca_dev, 0xb8, 0x12); /* Output Control 2 */
471 spca506_WriteI2c(gspca_dev, 0x01, 0x13); /* Output Control 3 */
472 spca506_WriteI2c(gspca_dev, 0x00, 0x14); /* reserved */
473 spca506_WriteI2c(gspca_dev, 0x00, 0x15); /* VGATE START */
474 spca506_WriteI2c(gspca_dev, 0x00, 0x16); /* VGATE STOP */
475 spca506_WriteI2c(gspca_dev, 0x00, 0x17); /* VGATE Control (MSB) */
476 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
477 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
478 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
479 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
480 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
481 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
482 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
483 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
484 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
485 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
486 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
487 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
488 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
489 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
490 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
491 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
492 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
493 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
494 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
495 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
496 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
497 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
498 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
499 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
500 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
501 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
502 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
503 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
504 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
505 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
506 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
507 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
508 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
509 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
510 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
511 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
512 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
513 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
514 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
515 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
516 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
517 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
518 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
519 /**************************************/
520 reg_w(dev, 0x05, 0x00, 0x0003);
521 reg_w(dev, 0x05, 0x00, 0x0004);
522 reg_w(dev, 0x03, 0x10, 0x0001);
523 reg_w(dev, 0x03, 0x78, 0x0000);
524 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
526 spca506_Setsize(gspca_dev, 0, 0x10, 0x10);
529 spca506_Setsize(gspca_dev, 1, 0x1a, 0x1a);
532 spca506_Setsize(gspca_dev, 2, 0x1c, 0x1c);
535 spca506_Setsize(gspca_dev, 4, 0x34, 0x34);
539 spca506_Setsize(gspca_dev, 5, 0x40, 0x40);
543 /* compress setting and size */
545 reg_w(dev, 0x02, 0x01, 0x0000);
546 reg_w(dev, 0x03, 0x12, 0x0000);
547 reg_r(gspca_dev, 0x04, 0x0001, 2);
548 PDEBUG(D_STREAM, "webcam started");
549 spca506_GetNormeInput(gspca_dev, &norme, &channel);
550 spca506_SetNormeInput(gspca_dev, norme, channel);
554 static void sd_stopN(struct gspca_dev *gspca_dev)
556 struct usb_device *dev = gspca_dev->dev;
558 reg_w(dev, 0x02, 0x00, 0x0000);
559 reg_w(dev, 0x03, 0x00, 0x0004);
560 reg_w(dev, 0x03, 0x00, 0x0003);
563 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
564 struct gspca_frame *frame, /* target */
565 __u8 *data, /* isoc packet */
566 int len) /* iso packet length */
569 case 0: /* start of frame */
570 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
572 data += SPCA50X_OFFSET_DATA;
573 len -= SPCA50X_OFFSET_DATA;
574 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
577 case 0xff: /* drop */
578 /* gspca_dev->last_packet_type = DISCARD_PACKET; */
583 gspca_frame_add(gspca_dev, INTER_PACKET, frame,
589 static void setbrightness(struct gspca_dev *gspca_dev)
591 struct sd *sd = (struct sd *) gspca_dev;
593 spca506_Initi2c(gspca_dev);
594 spca506_WriteI2c(gspca_dev, sd->brightness, SAA7113_bright);
595 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
598 static void getbrightness(struct gspca_dev *gspca_dev)
600 struct sd *sd = (struct sd *) gspca_dev;
602 sd->brightness = spca506_ReadI2c(gspca_dev, SAA7113_bright);
605 static void setcontrast(struct gspca_dev *gspca_dev)
607 struct sd *sd = (struct sd *) gspca_dev;
609 spca506_Initi2c(gspca_dev);
610 spca506_WriteI2c(gspca_dev, sd->contrast, SAA7113_contrast);
611 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
614 static void getcontrast(struct gspca_dev *gspca_dev)
616 struct sd *sd = (struct sd *) gspca_dev;
618 sd->contrast = spca506_ReadI2c(gspca_dev, SAA7113_contrast);
621 static void setcolors(struct gspca_dev *gspca_dev)
623 struct sd *sd = (struct sd *) gspca_dev;
625 spca506_Initi2c(gspca_dev);
626 spca506_WriteI2c(gspca_dev, sd->colors, SAA7113_saturation);
627 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
630 static void getcolors(struct gspca_dev *gspca_dev)
632 struct sd *sd = (struct sd *) gspca_dev;
634 sd->colors = spca506_ReadI2c(gspca_dev, SAA7113_saturation);
637 static void sethue(struct gspca_dev *gspca_dev)
639 struct sd *sd = (struct sd *) gspca_dev;
641 spca506_Initi2c(gspca_dev);
642 spca506_WriteI2c(gspca_dev, sd->hue, SAA7113_hue);
643 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
646 static void gethue(struct gspca_dev *gspca_dev)
648 struct sd *sd = (struct sd *) gspca_dev;
650 sd->hue = spca506_ReadI2c(gspca_dev, SAA7113_hue);
653 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
655 struct sd *sd = (struct sd *) gspca_dev;
657 sd->brightness = val;
658 if (gspca_dev->streaming)
659 setbrightness(gspca_dev);
663 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
665 struct sd *sd = (struct sd *) gspca_dev;
667 getbrightness(gspca_dev);
668 *val = sd->brightness;
672 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
674 struct sd *sd = (struct sd *) gspca_dev;
677 if (gspca_dev->streaming)
678 setcontrast(gspca_dev);
682 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
684 struct sd *sd = (struct sd *) gspca_dev;
686 getcontrast(gspca_dev);
691 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
693 struct sd *sd = (struct sd *) gspca_dev;
696 if (gspca_dev->streaming)
697 setcolors(gspca_dev);
701 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
703 struct sd *sd = (struct sd *) gspca_dev;
705 getcolors(gspca_dev);
710 static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
712 struct sd *sd = (struct sd *) gspca_dev;
715 if (gspca_dev->streaming)
720 static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
722 struct sd *sd = (struct sd *) gspca_dev;
729 /* sub-driver description */
730 static struct sd_desc sd_desc = {
733 .nctrls = ARRAY_SIZE(sd_ctrls),
738 .pkt_scan = sd_pkt_scan,
741 /* -- module initialisation -- */
742 static __devinitdata struct usb_device_id device_table[] = {
743 {USB_DEVICE(0x06e1, 0xa190)},
744 /*fixme: may be IntelPCCameraPro BRIDGE_SPCA505
745 {USB_DEVICE(0x0733, 0x0430)}, */
746 {USB_DEVICE(0x0734, 0x043b)},
747 {USB_DEVICE(0x99fa, 0x8988)},
750 MODULE_DEVICE_TABLE(usb, device_table);
752 /* -- device connect -- */
753 static int sd_probe(struct usb_interface *intf,
754 const struct usb_device_id *id)
756 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
760 static struct usb_driver sd_driver = {
762 .id_table = device_table,
764 .disconnect = gspca_disconnect,
766 .suspend = gspca_suspend,
767 .resume = gspca_resume,
771 /* -- module insert / remove -- */
772 static int __init sd_mod_init(void)
775 ret = usb_register(&sd_driver);
778 PDEBUG(D_PROBE, "registered");
781 static void __exit sd_mod_exit(void)
783 usb_deregister(&sd_driver);
784 PDEBUG(D_PROBE, "deregistered");
787 module_init(sd_mod_init);
788 module_exit(sd_mod_exit);