blob: f9006542c58f1b11aa76ffb59bd191c4da27e7ea [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 Moine335b3f82008-07-30 04:53:02 -030012/* compilation option */
13#define GSPCA_DEBUG 1
14
15#ifdef GSPCA_DEBUG
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030016/* GSPCA our debug messages */
17extern int gspca_debug;
18#define PDEBUG(level, fmt, args...) \
19 do {\
20 if (gspca_debug & (level)) \
21 printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
22 } while (0)
23#define D_ERR 0x01
24#define D_PROBE 0x02
25#define D_CONF 0x04
26#define D_STREAM 0x08
27#define D_FRAM 0x10
28#define D_PACK 0x20
29#define D_USBI 0x40
30#define D_USBO 0x80
Jean-Francois Moined43fa322008-06-12 10:58:58 -030031#define D_V4L2 0x0100
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030032#else
33#define PDEBUG(level, fmt, args...)
34#endif
35#undef err
36#define err(fmt, args...) \
37 do {\
38 printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args); \
39 } while (0)
40#undef info
41#define info(fmt, args...) \
42 do {\
43 printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
44 } while (0)
45#undef warn
46#define warn(fmt, args...) \
47 do {\
48 printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args); \
49 } while (0)
50
51#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
Jean-Francois Moine0be010042008-09-04 07:01:50 -030052/* image transfers */
53#define MAX_NURBS 4 /* max number of URBs */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030054#define ISO_MAX_PKT 32 /* max number of packets in an ISOC transfer */
Jean-Francois Moined43fa322008-06-12 10:58:58 -030055#define ISO_MAX_SIZE 0x8000 /* max size of one URB buffer (32 Kb) */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030056
57/* device information - set at probe time */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030058struct cam {
Jean-Francois Moine95d91422008-09-29 05:57:32 -030059 int bulk_size; /* buffer size when image transfer by bulk */
Jean-Francois Moinec2446b32008-07-05 11:49:20 -030060 struct v4l2_pix_format *cam_mode; /* size nmodes */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030061 char nmodes;
62 __u8 epaddr;
63};
64
65struct gspca_dev;
66struct gspca_frame;
67
68/* subdriver operations */
69typedef int (*cam_op) (struct gspca_dev *);
70typedef void (*cam_v_op) (struct gspca_dev *);
71typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
72typedef int (*cam_jpg_op) (struct gspca_dev *,
73 struct v4l2_jpegcompression *);
74typedef int (*cam_qmnu_op) (struct gspca_dev *,
75 struct v4l2_querymenu *);
76typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
77 struct gspca_frame *frame,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030078 __u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030079 int len);
80
81struct ctrl {
82 struct v4l2_queryctrl qctrl;
83 int (*set)(struct gspca_dev *, __s32);
84 int (*get)(struct gspca_dev *, __s32 *);
85};
86
87/* subdriver description */
88struct sd_desc {
89/* information */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -030090 const char *name; /* sub-driver name */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030091/* controls */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -030092 const struct ctrl *ctrls;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030093 int nctrls;
Jean-Francois Moine012d6b02008-09-03 17:12:16 -030094/* mandatory operations */
Hans de Goedee2997a72008-04-23 08:09:12 -030095 cam_cf_op config; /* called on probe */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -030096 cam_op init; /* called on probe and resume */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -030097 cam_op start; /* called on stream on */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030098 cam_pkt_op pkt_scan;
Jean-Francois Moinec2446b32008-07-05 11:49:20 -030099/* optional operations */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300100 cam_v_op stopN; /* called on stream off - main alt */
101 cam_v_op stop0; /* called on stream off - alt 0 */
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300102 cam_v_op dq_callback; /* called when a frame has been dequeued */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300103 cam_jpg_op get_jcomp;
104 cam_jpg_op set_jcomp;
105 cam_qmnu_op querymenu;
106};
107
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300108/* packet types when moving from iso buf to frame buf */
109#define DISCARD_PACKET 0
110#define FIRST_PACKET 1
111#define INTER_PACKET 2
112#define LAST_PACKET 3
113
114struct gspca_frame {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300115 __u8 *data; /* frame buffer */
116 __u8 *data_end; /* end of frame while filling */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300117 int vma_use_count;
118 struct v4l2_buffer v4l2_buf;
119};
120
121struct gspca_dev {
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300122 struct video_device vdev; /* !! must be the first item */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300123 struct file_operations fops;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300124 struct usb_device *dev;
Frank Zago6b060ff2008-09-28 08:12:22 -0300125 struct kref kref;
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300126 struct file *capt_file; /* file doing video capture */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300127
128 struct cam cam; /* device information */
129 const struct sd_desc *sd_desc; /* subdriver description */
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -0300130 unsigned ctrl_dis; /* disabled controls (bit map) */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300131
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300132#define USB_BUF_SZ 64
133 __u8 *usb_buf; /* buffer for USB exchanges */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300134 struct urb *urb[MAX_NURBS];
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300135
136 __u8 *frbuf; /* buffer for nframes */
137 struct gspca_frame frame[GSPCA_MAX_FRAMES];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300138 __u32 frsz; /* frame size */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300139 char nframes; /* number of frames */
140 char fr_i; /* frame being filled */
141 char fr_q; /* next frame to queue */
142 char fr_o; /* next frame to dequeue */
143 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
144 char last_packet_type;
145
146 __u8 iface; /* USB interface number */
147 __u8 alt; /* USB alternate setting */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300148 __u8 curr_mode; /* current camera mode */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300149 __u32 pixfmt; /* current mode parameters */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300150 __u16 width;
151 __u16 height;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300152
153 atomic_t nevent; /* number of frames done */
154 wait_queue_head_t wq; /* wait queue */
155 struct mutex usb_lock; /* usb exchange protection */
156 struct mutex read_lock; /* read protection */
157 struct mutex queue_lock; /* ISOC queue protection */
158 __u32 sequence; /* frame sequence number */
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300159 char streaming;
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300160#ifdef CONFIG_PM
161 char frozen; /* suspend - resume */
162#endif
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300163 char users; /* number of opens */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300164 char present; /* device connected */
165 char nbufread; /* number of buffers for read() */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300166 char nurbs; /* number of allocated URBs */
167 char memory; /* memory type (V4L2_MEMORY_xxx) */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300168 __u8 nbalt; /* number of USB alternate settings */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300169};
170
171int gspca_dev_probe(struct usb_interface *intf,
172 const struct usb_device_id *id,
173 const struct sd_desc *sd_desc,
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300174 int dev_size,
175 struct module *module);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300176void gspca_disconnect(struct usb_interface *intf);
177struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
178 int packet_type,
179 struct gspca_frame *frame,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300180 const __u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300181 int len);
Jean-Francois Moine1b60e1a2008-09-20 05:44:21 -0300182struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev);
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300183#ifdef CONFIG_PM
184int gspca_suspend(struct usb_interface *intf, pm_message_t message);
185int gspca_resume(struct usb_interface *intf);
186#endif
Hans de Goededcef32372008-07-10 10:40:53 -0300187int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
188 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300189#endif /* GSPCAV2_H */