uvc.h 4.6 KB

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