uvc.h 4.8 KB

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