V4L/DVB (4068): Removed all references to kernel stuff from videodev.h and videodev2.h
[deliverable/linux.git] / drivers / media / video / cpia2 / cpia2.h
1 /****************************************************************************
2 *
3 * Filename: cpia2.h
4 *
5 * Copyright 2001, STMicrolectronics, Inc.
6 *
7 * Contact: steve.miller@st.com
8 *
9 * Description:
10 * This is a USB driver for CPiA2 based video cameras.
11 *
12 * This driver is modelled on the cpia usb driver by
13 * Jochen Scharrlach and Johannes Erdfeldt.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 ****************************************************************************/
30
31 #ifndef __CPIA2_H__
32 #define __CPIA2_H__
33
34 #include <linux/version.h>
35 #include <linux/videodev.h>
36 #include <media/v4l2-common.h>
37 #include <linux/usb.h>
38 #include <linux/poll.h>
39
40 #include "cpia2dev.h"
41 #include "cpia2_registers.h"
42
43 /* define for verbose debug output */
44 //#define _CPIA2_DEBUG_
45
46 #define CPIA2_MAJ_VER 2
47 #define CPIA2_MIN_VER 0
48 #define CPIA2_PATCH_VER 0
49
50 /***
51 * Image defines
52 ***/
53 #ifndef true
54 #define true 1
55 #define false 0
56 #endif
57
58 /* Misc constants */
59 #define ALLOW_CORRUPT 0 /* Causes collater to discard checksum */
60
61 /* USB Transfer mode */
62 #define XFER_ISOC 0
63 #define XFER_BULK 1
64
65 /* USB Alternates */
66 #define USBIF_CMDONLY 0
67 #define USBIF_BULK 1
68 #define USBIF_ISO_1 2 /* 128 bytes/ms */
69 #define USBIF_ISO_2 3 /* 384 bytes/ms */
70 #define USBIF_ISO_3 4 /* 640 bytes/ms */
71 #define USBIF_ISO_4 5 /* 768 bytes/ms */
72 #define USBIF_ISO_5 6 /* 896 bytes/ms */
73 #define USBIF_ISO_6 7 /* 1023 bytes/ms */
74
75 /* Flicker Modes */
76 #define NEVER_FLICKER 0
77 #define ANTI_FLICKER_ON 1
78 #define FLICKER_60 60
79 #define FLICKER_50 50
80
81 /* Debug flags */
82 #define DEBUG_NONE 0
83 #define DEBUG_REG 0x00000001
84 #define DEBUG_DUMP_PATCH 0x00000002
85 #define DEBUG_DUMP_REGS 0x00000004
86
87 /***
88 * Video frame sizes
89 ***/
90 enum {
91 VIDEOSIZE_VGA = 0, /* 640x480 */
92 VIDEOSIZE_CIF, /* 352x288 */
93 VIDEOSIZE_QVGA, /* 320x240 */
94 VIDEOSIZE_QCIF, /* 176x144 */
95 VIDEOSIZE_288_216,
96 VIDEOSIZE_256_192,
97 VIDEOSIZE_224_168,
98 VIDEOSIZE_192_144,
99 };
100
101 #define STV_IMAGE_CIF_ROWS 288
102 #define STV_IMAGE_CIF_COLS 352
103
104 #define STV_IMAGE_QCIF_ROWS 144
105 #define STV_IMAGE_QCIF_COLS 176
106
107 #define STV_IMAGE_VGA_ROWS 480
108 #define STV_IMAGE_VGA_COLS 640
109
110 #define STV_IMAGE_QVGA_ROWS 240
111 #define STV_IMAGE_QVGA_COLS 320
112
113 #define JPEG_MARKER_COM (1<<6) /* Comment segment */
114
115 /***
116 * Enums
117 ***/
118 /* Sensor types available with cpia2 asics */
119 enum sensors {
120 CPIA2_SENSOR_410,
121 CPIA2_SENSOR_500
122 };
123
124 /* Asic types available in the CPiA2 architecture */
125 #define CPIA2_ASIC_672 0x67
126
127 /* Device types (stv672, stv676, etc) */
128 #define DEVICE_STV_672 0x0001
129 #define DEVICE_STV_676 0x0002
130
131 enum frame_status {
132 FRAME_EMPTY,
133 FRAME_READING, /* In the process of being grabbed into */
134 FRAME_READY, /* Ready to be read */
135 FRAME_ERROR,
136 };
137
138 /***
139 * Register access (for USB request byte)
140 ***/
141 enum {
142 CAMERAACCESS_SYSTEM = 0,
143 CAMERAACCESS_VC,
144 CAMERAACCESS_VP,
145 CAMERAACCESS_IDATA
146 };
147
148 #define CAMERAACCESS_TYPE_BLOCK 0x00
149 #define CAMERAACCESS_TYPE_RANDOM 0x04
150 #define CAMERAACCESS_TYPE_MASK 0x08
151 #define CAMERAACCESS_TYPE_REPEAT 0x0C
152
153 #define TRANSFER_READ 0
154 #define TRANSFER_WRITE 1
155
156 #define DEFAULT_ALT USBIF_ISO_6
157 #define DEFAULT_BRIGHTNESS 0x46
158 #define DEFAULT_CONTRAST 0x93
159 #define DEFAULT_SATURATION 0x7f
160 #define DEFAULT_TARGET_KB 0x30
161
162 /* Power state */
163 #define HI_POWER_MODE CPIA2_SYSTEM_CONTROL_HIGH_POWER
164 #define LO_POWER_MODE CPIA2_SYSTEM_CONTROL_LOW_POWER
165
166
167 /********
168 * Commands
169 *******/
170 enum {
171 CPIA2_CMD_NONE = 0,
172 CPIA2_CMD_GET_VERSION,
173 CPIA2_CMD_GET_PNP_ID,
174 CPIA2_CMD_GET_ASIC_TYPE,
175 CPIA2_CMD_GET_SENSOR,
176 CPIA2_CMD_GET_VP_DEVICE,
177 CPIA2_CMD_GET_VP_BRIGHTNESS,
178 CPIA2_CMD_SET_VP_BRIGHTNESS,
179 CPIA2_CMD_GET_CONTRAST,
180 CPIA2_CMD_SET_CONTRAST,
181 CPIA2_CMD_GET_VP_SATURATION,
182 CPIA2_CMD_SET_VP_SATURATION,
183 CPIA2_CMD_GET_VP_GPIO_DIRECTION,
184 CPIA2_CMD_SET_VP_GPIO_DIRECTION,
185 CPIA2_CMD_GET_VP_GPIO_DATA,
186 CPIA2_CMD_SET_VP_GPIO_DATA,
187 CPIA2_CMD_GET_VC_MP_GPIO_DIRECTION,
188 CPIA2_CMD_SET_VC_MP_GPIO_DIRECTION,
189 CPIA2_CMD_GET_VC_MP_GPIO_DATA,
190 CPIA2_CMD_SET_VC_MP_GPIO_DATA,
191 CPIA2_CMD_ENABLE_PACKET_CTRL,
192 CPIA2_CMD_GET_FLICKER_MODES,
193 CPIA2_CMD_SET_FLICKER_MODES,
194 CPIA2_CMD_RESET_FIFO, /* clear fifo and enable stream block */
195 CPIA2_CMD_SET_HI_POWER,
196 CPIA2_CMD_SET_LOW_POWER,
197 CPIA2_CMD_CLEAR_V2W_ERR,
198 CPIA2_CMD_SET_USER_MODE,
199 CPIA2_CMD_GET_USER_MODE,
200 CPIA2_CMD_FRAMERATE_REQ,
201 CPIA2_CMD_SET_COMPRESSION_STATE,
202 CPIA2_CMD_GET_WAKEUP,
203 CPIA2_CMD_SET_WAKEUP,
204 CPIA2_CMD_GET_PW_CONTROL,
205 CPIA2_CMD_SET_PW_CONTROL,
206 CPIA2_CMD_GET_SYSTEM_CTRL,
207 CPIA2_CMD_SET_SYSTEM_CTRL,
208 CPIA2_CMD_GET_VP_SYSTEM_STATE,
209 CPIA2_CMD_GET_VP_SYSTEM_CTRL,
210 CPIA2_CMD_SET_VP_SYSTEM_CTRL,
211 CPIA2_CMD_GET_VP_EXP_MODES,
212 CPIA2_CMD_SET_VP_EXP_MODES,
213 CPIA2_CMD_GET_DEVICE_CONFIG,
214 CPIA2_CMD_SET_DEVICE_CONFIG,
215 CPIA2_CMD_SET_SERIAL_ADDR,
216 CPIA2_CMD_SET_SENSOR_CR1,
217 CPIA2_CMD_GET_VC_CONTROL,
218 CPIA2_CMD_SET_VC_CONTROL,
219 CPIA2_CMD_SET_TARGET_KB,
220 CPIA2_CMD_SET_DEF_JPEG_OPT,
221 CPIA2_CMD_REHASH_VP4,
222 CPIA2_CMD_GET_USER_EFFECTS,
223 CPIA2_CMD_SET_USER_EFFECTS
224 };
225
226 enum user_cmd {
227 COMMAND_NONE = 0x00000001,
228 COMMAND_SET_FPS = 0x00000002,
229 COMMAND_SET_COLOR_PARAMS = 0x00000004,
230 COMMAND_GET_COLOR_PARAMS = 0x00000008,
231 COMMAND_SET_FORMAT = 0x00000010, /* size, etc */
232 COMMAND_SET_FLICKER = 0x00000020
233 };
234
235 /***
236 * Some defines specific to the 676 chip
237 ***/
238 #define CAMACC_CIF 0x01
239 #define CAMACC_VGA 0x02
240 #define CAMACC_QCIF 0x04
241 #define CAMACC_QVGA 0x08
242
243
244 struct cpia2_register {
245 u8 index;
246 u8 value;
247 };
248
249 struct cpia2_reg_mask {
250 u8 index;
251 u8 and_mask;
252 u8 or_mask;
253 u8 fill;
254 };
255
256 struct cpia2_command {
257 u32 command;
258 u8 req_mode; /* (Block or random) | registerBank */
259 u8 reg_count;
260 u8 direction;
261 u8 start;
262 union reg_types {
263 struct cpia2_register registers[32];
264 struct cpia2_reg_mask masks[16];
265 u8 block_data[64];
266 u8 *patch_data; /* points to function defined block */
267 } buffer;
268 };
269
270 struct camera_params {
271 struct {
272 u8 firmware_revision_hi; /* For system register set (bank 0) */
273 u8 firmware_revision_lo;
274 u8 asic_id; /* Video Compressor set (bank 1) */
275 u8 asic_rev;
276 u8 vp_device_hi; /* Video Processor set (bank 2) */
277 u8 vp_device_lo;
278 u8 sensor_flags;
279 u8 sensor_rev;
280 } version;
281
282 struct {
283 u32 device_type; /* enumerated from vendor/product ids.
284 * Currently, either STV_672 or STV_676 */
285 u16 vendor;
286 u16 product;
287 u16 device_revision;
288 } pnp_id;
289
290 struct {
291 u8 brightness; /* CPIA2_VP_EXPOSURE_TARGET */
292 u8 contrast; /* Note: this is CPIA2_VP_YRANGE */
293 u8 saturation; /* CPIA2_VP_SATURATION */
294 } color_params;
295
296 struct {
297 u8 cam_register;
298 u8 flicker_mode_req; /* 1 if flicker on, else never flicker */
299 int mains_frequency;
300 } flicker_control;
301
302 struct {
303 u8 jpeg_options;
304 u8 creep_period;
305 u8 user_squeeze;
306 u8 inhibit_htables;
307 } compression;
308
309 struct {
310 u8 ohsize; /* output image size */
311 u8 ovsize;
312 u8 hcrop; /* cropping start_pos/4 */
313 u8 vcrop;
314 u8 hphase; /* scaling registers */
315 u8 vphase;
316 u8 hispan;
317 u8 vispan;
318 u8 hicrop;
319 u8 vicrop;
320 u8 hifraction;
321 u8 vifraction;
322 } image_size;
323
324 struct {
325 int width; /* actual window width */
326 int height; /* actual window height */
327 } roi;
328
329 struct {
330 u8 video_mode;
331 u8 frame_rate;
332 u8 video_size; /* Not a register, just a convenience for cropped sizes */
333 u8 gpio_direction;
334 u8 gpio_data;
335 u8 system_ctrl;
336 u8 system_state;
337 u8 lowlight_boost; /* Bool: 0 = off, 1 = on */
338 u8 device_config;
339 u8 exposure_modes;
340 u8 user_effects;
341 } vp_params;
342
343 struct {
344 u8 pw_control;
345 u8 wakeup;
346 u8 vc_control;
347 u8 vc_mp_direction;
348 u8 vc_mp_data;
349 u8 target_kb;
350 } vc_params;
351
352 struct {
353 u8 power_mode;
354 u8 system_ctrl;
355 u8 stream_mode; /* This is the current alternate for usb drivers */
356 u8 allow_corrupt;
357 } camera_state;
358 };
359
360 #define NUM_SBUF 2
361
362 struct cpia2_sbuf {
363 char *data;
364 struct urb *urb;
365 };
366
367 struct framebuf {
368 struct timeval timestamp;
369 unsigned long seq;
370 int num;
371 int length;
372 int max_length;
373 volatile enum frame_status status;
374 u8 *data;
375 struct framebuf *next;
376 };
377
378 struct cpia2_fh {
379 enum v4l2_priority prio;
380 u8 mmapped;
381 };
382
383 struct camera_data {
384 /* locks */
385 struct mutex busy_lock; /* guard against SMP multithreading */
386 struct v4l2_prio_state prio;
387
388 /* camera status */
389 volatile int present; /* Is the camera still present? */
390 int open_count; /* # of process that have camera open */
391 int first_image_seen;
392 u8 mains_freq; /* for flicker control */
393 enum sensors sensor_type;
394 u8 flush;
395 u8 mmapped;
396 int streaming; /* 0 = no, 1 = yes */
397 int xfer_mode; /* XFER_BULK or XFER_ISOC */
398 struct camera_params params; /* camera settings */
399
400 /* v4l */
401 int video_size; /* VIDEO_SIZE_ */
402 struct video_device *vdev; /* v4l videodev */
403 struct video_picture vp; /* v4l camera settings */
404 struct video_window vw; /* v4l capture area */
405 __u32 pixelformat; /* Format fourcc */
406
407 /* USB */
408 struct usb_device *dev;
409 unsigned char iface;
410 unsigned int cur_alt;
411 unsigned int old_alt;
412 struct cpia2_sbuf sbuf[NUM_SBUF]; /* Double buffering */
413
414 wait_queue_head_t wq_stream;
415
416 /* Buffering */
417 u32 frame_size;
418 int num_frames;
419 unsigned long frame_count;
420 u8 *frame_buffer; /* frame buffer data */
421 struct framebuf *buffers;
422 struct framebuf * volatile curbuff;
423 struct framebuf *workbuff;
424
425 /* MJPEG Extension */
426 int APPn; /* Number of APP segment to be written, must be 0..15 */
427 int APP_len; /* Length of data in JPEG APPn segment */
428 char APP_data[60]; /* Data in the JPEG APPn segment. */
429
430 int COM_len; /* Length of data in JPEG COM segment */
431 char COM_data[60]; /* Data in JPEG COM segment */
432 };
433
434 /* v4l */
435 int cpia2_register_camera(struct camera_data *cam);
436 void cpia2_unregister_camera(struct camera_data *cam);
437
438 /* core */
439 int cpia2_reset_camera(struct camera_data *cam);
440 int cpia2_set_low_power(struct camera_data *cam);
441 void cpia2_dbg_dump_registers(struct camera_data *cam);
442 int cpia2_match_video_size(int width, int height);
443 void cpia2_set_camera_state(struct camera_data *cam);
444 void cpia2_save_camera_state(struct camera_data *cam);
445 void cpia2_set_color_params(struct camera_data *cam);
446 void cpia2_set_brightness(struct camera_data *cam, unsigned char value);
447 void cpia2_set_contrast(struct camera_data *cam, unsigned char value);
448 void cpia2_set_saturation(struct camera_data *cam, unsigned char value);
449 int cpia2_set_flicker_mode(struct camera_data *cam, int mode);
450 void cpia2_set_format(struct camera_data *cam);
451 int cpia2_send_command(struct camera_data *cam, struct cpia2_command *cmd);
452 int cpia2_do_command(struct camera_data *cam,
453 unsigned int command,
454 unsigned char direction, unsigned char param);
455 struct camera_data *cpia2_init_camera_struct(void);
456 int cpia2_init_camera(struct camera_data *cam);
457 int cpia2_allocate_buffers(struct camera_data *cam);
458 void cpia2_free_buffers(struct camera_data *cam);
459 long cpia2_read(struct camera_data *cam,
460 char __user *buf, unsigned long count, int noblock);
461 unsigned int cpia2_poll(struct camera_data *cam,
462 struct file *filp, poll_table *wait);
463 int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma);
464 void cpia2_set_property_flip(struct camera_data *cam, int prop_val);
465 void cpia2_set_property_mirror(struct camera_data *cam, int prop_val);
466 int cpia2_set_target_kb(struct camera_data *cam, unsigned char value);
467 int cpia2_set_gpio(struct camera_data *cam, unsigned char setting);
468 int cpia2_set_fps(struct camera_data *cam, int framerate);
469
470 /* usb */
471 int cpia2_usb_init(void);
472 void cpia2_usb_cleanup(void);
473 int cpia2_usb_transfer_cmd(struct camera_data *cam, void *registers,
474 u8 request, u8 start, u8 count, u8 direction);
475 int cpia2_usb_stream_start(struct camera_data *cam, unsigned int alternate);
476 int cpia2_usb_stream_stop(struct camera_data *cam);
477 int cpia2_usb_stream_pause(struct camera_data *cam);
478 int cpia2_usb_stream_resume(struct camera_data *cam);
479 int cpia2_usb_change_streaming_alternate(struct camera_data *cam,
480 unsigned int alt);
481
482
483 /* ----------------------- debug functions ---------------------- */
484 #ifdef _CPIA2_DEBUG_
485 #define ALOG(lev, fmt, args...) printk(lev "%s:%d %s(): " fmt, __FILE__, __LINE__, __func__, ## args)
486 #define LOG(fmt, args...) ALOG(KERN_INFO, fmt, ## args)
487 #define ERR(fmt, args...) ALOG(KERN_ERR, fmt, ## args)
488 #define DBG(fmt, args...) ALOG(KERN_DEBUG, fmt, ## args)
489 #else
490 #define ALOG(fmt,args...) printk(fmt,##args)
491 #define LOG(fmt,args...) ALOG(KERN_INFO "cpia2: "fmt,##args)
492 #define ERR(fmt,args...) ALOG(KERN_ERR "cpia2: "fmt,##args)
493 #define DBG(fmn,args...) do {} while(0)
494 #endif
495 /* No function or lineno, for shorter lines */
496 #define KINFO(fmt, args...) printk(KERN_INFO fmt,##args)
497
498 #endif
This page took 0.042058 seconds and 6 git commands to generate.