2 * Mars MR97310A library
4 * The original mr97310a driver, which supported the Aiptek Pencam VGA+, is
5 * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com>
7 * Support for the MR97310A cameras in addition to the Aiptek Pencam VGA+
8 * and for the routines for detecting and classifying these various cameras,
9 * is Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu>
11 * Support for the control settings for the CIF cameras is
12 * Copyright (C) 2009 Hans de Goede <hdgoede@redhat.com> and
13 * Thomas Kaiser <thomas@kaiser-linux.li>
15 * Support for the control settings for the VGA cameras is
16 * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu>
18 * Several previously unsupported cameras are owned and have been tested by
19 * Hans de Goede <hdgoede@redhat.com> and
20 * Thomas Kaiser <thomas@kaiser-linux.li> and
21 * Theodore Kilgore <kilgota@auburn.edu>
23 * The MR97311A support in gspca/mars.c has been helpful in understanding some
24 * of the registers in these cameras.
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 #define MODULE_NAME "mr97310a"
45 #define CAM_TYPE_CIF 0
46 #define CAM_TYPE_VGA 1
48 #define MR97310A_BRIGHTNESS_DEFAULT 0
50 #define MR97310A_EXPOSURE_MIN 0
51 #define MR97310A_EXPOSURE_MAX 4095
52 #define MR97310A_EXPOSURE_DEFAULT 1000
54 #define MR97310A_GAIN_MIN 0
55 #define MR97310A_GAIN_MAX 31
56 #define MR97310A_GAIN_DEFAULT 25
58 MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>,"
59 "Theodore Kilgore <kilgota@auburn.edu>");
60 MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver");
61 MODULE_LICENSE("GPL");
63 /* global parameters */
64 int force_sensor_type
= -1;
65 module_param(force_sensor_type
, int, 0644);
66 MODULE_PARM_DESC(force_sensor_type
, "Force sensor type (-1 (auto), 0 or 1)");
68 /* specific webcam descriptor */
70 struct gspca_dev gspca_dev
; /* !! must be the first item */
72 u8 cam_type
; /* 0 is CIF and 1 is VGA */
73 u8 sensor_type
; /* We use 0 and 1 here, too. */
81 struct sensor_w_data
{
88 static void sd_stopN(struct gspca_dev
*gspca_dev
);
89 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
);
90 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
);
91 static int sd_setexposure(struct gspca_dev
*gspca_dev
, __s32 val
);
92 static int sd_getexposure(struct gspca_dev
*gspca_dev
, __s32
*val
);
93 static int sd_setgain(struct gspca_dev
*gspca_dev
, __s32 val
);
94 static int sd_getgain(struct gspca_dev
*gspca_dev
, __s32
*val
);
95 static void setbrightness(struct gspca_dev
*gspca_dev
);
96 static void setexposure(struct gspca_dev
*gspca_dev
);
97 static void setgain(struct gspca_dev
*gspca_dev
);
99 /* V4L2 controls supported by the driver */
100 static struct ctrl sd_ctrls
[] = {
101 /* Seprate brightness control description for Argus QuickClix as it has
102 different limits from to other mr97310a camera's */
104 #define NORM_BRIGHTNESS_IDX 0
106 .id
= V4L2_CID_BRIGHTNESS
,
107 .type
= V4L2_CTRL_TYPE_INTEGER
,
108 .name
= "Brightness",
112 .default_value
= MR97310A_BRIGHTNESS_DEFAULT
,
115 .set
= sd_setbrightness
,
116 .get
= sd_getbrightness
,
119 #define ARGUS_QC_BRIGHTNESS_IDX 1
121 .id
= V4L2_CID_BRIGHTNESS
,
122 .type
= V4L2_CTRL_TYPE_INTEGER
,
123 .name
= "Brightness",
127 .default_value
= MR97310A_BRIGHTNESS_DEFAULT
,
130 .set
= sd_setbrightness
,
131 .get
= sd_getbrightness
,
134 #define EXPOSURE_IDX 2
136 .id
= V4L2_CID_EXPOSURE
,
137 .type
= V4L2_CTRL_TYPE_INTEGER
,
139 .minimum
= MR97310A_EXPOSURE_MIN
,
140 .maximum
= MR97310A_EXPOSURE_MAX
,
142 .default_value
= MR97310A_EXPOSURE_DEFAULT
,
145 .set
= sd_setexposure
,
146 .get
= sd_getexposure
,
152 .type
= V4L2_CTRL_TYPE_INTEGER
,
154 .minimum
= MR97310A_GAIN_MIN
,
155 .maximum
= MR97310A_GAIN_MAX
,
157 .default_value
= MR97310A_GAIN_DEFAULT
,
165 static const struct v4l2_pix_format vga_mode
[] = {
166 {160, 120, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
168 .sizeimage
= 160 * 120,
169 .colorspace
= V4L2_COLORSPACE_SRGB
,
171 {176, 144, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
173 .sizeimage
= 176 * 144,
174 .colorspace
= V4L2_COLORSPACE_SRGB
,
176 {320, 240, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
178 .sizeimage
= 320 * 240,
179 .colorspace
= V4L2_COLORSPACE_SRGB
,
181 {352, 288, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
183 .sizeimage
= 352 * 288,
184 .colorspace
= V4L2_COLORSPACE_SRGB
,
186 {640, 480, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
188 .sizeimage
= 640 * 480,
189 .colorspace
= V4L2_COLORSPACE_SRGB
,
193 /* the bytes to write are in gspca_dev->usb_buf */
194 static int mr_write(struct gspca_dev
*gspca_dev
, int len
)
198 rc
= usb_bulk_msg(gspca_dev
->dev
,
199 usb_sndbulkpipe(gspca_dev
->dev
, 4),
200 gspca_dev
->usb_buf
, len
, NULL
, 500);
202 PDEBUG(D_ERR
, "reg write [%02x] error %d",
203 gspca_dev
->usb_buf
[0], rc
);
207 /* the bytes are read into gspca_dev->usb_buf */
208 static int mr_read(struct gspca_dev
*gspca_dev
, int len
)
212 rc
= usb_bulk_msg(gspca_dev
->dev
,
213 usb_rcvbulkpipe(gspca_dev
->dev
, 3),
214 gspca_dev
->usb_buf
, len
, NULL
, 500);
216 PDEBUG(D_ERR
, "reg read [%02x] error %d",
217 gspca_dev
->usb_buf
[0], rc
);
221 static int sensor_write_reg(struct gspca_dev
*gspca_dev
, u8 reg
, u8 flags
,
222 const u8
*data
, int len
)
224 gspca_dev
->usb_buf
[0] = 0x1f;
225 gspca_dev
->usb_buf
[1] = flags
;
226 gspca_dev
->usb_buf
[2] = reg
;
227 memcpy(gspca_dev
->usb_buf
+ 3, data
, len
);
229 return mr_write(gspca_dev
, len
+ 3);
232 static int sensor_write_regs(struct gspca_dev
*gspca_dev
,
233 const struct sensor_w_data
*data
, int len
)
237 for (i
= 0; i
< len
; i
++) {
238 rc
= sensor_write_reg(gspca_dev
, data
[i
].reg
, data
[i
].flags
,
239 data
[i
].data
, data
[i
].len
);
247 static int sensor_write1(struct gspca_dev
*gspca_dev
, u8 reg
, u8 data
)
249 struct sd
*sd
= (struct sd
*) gspca_dev
;
254 if (sd
->cam_type
== CAM_TYPE_CIF
) {
255 rc
= sensor_write_reg(gspca_dev
, reg
, 0x01, &buf
, 1);
256 confirm_reg
= sd
->sensor_type
? 0x13 : 0x11;
258 rc
= sensor_write_reg(gspca_dev
, reg
, 0x00, &buf
, 1);
265 rc
= sensor_write_reg(gspca_dev
, confirm_reg
, 0x00, &buf
, 1);
272 static int cam_get_response16(struct gspca_dev
*gspca_dev
, u8 reg
, int verbose
)
276 gspca_dev
->usb_buf
[0] = reg
;
277 err_code
= mr_write(gspca_dev
, 1);
281 err_code
= mr_read(gspca_dev
, 16);
286 PDEBUG(D_PROBE
, "Register: %02x reads %02x%02x%02x", reg
,
287 gspca_dev
->usb_buf
[0],
288 gspca_dev
->usb_buf
[1],
289 gspca_dev
->usb_buf
[2]);
294 static int zero_the_pointer(struct gspca_dev
*gspca_dev
)
296 __u8
*data
= gspca_dev
->usb_buf
;
301 err_code
= cam_get_response16(gspca_dev
, 0x21, 0);
305 err_code
= mr_write(gspca_dev
, 1);
308 err_code
= mr_write(gspca_dev
, 2);
312 err_code
= cam_get_response16(gspca_dev
, 0x21, 0);
318 err_code
= mr_write(gspca_dev
, 2);
322 err_code
= cam_get_response16(gspca_dev
, 0x21, 0);
328 err_code
= mr_write(gspca_dev
, 2);
332 err_code
= cam_get_response16(gspca_dev
, 0x21, 0);
338 err_code
= mr_write(gspca_dev
, 2);
342 while (status
!= 0x0a && tries
< 256) {
343 err_code
= cam_get_response16(gspca_dev
, 0x21, 0);
350 PDEBUG(D_ERR
, "status is %02x", status
);
356 err_code
= mr_write(gspca_dev
, 2);
360 err_code
= cam_get_response16(gspca_dev
, 0x21, 0);
368 err_code
= mr_write(gspca_dev
, 1);
372 err_code
= mr_read(gspca_dev
, 16);
379 static int stream_start(struct gspca_dev
*gspca_dev
)
381 gspca_dev
->usb_buf
[0] = 0x01;
382 gspca_dev
->usb_buf
[1] = 0x01;
383 return mr_write(gspca_dev
, 2);
386 static void stream_stop(struct gspca_dev
*gspca_dev
)
388 gspca_dev
->usb_buf
[0] = 0x01;
389 gspca_dev
->usb_buf
[1] = 0x00;
390 if (mr_write(gspca_dev
, 2) < 0)
391 PDEBUG(D_ERR
, "Stream Stop failed");
394 static void lcd_stop(struct gspca_dev
*gspca_dev
)
396 gspca_dev
->usb_buf
[0] = 0x19;
397 gspca_dev
->usb_buf
[1] = 0x54;
398 if (mr_write(gspca_dev
, 2) < 0)
399 PDEBUG(D_ERR
, "LCD Stop failed");
402 static int isoc_enable(struct gspca_dev
*gspca_dev
)
404 gspca_dev
->usb_buf
[0] = 0x00;
405 gspca_dev
->usb_buf
[1] = 0x4d; /* ISOC transfering enable... */
406 return mr_write(gspca_dev
, 2);
409 /* this function is called at probe time */
410 static int sd_config(struct gspca_dev
*gspca_dev
,
411 const struct usb_device_id
*id
)
413 struct sd
*sd
= (struct sd
*) gspca_dev
;
417 cam
= &gspca_dev
->cam
;
418 cam
->cam_mode
= vga_mode
;
419 cam
->nmodes
= ARRAY_SIZE(vga_mode
);
422 /* Now, logical layout of the driver must fall sacrifice to the
423 * realities of the hardware supported. We have to sort out several
424 * cameras which share the USB ID but are in fact different inside.
425 * We need to start the initialization process for the cameras in
426 * order to classify them. Some of the supported cameras require the
427 * memory pointer to be set to 0 as the very first item of business
428 * or else they will not stream. So we do that immediately.
430 err_code
= zero_the_pointer(gspca_dev
);
434 err_code
= stream_start(gspca_dev
);
438 if (id
->idProduct
== 0x010e) {
439 sd
->cam_type
= CAM_TYPE_CIF
;
441 err_code
= cam_get_response16(gspca_dev
, 0x06, 1);
445 * The various CIF cameras share the same USB ID but use
446 * different init routines and different controls. We need to
447 * detect which one is connected!
449 * A list of known CIF cameras follows. They all report either
450 * 0002 for type 0 or 0003 for type 1.
451 * If you have another to report, please do
453 * Name sd->sensor_type reported by
455 * Sakar Spy-shot 0 T. Kilgore
456 * Innovage 0 T. Kilgore
457 * Vivitar Mini 0 H. De Goede
458 * Vivitar Mini 0 E. Rodriguez
459 * Vivitar Mini 1 T. Kilgore
460 * Elta-Media 8212dc 1 T. Kaiser
461 * Philips dig. keych. 1 T. Kilgore
463 switch (gspca_dev
->usb_buf
[1]) {
471 PDEBUG(D_ERR
, "Unknown CIF Sensor id : %02x",
472 gspca_dev
->usb_buf
[1]);
475 PDEBUG(D_PROBE
, "MR97310A CIF camera detected, sensor: %d",
478 sd
->cam_type
= CAM_TYPE_VGA
;
480 err_code
= cam_get_response16(gspca_dev
, 0x07, 1);
485 * Here is a table of the responses to the previous command
486 * from the known MR97310A VGA cameras.
488 * Name gspca_dev->usb_buf[] sd->sensor_type
490 * Aiptek Pencam VGA+ 0300 0 1
491 * ION digital 0350 0 1
492 * Argus DC-1620 0450 1 0
493 * Argus QuickClix 0420 1 1
495 * Based upon these results, we assume default settings
496 * and then correct as necessary, as follows.
502 if ((gspca_dev
->usb_buf
[0] != 0x03) &&
503 (gspca_dev
->usb_buf
[0] != 0x04)) {
504 PDEBUG(D_ERR
, "Unknown VGA Sensor id Byte 0: %02x",
505 gspca_dev
->usb_buf
[1]);
506 PDEBUG(D_ERR
, "Defaults assumed, may not work");
507 PDEBUG(D_ERR
, "Please report this");
509 if (gspca_dev
->usb_buf
[0] == 0x04) {
511 switch (gspca_dev
->usb_buf
[1]) {
514 PDEBUG(D_PROBE
, "sensor_type corrected to 0");
517 /* Nothing to do here. */
521 "Unknown VGA Sensor id Byte 1: %02x",
522 gspca_dev
->usb_buf
[1]);
524 "Defaults assumed, may not work");
525 PDEBUG(D_ERR
, "Please report this");
528 PDEBUG(D_PROBE
, "MR97310A VGA camera detected, sensor: %d",
531 /* Stop streaming as we've started it to probe the sensor type. */
534 if (force_sensor_type
!= -1) {
535 sd
->sensor_type
= !!force_sensor_type
;
536 PDEBUG(D_PROBE
, "Forcing sensor type to: %d",
540 /* Setup controls depending on camera type */
541 if (sd
->cam_type
== CAM_TYPE_CIF
) {
542 /* No brightness for sensor_type 0 */
543 if (sd
->sensor_type
== 0)
544 gspca_dev
->ctrl_dis
= (1 << NORM_BRIGHTNESS_IDX
) |
545 (1 << ARGUS_QC_BRIGHTNESS_IDX
);
547 gspca_dev
->ctrl_dis
= (1 << ARGUS_QC_BRIGHTNESS_IDX
);
549 /* All controls need to be disabled if VGA sensor_type is 0 */
550 if (sd
->sensor_type
== 0)
551 gspca_dev
->ctrl_dis
= (1 << NORM_BRIGHTNESS_IDX
) |
552 (1 << ARGUS_QC_BRIGHTNESS_IDX
) |
553 (1 << EXPOSURE_IDX
) |
555 else if (sd
->do_lcd_stop
)
556 /* Argus QuickClix has different brightness limits */
557 gspca_dev
->ctrl_dis
= (1 << NORM_BRIGHTNESS_IDX
);
559 gspca_dev
->ctrl_dis
= (1 << ARGUS_QC_BRIGHTNESS_IDX
);
562 sd
->brightness
= MR97310A_BRIGHTNESS_DEFAULT
;
563 sd
->exposure
= MR97310A_EXPOSURE_DEFAULT
;
564 sd
->gain
= MR97310A_GAIN_DEFAULT
;
569 /* this function is called at probe and resume time */
570 static int sd_init(struct gspca_dev
*gspca_dev
)
575 static int start_cif_cam(struct gspca_dev
*gspca_dev
)
577 struct sd
*sd
= (struct sd
*) gspca_dev
;
578 __u8
*data
= gspca_dev
->usb_buf
;
580 const __u8 startup_string
[] = {
584 0x00, /* Hsize/8 for 352 or 320 */
585 0x00, /* Vsize/4 for 288 or 240 */
586 0x13, /* or 0xbb, depends on sensor */
587 0x00, /* Hstart, depends on res. */
588 0x00, /* reserved ? */
589 0x00, /* Vstart, depends on res. and sensor */
590 0x50, /* 0x54 to get 176 or 160 */
594 /* Note: Some of the above descriptions guessed from MR97113A driver */
596 memcpy(data
, startup_string
, 11);
600 switch (gspca_dev
->width
) {
602 data
[9] |= 0x04; /* reg 8, 2:1 scale down from 320 */
606 data
[3] = 0x28; /* reg 2, H size/8 */
607 data
[4] = 0x3c; /* reg 3, V size/4 */
608 data
[6] = 0x14; /* reg 5, H start */
609 data
[8] = 0x1a + sd
->sensor_type
; /* reg 7, V start */
612 data
[9] |= 0x04; /* reg 8, 2:1 scale down from 352 */
615 data
[3] = 0x2c; /* reg 2, H size/8 */
616 data
[4] = 0x48; /* reg 3, V size/4 */
617 data
[6] = 0x06; /* reg 5, H start */
618 data
[8] = 0x06 - sd
->sensor_type
; /* reg 7, V start */
621 err_code
= mr_write(gspca_dev
, 11);
625 if (!sd
->sensor_type
) {
626 const struct sensor_w_data cif_sensor0_init_data
[] = {
627 {0x02, 0x00, {0x03, 0x5a, 0xb5, 0x01,
628 0x0f, 0x14, 0x0f, 0x10}, 8},
629 {0x0c, 0x00, {0x04, 0x01, 0x01, 0x00, 0x1f}, 5},
630 {0x12, 0x00, {0x07}, 1},
631 {0x1f, 0x00, {0x06}, 1},
632 {0x27, 0x00, {0x04}, 1},
633 {0x29, 0x00, {0x0c}, 1},
634 {0x40, 0x00, {0x40, 0x00, 0x04}, 3},
635 {0x50, 0x00, {0x60}, 1},
636 {0x60, 0x00, {0x06}, 1},
637 {0x6b, 0x00, {0x85, 0x85, 0xc8, 0xc8, 0xc8, 0xc8}, 6},
638 {0x72, 0x00, {0x1e, 0x56}, 2},
639 {0x75, 0x00, {0x58, 0x40, 0xa2, 0x02, 0x31, 0x02,
640 0x31, 0x80, 0x00}, 9},
641 {0x11, 0x00, {0x01}, 1},
644 err_code
= sensor_write_regs(gspca_dev
, cif_sensor0_init_data
,
645 ARRAY_SIZE(cif_sensor0_init_data
));
646 } else { /* sd->sensor_type = 1 */
647 const struct sensor_w_data cif_sensor1_init_data
[] = {
648 /* Reg 3,4, 7,8 get set by the controls */
649 {0x02, 0x00, {0x10}, 1},
650 {0x05, 0x01, {0x22}, 1}, /* 5/6 also seen as 65h/32h */
651 {0x06, 0x01, {0x00}, 1},
652 {0x09, 0x02, {0x0e}, 1},
653 {0x0a, 0x02, {0x05}, 1},
654 {0x0b, 0x02, {0x05}, 1},
655 {0x0c, 0x02, {0x0f}, 1},
656 {0x0d, 0x02, {0x07}, 1},
657 {0x0e, 0x02, {0x0c}, 1},
658 {0x0f, 0x00, {0x00}, 1},
659 {0x10, 0x00, {0x06}, 1},
660 {0x11, 0x00, {0x07}, 1},
661 {0x12, 0x00, {0x00}, 1},
662 {0x13, 0x00, {0x01}, 1},
665 err_code
= sensor_write_regs(gspca_dev
, cif_sensor1_init_data
,
666 ARRAY_SIZE(cif_sensor1_init_data
));
671 static int start_vga_cam(struct gspca_dev
*gspca_dev
)
673 struct sd
*sd
= (struct sd
*) gspca_dev
;
674 __u8
*data
= gspca_dev
->usb_buf
;
676 const __u8 startup_string
[] = {0x00, 0x0d, 0x01, 0x00, 0x00, 0x2b,
677 0x00, 0x00, 0x00, 0x50, 0xc0};
678 /* What some of these mean is explained in start_cif_cam(), above */
680 memcpy(data
, startup_string
, 11);
681 if (!sd
->sensor_type
) {
686 switch (gspca_dev
->width
) {
688 data
[9] |= 0x0c; /* reg 8, 4:1 scale down */
691 data
[9] |= 0x04; /* reg 8, 2:1 scale down */
695 data
[3] = 0x50; /* reg 2, H size/8 */
696 data
[4] = 0x78; /* reg 3, V size/4 */
697 data
[6] = 0x04; /* reg 5, H start */
698 data
[8] = 0x03; /* reg 7, V start */
700 data
[8] = 0x04; /* Bayer tile shifted */
704 data
[9] |= 0x04; /* reg 8, 2:1 scale down */
707 data
[3] = 0x2c; /* reg 2, H size */
708 data
[4] = 0x48; /* reg 3, V size */
709 data
[6] = 0x94; /* reg 5, H start */
710 data
[8] = 0x63; /* reg 7, V start */
712 data
[8] = 0x64; /* Bayer tile shifted */
716 err_code
= mr_write(gspca_dev
, 11);
720 if (!sd
->sensor_type
) {
721 /* The only known sensor_type 0 cam is the Argus DC-1620 */
722 const struct sensor_w_data vga_sensor0_init_data
[] = {
723 {0x01, 0x00, {0x0c, 0x00, 0x04}, 3},
724 {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4},
725 {0x20, 0x00, {0x00, 0x80, 0x00, 0x08}, 4},
726 {0x25, 0x00, {0x03, 0xa9, 0x80}, 3},
727 {0x30, 0x00, {0x30, 0x18, 0x10, 0x18}, 4},
730 err_code
= sensor_write_regs(gspca_dev
, vga_sensor0_init_data
,
731 ARRAY_SIZE(vga_sensor0_init_data
));
732 } else { /* sd->sensor_type = 1 */
733 const struct sensor_w_data vga_sensor1_init_data
[] = {
734 {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00,
735 0x07, 0x00, 0x01}, 8},
736 {0x11, 0x04, {0x01}, 1},
737 /*{0x0a, 0x00, {0x00, 0x01, 0x00, 0x00, 0x01, */
738 {0x0a, 0x00, {0x01, 0x06, 0x00, 0x00, 0x01,
740 {0x11, 0x04, {0x01}, 1},
741 {0x12, 0x00, {0x00, 0x63, 0x00, 0x70, 0x00, 0x00}, 6},
742 {0x11, 0x04, {0x01}, 1},
745 err_code
= sensor_write_regs(gspca_dev
, vga_sensor1_init_data
,
746 ARRAY_SIZE(vga_sensor1_init_data
));
751 static int sd_start(struct gspca_dev
*gspca_dev
)
753 struct sd
*sd
= (struct sd
*) gspca_dev
;
758 /* Some of the VGA cameras require the memory pointer
759 * to be set to 0 again. We have been forced to start the
760 * stream somewhere else to detect the hardware, and closed it,
761 * and now since we are restarting the stream we need to do a
762 * completely fresh and clean start. */
763 err_code
= zero_the_pointer(gspca_dev
);
767 err_code
= stream_start(gspca_dev
);
771 if (sd
->cam_type
== CAM_TYPE_CIF
) {
772 err_code
= start_cif_cam(gspca_dev
);
774 err_code
= start_vga_cam(gspca_dev
);
779 setbrightness(gspca_dev
);
780 setexposure(gspca_dev
);
783 return isoc_enable(gspca_dev
);
786 static void sd_stopN(struct gspca_dev
*gspca_dev
)
788 struct sd
*sd
= (struct sd
*) gspca_dev
;
790 stream_stop(gspca_dev
);
791 /* Not all the cams need this, but even if not, probably a good idea */
792 zero_the_pointer(gspca_dev
);
797 static void setbrightness(struct gspca_dev
*gspca_dev
)
799 struct sd
*sd
= (struct sd
*) gspca_dev
;
801 u8 sign_reg
= 7; /* This reg and the next one used on CIF cams. */
802 u8 value_reg
= 8; /* VGA cams seem to use regs 0x0b and 0x0c */
803 const u8 quick_clix_table
[] =
804 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
805 { 0, 4, 8, 12, 1, 2, 3, 5, 6, 9, 7, 10, 13, 11, 14, 15};
807 * This control is disabled for CIF type 1 and VGA type 0 cameras.
808 * It does not quite act linearly for the Argus QuickClix camera,
809 * but it does control brightness. The values are 0 - 15 only, and
810 * the table above makes them act consecutively.
812 if ((gspca_dev
->ctrl_dis
& (1 << NORM_BRIGHTNESS_IDX
)) &&
813 (gspca_dev
->ctrl_dis
& (1 << ARGUS_QC_BRIGHTNESS_IDX
)))
816 if (sd
->cam_type
== CAM_TYPE_VGA
) {
821 /* Note register 7 is also seen as 0x8x or 0xCx in dumps */
822 if (sd
->brightness
> 0) {
823 sensor_write1(gspca_dev
, sign_reg
, 0x00);
824 val
= sd
->brightness
;
826 sensor_write1(gspca_dev
, sign_reg
, 0x01);
827 val
= (257 - sd
->brightness
);
829 /* Use lookup table for funky Argus QuickClix brightness */
831 val
= quick_clix_table
[val
];
833 sensor_write1(gspca_dev
, value_reg
, val
);
836 static void setexposure(struct gspca_dev
*gspca_dev
)
838 struct sd
*sd
= (struct sd
*) gspca_dev
;
841 if (gspca_dev
->ctrl_dis
& (1 << EXPOSURE_IDX
))
844 if (sd
->cam_type
== CAM_TYPE_CIF
&& sd
->sensor_type
== 1) {
845 /* This cam does not like exposure settings > 300,
846 so scale 0 - 4095 to 300 - 4095 */
847 exposure
= (sd
->exposure
* 9267) / 10000 + 300;
848 sensor_write1(gspca_dev
, 3, exposure
>> 4);
849 sensor_write1(gspca_dev
, 4, exposure
& 0x0f);
851 /* We have both a clock divider and an exposure register.
852 We first calculate the clock divider, as that determines
853 the maximum exposure and then we calculayte the exposure
854 register setting (which goes from 0 - 511).
856 Note our 0 - 4095 exposure is mapped to 0 - 511
857 milliseconds exposure time */
858 u8 clockdiv
= (60 * sd
->exposure
+ 7999) / 8000;
860 /* Limit framerate to not exceed usb bandwidth */
861 if (clockdiv
< 3 && gspca_dev
->width
>= 320)
863 else if (clockdiv
< 2)
866 if (sd
->cam_type
== CAM_TYPE_VGA
&& clockdiv
< 4)
869 /* Frame exposure time in ms = 1000 * clockdiv / 60 ->
870 exposure = (sd->exposure / 8) * 511 / (1000 * clockdiv / 60) */
871 exposure
= (60 * 511 * sd
->exposure
) / (8000 * clockdiv
);
875 /* exposure register value is reversed! */
876 exposure
= 511 - exposure
;
878 sensor_write1(gspca_dev
, 0x02, clockdiv
);
879 sensor_write1(gspca_dev
, 0x0e, exposure
& 0xff);
880 sensor_write1(gspca_dev
, 0x0f, exposure
>> 8);
884 static void setgain(struct gspca_dev
*gspca_dev
)
886 struct sd
*sd
= (struct sd
*) gspca_dev
;
888 if (gspca_dev
->ctrl_dis
& (1 << GAIN_IDX
))
891 if (sd
->cam_type
== CAM_TYPE_CIF
&& sd
->sensor_type
== 1) {
892 sensor_write1(gspca_dev
, 0x0e, sd
->gain
);
894 sensor_write1(gspca_dev
, 0x10, sd
->gain
);
898 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
)
900 struct sd
*sd
= (struct sd
*) gspca_dev
;
902 sd
->brightness
= val
;
903 if (gspca_dev
->streaming
)
904 setbrightness(gspca_dev
);
908 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
)
910 struct sd
*sd
= (struct sd
*) gspca_dev
;
912 *val
= sd
->brightness
;
916 static int sd_setexposure(struct gspca_dev
*gspca_dev
, __s32 val
)
918 struct sd
*sd
= (struct sd
*) gspca_dev
;
921 if (gspca_dev
->streaming
)
922 setexposure(gspca_dev
);
926 static int sd_getexposure(struct gspca_dev
*gspca_dev
, __s32
*val
)
928 struct sd
*sd
= (struct sd
*) gspca_dev
;
934 static int sd_setgain(struct gspca_dev
*gspca_dev
, __s32 val
)
936 struct sd
*sd
= (struct sd
*) gspca_dev
;
939 if (gspca_dev
->streaming
)
944 static int sd_getgain(struct gspca_dev
*gspca_dev
, __s32
*val
)
946 struct sd
*sd
= (struct sd
*) gspca_dev
;
952 /* Include pac common sof detection functions */
953 #include "pac_common.h"
955 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
956 struct gspca_frame
*frame
, /* target */
957 __u8
*data
, /* isoc packet */
958 int len
) /* iso packet length */
962 sof
= pac_find_sof(gspca_dev
, data
, len
);
966 /* finish decoding current frame */
968 if (n
> sizeof pac_sof_marker
)
969 n
-= sizeof pac_sof_marker
;
972 frame
= gspca_frame_add(gspca_dev
, LAST_PACKET
, frame
,
974 /* Start next frame. */
975 gspca_frame_add(gspca_dev
, FIRST_PACKET
, frame
,
976 pac_sof_marker
, sizeof pac_sof_marker
);
980 gspca_frame_add(gspca_dev
, INTER_PACKET
, frame
, data
, len
);
983 /* sub-driver description */
984 static const struct sd_desc sd_desc
= {
987 .nctrls
= ARRAY_SIZE(sd_ctrls
),
992 .pkt_scan
= sd_pkt_scan
,
995 /* -- module initialisation -- */
996 static const __devinitdata
struct usb_device_id device_table
[] = {
997 {USB_DEVICE(0x08ca, 0x0111)}, /* Aiptek Pencam VGA+ */
998 {USB_DEVICE(0x093a, 0x010f)}, /* All other known MR97310A VGA cams */
999 {USB_DEVICE(0x093a, 0x010e)}, /* All known MR97310A CIF cams */
1002 MODULE_DEVICE_TABLE(usb
, device_table
);
1004 /* -- device connect -- */
1005 static int sd_probe(struct usb_interface
*intf
,
1006 const struct usb_device_id
*id
)
1008 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
1012 static struct usb_driver sd_driver
= {
1013 .name
= MODULE_NAME
,
1014 .id_table
= device_table
,
1016 .disconnect
= gspca_disconnect
,
1018 .suspend
= gspca_suspend
,
1019 .resume
= gspca_resume
,
1023 /* -- module insert / remove -- */
1024 static int __init
sd_mod_init(void)
1028 ret
= usb_register(&sd_driver
);
1031 PDEBUG(D_PROBE
, "registered");
1034 static void __exit
sd_mod_exit(void)
1036 usb_deregister(&sd_driver
);
1037 PDEBUG(D_PROBE
, "deregistered");
1040 module_init(sd_mod_init
);
1041 module_exit(sd_mod_exit
);