1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#define MODULE_NAME "mr97310a"
37
38#include "gspca.h"
39
40#define CAM_TYPE_CIF 0
41#define CAM_TYPE_VGA 1
42
43#define MR97310A_BRIGHTNESS_MIN -254
44#define MR97310A_BRIGHTNESS_MAX 255
45#define MR97310A_BRIGHTNESS_DEFAULT 0
46
47#define MR97310A_EXPOSURE_MIN 300
48#define MR97310A_EXPOSURE_MAX 4095
49#define MR97310A_EXPOSURE_DEFAULT 1000
50
51#define MR97310A_GAIN_MIN 0
52#define MR97310A_GAIN_MAX 31
53#define MR97310A_GAIN_DEFAULT 25
54
55MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>,"
56 "Theodore Kilgore <kilgota@auburn.edu>");
57MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver");
58MODULE_LICENSE("GPL");
59
60
61int force_sensor_type = -1;
62module_param(force_sensor_type, int, 0644);
63MODULE_PARM_DESC(force_sensor_type, "Force sensor type (-1 (auto), 0 or 1)");
64
65
66struct sd {
67 struct gspca_dev gspca_dev;
68 u8 sof_read;
69 u8 cam_type;
70 u8 sensor_type;
71 u8 do_lcd_stop;
72
73 int brightness;
74 u16 exposure;
75 u8 gain;
76};
77
78struct sensor_w_data {
79 u8 reg;
80 u8 flags;
81 u8 data[16];
82 int len;
83};
84
85static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
86static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
87static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
88static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
89static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
90static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
91static void setbrightness(struct gspca_dev *gspca_dev);
92static void setexposure(struct gspca_dev *gspca_dev);
93static void setgain(struct gspca_dev *gspca_dev);
94
95
96static struct ctrl sd_ctrls[] = {
97 {
98#define BRIGHTNESS_IDX 0
99 {
100 .id = V4L2_CID_BRIGHTNESS,
101 .type = V4L2_CTRL_TYPE_INTEGER,
102 .name = "Brightness",
103 .minimum = MR97310A_BRIGHTNESS_MIN,
104 .maximum = MR97310A_BRIGHTNESS_MAX,
105 .step = 1,
106 .default_value = MR97310A_BRIGHTNESS_DEFAULT,
107 .flags = 0,
108 },
109 .set = sd_setbrightness,
110 .get = sd_getbrightness,
111 },
112 {
113#define EXPOSURE_IDX 1
114 {
115 .id = V4L2_CID_EXPOSURE,
116 .type = V4L2_CTRL_TYPE_INTEGER,
117 .name = "Exposure",
118 .minimum = MR97310A_EXPOSURE_MIN,
119 .maximum = MR97310A_EXPOSURE_MAX,
120 .step = 1,
121 .default_value = MR97310A_EXPOSURE_DEFAULT,
122 .flags = 0,
123 },
124 .set = sd_setexposure,
125 .get = sd_getexposure,
126 },
127 {
128#define GAIN_IDX 2
129 {
130 .id = V4L2_CID_GAIN,
131 .type = V4L2_CTRL_TYPE_INTEGER,
132 .name = "Gain",
133 .minimum = MR97310A_GAIN_MIN,
134 .maximum = MR97310A_GAIN_MAX,
135 .step = 1,
136 .default_value = MR97310A_GAIN_DEFAULT,
137 .flags = 0,
138 },
139 .set = sd_setgain,
140 .get = sd_getgain,
141 },
142};
143
144static const struct v4l2_pix_format vga_mode[] = {
145 {160, 120, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
146 .bytesperline = 160,
147 .sizeimage = 160 * 120,
148 .colorspace = V4L2_COLORSPACE_SRGB,
149 .priv = 4},
150 {176, 144, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
151 .bytesperline = 176,
152 .sizeimage = 176 * 144,
153 .colorspace = V4L2_COLORSPACE_SRGB,
154 .priv = 3},
155 {320, 240, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
156 .bytesperline = 320,
157 .sizeimage = 320 * 240,
158 .colorspace = V4L2_COLORSPACE_SRGB,
159 .priv = 2},
160 {352, 288, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
161 .bytesperline = 352,
162 .sizeimage = 352 * 288,
163 .colorspace = V4L2_COLORSPACE_SRGB,
164 .priv = 1},
165 {640, 480, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
166 .bytesperline = 640,
167 .sizeimage = 640 * 480,
168 .colorspace = V4L2_COLORSPACE_SRGB,
169 .priv = 0},
170};
171
172
173static int mr_write(struct gspca_dev *gspca_dev, int len)
174{
175 int rc;
176
177 rc = usb_bulk_msg(gspca_dev->dev,
178 usb_sndbulkpipe(gspca_dev->dev, 4),
179 gspca_dev->usb_buf, len, NULL, 500);
180 if (rc < 0)
181 PDEBUG(D_ERR, "reg write [%02x] error %d",
182 gspca_dev->usb_buf[0], rc);
183 return rc;
184}
185
186
187static int mr_read(struct gspca_dev *gspca_dev, int len)
188{
189 int rc;
190
191 rc = usb_bulk_msg(gspca_dev->dev,
192 usb_rcvbulkpipe(gspca_dev->dev, 3),
193 gspca_dev->usb_buf, len, NULL, 500);
194 if (rc < 0)
195 PDEBUG(D_ERR, "reg read [%02x] error %d",
196 gspca_dev->usb_buf[0], rc);
197 return rc;
198}
199
200static int sensor_write_reg(struct gspca_dev *gspca_dev, u8 reg, u8 flags,
201 const u8 *data, int len)
202{
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);
207
208 return mr_write(gspca_dev, len + 3);
209}
210
211static int sensor_write_regs(struct gspca_dev *gspca_dev,
212 const struct sensor_w_data *data, int len)
213{
214 int i, rc;
215
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);
219 if (rc < 0)
220 return rc;
221 }
222
223 return 0;
224}
225
226static int sensor_write1(struct gspca_dev *gspca_dev, u8 reg, u8 data)
227{
228 struct sd *sd = (struct sd *) gspca_dev;
229 u8 buf, confirm_reg;
230 int rc;
231
232 buf = data;
233 rc = sensor_write_reg(gspca_dev, reg, 0x01, &buf, 1);
234 if (rc < 0)
235 return rc;
236
237 buf = 0x01;
238 confirm_reg = sd->sensor_type ? 0x13 : 0x11;
239 rc = sensor_write_reg(gspca_dev, confirm_reg, 0x00, &buf, 1);
240 if (rc < 0)
241 return rc;
242
243 return 0;
244}
245
246static int cam_get_response16(struct gspca_dev *gspca_dev)
247{
248 __u8 *data = gspca_dev->usb_buf;
249 int err_code;
250
251 data[0] = 0x21;
252 err_code = mr_write(gspca_dev, 1);
253 if (err_code < 0)
254 return err_code;
255
256 err_code = mr_read(gspca_dev, 16);
257 return err_code;
258}
259
260static int zero_the_pointer(struct gspca_dev *gspca_dev)
261{
262 __u8 *data = gspca_dev->usb_buf;
263 int err_code;
264 u8 status = 0;
265 int tries = 0;
266
267 err_code = cam_get_response16(gspca_dev);
268 if (err_code < 0)
269 return err_code;
270
271 err_code = mr_write(gspca_dev, 1);
272 data[0] = 0x19;
273 data[1] = 0x51;
274 err_code = mr_write(gspca_dev, 2);
275 if (err_code < 0)
276 return err_code;
277
278 err_code = cam_get_response16(gspca_dev);
279 if (err_code < 0)
280 return err_code;
281
282 data[0] = 0x19;
283 data[1] = 0xba;
284 err_code = mr_write(gspca_dev, 2);
285 if (err_code < 0)
286 return err_code;
287
288 err_code = cam_get_response16(gspca_dev);
289 if (err_code < 0)
290 return err_code;
291
292 data[0] = 0x19;
293 data[1] = 0x00;
294 err_code = mr_write(gspca_dev, 2);
295 if (err_code < 0)
296 return err_code;
297
298 err_code = cam_get_response16(gspca_dev);
299 if (err_code < 0)
300 return err_code;
301
302 data[0] = 0x19;
303 data[1] = 0x00;
304 err_code = mr_write(gspca_dev, 2);
305 if (err_code < 0)
306 return err_code;
307
308 while (status != 0x0a && tries < 256) {
309 err_code = cam_get_response16(gspca_dev);
310 status = data[0];
311 tries++;
312 if (err_code < 0)
313 return err_code;
314 }
315 if (status != 0x0a)
316 PDEBUG(D_ERR, "status is %02x", status);
317
318 tries = 0;
319 while (tries < 4) {
320 data[0] = 0x19;
321 data[1] = 0x00;
322 err_code = mr_write(gspca_dev, 2);
323 if (err_code < 0)
324 return err_code;
325
326 err_code = cam_get_response16(gspca_dev);
327 status = data[0];
328 tries++;
329 if (err_code < 0)
330 return err_code;
331 }
332
333 data[0] = 0x19;
334 err_code = mr_write(gspca_dev, 1);
335 if (err_code < 0)
336 return err_code;
337
338 err_code = mr_read(gspca_dev, 16);
339 if (err_code < 0)
340 return err_code;
341
342 return 0;
343}
344
345static u8 get_sensor_id(struct gspca_dev *gspca_dev)
346{
347 int err_code;
348
349 gspca_dev->usb_buf[0] = 0x1e;
350 err_code = mr_write(gspca_dev, 1);
351 if (err_code < 0)
352 return err_code;
353
354 err_code = mr_read(gspca_dev, 16);
355 if (err_code < 0)
356 return err_code;
357
358 PDEBUG(D_PROBE, "Byte zero reported is %01x", gspca_dev->usb_buf[0]);
359
360 return gspca_dev->usb_buf[0];
361}
362
363
364static int sd_config(struct gspca_dev *gspca_dev,
365 const struct usb_device_id *id)
366{
367 struct sd *sd = (struct sd *) gspca_dev;
368 struct cam *cam;
369 __u8 *data = gspca_dev->usb_buf;
370 int err_code;
371
372 cam = &gspca_dev->cam;
373 cam->cam_mode = vga_mode;
374 cam->nmodes = ARRAY_SIZE(vga_mode);
375
376 if (id->idProduct == 0x010e) {
377 sd->cam_type = CAM_TYPE_CIF;
378 cam->nmodes--;
379
380 data[0] = 0x01;
381 data[1] = 0x01;
382 err_code = mr_write(gspca_dev, 2);
383 if (err_code < 0)
384 return err_code;
385
386 msleep(200);
387 data[0] = get_sensor_id(gspca_dev);
388
389
390
391
392
393
394
395
396
397
398
399
400
401 if ((data[0] & 0x78) == 8 ||
402 ((data[0] & 0x2) == 0x2 && data[0] != 0x53))
403 sd->sensor_type = 1;
404 else
405 sd->sensor_type = 0;
406
407 PDEBUG(D_PROBE, "MR97310A CIF camera detected, sensor: %d",
408 sd->sensor_type);
409
410 if (force_sensor_type != -1) {
411 sd->sensor_type = !! force_sensor_type;
412 PDEBUG(D_PROBE, "Forcing sensor type to: %d",
413 sd->sensor_type);
414 }
415
416 if (sd->sensor_type == 0)
417 gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX);
418 } else {
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);
423 }
424
425 sd->brightness = MR97310A_BRIGHTNESS_DEFAULT;
426 sd->exposure = MR97310A_EXPOSURE_DEFAULT;
427 sd->gain = MR97310A_GAIN_DEFAULT;
428
429 return 0;
430}
431
432
433static int sd_init(struct gspca_dev *gspca_dev)
434{
435 return 0;
436}
437
438static int start_cif_cam(struct gspca_dev *gspca_dev)
439{
440 struct sd *sd = (struct sd *) gspca_dev;
441 __u8 *data = gspca_dev->usb_buf;
442 int err_code;
443 const __u8 startup_string[] = {
444 0x00,
445 0x0d,
446 0x01,
447 0x00,
448 0x00,
449 0x13,
450 0x00,
451 0x00,
452 0x00,
453 0x50,
454 0xc0
455 };
456
457
458 data[0] = 0x01;
459 data[1] = 0x01;
460 err_code = mr_write(gspca_dev, 2);
461 if (err_code < 0)
462 return err_code;
463
464 memcpy(data, startup_string, 11);
465 if (sd->sensor_type)
466 data[5] = 0xbb;
467
468 switch (gspca_dev->width) {
469 case 160:
470 data[9] |= 0x04;
471
472 case 320:
473 default:
474 data[3] = 0x28;
475 data[4] = 0x3c;
476 data[6] = 0x14;
477 data[8] = 0x1a + sd->sensor_type;
478 break;
479 case 176:
480 data[9] |= 0x04;
481
482 case 352:
483 data[3] = 0x2c;
484 data[4] = 0x48;
485 data[6] = 0x06;
486 data[8] = 0x06 - sd->sensor_type;
487 break;
488 }
489 err_code = mr_write(gspca_dev, 11);
490 if (err_code < 0)
491 return err_code;
492
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},
510 {0, 0, {0}, 0}
511 };
512 err_code = sensor_write_regs(gspca_dev, cif_sensor0_init_data,
513 ARRAY_SIZE(cif_sensor0_init_data));
514 } else {
515 const struct sensor_w_data cif_sensor1_init_data[] = {
516
517 {0x02, 0x00, {0x10}, 1},
518 {0x05, 0x01, {0x22}, 1},
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},
531 {0, 0, {0}, 0}
532 };
533 err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data,
534 ARRAY_SIZE(cif_sensor1_init_data));
535 }
536 if (err_code < 0)
537 return err_code;
538
539 setbrightness(gspca_dev);
540 setexposure(gspca_dev);
541 setgain(gspca_dev);
542
543 msleep(200);
544
545 data[0] = 0x00;
546 data[1] = 0x4d;
547 err_code = mr_write(gspca_dev, 2);
548 if (err_code < 0)
549 return err_code;
550
551 return 0;
552}
553
554static int start_vga_cam(struct gspca_dev *gspca_dev)
555{
556 struct sd *sd = (struct sd *) gspca_dev;
557 __u8 *data = gspca_dev->usb_buf;
558 int err_code;
559 const __u8 startup_string[] = {0x00, 0x0d, 0x01, 0x00, 0x00, 0x2b,
560 0x00, 0x00, 0x00, 0x50, 0xc0};
561
562
563 sd->sof_read = 0;
564
565
566
567
568
569
570
571 memset(data, 0, 16);
572 data[0] = 0x20;
573 err_code = mr_write(gspca_dev, 1);
574 if (err_code < 0)
575 return err_code;
576
577 err_code = mr_read(gspca_dev, 16);
578 if (err_code < 0)
579 return err_code;
580
581 PDEBUG(D_PROBE, "Byte reported is %02x", data[0]);
582
583 msleep(200);
584
585
586
587
588
589
590
591
592
593
594 sd->sensor_type = data[0] & 1;
595 sd->do_lcd_stop = (~data[0]) & 1;
596
597
598
599
600
601
602 data[0] = 0x01;
603 data[1] = 0x01;
604 err_code = mr_write(gspca_dev, 2);
605 if (err_code < 0)
606 return err_code;
607
608
609
610
611
612 if (!sd->sensor_type) {
613 data[0] = get_sensor_id(gspca_dev);
614 if (data[0] == 0x7f) {
615 sd->sensor_type = 1;
616 PDEBUG(D_PROBE, "sensor_type corrected to 1");
617 }
618 msleep(200);
619 }
620
621 if (force_sensor_type != -1) {
622 sd->sensor_type = !! force_sensor_type;
623 PDEBUG(D_PROBE, "Forcing sensor type to: %d",
624 sd->sensor_type);
625 }
626
627
628
629
630
631
632
633
634
635
636
637
638
639 memcpy(data, startup_string, 11);
640 if (!sd->sensor_type) {
641 data[5] = 0x00;
642 data[10] = 0x91;
643 }
644
645 switch (gspca_dev->width) {
646 case 160:
647 data[9] |= 0x0c;
648
649 case 320:
650 data[9] |= 0x04;
651
652 case 640:
653 default:
654 data[3] = 0x50;
655 data[4] = 0x78;
656 data[6] = 0x04;
657 data[8] = 0x03;
658 if (sd->do_lcd_stop)
659 data[8] = 0x04;
660 break;
661
662 case 176:
663 data[9] |= 0x04;
664
665 case 352:
666 data[3] = 0x2c;
667 data[4] = 0x48;
668 data[6] = 0x94;
669 data[8] = 0x63;
670 if (sd->do_lcd_stop)
671 data[8] = 0x64;
672 break;
673 }
674
675 err_code = mr_write(gspca_dev, 11);
676 if (err_code < 0)
677 return err_code;
678
679 if (!sd->sensor_type) {
680
681 const struct sensor_w_data vga_sensor0_init_data[] = {
682 {0x01, 0x00, {0x0c, 0x00, 0x04}, 3},
683 {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4},
684 {0x20, 0x00, {0x00, 0x80, 0x00, 0x08}, 4},
685 {0x25, 0x00, {0x03, 0xa9, 0x80}, 3},
686 {0x30, 0x00, {0x30, 0x18, 0x10, 0x18}, 4},
687 {0, 0, {0}, 0}
688 };
689 err_code = sensor_write_regs(gspca_dev, vga_sensor0_init_data,
690 ARRAY_SIZE(vga_sensor0_init_data));
691 } else {
692 const struct sensor_w_data vga_sensor1_init_data[] = {
693 {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00,
694 0x07, 0x00, 0x01}, 8},
695 {0x11, 0x04, {0x01}, 1},
696
697 {0x0a, 0x00, {0x01, 0x06, 0x00, 0x00, 0x01,
698 0x00, 0x0a}, 7},
699 {0x11, 0x04, {0x01}, 1},
700 {0x12, 0x00, {0x00, 0x63, 0x00, 0x70, 0x00, 0x00}, 6},
701 {0x11, 0x04, {0x01}, 1},
702 {0, 0, {0}, 0}
703 };
704 err_code = sensor_write_regs(gspca_dev, vga_sensor1_init_data,
705 ARRAY_SIZE(vga_sensor1_init_data));
706 }
707 if (err_code < 0)
708 return err_code;
709
710 msleep(200);
711 data[0] = 0x00;
712 data[1] = 0x4d;
713 err_code = mr_write(gspca_dev, 2);
714
715 return err_code;
716}
717
718static int sd_start(struct gspca_dev *gspca_dev)
719{
720 struct sd *sd = (struct sd *) gspca_dev;
721 int err_code;
722 struct cam *cam;
723
724 cam = &gspca_dev->cam;
725 sd->sof_read = 0;
726
727
728
729
730 zero_the_pointer(gspca_dev);
731 msleep(200);
732 if (sd->cam_type == CAM_TYPE_CIF) {
733 err_code = start_cif_cam(gspca_dev);
734 } else {
735 err_code = start_vga_cam(gspca_dev);
736 }
737 return err_code;
738}
739
740static void sd_stopN(struct gspca_dev *gspca_dev)
741{
742 struct sd *sd = (struct sd *) gspca_dev;
743 int result;
744
745 gspca_dev->usb_buf[0] = 1;
746 gspca_dev->usb_buf[1] = 0;
747 result = mr_write(gspca_dev, 2);
748 if (result < 0)
749 PDEBUG(D_ERR, "Camera Stop failed");
750
751
752 zero_the_pointer(gspca_dev);
753 if (sd->do_lcd_stop) {
754 gspca_dev->usb_buf[0] = 0x19;
755 gspca_dev->usb_buf[1] = 0x54;
756 result = mr_write(gspca_dev, 2);
757 if (result < 0)
758 PDEBUG(D_ERR, "Camera Stop failed");
759 }
760}
761
762static void setbrightness(struct gspca_dev *gspca_dev)
763{
764 struct sd *sd = (struct sd *) gspca_dev;
765 u8 val;
766
767 if (gspca_dev->ctrl_dis & (1 << BRIGHTNESS_IDX))
768 return;
769
770
771 if (sd->brightness > 0) {
772 sensor_write1(gspca_dev, 7, 0x00);
773 val = sd->brightness;
774 } else {
775 sensor_write1(gspca_dev, 7, 0x01);
776 val = 257 - sd->brightness;
777 }
778 sensor_write1(gspca_dev, 8, val);
779}
780
781static void setexposure(struct gspca_dev *gspca_dev)
782{
783 struct sd *sd = (struct sd *) gspca_dev;
784 u8 val;
785
786 if (gspca_dev->ctrl_dis & (1 << EXPOSURE_IDX))
787 return;
788
789 if (sd->sensor_type) {
790 val = sd->exposure >> 4;
791 sensor_write1(gspca_dev, 3, val);
792 val = sd->exposure & 0xf;
793 sensor_write1(gspca_dev, 4, val);
794 } else {
795 u8 clockdiv;
796 int exposure;
797
798
799
800
801
802
803
804
805 clockdiv = (60 * sd->exposure + 7999) / 8000;
806
807
808 if (clockdiv < 3 && gspca_dev->width >= 320)
809 clockdiv = 3;
810 else if (clockdiv < 2)
811 clockdiv = 2;
812
813
814
815 exposure = (60 * 511 * sd->exposure) / (8000 * clockdiv);
816 if (exposure > 511)
817 exposure = 511;
818
819
820 exposure = 511 - exposure;
821
822 sensor_write1(gspca_dev, 0x02, clockdiv);
823 sensor_write1(gspca_dev, 0x0e, exposure & 0xff);
824 sensor_write1(gspca_dev, 0x0f, exposure >> 8);
825 }
826}
827
828static void setgain(struct gspca_dev *gspca_dev)
829{
830 struct sd *sd = (struct sd *) gspca_dev;
831
832 if (gspca_dev->ctrl_dis & (1 << GAIN_IDX))
833 return;
834
835 if (sd->sensor_type) {
836 sensor_write1(gspca_dev, 0x0e, sd->gain);
837 } else {
838 sensor_write1(gspca_dev, 0x10, sd->gain);
839 }
840}
841
842static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
843{
844 struct sd *sd = (struct sd *) gspca_dev;
845
846 sd->brightness = val;
847 if (gspca_dev->streaming)
848 setbrightness(gspca_dev);
849 return 0;
850}
851
852static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
853{
854 struct sd *sd = (struct sd *) gspca_dev;
855
856 *val = sd->brightness;
857 return 0;
858}
859
860static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
861{
862 struct sd *sd = (struct sd *) gspca_dev;
863
864 sd->exposure = val;
865 if (gspca_dev->streaming)
866 setexposure(gspca_dev);
867 return 0;
868}
869
870static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
871{
872 struct sd *sd = (struct sd *) gspca_dev;
873
874 *val = sd->exposure;
875 return 0;
876}
877
878static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
879{
880 struct sd *sd = (struct sd *) gspca_dev;
881
882 sd->gain = val;
883 if (gspca_dev->streaming)
884 setgain(gspca_dev);
885 return 0;
886}
887
888static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
889{
890 struct sd *sd = (struct sd *) gspca_dev;
891
892 *val = sd->gain;
893 return 0;
894}
895
896
897#include "pac_common.h"
898
899static void sd_pkt_scan(struct gspca_dev *gspca_dev,
900 struct gspca_frame *frame,
901 __u8 *data,
902 int len)
903{
904 unsigned char *sof;
905
906 sof = pac_find_sof(gspca_dev, data, len);
907 if (sof) {
908 int n;
909
910
911 n = sof - data;
912 if (n > sizeof pac_sof_marker)
913 n -= sizeof pac_sof_marker;
914 else
915 n = 0;
916 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
917 data, n);
918
919 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
920 pac_sof_marker, sizeof pac_sof_marker);
921 len -= sof - data;
922 data = sof;
923 }
924 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
925}
926
927
928static const struct sd_desc sd_desc = {
929 .name = MODULE_NAME,
930 .ctrls = sd_ctrls,
931 .nctrls = ARRAY_SIZE(sd_ctrls),
932 .config = sd_config,
933 .init = sd_init,
934 .start = sd_start,
935 .stopN = sd_stopN,
936 .pkt_scan = sd_pkt_scan,
937};
938
939
940static const __devinitdata struct usb_device_id device_table[] = {
941 {USB_DEVICE(0x08ca, 0x0111)},
942 {USB_DEVICE(0x093a, 0x010f)},
943 {USB_DEVICE(0x093a, 0x010e)},
944 {}
945};
946MODULE_DEVICE_TABLE(usb, device_table);
947
948
949static int sd_probe(struct usb_interface *intf,
950 const struct usb_device_id *id)
951{
952 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
953 THIS_MODULE);
954}
955
956static struct usb_driver sd_driver = {
957 .name = MODULE_NAME,
958 .id_table = device_table,
959 .probe = sd_probe,
960 .disconnect = gspca_disconnect,
961#ifdef CONFIG_PM
962 .suspend = gspca_suspend,
963 .resume = gspca_resume,
964#endif
965};
966
967
968static int __init sd_mod_init(void)
969{
970 int ret;
971
972 ret = usb_register(&sd_driver);
973 if (ret < 0)
974 return ret;
975 PDEBUG(D_PROBE, "registered");
976 return 0;
977}
978static void __exit sd_mod_exit(void)
979{
980 usb_deregister(&sd_driver);
981 PDEBUG(D_PROBE, "deregistered");
982}
983
984module_init(sd_mod_init);
985module_exit(sd_mod_exit);
986