]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/media/usb/gspca/gspca.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / drivers / media / usb / gspca / gspca.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
63eb9546
JFM
2#ifndef GSPCAV2_H
3#define GSPCAV2_H
4
5#include <linux/module.h>
63eb9546
JFM
6#include <linux/kernel.h>
7#include <linux/usb.h>
8#include <linux/videodev2.h>
9#include <media/v4l2-common.h>
8cd05842 10#include <media/v4l2-ctrls.h>
2333565d 11#include <media/v4l2-device.h>
63eb9546
JFM
12#include <linux/mutex.h>
13
335b3f88 14
c93396e1
TK
15
16/* GSPCA debug codes */
17
18#define D_PROBE 1
19#define D_CONF 2
20#define D_STREAM 3
21#define D_FRAM 4
22#define D_PACK 5
23#define D_USBI 6
24#define D_USBO 7
25
63eb9546 26extern int gspca_debug;
c93396e1
TK
27
28
29#define PDEBUG(level, fmt, ...) \
30 v4l2_dbg(level, gspca_debug, &gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__)
31
32#define PERR(fmt, ...) \
33 v4l2_err(&gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__)
63eb9546
JFM
34
35#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
0be01004
JFM
36/* image transfers */
37#define MAX_NURBS 4 /* max number of URBs */
63eb9546 38
28ffe77f
AO
39
40/* used to list framerates supported by a camera mode (resolution) */
41struct framerates {
29b87f04 42 const u8 *rates;
28ffe77f
AO
43 int nrates;
44};
45
63eb9546 46/* device information - set at probe time */
63eb9546 47struct cam {
cc611b8a 48 const struct v4l2_pix_format *cam_mode; /* size nmodes */
2bbf53bd 49 const struct framerates *mode_framerates; /* must have size nmodes,
28ffe77f 50 * just like cam_mode */
47aaca96
JFM
51 u32 bulk_size; /* buffer size when image transfer by bulk */
52 u32 input_flags; /* value for ENUM_INPUT status flags */
53 u8 nmodes; /* size of cam_mode */
54 u8 no_urb_create; /* don't create transfer URBs */
55 u8 bulk_nurbs; /* number of URBs in bulk mode
dff369aa
AO
56 * - cannot be > MAX_NURBS
57 * - when 0 and bulk_size != 0 means
58 * 1 URB and submit done by subdriver */
6929dc6b 59 u8 bulk; /* image transfer by 0:isoc / 1:bulk */
49cb6b04
JFM
60 u8 npkt; /* number of packets in an ISOC message
61 * 0 is the default value: 32 packets */
eb3fb7c9
HG
62 u8 needs_full_bandwidth;/* Set this flag to notify the bandwidth calc.
63 * code that the cam fills all image buffers to
64 * the max, even when using compression. */
63eb9546
JFM
65};
66
67struct gspca_dev;
68struct gspca_frame;
69
70/* subdriver operations */
71typedef int (*cam_op) (struct gspca_dev *);
72typedef void (*cam_v_op) (struct gspca_dev *);
73typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
d88aab53 74typedef int (*cam_get_jpg_op) (struct gspca_dev *,
63eb9546 75 struct v4l2_jpegcompression *);
d88aab53
HV
76typedef int (*cam_set_jpg_op) (struct gspca_dev *,
77 const struct v4l2_jpegcompression *);
977ba3b1 78typedef int (*cam_get_reg_op) (struct gspca_dev *,
af1d9afa 79 struct v4l2_dbg_register *);
977ba3b1
HV
80typedef int (*cam_set_reg_op) (struct gspca_dev *,
81 const struct v4l2_dbg_register *);
b1c85cc0
HV
82typedef int (*cam_chip_info_op) (struct gspca_dev *,
83 struct v4l2_dbg_chip_info *);
668f44a6 84typedef void (*cam_streamparm_op) (struct gspca_dev *,
627a5ef7 85 struct v4l2_streamparm *);
63eb9546 86typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
76dd272b 87 u8 *data,
63eb9546 88 int len);
0274d42e
MN
89typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
90 u8 *data,
91 int len);
7d687af4
OZ
92typedef void (*cam_format_op) (struct gspca_dev *gspca_dev,
93 struct v4l2_format *fmt);
94typedef int (*cam_frmsize_op) (struct gspca_dev *gspca_dev,
95 struct v4l2_frmsizeenum *fsize);
63eb9546 96
63eb9546
JFM
97/* subdriver description */
98struct sd_desc {
99/* information */
a5ae2062 100 const char *name; /* sub-driver name */
012d6b02 101/* mandatory operations */
e2997a72 102 cam_cf_op config; /* called on probe */
012d6b02 103 cam_op init; /* called on probe and resume */
62bba5dd 104 cam_op init_controls; /* called on probe */
1f53b0b0 105 cam_op start; /* called on stream on after URBs creation */
63eb9546 106 cam_pkt_op pkt_scan;
c2446b3e 107/* optional operations */
1f53b0b0
JFM
108 cam_op isoc_init; /* called on stream on before getting the EP */
109 cam_op isoc_nego; /* called when URB submit failed with NOSPC */
012d6b02 110 cam_v_op stopN; /* called on stream off - main alt */
98522a7b 111 cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
c2446b3e 112 cam_v_op dq_callback; /* called when a frame has been dequeued */
d88aab53
HV
113 cam_get_jpg_op get_jcomp;
114 cam_set_jpg_op set_jcomp;
627a5ef7
JP
115 cam_streamparm_op get_streamparm;
116 cam_streamparm_op set_streamparm;
7d687af4
OZ
117 cam_format_op try_fmt;
118 cam_frmsize_op enum_framesizes;
af1d9afa 119#ifdef CONFIG_VIDEO_ADV_DEBUG
977ba3b1
HV
120 cam_set_reg_op set_register;
121 cam_get_reg_op get_register;
b1c85cc0 122 cam_chip_info_op get_chip_info;
af1d9afa 123#endif
13a00fab 124#if IS_ENABLED(CONFIG_INPUT)
0274d42e 125 cam_int_pkt_op int_pkt_scan;
ac82f59f
HG
126 /* other_input makes the gspca core create gspca_dev->input even when
127 int_pkt_scan is NULL, for cams with non interrupt driven buttons */
128 u8 other_input;
0274d42e 129#endif
63eb9546
JFM
130};
131
63eb9546 132/* packet types when moving from iso buf to frame buf */
e293e599
EA
133enum gspca_packet_type {
134 DISCARD_PACKET,
135 FIRST_PACKET,
136 INTER_PACKET,
137 LAST_PACKET
138};
63eb9546
JFM
139
140struct gspca_frame {
6a7eba24 141 __u8 *data; /* frame buffer */
63eb9546
JFM
142 int vma_use_count;
143 struct v4l2_buffer v4l2_buf;
144};
145
146struct gspca_dev {
a12ca6a6 147 struct video_device vdev; /* !! must be the first item */
5c4fa002 148 struct module *module; /* subdriver handling the device */
2333565d 149 struct v4l2_device v4l2_dev;
63eb9546 150 struct usb_device *dev;
4aa0d037 151 struct file *capt_file; /* file doing video capture */
a3d6e8cc 152 /* protected by queue_lock */
13a00fab 153#if IS_ENABLED(CONFIG_INPUT)
0274d42e
MN
154 struct input_dev *input_dev;
155 char phys[64]; /* physical device path */
156#endif
63eb9546
JFM
157
158 struct cam cam; /* device information */
159 const struct sd_desc *sd_desc; /* subdriver description */
a8a47860 160 struct v4l2_ctrl_handler ctrl_handler;
63eb9546 161
8cd05842
HG
162 /* autogain and exposure or gain control cluster, these are global as
163 the autogain/exposure functions in autogain_functions.c use them */
164 struct {
165 struct v4l2_ctrl *autogain;
166 struct v4l2_ctrl *exposure;
167 struct v4l2_ctrl *gain;
168 int exp_too_low_cnt, exp_too_high_cnt;
169 };
170
8295d99e
JFM
171#define USB_BUF_SZ 64
172 __u8 *usb_buf; /* buffer for USB exchanges */
d43fa32f 173 struct urb *urb[MAX_NURBS];
13a00fab 174#if IS_ENABLED(CONFIG_INPUT)
0274d42e
MN
175 struct urb *int_urb;
176#endif
63eb9546
JFM
177
178 __u8 *frbuf; /* buffer for nframes */
179 struct gspca_frame frame[GSPCA_MAX_FRAMES];
b192ca98 180 u8 *image; /* image beeing filled */
6a7eba24 181 __u32 frsz; /* frame size */
b192ca98 182 u32 image_len; /* current length of image */
f7059eaa
JFM
183 atomic_t fr_q; /* next frame to queue */
184 atomic_t fr_i; /* frame being filled */
63eb9546 185 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
f7059eaa
JFM
186 char nframes; /* number of frames */
187 u8 fr_o; /* next frame to dequeue */
ff374747
JFM
188 __u8 last_packet_type;
189 __s8 empty_packet; /* if (-1) don't check empty packets */
a3d6e8cc 190 __u8 streaming; /* protected by both mutexes (*) */
63eb9546 191
6a7eba24 192 __u8 curr_mode; /* current camera mode */
1966bc2a 193 struct v4l2_pix_format pixfmt; /* current mode parameters */
ff374747 194 __u32 sequence; /* frame sequence number */
63eb9546 195
63eb9546
JFM
196 wait_queue_head_t wq; /* wait queue */
197 struct mutex usb_lock; /* usb exchange protection */
63eb9546 198 struct mutex queue_lock; /* ISOC queue protection */
8c4ebae4 199 int usb_err; /* USB error - protected by usb_lock */
35680baa 200 u16 pkt_size; /* ISOC packet size */
6a709749
JFM
201#ifdef CONFIG_PM
202 char frozen; /* suspend - resume */
203#endif
63eb9546
JFM
204 char present; /* device connected */
205 char nbufread; /* number of buffers for read() */
d43fa32f 206 char memory; /* memory type (V4L2_MEMORY_xxx) */
ff374747
JFM
207 __u8 iface; /* USB interface number */
208 __u8 alt; /* USB alternate setting */
2fe15245 209 int xfer_ep; /* USB transfer endpoint address */
35680baa 210 u8 audio; /* presence of audio device */
a3d6e8cc
HV
211
212 /* (*) These variables are proteced by both usb_lock and queue_lock,
213 that is any code setting them is holding *both*, which means that
214 any code getting them needs to hold at least one of them */
63eb9546
JFM
215};
216
217int 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
222int 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 227void gspca_disconnect(struct usb_interface *intf);
76dd272b
JFM
228void 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
233int gspca_suspend(struct usb_interface *intf, pm_message_t message);
234int gspca_resume(struct usb_interface *intf);
235#endif
8cd05842
HG
236int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
237 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
238int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
751e78d0 239 int avg_lum, int desired_avg_lum, int deadzone);
8cd05842 240
63eb9546 241#endif /* GSPCAV2_H */