blob: 72a28857305151dbf06933939c3290f5b96f0200 [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 Moine0be01002008-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 Moinec2446b32008-07-05 11:49:20 -030059 struct v4l2_pix_format *cam_mode; /* size nmodes */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030060 char nmodes;
61 __u8 epaddr;
62};
63
64struct gspca_dev;
65struct gspca_frame;
66
67/* subdriver operations */
68typedef int (*cam_op) (struct gspca_dev *);
69typedef void (*cam_v_op) (struct gspca_dev *);
70typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
71typedef int (*cam_jpg_op) (struct gspca_dev *,
72 struct v4l2_jpegcompression *);
73typedef int (*cam_qmnu_op) (struct gspca_dev *,
74 struct v4l2_querymenu *);
75typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
76 struct gspca_frame *frame,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030077 __u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030078 int len);
79
80struct ctrl {
81 struct v4l2_queryctrl qctrl;
82 int (*set)(struct gspca_dev *, __s32);
83 int (*get)(struct gspca_dev *, __s32 *);
84};
85
86/* subdriver description */
87struct sd_desc {
88/* information */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -030089 const char *name; /* sub-driver name */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030090/* controls */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -030091 const struct ctrl *ctrls;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030092 int nctrls;
Jean-Francois Moine012d6b02008-09-03 17:12:16 -030093/* mandatory operations */
Hans de Goedee2997a72008-04-23 08:09:12 -030094 cam_cf_op config; /* called on probe */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -030095 cam_op init; /* called on probe and resume */
Hans de Goedee2997a72008-04-23 08:09:12 -030096 cam_v_op start; /* called on stream on */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030097 cam_pkt_op pkt_scan;
Jean-Francois Moinec2446b32008-07-05 11:49:20 -030098/* optional operations */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -030099 cam_v_op stopN; /* called on stream off - main alt */
100 cam_v_op stop0; /* called on stream off - alt 0 */
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300101 cam_v_op dq_callback; /* called when a frame has been dequeued */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300102 cam_jpg_op get_jcomp;
103 cam_jpg_op set_jcomp;
104 cam_qmnu_op querymenu;
105};
106
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300107/* packet types when moving from iso buf to frame buf */
108#define DISCARD_PACKET 0
109#define FIRST_PACKET 1
110#define INTER_PACKET 2
111#define LAST_PACKET 3
112
113struct gspca_frame {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300114 __u8 *data; /* frame buffer */
115 __u8 *data_end; /* end of frame while filling */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300116 int vma_use_count;
117 struct v4l2_buffer v4l2_buf;
118};
119
120struct gspca_dev {
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300121 struct video_device vdev; /* !! must be the first item */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300122 struct file_operations fops;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300123 struct usb_device *dev;
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300124 struct file *capt_file; /* file doing video capture */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300125
126 struct cam cam; /* device information */
127 const struct sd_desc *sd_desc; /* subdriver description */
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -0300128 unsigned ctrl_dis; /* disabled controls (bit map) */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300129
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300130#define USB_BUF_SZ 64
131 __u8 *usb_buf; /* buffer for USB exchanges */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300132 struct urb *urb[MAX_NURBS];
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300133
134 __u8 *frbuf; /* buffer for nframes */
135 struct gspca_frame frame[GSPCA_MAX_FRAMES];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300136 __u32 frsz; /* frame size */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300137 char nframes; /* number of frames */
138 char fr_i; /* frame being filled */
139 char fr_q; /* next frame to queue */
140 char fr_o; /* next frame to dequeue */
141 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
142 char last_packet_type;
143
144 __u8 iface; /* USB interface number */
145 __u8 alt; /* USB alternate setting */
Jean-Francois Moine0be01002008-09-04 07:01:50 -0300146 __u8 bulk; /* image transfer by isoc (0) or bulk (1) */
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 Moine6a709742008-09-03 16:48:10 -0300159#ifdef CONFIG_PM
160 char frozen; /* suspend - resume */
161#endif
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300162 char users; /* number of opens */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300163 char present; /* device connected */
164 char nbufread; /* number of buffers for read() */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300165 char nurbs; /* number of allocated URBs */
166 char memory; /* memory type (V4L2_MEMORY_xxx) */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300167 __u8 nbalt; /* number of USB alternate settings */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300168};
169
170int gspca_dev_probe(struct usb_interface *intf,
171 const struct usb_device_id *id,
172 const struct sd_desc *sd_desc,
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300173 int dev_size,
174 struct module *module);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300175void gspca_disconnect(struct usb_interface *intf);
176struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
177 int packet_type,
178 struct gspca_frame *frame,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300179 const __u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300180 int len);
Jean-Francois Moine1b60e1a2008-09-20 05:44:21 -0300181struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev);
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300182#ifdef CONFIG_PM
183int gspca_suspend(struct usb_interface *intf, pm_message_t message);
184int gspca_resume(struct usb_interface *intf);
185#endif
Hans de Goededcef3232008-07-10 10:40:53 -0300186int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
187 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300188#endif /* GSPCAV2_H */