blob: d39adf90303b9a4371fd3ed878705ae7754535d8 [file] [log] [blame]
Jean-Francois Moine63eb9542008-04-12 09:58:09 -03001#ifndef GSPCAV2_H
2#define GSPCAV2_H
3
4#include <linux/module.h>
Jean-Francois Moine63eb9542008-04-12 09:58:09 -03005#include <linux/kernel.h>
6#include <linux/usb.h>
7#include <linux/videodev2.h>
8#include <media/v4l2-common.h>
Hans de Goede8cd05842012-05-09 09:58:33 -03009#include <media/v4l2-ctrls.h>
Hans Verkuil23335652012-05-06 09:28:19 -030010#include <media/v4l2-device.h>
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030011#include <linux/mutex.h>
12
Jean-Francois Moine335b3f82008-07-30 04:53:02 -030013
Theodore Kilgorec93396e2013-02-04 13:17:55 -030014
15/* GSPCA debug codes */
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
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030025extern int gspca_debug;
Joe Perches133a9fe2011-08-21 19:56:57 -030026
Theodore Kilgorec93396e2013-02-04 13:17:55 -030027
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__)
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030033
34#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
Jean-Francois Moine0be01002008-09-04 07:01:50 -030035/* image transfers */
36#define MAX_NURBS 4 /* max number of URBs */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030037
Antonio Ospite28ffe772009-12-02 06:18:46 -030038
39/* used to list framerates supported by a camera mode (resolution) */
40struct framerates {
Antonio Ospite29b87f02010-01-17 03:27:04 -030041 const u8 *rates;
Antonio Ospite28ffe772009-12-02 06:18:46 -030042 int nrates;
43};
44
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030045/* device information - set at probe time */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030046struct cam {
Jean-Francois Moinecc611b82008-12-29 07:49:41 -030047 const struct v4l2_pix_format *cam_mode; /* size nmodes */
Jean-François Moine2bbf53b2010-12-28 07:01:04 -030048 const struct framerates *mode_framerates; /* must have size nmodes,
Antonio Ospite28ffe772009-12-02 06:18:46 -030049 * just like cam_mode */
Jean-Francois Moine47aaca92009-12-15 05:23:04 -030050 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
Antonio Ospitedff369a2008-11-14 07:53:32 -030055 * - cannot be > MAX_NURBS
56 * - when 0 and bulk_size != 0 means
57 * 1 URB and submit done by subdriver */
Jean-Francois Moine6929dc62009-04-21 13:45:56 -030058 u8 bulk; /* image transfer by 0:isoc / 1:bulk */
Jean-Francois Moine49cb6b02009-04-25 13:29:01 -030059 u8 npkt; /* number of packets in an ISOC message
60 * 0 is the default value: 32 packets */
Hans de Goedeeb3fb7c2012-01-01 16:35:01 -030061 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. */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030064};
65
66struct gspca_dev;
67struct gspca_frame;
68
69/* subdriver operations */
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 *);
Hans Verkuild88aab52012-09-17 05:05:25 -030073typedef int (*cam_get_jpg_op) (struct gspca_dev *,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030074 struct v4l2_jpegcompression *);
Hans Verkuild88aab52012-09-17 05:05:25 -030075typedef int (*cam_set_jpg_op) (struct gspca_dev *,
76 const struct v4l2_jpegcompression *);
Hans Verkuil977ba3b2013-03-24 08:28:46 -030077typedef int (*cam_get_reg_op) (struct gspca_dev *,
Brian Johnsonaf1d9af2009-07-19 05:29:20 -030078 struct v4l2_dbg_register *);
Hans Verkuil977ba3b2013-03-24 08:28:46 -030079typedef int (*cam_set_reg_op) (struct gspca_dev *,
80 const struct v4l2_dbg_register *);
Hans Verkuilb1c85cc2013-05-29 06:59:42 -030081typedef int (*cam_chip_info_op) (struct gspca_dev *,
82 struct v4l2_dbg_chip_info *);
Jean-François Moine668f44a2010-12-25 13:46:14 -030083typedef void (*cam_streamparm_op) (struct gspca_dev *,
Jim Paris627a5ef2008-12-10 06:02:42 -030084 struct v4l2_streamparm *);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030085typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -030086 u8 *data,
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030087 int len);
Márton Németh0274d422010-01-28 06:39:49 -030088typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
89 u8 *data,
90 int len);
Ondrej Zary7d687af2013-08-30 17:54:24 -030091typedef 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);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030095
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030096/* subdriver description */
97struct sd_desc {
98/* information */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -030099 const char *name; /* sub-driver name */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300100/* mandatory operations */
Hans de Goedee2997a72008-04-23 08:09:12 -0300101 cam_cf_op config; /* called on probe */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300102 cam_op init; /* called on probe and resume */
Hans Verkuil62bba5d2012-05-06 09:28:17 -0300103 cam_op init_controls; /* called on probe */
Jean-Francois Moine1f53b0b2009-06-30 07:07:01 -0300104 cam_op start; /* called on stream on after URBs creation */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300105 cam_pkt_op pkt_scan;
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300106/* optional operations */
Jean-Francois Moine1f53b0b2009-06-30 07:07:01 -0300107 cam_op isoc_init; /* called on stream on before getting the EP */
108 cam_op isoc_nego; /* called when URB submit failed with NOSPC */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300109 cam_v_op stopN; /* called on stream off - main alt */
Jean-Francois Moine98522a72008-11-18 06:33:08 -0300110 cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300111 cam_v_op dq_callback; /* called when a frame has been dequeued */
Hans Verkuild88aab52012-09-17 05:05:25 -0300112 cam_get_jpg_op get_jcomp;
113 cam_set_jpg_op set_jcomp;
Jim Paris627a5ef2008-12-10 06:02:42 -0300114 cam_streamparm_op get_streamparm;
115 cam_streamparm_op set_streamparm;
Ondrej Zary7d687af2013-08-30 17:54:24 -0300116 cam_format_op try_fmt;
117 cam_frmsize_op enum_framesizes;
Brian Johnsonaf1d9af2009-07-19 05:29:20 -0300118#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuil977ba3b2013-03-24 08:28:46 -0300119 cam_set_reg_op set_register;
120 cam_get_reg_op get_register;
Hans Verkuilb1c85cc2013-05-29 06:59:42 -0300121 cam_chip_info_op get_chip_info;
Brian Johnsonaf1d9af2009-07-19 05:29:20 -0300122#endif
Peter Senna Tschudin13a00fa2013-01-24 19:28:59 -0300123#if IS_ENABLED(CONFIG_INPUT)
Márton Németh0274d422010-01-28 06:39:49 -0300124 cam_int_pkt_op int_pkt_scan;
Hans de Goedeac82f592010-02-19 04:28:39 -0300125 /* other_input makes the gspca core create gspca_dev->input even when
126 int_pkt_scan is NULL, for cams with non interrupt driven buttons */
127 u8 other_input;
Márton Németh0274d422010-01-28 06:39:49 -0300128#endif
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300129};
130
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300131/* packet types when moving from iso buf to frame buf */
Erik Andrene293e592008-10-03 08:46:50 -0300132enum gspca_packet_type {
133 DISCARD_PACKET,
134 FIRST_PACKET,
135 INTER_PACKET,
136 LAST_PACKET
137};
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300138
139struct gspca_frame {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300140 __u8 *data; /* frame buffer */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300141 int vma_use_count;
142 struct v4l2_buffer v4l2_buf;
143};
144
145struct gspca_dev {
Jean-Francois Moinea12ca6a2008-11-19 06:37:53 -0300146 struct video_device vdev; /* !! must be the first item */
Jean-Francois Moine5c4fa0022008-11-18 15:52:31 -0300147 struct module *module; /* subdriver handling the device */
Hans Verkuil23335652012-05-06 09:28:19 -0300148 struct v4l2_device v4l2_dev;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300149 struct usb_device *dev;
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300150 struct file *capt_file; /* file doing video capture */
Hans Verkuila3d6e8c2012-05-06 09:28:27 -0300151 /* protected by queue_lock */
Peter Senna Tschudin13a00fa2013-01-24 19:28:59 -0300152#if IS_ENABLED(CONFIG_INPUT)
Márton Németh0274d422010-01-28 06:39:49 -0300153 struct input_dev *input_dev;
154 char phys[64]; /* physical device path */
155#endif
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300156
157 struct cam cam; /* device information */
158 const struct sd_desc *sd_desc; /* subdriver description */
Hans de Goedea8a47862012-05-09 11:19:00 -0300159 struct v4l2_ctrl_handler ctrl_handler;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300160
Hans de Goede8cd05842012-05-09 09:58:33 -0300161 /* autogain and exposure or gain control cluster, these are global as
162 the autogain/exposure functions in autogain_functions.c use them */
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
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300170#define USB_BUF_SZ 64
171 __u8 *usb_buf; /* buffer for USB exchanges */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300172 struct urb *urb[MAX_NURBS];
Peter Senna Tschudin13a00fa2013-01-24 19:28:59 -0300173#if IS_ENABLED(CONFIG_INPUT)
Márton Németh0274d422010-01-28 06:39:49 -0300174 struct urb *int_urb;
175#endif
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300176
177 __u8 *frbuf; /* buffer for nframes */
178 struct gspca_frame frame[GSPCA_MAX_FRAMES];
Jean-François Moineb192ca92010-06-27 03:08:19 -0300179 u8 *image; /* image beeing filled */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300180 __u32 frsz; /* frame size */
Jean-François Moineb192ca92010-06-27 03:08:19 -0300181 u32 image_len; /* current length of image */
Jean-François Moinef7059ea2010-07-06 04:32:27 -0300182 atomic_t fr_q; /* next frame to queue */
183 atomic_t fr_i; /* frame being filled */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300184 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
Jean-François Moinef7059ea2010-07-06 04:32:27 -0300185 char nframes; /* number of frames */
186 u8 fr_o; /* next frame to dequeue */
Jean-Francois Moineff374742008-10-23 07:29:51 -0300187 __u8 last_packet_type;
188 __s8 empty_packet; /* if (-1) don't check empty packets */
Hans Verkuila3d6e8c2012-05-06 09:28:27 -0300189 __u8 streaming; /* protected by both mutexes (*) */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300190
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300191 __u8 curr_mode; /* current camera mode */
Ondrej Zary1966bc22013-08-30 17:54:23 -0300192 struct v4l2_pix_format pixfmt; /* current mode parameters */
Jean-Francois Moineff374742008-10-23 07:29:51 -0300193 __u32 sequence; /* frame sequence number */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300194
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300195 wait_queue_head_t wq; /* wait queue */
196 struct mutex usb_lock; /* usb exchange protection */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300197 struct mutex queue_lock; /* ISOC queue protection */
Jean-Francois Moine8c4ebae2009-12-02 07:14:33 -0300198 int usb_err; /* USB error - protected by usb_lock */
Jean-François Moine35680ba2010-07-14 06:30:18 -0300199 u16 pkt_size; /* ISOC packet size */
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300200#ifdef CONFIG_PM
201 char frozen; /* suspend - resume */
202#endif
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300203 char present; /* device connected */
204 char nbufread; /* number of buffers for read() */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300205 char memory; /* memory type (V4L2_MEMORY_xxx) */
Jean-Francois Moineff374742008-10-23 07:29:51 -0300206 __u8 iface; /* USB interface number */
207 __u8 alt; /* USB alternate setting */
Antonio Ospite2fe15242014-06-25 06:27:56 -0300208 int xfer_ep; /* USB transfer endpoint address */
Jean-François Moine35680ba2010-07-14 06:30:18 -0300209 u8 audio; /* presence of audio device */
Hans Verkuila3d6e8c2012-05-06 09:28:27 -0300210
211 /* (*) These variables are proteced by both usb_lock and queue_lock,
212 that is any code setting them is holding *both*, which means that
213 any code getting them needs to hold at least one of them */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300214};
215
216int gspca_dev_probe(struct usb_interface *intf,
217 const struct usb_device_id *id,
218 const struct sd_desc *sd_desc,
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300219 int dev_size,
220 struct module *module);
Jean-François Moine44628642010-06-05 07:47:36 -0300221int gspca_dev_probe2(struct usb_interface *intf,
222 const struct usb_device_id *id,
223 const struct sd_desc *sd_desc,
224 int dev_size,
225 struct module *module);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300226void gspca_disconnect(struct usb_interface *intf);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300227void gspca_frame_add(struct gspca_dev *gspca_dev,
228 enum gspca_packet_type packet_type,
229 const u8 *data,
230 int len);
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300231#ifdef CONFIG_PM
232int gspca_suspend(struct usb_interface *intf, pm_message_t message);
233int gspca_resume(struct usb_interface *intf);
234#endif
Hans de Goede8cd05842012-05-09 09:58:33 -0300235int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
236 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
237int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
Antonio Ospite751e78d2014-06-04 09:03:40 -0300238 int avg_lum, int desired_avg_lum, int deadzone);
Hans de Goede8cd05842012-05-09 09:58:33 -0300239
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300240#endif /* GSPCAV2_H */