2 * f_uvc.h -- USB Video Class Gadget driver
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
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.
17 #include <linux/usb/composite.h>
19 #define USB_CLASS_VIDEO_CONTROL 1
20 #define USB_CLASS_VIDEO_STREAMING 2
22 struct uvc_descriptor_header {
25 __u8 bDescriptorSubType;
26 } __attribute__ ((packed));
28 struct uvc_header_descriptor {
31 __u8 bDescriptorSubType;
34 __u32 dwClockFrequency;
37 } __attribute__((__packed__));
39 #define UVC_HEADER_DESCRIPTOR(n) uvc_header_descriptor_##n
41 #define DECLARE_UVC_HEADER_DESCRIPTOR(n) \
42 struct UVC_HEADER_DESCRIPTOR(n) { \
44 __u8 bDescriptorType; \
45 __u8 bDescriptorSubType; \
48 __u32 dwClockFrequency; \
50 __u8 baInterfaceNr[n]; \
51 } __attribute__ ((packed))
53 struct uvc_input_terminal_descriptor {
56 __u8 bDescriptorSubType;
61 } __attribute__((__packed__));
63 struct uvc_output_terminal_descriptor {
66 __u8 bDescriptorSubType;
72 } __attribute__((__packed__));
74 struct uvc_camera_terminal_descriptor {
77 __u8 bDescriptorSubType;
82 __u16 wObjectiveFocalLengthMin;
83 __u16 wObjectiveFocalLengthMax;
84 __u16 wOcularFocalLength;
87 } __attribute__((__packed__));
89 struct uvc_selector_unit_descriptor {
92 __u8 bDescriptorSubType;
97 } __attribute__((__packed__));
99 #define UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
100 uvc_selector_unit_descriptor_##n
102 #define DECLARE_UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
103 struct UVC_SELECTOR_UNIT_DESCRIPTOR(n) { \
105 __u8 bDescriptorType; \
106 __u8 bDescriptorSubType; \
109 __u8 baSourceID[n]; \
111 } __attribute__ ((packed))
113 struct uvc_processing_unit_descriptor {
115 __u8 bDescriptorType;
116 __u8 bDescriptorSubType;
119 __u16 wMaxMultiplier;
123 } __attribute__((__packed__));
125 struct uvc_extension_unit_descriptor {
127 __u8 bDescriptorType;
128 __u8 bDescriptorSubType;
130 __u8 guidExtensionCode[16];
137 } __attribute__((__packed__));
139 #define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
140 uvc_extension_unit_descriptor_##p_##n
142 #define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
143 struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) { \
145 __u8 bDescriptorType; \
146 __u8 bDescriptorSubType; \
148 __u8 guidExtensionCode[16]; \
151 __u8 baSourceID[p]; \
153 __u8 bmControls[n]; \
155 } __attribute__ ((packed))
157 struct uvc_control_endpoint_descriptor {
159 __u8 bDescriptorType;
160 __u8 bDescriptorSubType;
161 __u16 wMaxTransferSize;
162 } __attribute__((__packed__));
164 #define UVC_DT_HEADER 1
165 #define UVC_DT_INPUT_TERMINAL 2
166 #define UVC_DT_OUTPUT_TERMINAL 3
167 #define UVC_DT_SELECTOR_UNIT 4
168 #define UVC_DT_PROCESSING_UNIT 5
169 #define UVC_DT_EXTENSION_UNIT 6
171 #define UVC_DT_HEADER_SIZE(n) (12+(n))
172 #define UVC_DT_INPUT_TERMINAL_SIZE 8
173 #define UVC_DT_OUTPUT_TERMINAL_SIZE 9
174 #define UVC_DT_CAMERA_TERMINAL_SIZE(n) (15+(n))
175 #define UVC_DT_SELECTOR_UNIT_SIZE(n) (6+(n))
176 #define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
177 #define UVC_DT_EXTENSION_UNIT_SIZE(p,n) (24+(p)+(n))
178 #define UVC_DT_CONTROL_ENDPOINT_SIZE 5
180 struct uvc_input_header_descriptor {
182 __u8 bDescriptorType;
183 __u8 bDescriptorSubType;
186 __u8 bEndpointAddress;
189 __u8 bStillCaptureMethod;
190 __u8 bTriggerSupport;
194 } __attribute__((__packed__));
196 #define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
197 uvc_input_header_descriptor_##n_##p
199 #define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
200 struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) { \
202 __u8 bDescriptorType; \
203 __u8 bDescriptorSubType; \
205 __u16 wTotalLength; \
206 __u8 bEndpointAddress; \
208 __u8 bTerminalLink; \
209 __u8 bStillCaptureMethod; \
210 __u8 bTriggerSupport; \
211 __u8 bTriggerUsage; \
213 __u8 bmaControls[p][n]; \
214 } __attribute__ ((packed))
216 struct uvc_output_header_descriptor {
218 __u8 bDescriptorType;
219 __u8 bDescriptorSubType;
222 __u8 bEndpointAddress;
226 } __attribute__((__packed__));
228 #define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
229 uvc_output_header_descriptor_##n_##p
231 #define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
232 struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) { \
234 __u8 bDescriptorType; \
235 __u8 bDescriptorSubType; \
237 __u16 wTotalLength; \
238 __u8 bEndpointAddress; \
239 __u8 bTerminalLink; \
241 __u8 bmaControls[p][n]; \
242 } __attribute__ ((packed))
244 struct uvc_format_uncompressed {
246 __u8 bDescriptorType;
247 __u8 bDescriptorSubType;
249 __u8 bNumFrameDescriptors;
252 __u8 bDefaultFrameIndex;
255 __u8 bmInterfaceFlags;
257 } __attribute__((__packed__));
259 struct uvc_frame_uncompressed {
261 __u8 bDescriptorType;
262 __u8 bDescriptorSubType;
269 __u32 dwMaxVideoFrameBufferSize;
270 __u32 dwDefaultFrameInterval;
271 __u8 bFrameIntervalType;
272 __u32 dwFrameInterval[];
273 } __attribute__((__packed__));
275 #define UVC_FRAME_UNCOMPRESSED(n) \
276 uvc_frame_uncompressed_##n
278 #define DECLARE_UVC_FRAME_UNCOMPRESSED(n) \
279 struct UVC_FRAME_UNCOMPRESSED(n) { \
281 __u8 bDescriptorType; \
282 __u8 bDescriptorSubType; \
284 __u8 bmCapabilities; \
287 __u32 dwMinBitRate; \
288 __u32 dwMaxBitRate; \
289 __u32 dwMaxVideoFrameBufferSize; \
290 __u32 dwDefaultFrameInterval; \
291 __u8 bFrameIntervalType; \
292 __u32 dwFrameInterval[n]; \
293 } __attribute__ ((packed))
295 struct uvc_format_mjpeg {
297 __u8 bDescriptorType;
298 __u8 bDescriptorSubType;
300 __u8 bNumFrameDescriptors;
302 __u8 bDefaultFrameIndex;
305 __u8 bmInterfaceFlags;
307 } __attribute__((__packed__));
309 struct uvc_frame_mjpeg {
311 __u8 bDescriptorType;
312 __u8 bDescriptorSubType;
319 __u32 dwMaxVideoFrameBufferSize;
320 __u32 dwDefaultFrameInterval;
321 __u8 bFrameIntervalType;
322 __u32 dwFrameInterval[];
323 } __attribute__((__packed__));
325 #define UVC_FRAME_MJPEG(n) \
328 #define DECLARE_UVC_FRAME_MJPEG(n) \
329 struct UVC_FRAME_MJPEG(n) { \
331 __u8 bDescriptorType; \
332 __u8 bDescriptorSubType; \
334 __u8 bmCapabilities; \
337 __u32 dwMinBitRate; \
338 __u32 dwMaxBitRate; \
339 __u32 dwMaxVideoFrameBufferSize; \
340 __u32 dwDefaultFrameInterval; \
341 __u8 bFrameIntervalType; \
342 __u32 dwFrameInterval[n]; \
343 } __attribute__ ((packed))
345 struct uvc_color_matching_descriptor {
347 __u8 bDescriptorType;
348 __u8 bDescriptorSubType;
349 __u8 bColorPrimaries;
350 __u8 bTransferCharacteristics;
351 __u8 bMatrixCoefficients;
352 } __attribute__((__packed__));
354 #define UVC_DT_INPUT_HEADER 1
355 #define UVC_DT_OUTPUT_HEADER 2
356 #define UVC_DT_FORMAT_UNCOMPRESSED 4
357 #define UVC_DT_FRAME_UNCOMPRESSED 5
358 #define UVC_DT_FORMAT_MJPEG 6
359 #define UVC_DT_FRAME_MJPEG 7
360 #define UVC_DT_COLOR_MATCHING 13
362 #define UVC_DT_INPUT_HEADER_SIZE(n, p) (13+(n*p))
363 #define UVC_DT_OUTPUT_HEADER_SIZE(n, p) (9+(n*p))
364 #define UVC_DT_FORMAT_UNCOMPRESSED_SIZE 27
365 #define UVC_DT_FRAME_UNCOMPRESSED_SIZE(n) (26+4*(n))
366 #define UVC_DT_FORMAT_MJPEG_SIZE 11
367 #define UVC_DT_FRAME_MJPEG_SIZE(n) (26+4*(n))
368 #define UVC_DT_COLOR_MATCHING_SIZE 6
370 extern int uvc_bind_config(struct usb_configuration *c,
371 const struct uvc_descriptor_header * const *control,
372 const struct uvc_descriptor_header * const *fs_streaming,
373 const struct uvc_descriptor_header * const *hs_streaming);
375 #endif /* _F_UVC_H_ */