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