uvc.h 3.8 KB

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