uvc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/composite.h>
  47. #include <linux/usb/gadget.h>
  48. #include <linux/videodev2.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 UVC_NUM_REQUESTS 4
  81. #define UVC_MAX_REQUEST_SIZE 64
  82. #define UVC_MAX_EVENTS 4
  83. /* ------------------------------------------------------------------------
  84. * Structures
  85. */
  86. struct uvc_video
  87. {
  88. struct usb_ep *ep;
  89. /* Frame parameters */
  90. u8 bpp;
  91. u32 fcc;
  92. unsigned int width;
  93. unsigned int height;
  94. unsigned int imagesize;
  95. struct mutex mutex; /* protects frame parameters */
  96. /* Requests */
  97. unsigned int req_size;
  98. struct usb_request *req[UVC_NUM_REQUESTS];
  99. __u8 *req_buffer[UVC_NUM_REQUESTS];
  100. struct list_head req_free;
  101. spinlock_t req_lock;
  102. void (*encode) (struct usb_request *req, struct uvc_video *video,
  103. struct uvc_buffer *buf);
  104. /* Context data used by the completion handler */
  105. __u32 payload_size;
  106. __u32 max_payload_size;
  107. struct uvc_video_queue queue;
  108. unsigned int fid;
  109. };
  110. enum uvc_state
  111. {
  112. UVC_STATE_DISCONNECTED,
  113. UVC_STATE_CONNECTED,
  114. UVC_STATE_STREAMING,
  115. };
  116. struct uvc_device
  117. {
  118. struct video_device vdev;
  119. struct v4l2_device v4l2_dev;
  120. enum uvc_state state;
  121. struct usb_function func;
  122. struct uvc_video video;
  123. /* Descriptors */
  124. struct {
  125. const struct uvc_descriptor_header * const *fs_control;
  126. const struct uvc_descriptor_header * const *ss_control;
  127. const struct uvc_descriptor_header * const *fs_streaming;
  128. const struct uvc_descriptor_header * const *hs_streaming;
  129. const struct uvc_descriptor_header * const *ss_streaming;
  130. } desc;
  131. unsigned int control_intf;
  132. struct usb_ep *control_ep;
  133. struct usb_request *control_req;
  134. void *control_buf;
  135. unsigned int streaming_intf;
  136. /* Events */
  137. unsigned int event_length;
  138. unsigned int event_setup_out : 1;
  139. };
  140. static inline struct uvc_device *to_uvc(struct usb_function *f)
  141. {
  142. return container_of(f, struct uvc_device, func);
  143. }
  144. struct uvc_file_handle
  145. {
  146. struct v4l2_fh vfh;
  147. struct uvc_video *device;
  148. };
  149. #define to_uvc_file_handle(handle) \
  150. container_of(handle, struct uvc_file_handle, vfh)
  151. /* ------------------------------------------------------------------------
  152. * Functions
  153. */
  154. extern void uvc_function_setup_continue(struct uvc_device *uvc);
  155. extern void uvc_endpoint_stream(struct uvc_device *dev);
  156. extern void uvc_function_connect(struct uvc_device *uvc);
  157. extern void uvc_function_disconnect(struct uvc_device *uvc);
  158. #endif /* __KERNEL__ */
  159. #endif /* _UVC_GADGET_H_ */