Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef GSPCAV2_H
0003 #define GSPCAV2_H
0004 
0005 #include <linux/module.h>
0006 #include <linux/kernel.h>
0007 #include <linux/usb.h>
0008 #include <linux/videodev2.h>
0009 #include <media/v4l2-common.h>
0010 #include <media/v4l2-ctrls.h>
0011 #include <media/v4l2-device.h>
0012 #include <media/videobuf2-v4l2.h>
0013 #include <media/videobuf2-vmalloc.h>
0014 #include <linux/mutex.h>
0015 
0016 
0017 
0018 /* GSPCA debug codes */
0019 
0020 #define D_PROBE  1
0021 #define D_CONF   2
0022 #define D_STREAM 3
0023 #define D_FRAM   4
0024 #define D_PACK   5
0025 #define D_USBI   6
0026 #define D_USBO   7
0027 
0028 extern int gspca_debug;
0029 
0030 
0031 #define gspca_dbg(gspca_dev, level, fmt, ...)           \
0032     v4l2_dbg(level, gspca_debug, &(gspca_dev)->v4l2_dev,    \
0033          fmt, ##__VA_ARGS__)
0034 
0035 #define gspca_err(gspca_dev, fmt, ...)              \
0036     v4l2_err(&(gspca_dev)->v4l2_dev, fmt, ##__VA_ARGS__)
0037 
0038 #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
0039 /* image transfers */
0040 #define MAX_NURBS 4     /* max number of URBs */
0041 
0042 
0043 /* used to list framerates supported by a camera mode (resolution) */
0044 struct framerates {
0045     const u8 *rates;
0046     int nrates;
0047 };
0048 
0049 /* device information - set at probe time */
0050 struct cam {
0051     const struct v4l2_pix_format *cam_mode; /* size nmodes */
0052     const struct framerates *mode_framerates; /* must have size nmodes,
0053                            * just like cam_mode */
0054     u32 bulk_size;      /* buffer size when image transfer by bulk */
0055     u32 input_flags;    /* value for ENUM_INPUT status flags */
0056     u8 nmodes;      /* size of cam_mode */
0057     u8 no_urb_create;   /* don't create transfer URBs */
0058     u8 bulk_nurbs;      /* number of URBs in bulk mode
0059                  * - cannot be > MAX_NURBS
0060                  * - when 0 and bulk_size != 0 means
0061                  *   1 URB and submit done by subdriver */
0062     u8 bulk;        /* image transfer by 0:isoc / 1:bulk */
0063     u8 npkt;        /* number of packets in an ISOC message
0064                  * 0 is the default value: 32 packets */
0065     u8 needs_full_bandwidth;/* Set this flag to notify the bandwidth calc.
0066                  * code that the cam fills all image buffers to
0067                  * the max, even when using compression. */
0068 };
0069 
0070 struct gspca_dev;
0071 struct gspca_frame;
0072 
0073 /* subdriver operations */
0074 typedef int (*cam_op) (struct gspca_dev *);
0075 typedef void (*cam_v_op) (struct gspca_dev *);
0076 typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
0077 typedef int (*cam_get_jpg_op) (struct gspca_dev *,
0078                 struct v4l2_jpegcompression *);
0079 typedef int (*cam_set_jpg_op) (struct gspca_dev *,
0080                 const struct v4l2_jpegcompression *);
0081 typedef int (*cam_get_reg_op) (struct gspca_dev *,
0082                 struct v4l2_dbg_register *);
0083 typedef int (*cam_set_reg_op) (struct gspca_dev *,
0084                 const struct v4l2_dbg_register *);
0085 typedef int (*cam_chip_info_op) (struct gspca_dev *,
0086                 struct v4l2_dbg_chip_info *);
0087 typedef void (*cam_streamparm_op) (struct gspca_dev *,
0088                   struct v4l2_streamparm *);
0089 typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
0090                 u8 *data,
0091                 int len);
0092 typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
0093                 u8 *data,
0094                 int len);
0095 typedef void (*cam_format_op) (struct gspca_dev *gspca_dev,
0096                 struct v4l2_format *fmt);
0097 typedef int (*cam_frmsize_op) (struct gspca_dev *gspca_dev,
0098                 struct v4l2_frmsizeenum *fsize);
0099 
0100 /* subdriver description */
0101 struct sd_desc {
0102 /* information */
0103     const char *name;   /* sub-driver name */
0104 /* mandatory operations */
0105     cam_cf_op config;   /* called on probe */
0106     cam_op init;        /* called on probe and resume */
0107     cam_op init_controls;   /* called on probe */
0108     cam_v_op probe_error;   /* called if probe failed, do cleanup here */
0109     cam_op start;       /* called on stream on after URBs creation */
0110     cam_pkt_op pkt_scan;
0111 /* optional operations */
0112     cam_op isoc_init;   /* called on stream on before getting the EP */
0113     cam_op isoc_nego;   /* called when URB submit failed with NOSPC */
0114     cam_v_op stopN;     /* called on stream off - main alt */
0115     cam_v_op stop0;     /* called on stream off & disconnect - alt 0 */
0116     cam_v_op dq_callback;   /* called when a frame has been dequeued */
0117     cam_get_jpg_op get_jcomp;
0118     cam_set_jpg_op set_jcomp;
0119     cam_streamparm_op get_streamparm;
0120     cam_streamparm_op set_streamparm;
0121     cam_format_op try_fmt;
0122     cam_frmsize_op enum_framesizes;
0123 #ifdef CONFIG_VIDEO_ADV_DEBUG
0124     cam_set_reg_op set_register;
0125     cam_get_reg_op get_register;
0126     cam_chip_info_op get_chip_info;
0127 #endif
0128 #if IS_ENABLED(CONFIG_INPUT)
0129     cam_int_pkt_op int_pkt_scan;
0130     /* other_input makes the gspca core create gspca_dev->input even when
0131        int_pkt_scan is NULL, for cams with non interrupt driven buttons */
0132     u8 other_input;
0133 #endif
0134 };
0135 
0136 /* packet types when moving from iso buf to frame buf */
0137 enum gspca_packet_type {
0138     DISCARD_PACKET,
0139     FIRST_PACKET,
0140     INTER_PACKET,
0141     LAST_PACKET
0142 };
0143 
0144 struct gspca_buffer {
0145     struct vb2_v4l2_buffer vb;
0146     struct list_head list;
0147 };
0148 
0149 static inline struct gspca_buffer *to_gspca_buffer(struct vb2_buffer *vb2)
0150 {
0151     return container_of(vb2, struct gspca_buffer, vb.vb2_buf);
0152 }
0153 
0154 struct gspca_dev {
0155     struct video_device vdev;   /* !! must be the first item */
0156     struct module *module;      /* subdriver handling the device */
0157     struct v4l2_device v4l2_dev;
0158     struct usb_device *dev;
0159 
0160 #if IS_ENABLED(CONFIG_INPUT)
0161     struct input_dev *input_dev;
0162     char phys[64];          /* physical device path */
0163 #endif
0164 
0165     struct cam cam;             /* device information */
0166     const struct sd_desc *sd_desc;      /* subdriver description */
0167     struct v4l2_ctrl_handler ctrl_handler;
0168 
0169     /* autogain and exposure or gain control cluster, these are global as
0170        the autogain/exposure functions in autogain_functions.c use them */
0171     struct {
0172         struct v4l2_ctrl *autogain;
0173         struct v4l2_ctrl *exposure;
0174         struct v4l2_ctrl *gain;
0175         int exp_too_low_cnt, exp_too_high_cnt;
0176     };
0177 
0178 #define USB_BUF_SZ 64
0179     __u8 *usb_buf;              /* buffer for USB exchanges */
0180     struct urb *urb[MAX_NURBS];
0181 #if IS_ENABLED(CONFIG_INPUT)
0182     struct urb *int_urb;
0183 #endif
0184 
0185     u8 *image;              /* image being filled */
0186     u32 image_len;              /* current length of image */
0187     __u8 last_packet_type;
0188     __s8 empty_packet;      /* if (-1) don't check empty packets */
0189     bool streaming;
0190 
0191     __u8 curr_mode;         /* current camera mode */
0192     struct v4l2_pix_format pixfmt;  /* current mode parameters */
0193     __u32 sequence;         /* frame sequence number */
0194 
0195     struct vb2_queue queue;
0196 
0197     spinlock_t qlock;
0198     struct list_head buf_list;
0199 
0200     wait_queue_head_t wq;       /* wait queue */
0201     struct mutex usb_lock;      /* usb exchange protection */
0202     int usb_err;            /* USB error - protected by usb_lock */
0203     u16 pkt_size;           /* ISOC packet size */
0204 #ifdef CONFIG_PM
0205     char frozen;            /* suspend - resume */
0206 #endif
0207     bool present;
0208     char memory;            /* memory type (V4L2_MEMORY_xxx) */
0209     __u8 iface;         /* USB interface number */
0210     __u8 alt;           /* USB alternate setting */
0211     int xfer_ep;            /* USB transfer endpoint address */
0212     u8 audio;           /* presence of audio device */
0213 
0214     /* (*) These variables are proteced by both usb_lock and queue_lock,
0215        that is any code setting them is holding *both*, which means that
0216        any code getting them needs to hold at least one of them */
0217 };
0218 
0219 int gspca_dev_probe(struct usb_interface *intf,
0220         const struct usb_device_id *id,
0221         const struct sd_desc *sd_desc,
0222         int dev_size,
0223         struct module *module);
0224 int gspca_dev_probe2(struct usb_interface *intf,
0225         const struct usb_device_id *id,
0226         const struct sd_desc *sd_desc,
0227         int dev_size,
0228         struct module *module);
0229 void gspca_disconnect(struct usb_interface *intf);
0230 void gspca_frame_add(struct gspca_dev *gspca_dev,
0231             enum gspca_packet_type packet_type,
0232             const u8 *data,
0233             int len);
0234 #ifdef CONFIG_PM
0235 int gspca_suspend(struct usb_interface *intf, pm_message_t message);
0236 int gspca_resume(struct usb_interface *intf);
0237 #endif
0238 int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
0239     int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
0240 int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
0241     int avg_lum, int desired_avg_lum, int deadzone);
0242 
0243 #endif /* GSPCAV2_H */