gspca.h 7.3 KB

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