hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/media/usb/gspca/ov534.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * ov534-ov7xxx gspca driver
34 *
....@@ -13,17 +14,7 @@
1314 * PS3 Eye camera - brightness, contrast, awb, agc, aec controls
1415 * added by Max Thrun <bear24rw@gmail.com>
1516 * PS3 Eye camera - FPS range extended by Joseph Howse
16
- * <josephhowse@nummist.com> http://nummist.com
17
- *
18
- * This program is free software; you can redistribute it and/or modify
19
- * it under the terms of the GNU General Public License as published by
20
- * the Free Software Foundation; either version 2 of the License, or
21
- * any later version.
22
- *
23
- * This program is distributed in the hope that it will be useful,
24
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
- * GNU General Public License for more details.
17
+ * <josephhowse@nummist.com> https://nummist.com
2718 */
2819
2920 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -103,6 +94,16 @@
10394 .sizeimage = 640 * 480 * 2,
10495 .colorspace = V4L2_COLORSPACE_SRGB,
10596 .priv = 0},
97
+ {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
98
+ .bytesperline = 320,
99
+ .sizeimage = 320 * 240,
100
+ .colorspace = V4L2_COLORSPACE_SRGB,
101
+ .priv = 1},
102
+ {640, 480, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
103
+ .bytesperline = 640,
104
+ .sizeimage = 640 * 480,
105
+ .colorspace = V4L2_COLORSPACE_SRGB,
106
+ .priv = 0},
106107 };
107108 static const struct v4l2_pix_format ov767x_mode[] = {
108109 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
....@@ -124,6 +125,14 @@
124125 .nrates = ARRAY_SIZE(qvga_rates),
125126 },
126127 { /* 640x480 */
128
+ .rates = vga_rates,
129
+ .nrates = ARRAY_SIZE(vga_rates),
130
+ },
131
+ { /* 320x240 SGBRG8 */
132
+ .rates = qvga_rates,
133
+ .nrates = ARRAY_SIZE(qvga_rates),
134
+ },
135
+ { /* 640x480 SGBRG8 */
127136 .rates = vga_rates,
128137 .nrates = ARRAY_SIZE(vga_rates),
129138 },
....@@ -411,9 +420,7 @@
411420 };
412421
413422 static const u8 bridge_init_772x[][2] = {
414
- { 0xc2, 0x0c },
415423 { 0x88, 0xf8 },
416
- { 0xc3, 0x69 },
417424 { 0x89, 0xff },
418425 { 0x76, 0x03 },
419426 { 0x92, 0x01 },
....@@ -439,7 +446,6 @@
439446 { 0x1f, 0x81 },
440447 { 0x34, 0x05 },
441448 { 0xe3, 0x04 },
442
- { 0x88, 0x00 },
443449 { 0x89, 0x00 },
444450 { 0x76, 0x00 },
445451 { 0xe7, 0x2e },
....@@ -447,26 +453,9 @@
447453 { 0x25, 0x42 },
448454 { 0x21, 0xf0 },
449455
450
- { 0x1c, 0x00 },
451
- { 0x1d, 0x40 },
452
- { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
453
- { 0x1d, 0x00 }, /* payload size */
454
-
455
- { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
456
- { 0x1d, 0x58 }, /* frame size */
457
- { 0x1d, 0x00 }, /* frame size */
458
-
459456 { 0x1c, 0x0a },
460457 { 0x1d, 0x08 }, /* turn on UVC header */
461458 { 0x1d, 0x0e }, /* .. */
462
-
463
- { 0x8d, 0x1c },
464
- { 0x8e, 0x80 },
465
- { 0xe5, 0x04 },
466
-
467
- { 0xc0, 0x50 },
468
- { 0xc1, 0x3c },
469
- { 0xc2, 0x0c },
470459 };
471460 static const u8 sensor_init_772x[][2] = {
472461 { 0x12, 0x80 },
....@@ -545,13 +534,10 @@
545534 { 0x8c, 0xe8 },
546535 { 0x8d, 0x20 },
547536
548
- { 0x0c, 0x90 },
549
-
550537 { 0x2b, 0x00 },
551538 { 0x22, 0x7f },
552539 { 0x23, 0x03 },
553540 { 0x11, 0x01 },
554
- { 0x0c, 0xd0 },
555541 { 0x64, 0xff },
556542 { 0x0d, 0x41 },
557543
....@@ -559,9 +545,9 @@
559545 { 0x0e, 0xcd },
560546 { 0xac, 0xbf },
561547 { 0x8e, 0x00 }, /* De-noise threshold */
562
- { 0x0c, 0xd0 }
563548 };
564
-static const u8 bridge_start_vga_772x[][2] = {
549
+static const u8 bridge_start_vga_yuyv_772x[][2] = {
550
+ {0x88, 0x00},
565551 {0x1c, 0x00},
566552 {0x1d, 0x40},
567553 {0x1d, 0x02},
....@@ -569,10 +555,14 @@
569555 {0x1d, 0x02},
570556 {0x1d, 0x58},
571557 {0x1d, 0x00},
558
+ {0x8d, 0x1c},
559
+ {0x8e, 0x80},
572560 {0xc0, 0x50},
573561 {0xc1, 0x3c},
562
+ {0xc2, 0x0c},
563
+ {0xc3, 0x69},
574564 };
575
-static const u8 sensor_start_vga_772x[][2] = {
565
+static const u8 sensor_start_vga_yuyv_772x[][2] = {
576566 {0x12, 0x00},
577567 {0x17, 0x26},
578568 {0x18, 0xa0},
....@@ -581,8 +571,10 @@
581571 {0x29, 0xa0},
582572 {0x2c, 0xf0},
583573 {0x65, 0x20},
574
+ {0x67, 0x00},
584575 };
585
-static const u8 bridge_start_qvga_772x[][2] = {
576
+static const u8 bridge_start_qvga_yuyv_772x[][2] = {
577
+ {0x88, 0x00},
586578 {0x1c, 0x00},
587579 {0x1d, 0x40},
588580 {0x1d, 0x02},
....@@ -590,10 +582,14 @@
590582 {0x1d, 0x01},
591583 {0x1d, 0x4b},
592584 {0x1d, 0x00},
585
+ {0x8d, 0x1c},
586
+ {0x8e, 0x80},
593587 {0xc0, 0x28},
594588 {0xc1, 0x1e},
589
+ {0xc2, 0x0c},
590
+ {0xc3, 0x69},
595591 };
596
-static const u8 sensor_start_qvga_772x[][2] = {
592
+static const u8 sensor_start_qvga_yuyv_772x[][2] = {
597593 {0x12, 0x40},
598594 {0x17, 0x3f},
599595 {0x18, 0x50},
....@@ -602,6 +598,61 @@
602598 {0x29, 0x50},
603599 {0x2c, 0x78},
604600 {0x65, 0x2f},
601
+ {0x67, 0x00},
602
+};
603
+static const u8 bridge_start_vga_gbrg_772x[][2] = {
604
+ {0x88, 0x08},
605
+ {0x1c, 0x00},
606
+ {0x1d, 0x00},
607
+ {0x1d, 0x02},
608
+ {0x1d, 0x00},
609
+ {0x1d, 0x01},
610
+ {0x1d, 0x2c},
611
+ {0x1d, 0x00},
612
+ {0x8d, 0x00},
613
+ {0x8e, 0x00},
614
+ {0xc0, 0x50},
615
+ {0xc1, 0x3c},
616
+ {0xc2, 0x01},
617
+ {0xc3, 0x01},
618
+};
619
+static const u8 sensor_start_vga_gbrg_772x[][2] = {
620
+ {0x12, 0x01},
621
+ {0x17, 0x26},
622
+ {0x18, 0xa0},
623
+ {0x19, 0x07},
624
+ {0x1a, 0xf0},
625
+ {0x29, 0xa0},
626
+ {0x2c, 0xf0},
627
+ {0x65, 0x20},
628
+ {0x67, 0x02},
629
+};
630
+static const u8 bridge_start_qvga_gbrg_772x[][2] = {
631
+ {0x88, 0x08},
632
+ {0x1c, 0x00},
633
+ {0x1d, 0x00},
634
+ {0x1d, 0x02},
635
+ {0x1d, 0x00},
636
+ {0x1d, 0x00},
637
+ {0x1d, 0x4b},
638
+ {0x1d, 0x00},
639
+ {0x8d, 0x00},
640
+ {0x8e, 0x00},
641
+ {0xc0, 0x28},
642
+ {0xc1, 0x1e},
643
+ {0xc2, 0x01},
644
+ {0xc3, 0x01},
645
+};
646
+static const u8 sensor_start_qvga_gbrg_772x[][2] = {
647
+ {0x12, 0x41},
648
+ {0x17, 0x3f},
649
+ {0x18, 0x50},
650
+ {0x19, 0x03},
651
+ {0x1a, 0x78},
652
+ {0x29, 0x50},
653
+ {0x2c, 0x78},
654
+ {0x65, 0x2f},
655
+ {0x67, 0x02},
605656 };
606657
607658 static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
....@@ -684,7 +735,7 @@
684735 int i;
685736
686737 for (i = 0; i < 5; i++) {
687
- msleep(10);
738
+ usleep_range(10000, 20000);
688739 data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
689740
690741 switch (data) {
....@@ -1282,7 +1333,7 @@
12821333
12831334 /* reset sensor */
12841335 sccb_reg_write(gspca_dev, 0x12, 0x80);
1285
- msleep(10);
1336
+ usleep_range(10000, 20000);
12861337
12871338 /* probe the sensor */
12881339 sccb_reg_read(gspca_dev, 0x0a);
....@@ -1320,25 +1371,33 @@
13201371 {
13211372 struct sd *sd = (struct sd *) gspca_dev;
13221373 int mode;
1323
- static const struct reg_array bridge_start[NSENSORS][2] = {
1374
+ static const struct reg_array bridge_start[NSENSORS][4] = {
13241375 [SENSOR_OV767x] = {{bridge_start_qvga_767x,
13251376 ARRAY_SIZE(bridge_start_qvga_767x)},
13261377 {bridge_start_vga_767x,
13271378 ARRAY_SIZE(bridge_start_vga_767x)}},
1328
- [SENSOR_OV772x] = {{bridge_start_qvga_772x,
1329
- ARRAY_SIZE(bridge_start_qvga_772x)},
1330
- {bridge_start_vga_772x,
1331
- ARRAY_SIZE(bridge_start_vga_772x)}},
1379
+ [SENSOR_OV772x] = {{bridge_start_qvga_yuyv_772x,
1380
+ ARRAY_SIZE(bridge_start_qvga_yuyv_772x)},
1381
+ {bridge_start_vga_yuyv_772x,
1382
+ ARRAY_SIZE(bridge_start_vga_yuyv_772x)},
1383
+ {bridge_start_qvga_gbrg_772x,
1384
+ ARRAY_SIZE(bridge_start_qvga_gbrg_772x)},
1385
+ {bridge_start_vga_gbrg_772x,
1386
+ ARRAY_SIZE(bridge_start_vga_gbrg_772x)} },
13321387 };
1333
- static const struct reg_array sensor_start[NSENSORS][2] = {
1388
+ static const struct reg_array sensor_start[NSENSORS][4] = {
13341389 [SENSOR_OV767x] = {{sensor_start_qvga_767x,
13351390 ARRAY_SIZE(sensor_start_qvga_767x)},
13361391 {sensor_start_vga_767x,
13371392 ARRAY_SIZE(sensor_start_vga_767x)}},
1338
- [SENSOR_OV772x] = {{sensor_start_qvga_772x,
1339
- ARRAY_SIZE(sensor_start_qvga_772x)},
1340
- {sensor_start_vga_772x,
1341
- ARRAY_SIZE(sensor_start_vga_772x)}},
1393
+ [SENSOR_OV772x] = {{sensor_start_qvga_yuyv_772x,
1394
+ ARRAY_SIZE(sensor_start_qvga_yuyv_772x)},
1395
+ {sensor_start_vga_yuyv_772x,
1396
+ ARRAY_SIZE(sensor_start_vga_yuyv_772x)},
1397
+ {sensor_start_qvga_gbrg_772x,
1398
+ ARRAY_SIZE(sensor_start_qvga_gbrg_772x)},
1399
+ {sensor_start_vga_gbrg_772x,
1400
+ ARRAY_SIZE(sensor_start_vga_gbrg_772x)} },
13421401 };
13431402
13441403 /* (from ms-win trace) */
....@@ -1444,10 +1503,9 @@
14441503 /* If this packet is marked as EOF, end the frame */
14451504 } else if (data[1] & UVC_STREAM_EOF) {
14461505 sd->last_pts = 0;
1447
- if (gspca_dev->pixfmt.pixelformat == V4L2_PIX_FMT_YUYV
1506
+ if (gspca_dev->pixfmt.pixelformat != V4L2_PIX_FMT_JPEG
14481507 && gspca_dev->image_len + len - 12 !=
1449
- gspca_dev->pixfmt.width *
1450
- gspca_dev->pixfmt.height * 2) {
1508
+ gspca_dev->pixfmt.sizeimage) {
14511509 gspca_dbg(gspca_dev, D_PACK, "wrong sized frame\n");
14521510 goto discard;
14531511 }