linux-old/drivers/usb/pwc.h
<<
>>
Prefs
   1/* (C) 1999-2003 Nemosoft Unv. (webcam@smcc.demon.nl)
   2
   3   This program is free software; you can redistribute it and/or modify
   4   it under the terms of the GNU General Public License as published by
   5   the Free Software Foundation; either version 2 of the License, or
   6   (at your option) any later version.
   7
   8   This program is distributed in the hope that it will be useful,
   9   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11   GNU General Public License for more details.
  12
  13   You should have received a copy of the GNU General Public License
  14   along with this program; if not, write to the Free Software
  15   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  16*/
  17
  18#ifndef PWC_H
  19#define PWC_H
  20
  21#include <linux/config.h>
  22#include <linux/module.h>
  23#include <linux/usb.h>
  24#include <linux/spinlock.h>
  25#include <linux/videodev.h>
  26#include <linux/wait.h>
  27#include <linux/smp_lock.h>
  28
  29#include <asm/semaphore.h>
  30#include <asm/errno.h>
  31
  32/* Defines and structures for the Philips webcam */
  33/* Used for checking memory corruption/pointer validation */
  34#define PWC_MAGIC 0x89DC10ABUL
  35#undef PWC_MAGIC
  36
  37/* Turn some debugging options on/off */
  38#define PWC_DEBUG 0
  39
  40/* Trace certain actions in the driver */
  41#define TRACE_MODULE    0x0001
  42#define TRACE_PROBE     0x0002
  43#define TRACE_OPEN      0x0004
  44#define TRACE_READ      0x0008
  45#define TRACE_MEMORY    0x0010
  46#define TRACE_FLOW      0x0020
  47#define TRACE_SIZE      0x0040
  48#define TRACE_PWCX      0x0080
  49#define TRACE_SEQUENCE  0x1000
  50
  51#define Trace(R, A...) if (pwc_trace & R) printk(KERN_DEBUG PWC_NAME " " A)
  52#define Debug(A...) printk(KERN_DEBUG PWC_NAME " " A)
  53#define Info(A...)  printk(KERN_INFO  PWC_NAME " " A)
  54#define Err(A...)   printk(KERN_ERR   PWC_NAME " " A)
  55
  56
  57/* Defines for ToUCam cameras */
  58#define TOUCAM_HEADER_SIZE              8
  59#define TOUCAM_TRAILER_SIZE             4
  60
  61/* Version block */
  62#define PWC_MAJOR       8
  63#define PWC_MINOR       11
  64#define PWC_VERSION     "8.11"
  65#define PWC_NAME        "pwc"
  66
  67/* Turn certain features on/off */
  68#define PWC_INT_PIPE 0
  69
  70/* Ignore errors in the first N frames, to allow for startup delays */
  71#define FRAME_LOWMARK 5
  72
  73/* Size and number of buffers for the ISO pipe. */
  74#define MAX_ISO_BUFS            2
  75#define ISO_FRAMES_PER_DESC     10
  76#define ISO_MAX_FRAME_SIZE      960
  77#define ISO_BUFFER_SIZE         (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
  78
  79/* Frame buffers: contains compressed or uncompressed video data. */
  80#define MAX_FRAMES              5
  81/* Maximum size after decompression is 640x480 YUV data, 1.5 * 640 * 480 */
  82#define PWC_FRAME_SIZE          (460800 + TOUCAM_HEADER_SIZE + TOUCAM_TRAILER_SIZE)
  83
  84/* Absolute maximum number of buffers available for mmap() */
  85#define MAX_IMAGES              10
  86
  87struct pwc_coord
  88{
  89        int x, y;               /* guess what */
  90        int size;               /* size, or offset */
  91};
  92
  93/* The following structures were based on cpia.h. Why reinvent the wheel? :-) */
  94struct pwc_iso_buf
  95{
  96        void *data;
  97        int  length;
  98        int  read;
  99        struct urb *urb;
 100};
 101
 102/* intermediate buffers with raw data from the USB cam */
 103struct pwc_frame_buf
 104{
 105   void *data;
 106   volatile int filled;         /* number of bytes filled */
 107   struct pwc_frame_buf *next;  /* list */
 108#if PWC_DEBUG
 109   int sequence;                /* Sequence number */
 110#endif
 111};
 112
 113struct pwc_device
 114{
 115   struct video_device vdev;
 116#ifdef PWC_MAGIC
 117   int magic;
 118#endif
 119   /* Pointer to our usb_device */
 120   struct usb_device *udev;
 121   
 122   int type;                    /* type of cam (645, 646, 675, 680, 690) */
 123   int release;                 /* release number */
 124   int error_status;            /* set when something goes wrong with the cam (unplugged, USB errors) */
 125   int usb_init;                /* set when the cam has been initialized over USB */
 126
 127   /*** Video data ***/
 128   int vopen;                   /* flag */
 129   int vendpoint;               /* video isoc endpoint */
 130   int vcinterface;             /* video control interface */
 131   int valternate;              /* alternate interface needed */
 132   int vframes, vsize;          /* frames-per-second & size (see PSZ_*) */
 133   int vframe_count;            /* received frames */
 134   int vframes_dumped;          /* counter for dumped frames */
 135   int vframes_error;           /* frames received in error */
 136   int vmax_packet_size;        /* USB maxpacket size */
 137   int vlast_packet_size;       /* for frame synchronisation */
 138   int visoc_errors;            /* number of contiguous ISOC errors */
 139   int vcompression;            /* desired compression factor */
 140   int vbandlength;             /* compressed band length; 0 is uncompressed */
 141   char vsnapshot;              /* snapshot mode */
 142   char vsync;                  /* used by isoc handler */
 143   char vmirror;                /* for ToUCaM series */
 144
 145   /* The image acquisition requires 3 to 4 steps:
 146      1. data is gathered in short packets from the USB controller
 147      2. data is synchronized and packed into a frame buffer
 148      3a. in case data is compressed, decompress it directly into image buffer
 149      3b. in case data is uncompressed, copy into image buffer with viewport
 150      4. data is transferred to the user process
 151
 152      Note that MAX_ISO_BUFS != MAX_FRAMES != MAX_IMAGES....
 153      We have in effect a back-to-back-double-buffer system.
 154    */
 155   /* 1: isoc */
 156   struct pwc_iso_buf sbuf[MAX_ISO_BUFS];
 157   char iso_init;
 158
 159   /* 2: frame */
 160   struct pwc_frame_buf *fbuf;  /* all frames */
 161   struct pwc_frame_buf *empty_frames, *empty_frames_tail;      /* all empty frames */
 162   struct pwc_frame_buf *full_frames, *full_frames_tail;        /* all filled frames */
 163   struct pwc_frame_buf *fill_frame;    /* frame currently being filled */
 164   struct pwc_frame_buf *read_frame;    /* frame currently read by user process */
 165   int frame_size;
 166   int frame_header_size, frame_trailer_size;
 167   int drop_frames;
 168#if PWC_DEBUG
 169   int sequence;                        /* Debugging aid */
 170#endif
 171
 172   /* 3: decompression */
 173   struct pwc_decompressor *decompressor;       /* function block with decompression routines */
 174   void *decompress_data;               /* private data for decompression engine */
 175
 176   /* 4: image */
 177   /* We have an 'image' and a 'view', where 'image' is the fixed-size image
 178      as delivered by the camera, and 'view' is the size requested by the
 179      program. The camera image is centered in this viewport, laced with
 180      a gray or black border. view_min <= image <= view <= view_max;
 181    */
 182   int image_mask;                      /* bitmask of supported sizes */
 183   struct pwc_coord view_min, view_max; /* minimum and maximum sizes */
 184   struct pwc_coord image, view;        /* image and viewport size */
 185   struct pwc_coord offset;             /* offset within the viewport */
 186
 187   void *image_data;                    /* total buffer, which is subdivided into ... */
 188   void *image_ptr[MAX_IMAGES];         /* ...several images... */
 189   int fill_image;                      /* ...which are rotated. */
 190   int len_per_image;                   /* length per image */
 191   int image_read_pos;                  /* In case we read data in pieces, keep track of were we are in the imagebuffer */
 192   int image_used[MAX_IMAGES];          /* For MCAPTURE and SYNC */
 193
 194   struct semaphore modlock;            /* to prevent races in video_open(), etc */
 195   spinlock_t ptrlock;                  /* for manipulating the buffer pointers */
 196
 197   /*** Misc. data ***/
 198   wait_queue_head_t frameq;            /* When waiting for a frame to finish... */
 199#if PWC_INT_PIPE
 200   void *usb_int_handler;               /* for the interrupt endpoint */
 201#endif
 202};
 203
 204/* Enumeration of image sizes */
 205#define PSZ_SQCIF       0x00
 206#define PSZ_QSIF        0x01
 207#define PSZ_QCIF        0x02
 208#define PSZ_SIF         0x03
 209#define PSZ_CIF         0x04
 210#define PSZ_VGA         0x05
 211#define PSZ_MAX         6
 212
 213
 214
 215#ifdef __cplusplus
 216extern "C" {
 217#endif
 218
 219/* Global variables */
 220extern int pwc_trace;
 221extern int pwc_preferred_compression;
 222
 223/** functions in pwc-if.c */
 224int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_fps, int new_compression, int new_snapshot);
 225
 226/** Functions in pwc-misc.c */
 227/* sizes in pixels */
 228extern struct pwc_coord pwc_image_sizes[PSZ_MAX];
 229
 230int pwc_decode_size(struct pwc_device *pdev, int width, int height);
 231void pwc_construct(struct pwc_device *pdev);
 232
 233/** Functions in pwc-ctrl.c */
 234/* Request a certain video mode. Returns < 0 if not possible */
 235extern int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot);
 236/* Calculate the number of bytes per image (not frame) */
 237extern void pwc_set_image_buffer_size(struct pwc_device *pdev);
 238
 239/* Various controls; should be obvious. Value 0..65535, or < 0 on error */
 240extern int pwc_get_brightness(struct pwc_device *pdev);
 241extern int pwc_set_brightness(struct pwc_device *pdev, int value);
 242extern int pwc_get_contrast(struct pwc_device *pdev);
 243extern int pwc_set_contrast(struct pwc_device *pdev, int value);
 244extern int pwc_get_gamma(struct pwc_device *pdev);
 245extern int pwc_set_gamma(struct pwc_device *pdev, int value);
 246extern int pwc_get_saturation(struct pwc_device *pdev);
 247extern int pwc_set_saturation(struct pwc_device *pdev, int value);
 248extern int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value);
 249extern int pwc_get_leds(struct pwc_device *pdev, int *on_value, int *off_value);
 250extern int pwc_get_cmos_sensor(struct pwc_device *pdev);
 251
 252/* Power down or up the camera; not supported by all models */
 253extern int pwc_camera_power(struct pwc_device *pdev, int power);
 254
 255/* Private ioctl()s; see pwc-ioctl.h */
 256extern int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg);
 257
 258
 259/** pwc-uncompress.c */
 260/* Expand frame to image, possibly including decompression. Uses read_frame and fill_image */
 261extern int pwc_decompress(struct pwc_device *pdev);
 262
 263#ifdef __cplusplus
 264}
 265#endif
 266
 267
 268#endif
 269
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.