aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/cpia.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/media/video/cpia.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/media/video/cpia.h')
-rw-r--r--drivers/media/video/cpia.h430
1 files changed, 430 insertions, 0 deletions
diff --git a/drivers/media/video/cpia.h b/drivers/media/video/cpia.h
new file mode 100644
index 000000000000..f629b693ee65
--- /dev/null
+++ b/drivers/media/video/cpia.h
@@ -0,0 +1,430 @@
1#ifndef cpia_h
2#define cpia_h
3
4/*
5 * CPiA Parallel Port Video4Linux driver
6 *
7 * Supports CPiA based parallel port Video Camera's.
8 *
9 * (C) Copyright 1999 Bas Huisman,
10 * Peter Pregler,
11 * Scott J. Bertin,
12 * VLSI Vision Ltd.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29#define CPIA_MAJ_VER 1
30#define CPIA_MIN_VER 2
31#define CPIA_PATCH_VER 3
32
33#define CPIA_PP_MAJ_VER CPIA_MAJ_VER
34#define CPIA_PP_MIN_VER CPIA_MIN_VER
35#define CPIA_PP_PATCH_VER CPIA_PATCH_VER
36
37#define CPIA_USB_MAJ_VER CPIA_MAJ_VER
38#define CPIA_USB_MIN_VER CPIA_MIN_VER
39#define CPIA_USB_PATCH_VER CPIA_PATCH_VER
40
41#define CPIA_MAX_FRAME_SIZE_UNALIGNED (352 * 288 * 4) /* CIF at RGB32 */
42#define CPIA_MAX_FRAME_SIZE ((CPIA_MAX_FRAME_SIZE_UNALIGNED + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) /* align above to PAGE_SIZE */
43
44#ifdef __KERNEL__
45
46#include <asm/uaccess.h>
47#include <linux/videodev.h>
48#include <linux/list.h>
49#include <linux/smp_lock.h>
50
51struct cpia_camera_ops
52{
53 /* open sets privdata to point to structure for this camera.
54 * Returns negative value on error, otherwise 0.
55 */
56 int (*open)(void *privdata);
57
58 /* Registers callback function cb to be called with cbdata
59 * when an image is ready. If cb is NULL, only single image grabs
60 * should be used. cb should immediately call streamRead to read
61 * the data or data may be lost. Returns negative value on error,
62 * otherwise 0.
63 */
64 int (*registerCallback)(void *privdata, void (*cb)(void *cbdata),
65 void *cbdata);
66
67 /* transferCmd sends commands to the camera. command MUST point to
68 * an 8 byte buffer in kernel space. data can be NULL if no extra
69 * data is needed. The size of the data is given by the last 2
70 * bytes of command. data must also point to memory in kernel space.
71 * Returns negative value on error, otherwise 0.
72 */
73 int (*transferCmd)(void *privdata, u8 *command, u8 *data);
74
75 /* streamStart initiates stream capture mode.
76 * Returns negative value on error, otherwise 0.
77 */
78 int (*streamStart)(void *privdata);
79
80 /* streamStop terminates stream capture mode.
81 * Returns negative value on error, otherwise 0.
82 */
83 int (*streamStop)(void *privdata);
84
85 /* streamRead reads a frame from the camera. buffer points to a
86 * buffer large enough to hold a complete frame in kernel space.
87 * noblock indicates if this should be a non blocking read.
88 * Returns the number of bytes read, or negative value on error.
89 */
90 int (*streamRead)(void *privdata, u8 *buffer, int noblock);
91
92 /* close disables the device until open() is called again.
93 * Returns negative value on error, otherwise 0.
94 */
95 int (*close)(void *privdata);
96
97 /* If wait_for_stream_ready is non-zero, wait until the streamState
98 * is STREAM_READY before calling streamRead.
99 */
100 int wait_for_stream_ready;
101
102 /*
103 * Used to maintain lowlevel module usage counts
104 */
105 struct module *owner;
106};
107
108struct cpia_frame {
109 u8 *data;
110 int count;
111 int width;
112 int height;
113 volatile int state;
114};
115
116struct cam_params {
117 struct {
118 u8 firmwareVersion;
119 u8 firmwareRevision;
120 u8 vcVersion;
121 u8 vcRevision;
122 } version;
123 struct {
124 u16 vendor;
125 u16 product;
126 u16 deviceRevision;
127 } pnpID;
128 struct {
129 u8 vpVersion;
130 u8 vpRevision;
131 u16 cameraHeadID;
132 } vpVersion;
133 struct {
134 u8 systemState;
135 u8 grabState;
136 u8 streamState;
137 u8 fatalError;
138 u8 cmdError;
139 u8 debugFlags;
140 u8 vpStatus;
141 u8 errorCode;
142 } status;
143 struct {
144 u8 brightness;
145 u8 contrast;
146 u8 saturation;
147 } colourParams;
148 struct {
149 u8 gainMode;
150 u8 expMode;
151 u8 compMode;
152 u8 centreWeight;
153 u8 gain;
154 u8 fineExp;
155 u8 coarseExpLo;
156 u8 coarseExpHi;
157 u8 redComp;
158 u8 green1Comp;
159 u8 green2Comp;
160 u8 blueComp;
161 } exposure;
162 struct {
163 u8 balanceMode;
164 u8 redGain;
165 u8 greenGain;
166 u8 blueGain;
167 } colourBalance;
168 struct {
169 u8 divisor;
170 u8 baserate;
171 } sensorFps;
172 struct {
173 u8 gain1;
174 u8 gain2;
175 u8 gain4;
176 u8 gain8;
177 } apcor;
178 struct {
179 u8 disabled;
180 u8 flickerMode;
181 u8 coarseJump;
182 int allowableOverExposure;
183 } flickerControl;
184 struct {
185 u8 gain1;
186 u8 gain2;
187 u8 gain4;
188 u8 gain8;
189 } vlOffset;
190 struct {
191 u8 mode;
192 u8 decimation;
193 } compression;
194 struct {
195 u8 frTargeting;
196 u8 targetFR;
197 u8 targetQ;
198 } compressionTarget;
199 struct {
200 u8 yThreshold;
201 u8 uvThreshold;
202 } yuvThreshold;
203 struct {
204 u8 hysteresis;
205 u8 threshMax;
206 u8 smallStep;
207 u8 largeStep;
208 u8 decimationHysteresis;
209 u8 frDiffStepThresh;
210 u8 qDiffStepThresh;
211 u8 decimationThreshMod;
212 } compressionParams;
213 struct {
214 u8 videoSize; /* CIF/QCIF */
215 u8 subSample;
216 u8 yuvOrder;
217 } format;
218 struct { /* Intel QX3 specific data */
219 u8 qx3_detected; /* a QX3 is present */
220 u8 toplight; /* top light lit , R/W */
221 u8 bottomlight; /* bottom light lit, R/W */
222 u8 button; /* snapshot button pressed (R/O) */
223 u8 cradled; /* microscope is in cradle (R/O) */
224 } qx3;
225 struct {
226 u8 colStart; /* skip first 8*colStart pixels */
227 u8 colEnd; /* finish at 8*colEnd pixels */
228 u8 rowStart; /* skip first 4*rowStart lines */
229 u8 rowEnd; /* finish at 4*rowEnd lines */
230 } roi;
231 u8 ecpTiming;
232 u8 streamStartLine;
233};
234
235enum v4l_camstates {
236 CPIA_V4L_IDLE = 0,
237 CPIA_V4L_ERROR,
238 CPIA_V4L_COMMAND,
239 CPIA_V4L_GRABBING,
240 CPIA_V4L_STREAMING,
241 CPIA_V4L_STREAMING_PAUSED,
242};
243
244#define FRAME_NUM 2 /* double buffering for now */
245
246struct cam_data {
247 struct list_head cam_data_list;
248
249 struct semaphore busy_lock; /* guard against SMP multithreading */
250 struct cpia_camera_ops *ops; /* lowlevel driver operations */
251 void *lowlevel_data; /* private data for lowlevel driver */
252 u8 *raw_image; /* buffer for raw image data */
253 struct cpia_frame decompressed_frame;
254 /* buffer to hold decompressed frame */
255 int image_size; /* sizeof last decompressed image */
256 int open_count; /* # of process that have camera open */
257
258 /* camera status */
259 int fps; /* actual fps reported by the camera */
260 int transfer_rate; /* transfer rate from camera in kB/s */
261 u8 mainsFreq; /* for flicker control */
262
263 /* proc interface */
264 struct semaphore param_lock; /* params lock for this camera */
265 struct cam_params params; /* camera settings */
266 struct proc_dir_entry *proc_entry; /* /proc/cpia/videoX */
267
268 /* v4l */
269 int video_size; /* VIDEO_SIZE_ */
270 volatile enum v4l_camstates camstate; /* v4l layer status */
271 struct video_device vdev; /* v4l videodev */
272 struct video_picture vp; /* v4l camera settings */
273 struct video_window vw; /* v4l capture area */
274 struct video_capture vc; /* v4l subcapture area */
275
276 /* mmap interface */
277 int curframe; /* the current frame to grab into */
278 u8 *frame_buf; /* frame buffer data */
279 struct cpia_frame frame[FRAME_NUM];
280 /* FRAME_NUM-buffering, so we need a array */
281
282 int first_frame;
283 int mmap_kludge; /* 'wrong' byte order for mmap */
284 volatile u32 cmd_queue; /* queued commands */
285 int exposure_status; /* EXPOSURE_* */
286 int exposure_count; /* number of frames at this status */
287};
288
289/* cpia_register_camera is called by low level driver for each camera.
290 * A unique camera number is returned, or a negative value on error */
291struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel);
292
293/* cpia_unregister_camera is called by low level driver when a camera
294 * is removed. This must not fail. */
295void cpia_unregister_camera(struct cam_data *cam);
296
297/* raw CIF + 64 byte header + (2 bytes line_length + EOL) per line + 4*EOI +
298 * one byte 16bit DMA alignment
299 */
300#define CPIA_MAX_IMAGE_SIZE ((352*288*2)+64+(288*3)+5)
301
302/* constant value's */
303#define MAGIC_0 0x19
304#define MAGIC_1 0x68
305#define DATA_IN 0xC0
306#define DATA_OUT 0x40
307#define VIDEOSIZE_QCIF 0 /* 176x144 */
308#define VIDEOSIZE_CIF 1 /* 352x288 */
309#define VIDEOSIZE_SIF 2 /* 320x240 */
310#define VIDEOSIZE_QSIF 3 /* 160x120 */
311#define VIDEOSIZE_48_48 4 /* where no one has gone before, iconsize! */
312#define VIDEOSIZE_64_48 5
313#define VIDEOSIZE_128_96 6
314#define VIDEOSIZE_160_120 VIDEOSIZE_QSIF
315#define VIDEOSIZE_176_144 VIDEOSIZE_QCIF
316#define VIDEOSIZE_192_144 7
317#define VIDEOSIZE_224_168 8
318#define VIDEOSIZE_256_192 9
319#define VIDEOSIZE_288_216 10
320#define VIDEOSIZE_320_240 VIDEOSIZE_SIF
321#define VIDEOSIZE_352_288 VIDEOSIZE_CIF
322#define VIDEOSIZE_88_72 11 /* quarter CIF */
323#define SUBSAMPLE_420 0
324#define SUBSAMPLE_422 1
325#define YUVORDER_YUYV 0
326#define YUVORDER_UYVY 1
327#define NOT_COMPRESSED 0
328#define COMPRESSED 1
329#define NO_DECIMATION 0
330#define DECIMATION_ENAB 1
331#define EOI 0xff /* End Of Image */
332#define EOL 0xfd /* End Of Line */
333#define FRAME_HEADER_SIZE 64
334
335/* Image grab modes */
336#define CPIA_GRAB_SINGLE 0
337#define CPIA_GRAB_CONTINUOUS 1
338
339/* Compression parameters */
340#define CPIA_COMPRESSION_NONE 0
341#define CPIA_COMPRESSION_AUTO 1
342#define CPIA_COMPRESSION_MANUAL 2
343#define CPIA_COMPRESSION_TARGET_QUALITY 0
344#define CPIA_COMPRESSION_TARGET_FRAMERATE 1
345
346/* Return offsets for GetCameraState */
347#define SYSTEMSTATE 0
348#define GRABSTATE 1
349#define STREAMSTATE 2
350#define FATALERROR 3
351#define CMDERROR 4
352#define DEBUGFLAGS 5
353#define VPSTATUS 6
354#define ERRORCODE 7
355
356/* SystemState */
357#define UNINITIALISED_STATE 0
358#define PASS_THROUGH_STATE 1
359#define LO_POWER_STATE 2
360#define HI_POWER_STATE 3
361#define WARM_BOOT_STATE 4
362
363/* GrabState */
364#define GRAB_IDLE 0
365#define GRAB_ACTIVE 1
366#define GRAB_DONE 2
367
368/* StreamState */
369#define STREAM_NOT_READY 0
370#define STREAM_READY 1
371#define STREAM_OPEN 2
372#define STREAM_PAUSED 3
373#define STREAM_FINISHED 4
374
375/* Fatal Error, CmdError, and DebugFlags */
376#define CPIA_FLAG 1
377#define SYSTEM_FLAG 2
378#define INT_CTRL_FLAG 4
379#define PROCESS_FLAG 8
380#define COM_FLAG 16
381#define VP_CTRL_FLAG 32
382#define CAPTURE_FLAG 64
383#define DEBUG_FLAG 128
384
385/* VPStatus */
386#define VP_STATE_OK 0x00
387
388#define VP_STATE_FAILED_VIDEOINIT 0x01
389#define VP_STATE_FAILED_AECACBINIT 0x02
390#define VP_STATE_AEC_MAX 0x04
391#define VP_STATE_ACB_BMAX 0x08
392
393#define VP_STATE_ACB_RMIN 0x10
394#define VP_STATE_ACB_GMIN 0x20
395#define VP_STATE_ACB_RMAX 0x40
396#define VP_STATE_ACB_GMAX 0x80
397
398/* default (minimum) compensation values */
399#define COMP_RED 220
400#define COMP_GREEN1 214
401#define COMP_GREEN2 COMP_GREEN1
402#define COMP_BLUE 230
403
404/* exposure status */
405#define EXPOSURE_VERY_LIGHT 0
406#define EXPOSURE_LIGHT 1
407#define EXPOSURE_NORMAL 2
408#define EXPOSURE_DARK 3
409#define EXPOSURE_VERY_DARK 4
410
411/* ErrorCode */
412#define ERROR_FLICKER_BELOW_MIN_EXP 0x01 /*flicker exposure got below minimum exposure */
413#define ALOG(fmt,args...) printk(fmt, ##args)
414#define LOG(fmt,args...) ALOG(KERN_INFO __FILE__ ":%s(%d):" fmt, __FUNCTION__ , __LINE__ , ##args)
415
416#ifdef _CPIA_DEBUG_
417#define ADBG(fmt,args...) printk(fmt, jiffies, ##args)
418#define DBG(fmt,args...) ADBG(KERN_DEBUG __FILE__" (%ld):%s(%d):" fmt, __FUNCTION__, __LINE__ , ##args)
419#else
420#define DBG(fmn,args...) do {} while(0)
421#endif
422
423#define DEB_BYTE(p)\
424 DBG("%1d %1d %1d %1d %1d %1d %1d %1d \n",\
425 (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\
426 (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0);
427
428#endif /* __KERNEL__ */
429
430#endif /* cpia_h */