blob: 0f3d15002555c62821308c32cd4b5b91df634a08 [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);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030091
Jean-Francois Moine63eb9542008-04-12 09:58:09 -030092/* subdriver description */
93struct sd_desc {
94/* information */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -030095 const char *name; /* sub-driver name */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -030096/* mandatory operations */
Hans de Goedee2997a72008-04-23 08:09:12 -030097 cam_cf_op config; /* called on probe */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -030098 cam_op init; /* called on probe and resume */
Hans Verkuil62bba5d2012-05-06 09:28:17 -030099 cam_op init_controls; /* called on probe */
Jean-Francois Moine1f53b0b2009-06-30 07:07:01 -0300100 cam_op start; /* called on stream on after URBs creation */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300101 cam_pkt_op pkt_scan;
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300102/* optional operations */
Jean-Francois Moine1f53b0b2009-06-30 07:07:01 -0300103 cam_op isoc_init; /* called on stream on before getting the EP */
104 cam_op isoc_nego; /* called when URB submit failed with NOSPC */
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300105 cam_v_op stopN; /* called on stream off - main alt */
Jean-Francois Moine98522a72008-11-18 06:33:08 -0300106 cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300107 cam_v_op dq_callback; /* called when a frame has been dequeued */
Hans Verkuild88aab52012-09-17 05:05:25 -0300108 cam_get_jpg_op get_jcomp;
109 cam_set_jpg_op set_jcomp;
Jim Paris627a5ef2008-12-10 06:02:42 -0300110 cam_streamparm_op get_streamparm;
111 cam_streamparm_op set_streamparm;
Brian Johnsonaf1d9af2009-07-19 05:29:20 -0300112#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuil977ba3b2013-03-24 08:28:46 -0300113 cam_set_reg_op set_register;
114 cam_get_reg_op get_register;
Hans Verkuilb1c85cc2013-05-29 06:59:42 -0300115 cam_chip_info_op get_chip_info;
Brian Johnsonaf1d9af2009-07-19 05:29:20 -0300116#endif
Peter Senna Tschudin13a00fa2013-01-24 19:28:59 -0300117#if IS_ENABLED(CONFIG_INPUT)
Márton Németh0274d422010-01-28 06:39:49 -0300118 cam_int_pkt_op int_pkt_scan;
Hans de Goedeac82f592010-02-19 04:28:39 -0300119 /* 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 */
121 u8 other_input;
Márton Németh0274d422010-01-28 06:39:49 -0300122#endif
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300123};
124
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300125/* packet types when moving from iso buf to frame buf */
Erik Andrene293e592008-10-03 08:46:50 -0300126enum gspca_packet_type {
127 DISCARD_PACKET,
128 FIRST_PACKET,
129 INTER_PACKET,
130 LAST_PACKET
131};
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300132
133struct gspca_frame {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300134 __u8 *data; /* frame buffer */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300135 int vma_use_count;
136 struct v4l2_buffer v4l2_buf;
137};
138
139struct gspca_dev {
Jean-Francois Moinea12ca6a2008-11-19 06:37:53 -0300140 struct video_device vdev; /* !! must be the first item */
Jean-Francois Moine5c4fa0022008-11-18 15:52:31 -0300141 struct module *module; /* subdriver handling the device */
Hans Verkuil23335652012-05-06 09:28:19 -0300142 struct v4l2_device v4l2_dev;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300143 struct usb_device *dev;
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300144 struct file *capt_file; /* file doing video capture */
Hans Verkuila3d6e8c2012-05-06 09:28:27 -0300145 /* protected by queue_lock */
Peter Senna Tschudin13a00fa2013-01-24 19:28:59 -0300146#if IS_ENABLED(CONFIG_INPUT)
Márton Németh0274d422010-01-28 06:39:49 -0300147 struct input_dev *input_dev;
148 char phys[64]; /* physical device path */
149#endif
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300150
151 struct cam cam; /* device information */
152 const struct sd_desc *sd_desc; /* subdriver description */
Hans de Goedea8a47862012-05-09 11:19:00 -0300153 struct v4l2_ctrl_handler ctrl_handler;
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300154
Hans de Goede8cd05842012-05-09 09:58:33 -0300155 /* autogain and exposure or gain control cluster, these are global as
156 the autogain/exposure functions in autogain_functions.c use them */
157 struct {
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;
162 };
163
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300164#define USB_BUF_SZ 64
165 __u8 *usb_buf; /* buffer for USB exchanges */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300166 struct urb *urb[MAX_NURBS];
Peter Senna Tschudin13a00fa2013-01-24 19:28:59 -0300167#if IS_ENABLED(CONFIG_INPUT)
Márton Németh0274d422010-01-28 06:39:49 -0300168 struct urb *int_urb;
169#endif
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300170
171 __u8 *frbuf; /* buffer for nframes */
172 struct gspca_frame frame[GSPCA_MAX_FRAMES];
Jean-François Moineb192ca92010-06-27 03:08:19 -0300173 u8 *image; /* image beeing filled */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300174 __u32 frsz; /* frame size */
Jean-François Moineb192ca92010-06-27 03:08:19 -0300175 u32 image_len; /* current length of image */
Jean-François Moinef7059ea2010-07-06 04:32:27 -0300176 atomic_t fr_q; /* next frame to queue */
177 atomic_t fr_i; /* frame being filled */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300178 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
Jean-François Moinef7059ea2010-07-06 04:32:27 -0300179 char nframes; /* number of frames */
180 u8 fr_o; /* next frame to dequeue */
Jean-Francois Moineff374742008-10-23 07:29:51 -0300181 __u8 last_packet_type;
182 __s8 empty_packet; /* if (-1) don't check empty packets */
Hans Verkuila3d6e8c2012-05-06 09:28:27 -0300183 __u8 streaming; /* protected by both mutexes (*) */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300184
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300185 __u8 curr_mode; /* current camera mode */
Ondrej Zary1966bc22013-08-30 17:54:23 -0300186 struct v4l2_pix_format pixfmt; /* current mode parameters */
Jean-Francois Moineff374742008-10-23 07:29:51 -0300187 __u32 sequence; /* frame sequence number */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300188
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300189 wait_queue_head_t wq; /* wait queue */
190 struct mutex usb_lock; /* usb exchange protection */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300191 struct mutex queue_lock; /* ISOC queue protection */
Jean-Francois Moine8c4ebae2009-12-02 07:14:33 -0300192 int usb_err; /* USB error - protected by usb_lock */
Jean-François Moine35680ba2010-07-14 06:30:18 -0300193 u16 pkt_size; /* ISOC packet size */
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300194#ifdef CONFIG_PM
195 char frozen; /* suspend - resume */
196#endif
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300197 char present; /* device connected */
198 char nbufread; /* number of buffers for read() */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300199 char memory; /* memory type (V4L2_MEMORY_xxx) */
Jean-Francois Moineff374742008-10-23 07:29:51 -0300200 __u8 iface; /* USB interface number */
201 __u8 alt; /* USB alternate setting */
Jean-François Moine35680ba2010-07-14 06:30:18 -0300202 u8 audio; /* presence of audio device */
Hans Verkuila3d6e8c2012-05-06 09:28:27 -0300203
204 /* (*) These variables are proteced by both usb_lock and queue_lock,
205 that is any code setting them is holding *both*, which means that
206 any code getting them needs to hold at least one of them */
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300207};
208
209int gspca_dev_probe(struct usb_interface *intf,
210 const struct usb_device_id *id,
211 const struct sd_desc *sd_desc,
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300212 int dev_size,
213 struct module *module);
Jean-François Moine44628642010-06-05 07:47:36 -0300214int gspca_dev_probe2(struct usb_interface *intf,
215 const struct usb_device_id *id,
216 const struct sd_desc *sd_desc,
217 int dev_size,
218 struct module *module);
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300219void gspca_disconnect(struct usb_interface *intf);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300220void gspca_frame_add(struct gspca_dev *gspca_dev,
221 enum gspca_packet_type packet_type,
222 const u8 *data,
223 int len);
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300224#ifdef CONFIG_PM
225int gspca_suspend(struct usb_interface *intf, pm_message_t message);
226int gspca_resume(struct usb_interface *intf);
227#endif
Hans de Goede8cd05842012-05-09 09:58:33 -0300228int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
229 int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
230int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
231 int avg_lum, int desired_avg_lum, int deadzone);
232
Jean-Francois Moine63eb9542008-04-12 09:58:09 -0300233#endif /* GSPCAV2_H */