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