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 1
30 #define CPIA_MIN_VER 2
31 #define CPIA_PATCH_VER 3
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
;
103 * Used to maintain lowlevel module usage counts
105 struct module
*owner
;
182 int allowableOverExposure
;
208 u8 decimationHysteresis
;
211 u8 decimationThreshMod
;
214 u8 videoSize
; /* CIF/QCIF */
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) */
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 */
241 CPIA_V4L_STREAMING_PAUSED
,
244 #define FRAME_NUM 2 /* double buffering for now */
247 struct list_head cam_data_list
;
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 */
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 */
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 */
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 */
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 */
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 */
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 */
291 struct cam_data
*cpia_register_camera(struct cpia_camera_ops
*ops
, void *lowlevel
);
293 /* cpia_unregister_camera is called by low level driver when a camera
294 * is removed. This must not fail. */
295 void cpia_unregister_camera(struct cam_data
*cam
);
297 /* raw CIF + 64 byte header + (2 bytes line_length + EOL) per line + 4*EOI +
298 * one byte 16bit DMA alignment
300 #define CPIA_MAX_IMAGE_SIZE ((352*288*2)+64+(288*3)+5)
302 /* constant value's */
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
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
335 /* Image grab modes */
336 #define CPIA_GRAB_SINGLE 0
337 #define CPIA_GRAB_CONTINUOUS 1
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
346 /* Return offsets for GetCameraState */
347 #define SYSTEMSTATE 0
349 #define STREAMSTATE 2
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
365 #define GRAB_ACTIVE 1
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
375 /* Fatal Error, CmdError, and DebugFlags */
377 #define SYSTEM_FLAG 2
378 #define INT_CTRL_FLAG 4
379 #define PROCESS_FLAG 8
381 #define VP_CTRL_FLAG 32
382 #define CAPTURE_FLAG 64
383 #define DEBUG_FLAG 128
386 #define VP_STATE_OK 0x00
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
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
398 /* default (minimum) compensation values */
400 #define COMP_GREEN1 214
401 #define COMP_GREEN2 COMP_GREEN1
402 #define COMP_BLUE 230
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
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)
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)
420 #define DBG(fmn,args...) do {} while(0)
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);
428 #endif /* __KERNEL__ */