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