gspca.h 5.5 KB

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