uvc.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * uvc_gadget.h -- USB Video Class Gadget driver
  3. *
  4. * Copyright (C) 2009-2010
  5. * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #ifndef _UVC_GADGET_H_
  14. #define _UVC_GADGET_H_
  15. #include <linux/ioctl.h>
  16. #include <linux/types.h>
  17. #include <linux/usb/ch9.h>
  18. #define UVC_EVENT_FIRST (V4L2_EVENT_PRIVATE_START + 0)
  19. #define UVC_EVENT_CONNECT (V4L2_EVENT_PRIVATE_START + 0)
  20. #define UVC_EVENT_DISCONNECT (V4L2_EVENT_PRIVATE_START + 1)
  21. #define UVC_EVENT_STREAMON (V4L2_EVENT_PRIVATE_START + 2)
  22. #define UVC_EVENT_STREAMOFF (V4L2_EVENT_PRIVATE_START + 3)
  23. #define UVC_EVENT_SETUP (V4L2_EVENT_PRIVATE_START + 4)
  24. #define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)
  25. #define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)
  26. struct uvc_request_data
  27. {
  28. unsigned int length;
  29. __u8 data[60];
  30. };
  31. struct uvc_event
  32. {
  33. union {
  34. enum usb_device_speed speed;
  35. struct usb_ctrlrequest req;
  36. struct uvc_request_data data;
  37. };
  38. };
  39. #define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data)
  40. #define UVC_INTF_CONTROL 0
  41. #define UVC_INTF_STREAMING 1
  42. /* ------------------------------------------------------------------------
  43. * UVC constants & structures
  44. */
  45. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  46. #define UVC_STREAM_EOH (1 << 7)
  47. #define UVC_STREAM_ERR (1 << 6)
  48. #define UVC_STREAM_STI (1 << 5)
  49. #define UVC_STREAM_RES (1 << 4)
  50. #define UVC_STREAM_SCR (1 << 3)
  51. #define UVC_STREAM_PTS (1 << 2)
  52. #define UVC_STREAM_EOF (1 << 1)
  53. #define UVC_STREAM_FID (1 << 0)
  54. struct uvc_streaming_control {
  55. __u16 bmHint;
  56. __u8 bFormatIndex;
  57. __u8 bFrameIndex;
  58. __u32 dwFrameInterval;
  59. __u16 wKeyFrameRate;
  60. __u16 wPFrameRate;
  61. __u16 wCompQuality;
  62. __u16 wCompWindowSize;
  63. __u16 wDelay;
  64. __u32 dwMaxVideoFrameSize;
  65. __u32 dwMaxPayloadTransferSize;
  66. __u32 dwClockFrequency;
  67. __u8 bmFramingInfo;
  68. __u8 bPreferedVersion;
  69. __u8 bMinVersion;
  70. __u8 bMaxVersion;
  71. } __attribute__((__packed__));
  72. /* ------------------------------------------------------------------------
  73. * Debugging, printing and logging
  74. */
  75. #ifdef __KERNEL__
  76. #include <linux/usb.h> /* For usb_endpoint_* */
  77. #include <linux/usb/gadget.h>
  78. #include <linux/videodev2.h>
  79. #include <media/v4l2-fh.h>
  80. #include "uvc_queue.h"
  81. #define UVC_TRACE_PROBE (1 << 0)
  82. #define UVC_TRACE_DESCR (1 << 1)
  83. #define UVC_TRACE_CONTROL (1 << 2)
  84. #define UVC_TRACE_FORMAT (1 << 3)
  85. #define UVC_TRACE_CAPTURE (1 << 4)
  86. #define UVC_TRACE_CALLS (1 << 5)
  87. #define UVC_TRACE_IOCTL (1 << 6)
  88. #define UVC_TRACE_FRAME (1 << 7)
  89. #define UVC_TRACE_SUSPEND (1 << 8)
  90. #define UVC_TRACE_STATUS (1 << 9)
  91. #define UVC_WARN_MINMAX 0
  92. #define UVC_WARN_PROBE_DEF 1
  93. extern unsigned int uvc_gadget_trace_param;
  94. #define uvc_trace(flag, msg...) \
  95. do { \
  96. if (uvc_gadget_trace_param & flag) \
  97. printk(KERN_DEBUG "uvcvideo: " msg); \
  98. } while (0)
  99. #define uvc_warn_once(dev, warn, msg...) \
  100. do { \
  101. if (!test_and_set_bit(warn, &dev->warnings)) \
  102. printk(KERN_INFO "uvcvideo: " msg); \
  103. } while (0)
  104. #define uvc_printk(level, msg...) \
  105. printk(level "uvcvideo: " msg)
  106. /* ------------------------------------------------------------------------
  107. * Driver specific constants
  108. */
  109. #define DRIVER_VERSION "0.1.0"
  110. #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
  111. #define DMA_ADDR_INVALID (~(dma_addr_t)0)
  112. #define UVC_NUM_REQUESTS 4
  113. #define UVC_MAX_REQUEST_SIZE 64
  114. #define UVC_MAX_EVENTS 4
  115. #define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
  116. #define USB_CLASS_MISC 0xef
  117. /* ------------------------------------------------------------------------
  118. * Structures
  119. */
  120. struct uvc_video
  121. {
  122. struct usb_ep *ep;
  123. /* Frame parameters */
  124. u8 bpp;
  125. u32 fcc;
  126. unsigned int width;
  127. unsigned int height;
  128. unsigned int imagesize;
  129. /* Requests */
  130. unsigned int req_size;
  131. struct usb_request *req[UVC_NUM_REQUESTS];
  132. __u8 *req_buffer[UVC_NUM_REQUESTS];
  133. struct list_head req_free;
  134. spinlock_t req_lock;
  135. void (*encode) (struct usb_request *req, struct uvc_video *video,
  136. struct uvc_buffer *buf);
  137. /* Context data used by the completion handler */
  138. __u32 payload_size;
  139. __u32 max_payload_size;
  140. struct uvc_video_queue queue;
  141. unsigned int fid;
  142. };
  143. enum uvc_state
  144. {
  145. UVC_STATE_DISCONNECTED,
  146. UVC_STATE_CONNECTED,
  147. UVC_STATE_STREAMING,
  148. };
  149. struct uvc_device
  150. {
  151. struct video_device *vdev;
  152. enum uvc_state state;
  153. struct usb_function func;
  154. struct uvc_video video;
  155. /* Descriptors */
  156. struct {
  157. const struct uvc_descriptor_header * const *control;
  158. const struct uvc_descriptor_header * const *fs_streaming;
  159. const struct uvc_descriptor_header * const *hs_streaming;
  160. } desc;
  161. unsigned int control_intf;
  162. struct usb_ep *control_ep;
  163. struct usb_request *control_req;
  164. void *control_buf;
  165. unsigned int streaming_intf;
  166. /* Events */
  167. unsigned int event_length;
  168. unsigned int event_setup_out : 1;
  169. };
  170. static inline struct uvc_device *to_uvc(struct usb_function *f)
  171. {
  172. return container_of(f, struct uvc_device, func);
  173. }
  174. struct uvc_file_handle
  175. {
  176. struct v4l2_fh vfh;
  177. struct uvc_video *device;
  178. };
  179. #define to_uvc_file_handle(handle) \
  180. container_of(handle, struct uvc_file_handle, vfh)
  181. /* ------------------------------------------------------------------------
  182. * Functions
  183. */
  184. extern void uvc_endpoint_stream(struct uvc_device *dev);
  185. extern void uvc_function_connect(struct uvc_device *uvc);
  186. extern void uvc_function_disconnect(struct uvc_device *uvc);
  187. #endif /* __KERNEL__ */
  188. #endif /* _UVC_GADGET_H_ */