2 * Mars MR97310A library
4 * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com>
6 * Support for the MR97310A cameras in addition to the Aiptek Pencam VGA+
7 * and for the routines for detecting and classifying these various cameras,
9 * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu>
13 * The MR97311A support in gspca/mars.c has been helpful in understanding some
14 * of the registers in these cameras.
16 * Hans de Goede <hdgoede@redhat.com> and
17 * Thomas Kaiser <thomas@kaiser-linux.li>
18 * have assisted with their experience. Each of them has also helped by
19 * testing a previously unsupported camera.
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #define MODULE_NAME "mr97310a"
40 #define CAM_TYPE_CIF 0
41 #define CAM_TYPE_VGA 1
43 #define MR97310A_BRIGHTNESS_MIN -254
44 #define MR97310A_BRIGHTNESS_MAX 255
45 #define MR97310A_BRIGHTNESS_DEFAULT 0
47 #define MR97310A_EXPOSURE_MIN 300
48 #define MR97310A_EXPOSURE_MAX 4095
49 #define MR97310A_EXPOSURE_DEFAULT 1000
51 #define MR97310A_GAIN_MIN 0
52 #define MR97310A_GAIN_MAX 31
53 #define MR97310A_GAIN_DEFAULT 25
55 MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>,"
56 "Theodore Kilgore <kilgota@auburn.edu>");
57 MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver");
58 MODULE_LICENSE("GPL");
60 /* global parameters */
61 int force_sensor_type
= -1;
62 module_param(force_sensor_type
, int, 0644);
63 MODULE_PARM_DESC(force_sensor_type
, "Force sensor type (-1 (auto), 0 or 1)");
65 /* specific webcam descriptor */
67 struct gspca_dev gspca_dev
; /* !! must be the first item */
69 u8 cam_type
; /* 0 is CIF and 1 is VGA */
70 u8 sensor_type
; /* We use 0 and 1 here, too. */
78 struct sensor_w_data
{
85 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
);
86 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
);
87 static int sd_setexposure(struct gspca_dev
*gspca_dev
, __s32 val
);
88 static int sd_getexposure(struct gspca_dev
*gspca_dev
, __s32
*val
);
89 static int sd_setgain(struct gspca_dev
*gspca_dev
, __s32 val
);
90 static int sd_getgain(struct gspca_dev
*gspca_dev
, __s32
*val
);
91 static void setbrightness(struct gspca_dev
*gspca_dev
);
92 static void setexposure(struct gspca_dev
*gspca_dev
);
93 static void setgain(struct gspca_dev
*gspca_dev
);
95 /* V4L2 controls supported by the driver */
96 static struct ctrl sd_ctrls
[] = {
98 #define BRIGHTNESS_IDX 0
100 .id
= V4L2_CID_BRIGHTNESS
,
101 .type
= V4L2_CTRL_TYPE_INTEGER
,
102 .name
= "Brightness",
103 .minimum
= MR97310A_BRIGHTNESS_MIN
,
104 .maximum
= MR97310A_BRIGHTNESS_MAX
,
106 .default_value
= MR97310A_BRIGHTNESS_DEFAULT
,
109 .set
= sd_setbrightness
,
110 .get
= sd_getbrightness
,
113 #define EXPOSURE_IDX 1
115 .id
= V4L2_CID_EXPOSURE
,
116 .type
= V4L2_CTRL_TYPE_INTEGER
,
118 .minimum
= MR97310A_EXPOSURE_MIN
,
119 .maximum
= MR97310A_EXPOSURE_MAX
,
121 .default_value
= MR97310A_EXPOSURE_DEFAULT
,
124 .set
= sd_setexposure
,
125 .get
= sd_getexposure
,
131 .type
= V4L2_CTRL_TYPE_INTEGER
,
133 .minimum
= MR97310A_GAIN_MIN
,
134 .maximum
= MR97310A_GAIN_MAX
,
136 .default_value
= MR97310A_GAIN_DEFAULT
,
144 static const struct v4l2_pix_format vga_mode
[] = {
145 {160, 120, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
147 .sizeimage
= 160 * 120,
148 .colorspace
= V4L2_COLORSPACE_SRGB
,
150 {176, 144, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
152 .sizeimage
= 176 * 144,
153 .colorspace
= V4L2_COLORSPACE_SRGB
,
155 {320, 240, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
157 .sizeimage
= 320 * 240,
158 .colorspace
= V4L2_COLORSPACE_SRGB
,
160 {352, 288, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
162 .sizeimage
= 352 * 288,
163 .colorspace
= V4L2_COLORSPACE_SRGB
,
165 {640, 480, V4L2_PIX_FMT_MR97310A
, V4L2_FIELD_NONE
,
167 .sizeimage
= 640 * 480,
168 .colorspace
= V4L2_COLORSPACE_SRGB
,
172 /* the bytes to write are in gspca_dev->usb_buf */
173 static int mr_write(struct gspca_dev
*gspca_dev
, int len
)
177 rc
= usb_bulk_msg(gspca_dev
->dev
,
178 usb_sndbulkpipe(gspca_dev
->dev
, 4),
179 gspca_dev
->usb_buf
, len
, NULL
, 500);
181 PDEBUG(D_ERR
, "reg write [%02x] error %d",
182 gspca_dev
->usb_buf
[0], rc
);
186 /* the bytes are read into gspca_dev->usb_buf */
187 static int mr_read(struct gspca_dev
*gspca_dev
, int len
)
191 rc
= usb_bulk_msg(gspca_dev
->dev
,
192 usb_rcvbulkpipe(gspca_dev
->dev
, 3),
193 gspca_dev
->usb_buf
, len
, NULL
, 500);
195 PDEBUG(D_ERR
, "reg read [%02x] error %d",
196 gspca_dev
->usb_buf
[0], rc
);
200 static int sensor_write_reg(struct gspca_dev
*gspca_dev
, u8 reg
, u8 flags
,
201 const u8
*data
, int len
)
203 gspca_dev
->usb_buf
[0] = 0x1f;
204 gspca_dev
->usb_buf
[1] = flags
;
205 gspca_dev
->usb_buf
[2] = reg
;
206 memcpy(gspca_dev
->usb_buf
+ 3, data
, len
);
208 return mr_write(gspca_dev
, len
+ 3);
211 static int sensor_write_regs(struct gspca_dev
*gspca_dev
,
212 const struct sensor_w_data
*data
, int len
)
216 for (i
= 0; i
< len
; i
++) {
217 rc
= sensor_write_reg(gspca_dev
, data
[i
].reg
, data
[i
].flags
,
218 data
[i
].data
, data
[i
].len
);
226 static int sensor_write1(struct gspca_dev
*gspca_dev
, u8 reg
, u8 data
)
228 struct sd
*sd
= (struct sd
*) gspca_dev
;
233 rc
= sensor_write_reg(gspca_dev
, reg
, 0x01, &buf
, 1);
238 confirm_reg
= sd
->sensor_type
? 0x13 : 0x11;
239 rc
= sensor_write_reg(gspca_dev
, confirm_reg
, 0x00, &buf
, 1);
246 static int cam_get_response16(struct gspca_dev
*gspca_dev
)
248 __u8
*data
= gspca_dev
->usb_buf
;
252 err_code
= mr_write(gspca_dev
, 1);
256 err_code
= mr_read(gspca_dev
, 16);
260 static int zero_the_pointer(struct gspca_dev
*gspca_dev
)
262 __u8
*data
= gspca_dev
->usb_buf
;
267 err_code
= cam_get_response16(gspca_dev
);
271 err_code
= mr_write(gspca_dev
, 1);
274 err_code
= mr_write(gspca_dev
, 2);
278 err_code
= cam_get_response16(gspca_dev
);
284 err_code
= mr_write(gspca_dev
, 2);
288 err_code
= cam_get_response16(gspca_dev
);
294 err_code
= mr_write(gspca_dev
, 2);
298 err_code
= cam_get_response16(gspca_dev
);
304 err_code
= mr_write(gspca_dev
, 2);
308 while (status
!= 0x0a && tries
< 256) {
309 err_code
= cam_get_response16(gspca_dev
);
316 PDEBUG(D_ERR
, "status is %02x", status
);
322 err_code
= mr_write(gspca_dev
, 2);
326 err_code
= cam_get_response16(gspca_dev
);
334 err_code
= mr_write(gspca_dev
, 1);
338 err_code
= mr_read(gspca_dev
, 16);
345 static u8
get_sensor_id(struct gspca_dev
*gspca_dev
)
349 gspca_dev
->usb_buf
[0] = 0x1e;
350 err_code
= mr_write(gspca_dev
, 1);
354 err_code
= mr_read(gspca_dev
, 16);
358 PDEBUG(D_PROBE
, "Byte zero reported is %01x", gspca_dev
->usb_buf
[0]);
360 return gspca_dev
->usb_buf
[0];
363 /* this function is called at probe time */
364 static int sd_config(struct gspca_dev
*gspca_dev
,
365 const struct usb_device_id
*id
)
367 struct sd
*sd
= (struct sd
*) gspca_dev
;
369 __u8
*data
= gspca_dev
->usb_buf
;
372 cam
= &gspca_dev
->cam
;
373 cam
->cam_mode
= vga_mode
;
374 cam
->nmodes
= ARRAY_SIZE(vga_mode
);
376 if (id
->idProduct
== 0x010e) {
377 sd
->cam_type
= CAM_TYPE_CIF
;
382 err_code
= mr_write(gspca_dev
, 2);
387 data
[0] = get_sensor_id(gspca_dev
);
389 * Known CIF cameras. If you have another to report, please do
391 * Name byte just read sd->sensor_type
393 * Sakar Spy-shot 0x28 T. Kilgore 0
394 * Innovage 0xf5 (unstable) T. Kilgore 0
395 * Vivitar Mini 0x53 H. De Goede 0
396 * Vivitar Mini 0x04 / 0x24 E. Rodriguez 0
397 * Vivitar Mini 0x08 T. Kilgore 1
398 * Elta-Media 8212dc 0x23 T. Kaiser 1
399 * Philips dig. keych. 0x37 T. Kilgore 1
401 if ((data
[0] & 0x78) == 8 ||
402 ((data
[0] & 0x2) == 0x2 && data
[0] != 0x53))
407 PDEBUG(D_PROBE
, "MR97310A CIF camera detected, sensor: %d",
410 if (force_sensor_type
!= -1) {
411 sd
->sensor_type
= !! force_sensor_type
;
412 PDEBUG(D_PROBE
, "Forcing sensor type to: %d",
416 if (sd
->sensor_type
== 0)
417 gspca_dev
->ctrl_dis
= (1 << BRIGHTNESS_IDX
);
419 sd
->cam_type
= CAM_TYPE_VGA
;
420 PDEBUG(D_PROBE
, "MR97310A VGA camera detected");
421 gspca_dev
->ctrl_dis
= (1 << BRIGHTNESS_IDX
) |
422 (1 << EXPOSURE_IDX
) | (1 << GAIN_IDX
);
425 sd
->brightness
= MR97310A_BRIGHTNESS_DEFAULT
;
426 sd
->exposure
= MR97310A_EXPOSURE_DEFAULT
;
427 sd
->gain
= MR97310A_GAIN_DEFAULT
;
432 /* this function is called at probe and resume time */
433 static int sd_init(struct gspca_dev
*gspca_dev
)
438 static int start_cif_cam(struct gspca_dev
*gspca_dev
)
440 struct sd
*sd
= (struct sd
*) gspca_dev
;
441 __u8
*data
= gspca_dev
->usb_buf
;
443 const __u8 startup_string
[] = {
447 0x00, /* Hsize/8 for 352 or 320 */
448 0x00, /* Vsize/4 for 288 or 240 */
449 0x13, /* or 0xbb, depends on sensor */
450 0x00, /* Hstart, depends on res. */
451 0x00, /* reserved ? */
452 0x00, /* Vstart, depends on res. and sensor */
453 0x50, /* 0x54 to get 176 or 160 */
457 /* Note: Some of the above descriptions guessed from MR97113A driver */
460 err_code
= mr_write(gspca_dev
, 2);
464 memcpy(data
, startup_string
, 11);
468 switch (gspca_dev
->width
) {
470 data
[9] |= 0x04; /* reg 8, 2:1 scale down from 320 */
474 data
[3] = 0x28; /* reg 2, H size/8 */
475 data
[4] = 0x3c; /* reg 3, V size/4 */
476 data
[6] = 0x14; /* reg 5, H start */
477 data
[8] = 0x1a + sd
->sensor_type
; /* reg 7, V start */
480 data
[9] |= 0x04; /* reg 8, 2:1 scale down from 352 */
483 data
[3] = 0x2c; /* reg 2, H size/8 */
484 data
[4] = 0x48; /* reg 3, V size/4 */
485 data
[6] = 0x06; /* reg 5, H start */
486 data
[8] = 0x06 - sd
->sensor_type
; /* reg 7, V start */
489 err_code
= mr_write(gspca_dev
, 11);
493 if (!sd
->sensor_type
) {
494 const struct sensor_w_data cif_sensor0_init_data
[] = {
495 {0x02, 0x00, {0x03, 0x5a, 0xb5, 0x01,
496 0x0f, 0x14, 0x0f, 0x10}, 8},
497 {0x0c, 0x00, {0x04, 0x01, 0x01, 0x00, 0x1f}, 5},
498 {0x12, 0x00, {0x07}, 1},
499 {0x1f, 0x00, {0x06}, 1},
500 {0x27, 0x00, {0x04}, 1},
501 {0x29, 0x00, {0x0c}, 1},
502 {0x40, 0x00, {0x40, 0x00, 0x04}, 3},
503 {0x50, 0x00, {0x60}, 1},
504 {0x60, 0x00, {0x06}, 1},
505 {0x6b, 0x00, {0x85, 0x85, 0xc8, 0xc8, 0xc8, 0xc8}, 6},
506 {0x72, 0x00, {0x1e, 0x56}, 2},
507 {0x75, 0x00, {0x58, 0x40, 0xa2, 0x02, 0x31, 0x02,
508 0x31, 0x80, 0x00}, 9},
509 {0x11, 0x00, {0x01}, 1},
512 err_code
= sensor_write_regs(gspca_dev
, cif_sensor0_init_data
,
513 ARRAY_SIZE(cif_sensor0_init_data
));
514 } else { /* sd->sensor_type = 1 */
515 const struct sensor_w_data cif_sensor1_init_data
[] = {
516 /* Reg 3,4, 7,8 get set by the controls */
517 {0x02, 0x00, {0x10}, 1},
518 {0x05, 0x01, {0x22}, 1}, /* 5/6 also seen as 65h/32h */
519 {0x06, 0x01, {0x00}, 1},
520 {0x09, 0x02, {0x0e}, 1},
521 {0x0a, 0x02, {0x05}, 1},
522 {0x0b, 0x02, {0x05}, 1},
523 {0x0c, 0x02, {0x0f}, 1},
524 {0x0d, 0x02, {0x07}, 1},
525 {0x0e, 0x02, {0x0c}, 1},
526 {0x0f, 0x00, {0x00}, 1},
527 {0x10, 0x00, {0x06}, 1},
528 {0x11, 0x00, {0x07}, 1},
529 {0x12, 0x00, {0x00}, 1},
530 {0x13, 0x00, {0x01}, 1},
533 /* Without this command the cam won't work with USB-UHCI */
534 gspca_dev
->usb_buf
[0] = 0x0a;
535 gspca_dev
->usb_buf
[1] = 0x00;
536 err_code
= mr_write(gspca_dev
, 2);
539 err_code
= sensor_write_regs(gspca_dev
, cif_sensor1_init_data
,
540 ARRAY_SIZE(cif_sensor1_init_data
));
545 setbrightness(gspca_dev
);
546 setexposure(gspca_dev
);
552 data
[1] = 0x4d; /* ISOC transfering enable... */
553 err_code
= mr_write(gspca_dev
, 2);
560 static int start_vga_cam(struct gspca_dev
*gspca_dev
)
562 struct sd
*sd
= (struct sd
*) gspca_dev
;
563 __u8
*data
= gspca_dev
->usb_buf
;
565 const __u8 startup_string
[] = {0x00, 0x0d, 0x01, 0x00, 0x00, 0x2b,
566 0x00, 0x00, 0x00, 0x50, 0xc0};
568 /* What some of these mean is explained in start_cif_cam(), above */
572 * We have to know which camera we have, because the register writes
573 * depend upon the camera. This test, run before we actually enter
574 * the initialization routine, distinguishes most of the cameras, If
575 * needed, another routine is done later, too.
579 err_code
= mr_write(gspca_dev
, 1);
583 err_code
= mr_read(gspca_dev
, 16);
587 PDEBUG(D_PROBE
, "Byte reported is %02x", data
[0]);
591 * Known VGA cameras. If you have another to report, please do
593 * Name byte just read sd->sensor_type
595 * Aiptek Pencam VGA+ 0x31 0 1
596 * ION digital 0x31 0 1
597 * Argus DC-1620 0x30 1 0
598 * Argus QuickClix 0x30 1 1 (not caught here)
600 sd
->sensor_type
= data
[0] & 1;
601 sd
->do_lcd_stop
= (~data
[0]) & 1;
605 /* Streaming setup begins here. */
610 err_code
= mr_write(gspca_dev
, 2);
615 * A second test can now resolve any remaining ambiguity in the
616 * identification of the camera type,
618 if (!sd
->sensor_type
) {
619 data
[0] = get_sensor_id(gspca_dev
);
620 if (data
[0] == 0x7f) {
622 PDEBUG(D_PROBE
, "sensor_type corrected to 1");
627 if (force_sensor_type
!= -1) {
628 sd
->sensor_type
= !! force_sensor_type
;
629 PDEBUG(D_PROBE
, "Forcing sensor type to: %d",
635 * This test is only run if the previous test returned 0x30, but
636 * here is the information for all others, too, just for reference.
638 * Name byte just read sd->sensor_type
640 * Aiptek Pencam VGA+ 0xfb (this test not run) 1
641 * ION digital 0xbd (this test not run) 1
642 * Argus DC-1620 0xe5 (no change) 0
643 * Argus QuickClix 0x7f (reclassified) 1
645 memcpy(data
, startup_string
, 11);
646 if (!sd
->sensor_type
) {
651 switch (gspca_dev
->width
) {
653 data
[9] |= 0x0c; /* reg 8, 4:1 scale down */
656 data
[9] |= 0x04; /* reg 8, 2:1 scale down */
660 data
[3] = 0x50; /* reg 2, H size/8 */
661 data
[4] = 0x78; /* reg 3, V size/4 */
662 data
[6] = 0x04; /* reg 5, H start */
663 data
[8] = 0x03; /* reg 7, V start */
665 data
[8] = 0x04; /* Bayer tile shifted */
669 data
[9] |= 0x04; /* reg 8, 2:1 scale down */
672 data
[3] = 0x2c; /* reg 2, H size */
673 data
[4] = 0x48; /* reg 3, V size */
674 data
[6] = 0x94; /* reg 5, H start */
675 data
[8] = 0x63; /* reg 7, V start */
677 data
[8] = 0x64; /* Bayer tile shifted */
681 err_code
= mr_write(gspca_dev
, 11);
685 if (!sd
->sensor_type
) {
686 /* The only known sensor_type 0 cam is the Argus DC-1620 */
687 const struct sensor_w_data vga_sensor0_init_data
[] = {
688 {0x01, 0x00, {0x0c, 0x00, 0x04}, 3},
689 {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4},
690 {0x20, 0x00, {0x00, 0x80, 0x00, 0x08}, 4},
691 {0x25, 0x00, {0x03, 0xa9, 0x80}, 3},
692 {0x30, 0x00, {0x30, 0x18, 0x10, 0x18}, 4},
695 err_code
= sensor_write_regs(gspca_dev
, vga_sensor0_init_data
,
696 ARRAY_SIZE(vga_sensor0_init_data
));
697 } else { /* sd->sensor_type = 1 */
698 const struct sensor_w_data vga_sensor1_init_data
[] = {
699 {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00,
700 0x07, 0x00, 0x01}, 8},
701 {0x11, 0x04, {0x01}, 1},
702 /*{0x0a, 0x00, {0x00, 0x01, 0x00, 0x00, 0x01, */
703 {0x0a, 0x00, {0x01, 0x06, 0x00, 0x00, 0x01,
705 {0x11, 0x04, {0x01}, 1},
706 {0x12, 0x00, {0x00, 0x63, 0x00, 0x70, 0x00, 0x00}, 6},
707 {0x11, 0x04, {0x01}, 1},
710 err_code
= sensor_write_regs(gspca_dev
, vga_sensor1_init_data
,
711 ARRAY_SIZE(vga_sensor1_init_data
));
718 data
[1] = 0x4d; /* ISOC transfering enable... */
719 err_code
= mr_write(gspca_dev
, 2);
724 static int sd_start(struct gspca_dev
*gspca_dev
)
726 struct sd
*sd
= (struct sd
*) gspca_dev
;
730 cam
= &gspca_dev
->cam
;
733 * Some of the supported cameras require the memory pointer to be
734 * set to 0, or else they will not stream.
736 zero_the_pointer(gspca_dev
);
738 if (sd
->cam_type
== CAM_TYPE_CIF
) {
739 err_code
= start_cif_cam(gspca_dev
);
741 err_code
= start_vga_cam(gspca_dev
);
746 static void sd_stopN(struct gspca_dev
*gspca_dev
)
748 struct sd
*sd
= (struct sd
*) gspca_dev
;
751 gspca_dev
->usb_buf
[0] = 1;
752 gspca_dev
->usb_buf
[1] = 0;
753 result
= mr_write(gspca_dev
, 2);
755 PDEBUG(D_ERR
, "Camera Stop failed");
757 /* Not all the cams need this, but even if not, probably a good idea */
758 zero_the_pointer(gspca_dev
);
759 if (sd
->do_lcd_stop
) {
760 gspca_dev
->usb_buf
[0] = 0x19;
761 gspca_dev
->usb_buf
[1] = 0x54;
762 result
= mr_write(gspca_dev
, 2);
764 PDEBUG(D_ERR
, "Camera Stop failed");
768 static void setbrightness(struct gspca_dev
*gspca_dev
)
770 struct sd
*sd
= (struct sd
*) gspca_dev
;
773 if (gspca_dev
->ctrl_dis
& (1 << BRIGHTNESS_IDX
))
776 /* Note register 7 is also seen as 0x8x or 0xCx in dumps */
777 if (sd
->brightness
> 0) {
778 sensor_write1(gspca_dev
, 7, 0x00);
779 val
= sd
->brightness
;
781 sensor_write1(gspca_dev
, 7, 0x01);
782 val
= 257 - sd
->brightness
;
784 sensor_write1(gspca_dev
, 8, val
);
787 static void setexposure(struct gspca_dev
*gspca_dev
)
789 struct sd
*sd
= (struct sd
*) gspca_dev
;
792 if (gspca_dev
->ctrl_dis
& (1 << EXPOSURE_IDX
))
795 if (sd
->sensor_type
) {
796 val
= sd
->exposure
>> 4;
797 sensor_write1(gspca_dev
, 3, val
);
798 val
= sd
->exposure
& 0xf;
799 sensor_write1(gspca_dev
, 4, val
);
804 /* We have both a clock divider and an exposure register.
805 We first calculate the clock divider, as that determines
806 the maximum exposure and then we calculayte the exposure
807 register setting (which goes from 0 - 511).
809 Note our 0 - 4095 exposure is mapped to 0 - 511
810 milliseconds exposure time */
811 clockdiv
= (60 * sd
->exposure
+ 7999) / 8000;
813 /* Limit framerate to not exceed usb bandwidth */
814 if (clockdiv
< 3 && gspca_dev
->width
>= 320)
816 else if (clockdiv
< 2)
819 /* Frame exposure time in ms = 1000 * clockdiv / 60 ->
820 exposure = (sd->exposure / 8) * 511 / (1000 * clockdiv / 60) */
821 exposure
= (60 * 511 * sd
->exposure
) / (8000 * clockdiv
);
825 /* exposure register value is reversed! */
826 exposure
= 511 - exposure
;
828 sensor_write1(gspca_dev
, 0x02, clockdiv
);
829 sensor_write1(gspca_dev
, 0x0e, exposure
& 0xff);
830 sensor_write1(gspca_dev
, 0x0f, exposure
>> 8);
834 static void setgain(struct gspca_dev
*gspca_dev
)
836 struct sd
*sd
= (struct sd
*) gspca_dev
;
838 if (gspca_dev
->ctrl_dis
& (1 << GAIN_IDX
))
841 if (sd
->sensor_type
) {
842 sensor_write1(gspca_dev
, 0x0e, sd
->gain
);
844 sensor_write1(gspca_dev
, 0x10, sd
->gain
);
848 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
)
850 struct sd
*sd
= (struct sd
*) gspca_dev
;
852 sd
->brightness
= val
;
853 if (gspca_dev
->streaming
)
854 setbrightness(gspca_dev
);
858 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
)
860 struct sd
*sd
= (struct sd
*) gspca_dev
;
862 *val
= sd
->brightness
;
866 static int sd_setexposure(struct gspca_dev
*gspca_dev
, __s32 val
)
868 struct sd
*sd
= (struct sd
*) gspca_dev
;
871 if (gspca_dev
->streaming
)
872 setexposure(gspca_dev
);
876 static int sd_getexposure(struct gspca_dev
*gspca_dev
, __s32
*val
)
878 struct sd
*sd
= (struct sd
*) gspca_dev
;
884 static int sd_setgain(struct gspca_dev
*gspca_dev
, __s32 val
)
886 struct sd
*sd
= (struct sd
*) gspca_dev
;
889 if (gspca_dev
->streaming
)
894 static int sd_getgain(struct gspca_dev
*gspca_dev
, __s32
*val
)
896 struct sd
*sd
= (struct sd
*) gspca_dev
;
902 /* Include pac common sof detection functions */
903 #include "pac_common.h"
905 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
906 struct gspca_frame
*frame
, /* target */
907 __u8
*data
, /* isoc packet */
908 int len
) /* iso packet length */
912 sof
= pac_find_sof(gspca_dev
, data
, len
);
916 /* finish decoding current frame */
918 if (n
> sizeof pac_sof_marker
)
919 n
-= sizeof pac_sof_marker
;
922 frame
= gspca_frame_add(gspca_dev
, LAST_PACKET
, frame
,
924 /* Start next frame. */
925 gspca_frame_add(gspca_dev
, FIRST_PACKET
, frame
,
926 pac_sof_marker
, sizeof pac_sof_marker
);
930 gspca_frame_add(gspca_dev
, INTER_PACKET
, frame
, data
, len
);
933 /* sub-driver description */
934 static const struct sd_desc sd_desc
= {
937 .nctrls
= ARRAY_SIZE(sd_ctrls
),
942 .pkt_scan
= sd_pkt_scan
,
945 /* -- module initialisation -- */
946 static const __devinitdata
struct usb_device_id device_table
[] = {
947 {USB_DEVICE(0x08ca, 0x0111)}, /* Aiptek Pencam VGA+ */
948 {USB_DEVICE(0x093a, 0x010f)}, /* All other known MR97310A VGA cams */
949 {USB_DEVICE(0x093a, 0x010e)}, /* All known MR97310A CIF cams */
952 MODULE_DEVICE_TABLE(usb
, device_table
);
954 /* -- device connect -- */
955 static int sd_probe(struct usb_interface
*intf
,
956 const struct usb_device_id
*id
)
958 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
962 static struct usb_driver sd_driver
= {
964 .id_table
= device_table
,
966 .disconnect
= gspca_disconnect
,
968 .suspend
= gspca_suspend
,
969 .resume
= gspca_resume
,
973 /* -- module insert / remove -- */
974 static int __init
sd_mod_init(void)
978 ret
= usb_register(&sd_driver
);
981 PDEBUG(D_PROBE
, "registered");
984 static void __exit
sd_mod_exit(void)
986 usb_deregister(&sd_driver
);
987 PDEBUG(D_PROBE
, "deregistered");
990 module_init(sd_mod_init
);
991 module_exit(sd_mod_exit
);