gspca.h 8.2 KB

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