uvc.h 4.6 KB

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