blob: 0d23e0a90c7796089a1f08e41b42c7fd04b9e16a [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
Hans de Goeded646e702008-07-03 06:48:22 -030012#ifdef CONFIG_VIDEO_ADV_DEBUG
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030013/* GSPCA our debug messages */
14extern int gspca_debug;
15#define PDEBUG(level, fmt, args...) \
16 do {\
17 if (gspca_debug & (level)) \
18 printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
19 } while (0)
20#define D_ERR 0x01
21#define D_PROBE 0x02
22#define D_CONF 0x04
23#define D_STREAM 0x08
24#define D_FRAM 0x10
25#define D_PACK 0x20
26#define D_USBI 0x40
27#define D_USBO 0x80
Jean-Francois Moined43fa322008-06-12 10:58:58 -030028#define D_V4L2 0x0100
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030029#else
30#define PDEBUG(level, fmt, args...)
31#endif
32#undef err
33#define err(fmt, args...) \
34 do {\
35 printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args); \
36 } while (0)
37#undef info
38#define info(fmt, args...) \
39 do {\
40 printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
41 } while (0)
42#undef warn
43#define warn(fmt, args...) \
44 do {\
45 printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args); \
46 } while (0)
47
48#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
49/* ISOC transfers */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030050#define MAX_NURBS 16 /* max number of URBs */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030051#define ISO_MAX_PKT 32 /* max number of packets in an ISOC transfer */
Jean-Francois Moined43fa322008-06-12 10:58:58 -030052#define ISO_MAX_SIZE 0x8000 /* max size of one URB buffer (32 Kb) */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030053
54/* device information - set at probe time */
55struct cam_mode {
56 __u32 pixfmt;
57 short width;
58 short height;
59 short mode; /* subdriver value */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030060};
61struct cam {
62 char *dev_name;
63 struct cam_mode *cam_mode; /* size nmodes */
64 char nmodes;
65 __u8 epaddr;
66};
67
68struct gspca_dev;
69struct gspca_frame;
70
71/* subdriver operations */
72typedef int (*cam_op) (struct gspca_dev *);
73typedef void (*cam_v_op) (struct gspca_dev *);
74typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
75typedef int (*cam_jpg_op) (struct gspca_dev *,
76 struct v4l2_jpegcompression *);
77typedef int (*cam_qmnu_op) (struct gspca_dev *,
78 struct v4l2_querymenu *);
79typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
80 struct gspca_frame *frame,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030081 __u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030082 int len);
83
84struct ctrl {
85 struct v4l2_queryctrl qctrl;
86 int (*set)(struct gspca_dev *, __s32);
87 int (*get)(struct gspca_dev *, __s32 *);
88};
89
90/* subdriver description */
91struct sd_desc {
92/* information */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -030093 const char *name; /* sub-driver name */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030094/* controls */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -030095 const struct ctrl *ctrls;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030096 int nctrls;
97/* operations */
Hans de Goedee2997a72008-04-23 08:09:12 -030098 cam_cf_op config; /* called on probe */
99 cam_op open; /* called on open */
100 cam_v_op start; /* called on stream on */
101 cam_v_op stopN; /* called on stream off - main alt */
102 cam_v_op stop0; /* called on stream off - alt 0 */
103 cam_v_op close; /* called on close */
104 cam_v_op dq_callback; /* called when a frame has been dequeued */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300105 cam_pkt_op pkt_scan;
106 cam_jpg_op get_jcomp;
107 cam_jpg_op set_jcomp;
108 cam_qmnu_op querymenu;
109};
110
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300111/* packet types when moving from iso buf to frame buf */
112#define DISCARD_PACKET 0
113#define FIRST_PACKET 1
114#define INTER_PACKET 2
115#define LAST_PACKET 3
116
117struct gspca_frame {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300118 __u8 *data; /* frame buffer */
119 __u8 *data_end; /* end of frame while filling */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300120 int vma_use_count;
121 struct v4l2_buffer v4l2_buf;
122};
123
124struct gspca_dev {
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300125 struct video_device vdev; /* !! must be the first item */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300126 struct file_operations fops;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300127 struct usb_device *dev;
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300128 struct file *capt_file; /* file doing video capture */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300129
130 struct cam cam; /* device information */
131 const struct sd_desc *sd_desc; /* subdriver description */
132
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300133 struct urb *urb[MAX_NURBS];
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300134
135 __u8 *frbuf; /* buffer for nframes */
136 struct gspca_frame frame[GSPCA_MAX_FRAMES];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300137 __u32 frsz; /* frame size */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300138 char nframes; /* number of frames */
139 char fr_i; /* frame being filled */
140 char fr_q; /* next frame to queue */
141 char fr_o; /* next frame to dequeue */
142 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
143 char last_packet_type;
144
145 __u8 iface; /* USB interface number */
146 __u8 alt; /* USB alternate setting */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300147 __u8 curr_mode; /* current camera mode */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300148 __u32 pixfmt; /* current mode parameters */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300149 __u16 width;
150 __u16 height;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300151
152 atomic_t nevent; /* number of frames done */
153 wait_queue_head_t wq; /* wait queue */
154 struct mutex usb_lock; /* usb exchange protection */
155 struct mutex read_lock; /* read protection */
156 struct mutex queue_lock; /* ISOC queue protection */
157 __u32 sequence; /* frame sequence number */
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300158 char streaming;
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300159 char users; /* number of opens */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300160 char present; /* device connected */
161 char nbufread; /* number of buffers for read() */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300162 char nurbs; /* number of allocated URBs */
163 char memory; /* memory type (V4L2_MEMORY_xxx) */
164 __u8 urb_in; /* URB pointers - used when !mmap */
165 __u8 urb_out;
166 __u8 nbalt; /* number of USB alternate settings */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300167};
168
169int gspca_dev_probe(struct usb_interface *intf,
170 const struct usb_device_id *id,
171 const struct sd_desc *sd_desc,
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300172 int dev_size,
173 struct module *module);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300174void gspca_disconnect(struct usb_interface *intf);
175struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
176 int packet_type,
177 struct gspca_frame *frame,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300178 const __u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300179 int len);
180#endif /* GSPCAV2_H */