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 0
30 #define CPIA_MIN_VER 7
31 #define CPIA_PATCH_VER 4
32
33 #define CPIA_PP_MAJ_VER 0
34 #define CPIA_PP_MIN_VER 7
35 #define CPIA_PP_PATCH_VER 4
36
37 #define CPIA_MAX_FRAME_SIZE_UNALIGNED (352 * 288 * 4) /* CIF at RGB32 */
38 #define CPIA_MAX_FRAME_SIZE ((CPIA_MAX_FRAME_SIZE_UNALIGNED + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) /* align above to PAGE_SIZE */
39
40 #ifdef __KERNEL__
41
42 #include <asm/uaccess.h>
43 #include <linux/videodev.h>
44 #include <linux/smp_lock.h>
45
46 struct cpia_camera_ops
47 {
48 /* open sets privdata to point to structure for this camera.
49 * Returns negative value on error, otherwise 0.
50 */
51 int (*open)(void *privdata);
52
53 /* Registers callback function cb to be called with cbdata
54 * when an image is ready. If cb is NULL, only single image grabs
55 * should be used. cb should immediately call streamRead to read
56 * the data or data may be lost. Returns negative value on error,
57 * otherwise 0.
58 */
59 int (*registerCallback)(void *privdata, void (*cb)(void *cbdata),
60 void *cbdata);
61
62 /* transferCmd sends commands to the camera. command MUST point to
63 * an 8 byte buffer in kernel space. data can be NULL if no extra
64 * data is needed. The size of the data is given by the last 2
65 * bytes of comand. data must also point to memory in kernel space.
66 * Returns negative value on error, otherwise 0.
67 */
68 int (*transferCmd)(void *privdata, u8 *command, u8 *data);
69
70 /* streamStart initiates stream capture mode.
71 * Returns negative value on error, otherwise 0.
72 */
73 int (*streamStart)(void *privdata);
74
75 /* streamStop terminates stream capture mode.
76 * Returns negative value on error, otherwise 0.
77 */
78 int (*streamStop)(void *privdata);
79
80 /* streamRead reads a frame from the camera. buffer points to a
81 * buffer large enough to hold a complete frame in kernel space.
82 * noblock indicates if this should be a non blocking read.
83 * Returns the number of bytes read, or negative value on error.
84 */
85 int (*streamRead)(void *privdata, u8 *buffer, int noblock);
86
87 /* close disables the device until open() is called again.
88 * Returns negative value on error, otherwise 0.
89 */
90 int (*close)(void *privdata);
91
92 /* If wait_for_stream_ready is non-zero, wait until the streamState
93 * is STREAM_READY before calling streamRead.
94 */
95 int wait_for_stream_ready;
96 };
97
98 struct cpia_frame {
99 u8 *data;
100 int count;
101 int width;
102 int height;
103 volatile int state;
104 };
105
106 struct cam_params {
107 struct {
108 u8 firmwareVersion;
109 u8 firmwareRevision;
110 u8 vcVersion;
111 u8 vcRevision;
112 } version;
113 struct {
114 u16 vendor;
115 u16 product;
116 u16 deviceRevision;
117 } pnpID;
118 struct {
119 u8 vpVersion;
120 u8 vpRevision;
121 u16 cameraHeadID;
122 } vpVersion;
123 struct {
124 u8 systemState;
125 u8 grabState;
126 u8 streamState;
127 u8 fatalError;
128 u8 cmdError;
129 u8 debugFlags;
130 u8 vpStatus;
131 u8 errorCode;
132 } status;
133 struct {
134 u8 brightness;
135 u8 contrast;
136 u8 saturation;
137 } colourParams;
138 struct {
139 u8 gainMode;
140 u8 expMode;
141 u8 compMode;
142 u8 centreWeight;
143 u8 gain;
144 u8 fineExp;
145 u8 coarseExpLo;
146 u8 coarseExpHi;
147 u8 redComp;
148 u8 green1Comp;
149 u8 green2Comp;
150 u8 blueComp;
151 } exposure;
152 struct {
153 u8 balanceModeIsAuto;
154 u8 redGain;
155 u8 greenGain;
156 u8 blueGain;
157 } colourBalance;
158 struct {
159 u8 divisor;
160 u8 baserate;
161 } sensorFps;
162 struct {
163 u8 gain1;
164 u8 gain2;
165 u8 gain4;
166 u8 gain8;
167 } apcor;
168 struct {
169 u8 flickerMode;
170 u8 coarseJump;
171 u8 allowableOverExposure;
172 } flickerControl;
173 struct {
174 u8 gain1;
175 u8 gain2;
176 u8 gain4;
177 u8 gain8;
178 } vlOffset;
179 struct {
180 u8 mode;
181 u8 decimation;
182 } compression;
183 struct {
184 u8 frTargeting;
185 u8 targetFR;
186 u8 targetQ;
187 } compressionTarget;
188 struct {
189 u8 yThreshold;
190 u8 uvThreshold;
191 } yuvThreshold;
192 struct {
193 u8 hysteresis;
194 u8 threshMax;
195 u8 smallStep;
196 u8 largeStep;
197 u8 decimationHysteresis;
198 u8 frDiffStepThresh;
199 u8 qDiffStepThresh;
200 u8 decimationThreshMod;
201 } compressionParams;
202 struct {
203 u8 videoSize; /* CIF/QCIF */
204 u8 subSample;
205 u8 yuvOrder;
206 } format;
207 struct {
208 u8 colStart; /* skip first 8*colStart pixels */
209 u8 colEnd; /* finish at 8*colEnd pixels */
210 u8 rowStart; /* skip first 4*rowStart lines */
211 u8 rowEnd; /* finish at 4*rowEnd lines */
212 } roi;
213 u8 ecpTiming;
214 u8 streamStartLine;
215 };
216
217 enum v4l_camstates {
218 CPIA_V4L_IDLE = 0,
219 CPIA_V4L_ERROR,
220 CPIA_V4L_COMMAND,
221 CPIA_V4L_GRABBING,
222 CPIA_V4L_STREAMING,
223 CPIA_V4L_STREAMING_PAUSED,
224 };
225
226 #define FRAME_NUM 2 /* double buffering for now */
227
228 struct cam_data {
229 struct cam_data **previous;
230 struct cam_data *next;
231
232 struct semaphore busy_lock; /* guard against SMP multithreading */
233 struct cpia_camera_ops *ops; /* lowlevel driver operations */
234 void *lowlevel_data; /* private data for lowlevel driver */
235 u8 *raw_image; /* buffer for raw image data */
236 struct cpia_frame decompressed_frame;
237 /* buffer to hold decompressed frame */
238 int image_size; /* sizeof last decompressed image */
239 int open_count; /* # of process that have camera open */
240
241 /* camera status */
242 int fps; /* actual fps reported by the camera */
243 int transfer_rate; /* transfer rate from camera in kB/s */
244 u8 mainsFreq; /* for flicker control */
245
246 /* proc interface */
247 struct semaphore param_lock; /* params lock for this camera */
248 struct cam_params params; /* camera settings */
249 struct proc_dir_entry *proc_entry; /* /proc/cpia/videoX */
250
251 /* v4l */
252 int video_size; /* VIDEO_SIZE_ */
253 volatile enum v4l_camstates camstate; /* v4l layer status */
254 struct video_device vdev; /* v4l videodev */
255 struct video_picture vp; /* v4l camera settings */
256 struct video_window vw; /* v4l capture area */
257
258 /* mmap interface */
259 int curframe; /* the current frame to grab into */
260 u8 *frame_buf; /* frame buffer data */
261 struct cpia_frame frame[FRAME_NUM];
262 /* FRAME_NUM-buffering, so we need a array */
263
264 int first_frame;
265 int mmap_kludge; /* 'wrong' byte order for mmap */
266 volatile u32 cmd_queue; /* queued commands */
267 };
268
269 /* cpia_register_camera is called by low level driver for each camera.
270 * A unique camera number is returned, or a negative value on error */
271 struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel);
272
273 /* cpia_unregister_camera is called by low level driver when a camera
274 * is removed. This must not fail. */
275 void cpia_unregister_camera(struct cam_data *cam);
276
277 /* raw CIF + 64 byte header + (2 bytes line_length + EOL) per line + 4*EOI +
278 * one byte 16bit DMA alignment
279 */
280 #define CPIA_MAX_IMAGE_SIZE ((352*288*2)+64+(288*3)+5)
281
282 /* constant value's */
283 #define MAGIC_0 0x19
284 #define MAGIC_1 0x68
285 #define DATA_IN 0xC0
286 #define DATA_OUT 0x40
287 #define VIDEOSIZE_QCIF 0 /* 176x144 */
288 #define VIDEOSIZE_CIF 1 /* 352x288 */
289 #define VIDEOSIZE_SIF 2 /* 320x240 */
290 #define VIDEOSIZE_QSIF 3 /* 160x120 */
291 #define VIDEOSIZE_48_48 4 /* where no one has gone before, iconsize! */
292 #define VIDEOSIZE_64_48 5
293 #define VIDEOSIZE_128_96 6
294 #define VIDEOSIZE_160_120 VIDEOSIZE_QSIF
295 #define VIDEOSIZE_176_144 VIDEOSIZE_QCIF
296 #define VIDEOSIZE_192_144 7
297 #define VIDEOSIZE_224_168 8
298 #define VIDEOSIZE_256_192 9
299 #define VIDEOSIZE_288_216 10
300 #define VIDEOSIZE_320_240 VIDEOSIZE_SIF
301 #define VIDEOSIZE_352_288 VIDEOSIZE_CIF
302 #define VIDEOSIZE_88_72 11 /* quarter CIF */
303 #define SUBSAMPLE_420 0
304 #define SUBSAMPLE_422 1
305 #define YUVORDER_YUYV 0
306 #define YUVORDER_UYVY 1
307 #define NOT_COMPRESSED 0
308 #define COMPRESSED 1
309 #define NO_DECIMATION 0
310 #define DECIMATION_ENAB 1
311 #define EOI 0xff /* End Of Image */
312 #define EOL 0xfd /* End Of Line */
313 #define FRAME_HEADER_SIZE 64
314
315 /* Image grab modes */
316 #define CPIA_GRAB_SINGLE 0
317 #define CPIA_GRAB_CONTINUOUS 1
318
319 /* Compression parameters */
320 #define CPIA_COMPRESSION_NONE 0
321 #define CPIA_COMPRESSION_AUTO 1
322 #define CPIA_COMPRESSION_MANUAL 2
323 #define CPIA_COMPRESSION_TARGET_QUALITY 0
324 #define CPIA_COMPRESSION_TARGET_FRAMERATE 1
325
326 /* Return offsets for GetCameraState */
327 #define SYSTEMSTATE 0
328 #define GRABSTATE 1
329 #define STREAMSTATE 2
330 #define FATALERROR 3
331 #define CMDERROR 4
332 #define DEBUGFLAGS 5
333 #define VPSTATUS 6
334 #define ERRORCODE 7
335
336 /* SystemState */
337 #define UNINITIALISED_STATE 0
338 #define PASS_THROUGH_STATE 1
339 #define LO_POWER_STATE 2
340 #define HI_POWER_STATE 3
341 #define WARM_BOOT_STATE 4
342
343 /* GrabState */
344 #define GRAB_IDLE 0
345 #define GRAB_ACTIVE 1
346 #define GRAB_DONE 2
347
348 /* StreamState */
349 #define STREAM_NOT_READY 0
350 #define STREAM_READY 1
351 #define STREAM_OPEN 2
352 #define STREAM_PAUSED 3
353 #define STREAM_FINISHED 4
354
355 /* Fatal Error, CmdError, and DebugFlags */
356 #define CPIA_FLAG 1
357 #define SYSTEM_FLAG 2
358 #define INT_CTRL_FLAG 4
359 #define PROCESS_FLAG 8
360 #define COM_FLAG 16
361 #define VP_CTRL_FLAG 32
362 #define CAPTURE_FLAG 64
363 #define DEBUG_FLAG 128
364
365 /* VPStatus */
366 #define VP_STATE_OK 0x00
367
368 #define VP_STATE_FAILED_VIDEOINIT 0x01
369 #define VP_STATE_FAILED_AECACBINIT 0x02
370 #define VP_STATE_AEC_MAX 0x04
371 #define VP_STATE_ACB_BMAX 0x08
372
373 #define VP_STATE_ACB_RMIN 0x10
374 #define VP_STATE_ACB_GMIN 0x20
375 #define VP_STATE_ACB_RMAX 0x40
376 #define VP_STATE_ACB_GMAX 0x80
377
378 /* ErrorCode */
379 #define ERROR_FLICKER_BELOW_MIN_EXP 0x01 /*flicker exposure got below minimum exposure */
380
381 #define ALOG(lineno,fmt,args...) printk(fmt,lineno,##args)
382 #define LOG(fmt,args...) ALOG((__LINE__),KERN_INFO __FILE__":"__FUNCTION__"(%d):"fmt,##args)
383
384 #ifdef _CPIA_DEBUG_
385 #define ADBG(lineno,fmt,args...) printk(fmt, jiffies, lineno, ##args)
386 #define DBG(fmt,args...) ADBG((__LINE__),KERN_DEBUG __FILE__"(%ld):"__FUNCTION__"(%d):"fmt,##args)
387 #else
388 #define DBG(fmn,args...) do {} while(0)
389 #endif
390
391 #define DEB_BYTE(p)\
392 DBG("%1d %1d %1d %1d %1d %1d %1d %1d \n",\
393 (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\
394 (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0);
395
396 #define ADD_TO_LIST(l, drv) \
397 {\
398 lock_kernel();\
399 (drv)->next = l;\
400 (drv)->previous = &(l);\
401 (l) = drv;\
402 unlock_kernel();\
403 } while(0)
404
405 #define REMOVE_FROM_LIST(drv) \
406 {\
407 if ((drv)->previous != NULL) {\
408 lock_kernel();\
409 if ((drv)->next != NULL)\
410 (drv)->next->previous = (drv)->previous;\
411 *((drv)->previous) = (drv)->next;\
412 (drv)->previous = NULL;\
413 (drv)->next = NULL;\
414 unlock_kernel();\
415 }\
416 } while (0)
417
418
419 #endif /* __KERNEL__ */
420
421 #endif /* cpia_h */
422
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.