4 #include <linux/module.h>
5 #include <linux/kernel.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>
15 /* GSPCA debug codes */
25 extern int gspca_debug;
28 #define PDEBUG(level, fmt, ...) \
29 v4l2_dbg(level, gspca_debug, &gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__)
31 #define PERR(fmt, ...) \
32 v4l2_err(&gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__)
34 #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
36 #define MAX_NURBS 4 /* max number of URBs */
39 /* used to list framerates supported by a camera mode (resolution) */
45 /* device information - set at probe time */
47 const struct v4l2_pix_format *cam_mode; /* size nmodes */
48 const struct framerates *mode_framerates; /* must have size nmodes,
49 * just like cam_mode */
50 u32 bulk_size; /* buffer size when image transfer by bulk */
51 u32 input_flags; /* value for ENUM_INPUT status flags */
52 u8 nmodes; /* size of cam_mode */
53 u8 no_urb_create; /* don't create transfer URBs */
54 u8 bulk_nurbs; /* number of URBs in bulk mode
55 * - cannot be > MAX_NURBS
56 * - when 0 and bulk_size != 0 means
57 * 1 URB and submit done by subdriver */
58 u8 bulk; /* image transfer by 0:isoc / 1:bulk */
59 u8 npkt; /* number of packets in an ISOC message
60 * 0 is the default value: 32 packets */
61 u8 needs_full_bandwidth;/* Set this flag to notify the bandwidth calc.
62 * code that the cam fills all image buffers to
63 * the max, even when using compression. */
69 /* subdriver operations */
70 typedef int (*cam_op) (struct gspca_dev *);
71 typedef void (*cam_v_op) (struct gspca_dev *);
72 typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
73 typedef int (*cam_get_jpg_op) (struct gspca_dev *,
74 struct v4l2_jpegcompression *);
75 typedef int (*cam_set_jpg_op) (struct gspca_dev *,
76 const struct v4l2_jpegcompression *);
77 typedef int (*cam_get_reg_op) (struct gspca_dev *,
78 struct v4l2_dbg_register *);
79 typedef int (*cam_set_reg_op) (struct gspca_dev *,
80 const struct v4l2_dbg_register *);
81 typedef int (*cam_ident_op) (struct gspca_dev *,
82 struct v4l2_dbg_chip_ident *);
83 typedef void (*cam_streamparm_op) (struct gspca_dev *,
84 struct v4l2_streamparm *);
85 typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
88 typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
92 /* subdriver description */
95 const char *name; /* sub-driver name */
96 /* mandatory operations */
97 cam_cf_op config; /* called on probe */
98 cam_op init; /* called on probe and resume */
99 cam_op init_controls; /* called on probe */
100 cam_op start; /* called on stream on after URBs creation */
102 /* optional operations */
103 cam_op isoc_init; /* called on stream on before getting the EP */
104 cam_op isoc_nego; /* called when URB submit failed with NOSPC */
105 cam_v_op stopN; /* called on stream off - main alt */
106 cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
107 cam_v_op dq_callback; /* called when a frame has been dequeued */
108 cam_get_jpg_op get_jcomp;
109 cam_set_jpg_op set_jcomp;
110 cam_streamparm_op get_streamparm;
111 cam_streamparm_op set_streamparm;
112 #ifdef CONFIG_VIDEO_ADV_DEBUG
113 cam_set_reg_op set_register;
114 cam_get_reg_op get_register;
116 cam_ident_op get_chip_ident;
117 #if IS_ENABLED(CONFIG_INPUT)
118 cam_int_pkt_op int_pkt_scan;
119 /* other_input makes the gspca core create gspca_dev->input even when
120 int_pkt_scan is NULL, for cams with non interrupt driven buttons */
125 /* packet types when moving from iso buf to frame buf */
126 enum gspca_packet_type {
134 __u8 *data; /* frame buffer */
136 struct v4l2_buffer v4l2_buf;
140 struct video_device vdev; /* !! must be the first item */
141 struct module *module; /* subdriver handling the device */
142 struct v4l2_device v4l2_dev;
143 struct usb_device *dev;
144 struct file *capt_file; /* file doing video capture */
145 /* protected by queue_lock */
146 #if IS_ENABLED(CONFIG_INPUT)
147 struct input_dev *input_dev;
148 char phys[64]; /* physical device path */
151 struct cam cam; /* device information */
152 const struct sd_desc *sd_desc; /* subdriver description */
153 struct v4l2_ctrl_handler ctrl_handler;
155 /* autogain and exposure or gain control cluster, these are global as
156 the autogain/exposure functions in autogain_functions.c use them */
158 struct v4l2_ctrl *autogain;
159 struct v4l2_ctrl *exposure;
160 struct v4l2_ctrl *gain;
161 int exp_too_low_cnt, exp_too_high_cnt;
164 #define USB_BUF_SZ 64
165 __u8 *usb_buf; /* buffer for USB exchanges */
166 struct urb *urb[MAX_NURBS];
167 #if IS_ENABLED(CONFIG_INPUT)
171 __u8 *frbuf; /* buffer for nframes */
172 struct gspca_frame frame[GSPCA_MAX_FRAMES];
173 u8 *image; /* image beeing filled */
174 __u32 frsz; /* frame size */
175 u32 image_len; /* current length of image */
176 atomic_t fr_q; /* next frame to queue */
177 atomic_t fr_i; /* frame being filled */
178 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
179 char nframes; /* number of frames */
180 u8 fr_o; /* next frame to dequeue */
181 __u8 last_packet_type;
182 __s8 empty_packet; /* if (-1) don't check empty packets */
183 __u8 streaming; /* protected by both mutexes (*) */
185 __u8 curr_mode; /* current camera mode */
186 __u32 pixfmt; /* current mode parameters */
189 __u32 sequence; /* frame sequence number */
191 wait_queue_head_t wq; /* wait queue */
192 struct mutex usb_lock; /* usb exchange protection */
193 struct mutex queue_lock; /* ISOC queue protection */
194 int usb_err; /* USB error - protected by usb_lock */
195 u16 pkt_size; /* ISOC packet size */
197 char frozen; /* suspend - resume */
199 char present; /* device connected */
200 char nbufread; /* number of buffers for read() */
201 char memory; /* memory type (V4L2_MEMORY_xxx) */
202 __u8 iface; /* USB interface number */
203 __u8 alt; /* USB alternate setting */
204 u8 audio; /* presence of audio device */
206 /* (*) These variables are proteced by both usb_lock and queue_lock,
207 that is any code setting them is holding *both*, which means that
208 any code getting them needs to hold at least one of them */
211 int gspca_dev_probe(struct usb_interface *intf,
212 const struct usb_device_id *id,
213 const struct sd_desc *sd_desc,
215 struct module *module);
216 int gspca_dev_probe2(struct usb_interface *intf,
217 const struct usb_device_id *id,
218 const struct sd_desc *sd_desc,
220 struct module *module);
221 void gspca_disconnect(struct usb_interface *intf);
222 void gspca_frame_add(struct gspca_dev *gspca_dev,
223 enum gspca_packet_type packet_type,
227 int gspca_suspend(struct usb_interface *intf, pm_message_t message);
228 int gspca_resume(struct usb_interface *intf);
230 int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
231 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
232 int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
233 int avg_lum, int desired_avg_lum, int deadzone);
235 #endif /* GSPCAV2_H */