1#ifndef GSPCAV2_H
2#define GSPCAV2_H
3
4#include <linux/module.h>
5#include <linux/kernel.h>
6#include <linux/usb.h>
7#include <linux/videodev2.h>
8#include <media/v4l2-common.h>
9#include <media/v4l2-ctrls.h>
10#include <media/v4l2-device.h>
11#include <linux/mutex.h>
12
13
14
15
16
17#define D_PROBE 1
18#define D_CONF 2
19#define D_STREAM 3
20#define D_FRAM 4
21#define D_PACK 5
22#define D_USBI 6
23#define D_USBO 7
24
25extern int gspca_debug;
26
27
28#define PDEBUG(level, fmt, ...) \
29 v4l2_dbg(level, gspca_debug, &gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__)
30
31#define PERR(fmt, ...) \
32 v4l2_err(&gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__)
33
34#define GSPCA_MAX_FRAMES 16
35
36#define MAX_NURBS 4
37
38
39
40struct framerates {
41 const u8 *rates;
42 int nrates;
43};
44
45
46struct cam {
47 const struct v4l2_pix_format *cam_mode;
48 const struct framerates *mode_framerates;
49
50 u32 bulk_size;
51 u32 input_flags;
52 u8 nmodes;
53 u8 no_urb_create;
54 u8 bulk_nurbs;
55
56
57
58 u8 bulk;
59 u8 npkt;
60
61 u8 needs_full_bandwidth;
62
63
64};
65
66struct gspca_dev;
67struct gspca_frame;
68
69
70typedef int (*cam_op) (struct gspca_dev *);
71typedef void (*cam_v_op) (struct gspca_dev *);
72typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
73typedef int (*cam_get_jpg_op) (struct gspca_dev *,
74 struct v4l2_jpegcompression *);
75typedef int (*cam_set_jpg_op) (struct gspca_dev *,
76 const struct v4l2_jpegcompression *);
77typedef int (*cam_get_reg_op) (struct gspca_dev *,
78 struct v4l2_dbg_register *);
79typedef int (*cam_set_reg_op) (struct gspca_dev *,
80 const struct v4l2_dbg_register *);
81typedef int (*cam_chip_info_op) (struct gspca_dev *,
82 struct v4l2_dbg_chip_info *);
83typedef void (*cam_streamparm_op) (struct gspca_dev *,
84 struct v4l2_streamparm *);
85typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
86 u8 *data,
87 int len);
88typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
89 u8 *data,
90 int len);
91typedef void (*cam_format_op) (struct gspca_dev *gspca_dev,
92 struct v4l2_format *fmt);
93typedef int (*cam_frmsize_op) (struct gspca_dev *gspca_dev,
94 struct v4l2_frmsizeenum *fsize);
95
96
97struct sd_desc {
98
99 const char *name;
100
101 cam_cf_op config;
102 cam_op init;
103 cam_op init_controls;
104 cam_op start;
105 cam_pkt_op pkt_scan;
106
107 cam_op isoc_init;
108 cam_op isoc_nego;
109 cam_v_op stopN;
110 cam_v_op stop0;
111 cam_v_op dq_callback;
112 cam_get_jpg_op get_jcomp;
113 cam_set_jpg_op set_jcomp;
114 cam_streamparm_op get_streamparm;
115 cam_streamparm_op set_streamparm;
116 cam_format_op try_fmt;
117 cam_frmsize_op enum_framesizes;
118#ifdef CONFIG_VIDEO_ADV_DEBUG
119 cam_set_reg_op set_register;
120 cam_get_reg_op get_register;
121 cam_chip_info_op get_chip_info;
122#endif
123#if IS_ENABLED(CONFIG_INPUT)
124 cam_int_pkt_op int_pkt_scan;
125
126
127 u8 other_input;
128#endif
129};
130
131
132enum gspca_packet_type {
133 DISCARD_PACKET,
134 FIRST_PACKET,
135 INTER_PACKET,
136 LAST_PACKET
137};
138
139struct gspca_frame {
140 __u8 *data;
141 int vma_use_count;
142 struct v4l2_buffer v4l2_buf;
143};
144
145struct gspca_dev {
146 struct video_device vdev;
147 struct module *module;
148 struct v4l2_device v4l2_dev;
149 struct usb_device *dev;
150 struct file *capt_file;
151
152#if IS_ENABLED(CONFIG_INPUT)
153 struct input_dev *input_dev;
154 char phys[64];
155#endif
156
157 struct cam cam;
158 const struct sd_desc *sd_desc;
159 struct v4l2_ctrl_handler ctrl_handler;
160
161
162
163 struct {
164 struct v4l2_ctrl *autogain;
165 struct v4l2_ctrl *exposure;
166 struct v4l2_ctrl *gain;
167 int exp_too_low_cnt, exp_too_high_cnt;
168 };
169
170#define USB_BUF_SZ 64
171 __u8 *usb_buf;
172 struct urb *urb[MAX_NURBS];
173#if IS_ENABLED(CONFIG_INPUT)
174 struct urb *int_urb;
175#endif
176
177 __u8 *frbuf;
178 struct gspca_frame frame[GSPCA_MAX_FRAMES];
179 u8 *image;
180 __u32 frsz;
181 u32 image_len;
182 atomic_t fr_q;
183 atomic_t fr_i;
184 signed char fr_queue[GSPCA_MAX_FRAMES];
185 char nframes;
186 u8 fr_o;
187 __u8 last_packet_type;
188 __s8 empty_packet;
189 __u8 streaming;
190
191 __u8 curr_mode;
192 struct v4l2_pix_format pixfmt;
193 __u32 sequence;
194
195 wait_queue_head_t wq;
196 struct mutex usb_lock;
197 struct mutex queue_lock;
198 int usb_err;
199 u16 pkt_size;
200#ifdef CONFIG_PM
201 char frozen;
202#endif
203 char present;
204 char nbufread;
205 char memory;
206 __u8 iface;
207 __u8 alt;
208 u8 audio;
209
210
211
212
213};
214
215int gspca_dev_probe(struct usb_interface *intf,
216 const struct usb_device_id *id,
217 const struct sd_desc *sd_desc,
218 int dev_size,
219 struct module *module);
220int gspca_dev_probe2(struct usb_interface *intf,
221 const struct usb_device_id *id,
222 const struct sd_desc *sd_desc,
223 int dev_size,
224 struct module *module);
225void gspca_disconnect(struct usb_interface *intf);
226void gspca_frame_add(struct gspca_dev *gspca_dev,
227 enum gspca_packet_type packet_type,
228 const u8 *data,
229 int len);
230#ifdef CONFIG_PM
231int gspca_suspend(struct usb_interface *intf, pm_message_t message);
232int gspca_resume(struct usb_interface *intf);
233#endif
234int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
235 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
236int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
237 int avg_lum, int desired_avg_lum, int deadzone);
238
239#endif
240