uvc.h 3.9 KB

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