aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/spca561.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/gspca/spca561.c')
-rw-r--r--drivers/media/video/gspca/spca561.c723
1 files changed, 466 insertions, 257 deletions
diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c
index 1073ac3d2ec6..1c29c279a982 100644
--- a/drivers/media/video/gspca/spca561.c
+++ b/drivers/media/video/gspca/spca561.c
@@ -32,69 +32,48 @@ MODULE_LICENSE("GPL");
32struct sd { 32struct sd {
33 struct gspca_dev gspca_dev; /* !! must be the first item */ 33 struct gspca_dev gspca_dev; /* !! must be the first item */
34 34
35 unsigned short contrast; 35 __u16 contrast; /* rev72a only */
36 __u8 brightness; 36#define CONTRAST_MIN 0x0000
37#define CONTRAST_DEF 0x2000
38#define CONTRAST_MAX 0x3fff
39
40 __u16 exposure; /* rev12a only */
41#define EXPOSURE_MIN 1
42#define EXPOSURE_DEF 200
43#define EXPOSURE_MAX (4095 - 900) /* see set_exposure */
44
45 __u8 brightness; /* rev72a only */
46#define BRIGHTNESS_MIN 0
47#define BRIGHTNESS_DEF 32
48#define BRIGHTNESS_MAX 63
49
50 __u8 white; /* rev12a only */
51#define WHITE_MIN 1
52#define WHITE_DEF 0x40
53#define WHITE_MAX 0x7f
54
37 __u8 autogain; 55 __u8 autogain;
56#define AUTOGAIN_MIN 0
57#define AUTOGAIN_DEF 1
58#define AUTOGAIN_MAX 1
59
60 __u8 gain; /* rev12a only */
61#define GAIN_MIN 0x0
62#define GAIN_DEF 0x24
63#define GAIN_MAX 0x24
64
65#define EXPO12A_DEF 3
66 __u8 expo12a; /* expo/gain? for rev 12a */
38 67
39 __u8 chip_revision; 68 __u8 chip_revision;
69#define Rev012A 0
70#define Rev072A 1
71
40 signed char ag_cnt; 72 signed char ag_cnt;
41#define AG_CNT_START 13 73#define AG_CNT_START 13
42}; 74};
43 75
44/* V4L2 controls supported by the driver */ 76static struct v4l2_pix_format sif_012a_mode[] = {
45static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
46static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
47static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
48static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
49static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
50static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
51
52static struct ctrl sd_ctrls[] = {
53#define SD_BRIGHTNESS 0
54 {
55 {
56 .id = V4L2_CID_BRIGHTNESS,
57 .type = V4L2_CTRL_TYPE_INTEGER,
58 .name = "Brightness",
59 .minimum = 0,
60 .maximum = 63,
61 .step = 1,
62 .default_value = 32,
63 },
64 .set = sd_setbrightness,
65 .get = sd_getbrightness,
66 },
67#define SD_CONTRAST 1
68 {
69 {
70 .id = V4L2_CID_CONTRAST,
71 .type = V4L2_CTRL_TYPE_INTEGER,
72 .name = "Contrast",
73 .minimum = 0,
74 .maximum = 0x3fff,
75 .step = 1,
76 .default_value = 0x2000,
77 },
78 .set = sd_setcontrast,
79 .get = sd_getcontrast,
80 },
81#define SD_AUTOGAIN 2
82 {
83 {
84 .id = V4L2_CID_AUTOGAIN,
85 .type = V4L2_CTRL_TYPE_BOOLEAN,
86 .name = "Auto Gain",
87 .minimum = 0,
88 .maximum = 1,
89 .step = 1,
90 .default_value = 1,
91 },
92 .set = sd_setautogain,
93 .get = sd_getautogain,
94 },
95};
96
97static struct v4l2_pix_format sif_mode[] = {
98 {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE, 77 {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
99 .bytesperline = 160, 78 .bytesperline = 160,
100 .sizeimage = 160 * 120, 79 .sizeimage = 160 * 120,
@@ -117,6 +96,29 @@ static struct v4l2_pix_format sif_mode[] = {
117 .priv = 0}, 96 .priv = 0},
118}; 97};
119 98
99static struct v4l2_pix_format sif_072a_mode[] = {
100 {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
101 .bytesperline = 160,
102 .sizeimage = 160 * 120,
103 .colorspace = V4L2_COLORSPACE_SRGB,
104 .priv = 3},
105 {176, 144, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
106 .bytesperline = 176,
107 .sizeimage = 176 * 144,
108 .colorspace = V4L2_COLORSPACE_SRGB,
109 .priv = 2},
110 {320, 240, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
111 .bytesperline = 320,
112 .sizeimage = 320 * 240,
113 .colorspace = V4L2_COLORSPACE_SRGB,
114 .priv = 1},
115 {352, 288, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
116 .bytesperline = 352,
117 .sizeimage = 352 * 288,
118 .colorspace = V4L2_COLORSPACE_SRGB,
119 .priv = 0},
120};
121
120/* 122/*
121 * Initialization data 123 * Initialization data
122 * I'm not very sure how to split initialization from open data 124 * I'm not very sure how to split initialization from open data
@@ -143,12 +145,8 @@ static struct v4l2_pix_format sif_mode[] = {
143#define SPCA561_INDEX_I2C_BASE 0x8800 145#define SPCA561_INDEX_I2C_BASE 0x8800
144#define SPCA561_SNAPBIT 0x20 146#define SPCA561_SNAPBIT 0x20
145#define SPCA561_SNAPCTRL 0x40 147#define SPCA561_SNAPCTRL 0x40
146enum {
147 Rev072A = 0,
148 Rev012A,
149};
150 148
151static void reg_w_val(struct usb_device *dev, __u16 index, __u16 value) 149static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
152{ 150{
153 int ret; 151 int ret;
154 152
@@ -198,12 +196,6 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
198 index, gspca_dev->usb_buf, len, 500); 196 index, gspca_dev->usb_buf, len, 500);
199} 197}
200 198
201static void i2c_init(struct gspca_dev *gspca_dev, __u8 mode)
202{
203 reg_w_val(gspca_dev->dev, 0x92, 0x8804);
204 reg_w_val(gspca_dev->dev, mode, 0x8802);
205}
206
207static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg) 199static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg)
208{ 200{
209 int retry = 60; 201 int retry = 60;
@@ -212,9 +204,9 @@ static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg)
212 204
213 DataLow = valeur; 205 DataLow = valeur;
214 DataHight = valeur >> 8; 206 DataHight = valeur >> 8;
215 reg_w_val(gspca_dev->dev, reg, 0x8801); 207 reg_w_val(gspca_dev->dev, 0x8801, reg);
216 reg_w_val(gspca_dev->dev, DataLow, 0x8805); 208 reg_w_val(gspca_dev->dev, 0x8805, DataLow);
217 reg_w_val(gspca_dev->dev, DataHight, 0x8800); 209 reg_w_val(gspca_dev->dev, 0x8800, DataHight);
218 while (retry--) { 210 while (retry--) {
219 reg_r(gspca_dev, 0x8803, 1); 211 reg_r(gspca_dev, 0x8803, 1);
220 if (!gspca_dev->usb_buf[0]) 212 if (!gspca_dev->usb_buf[0])
@@ -228,9 +220,9 @@ static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode)
228 __u8 value; 220 __u8 value;
229 __u8 vallsb; 221 __u8 vallsb;
230 222
231 reg_w_val(gspca_dev->dev, 0x92, 0x8804); 223 reg_w_val(gspca_dev->dev, 0x8804, 0x92);
232 reg_w_val(gspca_dev->dev, reg, 0x8801); 224 reg_w_val(gspca_dev->dev, 0x8801, reg);
233 reg_w_val(gspca_dev->dev, (mode | 0x01), 0x8802); 225 reg_w_val(gspca_dev->dev, 0x8802, (mode | 0x01));
234 while (retry--) { 226 while (retry--) {
235 reg_r(gspca_dev, 0x8803, 1); 227 reg_r(gspca_dev, 0x8803, 1);
236 if (!gspca_dev->usb_buf) 228 if (!gspca_dev->usb_buf)
@@ -438,21 +430,10 @@ static const __u16 spca561_init_data[][2] = {
438 {0x0035, 0x8801}, /* 0x14 - set gain general */ 430 {0x0035, 0x8801}, /* 0x14 - set gain general */
439 {0x001f, 0x8805}, /* 0x14 */ 431 {0x001f, 0x8805}, /* 0x14 */
440 {0x0000, 0x8800}, 432 {0x0000, 0x8800},
441 {0x0030, 0x8112}, 433 {0x000e, 0x8112}, /* white balance - was 30 */
442 {} 434 {}
443}; 435};
444 436
445static void sensor_reset(struct gspca_dev *gspca_dev)
446{
447 reg_w_val(gspca_dev->dev, 0x8631, 0xc8);
448 reg_w_val(gspca_dev->dev, 0x8634, 0xc8);
449 reg_w_val(gspca_dev->dev, 0x8112, 0x00);
450 reg_w_val(gspca_dev->dev, 0x8114, 0x00);
451 reg_w_val(gspca_dev->dev, 0x8118, 0x21);
452 i2c_init(gspca_dev, 0x14);
453 i2c_write(gspca_dev, 1, 0x0d);
454 i2c_write(gspca_dev, 0, 0x0d);
455}
456 437
457/******************** QC Express etch2 stuff ********************/ 438/******************** QC Express etch2 stuff ********************/
458static const __u16 Pb100_1map8300[][2] = { 439static const __u16 Pb100_1map8300[][2] = {
@@ -462,9 +443,9 @@ static const __u16 Pb100_1map8300[][2] = {
462 {0x8303, 0x0125}, /* image area */ 443 {0x8303, 0x0125}, /* image area */
463 {0x8304, 0x0169}, 444 {0x8304, 0x0169},
464 {0x8328, 0x000b}, 445 {0x8328, 0x000b},
465 {0x833c, 0x0001}, 446 {0x833c, 0x0001}, /*fixme: win:07*/
466 447
467 {0x832f, 0x0419}, 448 {0x832f, 0x1904}, /*fixme: was 0419*/
468 {0x8307, 0x00aa}, 449 {0x8307, 0x00aa},
469 {0x8301, 0x0003}, 450 {0x8301, 0x0003},
470 {0x8302, 0x000e}, 451 {0x8302, 0x000e},
@@ -478,9 +459,10 @@ static const __u16 Pb100_2map8300[][2] = {
478}; 459};
479 460
480static const __u16 spca561_161rev12A_data1[][2] = { 461static const __u16 spca561_161rev12A_data1[][2] = {
481 {0x21, 0x8118}, 462 {0x29, 0x8118}, /* white balance - was 21 */
482 {0x01, 0x8114}, 463 {0x08, 0x8114}, /* white balance - was 01 */
483 {0x00, 0x8112}, 464 {0x0e, 0x8112}, /* white balance - was 00 */
465 {0x00, 0x8102}, /* white balance - new */
484 {0x92, 0x8804}, 466 {0x92, 0x8804},
485 {0x04, 0x8802}, /* windows uses 08 */ 467 {0x04, 0x8802}, /* windows uses 08 */
486 {} 468 {}
@@ -505,14 +487,16 @@ static const __u16 spca561_161rev12A_data2[][2] = {
505 {0xb0, 0x8603}, 487 {0xb0, 0x8603},
506 488
507 /* sensor gains */ 489 /* sensor gains */
490 {0x07, 0x8601}, /* white balance - new */
491 {0x07, 0x8602}, /* white balance - new */
508 {0x00, 0x8610}, /* *red */ 492 {0x00, 0x8610}, /* *red */
509 {0x00, 0x8611}, /* 3f *green */ 493 {0x00, 0x8611}, /* 3f *green */
510 {0x00, 0x8612}, /* green *blue */ 494 {0x00, 0x8612}, /* green *blue */
511 {0x00, 0x8613}, /* blue *green */ 495 {0x00, 0x8613}, /* blue *green */
512 {0x35, 0x8614}, /* green *red */ 496 {0x43, 0x8614}, /* green *red - white balance - was 0x35 */
513 {0x35, 0x8615}, /* 40 *green */ 497 {0x40, 0x8615}, /* 40 *green - white balance - was 0x35 */
514 {0x35, 0x8616}, /* 7a *blue */ 498 {0x71, 0x8616}, /* 7a *blue - white balance - was 0x35 */
515 {0x35, 0x8617}, /* 40 *green */ 499 {0x40, 0x8617}, /* 40 *green - white balance - was 0x35 */
516 500
517 {0x0c, 0x8620}, /* 0c */ 501 {0x0c, 0x8620}, /* 0c */
518 {0xc8, 0x8631}, /* c8 */ 502 {0xc8, 0x8631}, /* c8 */
@@ -527,6 +511,7 @@ static const __u16 spca561_161rev12A_data2[][2] = {
527 {0xdf, 0x863c}, /* df */ 511 {0xdf, 0x863c}, /* df */
528 {0xf0, 0x8505}, 512 {0xf0, 0x8505},
529 {0x32, 0x850a}, 513 {0x32, 0x850a},
514/* {0x99, 0x8700}, * - white balance - new (removed) */
530 {} 515 {}
531}; 516};
532 517
@@ -545,9 +530,10 @@ static void sensor_mapwrite(struct gspca_dev *gspca_dev,
545} 530}
546static void init_161rev12A(struct gspca_dev *gspca_dev) 531static void init_161rev12A(struct gspca_dev *gspca_dev)
547{ 532{
548 sensor_reset(gspca_dev); 533/* sensor_reset(gspca_dev); (not in win) */
549 write_vector(gspca_dev, spca561_161rev12A_data1); 534 write_vector(gspca_dev, spca561_161rev12A_data1);
550 sensor_mapwrite(gspca_dev, Pb100_1map8300); 535 sensor_mapwrite(gspca_dev, Pb100_1map8300);
536/*fixme: should be in sd_start*/
551 write_vector(gspca_dev, spca561_161rev12A_data2); 537 write_vector(gspca_dev, spca561_161rev12A_data2);
552 sensor_mapwrite(gspca_dev, Pb100_2map8300); 538 sensor_mapwrite(gspca_dev, Pb100_2map8300);
553} 539}
@@ -581,35 +567,38 @@ static int sd_config(struct gspca_dev *gspca_dev,
581 } 567 }
582 568
583 cam = &gspca_dev->cam; 569 cam = &gspca_dev->cam;
584 cam->dev_name = (char *) id->driver_info;
585 cam->epaddr = 0x01; 570 cam->epaddr = 0x01;
586 gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */ 571 gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */
587 cam->cam_mode = sif_mode;
588 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
589 572
590 sd->chip_revision = id->driver_info; 573 sd->chip_revision = id->driver_info;
591 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 574 if (sd->chip_revision == Rev012A) {
592 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 575 cam->cam_mode = sif_012a_mode;
593 sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value; 576 cam->nmodes = ARRAY_SIZE(sif_012a_mode);
577 } else {
578 cam->cam_mode = sif_072a_mode;
579 cam->nmodes = ARRAY_SIZE(sif_072a_mode);
580 }
581 sd->brightness = BRIGHTNESS_DEF;
582 sd->contrast = CONTRAST_DEF;
583 sd->white = WHITE_DEF;
584 sd->exposure = EXPOSURE_DEF;
585 sd->autogain = AUTOGAIN_DEF;
586 sd->gain = GAIN_DEF;
587 sd->expo12a = EXPO12A_DEF;
594 return 0; 588 return 0;
595} 589}
596 590
597/* this function is called at open time */ 591/* this function is called at probe and resume time */
598static int sd_open(struct gspca_dev *gspca_dev) 592static int sd_init_12a(struct gspca_dev *gspca_dev)
599{ 593{
600 struct sd *sd = (struct sd *) gspca_dev; 594 PDEBUG(D_STREAM, "Chip revision: 012a");
601 595 init_161rev12A(gspca_dev);
602 switch (sd->chip_revision) { 596 return 0;
603 case Rev072A: 597}
604 PDEBUG(D_STREAM, "Chip revision id: 072a"); 598static int sd_init_72a(struct gspca_dev *gspca_dev)
605 write_vector(gspca_dev, spca561_init_data); 599{
606 break; 600 PDEBUG(D_STREAM, "Chip revision: 072a");
607 default: 601 write_vector(gspca_dev, spca561_init_data);
608/* case Rev012A: */
609 PDEBUG(D_STREAM, "Chip revision id: 012a");
610 init_161rev12A(gspca_dev);
611 break;
612 }
613 return 0; 602 return 0;
614} 603}
615 604
@@ -618,25 +607,20 @@ static void setcontrast(struct gspca_dev *gspca_dev)
618 struct sd *sd = (struct sd *) gspca_dev; 607 struct sd *sd = (struct sd *) gspca_dev;
619 struct usb_device *dev = gspca_dev->dev; 608 struct usb_device *dev = gspca_dev->dev;
620 __u8 lowb; 609 __u8 lowb;
621 int expotimes;
622 610
623 switch (sd->chip_revision) { 611 switch (sd->chip_revision) {
624 case Rev072A: 612 case Rev072A:
625 lowb = sd->contrast >> 8; 613 lowb = sd->contrast >> 8;
626 reg_w_val(dev, lowb, 0x8651); 614 reg_w_val(dev, 0x8651, lowb);
627 reg_w_val(dev, lowb, 0x8652); 615 reg_w_val(dev, 0x8652, lowb);
628 reg_w_val(dev, lowb, 0x8653); 616 reg_w_val(dev, 0x8653, lowb);
629 reg_w_val(dev, lowb, 0x8654); 617 reg_w_val(dev, 0x8654, lowb);
630 break; 618 break;
631 case Rev012A: { 619 default: {
632 __u8 Reg8391[] = 620/* case Rev012A: { */
633 { 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00 }; 621 static const __u8 Reg8391[] =
634 622 { 0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00 };
635 /* Write camera sensor settings */ 623
636 expotimes = (sd->contrast >> 5) & 0x07ff;
637 Reg8391[0] = expotimes & 0xff; /* exposure */
638 Reg8391[1] = 0x18 | (expotimes >> 8);
639 Reg8391[2] = sd->brightness; /* gain */
640 reg_w_buf(gspca_dev, 0x8391, Reg8391, 8); 624 reg_w_buf(gspca_dev, 0x8391, Reg8391, 8);
641 reg_w_buf(gspca_dev, 0x8390, Reg8391, 8); 625 reg_w_buf(gspca_dev, 0x8390, Reg8391, 8);
642 break; 626 break;
@@ -644,93 +628,151 @@ static void setcontrast(struct gspca_dev *gspca_dev)
644 } 628 }
645} 629}
646 630
647static void setautogain(struct gspca_dev *gspca_dev) 631/* rev12a only */
632static void setwhite(struct gspca_dev *gspca_dev)
648{ 633{
649 struct sd *sd = (struct sd *) gspca_dev; 634 struct sd *sd = (struct sd *) gspca_dev;
635 __u16 white;
636 __u8 reg8614, reg8616;
637
638 white = sd->white;
639 /* try to emulate MS-win as possible */
640 reg8616 = 0x90 - white * 5 / 8;
641 reg_w_val(gspca_dev->dev, 0x8616, reg8616);
642 reg8614 = 0x20 + white * 3 / 8;
643 reg_w_val(gspca_dev->dev, 0x8614, reg8614);
644}
650 645
651 if (sd->chip_revision == Rev072A) { 646/* rev 12a only */
652 if (sd->autogain) 647static void setexposure(struct gspca_dev *gspca_dev)
653 sd->ag_cnt = AG_CNT_START; 648{
654 else 649 struct sd *sd = (struct sd *) gspca_dev;
655 sd->ag_cnt = -1; 650 int expo;
651 int clock_divider;
652 __u8 data[2];
653
654 /* Register 0x8309 controls exposure for the spca561,
655 the basic exposure setting goes from 1-2047, where 1 is completely
656 dark and 2047 is very bright. It not only influences exposure but
657 also the framerate (to allow for longer exposure) from 1 - 300 it
658 only raises the exposure time then from 300 - 600 it halves the
659 framerate to be able to further raise the exposure time and for every
660 300 more it halves the framerate again. This allows for a maximum
661 exposure time of circa 0.2 - 0.25 seconds (30 / (2000/3000) fps).
662 Sometimes this is not enough, the 1-2047 uses bits 0-10, bits 11-12
663 configure a divider for the base framerate which us used at the
664 exposure setting of 1-300. These bits configure the base framerate
665 according to the following formula: fps = 60 / (value + 2) */
666 if (sd->exposure < 2048) {
667 expo = sd->exposure;
668 clock_divider = 0;
669 } else {
670 /* Add 900 to make the 0 setting of the second part of the
671 exposure equal to the 2047 setting of the first part. */
672 expo = (sd->exposure - 2048) + 900;
673 clock_divider = 3;
656 } 674 }
675 expo |= clock_divider << 11;
676 data[0] = expo;
677 data[1] = expo >> 8;
678 reg_w_buf(gspca_dev, 0x8309, data, 2);
679}
680
681/* rev 12a only */
682static void setgain(struct gspca_dev *gspca_dev)
683{
684 struct sd *sd = (struct sd *) gspca_dev;
685 __u8 data[2];
686
687 data[0] = sd->gain;
688 data[1] = 0;
689 reg_w_buf(gspca_dev, 0x8335, data, 2);
657} 690}
658 691
659static void sd_start(struct gspca_dev *gspca_dev) 692static void setautogain(struct gspca_dev *gspca_dev)
660{ 693{
661 struct sd *sd = (struct sd *) gspca_dev; 694 struct sd *sd = (struct sd *) gspca_dev;
695
696 if (sd->autogain)
697 sd->ag_cnt = AG_CNT_START;
698 else
699 sd->ag_cnt = -1;
700}
701
702static void sd_start_12a(struct gspca_dev *gspca_dev)
703{
662 struct usb_device *dev = gspca_dev->dev; 704 struct usb_device *dev = gspca_dev->dev;
663 int Clck; 705 int Clck = 0x8a; /* lower 0x8X values lead to fps > 30 */
664 __u8 Reg8307[] = { 0xaa, 0x00 }; 706 __u8 Reg8307[] = { 0xaa, 0x00 };
665 int mode; 707 int mode;
666 708
667 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 709 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
668 switch (sd->chip_revision) { 710 if (mode <= 1) {
669 case Rev072A: 711 /* Use compression on 320x240 and above */
670 switch (mode) { 712 reg_w_val(dev, 0x8500, 0x10 | mode);
671 default: 713 } else {
672/* case 0: 714 /* I couldn't get the compression to work below 320x240
673 case 1: */ 715 * Fortunately at these resolutions the bandwidth
674 Clck = 0x25; 716 * is sufficient to push raw frames at ~20fps */
675 break; 717 reg_w_val(dev, 0x8500, mode);
676 case 2: 718 } /* -- qq@kuku.eu.org */
677 Clck = 0x22; 719 reg_w_buf(gspca_dev, 0x8307, Reg8307, 2);
678 break; 720 reg_w_val(gspca_dev->dev, 0x8700, Clck);
679 case 3: 721 /* 0x8f 0x85 0x27 clock */
680 Clck = 0x21; 722 reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
681 break; 723 reg_w_val(gspca_dev->dev, 0x850b, 0x03);
682 } 724 setcontrast(gspca_dev);
683 reg_w_val(dev, 0x8500, mode); /* mode */ 725 setwhite(gspca_dev);
684 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */ 726 setautogain(gspca_dev);
685 reg_w_val(dev, 0x8112, 0x10 | 0x20); 727 setexposure(gspca_dev);
686 setautogain(gspca_dev); 728}
687 break; 729static void sd_start_72a(struct gspca_dev *gspca_dev)
730{
731 struct usb_device *dev = gspca_dev->dev;
732 int Clck;
733 int mode;
734
735 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
736 switch (mode) {
688 default: 737 default:
689/* case Rev012A: */ 738/* case 0:
690 switch (mode) { 739 case 1: */
691 case 0: 740 Clck = 0x25;
692 case 1: 741 break;
693 Clck = 0x8a; 742 case 2:
694 break; 743 Clck = 0x22;
695 case 2: 744 break;
696 Clck = 0x85; 745 case 3:
697 break; 746 Clck = 0x21;
698 default:
699 Clck = 0x83;
700 break;
701 }
702 if (mode <= 1) {
703 /* Use compression on 320x240 and above */
704 reg_w_val(dev, 0x8500, 0x10 | mode);
705 } else {
706 /* I couldn't get the compression to work below 320x240
707 * Fortunately at these resolutions the bandwidth
708 * is sufficient to push raw frames at ~20fps */
709 reg_w_val(dev, 0x8500, mode);
710 } /* -- qq@kuku.eu.org */
711 reg_w_buf(gspca_dev, 0x8307, Reg8307, 2);
712 reg_w_val(gspca_dev->dev, 0x8700, Clck);
713 /* 0x8f 0x85 0x27 clock */
714 reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
715 reg_w_val(gspca_dev->dev, 0x850b, 0x03);
716 setcontrast(gspca_dev);
717 break; 747 break;
718 } 748 }
749 reg_w_val(dev, 0x8500, mode); /* mode */
750 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
751 reg_w_val(dev, 0x8112, 0x10 | 0x20);
752 setautogain(gspca_dev);
719} 753}
720 754
721static void sd_stopN(struct gspca_dev *gspca_dev) 755static void sd_stopN(struct gspca_dev *gspca_dev)
722{ 756{
723 reg_w_val(gspca_dev->dev, 0x8112, 0x20); 757 struct sd *sd = (struct sd *) gspca_dev;
758
759 if (sd->chip_revision == Rev012A) {
760 reg_w_val(gspca_dev->dev, 0x8112, 0x0e);
761 } else {
762 reg_w_val(gspca_dev->dev, 0x8112, 0x20);
763/* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */
764 }
724} 765}
725 766
726static void sd_stop0(struct gspca_dev *gspca_dev) 767static void sd_stop0(struct gspca_dev *gspca_dev)
727{ 768{
728} 769 struct sd *sd = (struct sd *) gspca_dev;
729 770
730/* this function is called at close time */ 771 if (sd->chip_revision == Rev012A) {
731static void sd_close(struct gspca_dev *gspca_dev) 772 reg_w_val(gspca_dev->dev, 0x8118, 0x29);
732{ 773 reg_w_val(gspca_dev->dev, 0x8114, 0x08);
733 reg_w_val(gspca_dev->dev, 0x8114, 0); 774 }
775/* reg_w_val(gspca_dev->dev, 0x8114, 0); */
734} 776}
735 777
736static void do_autogain(struct gspca_dev *gspca_dev) 778static void do_autogain(struct gspca_dev *gspca_dev)
@@ -744,6 +786,7 @@ static void do_autogain(struct gspca_dev *gspca_dev)
744 __u8 luma_mean = 110; 786 __u8 luma_mean = 110;
745 __u8 luma_delta = 20; 787 __u8 luma_delta = 20;
746 __u8 spring = 4; 788 __u8 spring = 4;
789 __u8 reg8339[2];
747 790
748 if (sd->ag_cnt < 0) 791 if (sd->ag_cnt < 0)
749 return; 792 return;
@@ -798,13 +841,16 @@ static void do_autogain(struct gspca_dev *gspca_dev)
798 } 841 }
799 break; 842 break;
800 case Rev012A: 843 case Rev012A:
801 /* sensor registers is access and memory mapped to 0x8300 */ 844 reg_r(gspca_dev, 0x8330, 2);
802 /* readind all 0x83xx block the sensor */ 845 if (gspca_dev->usb_buf[1] > 0x08) {
803 /* 846 reg8339[0] = ++sd->expo12a;
804 * The data from the header seem wrong where is the luma 847 reg8339[1] = 0;
805 * and chroma mean value 848 reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
806 * at the moment set exposure in contrast set 849 } else if (gspca_dev->usb_buf[1] < 0x02) {
807 */ 850 reg8339[0] = --sd->expo12a;
851 reg8339[1] = 0;
852 reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
853 }
808 break; 854 break;
809 } 855 }
810} 856}
@@ -814,6 +860,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
814 __u8 *data, /* isoc packet */ 860 __u8 *data, /* isoc packet */
815 int len) /* iso packet length */ 861 int len) /* iso packet length */
816{ 862{
863 struct sd *sd = (struct sd *) gspca_dev;
864
817 switch (data[0]) { 865 switch (data[0]) {
818 case 0: /* start of frame */ 866 case 0: /* start of frame */
819 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, 867 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
@@ -826,8 +874,13 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
826 frame, data, len); 874 frame, data, len);
827 } else { 875 } else {
828 /* raw bayer (with a header, which we skip) */ 876 /* raw bayer (with a header, which we skip) */
829 data += 20; 877 if (sd->chip_revision == Rev012A) {
830 len -= 20; 878 data += 20;
879 len -= 20;
880 } else {
881 data += 16;
882 len -= 16;
883 }
831 gspca_frame_add(gspca_dev, FIRST_PACKET, 884 gspca_frame_add(gspca_dev, FIRST_PACKET,
832 frame, data, len); 885 frame, data, len);
833 } 886 }
@@ -841,24 +894,17 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
841 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); 894 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
842} 895}
843 896
897/* rev 72a only */
844static void setbrightness(struct gspca_dev *gspca_dev) 898static void setbrightness(struct gspca_dev *gspca_dev)
845{ 899{
846 struct sd *sd = (struct sd *) gspca_dev; 900 struct sd *sd = (struct sd *) gspca_dev;
847 __u8 value; 901 __u8 value;
848 902
849 switch (sd->chip_revision) { 903 value = sd->brightness;
850 case Rev072A: 904 reg_w_val(gspca_dev->dev, 0x8611, value);
851 value = sd->brightness; 905 reg_w_val(gspca_dev->dev, 0x8612, value);
852 reg_w_val(gspca_dev->dev, value, 0x8611); 906 reg_w_val(gspca_dev->dev, 0x8613, value);
853 reg_w_val(gspca_dev->dev, value, 0x8612); 907 reg_w_val(gspca_dev->dev, 0x8614, value);
854 reg_w_val(gspca_dev->dev, value, 0x8613);
855 reg_w_val(gspca_dev->dev, value, 0x8614);
856 break;
857 default:
858/* case Rev012A: */
859 setcontrast(gspca_dev);
860 break;
861 }
862} 908}
863 909
864static void getbrightness(struct gspca_dev *gspca_dev) 910static void getbrightness(struct gspca_dev *gspca_dev)
@@ -866,52 +912,38 @@ static void getbrightness(struct gspca_dev *gspca_dev)
866 struct sd *sd = (struct sd *) gspca_dev; 912 struct sd *sd = (struct sd *) gspca_dev;
867 __u16 tot; 913 __u16 tot;
868 914
869 switch (sd->chip_revision) { 915 tot = 0;
870 case Rev072A: 916 reg_r(gspca_dev, 0x8611, 1);
871 tot = 0; 917 tot += gspca_dev->usb_buf[0];
872 reg_r(gspca_dev, 0x8611, 1); 918 reg_r(gspca_dev, 0x8612, 1);
873 tot += gspca_dev->usb_buf[0]; 919 tot += gspca_dev->usb_buf[0];
874 reg_r(gspca_dev, 0x8612, 1); 920 reg_r(gspca_dev, 0x8613, 1);
875 tot += gspca_dev->usb_buf[0]; 921 tot += gspca_dev->usb_buf[0];
876 reg_r(gspca_dev, 0x8613, 1); 922 reg_r(gspca_dev, 0x8614, 1);
877 tot += gspca_dev->usb_buf[0]; 923 tot += gspca_dev->usb_buf[0];
878 reg_r(gspca_dev, 0x8614, 1); 924 sd->brightness = tot >> 2;
879 tot += gspca_dev->usb_buf[0];
880 sd->brightness = tot >> 2;
881 break;
882 default:
883/* case Rev012A: */
884 /* no way to read sensor settings */
885 break;
886 }
887} 925}
888 926
927/* rev72a only */
889static void getcontrast(struct gspca_dev *gspca_dev) 928static void getcontrast(struct gspca_dev *gspca_dev)
890{ 929{
891 struct sd *sd = (struct sd *) gspca_dev; 930 struct sd *sd = (struct sd *) gspca_dev;
892 __u16 tot; 931 __u16 tot;
893 932
894 switch (sd->chip_revision) { 933 tot = 0;
895 case Rev072A: 934 reg_r(gspca_dev, 0x8651, 1);
896 tot = 0; 935 tot += gspca_dev->usb_buf[0];
897 reg_r(gspca_dev, 0x8651, 1); 936 reg_r(gspca_dev, 0x8652, 1);
898 tot += gspca_dev->usb_buf[0]; 937 tot += gspca_dev->usb_buf[0];
899 reg_r(gspca_dev, 0x8652, 1); 938 reg_r(gspca_dev, 0x8653, 1);
900 tot += gspca_dev->usb_buf[0]; 939 tot += gspca_dev->usb_buf[0];
901 reg_r(gspca_dev, 0x8653, 1); 940 reg_r(gspca_dev, 0x8654, 1);
902 tot += gspca_dev->usb_buf[0]; 941 tot += gspca_dev->usb_buf[0];
903 reg_r(gspca_dev, 0x8654, 1); 942 sd->contrast = tot << 6;
904 tot += gspca_dev->usb_buf[0];
905 sd->contrast = tot << 6;
906 break;
907 default:
908/* case Rev012A: */
909 /* no way to read sensor settings */
910 break;
911 }
912 PDEBUG(D_CONF, "get contrast %d", sd->contrast); 943 PDEBUG(D_CONF, "get contrast %d", sd->contrast);
913} 944}
914 945
946/* rev 72a only */
915static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 947static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
916{ 948{
917 struct sd *sd = (struct sd *) gspca_dev; 949 struct sd *sd = (struct sd *) gspca_dev;
@@ -931,6 +963,7 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
931 return 0; 963 return 0;
932} 964}
933 965
966/* rev 72a only */
934static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) 967static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
935{ 968{
936 struct sd *sd = (struct sd *) gspca_dev; 969 struct sd *sd = (struct sd *) gspca_dev;
@@ -968,20 +1001,190 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
968 return 0; 1001 return 0;
969} 1002}
970 1003
1004/* rev12a only */
1005static int sd_setwhite(struct gspca_dev *gspca_dev, __s32 val)
1006{
1007 struct sd *sd = (struct sd *) gspca_dev;
1008
1009 sd->white = val;
1010 if (gspca_dev->streaming)
1011 setwhite(gspca_dev);
1012 return 0;
1013}
1014
1015static int sd_getwhite(struct gspca_dev *gspca_dev, __s32 *val)
1016{
1017 struct sd *sd = (struct sd *) gspca_dev;
1018
1019 *val = sd->white;
1020 return 0;
1021}
1022
1023/* rev12a only */
1024static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1025{
1026 struct sd *sd = (struct sd *) gspca_dev;
1027
1028 sd->exposure = val;
1029 if (gspca_dev->streaming)
1030 setexposure(gspca_dev);
1031 return 0;
1032}
1033
1034static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
1035{
1036 struct sd *sd = (struct sd *) gspca_dev;
1037
1038 *val = sd->exposure;
1039 return 0;
1040}
1041
1042/* rev12a only */
1043static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
1044{
1045 struct sd *sd = (struct sd *) gspca_dev;
1046
1047 sd->gain = val;
1048 if (gspca_dev->streaming)
1049 setgain(gspca_dev);
1050 return 0;
1051}
1052
1053static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1054{
1055 struct sd *sd = (struct sd *) gspca_dev;
1056
1057 *val = sd->gain;
1058 return 0;
1059}
1060
1061/* control tables */
1062static struct ctrl sd_ctrls_12a[] = {
1063 {
1064 {
1065 .id = V4L2_CID_DO_WHITE_BALANCE,
1066 .type = V4L2_CTRL_TYPE_INTEGER,
1067 .name = "While Balance",
1068 .minimum = WHITE_MIN,
1069 .maximum = WHITE_MAX,
1070 .step = 1,
1071 .default_value = WHITE_DEF,
1072 },
1073 .set = sd_setwhite,
1074 .get = sd_getwhite,
1075 },
1076 {
1077 {
1078 .id = V4L2_CID_EXPOSURE,
1079 .type = V4L2_CTRL_TYPE_INTEGER,
1080 .name = "Exposure",
1081 .minimum = EXPOSURE_MIN,
1082 .maximum = EXPOSURE_MAX,
1083 .step = 1,
1084 .default_value = EXPOSURE_DEF,
1085 },
1086 .set = sd_setexposure,
1087 .get = sd_getexposure,
1088 },
1089 {
1090 {
1091 .id = V4L2_CID_AUTOGAIN,
1092 .type = V4L2_CTRL_TYPE_BOOLEAN,
1093 .name = "Auto Gain",
1094 .minimum = AUTOGAIN_MIN,
1095 .maximum = AUTOGAIN_MAX,
1096 .step = 1,
1097 .default_value = AUTOGAIN_DEF,
1098 },
1099 .set = sd_setautogain,
1100 .get = sd_getautogain,
1101 },
1102 {
1103 {
1104 .id = V4L2_CID_GAIN,
1105 .type = V4L2_CTRL_TYPE_INTEGER,
1106 .name = "Gain",
1107 .minimum = GAIN_MIN,
1108 .maximum = GAIN_MAX,
1109 .step = 1,
1110 .default_value = GAIN_DEF,
1111 },
1112 .set = sd_setgain,
1113 .get = sd_getgain,
1114 },
1115};
1116
1117static struct ctrl sd_ctrls_72a[] = {
1118 {
1119 {
1120 .id = V4L2_CID_BRIGHTNESS,
1121 .type = V4L2_CTRL_TYPE_INTEGER,
1122 .name = "Brightness",
1123 .minimum = BRIGHTNESS_MIN,
1124 .maximum = BRIGHTNESS_MAX,
1125 .step = 1,
1126 .default_value = BRIGHTNESS_DEF,
1127 },
1128 .set = sd_setbrightness,
1129 .get = sd_getbrightness,
1130 },
1131 {
1132 {
1133 .id = V4L2_CID_CONTRAST,
1134 .type = V4L2_CTRL_TYPE_INTEGER,
1135 .name = "Contrast",
1136 .minimum = CONTRAST_MIN,
1137 .maximum = CONTRAST_MAX,
1138 .step = 1,
1139 .default_value = CONTRAST_DEF,
1140 },
1141 .set = sd_setcontrast,
1142 .get = sd_getcontrast,
1143 },
1144 {
1145 {
1146 .id = V4L2_CID_AUTOGAIN,
1147 .type = V4L2_CTRL_TYPE_BOOLEAN,
1148 .name = "Auto Gain",
1149 .minimum = AUTOGAIN_MIN,
1150 .maximum = AUTOGAIN_MAX,
1151 .step = 1,
1152 .default_value = AUTOGAIN_DEF,
1153 },
1154 .set = sd_setautogain,
1155 .get = sd_getautogain,
1156 },
1157};
1158
971/* sub-driver description */ 1159/* sub-driver description */
972static const struct sd_desc sd_desc = { 1160static const struct sd_desc sd_desc_12a = {
1161 .name = MODULE_NAME,
1162 .ctrls = sd_ctrls_12a,
1163 .nctrls = ARRAY_SIZE(sd_ctrls_12a),
1164 .config = sd_config,
1165 .init = sd_init_12a,
1166 .start = sd_start_12a,
1167 .stopN = sd_stopN,
1168 .stop0 = sd_stop0,
1169 .pkt_scan = sd_pkt_scan,
1170/* .dq_callback = do_autogain, * fixme */
1171};
1172static const struct sd_desc sd_desc_72a = {
973 .name = MODULE_NAME, 1173 .name = MODULE_NAME,
974 .ctrls = sd_ctrls, 1174 .ctrls = sd_ctrls_72a,
975 .nctrls = ARRAY_SIZE(sd_ctrls), 1175 .nctrls = ARRAY_SIZE(sd_ctrls_72a),
976 .config = sd_config, 1176 .config = sd_config,
977 .open = sd_open, 1177 .init = sd_init_72a,
978 .start = sd_start, 1178 .start = sd_start_72a,
979 .stopN = sd_stopN, 1179 .stopN = sd_stopN,
980 .stop0 = sd_stop0, 1180 .stop0 = sd_stop0,
981 .close = sd_close,
982 .pkt_scan = sd_pkt_scan, 1181 .pkt_scan = sd_pkt_scan,
983 .dq_callback = do_autogain, 1182 .dq_callback = do_autogain,
984}; 1183};
1184static const struct sd_desc *sd_desc[2] = {
1185 &sd_desc_12a,
1186 &sd_desc_72a
1187};
985 1188
986/* -- module initialisation -- */ 1189/* -- module initialisation -- */
987static const __devinitdata struct usb_device_id device_table[] = { 1190static const __devinitdata struct usb_device_id device_table[] = {
@@ -1009,7 +1212,9 @@ MODULE_DEVICE_TABLE(usb, device_table);
1009static int sd_probe(struct usb_interface *intf, 1212static int sd_probe(struct usb_interface *intf,
1010 const struct usb_device_id *id) 1213 const struct usb_device_id *id)
1011{ 1214{
1012 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), 1215 return gspca_dev_probe(intf, id,
1216 sd_desc[id->driver_info],
1217 sizeof(struct sd),
1013 THIS_MODULE); 1218 THIS_MODULE);
1014} 1219}
1015 1220
@@ -1018,6 +1223,10 @@ static struct usb_driver sd_driver = {
1018 .id_table = device_table, 1223 .id_table = device_table,
1019 .probe = sd_probe, 1224 .probe = sd_probe,
1020 .disconnect = gspca_disconnect, 1225 .disconnect = gspca_disconnect,
1226#ifdef CONFIG_PM
1227 .suspend = gspca_suspend,
1228 .resume = gspca_resume,
1229#endif
1021}; 1230};
1022 1231
1023/* -- module insert / remove -- */ 1232/* -- module insert / remove -- */