blob: 1581fa808b6f7858cc6908f0ace6c2c040705c8b [file] [log] [blame]
Jean-Francois Moine63eb9542008-04-12 09:58:09 -03001#ifndef GSPCAV2_H
2#define GSPCAV2_H
3
4#include <linux/module.h>
5#include <linux/version.h>
6#include <linux/kernel.h>
7#include <linux/usb.h>
8#include <linux/videodev2.h>
9#include <media/v4l2-common.h>
10#include <linux/mutex.h>
11
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030012/* values in 2.6.27 */
13#ifndef V4L2_PIX_FMT_SPCA501
14#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1')
15#endif
16#ifndef V4L2_PIX_FMT_SPCA561
17#define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1')
18#endif
19
20/* values in 2.6.26 */
21#ifndef V4L2_CID_POWER_LINE_FREQUENCY
22#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24)
23#endif
24#ifndef V4L2_CID_WHITE_BALANCE_TEMPERATURE
25#define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE + 26)
26#endif
27#ifndef V4L2_CID_SHARPNESS
28#define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27)
29#endif
30
31#ifdef VIDEO_ADV_DEBUG
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030032/* GSPCA our debug messages */
33extern int gspca_debug;
34#define PDEBUG(level, fmt, args...) \
35 do {\
36 if (gspca_debug & (level)) \
37 printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
38 } while (0)
39#define D_ERR 0x01
40#define D_PROBE 0x02
41#define D_CONF 0x04
42#define D_STREAM 0x08
43#define D_FRAM 0x10
44#define D_PACK 0x20
45#define D_USBI 0x40
46#define D_USBO 0x80
Jean-Francois Moined43fa322008-06-12 10:58:58 -030047#define D_V4L2 0x0100
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030048#else
49#define PDEBUG(level, fmt, args...)
50#endif
51#undef err
52#define err(fmt, args...) \
53 do {\
54 printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args); \
55 } while (0)
56#undef info
57#define info(fmt, args...) \
58 do {\
59 printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
60 } while (0)
61#undef warn
62#define warn(fmt, args...) \
63 do {\
64 printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args); \
65 } while (0)
66
67#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
68/* ISOC transfers */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030069#define MAX_NURBS 16 /* max number of URBs */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030070#define ISO_MAX_PKT 32 /* max number of packets in an ISOC transfer */
Jean-Francois Moined43fa322008-06-12 10:58:58 -030071#define ISO_MAX_SIZE 0x8000 /* max size of one URB buffer (32 Kb) */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030072
73/* device information - set at probe time */
74struct cam_mode {
75 __u32 pixfmt;
76 short width;
77 short height;
78 short mode; /* subdriver value */
79 short reserved; /* subdriver value */
80};
81struct cam {
82 char *dev_name;
83 struct cam_mode *cam_mode; /* size nmodes */
84 char nmodes;
85 __u8 epaddr;
86};
87
88struct gspca_dev;
89struct gspca_frame;
90
91/* subdriver operations */
92typedef int (*cam_op) (struct gspca_dev *);
93typedef void (*cam_v_op) (struct gspca_dev *);
94typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
95typedef int (*cam_jpg_op) (struct gspca_dev *,
96 struct v4l2_jpegcompression *);
97typedef int (*cam_qmnu_op) (struct gspca_dev *,
98 struct v4l2_querymenu *);
99typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
100 struct gspca_frame *frame,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300101 __u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300102 int len);
103
104struct ctrl {
105 struct v4l2_queryctrl qctrl;
106 int (*set)(struct gspca_dev *, __s32);
107 int (*get)(struct gspca_dev *, __s32 *);
108};
109
110/* subdriver description */
111struct sd_desc {
112/* information */
Hans de Goedee2997a72008-04-23 08:09:12 -0300113 char *name; /* sub-driver name */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300114/* controls */
115 struct ctrl *ctrls;
116 int nctrls;
117/* operations */
Hans de Goedee2997a72008-04-23 08:09:12 -0300118 cam_cf_op config; /* called on probe */
119 cam_op open; /* called on open */
120 cam_v_op start; /* called on stream on */
121 cam_v_op stopN; /* called on stream off - main alt */
122 cam_v_op stop0; /* called on stream off - alt 0 */
123 cam_v_op close; /* called on close */
124 cam_v_op dq_callback; /* called when a frame has been dequeued */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300125 cam_pkt_op pkt_scan;
126 cam_jpg_op get_jcomp;
127 cam_jpg_op set_jcomp;
128 cam_qmnu_op querymenu;
129};
130
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300131/* packet types when moving from iso buf to frame buf */
132#define DISCARD_PACKET 0
133#define FIRST_PACKET 1
134#define INTER_PACKET 2
135#define LAST_PACKET 3
136
137struct gspca_frame {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300138 __u8 *data; /* frame buffer */
139 __u8 *data_end; /* end of frame while filling */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300140 int vma_use_count;
141 struct v4l2_buffer v4l2_buf;
142};
143
144struct gspca_dev {
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300145 struct video_device vdev; /* !! must be the first item */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300146 struct file_operations fops;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300147 struct usb_device *dev;
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300148 struct file *capt_file; /* file doing video capture */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300149
150 struct cam cam; /* device information */
151 const struct sd_desc *sd_desc; /* subdriver description */
152
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300153 struct urb *urb[MAX_NURBS];
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300154
155 __u8 *frbuf; /* buffer for nframes */
156 struct gspca_frame frame[GSPCA_MAX_FRAMES];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300157 __u32 frsz; /* frame size */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300158 char nframes; /* number of frames */
159 char fr_i; /* frame being filled */
160 char fr_q; /* next frame to queue */
161 char fr_o; /* next frame to dequeue */
162 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
163 char last_packet_type;
164
165 __u8 iface; /* USB interface number */
166 __u8 alt; /* USB alternate setting */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300167 __u8 curr_mode; /* current camera mode */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300168 __u32 pixfmt; /* current mode parameters */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300169 __u16 width;
170 __u16 height;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300171
172 atomic_t nevent; /* number of frames done */
173 wait_queue_head_t wq; /* wait queue */
174 struct mutex usb_lock; /* usb exchange protection */
175 struct mutex read_lock; /* read protection */
176 struct mutex queue_lock; /* ISOC queue protection */
177 __u32 sequence; /* frame sequence number */
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300178 char streaming;
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300179 char users; /* number of opens */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300180 char present; /* device connected */
181 char nbufread; /* number of buffers for read() */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300182 char nurbs; /* number of allocated URBs */
183 char memory; /* memory type (V4L2_MEMORY_xxx) */
184 __u8 urb_in; /* URB pointers - used when !mmap */
185 __u8 urb_out;
186 __u8 nbalt; /* number of USB alternate settings */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300187};
188
189int gspca_dev_probe(struct usb_interface *intf,
190 const struct usb_device_id *id,
191 const struct sd_desc *sd_desc,
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300192 int dev_size,
193 struct module *module);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300194void gspca_disconnect(struct usb_interface *intf);
195struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
196 int packet_type,
197 struct gspca_frame *frame,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300198 __u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300199 int len);
200#endif /* GSPCAV2_H */