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 <media/v4l2-common.h>
49 #include <linux/list.h>
50 #include <linux/smp_lock.h>
51 #include <linux/mutex.h>
53 struct cpia_camera_ops
55 /* open sets privdata to point to structure for this camera.
56 * Returns negative value on error, otherwise 0.
58 int (*open
)(void *privdata
);
60 /* Registers callback function cb to be called with cbdata
61 * when an image is ready. If cb is NULL, only single image grabs
62 * should be used. cb should immediately call streamRead to read
63 * the data or data may be lost. Returns negative value on error,
66 int (*registerCallback
)(void *privdata
, void (*cb
)(void *cbdata
),
69 /* transferCmd sends commands to the camera. command MUST point to
70 * an 8 byte buffer in kernel space. data can be NULL if no extra
71 * data is needed. The size of the data is given by the last 2
72 * bytes of command. data must also point to memory in kernel space.
73 * Returns negative value on error, otherwise 0.
75 int (*transferCmd
)(void *privdata
, u8
*command
, u8
*data
);
77 /* streamStart initiates stream capture mode.
78 * Returns negative value on error, otherwise 0.
80 int (*streamStart
)(void *privdata
);
82 /* streamStop terminates stream capture mode.
83 * Returns negative value on error, otherwise 0.
85 int (*streamStop
)(void *privdata
);
87 /* streamRead reads a frame from the camera. buffer points to a
88 * buffer large enough to hold a complete frame in kernel space.
89 * noblock indicates if this should be a non blocking read.
90 * Returns the number of bytes read, or negative value on error.
92 int (*streamRead
)(void *privdata
, u8
*buffer
, int noblock
);
94 /* close disables the device until open() is called again.
95 * Returns negative value on error, otherwise 0.
97 int (*close
)(void *privdata
);
99 /* If wait_for_stream_ready is non-zero, wait until the streamState
100 * is STREAM_READY before calling streamRead.
102 int wait_for_stream_ready
;
105 * Used to maintain lowlevel module usage counts
107 struct module
*owner
;
184 int allowableOverExposure
;
210 u8 decimationHysteresis
;
213 u8 decimationThreshMod
;
216 u8 videoSize
; /* CIF/QCIF */
220 struct { /* Intel QX3 specific data */
221 u8 qx3_detected
; /* a QX3 is present */
222 u8 toplight
; /* top light lit , R/W */
223 u8 bottomlight
; /* bottom light lit, R/W */
224 u8 button
; /* snapshot button pressed (R/O) */
225 u8 cradled
; /* microscope is in cradle (R/O) */
228 u8 colStart
; /* skip first 8*colStart pixels */
229 u8 colEnd
; /* finish at 8*colEnd pixels */
230 u8 rowStart
; /* skip first 4*rowStart lines */
231 u8 rowEnd
; /* finish at 4*rowEnd lines */
243 CPIA_V4L_STREAMING_PAUSED
,
246 #define FRAME_NUM 2 /* double buffering for now */
249 struct list_head cam_data_list
;
251 struct mutex busy_lock
; /* guard against SMP multithreading */
252 struct cpia_camera_ops
*ops
; /* lowlevel driver operations */
253 void *lowlevel_data
; /* private data for lowlevel driver */
254 u8
*raw_image
; /* buffer for raw image data */
255 struct cpia_frame decompressed_frame
;
256 /* buffer to hold decompressed frame */
257 int image_size
; /* sizeof last decompressed image */
258 int open_count
; /* # of process that have camera open */
261 int fps
; /* actual fps reported by the camera */
262 int transfer_rate
; /* transfer rate from camera in kB/s */
263 u8 mainsFreq
; /* for flicker control */
266 struct mutex param_lock
; /* params lock for this camera */
267 struct cam_params params
; /* camera settings */
268 struct proc_dir_entry
*proc_entry
; /* /proc/cpia/videoX */
271 int video_size
; /* VIDEO_SIZE_ */
272 volatile enum v4l_camstates camstate
; /* v4l layer status */
273 struct video_device vdev
; /* v4l videodev */
274 struct video_picture vp
; /* v4l camera settings */
275 struct video_window vw
; /* v4l capture area */
276 struct video_capture vc
; /* v4l subcapture area */
279 int curframe
; /* the current frame to grab into */
280 u8
*frame_buf
; /* frame buffer data */
281 struct cpia_frame frame
[FRAME_NUM
];
282 /* FRAME_NUM-buffering, so we need a array */
285 int mmap_kludge
; /* 'wrong' byte order for mmap */
286 volatile u32 cmd_queue
; /* queued commands */
287 int exposure_status
; /* EXPOSURE_* */
288 int exposure_count
; /* number of frames at this status */
291 /* cpia_register_camera is called by low level driver for each camera.
292 * A unique camera number is returned, or a negative value on error */
293 struct cam_data
*cpia_register_camera(struct cpia_camera_ops
*ops
, void *lowlevel
);
295 /* cpia_unregister_camera is called by low level driver when a camera
296 * is removed. This must not fail. */
297 void cpia_unregister_camera(struct cam_data
*cam
);
299 /* raw CIF + 64 byte header + (2 bytes line_length + EOL) per line + 4*EOI +
300 * one byte 16bit DMA alignment
302 #define CPIA_MAX_IMAGE_SIZE ((352*288*2)+64+(288*3)+5)
304 /* constant value's */
308 #define DATA_OUT 0x40
309 #define VIDEOSIZE_QCIF 0 /* 176x144 */
310 #define VIDEOSIZE_CIF 1 /* 352x288 */
311 #define VIDEOSIZE_SIF 2 /* 320x240 */
312 #define VIDEOSIZE_QSIF 3 /* 160x120 */
313 #define VIDEOSIZE_48_48 4 /* where no one has gone before, iconsize! */
314 #define VIDEOSIZE_64_48 5
315 #define VIDEOSIZE_128_96 6
316 #define VIDEOSIZE_160_120 VIDEOSIZE_QSIF
317 #define VIDEOSIZE_176_144 VIDEOSIZE_QCIF
318 #define VIDEOSIZE_192_144 7
319 #define VIDEOSIZE_224_168 8
320 #define VIDEOSIZE_256_192 9
321 #define VIDEOSIZE_288_216 10
322 #define VIDEOSIZE_320_240 VIDEOSIZE_SIF
323 #define VIDEOSIZE_352_288 VIDEOSIZE_CIF
324 #define VIDEOSIZE_88_72 11 /* quarter CIF */
325 #define SUBSAMPLE_420 0
326 #define SUBSAMPLE_422 1
327 #define YUVORDER_YUYV 0
328 #define YUVORDER_UYVY 1
329 #define NOT_COMPRESSED 0
331 #define NO_DECIMATION 0
332 #define DECIMATION_ENAB 1
333 #define EOI 0xff /* End Of Image */
334 #define EOL 0xfd /* End Of Line */
335 #define FRAME_HEADER_SIZE 64
337 /* Image grab modes */
338 #define CPIA_GRAB_SINGLE 0
339 #define CPIA_GRAB_CONTINUOUS 1
341 /* Compression parameters */
342 #define CPIA_COMPRESSION_NONE 0
343 #define CPIA_COMPRESSION_AUTO 1
344 #define CPIA_COMPRESSION_MANUAL 2
345 #define CPIA_COMPRESSION_TARGET_QUALITY 0
346 #define CPIA_COMPRESSION_TARGET_FRAMERATE 1
348 /* Return offsets for GetCameraState */
349 #define SYSTEMSTATE 0
351 #define STREAMSTATE 2
359 #define UNINITIALISED_STATE 0
360 #define PASS_THROUGH_STATE 1
361 #define LO_POWER_STATE 2
362 #define HI_POWER_STATE 3
363 #define WARM_BOOT_STATE 4
367 #define GRAB_ACTIVE 1
371 #define STREAM_NOT_READY 0
372 #define STREAM_READY 1
373 #define STREAM_OPEN 2
374 #define STREAM_PAUSED 3
375 #define STREAM_FINISHED 4
377 /* Fatal Error, CmdError, and DebugFlags */
379 #define SYSTEM_FLAG 2
380 #define INT_CTRL_FLAG 4
381 #define PROCESS_FLAG 8
383 #define VP_CTRL_FLAG 32
384 #define CAPTURE_FLAG 64
385 #define DEBUG_FLAG 128
388 #define VP_STATE_OK 0x00
390 #define VP_STATE_FAILED_VIDEOINIT 0x01
391 #define VP_STATE_FAILED_AECACBINIT 0x02
392 #define VP_STATE_AEC_MAX 0x04
393 #define VP_STATE_ACB_BMAX 0x08
395 #define VP_STATE_ACB_RMIN 0x10
396 #define VP_STATE_ACB_GMIN 0x20
397 #define VP_STATE_ACB_RMAX 0x40
398 #define VP_STATE_ACB_GMAX 0x80
400 /* default (minimum) compensation values */
402 #define COMP_GREEN1 214
403 #define COMP_GREEN2 COMP_GREEN1
404 #define COMP_BLUE 230
406 /* exposure status */
407 #define EXPOSURE_VERY_LIGHT 0
408 #define EXPOSURE_LIGHT 1
409 #define EXPOSURE_NORMAL 2
410 #define EXPOSURE_DARK 3
411 #define EXPOSURE_VERY_DARK 4
414 #define ERROR_FLICKER_BELOW_MIN_EXP 0x01 /*flicker exposure got below minimum exposure */
415 #define ALOG(fmt,args...) printk(fmt, ##args)
416 #define LOG(fmt,args...) ALOG(KERN_INFO __FILE__ ":%s(%d):" fmt, __FUNCTION__ , __LINE__ , ##args)
419 #define ADBG(fmt,args...) printk(fmt, jiffies, ##args)
420 #define DBG(fmt,args...) ADBG(KERN_DEBUG __FILE__" (%ld):%s(%d):" fmt, __FUNCTION__, __LINE__ , ##args)
422 #define DBG(fmn,args...) do {} while(0)
426 DBG("%1d %1d %1d %1d %1d %1d %1d %1d \n",\
427 (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\
428 (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0);
430 #endif /* __KERNEL__ */