f_uvc.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * f_uvc.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 _F_UVC_H_
  14. #define _F_UVC_H_
  15. #include <linux/usb/composite.h>
  16. #define USB_CLASS_VIDEO_CONTROL 1
  17. #define USB_CLASS_VIDEO_STREAMING 2
  18. struct uvc_descriptor_header {
  19. __u8 bLength;
  20. __u8 bDescriptorType;
  21. __u8 bDescriptorSubType;
  22. } __attribute__ ((packed));
  23. struct uvc_header_descriptor {
  24. __u8 bLength;
  25. __u8 bDescriptorType;
  26. __u8 bDescriptorSubType;
  27. __u16 bcdUVC;
  28. __u16 wTotalLength;
  29. __u32 dwClockFrequency;
  30. __u8 bInCollection;
  31. __u8 baInterfaceNr[];
  32. } __attribute__((__packed__));
  33. #define UVC_HEADER_DESCRIPTOR(n) uvc_header_descriptor_##n
  34. #define DECLARE_UVC_HEADER_DESCRIPTOR(n) \
  35. struct UVC_HEADER_DESCRIPTOR(n) { \
  36. __u8 bLength; \
  37. __u8 bDescriptorType; \
  38. __u8 bDescriptorSubType; \
  39. __u16 bcdUVC; \
  40. __u16 wTotalLength; \
  41. __u32 dwClockFrequency; \
  42. __u8 bInCollection; \
  43. __u8 baInterfaceNr[n]; \
  44. } __attribute__ ((packed))
  45. struct uvc_input_terminal_descriptor {
  46. __u8 bLength;
  47. __u8 bDescriptorType;
  48. __u8 bDescriptorSubType;
  49. __u8 bTerminalID;
  50. __u16 wTerminalType;
  51. __u8 bAssocTerminal;
  52. __u8 iTerminal;
  53. } __attribute__((__packed__));
  54. struct uvc_output_terminal_descriptor {
  55. __u8 bLength;
  56. __u8 bDescriptorType;
  57. __u8 bDescriptorSubType;
  58. __u8 bTerminalID;
  59. __u16 wTerminalType;
  60. __u8 bAssocTerminal;
  61. __u8 bSourceID;
  62. __u8 iTerminal;
  63. } __attribute__((__packed__));
  64. struct uvc_camera_terminal_descriptor {
  65. __u8 bLength;
  66. __u8 bDescriptorType;
  67. __u8 bDescriptorSubType;
  68. __u8 bTerminalID;
  69. __u16 wTerminalType;
  70. __u8 bAssocTerminal;
  71. __u8 iTerminal;
  72. __u16 wObjectiveFocalLengthMin;
  73. __u16 wObjectiveFocalLengthMax;
  74. __u16 wOcularFocalLength;
  75. __u8 bControlSize;
  76. __u8 bmControls[3];
  77. } __attribute__((__packed__));
  78. struct uvc_selector_unit_descriptor {
  79. __u8 bLength;
  80. __u8 bDescriptorType;
  81. __u8 bDescriptorSubType;
  82. __u8 bUnitID;
  83. __u8 bNrInPins;
  84. __u8 baSourceID[0];
  85. __u8 iSelector;
  86. } __attribute__((__packed__));
  87. #define UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
  88. uvc_selector_unit_descriptor_##n
  89. #define DECLARE_UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
  90. struct UVC_SELECTOR_UNIT_DESCRIPTOR(n) { \
  91. __u8 bLength; \
  92. __u8 bDescriptorType; \
  93. __u8 bDescriptorSubType; \
  94. __u8 bUnitID; \
  95. __u8 bNrInPins; \
  96. __u8 baSourceID[n]; \
  97. __u8 iSelector; \
  98. } __attribute__ ((packed))
  99. struct uvc_processing_unit_descriptor {
  100. __u8 bLength;
  101. __u8 bDescriptorType;
  102. __u8 bDescriptorSubType;
  103. __u8 bUnitID;
  104. __u8 bSourceID;
  105. __u16 wMaxMultiplier;
  106. __u8 bControlSize;
  107. __u8 bmControls[2];
  108. __u8 iProcessing;
  109. } __attribute__((__packed__));
  110. struct uvc_extension_unit_descriptor {
  111. __u8 bLength;
  112. __u8 bDescriptorType;
  113. __u8 bDescriptorSubType;
  114. __u8 bUnitID;
  115. __u8 guidExtensionCode[16];
  116. __u8 bNumControls;
  117. __u8 bNrInPins;
  118. __u8 baSourceID[0];
  119. __u8 bControlSize;
  120. __u8 bmControls[0];
  121. __u8 iExtension;
  122. } __attribute__((__packed__));
  123. #define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
  124. uvc_extension_unit_descriptor_##p_##n
  125. #define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
  126. struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) { \
  127. __u8 bLength; \
  128. __u8 bDescriptorType; \
  129. __u8 bDescriptorSubType; \
  130. __u8 bUnitID; \
  131. __u8 guidExtensionCode[16]; \
  132. __u8 bNumControls; \
  133. __u8 bNrInPins; \
  134. __u8 baSourceID[p]; \
  135. __u8 bControlSize; \
  136. __u8 bmControls[n]; \
  137. __u8 iExtension; \
  138. } __attribute__ ((packed))
  139. struct uvc_control_endpoint_descriptor {
  140. __u8 bLength;
  141. __u8 bDescriptorType;
  142. __u8 bDescriptorSubType;
  143. __u16 wMaxTransferSize;
  144. } __attribute__((__packed__));
  145. #define UVC_DT_HEADER 1
  146. #define UVC_DT_INPUT_TERMINAL 2
  147. #define UVC_DT_OUTPUT_TERMINAL 3
  148. #define UVC_DT_SELECTOR_UNIT 4
  149. #define UVC_DT_PROCESSING_UNIT 5
  150. #define UVC_DT_EXTENSION_UNIT 6
  151. #define UVC_DT_HEADER_SIZE(n) (12+(n))
  152. #define UVC_DT_INPUT_TERMINAL_SIZE 8
  153. #define UVC_DT_OUTPUT_TERMINAL_SIZE 9
  154. #define UVC_DT_CAMERA_TERMINAL_SIZE(n) (15+(n))
  155. #define UVC_DT_SELECTOR_UNIT_SIZE(n) (6+(n))
  156. #define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
  157. #define UVC_DT_EXTENSION_UNIT_SIZE(p,n) (24+(p)+(n))
  158. #define UVC_DT_CONTROL_ENDPOINT_SIZE 5
  159. struct uvc_input_header_descriptor {
  160. __u8 bLength;
  161. __u8 bDescriptorType;
  162. __u8 bDescriptorSubType;
  163. __u8 bNumFormats;
  164. __u16 wTotalLength;
  165. __u8 bEndpointAddress;
  166. __u8 bmInfo;
  167. __u8 bTerminalLink;
  168. __u8 bStillCaptureMethod;
  169. __u8 bTriggerSupport;
  170. __u8 bTriggerUsage;
  171. __u8 bControlSize;
  172. __u8 bmaControls[];
  173. } __attribute__((__packed__));
  174. #define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
  175. uvc_input_header_descriptor_##n_##p
  176. #define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
  177. struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) { \
  178. __u8 bLength; \
  179. __u8 bDescriptorType; \
  180. __u8 bDescriptorSubType; \
  181. __u8 bNumFormats; \
  182. __u16 wTotalLength; \
  183. __u8 bEndpointAddress; \
  184. __u8 bmInfo; \
  185. __u8 bTerminalLink; \
  186. __u8 bStillCaptureMethod; \
  187. __u8 bTriggerSupport; \
  188. __u8 bTriggerUsage; \
  189. __u8 bControlSize; \
  190. __u8 bmaControls[p][n]; \
  191. } __attribute__ ((packed))
  192. struct uvc_output_header_descriptor {
  193. __u8 bLength;
  194. __u8 bDescriptorType;
  195. __u8 bDescriptorSubType;
  196. __u8 bNumFormats;
  197. __u16 wTotalLength;
  198. __u8 bEndpointAddress;
  199. __u8 bTerminalLink;
  200. __u8 bControlSize;
  201. __u8 bmaControls[];
  202. } __attribute__((__packed__));
  203. #define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
  204. uvc_output_header_descriptor_##n_##p
  205. #define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
  206. struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) { \
  207. __u8 bLength; \
  208. __u8 bDescriptorType; \
  209. __u8 bDescriptorSubType; \
  210. __u8 bNumFormats; \
  211. __u16 wTotalLength; \
  212. __u8 bEndpointAddress; \
  213. __u8 bTerminalLink; \
  214. __u8 bControlSize; \
  215. __u8 bmaControls[p][n]; \
  216. } __attribute__ ((packed))
  217. struct uvc_format_uncompressed {
  218. __u8 bLength;
  219. __u8 bDescriptorType;
  220. __u8 bDescriptorSubType;
  221. __u8 bFormatIndex;
  222. __u8 bNumFrameDescriptors;
  223. __u8 guidFormat[16];
  224. __u8 bBitsPerPixel;
  225. __u8 bDefaultFrameIndex;
  226. __u8 bAspectRatioX;
  227. __u8 bAspectRatioY;
  228. __u8 bmInterfaceFlags;
  229. __u8 bCopyProtect;
  230. } __attribute__((__packed__));
  231. struct uvc_frame_uncompressed {
  232. __u8 bLength;
  233. __u8 bDescriptorType;
  234. __u8 bDescriptorSubType;
  235. __u8 bFrameIndex;
  236. __u8 bmCapabilities;
  237. __u16 wWidth;
  238. __u16 wHeight;
  239. __u32 dwMinBitRate;
  240. __u32 dwMaxBitRate;
  241. __u32 dwMaxVideoFrameBufferSize;
  242. __u32 dwDefaultFrameInterval;
  243. __u8 bFrameIntervalType;
  244. __u32 dwFrameInterval[];
  245. } __attribute__((__packed__));
  246. #define UVC_FRAME_UNCOMPRESSED(n) \
  247. uvc_frame_uncompressed_##n
  248. #define DECLARE_UVC_FRAME_UNCOMPRESSED(n) \
  249. struct UVC_FRAME_UNCOMPRESSED(n) { \
  250. __u8 bLength; \
  251. __u8 bDescriptorType; \
  252. __u8 bDescriptorSubType; \
  253. __u8 bFrameIndex; \
  254. __u8 bmCapabilities; \
  255. __u16 wWidth; \
  256. __u16 wHeight; \
  257. __u32 dwMinBitRate; \
  258. __u32 dwMaxBitRate; \
  259. __u32 dwMaxVideoFrameBufferSize; \
  260. __u32 dwDefaultFrameInterval; \
  261. __u8 bFrameIntervalType; \
  262. __u32 dwFrameInterval[n]; \
  263. } __attribute__ ((packed))
  264. struct uvc_format_mjpeg {
  265. __u8 bLength;
  266. __u8 bDescriptorType;
  267. __u8 bDescriptorSubType;
  268. __u8 bFormatIndex;
  269. __u8 bNumFrameDescriptors;
  270. __u8 bmFlags;
  271. __u8 bDefaultFrameIndex;
  272. __u8 bAspectRatioX;
  273. __u8 bAspectRatioY;
  274. __u8 bmInterfaceFlags;
  275. __u8 bCopyProtect;
  276. } __attribute__((__packed__));
  277. struct uvc_frame_mjpeg {
  278. __u8 bLength;
  279. __u8 bDescriptorType;
  280. __u8 bDescriptorSubType;
  281. __u8 bFrameIndex;
  282. __u8 bmCapabilities;
  283. __u16 wWidth;
  284. __u16 wHeight;
  285. __u32 dwMinBitRate;
  286. __u32 dwMaxBitRate;
  287. __u32 dwMaxVideoFrameBufferSize;
  288. __u32 dwDefaultFrameInterval;
  289. __u8 bFrameIntervalType;
  290. __u32 dwFrameInterval[];
  291. } __attribute__((__packed__));
  292. #define UVC_FRAME_MJPEG(n) \
  293. uvc_frame_mjpeg_##n
  294. #define DECLARE_UVC_FRAME_MJPEG(n) \
  295. struct UVC_FRAME_MJPEG(n) { \
  296. __u8 bLength; \
  297. __u8 bDescriptorType; \
  298. __u8 bDescriptorSubType; \
  299. __u8 bFrameIndex; \
  300. __u8 bmCapabilities; \
  301. __u16 wWidth; \
  302. __u16 wHeight; \
  303. __u32 dwMinBitRate; \
  304. __u32 dwMaxBitRate; \
  305. __u32 dwMaxVideoFrameBufferSize; \
  306. __u32 dwDefaultFrameInterval; \
  307. __u8 bFrameIntervalType; \
  308. __u32 dwFrameInterval[n]; \
  309. } __attribute__ ((packed))
  310. struct uvc_color_matching_descriptor {
  311. __u8 bLength;
  312. __u8 bDescriptorType;
  313. __u8 bDescriptorSubType;
  314. __u8 bColorPrimaries;
  315. __u8 bTransferCharacteristics;
  316. __u8 bMatrixCoefficients;
  317. } __attribute__((__packed__));
  318. #define UVC_DT_INPUT_HEADER 1
  319. #define UVC_DT_OUTPUT_HEADER 2
  320. #define UVC_DT_FORMAT_UNCOMPRESSED 4
  321. #define UVC_DT_FRAME_UNCOMPRESSED 5
  322. #define UVC_DT_FORMAT_MJPEG 6
  323. #define UVC_DT_FRAME_MJPEG 7
  324. #define UVC_DT_COLOR_MATCHING 13
  325. #define UVC_DT_INPUT_HEADER_SIZE(n, p) (13+(n*p))
  326. #define UVC_DT_OUTPUT_HEADER_SIZE(n, p) (9+(n*p))
  327. #define UVC_DT_FORMAT_UNCOMPRESSED_SIZE 27
  328. #define UVC_DT_FRAME_UNCOMPRESSED_SIZE(n) (26+4*(n))
  329. #define UVC_DT_FORMAT_MJPEG_SIZE 11
  330. #define UVC_DT_FRAME_MJPEG_SIZE(n) (26+4*(n))
  331. #define UVC_DT_COLOR_MATCHING_SIZE 6
  332. extern int uvc_bind_config(struct usb_configuration *c,
  333. const struct uvc_descriptor_header * const *control,
  334. const struct uvc_descriptor_header * const *fs_streaming,
  335. const struct uvc_descriptor_header * const *hs_streaming);
  336. #endif /* _F_UVC_H_ */