Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cpia2.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Filename: cpia2.h
4  *
5  * Copyright 2001, STMicrolectronics, Inc.
6  *
7  * Contact: [email protected]
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/videodev2.h>
35 #include <linux/usb.h>
36 #include <linux/poll.h>
37 #include <media/v4l2-common.h>
38 #include <media/v4l2-device.h>
39 #include <media/v4l2-ctrls.h>
40 
41 #include "cpia2_registers.h"
42 
43 /* define for verbose debug output */
44 //#define _CPIA2_DEBUG_
45 
46 /***
47  * Image defines
48  ***/
49 
50 /* Misc constants */
51 #define ALLOW_CORRUPT 0 /* Causes collater to discard checksum */
52 
53 /* USB Transfer mode */
54 #define XFER_ISOC 0
55 #define XFER_BULK 1
56 
57 /* USB Alternates */
58 #define USBIF_CMDONLY 0
59 #define USBIF_BULK 1
60 #define USBIF_ISO_1 2 /* 128 bytes/ms */
61 #define USBIF_ISO_2 3 /* 384 bytes/ms */
62 #define USBIF_ISO_3 4 /* 640 bytes/ms */
63 #define USBIF_ISO_4 5 /* 768 bytes/ms */
64 #define USBIF_ISO_5 6 /* 896 bytes/ms */
65 #define USBIF_ISO_6 7 /* 1023 bytes/ms */
66 
67 /* Flicker Modes */
68 #define NEVER_FLICKER 0
69 #define FLICKER_60 60
70 #define FLICKER_50 50
71 
72 /* Debug flags */
73 #define DEBUG_NONE 0
74 #define DEBUG_REG 0x00000001
75 #define DEBUG_DUMP_PATCH 0x00000002
76 #define DEBUG_DUMP_REGS 0x00000004
77 
78 /***
79  * Video frame sizes
80  ***/
81 enum {
82  VIDEOSIZE_VGA = 0, /* 640x480 */
83  VIDEOSIZE_CIF, /* 352x288 */
84  VIDEOSIZE_QVGA, /* 320x240 */
85  VIDEOSIZE_QCIF, /* 176x144 */
90 };
91 
92 #define STV_IMAGE_CIF_ROWS 288
93 #define STV_IMAGE_CIF_COLS 352
94 
95 #define STV_IMAGE_QCIF_ROWS 144
96 #define STV_IMAGE_QCIF_COLS 176
97 
98 #define STV_IMAGE_VGA_ROWS 480
99 #define STV_IMAGE_VGA_COLS 640
100 
101 #define STV_IMAGE_QVGA_ROWS 240
102 #define STV_IMAGE_QVGA_COLS 320
103 
104 #define JPEG_MARKER_COM (1<<6) /* Comment segment */
105 
106 /***
107  * Enums
108  ***/
109 /* Sensor types available with cpia2 asics */
110 enum sensors {
113 };
114 
115 /* Asic types available in the CPiA2 architecture */
116 #define CPIA2_ASIC_672 0x67
117 
118 /* Device types (stv672, stv676, etc) */
119 #define DEVICE_STV_672 0x0001
120 #define DEVICE_STV_676 0x0002
121 
124  FRAME_READING, /* In the process of being grabbed into */
125  FRAME_READY, /* Ready to be read */
127 };
128 
129 /***
130  * Register access (for USB request byte)
131  ***/
132 enum {
137 };
138 
139 #define CAMERAACCESS_TYPE_BLOCK 0x00
140 #define CAMERAACCESS_TYPE_RANDOM 0x04
141 #define CAMERAACCESS_TYPE_MASK 0x08
142 #define CAMERAACCESS_TYPE_REPEAT 0x0C
143 
144 #define TRANSFER_READ 0
145 #define TRANSFER_WRITE 1
146 
147 #define DEFAULT_ALT USBIF_ISO_6
148 #define DEFAULT_BRIGHTNESS 0x46
149 #define DEFAULT_CONTRAST 0x93
150 #define DEFAULT_SATURATION 0x7f
151 
152 /* Power state */
153 #define HI_POWER_MODE CPIA2_SYSTEM_CONTROL_HIGH_POWER
154 #define LO_POWER_MODE CPIA2_SYSTEM_CONTROL_LOW_POWER
155 
156 
157 /********
158  * Commands
159  *******/
160 enum {
184  CPIA2_CMD_RESET_FIFO, /* clear fifo and enable stream block */
214 };
215 
216 enum user_cmd {
217  COMMAND_NONE = 0x00000001,
218  COMMAND_SET_FPS = 0x00000002,
221  COMMAND_SET_FORMAT = 0x00000010, /* size, etc */
222  COMMAND_SET_FLICKER = 0x00000020
223 };
224 
225 /***
226  * Some defines specific to the 676 chip
227  ***/
228 #define CAMACC_CIF 0x01
229 #define CAMACC_VGA 0x02
230 #define CAMACC_QCIF 0x04
231 #define CAMACC_QVGA 0x08
232 
233 
237 };
238 
244 };
245 
248  u8 req_mode; /* (Block or random) | registerBank */
252  union reg_types {
254  struct cpia2_reg_mask masks[16];
256  u8 *patch_data; /* points to function defined block */
257  } buffer;
258 };
259 
261  struct {
262  u8 firmware_revision_hi; /* For system register set (bank 0) */
264  u8 asic_id; /* Video Compressor set (bank 1) */
266  u8 vp_device_hi; /* Video Processor set (bank 2) */
270  } version;
271 
272  struct {
273  u32 device_type; /* enumerated from vendor/product ids.
274  * Currently, either STV_672 or STV_676 */
278  } pnp_id;
279 
280  struct {
281  u8 brightness; /* CPIA2_VP_EXPOSURE_TARGET */
282  u8 contrast; /* Note: this is CPIA2_VP_YRANGE */
283  u8 saturation; /* CPIA2_VP_SATURATION */
284  } color_params;
285 
286  struct {
288  u8 flicker_mode_req; /* 1 if flicker on, else never flicker */
289  } flicker_control;
290 
291  struct {
296  } compression;
297 
298  struct {
299  u8 ohsize; /* output image size */
301  u8 hcrop; /* cropping start_pos/4 */
303  u8 hphase; /* scaling registers */
311  } image_size;
312 
313  struct {
314  int width; /* actual window width */
315  int height; /* actual window height */
316  } roi;
317 
318  struct {
321  u8 video_size; /* Not a register, just a convenience for cropped sizes */
326  u8 lowlight_boost; /* Bool: 0 = off, 1 = on */
330  } vp_params;
331 
332  struct {
339  } vc_params;
340 
341  struct {
343  u8 system_ctrl;
344  u8 stream_mode; /* This is the current alternate for usb drivers */
346  } camera_state;
347 };
348 
349 #define NUM_SBUF 2
350 
351 struct cpia2_sbuf {
352  char *data;
353  struct urb *urb;
354 };
355 
356 struct framebuf {
358  unsigned long seq;
359  int num;
360  int length;
362  volatile enum frame_status status;
364  struct framebuf *next;
365 };
366 
367 struct camera_data {
368  /* locks */
370  struct mutex v4l2_lock; /* serialize file operations */
372  struct {
373  /* Lights control cluster */
376  };
378 
379  /* camera status */
385  int streaming; /* 0 = no, 1 = yes */
386  int xfer_mode; /* XFER_BULK or XFER_ISOC */
387  struct camera_params params; /* camera settings */
388 
389  /* v4l */
390  int video_size; /* VIDEO_SIZE_ */
391  struct video_device vdev; /* v4l videodev */
393  u32 height; /* Its size */
394  __u32 pixelformat; /* Format fourcc */
395 
396  /* USB */
397  struct usb_device *dev;
398  unsigned char iface;
399  unsigned int cur_alt;
400  unsigned int old_alt;
401  struct cpia2_sbuf sbuf[NUM_SBUF]; /* Double buffering */
402 
404 
405  /* Buffering */
408  unsigned long frame_count;
409  u8 *frame_buffer; /* frame buffer data */
410  struct framebuf *buffers;
411  struct framebuf * volatile curbuff;
413 
414  /* MJPEG Extension */
415  int APPn; /* Number of APP segment to be written, must be 0..15 */
416  int APP_len; /* Length of data in JPEG APPn segment */
417  char APP_data[60]; /* Data in the JPEG APPn segment. */
418 
419  int COM_len; /* Length of data in JPEG COM segment */
420  char COM_data[60]; /* Data in JPEG COM segment */
421 };
422 
423 /* v4l */
426 void cpia2_camera_release(struct v4l2_device *v4l2_dev);
427 
428 /* core */
429 int cpia2_reset_camera(struct camera_data *cam);
430 int cpia2_set_low_power(struct camera_data *cam);
432 int cpia2_match_video_size(int width, int height);
436 void cpia2_set_brightness(struct camera_data *cam, unsigned char value);
437 void cpia2_set_contrast(struct camera_data *cam, unsigned char value);
438 void cpia2_set_saturation(struct camera_data *cam, unsigned char value);
439 int cpia2_set_flicker_mode(struct camera_data *cam, int mode);
440 void cpia2_set_format(struct camera_data *cam);
441 int cpia2_send_command(struct camera_data *cam, struct cpia2_command *cmd);
442 int cpia2_do_command(struct camera_data *cam,
443  unsigned int command,
444  unsigned char direction, unsigned char param);
446 int cpia2_init_camera(struct camera_data *cam);
448 void cpia2_free_buffers(struct camera_data *cam);
449 long cpia2_read(struct camera_data *cam,
450  char __user *buf, unsigned long count, int noblock);
451 unsigned int cpia2_poll(struct camera_data *cam,
452  struct file *filp, poll_table *wait);
453 int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma);
454 void cpia2_set_property_flip(struct camera_data *cam, int prop_val);
455 void cpia2_set_property_mirror(struct camera_data *cam, int prop_val);
456 int cpia2_set_gpio(struct camera_data *cam, unsigned char setting);
457 int cpia2_set_fps(struct camera_data *cam, int framerate);
458 
459 /* usb */
460 int cpia2_usb_init(void);
461 void cpia2_usb_cleanup(void);
464 int cpia2_usb_stream_start(struct camera_data *cam, unsigned int alternate);
469  unsigned int alt);
470 
471 
472 /* ----------------------- debug functions ---------------------- */
473 #ifdef _CPIA2_DEBUG_
474 #define ALOG(lev, fmt, args...) printk(lev "%s:%d %s(): " fmt, __FILE__, __LINE__, __func__, ## args)
475 #define LOG(fmt, args...) ALOG(KERN_INFO, fmt, ## args)
476 #define ERR(fmt, args...) ALOG(KERN_ERR, fmt, ## args)
477 #define DBG(fmt, args...) ALOG(KERN_DEBUG, fmt, ## args)
478 #else
479 #define ALOG(fmt,args...) printk(fmt,##args)
480 #define LOG(fmt,args...) ALOG(KERN_INFO "cpia2: "fmt,##args)
481 #define ERR(fmt,args...) ALOG(KERN_ERR "cpia2: "fmt,##args)
482 #define DBG(fmn,args...) do {} while(0)
483 #endif
484 /* No function or lineno, for shorter lines */
485 #define KINFO(fmt, args...) printk(KERN_INFO fmt,##args)
486 
487 #endif