gspca.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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_get_reg_op) (struct gspca_dev *,
  63. struct v4l2_dbg_register *);
  64. typedef int (*cam_set_reg_op) (struct gspca_dev *,
  65. const struct v4l2_dbg_register *);
  66. typedef int (*cam_chip_info_op) (struct gspca_dev *,
  67. struct v4l2_dbg_chip_info *);
  68. typedef void (*cam_streamparm_op) (struct gspca_dev *,
  69. struct v4l2_streamparm *);
  70. typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
  71. u8 *data,
  72. int len);
  73. typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
  74. u8 *data,
  75. int len);
  76. /* subdriver description */
  77. struct sd_desc {
  78. /* information */
  79. const char *name; /* sub-driver name */
  80. /* mandatory operations */
  81. cam_cf_op config; /* called on probe */
  82. cam_op init; /* called on probe and resume */
  83. cam_op init_controls; /* called on probe */
  84. cam_op start; /* called on stream on after URBs creation */
  85. cam_pkt_op pkt_scan;
  86. /* optional operations */
  87. cam_op isoc_init; /* called on stream on before getting the EP */
  88. cam_op isoc_nego; /* called when URB submit failed with NOSPC */
  89. cam_v_op stopN; /* called on stream off - main alt */
  90. cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
  91. cam_v_op dq_callback; /* called when a frame has been dequeued */
  92. cam_get_jpg_op get_jcomp;
  93. cam_set_jpg_op set_jcomp;
  94. cam_streamparm_op get_streamparm;
  95. cam_streamparm_op set_streamparm;
  96. #ifdef CONFIG_VIDEO_ADV_DEBUG
  97. cam_set_reg_op set_register;
  98. cam_get_reg_op get_register;
  99. cam_chip_info_op get_chip_info;
  100. #endif
  101. #if IS_ENABLED(CONFIG_INPUT)
  102. cam_int_pkt_op int_pkt_scan;
  103. /* other_input makes the gspca core create gspca_dev->input even when
  104. int_pkt_scan is NULL, for cams with non interrupt driven buttons */
  105. u8 other_input;
  106. #endif
  107. };
  108. /* packet types when moving from iso buf to frame buf */
  109. enum gspca_packet_type {
  110. DISCARD_PACKET,
  111. FIRST_PACKET,
  112. INTER_PACKET,
  113. LAST_PACKET
  114. };
  115. struct gspca_frame {
  116. __u8 *data; /* frame buffer */
  117. int vma_use_count;
  118. struct v4l2_buffer v4l2_buf;
  119. };
  120. struct gspca_dev {
  121. struct video_device vdev; /* !! must be the first item */
  122. struct module *module; /* subdriver handling the device */
  123. struct v4l2_device v4l2_dev;
  124. struct usb_device *dev;
  125. struct file *capt_file; /* file doing video capture */
  126. /* protected by queue_lock */
  127. #if IS_ENABLED(CONFIG_INPUT)
  128. struct input_dev *input_dev;
  129. char phys[64]; /* physical device path */
  130. #endif
  131. struct cam cam; /* device information */
  132. const struct sd_desc *sd_desc; /* subdriver description */
  133. struct v4l2_ctrl_handler ctrl_handler;
  134. /* autogain and exposure or gain control cluster, these are global as
  135. the autogain/exposure functions in autogain_functions.c use them */
  136. struct {
  137. struct v4l2_ctrl *autogain;
  138. struct v4l2_ctrl *exposure;
  139. struct v4l2_ctrl *gain;
  140. int exp_too_low_cnt, exp_too_high_cnt;
  141. };
  142. #define USB_BUF_SZ 64
  143. __u8 *usb_buf; /* buffer for USB exchanges */
  144. struct urb *urb[MAX_NURBS];
  145. #if IS_ENABLED(CONFIG_INPUT)
  146. struct urb *int_urb;
  147. #endif
  148. __u8 *frbuf; /* buffer for nframes */
  149. struct gspca_frame frame[GSPCA_MAX_FRAMES];
  150. u8 *image; /* image beeing filled */
  151. __u32 frsz; /* frame size */
  152. u32 image_len; /* current length of image */
  153. atomic_t fr_q; /* next frame to queue */
  154. atomic_t fr_i; /* frame being filled */
  155. signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
  156. char nframes; /* number of frames */
  157. u8 fr_o; /* next frame to dequeue */
  158. __u8 last_packet_type;
  159. __s8 empty_packet; /* if (-1) don't check empty packets */
  160. __u8 streaming; /* protected by both mutexes (*) */
  161. __u8 curr_mode; /* current camera mode */
  162. __u32 pixfmt; /* current mode parameters */
  163. __u16 width;
  164. __u16 height;
  165. __u32 sequence; /* frame sequence number */
  166. wait_queue_head_t wq; /* wait queue */
  167. struct mutex usb_lock; /* usb exchange protection */
  168. struct mutex queue_lock; /* ISOC queue protection */
  169. int usb_err; /* USB error - protected by usb_lock */
  170. u16 pkt_size; /* ISOC packet size */
  171. #ifdef CONFIG_PM
  172. char frozen; /* suspend - resume */
  173. #endif
  174. char present; /* device connected */
  175. char nbufread; /* number of buffers for read() */
  176. char memory; /* memory type (V4L2_MEMORY_xxx) */
  177. __u8 iface; /* USB interface number */
  178. __u8 alt; /* USB alternate setting */
  179. u8 audio; /* presence of audio device */
  180. /* (*) These variables are proteced by both usb_lock and queue_lock,
  181. that is any code setting them is holding *both*, which means that
  182. any code getting them needs to hold at least one of them */
  183. };
  184. int gspca_dev_probe(struct usb_interface *intf,
  185. const struct usb_device_id *id,
  186. const struct sd_desc *sd_desc,
  187. int dev_size,
  188. struct module *module);
  189. int gspca_dev_probe2(struct usb_interface *intf,
  190. const struct usb_device_id *id,
  191. const struct sd_desc *sd_desc,
  192. int dev_size,
  193. struct module *module);
  194. void gspca_disconnect(struct usb_interface *intf);
  195. void gspca_frame_add(struct gspca_dev *gspca_dev,
  196. enum gspca_packet_type packet_type,
  197. const u8 *data,
  198. int len);
  199. #ifdef CONFIG_PM
  200. int gspca_suspend(struct usb_interface *intf, pm_message_t message);
  201. int gspca_resume(struct usb_interface *intf);
  202. #endif
  203. int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum,
  204. int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
  205. int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
  206. int avg_lum, int desired_avg_lum, int deadzone);
  207. #endif /* GSPCAV2_H */