]>
Commit | Line | Data |
---|---|---|
63eb9546 JFM |
1 | #ifndef GSPCAV2_H |
2 | #define GSPCAV2_H | |
3 | ||
4 | #include <linux/module.h> | |
63eb9546 JFM |
5 | #include <linux/kernel.h> |
6 | #include <linux/usb.h> | |
7 | #include <linux/videodev2.h> | |
8 | #include <media/v4l2-common.h> | |
9 | #include <linux/mutex.h> | |
10 | ||
335b3f88 | 11 | /* compilation option */ |
cf221766 | 12 | /*#define GSPCA_DEBUG 1*/ |
335b3f88 JFM |
13 | |
14 | #ifdef GSPCA_DEBUG | |
63eb9546 JFM |
15 | /* GSPCA our debug messages */ |
16 | extern int gspca_debug; | |
133a9fe9 JP |
17 | #define PDEBUG(level, fmt, ...) \ |
18 | do { \ | |
19 | if (gspca_debug & (level)) \ | |
20 | pr_info(fmt, ##__VA_ARGS__); \ | |
21 | } while (0) | |
22 | ||
63eb9546 JFM |
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 | |
f8e5677f JFM |
29 | #define D_USBI 0x00 |
30 | #define D_USBO 0x00 | |
d43fa32f | 31 | #define D_V4L2 0x0100 |
63eb9546 | 32 | #else |
133a9fe9 | 33 | #define PDEBUG(level, fmt, ...) |
63eb9546 | 34 | #endif |
63eb9546 JFM |
35 | |
36 | #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */ | |
0be01004 JFM |
37 | /* image transfers */ |
38 | #define MAX_NURBS 4 /* max number of URBs */ | |
63eb9546 | 39 | |
28ffe77f AO |
40 | |
41 | /* used to list framerates supported by a camera mode (resolution) */ | |
42 | struct framerates { | |
29b87f04 | 43 | const u8 *rates; |
28ffe77f AO |
44 | int nrates; |
45 | }; | |
46 | ||
6a33091f JFM |
47 | /* control definition */ |
48 | struct gspca_ctrl { | |
49 | s16 val; /* current value */ | |
50 | s16 def; /* default value */ | |
51 | s16 min, max; /* minimum and maximum values */ | |
52 | }; | |
53 | ||
63eb9546 | 54 | /* device information - set at probe time */ |
63eb9546 | 55 | struct cam { |
cc611b8a | 56 | const struct v4l2_pix_format *cam_mode; /* size nmodes */ |
2bbf53bd | 57 | const struct framerates *mode_framerates; /* must have size nmodes, |
28ffe77f | 58 | * just like cam_mode */ |
6a33091f JFM |
59 | struct gspca_ctrl *ctrls; /* control table - size nctrls */ |
60 | /* may be NULL */ | |
47aaca96 JFM |
61 | u32 bulk_size; /* buffer size when image transfer by bulk */ |
62 | u32 input_flags; /* value for ENUM_INPUT status flags */ | |
63 | u8 nmodes; /* size of cam_mode */ | |
64 | u8 no_urb_create; /* don't create transfer URBs */ | |
65 | u8 bulk_nurbs; /* number of URBs in bulk mode | |
dff369aa AO |
66 | * - cannot be > MAX_NURBS |
67 | * - when 0 and bulk_size != 0 means | |
68 | * 1 URB and submit done by subdriver */ | |
6929dc6b | 69 | u8 bulk; /* image transfer by 0:isoc / 1:bulk */ |
49cb6b04 JFM |
70 | u8 npkt; /* number of packets in an ISOC message |
71 | * 0 is the default value: 32 packets */ | |
eb3fb7c9 HG |
72 | u8 needs_full_bandwidth;/* Set this flag to notify the bandwidth calc. |
73 | * code that the cam fills all image buffers to | |
74 | * the max, even when using compression. */ | |
63eb9546 JFM |
75 | }; |
76 | ||
77 | struct gspca_dev; | |
78 | struct gspca_frame; | |
79 | ||
80 | /* subdriver operations */ | |
81 | typedef int (*cam_op) (struct gspca_dev *); | |
82 | typedef void (*cam_v_op) (struct gspca_dev *); | |
83 | typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *); | |
84 | typedef int (*cam_jpg_op) (struct gspca_dev *, | |
85 | struct v4l2_jpegcompression *); | |
af1d9afa BJ |
86 | typedef int (*cam_reg_op) (struct gspca_dev *, |
87 | struct v4l2_dbg_register *); | |
88 | typedef int (*cam_ident_op) (struct gspca_dev *, | |
89 | struct v4l2_dbg_chip_ident *); | |
668f44a6 | 90 | typedef void (*cam_streamparm_op) (struct gspca_dev *, |
627a5ef7 | 91 | struct v4l2_streamparm *); |
63eb9546 JFM |
92 | typedef int (*cam_qmnu_op) (struct gspca_dev *, |
93 | struct v4l2_querymenu *); | |
94 | typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev, | |
76dd272b | 95 | u8 *data, |
63eb9546 | 96 | int len); |
0274d42e MN |
97 | typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev, |
98 | u8 *data, | |
99 | int len); | |
63eb9546 JFM |
100 | |
101 | struct ctrl { | |
102 | struct v4l2_queryctrl qctrl; | |
103 | int (*set)(struct gspca_dev *, __s32); | |
104 | int (*get)(struct gspca_dev *, __s32 *); | |
6a33091f | 105 | cam_v_op set_control; |
63eb9546 JFM |
106 | }; |
107 | ||
108 | /* subdriver description */ | |
109 | struct sd_desc { | |
110 | /* information */ | |
a5ae2062 | 111 | const char *name; /* sub-driver name */ |
63eb9546 | 112 | /* controls */ |
6a33091f | 113 | const struct ctrl *ctrls; /* static control definition */ |
63eb9546 | 114 | int nctrls; |
012d6b02 | 115 | /* mandatory operations */ |
e2997a72 | 116 | cam_cf_op config; /* called on probe */ |
012d6b02 | 117 | cam_op init; /* called on probe and resume */ |
62bba5dd | 118 | cam_op init_controls; /* called on probe */ |
1f53b0b0 | 119 | cam_op start; /* called on stream on after URBs creation */ |
63eb9546 | 120 | cam_pkt_op pkt_scan; |
c2446b3e | 121 | /* optional operations */ |
1f53b0b0 JFM |
122 | cam_op isoc_init; /* called on stream on before getting the EP */ |
123 | cam_op isoc_nego; /* called when URB submit failed with NOSPC */ | |
012d6b02 | 124 | cam_v_op stopN; /* called on stream off - main alt */ |
98522a7b | 125 | cam_v_op stop0; /* called on stream off & disconnect - alt 0 */ |
c2446b3e | 126 | cam_v_op dq_callback; /* called when a frame has been dequeued */ |
63eb9546 JFM |
127 | cam_jpg_op get_jcomp; |
128 | cam_jpg_op set_jcomp; | |
129 | cam_qmnu_op querymenu; | |
627a5ef7 JP |
130 | cam_streamparm_op get_streamparm; |
131 | cam_streamparm_op set_streamparm; | |
af1d9afa BJ |
132 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
133 | cam_reg_op set_register; | |
134 | cam_reg_op get_register; | |
135 | #endif | |
136 | cam_ident_op get_chip_ident; | |
f7628015 | 137 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
0274d42e | 138 | cam_int_pkt_op int_pkt_scan; |
ac82f59f HG |
139 | /* other_input makes the gspca core create gspca_dev->input even when |
140 | int_pkt_scan is NULL, for cams with non interrupt driven buttons */ | |
141 | u8 other_input; | |
0274d42e | 142 | #endif |
63eb9546 JFM |
143 | }; |
144 | ||
63eb9546 | 145 | /* packet types when moving from iso buf to frame buf */ |
e293e599 EA |
146 | enum gspca_packet_type { |
147 | DISCARD_PACKET, | |
148 | FIRST_PACKET, | |
149 | INTER_PACKET, | |
150 | LAST_PACKET | |
151 | }; | |
63eb9546 JFM |
152 | |
153 | struct gspca_frame { | |
6a7eba24 | 154 | __u8 *data; /* frame buffer */ |
63eb9546 JFM |
155 | int vma_use_count; |
156 | struct v4l2_buffer v4l2_buf; | |
157 | }; | |
158 | ||
159 | struct gspca_dev { | |
a12ca6a6 | 160 | struct video_device vdev; /* !! must be the first item */ |
5c4fa002 | 161 | struct module *module; /* subdriver handling the device */ |
63eb9546 | 162 | struct usb_device *dev; |
4aa0d037 | 163 | struct file *capt_file; /* file doing video capture */ |
f7628015 | 164 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
0274d42e MN |
165 | struct input_dev *input_dev; |
166 | char phys[64]; /* physical device path */ | |
167 | #endif | |
63eb9546 JFM |
168 | |
169 | struct cam cam; /* device information */ | |
170 | const struct sd_desc *sd_desc; /* subdriver description */ | |
f50ba1be | 171 | unsigned ctrl_dis; /* disabled controls (bit map) */ |
4af85668 | 172 | unsigned ctrl_inac; /* inactive controls (bit map) */ |
63eb9546 | 173 | |
8295d99e JFM |
174 | #define USB_BUF_SZ 64 |
175 | __u8 *usb_buf; /* buffer for USB exchanges */ | |
d43fa32f | 176 | struct urb *urb[MAX_NURBS]; |
f7628015 | 177 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
0274d42e MN |
178 | struct urb *int_urb; |
179 | #endif | |
63eb9546 JFM |
180 | |
181 | __u8 *frbuf; /* buffer for nframes */ | |
182 | struct gspca_frame frame[GSPCA_MAX_FRAMES]; | |
b192ca98 | 183 | u8 *image; /* image beeing filled */ |
6a7eba24 | 184 | __u32 frsz; /* frame size */ |
b192ca98 | 185 | u32 image_len; /* current length of image */ |
f7059eaa JFM |
186 | atomic_t fr_q; /* next frame to queue */ |
187 | atomic_t fr_i; /* frame being filled */ | |
63eb9546 | 188 | signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */ |
f7059eaa JFM |
189 | char nframes; /* number of frames */ |
190 | u8 fr_o; /* next frame to dequeue */ | |
ff374747 JFM |
191 | __u8 last_packet_type; |
192 | __s8 empty_packet; /* if (-1) don't check empty packets */ | |
193 | __u8 streaming; | |
63eb9546 | 194 | |
6a7eba24 | 195 | __u8 curr_mode; /* current camera mode */ |
63eb9546 | 196 | __u32 pixfmt; /* current mode parameters */ |
6a7eba24 JFM |
197 | __u16 width; |
198 | __u16 height; | |
ff374747 | 199 | __u32 sequence; /* frame sequence number */ |
63eb9546 | 200 | |
63eb9546 JFM |
201 | wait_queue_head_t wq; /* wait queue */ |
202 | struct mutex usb_lock; /* usb exchange protection */ | |
63eb9546 | 203 | struct mutex queue_lock; /* ISOC queue protection */ |
8c4ebae4 | 204 | int usb_err; /* USB error - protected by usb_lock */ |
35680baa | 205 | u16 pkt_size; /* ISOC packet size */ |
6a709749 JFM |
206 | #ifdef CONFIG_PM |
207 | char frozen; /* suspend - resume */ | |
208 | #endif | |
63eb9546 JFM |
209 | char present; /* device connected */ |
210 | char nbufread; /* number of buffers for read() */ | |
d43fa32f | 211 | char memory; /* memory type (V4L2_MEMORY_xxx) */ |
ff374747 JFM |
212 | __u8 iface; /* USB interface number */ |
213 | __u8 alt; /* USB alternate setting */ | |
35680baa | 214 | u8 audio; /* presence of audio device */ |
63eb9546 JFM |
215 | }; |
216 | ||
217 | int gspca_dev_probe(struct usb_interface *intf, | |
218 | const struct usb_device_id *id, | |
219 | const struct sd_desc *sd_desc, | |
d43fa32f JFM |
220 | int dev_size, |
221 | struct module *module); | |
4462864d JFM |
222 | int gspca_dev_probe2(struct usb_interface *intf, |
223 | const struct usb_device_id *id, | |
224 | const struct sd_desc *sd_desc, | |
225 | int dev_size, | |
226 | struct module *module); | |
63eb9546 | 227 | void gspca_disconnect(struct usb_interface *intf); |
76dd272b JFM |
228 | void gspca_frame_add(struct gspca_dev *gspca_dev, |
229 | enum gspca_packet_type packet_type, | |
230 | const u8 *data, | |
231 | int len); | |
6a709749 JFM |
232 | #ifdef CONFIG_PM |
233 | int gspca_suspend(struct usb_interface *intf, pm_message_t message); | |
234 | int gspca_resume(struct usb_interface *intf); | |
235 | #endif | |
dcef3237 HG |
236 | int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum, |
237 | int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee); | |
63eb9546 | 238 | #endif /* GSPCAV2_H */ |