linux/drivers/media/video/ov511.h
<<
>>
Prefs
   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     /* Turn on debug messages */
  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/* This macro restricts an int variable to an inclusive range */
  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/* DEFINES FOR OV511 AND OTHER CHIPS */
  30/* --------------------------------- */
  31
  32/* USB IDs */
  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/*     OV51x REGISTER MNEMONICS      */
  44/* --------------------------------- */
  45
  46/* Camera interface register numbers */
  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/* Snapshot mode camera interface register numbers */
  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/* DRAM register numbers */
  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/* ISO FIFO register numbers */
  73#define R51x_FIFO_PSIZE         0x30    /* 2 bytes wide w/ OV518(+) */
  74#define R511_FIFO_OPTS          0x31
  75
  76/* Parallel IO register numbers */
  77#define R511_PIO_OPTS           0x38
  78#define R511_PIO_DATA           0x39
  79#define R511_PIO_BIST           0x3E
  80#define R518_GPIO_IN            0x55    /* OV518(+) only */
  81#define R518_GPIO_OUT           0x56    /* OV518(+) only */
  82#define R518_GPIO_CTL           0x57    /* OV518(+) only */
  83#define R518_GPIO_PULSE_IN      0x58    /* OV518(+) only */
  84#define R518_GPIO_PULSE_CLEAR   0x59    /* OV518(+) only */
  85#define R518_GPIO_PULSE_POL     0x5a    /* OV518(+) only */
  86#define R518_GPIO_PULSE_EN      0x5b    /* OV518(+) only */
  87#define R518_GPIO_RESET         0x5c    /* OV518(+) only */
  88
  89/* I2C registers */
  90#define R511_I2C_CTL            0x40
  91#define R518_I2C_CTL            0x47    /* OV518(+) only */
  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/* I2C snapshot registers */
 101#define R511_SI2C_SADDR_3       0x48
 102#define R511_SI2C_DATA          0x49
 103
 104/* System control registers */
 105#define R51x_SYS_RESET          0x50
 106                /* Reset type definitions */
 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 /* All but OV511 & regs */
 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 /* OV511+/OV518(+) only */
 121#define R511_SYS_LED_CTL        0x55 /* OV511+ only */
 122#define R511_SYS_USER           0x5E
 123#define R511_SYS_CUST_ID        0x5F
 124
 125/* OmniCE (compression) registers */
 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/*         ALTERNATE NUMBERS         */
 140/* --------------------------------- */
 141
 142/* Alternate numbers for various max packet sizes (OV511 only) */
 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/* Alternate numbers for various max packet sizes (OV511+ only) */
 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/* Alternate numbers for various max packet sizes (OV518(+) only) */
 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/*     OV7610 REGISTER MNEMONICS     */
 174/* --------------------------------- */
 175
 176/* OV7610 registers */
 177#define OV7610_REG_GAIN          0x00   /* gain setting (5:0) */
 178#define OV7610_REG_BLUE          0x01   /* blue channel balance */
 179#define OV7610_REG_RED           0x02   /* red channel balance */
 180#define OV7610_REG_SAT           0x03   /* saturation */
 181                                        /* 04 reserved */
 182#define OV7610_REG_CNT           0x05   /* Y contrast */
 183#define OV7610_REG_BRT           0x06   /* Y brightness */
 184                                        /* 08-0b reserved */
 185#define OV7610_REG_BLUE_BIAS     0x0C   /* blue channel bias (5:0) */
 186#define OV7610_REG_RED_BIAS      0x0D   /* read channel bias (5:0) */
 187#define OV7610_REG_GAMMA_COEFF   0x0E   /* gamma settings */
 188#define OV7610_REG_WB_RANGE      0x0F   /* AEC/ALC/S-AWB settings */
 189#define OV7610_REG_EXP           0x10   /* manual exposure setting */
 190#define OV7610_REG_CLOCK         0x11   /* polarity/clock prescaler */
 191#define OV7610_REG_COM_A         0x12   /* misc common regs */
 192#define OV7610_REG_COM_B         0x13   /* misc common regs */
 193#define OV7610_REG_COM_C         0x14   /* misc common regs */
 194#define OV7610_REG_COM_D         0x15   /* misc common regs */
 195#define OV7610_REG_FIELD_DIVIDE  0x16   /* field interval/mode settings */
 196#define OV7610_REG_HWIN_START    0x17   /* horizontal window start */
 197#define OV7610_REG_HWIN_END      0x18   /* horizontal window end */
 198#define OV7610_REG_VWIN_START    0x19   /* vertical window start */
 199#define OV7610_REG_VWIN_END      0x1A   /* vertical window end */
 200#define OV7610_REG_PIXEL_SHIFT   0x1B   /* pixel shift */
 201#define OV7610_REG_ID_HIGH       0x1C   /* manufacturer ID MSB */
 202#define OV7610_REG_ID_LOW        0x1D   /* manufacturer ID LSB */
 203                                        /* 0e-0f reserved */
 204#define OV7610_REG_COM_E         0x20   /* misc common regs */
 205#define OV7610_REG_YOFFSET       0x21   /* Y channel offset */
 206#define OV7610_REG_UOFFSET       0x22   /* U channel offset */
 207                                        /* 23 reserved */
 208#define OV7610_REG_ECW           0x24   /* Exposure white level for AEC */
 209#define OV7610_REG_ECB           0x25   /* Exposure black level for AEC */
 210#define OV7610_REG_COM_F         0x26   /* misc settings */
 211#define OV7610_REG_COM_G         0x27   /* misc settings */
 212#define OV7610_REG_COM_H         0x28   /* misc settings */
 213#define OV7610_REG_COM_I         0x29   /* misc settings */
 214#define OV7610_REG_FRAMERATE_H   0x2A   /* frame rate MSB + misc */
 215#define OV7610_REG_FRAMERATE_L   0x2B   /* frame rate LSB */
 216#define OV7610_REG_ALC           0x2C   /* Auto Level Control settings */
 217#define OV7610_REG_COM_J         0x2D   /* misc settings */
 218#define OV7610_REG_VOFFSET       0x2E   /* V channel offset adjustment */
 219#define OV7610_REG_ARRAY_BIAS    0x2F   /* Array bias -- don't change */
 220                                        /* 30-32 reserved */
 221#define OV7610_REG_YGAMMA        0x33   /* misc gamma settings (7:6) */
 222#define OV7610_REG_BIAS_ADJUST   0x34   /* misc bias settings */
 223#define OV7610_REG_COM_L         0x35   /* misc settings */
 224                                        /* 36-37 reserved */
 225#define OV7610_REG_COM_K         0x38   /* misc registers */
 226
 227/* --------------------------------- */
 228/*           I2C ADDRESSES           */
 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/*       MISCELLANEOUS DEFINES       */
 239/* --------------------------------- */
 240
 241#define I2C_CLOCK_PRESCALER     0x03
 242
 243#define FRAMES_PER_DESC         10      /* FIXME - What should this be? */
 244#define MAX_FRAME_SIZE_PER_DESC 993     /* For statically allocated stuff */
 245#define PIXELS_PER_SEG          256     /* Pixels per segment */
 246
 247#define OV511_ENDPOINT_ADDRESS  1       /* Isoc endpoint number */
 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/* Control transfers use up to 4 bytes */
 257#define OV511_CBUF_SIZE         4
 258
 259/* Size of usb_make_path() buffer */
 260#define OV511_USB_PATH_LEN      64
 261
 262/* Bridge types */
 263enum {
 264        BRG_UNKNOWN,
 265        BRG_OV511,
 266        BRG_OV511PLUS,
 267        BRG_OV518,
 268        BRG_OV518PLUS,
 269};
 270
 271/* Bridge classes */
 272enum {
 273        BCL_UNKNOWN,
 274        BCL_OV511,
 275        BCL_OV518,
 276};
 277
 278/* Sensor types */
 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,         /* Scanning for start */
 297        STATE_HEADER,           /* Parsing header */
 298        STATE_LINES,            /* Parsing lines */
 299};
 300
 301/* Buffer states */
 302enum {
 303        BUF_NOT_ALLOCATED,
 304        BUF_ALLOCATED,
 305};
 306
 307/* --------- Definition of ioctl interface --------- */
 308
 309#define OV511_INTERFACE_VER 101
 310
 311/* LED options */
 312enum {
 313        LED_OFF,
 314        LED_ON,
 315        LED_AUTO,
 316};
 317
 318/* Raw frame formats */
 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; /* Write slave ID (read ID - 1) */
 329        unsigned char reg;   /* Index of register */
 330        unsigned char value; /* User sets this w/ write, driver does w/ read */
 331        unsigned char mask;  /* Bits to be changed. Not used with read ops */
 332};
 333
 334/* ioctls */
 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/* ------------- End IOCTL interface -------------- */
 340
 341struct usb_ov511;               /* Forward declaration */
 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,           /* Unused (no MCAPTURE) */
 353        FRAME_READY,            /* Ready to start grabbing */
 354        FRAME_GRABBING,         /* In the process of being grabbed into */
 355        FRAME_DONE,             /* Finished grabbing, but not been synced yet */
 356        FRAME_ERROR,            /* Something bad happened while processing */
 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;           /* Index of this frame */
 371        unsigned char *data;    /* Frame buffer */
 372        unsigned char *tempdata; /* Temp buffer for multi-stage conversions */
 373        unsigned char *rawdata; /* Raw camera data buffer */
 374        unsigned char *compbuf; /* Temp buffer for decompressor */
 375
 376        int depth;              /* Bytes per pixel */
 377        int width;              /* Width application is expecting */
 378        int height;             /* Height application is expecting */
 379
 380        int rawwidth;           /* Actual width of frame sent from camera */
 381        int rawheight;          /* Actual height of frame sent from camera */
 382
 383        int sub_flag;           /* Sub-capture mode for this frame? */
 384        unsigned int format;    /* Format for this frame */
 385        int compressed;         /* Is frame compressed? */
 386
 387        volatile int grabstate; /* State of grabbing */
 388        int scanstate;          /* State of scanning */
 389
 390        int bytes_recvd;        /* Number of image bytes received from camera */
 391
 392        long bytes_read;        /* Amount that has been read() */
 393
 394        wait_queue_head_t wq;   /* Processes waiting */
 395
 396        int snapshot;           /* True if frame was a snapshot */
 397};
 398
 399#define DECOMP_INTERFACE_VER 4
 400
 401/* Compression module operations */
 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        /* Determined by sensor type */
 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;           /* Auto brightness enabled flag */
 434        int auto_gain;          /* Auto gain control enabled flag */
 435        int auto_exp;           /* Auto exposure enabled flag */
 436        int backlight;          /* Backlight exposure algorithm flag */
 437        int mirror;             /* Image is reversed horizontally */
 438
 439        int led_policy;         /* LED: off|on|auto; OV511+ only */
 440
 441        struct mutex lock;      /* Serializes user-accessible operations */
 442        int user;               /* user count for exclusive use */
 443
 444        int streaming;          /* Are we streaming Isochronous? */
 445        int grabbing;           /* Are we grabbing? */
 446
 447        int compress;           /* Should the next frame be compressed? */
 448        int compress_inited;    /* Are compression params uploaded? */
 449
 450        int lightfreq;          /* Power (lighting) frequency */
 451        int bandfilt;           /* Banding filter enabled flag */
 452
 453        unsigned char *fbuf;    /* Videodev buffer area */
 454        unsigned char *tempfbuf; /* Temporary (intermediate) buffer area */
 455        unsigned char *rawfbuf; /* Raw camera data buffer area */
 456
 457        int sub_flag;           /* Pix Array subcapture on flag */
 458        int subx;               /* Pix Array subcapture x offset */
 459        int suby;               /* Pix Array subcapture y offset */
 460        int subw;               /* Pix Array subcapture width */
 461        int subh;               /* Pix Array subcapture height */
 462
 463        int curframe;           /* Current receiving sbuf */
 464        struct ov511_frame frame[OV511_NUMFRAMES];
 465
 466        struct ov511_sbuf sbuf[OV511_NUMSBUF];
 467
 468        wait_queue_head_t wq;   /* Processes waiting */
 469
 470        int snap_enabled;       /* Snapshot mode enabled */
 471
 472        int bridge;             /* Type of bridge (BRG_*) */
 473        int bclass;             /* Class of bridge (BCL_*) */
 474        int sensor;             /* Type of image sensor chip (SEN_*) */
 475
 476        int packet_size;        /* Frame size per isoc desc */
 477        int packet_numbering;   /* Is ISO frame numbering enabled? */
 478
 479        /* Framebuffer/sbuf management */
 480        int buf_state;
 481        struct mutex buf_lock;
 482
 483        struct ov51x_decomp_ops *decomp_ops;
 484
 485        /* Stop streaming while changing picture settings */
 486        int stop_during_set;
 487
 488        int stopped;            /* Streaming is temporarily paused */
 489
 490        /* Video decoder stuff */
 491        int input;              /* Composite, S-VIDEO, etc... */
 492        int num_inputs;         /* Number of inputs */
 493        int norm;               /* NTSC / PAL / SECAM */
 494        int has_decoder;        /* Device has a video decoder */
 495        int pal;                /* Device is designed for PAL resolution */
 496
 497        /* ov511 device number ID */
 498        int nr;                 /* Stores a device number */
 499
 500        /* I2C interface */
 501        struct mutex i2c_lock;    /* Protect I2C controller regs */
 502        unsigned char primary_i2c_slave;  /* I2C write id of sensor */
 503
 504        /* Control transaction stuff */
 505        unsigned char *cbuf;            /* Buffer for payload */
 506        struct mutex cbuf_lock;
 507};
 508
 509/* Used to represent a list of values and their respective symbolic names */
 510struct symbolic_list {
 511        int num;
 512        char *name;
 513};
 514
 515#define NOT_DEFINED_STR "Unknown"
 516
 517/* Returns the name of the matching element in the symbolic_list array. The
 518 * end of the list must be marked with an element that has a NULL name.
 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/* Compression stuff */
 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