uvc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. #ifndef _UVC_GADGET_H_
  13. #define _UVC_GADGET_H_
  14. #include <linux/ioctl.h>
  15. #include <linux/types.h>
  16. #include <linux/usb/ch9.h>
  17. #define UVC_EVENT_FIRST (V4L2_EVENT_PRIVATE_START + 0)
  18. #define UVC_EVENT_CONNECT (V4L2_EVENT_PRIVATE_START + 0)
  19. #define UVC_EVENT_DISCONNECT (V4L2_EVENT_PRIVATE_START + 1)
  20. #define UVC_EVENT_STREAMON (V4L2_EVENT_PRIVATE_START + 2)
  21. #define UVC_EVENT_STREAMOFF (V4L2_EVENT_PRIVATE_START + 3)
  22. #define UVC_EVENT_SETUP (V4L2_EVENT_PRIVATE_START + 4)
  23. #define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)
  24. #define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)
  25. struct uvc_request_data
  26. {
  27. __s32 length;
  28. __u8 data[60];
  29. };
  30. struct uvc_event
  31. {
  32. union {
  33. enum usb_device_speed speed;
  34. struct usb_ctrlrequest req;
  35. struct uvc_request_data data;
  36. };
  37. };
  38. #define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data)
  39. #define UVC_INTF_CONTROL 0
  40. #define UVC_INTF_STREAMING 1
  41. /* ------------------------------------------------------------------------
  42. * Debugging, printing and logging
  43. */
  44. #ifdef __KERNEL__
  45. #include <linux/usb.h> /* For usb_endpoint_* */
  46. #include <linux/usb/gadget.h>
  47. #include <linux/videodev2.h>
  48. #include <linux/version.h>
  49. #include <media/v4l2-fh.h>
  50. #include <media/v4l2-device.h>
  51. #include "uvc_queue.h"
  52. #define UVC_TRACE_PROBE (1 << 0)
  53. #define UVC_TRACE_DESCR (1 << 1)
  54. #define UVC_TRACE_CONTROL (1 << 2)
  55. #define UVC_TRACE_FORMAT (1 << 3)
  56. #define UVC_TRACE_CAPTURE (1 << 4)
  57. #define UVC_TRACE_CALLS (1 << 5)
  58. #define UVC_TRACE_IOCTL (1 << 6)
  59. #define UVC_TRACE_FRAME (1 << 7)
  60. #define UVC_TRACE_SUSPEND (1 << 8)
  61. #define UVC_TRACE_STATUS (1 << 9)
  62. #define UVC_WARN_MINMAX 0
  63. #define UVC_WARN_PROBE_DEF 1
  64. extern unsigned int uvc_gadget_trace_param;
  65. #define uvc_trace(flag, msg...) \
  66. do { \
  67. if (uvc_gadget_trace_param & flag) \
  68. printk(KERN_DEBUG "uvcvideo: " msg); \
  69. } while (0)
  70. #define uvc_warn_once(dev, warn, msg...) \
  71. do { \
  72. if (!test_and_set_bit(warn, &dev->warnings)) \
  73. printk(KERN_INFO "uvcvideo: " msg); \
  74. } while (0)
  75. #define uvc_printk(level, msg...) \
  76. printk(level "uvcvideo: " msg)
  77. /* ------------------------------------------------------------------------
  78. * Driver specific constants
  79. */
  80. #define DRIVER_VERSION "0.1.0"
  81. #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
  82. #define UVC_NUM_REQUESTS 4
  83. #define UVC_MAX_REQUEST_SIZE 64
  84. #define UVC_MAX_EVENTS 4
  85. /* ------------------------------------------------------------------------
  86. * Structures
  87. */
  88. struct uvc_video
  89. {
  90. struct usb_ep *ep;
  91. /* Frame parameters */
  92. u8 bpp;
  93. u32 fcc;
  94. unsigned int width;
  95. unsigned int height;
  96. unsigned int imagesize;
  97. /* Requests */
  98. unsigned int req_size;
  99. struct usb_request *req[UVC_NUM_REQUESTS];
  100. __u8 *req_buffer[UVC_NUM_REQUESTS];
  101. struct list_head req_free;
  102. spinlock_t req_lock;
  103. void (*encode) (struct usb_request *req, struct uvc_video *video,
  104. struct uvc_buffer *buf);
  105. /* Context data used by the completion handler */
  106. __u32 payload_size;
  107. __u32 max_payload_size;
  108. struct uvc_video_queue queue;
  109. unsigned int fid;
  110. };
  111. enum uvc_state
  112. {
  113. UVC_STATE_DISCONNECTED,
  114. UVC_STATE_CONNECTED,
  115. UVC_STATE_STREAMING,
  116. };
  117. struct uvc_device
  118. {
  119. struct video_device *vdev;
  120. struct v4l2_device v4l2_dev;
  121. enum uvc_state state;
  122. struct usb_function func;
  123. struct uvc_video video;
  124. /* Descriptors */
  125. struct {
  126. const struct uvc_descriptor_header * const *fs_control;
  127. const struct uvc_descriptor_header * const *ss_control;
  128. const struct uvc_descriptor_header * const *fs_streaming;
  129. const struct uvc_descriptor_header * const *hs_streaming;
  130. const struct uvc_descriptor_header * const *ss_streaming;
  131. } desc;
  132. unsigned int control_intf;
  133. struct usb_ep *control_ep;
  134. struct usb_request *control_req;
  135. void *control_buf;
  136. unsigned int streaming_intf;
  137. /* Events */
  138. unsigned int event_length;
  139. unsigned int event_setup_out : 1;
  140. };
  141. static inline struct uvc_device *to_uvc(struct usb_function *f)
  142. {
  143. return container_of(f, struct uvc_device, func);
  144. }
  145. struct uvc_file_handle
  146. {
  147. struct v4l2_fh vfh;
  148. struct uvc_video *device;
  149. };
  150. #define to_uvc_file_handle(handle) \
  151. container_of(handle, struct uvc_file_handle, vfh)
  152. /* ------------------------------------------------------------------------
  153. * Functions
  154. */
  155. extern void uvc_function_setup_continue(struct uvc_device *uvc);
  156. extern void uvc_endpoint_stream(struct uvc_device *dev);
  157. extern void uvc_function_connect(struct uvc_device *uvc);
  158. extern void uvc_function_disconnect(struct uvc_device *uvc);
  159. #endif /* __KERNEL__ */
  160. #endif /* _UVC_GADGET_H_ */