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