xref: /openbsd/sys/dev/usb/uvideo.h (revision 3eb42298)
1*3eb42298Smglocker /*	$OpenBSD: uvideo.h,v 1.60 2019/12/08 13:21:21 mglocker Exp $ */
2c200fde7Smglocker 
3cf110a4aSrobert /*
4cf110a4aSrobert  * Copyright (c) 2007 Robert Nagy <robert@openbsd.org>
5cf110a4aSrobert  * Copyright (c) 2008 Marcus Glocker <mglocker@openbsd.org>
6cf110a4aSrobert  *
7cf110a4aSrobert  * Permission to use, copy, modify, and distribute this software for any
8cf110a4aSrobert  * purpose with or without fee is hereby granted, provided that the above
9cf110a4aSrobert  * copyright notice and this permission notice appear in all copies.
10cf110a4aSrobert  *
11cf110a4aSrobert  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12cf110a4aSrobert  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13cf110a4aSrobert  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14cf110a4aSrobert  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15cf110a4aSrobert  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16cf110a4aSrobert  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17cf110a4aSrobert  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18cf110a4aSrobert  */
19cf110a4aSrobert 
201dc1fa5aSmglocker #include <sys/queue.h>
21cf110a4aSrobert #include <sys/videoio.h>
22cf110a4aSrobert 
23cf110a4aSrobert /*
24cf110a4aSrobert  * USB Video Class
25cf110a4aSrobert  */
26cf110a4aSrobert /* Table A-7: Video Class-Specific Endpoint Descriptor Subtypes */
27cf110a4aSrobert #define	EP_UNDEFINED					0x00
28cf110a4aSrobert #define EP_GENERAL					0x01
29cf110a4aSrobert #define EP_ENDPOINT					0x02
30cf110a4aSrobert #define EP_INTERRUPT					0x03
31cf110a4aSrobert 
32cf110a4aSrobert /* Table A-5: Video Class-Specific VC Interface Descriptor Subtypes */
33cf110a4aSrobert #define	UDESCSUB_VC_DESCRIPTOR_UNDEFINED		0x00
34cf110a4aSrobert #define UDESCSUB_VC_HEADER				0x01
35cf110a4aSrobert #define UDESCSUB_VC_INPUT_TERMINAL			0x02
36cf110a4aSrobert #define UDESCSUB_VC_OUTPUT_TERMINAL			0x03
37cf110a4aSrobert #define UDESCSUB_VC_SELECTOR_UNIT			0x04
38cf110a4aSrobert #define UDESCSUB_VC_PROCESSING_UNIT			0x05
39cf110a4aSrobert #define UDESCSUB_VC_EXTENSION_UNIT			0x06
40cf110a4aSrobert 
41cf110a4aSrobert /* Table A-6: Video Class-Specific VS Interface Descriptor Subtypes */
42cf110a4aSrobert #define	UDESCSUB_VS_UNDEFINED				0x00
43cf110a4aSrobert #define UDESCSUB_VS_INPUT_HEADER			0x01
44cf110a4aSrobert #define UDESCSUB_VS_OUTPUT_HEADER			0x02
45cf110a4aSrobert #define UDESCSUB_VS_STILL_IMAGE_FRAME			0x03
46cf110a4aSrobert #define UDESCSUB_VS_FORMAT_UNCOMPRESSED			0x04
47cf110a4aSrobert #define UDESCSUB_VS_FRAME_UNCOMPRESSED			0x05
48cf110a4aSrobert #define UDESCSUB_VS_FORMAT_MJPEG			0x06
49cf110a4aSrobert #define UDESCSUB_VS_FRAME_MJPEG				0x07
50cf110a4aSrobert #define UDESCSUB_VS_FORMAT_MPEG2TS			0x0a
51cf110a4aSrobert #define UDESCSUB_VS_FORMAT_DV				0x0c
52cf110a4aSrobert #define UDESCSUB_VS_COLORFORMAT				0x0d
53cf110a4aSrobert #define UDESCSUB_VS_FORMAT_FRAME_BASED			0x10
54cf110a4aSrobert #define UDESCSUB_VS_FRAME_FRAME_BASED			0x11
55cf110a4aSrobert #define UDESCSUB_VS_FORMAT_STREAM_BASED			0x12
56cf110a4aSrobert 
57cf110a4aSrobert /* Table A-8: Video Class-Specific Request Codes */
58cf110a4aSrobert #define RC_UNDEFINED					0x00
59cf110a4aSrobert #define SET_CUR						0x01
60cf110a4aSrobert #define GET_CUR						0x81
61cf110a4aSrobert #define GET_MIN						0x82
62cf110a4aSrobert #define GET_MAX						0x83
63cf110a4aSrobert #define GET_RES						0x84
64cf110a4aSrobert #define GET_LEN						0x85
65cf110a4aSrobert #define GET_INFO					0x86
66cf110a4aSrobert #define GET_DEF						0x87
67cf110a4aSrobert 
68cf110a4aSrobert /* Table A-9: Video Control Interface Control Selectors */
69cf110a4aSrobert #define VC_CONTROL_UNDEFINED				0x00
70cf110a4aSrobert #define VC_VIDEO_POWER_MODE_CONTROL			0x01
71cf110a4aSrobert #define VC_REQUEST_ERROR_CODE_CONTROL			0x02
72cf110a4aSrobert 
73cf110a4aSrobert /* Table A-11: Selector Unit Control Selectors */
74cf110a4aSrobert #define	SU_CONTROL_UNDEFINED				0x00
75cf110a4aSrobert #define	SU_INPUT_SELECT_CONTROL				0x01
76cf110a4aSrobert 
77cf110a4aSrobert /* Table A-12: Camera Terminal Control Selectors */
78cf110a4aSrobert #define	CT_CONTROL_UNDEFINED				0x00
79cf110a4aSrobert #define	CT_SCANNING_MODE_CONTROL			0x01
80cf110a4aSrobert #define	CT_AE_MODE_CONTROL				0x02
81cf110a4aSrobert #define	CT_AE_PRIORITY_CONTROL				0x03
82cf110a4aSrobert #define	CT_EXPOSURE_TIME_ABSOLUTE_CONTROL		0x04
83cf110a4aSrobert #define	CT_EXPOSURE_TIME_RELATIVE_CONTROL		0x05
84cf110a4aSrobert #define	CT_FOCUS_ABSOLUTE_CONTROL			0x06
85cf110a4aSrobert #define	CT_FOCUS_RELATIVE_CONTROL			0x07
86cf110a4aSrobert #define	CT_FOCUS_AUTO_CONTROL				0x08
87cf110a4aSrobert #define	CT_IRIS_ABSOLUTE_CONTROL			0x09
88cf110a4aSrobert #define	CT_IRIS_RELATIVE_CONTROL			0x0a
89cf110a4aSrobert #define	CT_ZOOM_ABSOLUTE_CONTROL			0x0b
90cf110a4aSrobert #define	CT_ZOOM_RELATIVE_CONTROL			0x0c
91cf110a4aSrobert #define	CT_PANTILT_ABSOLUTE_CONTROL			0x0d
92cf110a4aSrobert #define	CT_PANTILT_RELATIVE_CONTROL			0x0e
93cf110a4aSrobert #define	CT_ROLL_ABSOLUTE_CONTROL			0x0f
94cf110a4aSrobert #define	CT_ROLL_RELATIVE_CONTROL			0x10
95cf110a4aSrobert #define	CT_PRIVACY_CONTROL				0x11
96cf110a4aSrobert 
97cf110a4aSrobert /* Table A-13: Processing Unit Control Selectors */
98cf110a4aSrobert #define	PU_CONTROL_UNDEFINED				0x00
99cf110a4aSrobert #define	PU_BACKLIGHT_COMPENSATION_CONTROL		0x01
100cf110a4aSrobert #define	PU_BRIGHTNESS_CONTROL				0x02
101cf110a4aSrobert #define	PU_CONTRAST_CONTROL				0x03
102cf110a4aSrobert #define	PU_GAIN_CONTROL					0x04
103cf110a4aSrobert #define	PU_POWER_LINE_FREQUENCY_CONTROL			0x05
104cf110a4aSrobert #define	PU_HUE_CONTROL					0x06
105cf110a4aSrobert #define	PU_SATURATION_CONTROL				0x07
106cf110a4aSrobert #define	PU_SHARPNESS_CONTROL				0x08
107cf110a4aSrobert #define	PU_GAMMA_CONTROL				0x09
108cf110a4aSrobert #define	PU_WHITE_BALANCE_TEMPERATURE_CONTROL		0x0a
109cf110a4aSrobert #define	PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL	0x0b
110cf110a4aSrobert #define	PU_WHITE_BALANCE_COMPONENT_CONTROL		0x0c
111cf110a4aSrobert #define	PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL		0x0d
112cf110a4aSrobert #define	PU_DIGITAL_MULTIPLIER_CONTROL			0x0e
113cf110a4aSrobert #define	PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL		0x0f
114cf110a4aSrobert #define	PU_HUE_AUTO_CONTROL				0x10
115cf110a4aSrobert #define	PU_ANALOG_VIDEO_STANDARD_CONTROL		0x11
116cf110a4aSrobert #define	PU_ANALOG_LOCK_STATUS_CONTROL			0x12
117cf110a4aSrobert 
118cf110a4aSrobert /* Table A-15: VideoStreaming Interface Control Selectors */
119cf110a4aSrobert #define	VS_CONTROL_UNDEFINED				0x00
120cf110a4aSrobert #define	VS_PROBE_CONTROL				0x01
121cf110a4aSrobert #define	VS_COMMIT_CONTROL				0x02
122cf110a4aSrobert #define	VS_STILL_PROBE_CONTROL				0x03
123cf110a4aSrobert #define	VS_STILL_COMMIT_CONTROL				0x04
124cf110a4aSrobert #define	VS_STILL_IMAGE_TRIGGER_CONTROL			0x05
125cf110a4aSrobert #define	VS_STREAM_ERROR_CODE_CONTROL			0x06
126cf110a4aSrobert #define	VS_GENERATE_KEY_FRAME_CONTROL			0x07
127cf110a4aSrobert #define	VS_UPDATE_FRAME_SEGMENT_CONTROL			0x08
128cf110a4aSrobert #define	VS_SYNC_DELAY_CONTROL				0x09
129cf110a4aSrobert 
130cf110a4aSrobert /* probe commit bmRequests */
131cf110a4aSrobert #define	UVIDEO_SET_IF					0x21
132cf110a4aSrobert #define	UVIDEO_GET_IF					0xa1
133cf110a4aSrobert #define	UVIDEO_SET_EP					0x22
134cf110a4aSrobert #define	UVIDEO_GET_EP					0xa2
135cf110a4aSrobert 
136cf110a4aSrobert /* Table B-1: USB Terminal Types */
137cf110a4aSrobert #define	TT_VENDOR_SPECIFIC				0x0100
138cf110a4aSrobert #define	TT_STREAMING					0x0101
139cf110a4aSrobert 
140cf110a4aSrobert /* Table B-2: Input Terminal Types */
141cf110a4aSrobert #define	ITT_VENDOR_SPECIFIC				0x0200
142cf110a4aSrobert #define	ITT_CAMERA					0x0201
143cf110a4aSrobert #define	ITT_MEDIA_TRANSPORT_INPUT			0x0202
144cf110a4aSrobert 
145cf110a4aSrobert /* Table B-3: Output Terminal Types */
146cf110a4aSrobert #define	OTT_VENDOR_SPECIFIC				0x0300
147cf110a4aSrobert #define	OTT_DISPLAY					0x0301
148cf110a4aSrobert #define	OTT_MEDIA_TRANSPORT_OUTPUT			0x0302
149cf110a4aSrobert 
150cf110a4aSrobert /* Table B-4: External Terminal Types */
151cf110a4aSrobert #define	EXTERNAL_VENDOR_SPECIFIC			0x0400
152cf110a4aSrobert #define	COMPOSITE_CONNECTOR				0x0401
153cf110a4aSrobert #define	SVIDEO_CONNECTOR				0x0402
154cf110a4aSrobert #define	COMPONENT_CONNECTOR				0x0403
155cf110a4aSrobert 
156cf110a4aSrobert /* Table 3-3: VC Interface Header Descriptor */
157cf110a4aSrobert struct usb_video_header_desc {
158cf110a4aSrobert 	uByte	bLength;
159cf110a4aSrobert 	uByte	bDescriptorType;
160cf110a4aSrobert 	uByte	bDescriptorSubtype;
161cf110a4aSrobert 	uWord	bcdUVC;
162cf110a4aSrobert 	uWord	wTotalLength;
163f72577ceSmglocker 	uDWord	dwClockFrequency;
164cf110a4aSrobert 	uByte	bInCollection;
165ba30c7beSmglocker } __packed;
166259e150dSmglocker 
167259e150dSmglocker struct usb_video_header_desc_all {
168259e150dSmglocker 	struct usb_video_header_desc	*fix;
169259e150dSmglocker 	uByte				*baInterfaceNr;
170cf110a4aSrobert };
171cf110a4aSrobert 
172cf110a4aSrobert /* Table 3-4: Input Terminal Descriptor */
173cf110a4aSrobert struct usb_video_input_terminal_desc {
174cf110a4aSrobert 	uByte	bLength;
175cf110a4aSrobert 	uByte	bDescriptorType;
176cf110a4aSrobert 	uByte	bDescriptorSubtype;
177cf110a4aSrobert 	uByte	bTerminalID;
178cf110a4aSrobert 	uWord	wTerminalType;
179cf110a4aSrobert 	uByte	bAssocTerminal;
180cf110a4aSrobert 	uByte	iTerminal;
181ba30c7beSmglocker } __packed;
182cf110a4aSrobert 
183cf110a4aSrobert /* Table 3-5: Output Terminal Descriptor */
184cf110a4aSrobert struct usb_video_output_terminal_desc {
185cf110a4aSrobert 	uByte	bLength;
186cf110a4aSrobert 	uByte	bDescriptorType;
187cf110a4aSrobert 	uByte	bDescriptorSubtype;
188cf110a4aSrobert 	uByte	bTerminalID;
189cf110a4aSrobert 	uWord	wTerminalType;
190cf110a4aSrobert 	uByte	bAssocTerminal;
191cf110a4aSrobert 	uByte	bSourceID;
192cf110a4aSrobert 	uByte	iTerminal;
193ba30c7beSmglocker } __packed;
194cf110a4aSrobert 
195cf110a4aSrobert /* Table 3-6: Camera Terminal Descriptor */
196cf110a4aSrobert struct usb_video_camera_terminal_desc {
197cf110a4aSrobert 	uByte	bLength;
198cf110a4aSrobert 	uByte	bDescriptorType;
199cf110a4aSrobert 	uByte	bDescriptorSubtype;
200cf110a4aSrobert 	uByte	bTerminalID;
201cf110a4aSrobert 	uWord	wTerminalType;
202cf110a4aSrobert 	uByte	bAssocTerminal;
203cf110a4aSrobert 	uByte	iTerminal;
204cf110a4aSrobert 	uWord	wObjectiveFocalLengthMin;
205cf110a4aSrobert 	uWord	wObjectiveFocalLengthMax;
206cf110a4aSrobert 	uWord	wOcularFocalLength;
207cf110a4aSrobert 	uByte	bControlSize;
208f72577ceSmglocker 	uByte	*bmControls;
209ba30c7beSmglocker } __packed;
210cf110a4aSrobert 
2112ee56f53Smglocker /* Table 3-8: VC Processing Unit Descriptor */
2122ee56f53Smglocker struct usb_video_vc_processing_desc {
2132ee56f53Smglocker 	uByte	bLength;
2142ee56f53Smglocker 	uByte	bDescriptorType;
2152ee56f53Smglocker 	uByte	bDescriptorSubtype;
2162ee56f53Smglocker 	uByte	bUnitID;
2172ee56f53Smglocker 	uByte	bSourceID;
2182ee56f53Smglocker 	uWord	wMaxMultiplier;
2192ee56f53Smglocker 	uByte	bControlSize;
220eea62ee3Sjakemsr 	uByte	bmControls[255]; /* [bControlSize] */
221eea62ee3Sjakemsr 	/* uByte iProcessing; */
222eea62ee3Sjakemsr 	/* uByte bmVideoStandards; */
2232ee56f53Smglocker } __packed;
2242ee56f53Smglocker 
22501c33b94Smglocker /* Table 3-9: VC Extension Unit Descriptor */
22601c33b94Smglocker struct usb_video_vc_extension_desc {
22701c33b94Smglocker 	uByte	bLength;
22801c33b94Smglocker 	uByte	bDescriptorType;
22901c33b94Smglocker 	uByte	bDescriptorSubtype;
23001c33b94Smglocker 	uByte	bUnitID;
23101c33b94Smglocker 	uByte	guidExtensionCode[16];
23201c33b94Smglocker 	uByte	bNumControls;
23301c33b94Smglocker 	uByte	bNrInPins;
23401c33b94Smglocker } __packed;
23501c33b94Smglocker 
236cf110a4aSrobert /* Table 3-11: VC Endpoint Descriptor */
237cf110a4aSrobert struct usb_video_vc_endpoint_desc {
238cf110a4aSrobert 	uByte	bLength;
239cf110a4aSrobert 	uByte	bDescriptorType;
240cf110a4aSrobert 	uByte	bDescriptorSubtype;
241cf110a4aSrobert 	uWord	wMaxTransferSize;
242ba30c7beSmglocker } __packed;
243cf110a4aSrobert 
24469db36cdSmglocker /* Table 3-13: Interface Input Header Descriptor */
24569db36cdSmglocker struct usb_video_input_header_desc {
24669db36cdSmglocker 	uByte	bLength;
24769db36cdSmglocker 	uByte	bDescriptorType;
24869db36cdSmglocker 	uByte	bDescriptorSubtype;
24969db36cdSmglocker 	uByte	bNumFormats;
25069db36cdSmglocker 	uWord	wTotalLength;
25169db36cdSmglocker 	uByte	bEndpointAddress;
25269db36cdSmglocker 	uByte	bmInfo;
25369db36cdSmglocker 	uByte	bTerminalLink;
25469db36cdSmglocker 	uByte	bStillCaptureMethod;
25569db36cdSmglocker 	uByte	bTriggerSupport;
25669db36cdSmglocker 	uByte	bTriggerUsage;
25769db36cdSmglocker 	uByte	bControlSize;
258ba30c7beSmglocker } __packed;
25969db36cdSmglocker 
260c668bad0Smglocker struct usb_video_input_header_desc_all {
261c668bad0Smglocker 	struct usb_video_input_header_desc	*fix;
262c668bad0Smglocker 	uByte					*bmaControls;
263c668bad0Smglocker };
264c668bad0Smglocker 
265cf110a4aSrobert /* Table 3-18: Color Matching Descriptor */
266cf110a4aSrobert struct usb_video_color_matching_descr {
267cf110a4aSrobert 	uByte	bLength;
268cf110a4aSrobert 	uByte	bDescriptorType;
269cf110a4aSrobert 	uByte	bDescriptorSubtype;
270cf110a4aSrobert 	uByte	bColorPrimaries;
271cf110a4aSrobert 	uByte	bTransferCharacteristics;
272cf110a4aSrobert 	uByte	bMatrixCoefficients;
273cf110a4aSrobert } __packed;
274cf110a4aSrobert 
275cf110a4aSrobert /* Table 4-47: Video Probe and Commit Controls */
276cf110a4aSrobert struct usb_video_probe_commit {
277259e150dSmglocker 	uWord	bmHint;
278cf110a4aSrobert 	uByte	bFormatIndex;
279cf110a4aSrobert 	uByte	bFrameIndex;
280259e150dSmglocker 	uDWord	dwFrameInterval;
281259e150dSmglocker 	uWord	wKeyFrameRate;
282259e150dSmglocker 	uWord	wPFrameRate;
283259e150dSmglocker 	uWord	wCompQuality;
284259e150dSmglocker 	uWord	wCompWindowSize;
285259e150dSmglocker 	uWord	wDelay;
286259e150dSmglocker 	uDWord	dwMaxVideoFrameSize;
287259e150dSmglocker 	uDWord	dwMaxPayloadTransferSize;
288bedd8548Smglocker 	uDWord	dwClockFrequency;
289cf110a4aSrobert 	uByte	bmFramingInfo;
290cf110a4aSrobert 	uByte	bPreferedVersion;
291cf110a4aSrobert 	uByte	bMinVersion;
292cf110a4aSrobert 	uByte	bMaxVersion;
293cf110a4aSrobert } __packed;
294cf110a4aSrobert 
295cf110a4aSrobert /*
296cf110a4aSrobert  * USB Video Payload Uncompressed
297cf110a4aSrobert  */
298cf110a4aSrobert /* Table 2-1: Compression Formats */
299cf110a4aSrobert #define	UVIDEO_FORMAT_GUID_YUY2	{			\
300cf110a4aSrobert     0x59, 0x55, 0x59, 0x32, 0x00, 0x00, 0x10, 0x00,	\
301cf110a4aSrobert     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
302cf110a4aSrobert 
303cf110a4aSrobert #define	UVIDEO_FORMAT_GUID_NV12	{			\
304cf110a4aSrobert     0x4e, 0x56, 0x31, 0x32, 0x00, 0x00, 0x10, 0x00,	\
305cf110a4aSrobert     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
306cf110a4aSrobert 
3071af93364Syuo #define	UVIDEO_FORMAT_GUID_UYVY	{			\
3081af93364Syuo     0x55, 0x59, 0x56, 0x59, 0x00, 0x00, 0x10, 0x00,	\
3091af93364Syuo     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
3101af93364Syuo 
3117431723dSpatrick #define	UVIDEO_FORMAT_GUID_KSMEDIA_L8_IR	{	\
3127431723dSpatrick     0x32, 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00,	\
3137431723dSpatrick     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
3147431723dSpatrick 
315cf110a4aSrobert /*
316cf110a4aSrobert  * USB Video Payload MJPEG
317cf110a4aSrobert  */
318cf110a4aSrobert /* Table 2-1: Stream Header Format for the Motion-JPEG */
31934070ee7Smglocker #define UVIDEO_SH_MAX_LEN	12
32034070ee7Smglocker #define UVIDEO_SH_MIN_LEN	2
32134070ee7Smglocker struct usb_video_stream_header {
32234070ee7Smglocker 	uByte	bLength;
32334070ee7Smglocker 	uByte	bFlags;
32434070ee7Smglocker #define	UVIDEO_SH_FLAG_FID	(1 << 0)
32534070ee7Smglocker #define	UVIDEO_SH_FLAG_EOF	(1 << 1)
32634070ee7Smglocker #define	UVIDEO_SH_FLAG_PTS	(1 << 2)
32734070ee7Smglocker #define	UVIDEO_SH_FLAG_SCR	(1 << 3)
32834070ee7Smglocker #define	UVIDEO_SH_FLAG_RES	(1 << 4)
32934070ee7Smglocker #define	UVIDEO_SH_FLAG_STI	(1 << 5)
33034070ee7Smglocker #define	UVIDEO_SH_FLAG_ERR	(1 << 6)
33134070ee7Smglocker #define	UVIDEO_SH_FLAG_EOH	(1 << 7)
33234070ee7Smglocker 	/* TODO complete struct */
33334070ee7Smglocker } __packed;
334cf110a4aSrobert 
335cf110a4aSrobert /* Table 3-1: Motion-JPEG Video Format Descriptor */
336259e150dSmglocker struct usb_video_format_mjpeg_desc {
337cf110a4aSrobert 	uByte	bLength;
338cf110a4aSrobert 	uByte	bDescriptorType;
339cf110a4aSrobert 	uByte	bDescriptorSubtype;
340cf110a4aSrobert 	uByte	bFormatIndex;
341cf110a4aSrobert 	uByte	bNumFrameDescriptors;
342cf110a4aSrobert 	uByte	bmFlags;
343cf110a4aSrobert 	uByte	bDefaultFrameIndex;
344cf110a4aSrobert 	uByte	bAspectRatioX;
345cf110a4aSrobert 	uByte	bAspectRatioY;
346cf110a4aSrobert 	uByte	bmInterlaceFlags;
347cf110a4aSrobert 	uByte	bCopyProtect;
348cf110a4aSrobert } __packed;
349cf110a4aSrobert 
3502bc1e751Sjakemsr /* Table 3-2: Video Frame Descriptor (same for mjpeg and uncompressed)*/
3512bc1e751Sjakemsr struct usb_video_frame_desc {
352cf110a4aSrobert 	uByte	bLength;
353cf110a4aSrobert 	uByte	bDescriptorType;
354cf110a4aSrobert 	uByte	bDescriptorSubtype;
355cf110a4aSrobert 	uByte	bFrameIndex;
356cf110a4aSrobert 	uByte	bmCapabilities;
357cf110a4aSrobert 	uWord	wWidth;
358cf110a4aSrobert 	uWord	wHeight;
359cf110a4aSrobert 	uDWord	dwMinBitRate;
360cf110a4aSrobert 	uDWord	dwMaxBitRate;
361cf110a4aSrobert 	uDWord	dwMaxVideoFrameBufferSize;
362eaa1845bSmglocker 	uDWord	dwDefaultFrameInterval;
363cf110a4aSrobert 	uByte	bFrameIntervalType;
364c9ba893eSjakemsr 	/* uDWord ivals[]; frame intervals, length varies */
365cf110a4aSrobert } __packed;
366cf110a4aSrobert 
367cf110a4aSrobert /*
368786c2e79Smglocker  * USB Video Payload Uncompressed
369786c2e79Smglocker  */
370786c2e79Smglocker /* Table 3-1: Uncompressed Video Format Descriptor */
371786c2e79Smglocker struct usb_video_format_uncompressed_desc {
372786c2e79Smglocker 	uByte	bLength;
373786c2e79Smglocker 	uByte	bDescriptorType;
374786c2e79Smglocker 	uByte	bDescriptorSubtype;
375786c2e79Smglocker 	uByte	bFormatIndex;
376786c2e79Smglocker 	uByte	bNumFrameDescriptors;
377786c2e79Smglocker 	uByte	guidFormat[16];
378786c2e79Smglocker 	uByte	bBitsPerPixel;
379786c2e79Smglocker 	uByte	bDefaultFrameIndex;
380786c2e79Smglocker 	uByte	bAspectRatioX;
381786c2e79Smglocker 	uByte	bAspectRatioY;
382786c2e79Smglocker 	uByte	bmInterlaceFlags;
383786c2e79Smglocker 	uByte	bCopyProtect;
384786c2e79Smglocker } __packed;
385786c2e79Smglocker 
386786c2e79Smglocker /*
387cf110a4aSrobert  * Driver specific private definitions.
388cf110a4aSrobert  */
389ff018eb9Smglocker struct uvideo_format_desc {
390ff018eb9Smglocker 	uByte	bLength;
391ff018eb9Smglocker 	uByte	bDescriptorType;
392ff018eb9Smglocker 	uByte	bDescriptorSubtype;
393ff018eb9Smglocker 	uByte	bFormatIndex;
394ff018eb9Smglocker 	uByte	bNumFrameDescriptors;
395ff018eb9Smglocker 	union {
396ff018eb9Smglocker 		/* mjpeg */
397ff018eb9Smglocker 		struct {
398ff018eb9Smglocker 			uByte	bmFlags;
399ff018eb9Smglocker 			uByte	bDefaultFrameIndex;
400ff018eb9Smglocker 			uByte	bAspectRatioX;
401ff018eb9Smglocker 			uByte	bAspectRatioY;
402ff018eb9Smglocker 			uByte	bmInterlaceFlags;
403ff018eb9Smglocker 			uByte	bCopyProtect;
404ff018eb9Smglocker 		} mjpeg;
405ff018eb9Smglocker 
406ff018eb9Smglocker 		/* uncompressed */
407ff018eb9Smglocker 		struct {
408ff018eb9Smglocker 			uByte	guidFormat[16];
409ff018eb9Smglocker 			uByte	bBitsPerPixel;
410ff018eb9Smglocker 			uByte	bDefaultFrameIndex;
411ff018eb9Smglocker 			uByte	bAspectRatioX;
412ff018eb9Smglocker 			uByte	bAspectRatioY;
413ff018eb9Smglocker 			uByte	bmInterlaceFlags;
414ff018eb9Smglocker 			uByte	bCopyProtect;
415ff018eb9Smglocker 		} uc;
416ff018eb9Smglocker 	} u;
417ff018eb9Smglocker } __packed;
418ff018eb9Smglocker 
419c57f28b1Syuo #define UVIDEO_NFRAMES_MAX	40
420dae55fb3Smglocker struct uvideo_isoc_xfer {
421ba30c7beSmglocker 	struct uvideo_softc	*sc;
422ab0b1be7Smglocker 	struct usbd_xfer	*xfer;
423ba30c7beSmglocker 	void			*buf;
424dae55fb3Smglocker 	uint16_t		 size[UVIDEO_NFRAMES_MAX];
425dae55fb3Smglocker };
426dae55fb3Smglocker 
427dae55fb3Smglocker struct uvideo_bulk_xfer {
428dae55fb3Smglocker 	struct uvideo_softc	*sc;
429ab0b1be7Smglocker 	struct usbd_xfer	*xfer;
430dae55fb3Smglocker 	void			*buf;
431dae55fb3Smglocker 	uint16_t		 size;
432dae55fb3Smglocker };
433dae55fb3Smglocker 
434dae55fb3Smglocker #define UVIDEO_IXFERS		3
435dae55fb3Smglocker struct uvideo_vs_iface {
436ab0b1be7Smglocker 	struct usbd_interface	*ifaceh;
437ab0b1be7Smglocker 	struct usbd_pipe	*pipeh;
438d0eede0cSmglocker 	int			 iface;
439ba30c7beSmglocker 	int			 numalts;
440ba30c7beSmglocker 	int			 curalt;
441d0eede0cSmglocker 	int			 endpoint;
442c57f28b1Syuo 	uint32_t		 psize;
44394e1c81bSmglocker 	int			 bulk_endpoint;
44494e1c81bSmglocker 	int			 bulk_running;
445dae55fb3Smglocker 	struct uvideo_isoc_xfer	 ixfer[UVIDEO_IXFERS];
446dae55fb3Smglocker 	struct uvideo_bulk_xfer	 bxfer;
447ba30c7beSmglocker };
448ba30c7beSmglocker 
449ba30c7beSmglocker struct uvideo_frame_buffer {
450ba30c7beSmglocker 	int		 sample;
451ba30c7beSmglocker 	uint8_t		 fid;
452ba30c7beSmglocker 	int		 offset;
453ba30c7beSmglocker 	int		 buf_size;
454ba30c7beSmglocker 	uint8_t		*buf;
45545b0d639Sjakemsr 	uint32_t	 fmt_flags;
456ba30c7beSmglocker };
457ba30c7beSmglocker 
458*3eb42298Smglocker /*
459*3eb42298Smglocker  * 1920x1080 uncompressed (e.g. YUYV422) requires ~4MB image data per frame.
460*3eb42298Smglocker  * 4MB * 8 frame buffers = 32MB kernel memory required.
461*3eb42298Smglocker  * With 8 frame buffers we are pretty safe not to run out of kernel memory.
462*3eb42298Smglocker  */
463*3eb42298Smglocker #define UVIDEO_MAX_BUFFERS	8
464ba30c7beSmglocker struct uvideo_mmap {
465ba30c7beSmglocker 	SIMPLEQ_ENTRY(uvideo_mmap)	q_frames;
466ba30c7beSmglocker 	uint8_t				*buf;
467ba30c7beSmglocker 	struct v4l2_buffer		 v4l2_buf;
468ba30c7beSmglocker };
469ba30c7beSmglocker typedef SIMPLEQ_HEAD(, uvideo_mmap) q_mmap;
470ba30c7beSmglocker 
47196d56267Smglocker struct uvideo_format_group {
47294047bb7Smglocker 	uint32_t				 pixelformat;
473ff018eb9Smglocker 	uint8_t					 format_dfidx;
47448ae767dSmglocker 	struct uvideo_format_desc		*format;
475ff018eb9Smglocker 	/* frame descriptors for mjpeg and uncompressed are identical */
476c4402e05Sweerd #define UVIDEO_MAX_FRAME			 32
4772bc1e751Sjakemsr 	struct usb_video_frame_desc		*frame_cur;
4782bc1e751Sjakemsr 	struct usb_video_frame_desc		*frame[UVIDEO_MAX_FRAME];
47948ae767dSmglocker 	int					 frame_num;
48048ae767dSmglocker };
48196d56267Smglocker 
48288daba3dSmglocker struct uvideo_res {
48388daba3dSmglocker 	int width;
48488daba3dSmglocker 	int height;
48588daba3dSmglocker 	int fidx;
486ba30c7beSmglocker };
48788daba3dSmglocker 
4882ee56f53Smglocker struct uvideo_controls {
4892ee56f53Smglocker 	int		cid;
4902ee56f53Smglocker 	int		type;
4912ee56f53Smglocker 	char		name[32];
492617c7f44Sjakemsr 	uint8_t         ctrl_bit;
4932ee56f53Smglocker 	uint16_t	ctrl_selector;
4942ee56f53Smglocker 	uint16_t	ctrl_len;
495767e272eSjakemsr 	int		sig;
4962ee56f53Smglocker } uvideo_ctrls[] = {
497617c7f44Sjakemsr         /*
498617c7f44Sjakemsr          * Processing Unit Controls
499617c7f44Sjakemsr          */
5002ee56f53Smglocker 	{
5012ee56f53Smglocker 	    V4L2_CID_BRIGHTNESS,
5022ee56f53Smglocker 	    V4L2_CTRL_TYPE_INTEGER,
5032ee56f53Smglocker 	    "Brightness",
504617c7f44Sjakemsr 	    0,
5052ee56f53Smglocker 	    PU_BRIGHTNESS_CONTROL,
506767e272eSjakemsr 	    2,
507767e272eSjakemsr 	    1
5082ee56f53Smglocker 	},
5092ee56f53Smglocker 	{
5102ee56f53Smglocker 	    V4L2_CID_CONTRAST,
5112ee56f53Smglocker 	    V4L2_CTRL_TYPE_INTEGER,
5122ee56f53Smglocker 	    "Contrast",
513617c7f44Sjakemsr 	    1,
5142ee56f53Smglocker 	    PU_CONTRAST_CONTROL,
515767e272eSjakemsr 	    2,
516767e272eSjakemsr 	    0
5172ee56f53Smglocker 	},
5182ee56f53Smglocker 	{
5192ee56f53Smglocker 	    V4L2_CID_HUE,
5202ee56f53Smglocker 	    V4L2_CTRL_TYPE_INTEGER,
5212ee56f53Smglocker 	    "Hue",
522617c7f44Sjakemsr 	    2,
5232ee56f53Smglocker 	    PU_HUE_CONTROL,
524767e272eSjakemsr 	    2,
525767e272eSjakemsr 	    1
5262ee56f53Smglocker 	},
5272ee56f53Smglocker 	{
5282ee56f53Smglocker 	    V4L2_CID_SATURATION,
5292ee56f53Smglocker 	    V4L2_CTRL_TYPE_INTEGER,
5302ee56f53Smglocker 	    "Saturation",
531617c7f44Sjakemsr 	    3,
5322ee56f53Smglocker 	    PU_SATURATION_CONTROL,
533767e272eSjakemsr 	    2,
534767e272eSjakemsr 	    0
5352ee56f53Smglocker 	},
5362ee56f53Smglocker 	{
537617c7f44Sjakemsr 	    V4L2_CID_SHARPNESS,
538617c7f44Sjakemsr 	    V4L2_CTRL_TYPE_INTEGER,
539617c7f44Sjakemsr 	    "Sharpness",
540617c7f44Sjakemsr 	    4,
541617c7f44Sjakemsr 	    PU_SHARPNESS_CONTROL,
542767e272eSjakemsr 	    2,
543767e272eSjakemsr 	    0
544617c7f44Sjakemsr 	},
545617c7f44Sjakemsr 	{
5462ee56f53Smglocker 	    V4L2_CID_GAMMA,
5472ee56f53Smglocker 	    V4L2_CTRL_TYPE_INTEGER,
5482ee56f53Smglocker 	    "Gamma",
549617c7f44Sjakemsr 	    5,
5502ee56f53Smglocker 	    PU_GAMMA_CONTROL,
551767e272eSjakemsr 	    2,
552767e272eSjakemsr 	    0
5532ee56f53Smglocker 	},
5542ee56f53Smglocker 	{
555617c7f44Sjakemsr 	    V4L2_CID_WHITE_BALANCE_TEMPERATURE,
556617c7f44Sjakemsr 	    V4L2_CTRL_TYPE_INTEGER,
557617c7f44Sjakemsr 	    "White Balance Temperature",
558617c7f44Sjakemsr 	    6,
559617c7f44Sjakemsr 	    PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
560767e272eSjakemsr 	    2,
561767e272eSjakemsr 	    0
562617c7f44Sjakemsr 	},
563617c7f44Sjakemsr #if 0
564617c7f44Sjakemsr         /* XXX Two V4L2 ids mapping one UVC control */
565617c7f44Sjakemsr 	{
566617c7f44Sjakemsr 	    V4L2_CID_RED_BALANCE, /* V4L2_CID_BLUE_BALANCE */
567617c7f44Sjakemsr 	    V4L2_CTRL_TYPE_INTEGER,
568617c7f44Sjakemsr 	    "White Balance Red Component", /* Blue Component */
569617c7f44Sjakemsr 	    7,
570617c7f44Sjakemsr 	    PU_WHITE_BALANCE_COMPONENT_CONTROL,
571767e272eSjakemsr 	    4,
572767e272eSjakemsr 	    0
573617c7f44Sjakemsr 	},
574617c7f44Sjakemsr #endif
575617c7f44Sjakemsr         {
576617c7f44Sjakemsr             V4L2_CID_BACKLIGHT_COMPENSATION,
577617c7f44Sjakemsr             V4L2_CTRL_TYPE_INTEGER,
578617c7f44Sjakemsr             "Backlight Compensation",
579617c7f44Sjakemsr             8,
580617c7f44Sjakemsr             PU_BACKLIGHT_COMPENSATION_CONTROL,
581617c7f44Sjakemsr             2,
582767e272eSjakemsr 	    0
583617c7f44Sjakemsr         },
584617c7f44Sjakemsr 	{
5852ee56f53Smglocker 	    V4L2_CID_GAIN,
5862ee56f53Smglocker 	    V4L2_CTRL_TYPE_INTEGER,
5872ee56f53Smglocker 	    "Gain",
588617c7f44Sjakemsr 	    9,
5892ee56f53Smglocker 	    PU_GAIN_CONTROL,
5902ee56f53Smglocker 	    2,
591767e272eSjakemsr 	    0
5922ee56f53Smglocker 	},
593617c7f44Sjakemsr         {
594617c7f44Sjakemsr             V4L2_CID_POWER_LINE_FREQUENCY,
595617c7f44Sjakemsr             V4L2_CTRL_TYPE_MENU,
596617c7f44Sjakemsr             "Power Line Frequency",
597617c7f44Sjakemsr             10,
598617c7f44Sjakemsr             PU_POWER_LINE_FREQUENCY_CONTROL,
599767e272eSjakemsr             2,
600767e272eSjakemsr 	    0
601617c7f44Sjakemsr         },
602617c7f44Sjakemsr         {
603617c7f44Sjakemsr             V4L2_CID_HUE_AUTO,
604617c7f44Sjakemsr             V4L2_CTRL_TYPE_BOOLEAN,
605617c7f44Sjakemsr             "Hue Auto",
606617c7f44Sjakemsr             11,
607617c7f44Sjakemsr             PU_HUE_AUTO_CONTROL,
608617c7f44Sjakemsr             1,
609767e272eSjakemsr 	    0
610617c7f44Sjakemsr         },
611617c7f44Sjakemsr         {
612617c7f44Sjakemsr             V4L2_CID_AUTO_WHITE_BALANCE,
613617c7f44Sjakemsr             V4L2_CTRL_TYPE_BOOLEAN,
614617c7f44Sjakemsr             "White Balance Temperature Auto",
615617c7f44Sjakemsr             12,
616617c7f44Sjakemsr             PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
617617c7f44Sjakemsr             1,
618767e272eSjakemsr 	    0
619617c7f44Sjakemsr         },
620617c7f44Sjakemsr         {
621617c7f44Sjakemsr             V4L2_CID_AUTO_WHITE_BALANCE,
622617c7f44Sjakemsr             V4L2_CTRL_TYPE_BOOLEAN,
623617c7f44Sjakemsr             "White Balance Component Auto",
624617c7f44Sjakemsr             13,
625617c7f44Sjakemsr             PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
626617c7f44Sjakemsr             1,
627767e272eSjakemsr 	    0
628617c7f44Sjakemsr         },
629617c7f44Sjakemsr #if 0
630617c7f44Sjakemsr         /* XXX No V4L2 CID for these controls? */
631617c7f44Sjakemsr         {
632617c7f44Sjakemsr             V4L2_CID_XXX,
633617c7f44Sjakemsr             V4L2_CTRL_TYPE_INTEGER,
634617c7f44Sjakemsr             "Digital Multiplier",
635617c7f44Sjakemsr             14,
636617c7f44Sjakemsr             PU_DIGITAL_MULTIPLIER_CONTROL,
637617c7f44Sjakemsr             2,
638767e272eSjakemsr 	    0
639617c7f44Sjakemsr         },
640617c7f44Sjakemsr         {
641617c7f44Sjakemsr             V4L2_CID_XXX,
642617c7f44Sjakemsr             V4L2_CTRL_TYPE_INTEGER,
643617c7f44Sjakemsr             "Digital Multiplier Limit",
644617c7f44Sjakemsr             15,
645617c7f44Sjakemsr             PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL,
646617c7f44Sjakemsr             2,
647767e272eSjakemsr 	    0
648617c7f44Sjakemsr         },
649617c7f44Sjakemsr         {
650617c7f44Sjakemsr             V4L2_CID_XXX,
651617c7f44Sjakemsr             V4L2_CTRL_TYPE_INTEGER,
652617c7f44Sjakemsr             "Analog Video Standard",
653617c7f44Sjakemsr             16,
654617c7f44Sjakemsr             PU_ANALOG_VIDEO_STANDARD_CONTROL,
655617c7f44Sjakemsr             1,
656767e272eSjakemsr 	    0
657617c7f44Sjakemsr         },
658617c7f44Sjakemsr         {
659617c7f44Sjakemsr             V4L2_CID_XXX,
660617c7f44Sjakemsr             V4L2_CTRL_TYPE_INTEGER,
661617c7f44Sjakemsr             "Analog Lock Status",
662617c7f44Sjakemsr             17,
663617c7f44Sjakemsr             PU_ANALOG_LOCK_STATUS_CONTROL,
664617c7f44Sjakemsr             1,
665767e272eSjakemsr 	    0
666617c7f44Sjakemsr         },
667617c7f44Sjakemsr #endif
668767e272eSjakemsr 	{ 0, 0, "", 0, 0, 0, 0 }
6692ee56f53Smglocker };
670