5 * CPiA Parallel Port Video4Linux driver
7 * Supports CPiA based parallel port Video Camera's.
9 * (C) Copyright 1999 Bas Huisman,
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.
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.
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.
29 #define CPIA_MAJ_VER 0
30 #define CPIA_MIN_VER 8
31 #define CPIA_PATCH_VER 5
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
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
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 */
46 #include <asm/uaccess.h>
47 #include <linux/videodev.h>
48 #include <linux/list.h>
49 #include <linux/smp_lock.h>
51 struct cpia_camera_ops
53 /* open sets privdata to point to structure for this camera.
54 * Returns negative value on error, otherwise 0.
56 int (*open)(void *privdata);
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,
64 int (*registerCallback)(void *privdata, void (*cb)(void *cbdata),
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.
73 int (*transferCmd)(void *privdata, u8 *command, u8 *data);
75 /* streamStart initiates stream capture mode.
76 * Returns negative value on error, otherwise 0.
78 int (*streamStart)(void *privdata);
80 /* streamStop terminates stream capture mode.
81 * Returns negative value on error, otherwise 0.
83 int (*streamStop)(void *privdata);
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.
90 int (*streamRead)(void *privdata, u8 *buffer, int noblock);
92 /* close disables the device until open() is called again.
93 * Returns negative value on error, otherwise 0.
95 int (*close)(void *privdata);
97 /* If wait_for_stream_ready is non-zero, wait until the streamState
98 * is STREAM_READY before calling streamRead.
100 int wait_for_stream_ready;
102 * Used to maintain lowlevel module usage counts
104 struct module *owner;
162 u8 balanceModeIsAuto;
180 u8 allowableOverExposure;
206 u8 decimationHysteresis;
209 u8 decimationThreshMod;
212 u8 videoSize; /* CIF/QCIF */
216 struct { /* Intel QX3 specific data */
217 u8 qx3_detected; /* a QX3 is present */
218 u8 toplight; /* top light lit , R/W */
219 u8 bottomlight; /* bottom light lit, R/W */
220 u8 button; /* snapshot button pressed (R/O) */
221 u8 cradled; /* microscope is in cradle (R/O) */
224 u8 colStart; /* skip first 8*colStart pixels */
225 u8 colEnd; /* finish at 8*colEnd pixels */
226 u8 rowStart; /* skip first 4*rowStart lines */
227 u8 rowEnd; /* finish at 4*rowEnd lines */
239 CPIA_V4L_STREAMING_PAUSED,
242 #define FRAME_NUM 2 /* double buffering for now */
245 struct list_head cam_data_list;
247 struct semaphore busy_lock; /* guard against SMP multithreading */
248 struct cpia_camera_ops *ops; /* lowlevel driver operations */
249 void *lowlevel_data; /* private data for lowlevel driver */
250 u8 *raw_image; /* buffer for raw image data */
251 struct cpia_frame decompressed_frame;
252 /* buffer to hold decompressed frame */
253 int image_size; /* sizeof last decompressed image */
254 int open_count; /* # of process that have camera open */
257 int fps; /* actual fps reported by the camera */
258 int transfer_rate; /* transfer rate from camera in kB/s */
259 u8 mainsFreq; /* for flicker control */
262 struct semaphore param_lock; /* params lock for this camera */
263 struct cam_params params; /* camera settings */
264 struct proc_dir_entry *proc_entry; /* /proc/cpia/videoX */
267 int video_size; /* VIDEO_SIZE_ */
268 volatile enum v4l_camstates camstate; /* v4l layer status */
269 struct video_device vdev; /* v4l videodev */
270 struct video_picture vp; /* v4l camera settings */
271 struct video_window vw; /* v4l capture area */
274 int curframe; /* the current frame to grab into */
275 u8 *frame_buf; /* frame buffer data */
276 struct cpia_frame frame[FRAME_NUM];
277 /* FRAME_NUM-buffering, so we need a array */
280 int mmap_kludge; /* 'wrong' byte order for mmap */
281 volatile u32 cmd_queue; /* queued commands */
284 /* cpia_register_camera is called by low level driver for each camera.
285 * A unique camera number is returned, or a negative value on error */
286 struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel);
288 /* cpia_unregister_camera is called by low level driver when a camera
289 * is removed. This must not fail. */
290 void cpia_unregister_camera(struct cam_data *cam);
292 /* raw CIF + 64 byte header + (2 bytes line_length + EOL) per line + 4*EOI +
293 * one byte 16bit DMA alignment
295 #define CPIA_MAX_IMAGE_SIZE ((352*288*2)+64+(288*3)+5)
297 /* constant value's */
301 #define DATA_OUT 0x40
302 #define VIDEOSIZE_QCIF 0 /* 176x144 */
303 #define VIDEOSIZE_CIF 1 /* 352x288 */
304 #define VIDEOSIZE_SIF 2 /* 320x240 */
305 #define VIDEOSIZE_QSIF 3 /* 160x120 */
306 #define VIDEOSIZE_48_48 4 /* where no one has gone before, iconsize! */
307 #define VIDEOSIZE_64_48 5
308 #define VIDEOSIZE_128_96 6
309 #define VIDEOSIZE_160_120 VIDEOSIZE_QSIF
310 #define VIDEOSIZE_176_144 VIDEOSIZE_QCIF
311 #define VIDEOSIZE_192_144 7
312 #define VIDEOSIZE_224_168 8
313 #define VIDEOSIZE_256_192 9
314 #define VIDEOSIZE_288_216 10
315 #define VIDEOSIZE_320_240 VIDEOSIZE_SIF
316 #define VIDEOSIZE_352_288 VIDEOSIZE_CIF
317 #define VIDEOSIZE_88_72 11 /* quarter CIF */
318 #define SUBSAMPLE_420 0
319 #define SUBSAMPLE_422 1
320 #define YUVORDER_YUYV 0
321 #define YUVORDER_UYVY 1
322 #define NOT_COMPRESSED 0
324 #define NO_DECIMATION 0
325 #define DECIMATION_ENAB 1
326 #define EOI 0xff /* End Of Image */
327 #define EOL 0xfd /* End Of Line */
328 #define FRAME_HEADER_SIZE 64
330 /* Image grab modes */
331 #define CPIA_GRAB_SINGLE 0
332 #define CPIA_GRAB_CONTINUOUS 1
334 /* Compression parameters */
335 #define CPIA_COMPRESSION_NONE 0
336 #define CPIA_COMPRESSION_AUTO 1
337 #define CPIA_COMPRESSION_MANUAL 2
338 #define CPIA_COMPRESSION_TARGET_QUALITY 0
339 #define CPIA_COMPRESSION_TARGET_FRAMERATE 1
341 /* Return offsets for GetCameraState */
342 #define SYSTEMSTATE 0
344 #define STREAMSTATE 2
352 #define UNINITIALISED_STATE 0
353 #define PASS_THROUGH_STATE 1
354 #define LO_POWER_STATE 2
355 #define HI_POWER_STATE 3
356 #define WARM_BOOT_STATE 4
360 #define GRAB_ACTIVE 1
364 #define STREAM_NOT_READY 0
365 #define STREAM_READY 1
366 #define STREAM_OPEN 2
367 #define STREAM_PAUSED 3
368 #define STREAM_FINISHED 4
370 /* Fatal Error, CmdError, and DebugFlags */
372 #define SYSTEM_FLAG 2
373 #define INT_CTRL_FLAG 4
374 #define PROCESS_FLAG 8
376 #define VP_CTRL_FLAG 32
377 #define CAPTURE_FLAG 64
378 #define DEBUG_FLAG 128
381 #define VP_STATE_OK 0x00
383 #define VP_STATE_FAILED_VIDEOINIT 0x01
384 #define VP_STATE_FAILED_AECACBINIT 0x02
385 #define VP_STATE_AEC_MAX 0x04
386 #define VP_STATE_ACB_BMAX 0x08
388 #define VP_STATE_ACB_RMIN 0x10
389 #define VP_STATE_ACB_GMIN 0x20
390 #define VP_STATE_ACB_RMAX 0x40
391 #define VP_STATE_ACB_GMAX 0x80
394 #define ERROR_FLICKER_BELOW_MIN_EXP 0x01 /*flicker exposure got below minimum exposure */
396 #define ALOG(function,lineno,fmt,args...) printk(fmt, function, lineno, ##args)
397 #define LOG(fmt,args...) ALOG((__FUNCTION__), (__LINE__), \
398 KERN_INFO __FILE__":%s(%d):"fmt, ##args)
401 #define ADBG(function,lineno,fmt,args...) printk(fmt, jiffies, function, lineno, ##args)
402 #define DBG(fmt,args...) ADBG((__FUNCTION__), (__LINE__), \
403 KERN_DEBUG __FILE__"(%ld):%s(%d):"fmt, ##args)
405 #define DBG(fmn,args...) do {} while(0)
409 DBG("%1d %1d %1d %1d %1d %1d %1d %1d \n",\
410 (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\
411 (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0);
413 #endif /* __KERNEL__ */