gspca.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. /* used to list framerates supported by a camera mode (resolution) */
  44. struct framerates {
  45. const u8 *rates;
  46. int nrates;
  47. };
  48. /* device information - set at probe time */
  49. struct cam {
  50. const struct v4l2_pix_format *cam_mode; /* size nmodes */
  51. const struct framerates *mode_framerates; /* must have size nmode,
  52. * just like cam_mode */
  53. u32 bulk_size; /* buffer size when image transfer by bulk */
  54. u32 input_flags; /* value for ENUM_INPUT status flags */
  55. u8 nmodes; /* size of cam_mode */
  56. u8 no_urb_create; /* don't create transfer URBs */
  57. u8 bulk_nurbs; /* number of URBs in bulk mode
  58. * - cannot be > MAX_NURBS
  59. * - when 0 and bulk_size != 0 means
  60. * 1 URB and submit done by subdriver */
  61. u8 bulk; /* image transfer by 0:isoc / 1:bulk */
  62. u8 npkt; /* number of packets in an ISOC message
  63. * 0 is the default value: 32 packets */
  64. u8 reverse_alts; /* Alt settings are in high to low order */
  65. };
  66. struct gspca_dev;
  67. struct gspca_frame;
  68. /* subdriver operations */
  69. typedef int (*cam_op) (struct gspca_dev *);
  70. typedef void (*cam_v_op) (struct gspca_dev *);
  71. typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
  72. typedef int (*cam_jpg_op) (struct gspca_dev *,
  73. struct v4l2_jpegcompression *);
  74. typedef int (*cam_reg_op) (struct gspca_dev *,
  75. struct v4l2_dbg_register *);
  76. typedef int (*cam_ident_op) (struct gspca_dev *,
  77. struct v4l2_dbg_chip_ident *);
  78. typedef int (*cam_streamparm_op) (struct gspca_dev *,
  79. struct v4l2_streamparm *);
  80. typedef int (*cam_qmnu_op) (struct gspca_dev *,
  81. struct v4l2_querymenu *);
  82. typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
  83. u8 *data,
  84. int len);
  85. typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
  86. u8 *data,
  87. int len);
  88. struct ctrl {
  89. struct v4l2_queryctrl qctrl;
  90. int (*set)(struct gspca_dev *, __s32);
  91. int (*get)(struct gspca_dev *, __s32 *);
  92. };
  93. /* subdriver description */
  94. struct sd_desc {
  95. /* information */
  96. const char *name; /* sub-driver name */
  97. /* controls */
  98. const struct ctrl *ctrls;
  99. int nctrls;
  100. /* mandatory operations */
  101. cam_cf_op config; /* called on probe */
  102. cam_op init; /* called on probe and resume */
  103. cam_op start; /* called on stream on after URBs creation */
  104. cam_pkt_op pkt_scan;
  105. /* optional operations */
  106. cam_op isoc_init; /* called on stream on before getting the EP */
  107. cam_op isoc_nego; /* called when URB submit failed with NOSPC */
  108. cam_v_op stopN; /* called on stream off - main alt */
  109. cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
  110. cam_v_op dq_callback; /* called when a frame has been dequeued */
  111. cam_jpg_op get_jcomp;
  112. cam_jpg_op set_jcomp;
  113. cam_qmnu_op querymenu;
  114. cam_streamparm_op get_streamparm;
  115. cam_streamparm_op set_streamparm;
  116. #ifdef CONFIG_VIDEO_ADV_DEBUG
  117. cam_reg_op set_register;
  118. cam_reg_op get_register;
  119. #endif
  120. cam_ident_op get_chip_ident;
  121. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  122. cam_int_pkt_op int_pkt_scan;
  123. /* other_input makes the gspca core create gspca_dev->input even when
  124. int_pkt_scan is NULL, for cams with non interrupt driven buttons */
  125. u8 other_input;
  126. #endif
  127. };
  128. /* packet types when moving from iso buf to frame buf */
  129. enum gspca_packet_type {
  130. DISCARD_PACKET,
  131. FIRST_PACKET,
  132. INTER_PACKET,
  133. LAST_PACKET
  134. };
  135. struct gspca_frame {
  136. __u8 *data; /* frame buffer */
  137. int vma_use_count;
  138. struct v4l2_buffer v4l2_buf;
  139. };
  140. struct gspca_dev {
  141. struct video_device vdev; /* !! must be the first item */
  142. struct module *module; /* subdriver handling the device */
  143. struct usb_device *dev;
  144. struct file *capt_file; /* file doing video capture */
  145. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  146. struct input_dev *input_dev;
  147. char phys[64]; /* physical device path */
  148. #endif
  149. struct cam cam; /* device information */
  150. const struct sd_desc *sd_desc; /* subdriver description */
  151. unsigned ctrl_dis; /* disabled controls (bit map) */
  152. unsigned ctrl_inac; /* inactive controls (bit map) */
  153. #define USB_BUF_SZ 64
  154. __u8 *usb_buf; /* buffer for USB exchanges */
  155. struct urb *urb[MAX_NURBS];
  156. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  157. struct urb *int_urb;
  158. #endif
  159. __u8 *frbuf; /* buffer for nframes */
  160. struct gspca_frame frame[GSPCA_MAX_FRAMES];
  161. u8 *image; /* image beeing filled */
  162. __u32 frsz; /* frame size */
  163. u32 image_len; /* current length of image */
  164. atomic_t fr_q; /* next frame to queue */
  165. atomic_t fr_i; /* frame being filled */
  166. signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
  167. char nframes; /* number of frames */
  168. u8 fr_o; /* next frame to dequeue */
  169. __u8 last_packet_type;
  170. __s8 empty_packet; /* if (-1) don't check empty packets */
  171. __u8 streaming;
  172. __u8 curr_mode; /* current camera mode */
  173. __u32 pixfmt; /* current mode parameters */
  174. __u16 width;
  175. __u16 height;
  176. __u32 sequence; /* frame sequence number */
  177. wait_queue_head_t wq; /* wait queue */
  178. struct mutex usb_lock; /* usb exchange protection */
  179. struct mutex read_lock; /* read protection */
  180. struct mutex queue_lock; /* ISOC queue protection */
  181. int usb_err; /* USB error - protected by usb_lock */
  182. u16 pkt_size; /* ISOC packet size */
  183. #ifdef CONFIG_PM
  184. char frozen; /* suspend - resume */
  185. #endif
  186. char users; /* number of opens */
  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 nbalt; /* number of USB alternate settings */
  193. u8 audio; /* presence of audio device */
  194. };
  195. int gspca_dev_probe(struct usb_interface *intf,
  196. const struct usb_device_id *id,
  197. const struct sd_desc *sd_desc,
  198. int dev_size,
  199. struct module *module);
  200. int gspca_dev_probe2(struct usb_interface *intf,
  201. const struct usb_device_id *id,
  202. const struct sd_desc *sd_desc,
  203. int dev_size,
  204. struct module *module);
  205. void gspca_disconnect(struct usb_interface *intf);
  206. void gspca_frame_add(struct gspca_dev *gspca_dev,
  207. enum gspca_packet_type packet_type,
  208. const u8 *data,
  209. int len);
  210. #ifdef CONFIG_PM
  211. int gspca_suspend(struct usb_interface *intf, pm_message_t message);
  212. int gspca_resume(struct usb_interface *intf);
  213. #endif
  214. int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
  215. int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
  216. #endif /* GSPCAV2_H */