uvc.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 ([email protected])
  7. */
  8. #ifndef _UVC_GADGET_H_
  9. #define _UVC_GADGET_H_
  10. #include <linux/list.h>
  11. #include <linux/mutex.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/usb/composite.h>
  14. #include <linux/videodev2.h>
  15. #include <linux/wait.h>
  16. #include <media/v4l2-device.h>
  17. #include <media/v4l2-dev.h>
  18. #include <media/v4l2-fh.h>
  19. #include "uvc_queue.h"
  20. struct usb_ep;
  21. struct usb_request;
  22. struct uvc_descriptor_header;
  23. struct uvc_device;
  24. /* ------------------------------------------------------------------------
  25. * Debugging, printing and logging
  26. */
  27. #define UVC_TRACE_PROBE (1 << 0)
  28. #define UVC_TRACE_DESCR (1 << 1)
  29. #define UVC_TRACE_CONTROL (1 << 2)
  30. #define UVC_TRACE_FORMAT (1 << 3)
  31. #define UVC_TRACE_CAPTURE (1 << 4)
  32. #define UVC_TRACE_CALLS (1 << 5)
  33. #define UVC_TRACE_IOCTL (1 << 6)
  34. #define UVC_TRACE_FRAME (1 << 7)
  35. #define UVC_TRACE_SUSPEND (1 << 8)
  36. #define UVC_TRACE_STATUS (1 << 9)
  37. #define UVC_WARN_MINMAX 0
  38. #define UVC_WARN_PROBE_DEF 1
  39. extern unsigned int uvc_gadget_trace_param;
  40. #define uvc_trace(flag, msg...) \
  41. do { \
  42. if (uvc_gadget_trace_param & flag) \
  43. printk(KERN_DEBUG "uvcvideo: " msg); \
  44. } while (0)
  45. #define uvcg_dbg(f, fmt, args...) \
  46. dev_dbg(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
  47. #define uvcg_info(f, fmt, args...) \
  48. dev_info(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
  49. #define uvcg_warn(f, fmt, args...) \
  50. dev_warn(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
  51. #define uvcg_err(f, fmt, args...) \
  52. dev_err(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
  53. /* ------------------------------------------------------------------------
  54. * Driver specific constants
  55. */
  56. #define UVC_MAX_REQUEST_SIZE 64
  57. #define UVC_MAX_EVENTS 4
  58. #define UVCG_REQUEST_HEADER_LEN 12
  59. /* ------------------------------------------------------------------------
  60. * Structures
  61. */
  62. struct uvc_request {
  63. struct usb_request *req;
  64. u8 *req_buffer;
  65. struct uvc_video *video;
  66. struct sg_table sgt;
  67. u8 header[UVCG_REQUEST_HEADER_LEN];
  68. struct uvc_buffer *last_buf;
  69. struct list_head list;
  70. };
  71. struct uvc_video {
  72. struct uvc_device *uvc;
  73. struct usb_ep *ep;
  74. struct work_struct pump;
  75. struct workqueue_struct *async_wq;
  76. /* Frame parameters */
  77. u8 bpp;
  78. u32 fcc;
  79. unsigned int width;
  80. unsigned int height;
  81. unsigned int imagesize;
  82. struct mutex mutex; /* protects frame parameters */
  83. unsigned int uvc_num_requests;
  84. /* Requests */
  85. bool is_enabled; /* tracks whether video stream is enabled */
  86. unsigned int req_size;
  87. struct list_head ureqs; /* all uvc_requests allocated by uvc_video */
  88. /* USB requests that the video pump thread can encode into */
  89. struct list_head req_free;
  90. /*
  91. * USB requests video pump thread has already encoded into. These are
  92. * ready to be queued to the endpoint.
  93. */
  94. struct list_head req_ready;
  95. spinlock_t req_lock;
  96. unsigned int req_int_count;
  97. void (*encode) (struct usb_request *req, struct uvc_video *video,
  98. struct uvc_buffer *buf);
  99. /* Context data used by the completion handler */
  100. __u32 payload_size;
  101. __u32 max_payload_size;
  102. struct uvc_video_queue queue;
  103. unsigned int fid;
  104. };
  105. enum uvc_state {
  106. UVC_STATE_DISCONNECTED,
  107. UVC_STATE_CONNECTED,
  108. UVC_STATE_STREAMING,
  109. };
  110. struct uvc_device {
  111. struct video_device vdev;
  112. struct v4l2_device v4l2_dev;
  113. enum uvc_state state;
  114. struct usb_function func;
  115. struct uvc_video video;
  116. bool func_connected;
  117. wait_queue_head_t func_connected_queue;
  118. struct uvcg_streaming_header *header;
  119. /* Descriptors */
  120. struct {
  121. const struct uvc_descriptor_header * const *fs_control;
  122. const struct uvc_descriptor_header * const *ss_control;
  123. const struct uvc_descriptor_header * const *fs_streaming;
  124. const struct uvc_descriptor_header * const *hs_streaming;
  125. const struct uvc_descriptor_header * const *ss_streaming;
  126. } desc;
  127. unsigned int control_intf;
  128. struct usb_ep *control_ep;
  129. struct usb_request *control_req;
  130. void *control_buf;
  131. unsigned int streaming_intf;
  132. /* Events */
  133. unsigned int event_length;
  134. unsigned int event_setup_out : 1;
  135. };
  136. static inline struct uvc_device *to_uvc(struct usb_function *f)
  137. {
  138. return container_of(f, struct uvc_device, func);
  139. }
  140. struct uvc_file_handle {
  141. struct v4l2_fh vfh;
  142. struct uvc_video *device;
  143. bool is_uvc_app_handle;
  144. };
  145. #define to_uvc_file_handle(handle) \
  146. container_of(handle, struct uvc_file_handle, vfh)
  147. /* ------------------------------------------------------------------------
  148. * Functions
  149. */
  150. extern void uvc_function_setup_continue(struct uvc_device *uvc, int disable_ep);
  151. extern void uvc_function_connect(struct uvc_device *uvc);
  152. extern void uvc_function_disconnect(struct uvc_device *uvc);
  153. #endif /* _UVC_GADGET_H_ */