gspca.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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_v_op probe_error; /* called if probe failed, do cleanup here */
  93. cam_op start; /* called on stream on after URBs creation */
  94. cam_pkt_op pkt_scan;
  95. /* optional operations */
  96. cam_op isoc_init; /* called on stream on before getting the EP */
  97. cam_op isoc_nego; /* called when URB submit failed with NOSPC */
  98. cam_v_op stopN; /* called on stream off - main alt */
  99. cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
  100. cam_v_op dq_callback; /* called when a frame has been dequeued */
  101. cam_get_jpg_op get_jcomp;
  102. cam_set_jpg_op set_jcomp;
  103. cam_streamparm_op get_streamparm;
  104. cam_streamparm_op set_streamparm;
  105. cam_format_op try_fmt;
  106. cam_frmsize_op enum_framesizes;
  107. #ifdef CONFIG_VIDEO_ADV_DEBUG
  108. cam_set_reg_op set_register;
  109. cam_get_reg_op get_register;
  110. cam_chip_info_op get_chip_info;
  111. #endif
  112. #if IS_ENABLED(CONFIG_INPUT)
  113. cam_int_pkt_op int_pkt_scan;
  114. /* other_input makes the gspca core create gspca_dev->input even when
  115. int_pkt_scan is NULL, for cams with non interrupt driven buttons */
  116. u8 other_input;
  117. #endif
  118. };
  119. /* packet types when moving from iso buf to frame buf */
  120. enum gspca_packet_type {
  121. DISCARD_PACKET,
  122. FIRST_PACKET,
  123. INTER_PACKET,
  124. LAST_PACKET
  125. };
  126. struct gspca_buffer {
  127. struct vb2_v4l2_buffer vb;
  128. struct list_head list;
  129. };
  130. static inline struct gspca_buffer *to_gspca_buffer(struct vb2_buffer *vb2)
  131. {
  132. return container_of(vb2, struct gspca_buffer, vb.vb2_buf);
  133. }
  134. struct gspca_dev {
  135. struct video_device vdev; /* !! must be the first item */
  136. struct module *module; /* subdriver handling the device */
  137. struct v4l2_device v4l2_dev;
  138. struct usb_device *dev;
  139. #if IS_ENABLED(CONFIG_INPUT)
  140. struct input_dev *input_dev;
  141. char phys[64]; /* physical device path */
  142. #endif
  143. struct cam cam; /* device information */
  144. const struct sd_desc *sd_desc; /* subdriver description */
  145. struct v4l2_ctrl_handler ctrl_handler;
  146. /* autogain and exposure or gain control cluster, these are global as
  147. the autogain/exposure functions in autogain_functions.c use them */
  148. struct {
  149. struct v4l2_ctrl *autogain;
  150. struct v4l2_ctrl *exposure;
  151. struct v4l2_ctrl *gain;
  152. int exp_too_low_cnt, exp_too_high_cnt;
  153. };
  154. #define USB_BUF_SZ 64
  155. __u8 *usb_buf; /* buffer for USB exchanges */
  156. struct urb *urb[MAX_NURBS];
  157. #if IS_ENABLED(CONFIG_INPUT)
  158. struct urb *int_urb;
  159. #endif
  160. u8 *image; /* image being filled */
  161. u32 image_len; /* current length of image */
  162. __u8 last_packet_type;
  163. __s8 empty_packet; /* if (-1) don't check empty packets */
  164. bool streaming;
  165. __u8 curr_mode; /* current camera mode */
  166. struct v4l2_pix_format pixfmt; /* current mode parameters */
  167. __u32 sequence; /* frame sequence number */
  168. struct vb2_queue queue;
  169. spinlock_t qlock;
  170. struct list_head buf_list;
  171. wait_queue_head_t wq; /* wait queue */
  172. struct mutex usb_lock; /* usb exchange protection */
  173. int usb_err; /* USB error - protected by usb_lock */
  174. u16 pkt_size; /* ISOC packet size */
  175. #ifdef CONFIG_PM
  176. char frozen; /* suspend - resume */
  177. #endif
  178. bool present;
  179. char memory; /* memory type (V4L2_MEMORY_xxx) */
  180. __u8 iface; /* USB interface number */
  181. __u8 alt; /* USB alternate setting */
  182. int xfer_ep; /* USB transfer endpoint address */
  183. u8 audio; /* presence of audio device */
  184. /* (*) These variables are proteced by both usb_lock and queue_lock,
  185. that is any code setting them is holding *both*, which means that
  186. any code getting them needs to hold at least one of them */
  187. };
  188. int gspca_dev_probe(struct usb_interface *intf,
  189. const struct usb_device_id *id,
  190. const struct sd_desc *sd_desc,
  191. int dev_size,
  192. struct module *module);
  193. int gspca_dev_probe2(struct usb_interface *intf,
  194. const struct usb_device_id *id,
  195. const struct sd_desc *sd_desc,
  196. int dev_size,
  197. struct module *module);
  198. void gspca_disconnect(struct usb_interface *intf);
  199. void gspca_frame_add(struct gspca_dev *gspca_dev,
  200. enum gspca_packet_type packet_type,
  201. const u8 *data,
  202. int len);
  203. #ifdef CONFIG_PM
  204. int gspca_suspend(struct usb_interface *intf, pm_message_t message);
  205. int gspca_resume(struct usb_interface *intf);
  206. #endif
  207. int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
  208. int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
  209. int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
  210. int avg_lum, int desired_avg_lum, int deadzone);
  211. #endif /* GSPCAV2_H */