gspca.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #ifndef GSPCAV2_H
  2. #define GSPCAV2_H
  3. #include <linux/module.h>
  4. #include <linux/version.h>
  5. #include <linux/kernel.h>
  6. #include <linux/usb.h>
  7. #include <linux/videodev2.h>
  8. #include <media/v4l2-common.h>
  9. #include <linux/mutex.h>
  10. /* compilation option */
  11. #define GSPCA_DEBUG 1
  12. #ifdef GSPCA_DEBUG
  13. /* GSPCA our debug messages */
  14. extern int gspca_debug;
  15. #define PDEBUG(level, fmt, args...) \
  16. do {\
  17. if (gspca_debug & (level)) \
  18. printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
  19. } while (0)
  20. #define D_ERR 0x01
  21. #define D_PROBE 0x02
  22. #define D_CONF 0x04
  23. #define D_STREAM 0x08
  24. #define D_FRAM 0x10
  25. #define D_PACK 0x20
  26. #define D_USBI 0x40
  27. #define D_USBO 0x80
  28. #define D_V4L2 0x0100
  29. #else
  30. #define PDEBUG(level, fmt, args...)
  31. #endif
  32. #undef err
  33. #define err(fmt, args...) \
  34. do {\
  35. printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args); \
  36. } while (0)
  37. #undef info
  38. #define info(fmt, args...) \
  39. do {\
  40. printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
  41. } while (0)
  42. #undef warn
  43. #define warn(fmt, args...) \
  44. do {\
  45. printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args); \
  46. } while (0)
  47. #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
  48. /* image transfers */
  49. #define MAX_NURBS 4 /* max number of URBs */
  50. #define ISO_MAX_PKT 32 /* max number of packets in an ISOC transfer */
  51. #define ISO_MAX_SIZE 0x8000 /* max size of one URB buffer (32 Kb) */
  52. /* device information - set at probe time */
  53. struct cam {
  54. struct v4l2_pix_format *cam_mode; /* size nmodes */
  55. char nmodes;
  56. __u8 epaddr;
  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_qmnu_op) (struct gspca_dev *,
  67. struct v4l2_querymenu *);
  68. typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
  69. struct gspca_frame *frame,
  70. __u8 *data,
  71. int len);
  72. struct ctrl {
  73. struct v4l2_queryctrl qctrl;
  74. int (*set)(struct gspca_dev *, __s32);
  75. int (*get)(struct gspca_dev *, __s32 *);
  76. };
  77. /* subdriver description */
  78. struct sd_desc {
  79. /* information */
  80. const char *name; /* sub-driver name */
  81. /* controls */
  82. const struct ctrl *ctrls;
  83. int nctrls;
  84. /* mandatory operations */
  85. cam_cf_op config; /* called on probe */
  86. cam_op init; /* called on probe and resume */
  87. cam_v_op start; /* called on stream on */
  88. cam_pkt_op pkt_scan;
  89. /* optional operations */
  90. cam_v_op stopN; /* called on stream off - main alt */
  91. cam_v_op stop0; /* called on stream off - alt 0 */
  92. cam_v_op dq_callback; /* called when a frame has been dequeued */
  93. cam_jpg_op get_jcomp;
  94. cam_jpg_op set_jcomp;
  95. cam_qmnu_op querymenu;
  96. };
  97. /* packet types when moving from iso buf to frame buf */
  98. #define DISCARD_PACKET 0
  99. #define FIRST_PACKET 1
  100. #define INTER_PACKET 2
  101. #define LAST_PACKET 3
  102. struct gspca_frame {
  103. __u8 *data; /* frame buffer */
  104. __u8 *data_end; /* end of frame while filling */
  105. int vma_use_count;
  106. struct v4l2_buffer v4l2_buf;
  107. };
  108. struct gspca_dev {
  109. struct video_device vdev; /* !! must be the first item */
  110. struct file_operations fops;
  111. struct usb_device *dev;
  112. struct file *capt_file; /* file doing video capture */
  113. struct cam cam; /* device information */
  114. const struct sd_desc *sd_desc; /* subdriver description */
  115. unsigned ctrl_dis; /* disabled controls (bit map) */
  116. #define USB_BUF_SZ 64
  117. __u8 *usb_buf; /* buffer for USB exchanges */
  118. struct urb *urb[MAX_NURBS];
  119. __u8 *frbuf; /* buffer for nframes */
  120. struct gspca_frame frame[GSPCA_MAX_FRAMES];
  121. __u32 frsz; /* frame size */
  122. char nframes; /* number of frames */
  123. char fr_i; /* frame being filled */
  124. char fr_q; /* next frame to queue */
  125. char fr_o; /* next frame to dequeue */
  126. signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
  127. char last_packet_type;
  128. __u8 iface; /* USB interface number */
  129. __u8 alt; /* USB alternate setting */
  130. __u8 bulk; /* image transfer by isoc (0) or bulk (1) */
  131. __u8 curr_mode; /* current camera mode */
  132. __u32 pixfmt; /* current mode parameters */
  133. __u16 width;
  134. __u16 height;
  135. atomic_t nevent; /* number of frames done */
  136. wait_queue_head_t wq; /* wait queue */
  137. struct mutex usb_lock; /* usb exchange protection */
  138. struct mutex read_lock; /* read protection */
  139. struct mutex queue_lock; /* ISOC queue protection */
  140. __u32 sequence; /* frame sequence number */
  141. char streaming;
  142. #ifdef CONFIG_PM
  143. char frozen; /* suspend - resume */
  144. #endif
  145. char users; /* number of opens */
  146. char present; /* device connected */
  147. char nbufread; /* number of buffers for read() */
  148. char nurbs; /* number of allocated URBs */
  149. char memory; /* memory type (V4L2_MEMORY_xxx) */
  150. __u8 nbalt; /* number of USB alternate settings */
  151. };
  152. int gspca_dev_probe(struct usb_interface *intf,
  153. const struct usb_device_id *id,
  154. const struct sd_desc *sd_desc,
  155. int dev_size,
  156. struct module *module);
  157. void gspca_disconnect(struct usb_interface *intf);
  158. struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
  159. int packet_type,
  160. struct gspca_frame *frame,
  161. const __u8 *data,
  162. int len);
  163. struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev);
  164. #ifdef CONFIG_PM
  165. int gspca_suspend(struct usb_interface *intf, pm_message_t message);
  166. int gspca_resume(struct usb_interface *intf);
  167. #endif
  168. int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
  169. int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee);
  170. #endif /* GSPCAV2_H */