1#ifndef __LINUX_OV511_H
2#define __LINUX_OV511_H
3
4#include <asm/uaccess.h>
5#include <linux/videodev.h>
6#include <linux/smp_lock.h>
7#include <linux/usb.h>
8
9#define OV511_DEBUG
10
11#ifdef OV511_DEBUG
12 #define PDEBUG(level, fmt, args...) \
13 if (debug >= (level)) info("[%s:%d] " fmt, \
14 __PRETTY_FUNCTION__, __LINE__ , ## args)
15#else
16 #define PDEBUG(level, fmt, args...) do {} while(0)
17#endif
18
19
20#define RESTRICT_TO_RANGE(v,mi,ma) { \
21 if ((v) < (mi)) (v) = (mi); \
22 else if ((v) > (ma)) (v) = (ma); \
23}
24
25
26
27
28
29
30#define VEND_OMNIVISION 0x05A9
31#define PROD_OV511 0x0511
32#define PROD_OV511PLUS 0xA511
33#define PROD_OV518 0x0518
34#define PROD_OV518PLUS 0xA518
35
36#define VEND_MATTEL 0x0813
37#define PROD_ME2CAM 0x0002
38
39
40
41
42
43
44#define R511_CAM_DELAY 0x10
45#define R511_CAM_EDGE 0x11
46#define R511_CAM_PXCNT 0x12
47#define R511_CAM_LNCNT 0x13
48#define R511_CAM_PXDIV 0x14
49#define R511_CAM_LNDIV 0x15
50#define R511_CAM_UV_EN 0x16
51#define R511_CAM_LINE_MODE 0x17
52#define R511_CAM_OPTS 0x18
53
54
55#define R511_SNAP_FRAME 0x19
56#define R511_SNAP_PXCNT 0x1A
57#define R511_SNAP_LNCNT 0x1B
58#define R511_SNAP_PXDIV 0x1C
59#define R511_SNAP_LNDIV 0x1D
60#define R511_SNAP_UV_EN 0x1E
61#define R511_SNAP_OPTS 0x1F
62
63
64#define R511_DRAM_FLOW_CTL 0x20
65#define R511_DRAM_ARCP 0x21
66#define R511_DRAM_MRC 0x22
67#define R511_DRAM_RFC 0x23
68
69
70#define R51x_FIFO_PSIZE 0x30
71#define R511_FIFO_OPTS 0x31
72
73
74#define R511_PIO_OPTS 0x38
75#define R511_PIO_DATA 0x39
76#define R511_PIO_BIST 0x3E
77#define R518_GPIO_IN 0x55
78#define R518_GPIO_OUT 0x56
79#define R518_GPIO_CTL 0x57
80#define R518_GPIO_PULSE_IN 0x58
81#define R518_GPIO_PULSE_CLEAR 0x59
82#define R518_GPIO_PULSE_POL 0x5a
83#define R518_GPIO_PULSE_EN 0x5b
84#define R518_GPIO_RESET 0x5c
85
86
87#define R511_I2C_CTL 0x40
88#define R518_I2C_CTL 0x47
89#define R51x_I2C_W_SID 0x41
90#define R51x_I2C_SADDR_3 0x42
91#define R51x_I2C_SADDR_2 0x43
92#define R51x_I2C_R_SID 0x44
93#define R51x_I2C_DATA 0x45
94#define R51x_I2C_CLOCK 0x46
95#define R51x_I2C_TIMEOUT 0x47
96
97
98#define R511_SI2C_SADDR_3 0x48
99#define R511_SI2C_DATA 0x49
100
101
102#define R51x_SYS_RESET 0x50
103
104#define OV511_RESET_UDC 0x01
105#define OV511_RESET_I2C 0x02
106#define OV511_RESET_FIFO 0x04
107#define OV511_RESET_OMNICE 0x08
108#define OV511_RESET_DRAM 0x10
109#define OV511_RESET_CAM_INT 0x20
110#define OV511_RESET_OV511 0x40
111#define OV511_RESET_NOREGS 0x3F
112#define OV511_RESET_ALL 0x7F
113
114#define R511_SYS_CLOCK_DIV 0x51
115#define R51x_SYS_SNAP 0x52
116#define R51x_SYS_INIT 0x53
117#define R511_SYS_PWR_CLK 0x54
118#define R511_SYS_LED_CTL 0x55
119#define R511_SYS_USER 0x5E
120#define R511_SYS_CUST_ID 0x5F
121
122
123#define R511_COMP_PHY 0x70
124#define R511_COMP_PHUV 0x71
125#define R511_COMP_PVY 0x72
126#define R511_COMP_PVUV 0x73
127#define R511_COMP_QHY 0x74
128#define R511_COMP_QHUV 0x75
129#define R511_COMP_QVY 0x76
130#define R511_COMP_QVUV 0x77
131#define R511_COMP_EN 0x78
132#define R511_COMP_LUT_EN 0x79
133#define R511_COMP_LUT_BEGIN 0x80
134
135
136
137
138
139
140#define OV511_ALT_SIZE_992 0
141#define OV511_ALT_SIZE_993 1
142#define OV511_ALT_SIZE_768 2
143#define OV511_ALT_SIZE_769 3
144#define OV511_ALT_SIZE_512 4
145#define OV511_ALT_SIZE_513 5
146#define OV511_ALT_SIZE_257 6
147#define OV511_ALT_SIZE_0 7
148
149
150#define OV511PLUS_ALT_SIZE_0 0
151#define OV511PLUS_ALT_SIZE_33 1
152#define OV511PLUS_ALT_SIZE_129 2
153#define OV511PLUS_ALT_SIZE_257 3
154#define OV511PLUS_ALT_SIZE_385 4
155#define OV511PLUS_ALT_SIZE_513 5
156#define OV511PLUS_ALT_SIZE_769 6
157#define OV511PLUS_ALT_SIZE_961 7
158
159
160#define OV518_ALT_SIZE_0 0
161#define OV518_ALT_SIZE_128 1
162#define OV518_ALT_SIZE_256 2
163#define OV518_ALT_SIZE_384 3
164#define OV518_ALT_SIZE_512 4
165#define OV518_ALT_SIZE_640 5
166#define OV518_ALT_SIZE_768 6
167#define OV518_ALT_SIZE_896 7
168
169
170
171
172
173
174#define OV7610_REG_GAIN 0x00
175#define OV7610_REG_BLUE 0x01
176#define OV7610_REG_RED 0x02
177#define OV7610_REG_SAT 0x03
178
179#define OV7610_REG_CNT 0x05
180#define OV7610_REG_BRT 0x06
181
182#define OV7610_REG_BLUE_BIAS 0x0C
183#define OV7610_REG_RED_BIAS 0x0D
184#define OV7610_REG_GAMMA_COEFF 0x0E
185#define OV7610_REG_WB_RANGE 0x0F
186#define OV7610_REG_EXP 0x10
187#define OV7610_REG_CLOCK 0x11
188#define OV7610_REG_COM_A 0x12
189#define OV7610_REG_COM_B 0x13
190#define OV7610_REG_COM_C 0x14
191#define OV7610_REG_COM_D 0x15
192#define OV7610_REG_FIELD_DIVIDE 0x16
193#define OV7610_REG_HWIN_START 0x17
194#define OV7610_REG_HWIN_END 0x18
195#define OV7610_REG_VWIN_START 0x19
196#define OV7610_REG_VWIN_END 0x1A
197#define OV7610_REG_PIXEL_SHIFT 0x1B
198#define OV7610_REG_ID_HIGH 0x1C
199#define OV7610_REG_ID_LOW 0x1D
200
201#define OV7610_REG_COM_E 0x20
202#define OV7610_REG_YOFFSET 0x21
203#define OV7610_REG_UOFFSET 0x22
204
205#define OV7610_REG_ECW 0x24
206#define OV7610_REG_ECB 0x25
207#define OV7610_REG_COM_F 0x26
208#define OV7610_REG_COM_G 0x27
209#define OV7610_REG_COM_H 0x28
210#define OV7610_REG_COM_I 0x29
211#define OV7610_REG_FRAMERATE_H 0x2A
212#define OV7610_REG_FRAMERATE_L 0x2B
213#define OV7610_REG_ALC 0x2C
214#define OV7610_REG_COM_J 0x2D
215#define OV7610_REG_VOFFSET 0x2E
216#define OV7610_REG_ARRAY_BIAS 0x2F
217
218#define OV7610_REG_YGAMMA 0x33
219#define OV7610_REG_BIAS_ADJUST 0x34
220#define OV7610_REG_COM_L 0x35
221
222#define OV7610_REG_COM_K 0x38
223
224
225
226
227
228#define OV7xx0_SID 0x42
229#define OV6xx0_SID 0xC0
230#define OV8xx0_SID 0xA0
231#define KS0127_SID 0xD8
232#define SAA7111A_SID 0x48
233
234
235
236
237
238#define I2C_CLOCK_PRESCALER 0x03
239
240#define FRAMES_PER_DESC 10
241#define MAX_FRAME_SIZE_PER_DESC 993
242#define PIXELS_PER_SEG 256
243
244#define OV511_ENDPOINT_ADDRESS 1
245
246#define OV511_NUMFRAMES 2
247#if OV511_NUMFRAMES > VIDEO_MAX_FRAME
248 #error "OV511_NUMFRAMES is too high"
249#endif
250
251#define OV511_NUMSBUF 2
252
253
254#define OV511_CBUF_SIZE 4
255
256
257#define OV511_USB_PATH_LEN 64
258
259
260enum {
261 BRG_UNKNOWN,
262 BRG_OV511,
263 BRG_OV511PLUS,
264 BRG_OV518,
265 BRG_OV518PLUS,
266};
267
268
269enum {
270 BCL_UNKNOWN,
271 BCL_OV511,
272 BCL_OV518,
273};
274
275
276enum {
277 SEN_UNKNOWN,
278 SEN_OV76BE,
279 SEN_OV7610,
280 SEN_OV7620,
281 SEN_OV7620AE,
282 SEN_OV6620,
283 SEN_OV6630,
284 SEN_OV6630AE,
285 SEN_OV6630AF,
286 SEN_OV8600,
287 SEN_KS0127,
288 SEN_KS0127B,
289 SEN_SAA7111A,
290};
291
292enum {
293 STATE_SCANNING,
294 STATE_HEADER,
295 STATE_LINES,
296};
297
298
299enum {
300 BUF_NOT_ALLOCATED,
301 BUF_ALLOCATED,
302};
303
304
305
306#define OV511_INTERFACE_VER 101
307
308
309enum {
310 LED_OFF,
311 LED_ON,
312 LED_AUTO,
313};
314
315
316enum {
317 RAWFMT_INVALID,
318 RAWFMT_YUV400,
319 RAWFMT_YUV420,
320 RAWFMT_YUV422,
321 RAWFMT_GBR422,
322};
323
324
325enum {
326 OV511_USOPT_INVALID,
327 OV511_USOPT_BRIGHT,
328 OV511_USOPT_SAT,
329 OV511_USOPT_HUE,
330 OV511_USOPT_CONTRAST,
331};
332
333
334enum {
335 OV511_UIOPT_INVALID,
336 OV511_UIOPT_POWER_FREQ,
337 OV511_UIOPT_BFILTER,
338 OV511_UIOPT_LED,
339 OV511_UIOPT_DEBUG,
340 OV511_UIOPT_COMPRESS,
341};
342
343struct ov511_ushort_opt {
344 int optnum;
345 unsigned short val;
346};
347
348struct ov511_uint_opt {
349 int optnum;
350 unsigned int val;
351};
352
353struct ov511_i2c_struct {
354 unsigned char slave;
355 unsigned char reg;
356 unsigned char value;
357 unsigned char mask;
358};
359
360
361#define OV511IOC_GINTVER _IOR('v', BASE_VIDIOCPRIVATE + 0, int)
362#define OV511IOC_GUSHORT _IOWR('v', BASE_VIDIOCPRIVATE + 1, \
363 struct ov511_ushort_opt)
364#define OV511IOC_SUSHORT _IOW('v', BASE_VIDIOCPRIVATE + 2, \
365 struct ov511_ushort_opt)
366#define OV511IOC_GUINT _IOWR('v', BASE_VIDIOCPRIVATE + 3, \
367 struct ov511_uint_opt)
368#define OV511IOC_SUINT _IOW('v', BASE_VIDIOCPRIVATE + 4, \
369 struct ov511_uint_opt)
370#define OV511IOC_WI2C _IOW('v', BASE_VIDIOCPRIVATE + 5, \
371 struct ov511_i2c_struct)
372#define OV511IOC_RI2C _IOWR('v', BASE_VIDIOCPRIVATE + 6, \
373 struct ov511_i2c_struct)
374
375
376struct usb_ov511;
377
378struct ov511_sbuf {
379 struct usb_ov511 *ov;
380 unsigned char *data;
381 struct urb *urb;
382 spinlock_t lock;
383 int n;
384};
385
386enum {
387 FRAME_UNUSED,
388 FRAME_READY,
389 FRAME_GRABBING,
390 FRAME_DONE,
391 FRAME_ERROR,
392};
393
394struct ov511_regvals {
395 enum {
396 OV511_DONE_BUS,
397 OV511_REG_BUS,
398 OV511_I2C_BUS,
399 } bus;
400 unsigned char reg;
401 unsigned char val;
402};
403
404struct ov511_frame {
405 int framenum;
406 unsigned char *data;
407 unsigned char *tempdata;
408 unsigned char *rawdata;
409 unsigned char *compbuf;
410
411 int depth;
412 int width;
413 int height;
414
415 int rawwidth;
416 int rawheight;
417
418 int sub_flag;
419 unsigned int format;
420 int compressed;
421
422 volatile int grabstate;
423 int scanstate;
424
425 int bytes_recvd;
426
427 long bytes_read;
428
429 wait_queue_head_t wq;
430
431 int snapshot;
432};
433
434#define DECOMP_INTERFACE_VER 4
435
436
437struct ov51x_decomp_ops {
438 int (*decomp_400)(unsigned char *, unsigned char *, unsigned char *,
439 int, int, int);
440 int (*decomp_420)(unsigned char *, unsigned char *, unsigned char *,
441 int, int, int);
442 int (*decomp_422)(unsigned char *, unsigned char *, unsigned char *,
443 int, int, int);
444 struct module *owner;
445};
446
447struct usb_ov511 {
448 struct video_device vdev;
449
450
451 struct usb_device *dev;
452
453 int customid;
454 char *desc;
455 unsigned char iface;
456 char usb_path[OV511_USB_PATH_LEN];
457
458
459 int maxwidth;
460 int maxheight;
461 int minwidth;
462 int minheight;
463
464 int brightness;
465 int colour;
466 int contrast;
467 int hue;
468 int whiteness;
469 int exposure;
470 int auto_brt;
471 int auto_gain;
472 int auto_exp;
473 int backlight;
474 int mirror;
475
476 int led_policy;
477
478 struct semaphore lock;
479 int user;
480
481 int streaming;
482 int grabbing;
483
484 int compress;
485 int compress_inited;
486
487 int lightfreq;
488 int bandfilt;
489
490 unsigned char *fbuf;
491 unsigned char *tempfbuf;
492 unsigned char *rawfbuf;
493
494 int sub_flag;
495 int subx;
496 int suby;
497 int subw;
498 int subh;
499
500 int curframe;
501 struct ov511_frame frame[OV511_NUMFRAMES];
502
503 struct ov511_sbuf sbuf[OV511_NUMSBUF];
504
505 wait_queue_head_t wq;
506
507 int snap_enabled;
508
509 int bridge;
510 int bclass;
511 int sensor;
512
513 int packet_size;
514 int packet_numbering;
515
516 struct semaphore param_lock;
517
518
519 struct proc_dir_entry *proc_devdir;
520 struct proc_dir_entry *proc_info;
521 struct proc_dir_entry *proc_button;
522 struct proc_dir_entry *proc_control;
523
524
525 int buf_state;
526 struct semaphore buf_lock;
527
528 struct ov51x_decomp_ops *decomp_ops;
529
530
531 int stop_during_set;
532
533 int stopped;
534
535
536 int input;
537 int num_inputs;
538 int norm;
539 int has_decoder;
540 int pal;
541
542
543 struct semaphore i2c_lock;
544 unsigned char primary_i2c_slave;
545
546
547 unsigned char *cbuf;
548 struct semaphore cbuf_lock;
549};
550
551
552struct symbolic_list {
553 int num;
554 char *name;
555};
556
557#define NOT_DEFINED_STR "Unknown"
558
559
560
561
562static inline char *
563symbolic(struct symbolic_list list[], int num)
564{
565 int i;
566
567 for (i = 0; list[i].name != NULL; i++)
568 if (list[i].num == num)
569 return (list[i].name);
570
571 return (NOT_DEFINED_STR);
572}
573
574
575
576#define OV511_QUANTABLESIZE 64
577#define OV518_QUANTABLESIZE 32
578
579#define OV511_YQUANTABLE { \
580 0, 1, 1, 2, 2, 3, 3, 4, \
581 1, 1, 1, 2, 2, 3, 4, 4, \
582 1, 1, 2, 2, 3, 4, 4, 4, \
583 2, 2, 2, 3, 4, 4, 4, 4, \
584 2, 2, 3, 4, 4, 5, 5, 5, \
585 3, 3, 4, 4, 5, 5, 5, 5, \
586 3, 4, 4, 4, 5, 5, 5, 5, \
587 4, 4, 4, 4, 5, 5, 5, 5 \
588}
589
590#define OV511_UVQUANTABLE { \
591 0, 2, 2, 3, 4, 4, 4, 4, \
592 2, 2, 2, 4, 4, 4, 4, 4, \
593 2, 2, 3, 4, 4, 4, 4, 4, \
594 3, 4, 4, 4, 4, 4, 4, 4, \
595 4, 4, 4, 4, 4, 4, 4, 4, \
596 4, 4, 4, 4, 4, 4, 4, 4, \
597 4, 4, 4, 4, 4, 4, 4, 4, \
598 4, 4, 4, 4, 4, 4, 4, 4 \
599}
600
601#define OV518_YQUANTABLE { \
602 5, 4, 5, 6, 6, 7, 7, 7, \
603 5, 5, 5, 5, 6, 7, 7, 7, \
604 6, 6, 6, 6, 7, 7, 7, 8, \
605 7, 7, 6, 7, 7, 7, 8, 8 \
606}
607
608#define OV518_UVQUANTABLE { \
609 6, 6, 6, 7, 7, 7, 7, 7, \
610 6, 6, 6, 7, 7, 7, 7, 7, \
611 6, 6, 6, 7, 7, 7, 7, 8, \
612 7, 7, 7, 7, 7, 7, 8, 8 \
613}
614
615#endif
616