V4L/DVB (8157): gspca: all subdrivers
[safe/jmp/linux-2.6] / drivers / media / video / gspca / gspca.h
1 #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
12 /* 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
32 /* GSPCA our debug messages */
33 extern 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
47 #define D_V4L2 0x0100
48 #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 */
69 #define MAX_NURBS 16            /* max number of URBs */
70 #define ISO_MAX_PKT 32          /* max number of packets in an ISOC transfer */
71 #define ISO_MAX_SIZE 0x8000     /* max size of one URB buffer (32 Kb) */
72
73 /* device information - set at probe time */
74 struct cam_mode {
75         __u32 pixfmt;
76         short width;
77         short height;
78         short mode;             /* subdriver value */
79         short reserved;         /* subdriver value */
80 };
81 struct cam {
82         char *dev_name;
83         struct cam_mode *cam_mode;      /* size nmodes */
84         char nmodes;
85         __u8 epaddr;
86 };
87
88 struct gspca_dev;
89 struct gspca_frame;
90
91 /* subdriver operations */
92 typedef int (*cam_op) (struct gspca_dev *);
93 typedef void (*cam_v_op) (struct gspca_dev *);
94 typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
95 typedef int (*cam_jpg_op) (struct gspca_dev *,
96                                 struct v4l2_jpegcompression *);
97 typedef int (*cam_qmnu_op) (struct gspca_dev *,
98                         struct v4l2_querymenu *);
99 typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
100                                 struct gspca_frame *frame,
101                                 __u8 *data,
102                                 int len);
103
104 struct 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 */
111 struct sd_desc {
112 /* information */
113         char *name;             /* sub-driver name */
114 /* controls */
115         struct ctrl *ctrls;
116         int nctrls;
117 /* operations */
118         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 */
125         cam_pkt_op pkt_scan;
126         cam_jpg_op get_jcomp;
127         cam_jpg_op set_jcomp;
128         cam_qmnu_op querymenu;
129 };
130
131 /* 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
137 struct gspca_frame {
138         __u8 *data;                     /* frame buffer */
139         __u8 *data_end;                 /* end of frame while filling */
140         int vma_use_count;
141         struct v4l2_buffer v4l2_buf;
142 };
143
144 struct gspca_dev {
145         struct video_device vdev;       /* !! must be the first item */
146         struct file_operations fops;
147         struct usb_device *dev;
148         struct file *capt_file;         /* file doing video capture */
149
150         struct cam cam;                         /* device information */
151         const struct sd_desc *sd_desc;          /* subdriver description */
152
153         struct urb *urb[MAX_NURBS];
154
155         __u8 *frbuf;                            /* buffer for nframes */
156         struct gspca_frame frame[GSPCA_MAX_FRAMES];
157         __u32 frsz;                             /* frame size */
158         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 */
167         __u8 curr_mode;                 /* current camera mode */
168         __u32 pixfmt;                   /* current mode parameters */
169         __u16 width;
170         __u16 height;
171
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 */
178         char streaming;
179         char users;                     /* number of opens */
180         char present;                   /* device connected */
181         char nbufread;                  /* number of buffers for read() */
182         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 */
187 };
188
189 int gspca_dev_probe(struct usb_interface *intf,
190                 const struct usb_device_id *id,
191                 const struct sd_desc *sd_desc,
192                 int dev_size,
193                 struct module *module);
194 void gspca_disconnect(struct usb_interface *intf);
195 struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
196                                     int packet_type,
197                                     struct gspca_frame *frame,
198                                     __u8 *data,
199                                     int len);
200 #endif /* GSPCAV2_H */