gspca.h 7.7 KB

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