gspca.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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, args...) \
  15. do {\
  16. if (gspca_debug & (level)) \
  17. printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## 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 0x40
  26. #define D_USBO 0x80
  27. #define D_V4L2 0x0100
  28. #else
  29. #define PDEBUG(level, fmt, args...)
  30. #endif
  31. #undef err
  32. #define err(fmt, args...) \
  33. printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args)
  34. #undef info
  35. #define info(fmt, args...) \
  36. printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args)
  37. #undef warn
  38. #define warn(fmt, args...) \
  39. printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args)
  40. #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
  41. /* image transfers */
  42. #define MAX_NURBS 4 /* max number of URBs */
  43. /* device information - set at probe time */
  44. struct cam {
  45. int bulk_size; /* buffer size when image transfer by bulk */
  46. const struct v4l2_pix_format *cam_mode; /* size nmodes */
  47. char nmodes;
  48. __u8 bulk_nurbs; /* number of URBs in bulk mode
  49. * - cannot be > MAX_NURBS
  50. * - when 0 and bulk_size != 0 means
  51. * 1 URB and submit done by subdriver */
  52. u8 bulk; /* image transfer by 0:isoc / 1:bulk */
  53. u8 npkt; /* number of packets in an ISOC message
  54. * 0 is the default value: 32 packets */
  55. u32 input_flags; /* value for ENUM_INPUT status flags */
  56. char reverse_alts; /* Alt settings are in high to low order */
  57. };
  58. struct gspca_dev;
  59. struct gspca_frame;
  60. /* subdriver operations */
  61. typedef int (*cam_op) (struct gspca_dev *);
  62. typedef void (*cam_v_op) (struct gspca_dev *);
  63. typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
  64. typedef int (*cam_jpg_op) (struct gspca_dev *,
  65. struct v4l2_jpegcompression *);
  66. typedef int (*cam_reg_op) (struct gspca_dev *,
  67. struct v4l2_dbg_register *);
  68. typedef int (*cam_ident_op) (struct gspca_dev *,
  69. struct v4l2_dbg_chip_ident *);
  70. typedef int (*cam_streamparm_op) (struct gspca_dev *,
  71. struct v4l2_streamparm *);
  72. typedef int (*cam_qmnu_op) (struct gspca_dev *,
  73. struct v4l2_querymenu *);
  74. typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
  75. u8 *data,
  76. int len);
  77. struct ctrl {
  78. struct v4l2_queryctrl qctrl;
  79. int (*set)(struct gspca_dev *, __s32);
  80. int (*get)(struct gspca_dev *, __s32 *);
  81. };
  82. /* subdriver description */
  83. struct sd_desc {
  84. /* information */
  85. const char *name; /* sub-driver name */
  86. /* controls */
  87. const struct ctrl *ctrls;
  88. int nctrls;
  89. /* mandatory operations */
  90. cam_cf_op config; /* called on probe */
  91. cam_op init; /* called on probe and resume */
  92. cam_op start; /* called on stream on after URBs creation */
  93. cam_pkt_op pkt_scan;
  94. /* optional operations */
  95. cam_op isoc_init; /* called on stream on before getting the EP */
  96. cam_op isoc_nego; /* called when URB submit failed with NOSPC */
  97. cam_v_op stopN; /* called on stream off - main alt */
  98. cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
  99. cam_v_op dq_callback; /* called when a frame has been dequeued */
  100. cam_jpg_op get_jcomp;
  101. cam_jpg_op set_jcomp;
  102. cam_qmnu_op querymenu;
  103. cam_streamparm_op get_streamparm;
  104. cam_streamparm_op set_streamparm;
  105. #ifdef CONFIG_VIDEO_ADV_DEBUG
  106. cam_reg_op set_register;
  107. cam_reg_op get_register;
  108. #endif
  109. cam_ident_op get_chip_ident;
  110. };
  111. /* packet types when moving from iso buf to frame buf */
  112. enum gspca_packet_type {
  113. DISCARD_PACKET,
  114. FIRST_PACKET,
  115. INTER_PACKET,
  116. LAST_PACKET
  117. };
  118. struct gspca_frame {
  119. __u8 *data; /* frame buffer */
  120. __u8 *data_end; /* end of frame while filling */
  121. int vma_use_count;
  122. struct v4l2_buffer v4l2_buf;
  123. };
  124. struct gspca_dev {
  125. struct video_device vdev; /* !! must be the first item */
  126. struct module *module; /* subdriver handling the device */
  127. struct usb_device *dev;
  128. struct file *capt_file; /* file doing video capture */
  129. struct cam cam; /* device information */
  130. const struct sd_desc *sd_desc; /* subdriver description */
  131. unsigned ctrl_dis; /* disabled controls (bit map) */
  132. unsigned ctrl_inac; /* inactive controls (bit map) */
  133. #define USB_BUF_SZ 64
  134. __u8 *usb_buf; /* buffer for USB exchanges */
  135. struct urb *urb[MAX_NURBS];
  136. __u8 *frbuf; /* buffer for nframes */
  137. struct gspca_frame frame[GSPCA_MAX_FRAMES];
  138. struct gspca_frame *cur_frame; /* frame beeing filled */
  139. __u32 frsz; /* frame size */
  140. char nframes; /* number of frames */
  141. char fr_i; /* frame being filled */
  142. char fr_q; /* next frame to queue */
  143. char fr_o; /* next frame to dequeue */
  144. signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
  145. __u8 last_packet_type;
  146. __s8 empty_packet; /* if (-1) don't check empty packets */
  147. __u8 streaming;
  148. __u8 curr_mode; /* current camera mode */
  149. __u32 pixfmt; /* current mode parameters */
  150. __u16 width;
  151. __u16 height;
  152. __u32 sequence; /* frame sequence number */
  153. wait_queue_head_t wq; /* wait queue */
  154. struct mutex usb_lock; /* usb exchange protection */
  155. struct mutex read_lock; /* read protection */
  156. struct mutex queue_lock; /* ISOC queue protection */
  157. #ifdef CONFIG_PM
  158. char frozen; /* suspend - resume */
  159. #endif
  160. char users; /* number of opens */
  161. char present; /* device connected */
  162. char nbufread; /* number of buffers for read() */
  163. char nurbs; /* number of allocated URBs */
  164. char memory; /* memory type (V4L2_MEMORY_xxx) */
  165. __u8 iface; /* USB interface number */
  166. __u8 alt; /* USB alternate setting */
  167. __u8 nbalt; /* number of USB alternate settings */
  168. u16 pkt_size; /* ISOC packet size */
  169. };
  170. int gspca_dev_probe(struct usb_interface *intf,
  171. const struct usb_device_id *id,
  172. const struct sd_desc *sd_desc,
  173. int dev_size,
  174. struct module *module);
  175. void gspca_disconnect(struct usb_interface *intf);
  176. void gspca_frame_add(struct gspca_dev *gspca_dev,
  177. enum gspca_packet_type packet_type,
  178. const u8 *data,
  179. int len);
  180. struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev);
  181. #ifdef CONFIG_PM
  182. int gspca_suspend(struct usb_interface *intf, pm_message_t message);
  183. int gspca_resume(struct usb_interface *intf);
  184. #endif
  185. int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
  186. int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
  187. #endif /* GSPCAV2_H */