gspca.h 7.3 KB

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