/
ov519.c
5030 lines (4594 loc) · 135 KB
/
ov519.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* OV519 driver
*
* Copyright (C) 2008-2011 Jean-François Moine <moinejf@free.fr>
* Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com>
*
* This module is adapted from the ov51x-jpeg package, which itself
* was adapted from the ov511 driver.
*
* Original copyright for the ov511 driver is:
*
* Copyright (c) 1999-2006 Mark W. McClelland
* Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
* Many improvements by Bret Wallach <bwallac1@san.rr.com>
* Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
* OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
* Changes by Claudio Matsuoka <claudio@conectiva.com>
*
* ov51x-jpeg original copyright is:
*
* Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
* Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define MODULE_NAME "ov519"
#include <linux/input.h>
#include "gspca.h"
/* The jpeg_hdr is used by w996Xcf only */
/* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
#define CONEX_CAM
#include "jpeg.h"
MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
MODULE_DESCRIPTION("OV519 USB Camera Driver");
MODULE_LICENSE("GPL");
/* global parameters */
static int frame_rate;
/* Number of times to retry a failed I2C transaction. Increase this if you
* are getting "Failed to read sensor ID..." */
static int i2c_detect_tries = 10;
/* ov519 device descriptor */
struct sd {
struct gspca_dev gspca_dev; /* !! must be the first item */
struct v4l2_ctrl *jpegqual;
struct v4l2_ctrl *freq;
struct { /* h/vflip control cluster */
struct v4l2_ctrl *hflip;
struct v4l2_ctrl *vflip;
};
struct { /* autobrightness/brightness control cluster */
struct v4l2_ctrl *autobright;
struct v4l2_ctrl *brightness;
};
u8 revision;
u8 packet_nr;
char bridge;
#define BRIDGE_OV511 0
#define BRIDGE_OV511PLUS 1
#define BRIDGE_OV518 2
#define BRIDGE_OV518PLUS 3
#define BRIDGE_OV519 4 /* = ov530 */
#define BRIDGE_OVFX2 5
#define BRIDGE_W9968CF 6
#define BRIDGE_MASK 7
char invert_led;
#define BRIDGE_INVERT_LED 8
char snapshot_pressed;
char snapshot_needs_reset;
/* Determined by sensor type */
u8 sif;
#define QUALITY_MIN 50
#define QUALITY_MAX 70
#define QUALITY_DEF 50
u8 stopped; /* Streaming is temporarily paused */
u8 first_frame;
u8 frame_rate; /* current Framerate */
u8 clockdiv; /* clockdiv override */
s8 sensor; /* Type of image sensor chip (SEN_*) */
u8 sensor_addr;
u16 sensor_width;
u16 sensor_height;
s16 sensor_reg_cache[256];
u8 jpeg_hdr[JPEG_HDR_SZ];
};
enum sensors {
SEN_OV2610,
SEN_OV2610AE,
SEN_OV3610,
SEN_OV6620,
SEN_OV6630,
SEN_OV66308AF,
SEN_OV7610,
SEN_OV7620,
SEN_OV7620AE,
SEN_OV7640,
SEN_OV7648,
SEN_OV7660,
SEN_OV7670,
SEN_OV76BE,
SEN_OV8610,
SEN_OV9600,
};
/* Note this is a bit of a hack, but the w9968cf driver needs the code for all
the ov sensors which is already present here. When we have the time we
really should move the sensor drivers to v4l2 sub drivers. */
#include "w996Xcf.c"
/* table of the disabled controls */
struct ctrl_valid {
unsigned int has_brightness:1;
unsigned int has_contrast:1;
unsigned int has_exposure:1;
unsigned int has_autogain:1;
unsigned int has_sat:1;
unsigned int has_hvflip:1;
unsigned int has_autobright:1;
unsigned int has_freq:1;
};
static const struct ctrl_valid valid_controls[] = {
[SEN_OV2610] = {
.has_exposure = 1,
.has_autogain = 1,
},
[SEN_OV2610AE] = {
.has_exposure = 1,
.has_autogain = 1,
},
[SEN_OV3610] = {
/* No controls */
},
[SEN_OV6620] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_autobright = 1,
.has_freq = 1,
},
[SEN_OV6630] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_autobright = 1,
.has_freq = 1,
},
[SEN_OV66308AF] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_autobright = 1,
.has_freq = 1,
},
[SEN_OV7610] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_autobright = 1,
.has_freq = 1,
},
[SEN_OV7620] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_autobright = 1,
.has_freq = 1,
},
[SEN_OV7620AE] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_autobright = 1,
.has_freq = 1,
},
[SEN_OV7640] = {
.has_brightness = 1,
.has_sat = 1,
.has_freq = 1,
},
[SEN_OV7648] = {
.has_brightness = 1,
.has_sat = 1,
.has_freq = 1,
},
[SEN_OV7660] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_hvflip = 1,
.has_freq = 1,
},
[SEN_OV7670] = {
.has_brightness = 1,
.has_contrast = 1,
.has_hvflip = 1,
.has_freq = 1,
},
[SEN_OV76BE] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_autobright = 1,
.has_freq = 1,
},
[SEN_OV8610] = {
.has_brightness = 1,
.has_contrast = 1,
.has_sat = 1,
.has_autobright = 1,
},
[SEN_OV9600] = {
.has_exposure = 1,
.has_autogain = 1,
},
};
static const struct v4l2_pix_format ov519_vga_mode[] = {
{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 320,
.sizeimage = 320 * 240 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 1},
{640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 640,
.sizeimage = 640 * 480 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 0},
};
static const struct v4l2_pix_format ov519_sif_mode[] = {
{160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 160,
.sizeimage = 160 * 120 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 3},
{176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 176,
.sizeimage = 176 * 144 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 1},
{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 320,
.sizeimage = 320 * 240 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 2},
{352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 352,
.sizeimage = 352 * 288 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 0},
};
/* Note some of the sizeimage values for the ov511 / ov518 may seem
larger then necessary, however they need to be this big as the ov511 /
ov518 always fills the entire isoc frame, using 0 padding bytes when
it doesn't have any data. So with low framerates the amount of data
transferred can become quite large (libv4l will remove all the 0 padding
in userspace). */
static const struct v4l2_pix_format ov518_vga_mode[] = {
{320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
.bytesperline = 320,
.sizeimage = 320 * 240 * 3,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 1},
{640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
.bytesperline = 640,
.sizeimage = 640 * 480 * 2,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 0},
};
static const struct v4l2_pix_format ov518_sif_mode[] = {
{160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
.bytesperline = 160,
.sizeimage = 70000,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 3},
{176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
.bytesperline = 176,
.sizeimage = 70000,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 1},
{320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
.bytesperline = 320,
.sizeimage = 320 * 240 * 3,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 2},
{352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
.bytesperline = 352,
.sizeimage = 352 * 288 * 3,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 0},
};
static const struct v4l2_pix_format ov511_vga_mode[] = {
{320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
.bytesperline = 320,
.sizeimage = 320 * 240 * 3,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 1},
{640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
.bytesperline = 640,
.sizeimage = 640 * 480 * 2,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 0},
};
static const struct v4l2_pix_format ov511_sif_mode[] = {
{160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
.bytesperline = 160,
.sizeimage = 70000,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 3},
{176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
.bytesperline = 176,
.sizeimage = 70000,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 1},
{320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
.bytesperline = 320,
.sizeimage = 320 * 240 * 3,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 2},
{352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
.bytesperline = 352,
.sizeimage = 352 * 288 * 3,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv = 0},
};
static const struct v4l2_pix_format ovfx2_ov2610_mode[] = {
{800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 800,
.sizeimage = 800 * 600,
.colorspace = V4L2_COLORSPACE_SRGB,
.priv = 1},
{1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 1600,
.sizeimage = 1600 * 1200,
.colorspace = V4L2_COLORSPACE_SRGB},
};
static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
{640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 640,
.sizeimage = 640 * 480,
.colorspace = V4L2_COLORSPACE_SRGB,
.priv = 1},
{800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 800,
.sizeimage = 800 * 600,
.colorspace = V4L2_COLORSPACE_SRGB,
.priv = 1},
{1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 1024,
.sizeimage = 1024 * 768,
.colorspace = V4L2_COLORSPACE_SRGB,
.priv = 1},
{1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 1600,
.sizeimage = 1600 * 1200,
.colorspace = V4L2_COLORSPACE_SRGB,
.priv = 0},
{2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 2048,
.sizeimage = 2048 * 1536,
.colorspace = V4L2_COLORSPACE_SRGB,
.priv = 0},
};
static const struct v4l2_pix_format ovfx2_ov9600_mode[] = {
{640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 640,
.sizeimage = 640 * 480,
.colorspace = V4L2_COLORSPACE_SRGB,
.priv = 1},
{1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 1280,
.sizeimage = 1280 * 1024,
.colorspace = V4L2_COLORSPACE_SRGB},
};
/* Registers common to OV511 / OV518 */
#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
#define R51x_SYS_RESET 0x50
/* Reset type flags */
#define OV511_RESET_OMNICE 0x08
#define R51x_SYS_INIT 0x53
#define R51x_SYS_SNAP 0x52
#define R51x_SYS_CUST_ID 0x5f
#define R51x_COMP_LUT_BEGIN 0x80
/* OV511 Camera interface register numbers */
#define R511_CAM_DELAY 0x10
#define R511_CAM_EDGE 0x11
#define R511_CAM_PXCNT 0x12
#define R511_CAM_LNCNT 0x13
#define R511_CAM_PXDIV 0x14
#define R511_CAM_LNDIV 0x15
#define R511_CAM_UV_EN 0x16
#define R511_CAM_LINE_MODE 0x17
#define R511_CAM_OPTS 0x18
#define R511_SNAP_FRAME 0x19
#define R511_SNAP_PXCNT 0x1a
#define R511_SNAP_LNCNT 0x1b
#define R511_SNAP_PXDIV 0x1c
#define R511_SNAP_LNDIV 0x1d
#define R511_SNAP_UV_EN 0x1e
#define R511_SNAP_OPTS 0x1f
#define R511_DRAM_FLOW_CTL 0x20
#define R511_FIFO_OPTS 0x31
#define R511_I2C_CTL 0x40
#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
#define R511_COMP_EN 0x78
#define R511_COMP_LUT_EN 0x79
/* OV518 Camera interface register numbers */
#define R518_GPIO_OUT 0x56 /* OV518(+) only */
#define R518_GPIO_CTL 0x57 /* OV518(+) only */
/* OV519 Camera interface register numbers */
#define OV519_R10_H_SIZE 0x10
#define OV519_R11_V_SIZE 0x11
#define OV519_R12_X_OFFSETL 0x12
#define OV519_R13_X_OFFSETH 0x13
#define OV519_R14_Y_OFFSETL 0x14
#define OV519_R15_Y_OFFSETH 0x15
#define OV519_R16_DIVIDER 0x16
#define OV519_R20_DFR 0x20
#define OV519_R25_FORMAT 0x25
/* OV519 System Controller register numbers */
#define OV519_R51_RESET1 0x51
#define OV519_R54_EN_CLK1 0x54
#define OV519_R57_SNAPSHOT 0x57
#define OV519_GPIO_DATA_OUT0 0x71
#define OV519_GPIO_IO_CTRL0 0x72
/*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */
/*
* The FX2 chip does not give us a zero length read at end of frame.
* It does, however, give a short read at the end of a frame, if
* necessary, rather than run two frames together.
*
* By choosing the right bulk transfer size, we are guaranteed to always
* get a short read for the last read of each frame. Frame sizes are
* always a composite number (width * height, or a multiple) so if we
* choose a prime number, we are guaranteed that the last read of a
* frame will be short.
*
* But it isn't that easy: the 2.6 kernel requires a multiple of 4KB,
* otherwise EOVERFLOW "babbling" errors occur. I have not been able
* to figure out why. [PMiller]
*
* The constant (13 * 4096) is the largest "prime enough" number less than 64KB.
*
* It isn't enough to know the number of bytes per frame, in case we
* have data dropouts or buffer overruns (even though the FX2 double
* buffers, there are some pretty strict real time constraints for
* isochronous transfer for larger frame sizes).
*/
/*jfm: this value does not work for 800x600 - see isoc_init */
#define OVFX2_BULK_SIZE (13 * 4096)
/* I2C registers */
#define R51x_I2C_W_SID 0x41
#define R51x_I2C_SADDR_3 0x42
#define R51x_I2C_SADDR_2 0x43
#define R51x_I2C_R_SID 0x44
#define R51x_I2C_DATA 0x45
#define R518_I2C_CTL 0x47 /* OV518(+) only */
#define OVFX2_I2C_ADDR 0x00
/* I2C ADDRESSES */
#define OV7xx0_SID 0x42
#define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
#define OV8xx0_SID 0xa0
#define OV6xx0_SID 0xc0
/* OV7610 registers */
#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
#define OV7610_REG_BLUE 0x01 /* blue channel balance */
#define OV7610_REG_RED 0x02 /* red channel balance */
#define OV7610_REG_SAT 0x03 /* saturation */
#define OV8610_REG_HUE 0x04 /* 04 reserved */
#define OV7610_REG_CNT 0x05 /* Y contrast */
#define OV7610_REG_BRT 0x06 /* Y brightness */
#define OV7610_REG_COM_C 0x14 /* misc common regs */
#define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
#define OV7610_REG_COM_I 0x29 /* misc settings */
/* OV7660 and OV7670 registers */
#define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
#define OV7670_R01_BLUE 0x01 /* blue gain */
#define OV7670_R02_RED 0x02 /* red gain */
#define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
#define OV7670_R04_COM1 0x04 /* Control 1 */
/*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */
#define OV7670_R0C_COM3 0x0c /* Control 3 */
#define OV7670_R0D_COM4 0x0d /* Control 4 */
#define OV7670_R0E_COM5 0x0e /* All "reserved" */
#define OV7670_R0F_COM6 0x0f /* Control 6 */
#define OV7670_R10_AECH 0x10 /* More bits of AEC value */
#define OV7670_R11_CLKRC 0x11 /* Clock control */
#define OV7670_R12_COM7 0x12 /* Control 7 */
#define OV7670_COM7_FMT_VGA 0x00
/*#define OV7670_COM7_YUV 0x00 * YUV */
#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
#define OV7670_COM7_FMT_MASK 0x38
#define OV7670_COM7_RESET 0x80 /* Register reset */
#define OV7670_R13_COM8 0x13 /* Control 8 */
#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
#define OV7670_COM8_AWB 0x02 /* White balance enable */
#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
#define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */
#define OV7670_R15_COM10 0x15 /* Control 10 */
#define OV7670_R17_HSTART 0x17 /* Horiz start high bits */
#define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */
#define OV7670_R19_VSTART 0x19 /* Vert start high bits */
#define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */
#define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */
#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
#define OV7670_R24_AEW 0x24 /* AGC upper limit */
#define OV7670_R25_AEB 0x25 /* AGC lower limit */
#define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */
#define OV7670_R32_HREF 0x32 /* HREF pieces */
#define OV7670_R3A_TSLB 0x3a /* lots of stuff */
#define OV7670_R3B_COM11 0x3b /* Control 11 */
#define OV7670_COM11_EXP 0x02
#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
#define OV7670_R3C_COM12 0x3c /* Control 12 */
#define OV7670_R3D_COM13 0x3d /* Control 13 */
#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
#define OV7670_R3E_COM14 0x3e /* Control 14 */
#define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */
#define OV7670_R40_COM15 0x40 /* Control 15 */
/*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */
#define OV7670_R41_COM16 0x41 /* Control 16 */
#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
/* end of ov7660 common registers */
#define OV7670_R55_BRIGHT 0x55 /* Brightness */
#define OV7670_R56_CONTRAS 0x56 /* Contrast control */
#define OV7670_R69_GFIX 0x69 /* Fix gain control */
/*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */
#define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */
#define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
#define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */
#define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
#define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
#define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
#define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
#define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */
#define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */
struct ov_regvals {
u8 reg;
u8 val;
};
struct ov_i2c_regvals {
u8 reg;
u8 val;
};
/* Settings for OV2610 camera chip */
static const struct ov_i2c_regvals norm_2610[] = {
{ 0x12, 0x80 }, /* reset */
};
static const struct ov_i2c_regvals norm_2610ae[] = {
{0x12, 0x80}, /* reset */
{0x13, 0xcd},
{0x09, 0x01},
{0x0d, 0x00},
{0x11, 0x80},
{0x12, 0x20}, /* 1600x1200 */
{0x33, 0x0c},
{0x35, 0x90},
{0x36, 0x37},
/* ms-win traces */
{0x11, 0x83}, /* clock / 3 ? */
{0x2d, 0x00}, /* 60 Hz filter */
{0x24, 0xb0}, /* normal colors */
{0x25, 0x90},
{0x10, 0x43},
};
static const struct ov_i2c_regvals norm_3620b[] = {
/*
* From the datasheet: "Note that after writing to register COMH
* (0x12) to change the sensor mode, registers related to the
* sensor's cropping window will be reset back to their default
* values."
*
* "wait 4096 external clock ... to make sure the sensor is
* stable and ready to access registers" i.e. 160us at 24MHz
*/
{ 0x12, 0x80 }, /* COMH reset */
{ 0x12, 0x00 }, /* QXGA, master */
/*
* 11 CLKRC "Clock Rate Control"
* [7] internal frequency doublers: on
* [6] video port mode: master
* [5:0] clock divider: 1
*/
{ 0x11, 0x80 },
/*
* 13 COMI "Common Control I"
* = 192 (0xC0) 11000000
* COMI[7] "AEC speed selection"
* = 1 (0x01) 1....... "Faster AEC correction"
* COMI[6] "AEC speed step selection"
* = 1 (0x01) .1...... "Big steps, fast"
* COMI[5] "Banding filter on off"
* = 0 (0x00) ..0..... "Off"
* COMI[4] "Banding filter option"
* = 0 (0x00) ...0.... "Main clock is 48 MHz and
* the PLL is ON"
* COMI[3] "Reserved"
* = 0 (0x00) ....0...
* COMI[2] "AGC auto manual control selection"
* = 0 (0x00) .....0.. "Manual"
* COMI[1] "AWB auto manual control selection"
* = 0 (0x00) ......0. "Manual"
* COMI[0] "Exposure control"
* = 0 (0x00) .......0 "Manual"
*/
{ 0x13, 0xc0 },
/*
* 09 COMC "Common Control C"
* = 8 (0x08) 00001000
* COMC[7:5] "Reserved"
* = 0 (0x00) 000.....
* COMC[4] "Sleep Mode Enable"
* = 0 (0x00) ...0.... "Normal mode"
* COMC[3:2] "Sensor sampling reset timing selection"
* = 2 (0x02) ....10.. "Longer reset time"
* COMC[1:0] "Output drive current select"
* = 0 (0x00) ......00 "Weakest"
*/
{ 0x09, 0x08 },
/*
* 0C COMD "Common Control D"
* = 8 (0x08) 00001000
* COMD[7] "Reserved"
* = 0 (0x00) 0.......
* COMD[6] "Swap MSB and LSB at the output port"
* = 0 (0x00) .0...... "False"
* COMD[5:3] "Reserved"
* = 1 (0x01) ..001...
* COMD[2] "Output Average On Off"
* = 0 (0x00) .....0.. "Output Normal"
* COMD[1] "Sensor precharge voltage selection"
* = 0 (0x00) ......0. "Selects internal
* reference precharge
* voltage"
* COMD[0] "Snapshot option"
* = 0 (0x00) .......0 "Enable live video output
* after snapshot sequence"
*/
{ 0x0c, 0x08 },
/*
* 0D COME "Common Control E"
* = 161 (0xA1) 10100001
* COME[7] "Output average option"
* = 1 (0x01) 1....... "Output average of 4 pixels"
* COME[6] "Anti-blooming control"
* = 0 (0x00) .0...... "Off"
* COME[5:3] "Reserved"
* = 4 (0x04) ..100...
* COME[2] "Clock output power down pin status"
* = 0 (0x00) .....0.. "Tri-state data output pin
* on power down"
* COME[1] "Data output pin status selection at power down"
* = 0 (0x00) ......0. "Tri-state VSYNC, PCLK,
* HREF, and CHSYNC pins on
* power down"
* COME[0] "Auto zero circuit select"
* = 1 (0x01) .......1 "On"
*/
{ 0x0d, 0xa1 },
/*
* 0E COMF "Common Control F"
* = 112 (0x70) 01110000
* COMF[7] "System clock selection"
* = 0 (0x00) 0....... "Use 24 MHz system clock"
* COMF[6:4] "Reserved"
* = 7 (0x07) .111....
* COMF[3] "Manual auto negative offset canceling selection"
* = 0 (0x00) ....0... "Auto detect negative
* offset and cancel it"
* COMF[2:0] "Reserved"
* = 0 (0x00) .....000
*/
{ 0x0e, 0x70 },
/*
* 0F COMG "Common Control G"
* = 66 (0x42) 01000010
* COMG[7] "Optical black output selection"
* = 0 (0x00) 0....... "Disable"
* COMG[6] "Black level calibrate selection"
* = 1 (0x01) .1...... "Use optical black pixels
* to calibrate"
* COMG[5:4] "Reserved"
* = 0 (0x00) ..00....
* COMG[3] "Channel offset adjustment"
* = 0 (0x00) ....0... "Disable offset adjustment"
* COMG[2] "ADC black level calibration option"
* = 0 (0x00) .....0.. "Use B/G line and G/R
* line to calibrate each
* channel's black level"
* COMG[1] "Reserved"
* = 1 (0x01) ......1.
* COMG[0] "ADC black level calibration enable"
* = 0 (0x00) .......0 "Disable"
*/
{ 0x0f, 0x42 },
/*
* 14 COMJ "Common Control J"
* = 198 (0xC6) 11000110
* COMJ[7:6] "AGC gain ceiling"
* = 3 (0x03) 11...... "8x"
* COMJ[5:4] "Reserved"
* = 0 (0x00) ..00....
* COMJ[3] "Auto banding filter"
* = 0 (0x00) ....0... "Banding filter is always
* on off depending on
* COMI[5] setting"
* COMJ[2] "VSYNC drop option"
* = 1 (0x01) .....1.. "SYNC is dropped if frame
* data is dropped"
* COMJ[1] "Frame data drop"
* = 1 (0x01) ......1. "Drop frame data if
* exposure is not within
* tolerance. In AEC mode,
* data is normally dropped
* when data is out of
* range."
* COMJ[0] "Reserved"
* = 0 (0x00) .......0
*/
{ 0x14, 0xc6 },
/*
* 15 COMK "Common Control K"
* = 2 (0x02) 00000010
* COMK[7] "CHSYNC pin output swap"
* = 0 (0x00) 0....... "CHSYNC"
* COMK[6] "HREF pin output swap"
* = 0 (0x00) .0...... "HREF"
* COMK[5] "PCLK output selection"
* = 0 (0x00) ..0..... "PCLK always output"
* COMK[4] "PCLK edge selection"
* = 0 (0x00) ...0.... "Data valid on falling edge"
* COMK[3] "HREF output polarity"
* = 0 (0x00) ....0... "positive"
* COMK[2] "Reserved"
* = 0 (0x00) .....0..
* COMK[1] "VSYNC polarity"
* = 1 (0x01) ......1. "negative"
* COMK[0] "HSYNC polarity"
* = 0 (0x00) .......0 "positive"
*/
{ 0x15, 0x02 },
/*
* 33 CHLF "Current Control"
* = 9 (0x09) 00001001
* CHLF[7:6] "Sensor current control"
* = 0 (0x00) 00......
* CHLF[5] "Sensor current range control"
* = 0 (0x00) ..0..... "normal range"
* CHLF[4] "Sensor current"
* = 0 (0x00) ...0.... "normal current"
* CHLF[3] "Sensor buffer current control"
* = 1 (0x01) ....1... "half current"
* CHLF[2] "Column buffer current control"
* = 0 (0x00) .....0.. "normal current"
* CHLF[1] "Analog DSP current control"
* = 0 (0x00) ......0. "normal current"
* CHLF[1] "ADC current control"
* = 0 (0x00) ......0. "normal current"
*/
{ 0x33, 0x09 },
/*
* 34 VBLM "Blooming Control"
* = 80 (0x50) 01010000
* VBLM[7] "Hard soft reset switch"
* = 0 (0x00) 0....... "Hard reset"
* VBLM[6:4] "Blooming voltage selection"
* = 5 (0x05) .101....
* VBLM[3:0] "Sensor current control"
* = 0 (0x00) ....0000
*/
{ 0x34, 0x50 },
/*
* 36 VCHG "Sensor Precharge Voltage Control"
* = 0 (0x00) 00000000
* VCHG[7] "Reserved"
* = 0 (0x00) 0.......
* VCHG[6:4] "Sensor precharge voltage control"
* = 0 (0x00) .000....
* VCHG[3:0] "Sensor array common reference"
* = 0 (0x00) ....0000
*/
{ 0x36, 0x00 },
/*
* 37 ADC "ADC Reference Control"
* = 4 (0x04) 00000100
* ADC[7:4] "Reserved"
* = 0 (0x00) 0000....
* ADC[3] "ADC input signal range"
* = 0 (0x00) ....0... "Input signal 1.0x"
* ADC[2:0] "ADC range control"
* = 4 (0x04) .....100
*/
{ 0x37, 0x04 },
/*
* 38 ACOM "Analog Common Ground"
* = 82 (0x52) 01010010
* ACOM[7] "Analog gain control"
* = 0 (0x00) 0....... "Gain 1x"
* ACOM[6] "Analog black level calibration"
* = 1 (0x01) .1...... "On"
* ACOM[5:0] "Reserved"
* = 18 (0x12) ..010010
*/
{ 0x38, 0x52 },
/*
* 3A FREFA "Internal Reference Adjustment"
* = 0 (0x00) 00000000
* FREFA[7:0] "Range"
* = 0 (0x00) 00000000
*/
{ 0x3a, 0x00 },
/*
* 3C FVOPT "Internal Reference Adjustment"
* = 31 (0x1F) 00011111
* FVOPT[7:0] "Range"
* = 31 (0x1F) 00011111
*/
{ 0x3c, 0x1f },
/*
* 44 Undocumented = 0 (0x00) 00000000
* 44[7:0] "It's a secret"
* = 0 (0x00) 00000000
*/
{ 0x44, 0x00 },
/*
* 40 Undocumented = 0 (0x00) 00000000
* 40[7:0] "It's a secret"
* = 0 (0x00) 00000000
*/
{ 0x40, 0x00 },
/*
* 41 Undocumented = 0 (0x00) 00000000
* 41[7:0] "It's a secret"
* = 0 (0x00) 00000000
*/
{ 0x41, 0x00 },
/*
* 42 Undocumented = 0 (0x00) 00000000
* 42[7:0] "It's a secret"
* = 0 (0x00) 00000000
*/
{ 0x42, 0x00 },
/*
* 43 Undocumented = 0 (0x00) 00000000
* 43[7:0] "It's a secret"
* = 0 (0x00) 00000000
*/
{ 0x43, 0x00 },
/*
* 45 Undocumented = 128 (0x80) 10000000
* 45[7:0] "It's a secret"
* = 128 (0x80) 10000000
*/
{ 0x45, 0x80 },
/*
* 48 Undocumented = 192 (0xC0) 11000000
* 48[7:0] "It's a secret"
* = 192 (0xC0) 11000000
*/
{ 0x48, 0xc0 },
/*
* 49 Undocumented = 25 (0x19) 00011001
* 49[7:0] "It's a secret"
* = 25 (0x19) 00011001
*/
{ 0x49, 0x19 },
/*
* 4B Undocumented = 128 (0x80) 10000000
* 4B[7:0] "It's a secret"
* = 128 (0x80) 10000000
*/
{ 0x4b, 0x80 },
/*
* 4D Undocumented = 196 (0xC4) 11000100
* 4D[7:0] "It's a secret"
* = 196 (0xC4) 11000100
*/
{ 0x4d, 0xc4 },
/*
* 35 VREF "Reference Voltage Control"
* = 76 (0x4c) 01001100
* VREF[7:5] "Column high reference control"
* = 2 (0x02) 010..... "higher voltage"
* VREF[4:2] "Column low reference control"
* = 3 (0x03) ...011.. "Highest voltage"
* VREF[1:0] "Reserved"
* = 0 (0x00) ......00
*/
{ 0x35, 0x4c },
/*
* 3D Undocumented = 0 (0x00) 00000000
* 3D[7:0] "It's a secret"
* = 0 (0x00) 00000000
*/
{ 0x3d, 0x00 },
/*
* 3E Undocumented = 0 (0x00) 00000000
* 3E[7:0] "It's a secret"
* = 0 (0x00) 00000000
*/
{ 0x3e, 0x00 },
/*
* 3B FREFB "Internal Reference Adjustment"
* = 24 (0x18) 00011000
* FREFB[7:0] "Range"
* = 24 (0x18) 00011000
*/
{ 0x3b, 0x18 },
/*
* 33 CHLF "Current Control"
* = 25 (0x19) 00011001
* CHLF[7:6] "Sensor current control"
* = 0 (0x00) 00......
* CHLF[5] "Sensor current range control"
* = 0 (0x00) ..0..... "normal range"
* CHLF[4] "Sensor current"
* = 1 (0x01) ...1.... "double current"
* CHLF[3] "Sensor buffer current control"
* = 1 (0x01) ....1... "half current"
* CHLF[2] "Column buffer current control"
* = 0 (0x00) .....0.. "normal current"
* CHLF[1] "Analog DSP current control"