gspca.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef GSPCAV2_H
  3. #define GSPCAV2_H
  4. #include <linux/module.h>
  5. #include <linux/kernel.h>
  6. #include <linux/usb.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 <media/videobuf2-v4l2.h>
  12. #include <media/videobuf2-vmalloc.h>
  13. #include <linux/mutex.h>
  14. /* GSPCA debug codes */
  15. #define D_PROBE 1
  16. #define D_CONF 2
  17. #define D_STREAM 3
  18. #define D_FRAM 4
  19. #define D_PACK 5
  20. #define D_USBI 6
  21. #define D_USBO 7
  22. extern int gspca_debug;
  23. #define gspca_dbg(gspca_dev, level, fmt, ...) \
  24. v4l2_dbg(level, gspca_debug, &(gspca_dev)->v4l2_dev, \
  25. fmt, ##__VA_ARGS__)
  26. #define gspca_err(gspca_dev, fmt, ...) \
  27. v4l2_err(&(gspca_dev)->v4l2_dev, fmt, ##__VA_ARGS__)
  28. #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
  29. /* image transfers */
  30. #define MAX_NURBS 4 /* max number of URBs */
  31. /* used to list framerates supported by a camera mode (resolution) */
  32. struct framerates {
  33. const u8 *rates;
  34. int nrates;
  35. };
  36. /* device information - set at probe time */
  37. struct cam {
  38. const struct v4l2_pix_format *cam_mode; /* size nmodes */
  39. const struct framerates *mode_framerates; /* must have size nmodes,
  40. * just like cam_mode */
  41. u32 bulk_size; /* buffer size when image transfer by bulk */
  42. u32 input_flags; /* value for ENUM_INPUT status flags */
  43. u8 nmodes; /* size of cam_mode */
  44. u8 no_urb_create; /* don't create transfer URBs */
  45. u8 bulk_nurbs; /* number of URBs in bulk mode
  46. * - cannot be > MAX_NURBS
  47. * - when 0 and bulk_size != 0 means
  48. * 1 URB and submit done by subdriver */
  49. u8 bulk; /* image transfer by 0:isoc / 1:bulk */
  50. u8 npkt; /* number of packets in an ISOC message
  51. * 0 is the default value: 32 packets */
  52. u8 needs_full_bandwidth;/* Set this flag to notify the bandwidth calc.
  53. * code that the cam fills all image buffers to
  54. * the max, even when using compression. */
  55. };
  56. struct gspca_dev;
  57. struct gspca_frame;
  58. /* subdriver operations */
  59. typedef int (*cam_op) (struct gspca_dev *);
  60. typedef void (*cam_v_op) (struct gspca_dev *);
  61. typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
  62. typedef int (*cam_get_jpg_op) (struct gspca_dev *,
  63. struct v4l2_jpegcompression *);
  64. typedef int (*cam_set_jpg_op) (struct gspca_dev *,
  65. const struct v4l2_jpegcompression *);
  66. typedef int (*cam_get_reg_op) (struct gspca_dev *,
  67. struct v4l2_dbg_register *);
  68. typedef int (*cam_set_reg_op) (struct gspca_dev *,
  69. const struct v4l2_dbg_register *);
  70. typedef int (*cam_chip_info_op) (struct gspca_dev *,
  71. struct v4l2_dbg_chip_info *);
  72. typedef void (*cam_streamparm_op) (struct gspca_dev *,
  73. struct v4l2_streamparm *);
  74. typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
  75. u8 *data,
  76. int len);
  77. typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
  78. u8 *data,
  79. int len);
  80. typedef void (*cam_format_op) (struct gspca_dev *gspca_dev,
  81. struct v4l2_format *fmt);
  82. typedef int (*cam_frmsize_op) (struct gspca_dev *gspca_dev,
  83. struct v4l2_frmsizeenum *fsize);
  84. /* subdriver description */
  85. struct sd_desc {
  86. /* information */
  87. const char *name; /* sub-driver name */
  88. /* mandatory operations */
  89. cam_cf_op config; /* called on probe */
  90. cam_op init; /* called on probe and resume */
  91. cam_op init_controls; /* called on probe */
  92. cam_op start; /* called on stream on after URBs creation */
  93. cam_pkt_op pkt_scan;
  94. /* optional operations */
  95. cam_op isoc_init; /* called on stream on before getting the EP */
  96. cam_op isoc_nego; /* called when URB submit failed with NOSPC */
  97. cam_v_op stopN; /* called on stream off - main alt */
  98. cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
  99. cam_v_op dq_callback; /* called when a frame has been dequeued */
  100. cam_get_jpg_op get_jcomp;
  101. cam_set_jpg_op set_jcomp;
  102. cam_streamparm_op get_streamparm;
  103. cam_streamparm_op set_streamparm;
  104. cam_format_op try_fmt;
  105. cam_frmsize_op enum_framesizes;
  106. #ifdef CONFIG_VIDEO_ADV_DEBUG
  107. cam_set_reg_op set_register;
  108. cam_get_reg_op get_register;
  109. cam_chip_info_op get_chip_info;
  110. #endif
  111. #if IS_ENABLED(CONFIG_INPUT)
  112. cam_int_pkt_op int_pkt_scan;
  113. /* other_input makes the gspca core create gspca_dev->input even when
  114. int_pkt_scan is NULL, for cams with non interrupt driven buttons */
  115. u8 other_input;
  116. #endif
  117. };
  118. /* packet types when moving from iso buf to frame buf */
  119. enum gspca_packet_type {
  120. DISCARD_PACKET,
  121. FIRST_PACKET,
  122. INTER_PACKET,
  123. LAST_PACKET
  124. };
  125. struct gspca_buffer {
  126. struct vb2_v4l2_buffer vb;
  127. struct list_head list;
  128. };
  129. static inline struct gspca_buffer *to_gspca_buffer(struct vb2_buffer *vb2)
  130. {
  131. return container_of(vb2, struct gspca_buffer, vb.vb2_buf);
  132. }
  133. struct gspca_dev {
  134. struct video_device vdev; /* !! must be the first item */
  135. struct module *module; /* subdriver handling the device */
  136. struct v4l2_device v4l2_dev;
  137. struct usb_device *dev;
  138. #if IS_ENABLED(CONFIG_INPUT)
  139. struct input_dev *input_dev;
  140. char phys[64]; /* physical device path */
  141. #endif
  142. struct cam cam; /* device information */
  143. const struct sd_desc *sd_desc; /* subdriver description */
  144. struct v4l2_ctrl_handler ctrl_handler;
  145. /* autogain and exposure or gain control cluster, these are global as
  146. the autogain/exposure functions in autogain_functions.c use them */
  147. struct {
  148. struct v4l2_ctrl *autogain;
  149. struct v4l2_ctrl *exposure;
  150. struct v4l2_ctrl *gain;
  151. int exp_too_low_cnt, exp_too_high_cnt;
  152. };
  153. #define USB_BUF_SZ 64
  154. __u8 *usb_buf; /* buffer for USB exchanges */
  155. struct urb *urb[MAX_NURBS];
  156. #if IS_ENABLED(CONFIG_INPUT)
  157. struct urb *int_urb;
  158. #endif
  159. u8 *image; /* image being filled */
  160. u32 image_len; /* current length of image */
  161. __u8 last_packet_type;
  162. __s8 empty_packet; /* if (-1) don't check empty packets */
  163. bool streaming;
  164. __u8 curr_mode; /* current camera mode */
  165. struct v4l2_pix_format pixfmt; /* current mode parameters */
  166. __u32 sequence; /* frame sequence number */
  167. struct vb2_queue queue;
  168. spinlock_t qlock;
  169. struct list_head buf_list;
  170. wait_queue_head_t wq; /* wait queue */
  171. struct mutex usb_lock; /* usb exchange protection */
  172. int usb_err; /* USB error - protected by usb_lock */
  173. u16 pkt_size; /* ISOC packet size */
  174. #ifdef CONFIG_PM
  175. char frozen; /* suspend - resume */
  176. #endif
  177. bool present;
  178. char memory; /* memory type (V4L2_MEMORY_xxx) */
  179. __u8 iface; /* USB interface number */
  180. __u8 alt; /* USB alternate setting */
  181. int xfer_ep; /* USB transfer endpoint address */
  182. u8 audio; /* presence of audio device */
  183. /* (*) These variables are proteced by both usb_lock and queue_lock,
  184. that is any code setting them is holding *both*, which means that
  185. any code getting them needs to hold at least one of them */
  186. };
  187. int gspca_dev_probe(struct usb_interface *intf,
  188. const struct usb_device_id *id,
  189. const struct sd_desc *sd_desc,
  190. int dev_size,
  191. struct module *module);
  192. int gspca_dev_probe2(struct usb_interface *intf,
  193. const struct usb_device_id *id,
  194. const struct sd_desc *sd_desc,
  195. int dev_size,
  196. struct module *module);
  197. void gspca_disconnect(struct usb_interface *intf);
  198. void gspca_frame_add(struct gspca_dev *gspca_dev,
  199. enum gspca_packet_type packet_type,
  200. const u8 *data,
  201. int len);
  202. #ifdef CONFIG_PM
  203. int gspca_suspend(struct usb_interface *intf, pm_message_t message);
  204. int gspca_resume(struct usb_interface *intf);
  205. #endif
  206. int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
  207. int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
  208. int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
  209. int avg_lum, int desired_avg_lum, int deadzone);
  210. #endif /* GSPCAV2_H */