1f9f848faSopenharmony_ci/*-
2f9f848faSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause
3f9f848faSopenharmony_ci *
4f9f848faSopenharmony_ci * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
5f9f848faSopenharmony_ci * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
6f9f848faSopenharmony_ci * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
7f9f848faSopenharmony_ci *
8f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without
9f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions
10f9f848faSopenharmony_ci * are met:
11f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright
12f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer.
13f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
14f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
15f9f848faSopenharmony_ci *    documentation and/or other materials provided with the distribution.
16f9f848faSopenharmony_ci *
17f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18f9f848faSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19f9f848faSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20f9f848faSopenharmony_ci * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21f9f848faSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22f9f848faSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23f9f848faSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24f9f848faSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25f9f848faSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26f9f848faSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27f9f848faSopenharmony_ci * SUCH DAMAGE.
28f9f848faSopenharmony_ci */
29f9f848faSopenharmony_ci
30f9f848faSopenharmony_ci/*
31f9f848faSopenharmony_ci * This file contains standard definitions for the following USB
32f9f848faSopenharmony_ci * protocol versions:
33f9f848faSopenharmony_ci *
34f9f848faSopenharmony_ci * USB v1.0
35f9f848faSopenharmony_ci * USB v1.1
36f9f848faSopenharmony_ci * USB v2.0
37f9f848faSopenharmony_ci * USB v3.0
38f9f848faSopenharmony_ci */
39f9f848faSopenharmony_ci
40f9f848faSopenharmony_ci#ifndef _USB_STANDARD_H_
41f9f848faSopenharmony_ci#define	_USB_STANDARD_H_
42f9f848faSopenharmony_ci
43f9f848faSopenharmony_ci#if defined LOSCFG_DRIVERS_USB_HOST_EHCI
44f9f848faSopenharmony_ci#include "hisoc/usb.h"
45f9f848faSopenharmony_ci#endif
46f9f848faSopenharmony_ci#if defined LOSCFG_DRIVERS_USB_HOST_XHCI
47f9f848faSopenharmony_ci#include "hisoc/usb3.h"
48f9f848faSopenharmony_ci#endif
49f9f848faSopenharmony_ci
50f9f848faSopenharmony_ci/* Definition of some hardcoded USB constants. */
51f9f848faSopenharmony_ci
52f9f848faSopenharmony_ci#define	USB_MAX_IPACKET		8	/* initial USB packet size */
53f9f848faSopenharmony_ci#define	USB_EP_MAX (2*16)		/* hardcoded */
54f9f848faSopenharmony_ci#define	USB_ROOT_HUB_ADDR 1		/* index */
55f9f848faSopenharmony_ci#define	USB_MIN_DEVICES 2		/* unused + root HUB */
56f9f848faSopenharmony_ci#define	USB_UNCONFIG_INDEX 0xFF		/* internal use only */
57f9f848faSopenharmony_ci#define	USB_IFACE_INDEX_ANY 0xFF	/* internal use only */
58f9f848faSopenharmony_ci#define	USB_START_ADDR 0		/* default USB device BUS address
59f9f848faSopenharmony_ci					 * after USB bus reset */
60f9f848faSopenharmony_ci#define	USB_CONTROL_ENDPOINT 0		/* default control endpoint */
61f9f848faSopenharmony_ci
62f9f848faSopenharmony_ci#define	USB_FRAMES_PER_SECOND_FS 1000	/* full speed */
63f9f848faSopenharmony_ci#define	USB_FRAMES_PER_SECOND_HS 8000	/* high speed */
64f9f848faSopenharmony_ci
65f9f848faSopenharmony_ci#define	USB_FS_BYTES_PER_HS_UFRAME 188	/* bytes */
66f9f848faSopenharmony_ci#define	USB_HS_MICRO_FRAMES_MAX 8	/* units */
67f9f848faSopenharmony_ci
68f9f848faSopenharmony_ci#define	USB_ISOC_TIME_MAX 128		/* ms */
69f9f848faSopenharmony_ci
70f9f848faSopenharmony_ci/*
71f9f848faSopenharmony_ci * Minimum time a device needs to be powered down to go through a
72f9f848faSopenharmony_ci * power cycle. These values are not in the USB specification.
73f9f848faSopenharmony_ci */
74f9f848faSopenharmony_ci#define	USB_POWER_DOWN_TIME	200	/* ms */
75f9f848faSopenharmony_ci#define	USB_PORT_POWER_DOWN_TIME	100	/* ms */
76f9f848faSopenharmony_ci
77f9f848faSopenharmony_ci/* Definition of software USB power modes */
78f9f848faSopenharmony_ci#define	USB_POWER_MODE_OFF 0		/* turn off device */
79f9f848faSopenharmony_ci#define	USB_POWER_MODE_ON 1		/* always on */
80f9f848faSopenharmony_ci#define	USB_POWER_MODE_SAVE 2		/* automatic suspend and resume */
81f9f848faSopenharmony_ci#define	USB_POWER_MODE_SUSPEND 3	/* force suspend */
82f9f848faSopenharmony_ci#define	USB_POWER_MODE_RESUME 4		/* force resume */
83f9f848faSopenharmony_ci
84f9f848faSopenharmony_ci/* These are the values from the USB specification. */
85f9f848faSopenharmony_ci#define	USB_PORT_RESET_DELAY_SPEC	10	/* ms */
86f9f848faSopenharmony_ci#define	USB_PORT_ROOT_RESET_DELAY_SPEC	50	/* ms */
87f9f848faSopenharmony_ci#define	USB_PORT_RESET_RECOVERY_SPEC	10	/* ms */
88f9f848faSopenharmony_ci#define	USB_PORT_POWERUP_DELAY_SPEC	100	/* ms */
89f9f848faSopenharmony_ci#define	USB_PORT_RESUME_DELAY_SPEC	20	/* ms */
90f9f848faSopenharmony_ci#define	USB_SET_ADDRESS_SETTLE_SPEC	2	/* ms */
91f9f848faSopenharmony_ci#define	USB_RESUME_DELAY_SPEC		(20*5)	/* ms */
92f9f848faSopenharmony_ci#define	USB_RESUME_WAIT_SPEC		10	/* ms */
93f9f848faSopenharmony_ci#define	USB_RESUME_RECOVERY_SPEC	10	/* ms */
94f9f848faSopenharmony_ci#define	USB_EXTRA_POWER_UP_TIME_SPEC	0	/* ms */
95f9f848faSopenharmony_ci
96f9f848faSopenharmony_ci/* Allow for marginal and non-conforming devices. */
97f9f848faSopenharmony_ci#define	USB_PORT_RESET_DELAY		50	/* ms */
98f9f848faSopenharmony_ci#define	USB_PORT_ROOT_RESET_DELAY	250	/* ms */
99f9f848faSopenharmony_ci#define	USB_PORT_RESET_RECOVERY		250	/* ms */
100f9f848faSopenharmony_ci#define	USB_PORT_POWERUP_DELAY		300	/* ms */
101f9f848faSopenharmony_ci#define	USB_PORT_RESUME_DELAY		(20*2)	/* ms */
102f9f848faSopenharmony_ci#define	USB_SET_ADDRESS_SETTLE		10	/* ms */
103f9f848faSopenharmony_ci#define	USB_RESUME_DELAY		(50*5)	/* ms */
104f9f848faSopenharmony_ci#define	USB_RESUME_WAIT			50	/* ms */
105f9f848faSopenharmony_ci#define	USB_RESUME_RECOVERY		50	/* ms */
106f9f848faSopenharmony_ci#define	USB_EXTRA_POWER_UP_TIME		20	/* ms */
107f9f848faSopenharmony_ci
108f9f848faSopenharmony_ci#define	USB_MIN_POWER		100	/* mA */
109f9f848faSopenharmony_ci#define	USB_MAX_POWER		500	/* mA */
110f9f848faSopenharmony_ci
111f9f848faSopenharmony_ci#define	USB_BUS_RESET_DELAY	100	/* ms */
112f9f848faSopenharmony_ci
113f9f848faSopenharmony_ci/*
114f9f848faSopenharmony_ci * USB record layout in memory:
115f9f848faSopenharmony_ci *
116f9f848faSopenharmony_ci * - USB config 0
117f9f848faSopenharmony_ci *   - USB interfaces
118f9f848faSopenharmony_ci *     - USB alternative interfaces
119f9f848faSopenharmony_ci *       - USB endpoints
120f9f848faSopenharmony_ci *
121f9f848faSopenharmony_ci * - USB config 1
122f9f848faSopenharmony_ci *   - USB interfaces
123f9f848faSopenharmony_ci *     - USB alternative interfaces
124f9f848faSopenharmony_ci *       - USB endpoints
125f9f848faSopenharmony_ci */
126f9f848faSopenharmony_ci
127f9f848faSopenharmony_ci/* Declaration of USB records */
128f9f848faSopenharmony_ci
129f9f848faSopenharmony_cistruct usb_device_request {
130f9f848faSopenharmony_ci	uByte	bmRequestType;
131f9f848faSopenharmony_ci	uByte	bRequest;
132f9f848faSopenharmony_ci	uWord	wValue;
133f9f848faSopenharmony_ci	uWord	wIndex;
134f9f848faSopenharmony_ci	uWord	wLength;
135f9f848faSopenharmony_ci} __packed;
136f9f848faSopenharmony_citypedef struct usb_device_request usb_device_request_t;
137f9f848faSopenharmony_ci
138f9f848faSopenharmony_ci#define	UT_GET_DIR(a)		((a) & 0x80)
139f9f848faSopenharmony_ci#define	UT_WRITE		0x00
140f9f848faSopenharmony_ci#define	UT_READ			0x80
141f9f848faSopenharmony_ci
142f9f848faSopenharmony_ci#define	UT_GET_TYPE(a)		((a) & 0x60)
143f9f848faSopenharmony_ci#define	UT_STANDARD		0x00
144f9f848faSopenharmony_ci#define	UT_CLASS		0x20
145f9f848faSopenharmony_ci#define	UT_VENDOR		0x40
146f9f848faSopenharmony_ci
147f9f848faSopenharmony_ci#define	UT_GET_RECIPIENT(a) ((a) & 0x1f)
148f9f848faSopenharmony_ci#define	UT_DEVICE		0x00
149f9f848faSopenharmony_ci#define	UT_INTERFACE		0x01
150f9f848faSopenharmony_ci#define	UT_ENDPOINT		0x02
151f9f848faSopenharmony_ci#define	UT_OTHER		0x03
152f9f848faSopenharmony_ci
153f9f848faSopenharmony_ci#define	UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
154f9f848faSopenharmony_ci#define	UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
155f9f848faSopenharmony_ci#define	UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
156f9f848faSopenharmony_ci#define	UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
157f9f848faSopenharmony_ci#define	UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
158f9f848faSopenharmony_ci#define	UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
159f9f848faSopenharmony_ci#define	UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
160f9f848faSopenharmony_ci#define	UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
161f9f848faSopenharmony_ci#define	UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
162f9f848faSopenharmony_ci#define	UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
163f9f848faSopenharmony_ci#define	UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
164f9f848faSopenharmony_ci#define	UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
165f9f848faSopenharmony_ci#define	UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
166f9f848faSopenharmony_ci#define	UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
167f9f848faSopenharmony_ci#define	UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
168f9f848faSopenharmony_ci#define	UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
169f9f848faSopenharmony_ci#define	UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
170f9f848faSopenharmony_ci#define	UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
171f9f848faSopenharmony_ci#define	UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
172f9f848faSopenharmony_ci#define	UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
173f9f848faSopenharmony_ci#define	UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
174f9f848faSopenharmony_ci#define	UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
175f9f848faSopenharmony_ci
176f9f848faSopenharmony_ci/* Requests */
177f9f848faSopenharmony_ci#define	UR_GET_STATUS		0x00
178f9f848faSopenharmony_ci#define	UR_CLEAR_FEATURE	0x01
179f9f848faSopenharmony_ci#define	UR_SET_FEATURE		0x03
180f9f848faSopenharmony_ci#define	UR_SET_ADDRESS		0x05
181f9f848faSopenharmony_ci#define	UR_GET_DESCRIPTOR	0x06
182f9f848faSopenharmony_ci#define	UDESC_DEVICE		0x01
183f9f848faSopenharmony_ci#define	UDESC_CONFIG		0x02
184f9f848faSopenharmony_ci#define	UDESC_STRING		0x03
185f9f848faSopenharmony_ci#define	USB_LANGUAGE_TABLE	0x00	/* language ID string index */
186f9f848faSopenharmony_ci#define	UDESC_INTERFACE		0x04
187f9f848faSopenharmony_ci#define	UDESC_ENDPOINT		0x05
188f9f848faSopenharmony_ci#define	UDESC_DEVICE_QUALIFIER	0x06
189f9f848faSopenharmony_ci#define	UDESC_OTHER_SPEED_CONFIGURATION 0x07
190f9f848faSopenharmony_ci#define	UDESC_INTERFACE_POWER	0x08
191f9f848faSopenharmony_ci#define	UDESC_OTG		0x09
192f9f848faSopenharmony_ci#define	UDESC_DEBUG		0x0A
193f9f848faSopenharmony_ci#define	UDESC_IFACE_ASSOC	0x0B	/* interface association */
194f9f848faSopenharmony_ci#define	UDESC_BOS		0x0F	/* binary object store */
195f9f848faSopenharmony_ci#define	UDESC_DEVICE_CAPABILITY	0x10
196f9f848faSopenharmony_ci#define	UDESC_CS_DEVICE		0x21	/* class specific */
197f9f848faSopenharmony_ci#define	UDESC_CS_CONFIG		0x22
198f9f848faSopenharmony_ci#define	UDESC_CS_STRING		0x23
199f9f848faSopenharmony_ci#define	UDESC_CS_INTERFACE	0x24
200f9f848faSopenharmony_ci#define	UDESC_CS_ENDPOINT	0x25
201f9f848faSopenharmony_ci#define	UDESC_HUB		0x29
202f9f848faSopenharmony_ci#define	UDESC_SS_HUB		0x2A	/* super speed */
203f9f848faSopenharmony_ci#define	UDESC_ENDPOINT_SS_COMP	0x30	/* super speed */
204f9f848faSopenharmony_ci#define	UR_SET_DESCRIPTOR	0x07
205f9f848faSopenharmony_ci#define	UR_GET_CONFIG		0x08
206f9f848faSopenharmony_ci#define	UR_SET_CONFIG		0x09
207f9f848faSopenharmony_ci#define	UR_GET_INTERFACE	0x0a
208f9f848faSopenharmony_ci#define	UR_SET_INTERFACE	0x0b
209f9f848faSopenharmony_ci#define	UR_SYNCH_FRAME		0x0c
210f9f848faSopenharmony_ci#define	UR_SET_SEL		0x30
211f9f848faSopenharmony_ci#define	UR_ISOCH_DELAY		0x31
212f9f848faSopenharmony_ci
213f9f848faSopenharmony_ci/* HUB specific request */
214f9f848faSopenharmony_ci#define	UR_GET_BUS_STATE	0x02
215f9f848faSopenharmony_ci#define	UR_CLEAR_TT_BUFFER	0x08
216f9f848faSopenharmony_ci#define	UR_RESET_TT		0x09
217f9f848faSopenharmony_ci#define	UR_GET_TT_STATE		0x0a
218f9f848faSopenharmony_ci#define	UR_STOP_TT		0x0b
219f9f848faSopenharmony_ci#define	UR_SET_AND_TEST		0x0c	/* USB 2.0 only */
220f9f848faSopenharmony_ci#define	UR_SET_HUB_DEPTH	0x0c	/* USB 3.0 only */
221f9f848faSopenharmony_ci#define	USB_SS_HUB_DEPTH_MAX	5
222f9f848faSopenharmony_ci#define	UR_GET_PORT_ERR_COUNT	0x0d
223f9f848faSopenharmony_ci
224f9f848faSopenharmony_ci/* Feature numbers */
225f9f848faSopenharmony_ci#define	UF_ENDPOINT_HALT	0
226f9f848faSopenharmony_ci#define	UF_DEVICE_REMOTE_WAKEUP	1
227f9f848faSopenharmony_ci#define	UF_TEST_MODE		2
228f9f848faSopenharmony_ci#define	UF_DEVICE_B_HNP_ENABLE		3
229f9f848faSopenharmony_ci#define	UF_DEVICE_A_HNP_SUPPORT		4
230f9f848faSopenharmony_ci#define	UF_DEVICE_A_ALT_HNP_SUPPORT		5
231f9f848faSopenharmony_ci#define	UF_U1_ENABLE		0x30
232f9f848faSopenharmony_ci#define	UF_U2_ENABLE		0x31
233f9f848faSopenharmony_ci#define	UF_LTM_ENABLE		0x32
234f9f848faSopenharmony_ci
235f9f848faSopenharmony_ci/* HUB specific features */
236f9f848faSopenharmony_ci#define	UHF_C_HUB_LOCAL_POWER	0
237f9f848faSopenharmony_ci#define	UHF_C_HUB_OVER_CURRENT	1
238f9f848faSopenharmony_ci#define	UHF_PORT_CONNECTION	0
239f9f848faSopenharmony_ci#define	UHF_PORT_ENABLE		1
240f9f848faSopenharmony_ci#define	UHF_PORT_SUSPEND	2
241f9f848faSopenharmony_ci#define	UHF_PORT_OVER_CURRENT	3
242f9f848faSopenharmony_ci#define	UHF_PORT_RESET		4
243f9f848faSopenharmony_ci#define	UHF_PORT_LINK_STATE	5
244f9f848faSopenharmony_ci#define	UHF_PORT_POWER		8
245f9f848faSopenharmony_ci#define	UHF_PORT_LOW_SPEED	9
246f9f848faSopenharmony_ci#define	UHF_PORT_L1		10
247f9f848faSopenharmony_ci#define	UHF_C_PORT_CONNECTION	16
248f9f848faSopenharmony_ci#define	UHF_C_PORT_ENABLE	17
249f9f848faSopenharmony_ci#define	UHF_C_PORT_SUSPEND	18
250f9f848faSopenharmony_ci#define	UHF_C_PORT_OVER_CURRENT	19
251f9f848faSopenharmony_ci#define	UHF_C_PORT_RESET	20
252f9f848faSopenharmony_ci#define	UHF_PORT_TEST		21
253f9f848faSopenharmony_ci#define	UHF_PORT_INDICATOR	22
254f9f848faSopenharmony_ci#define	UHF_C_PORT_L1		23
255f9f848faSopenharmony_ci
256f9f848faSopenharmony_ci/* SuperSpeed HUB specific features */
257f9f848faSopenharmony_ci#define	UHF_PORT_U1_TIMEOUT	23
258f9f848faSopenharmony_ci#define	UHF_PORT_U2_TIMEOUT	24
259f9f848faSopenharmony_ci#define	UHF_C_PORT_LINK_STATE	25
260f9f848faSopenharmony_ci#define	UHF_C_PORT_CONFIG_ERROR	26
261f9f848faSopenharmony_ci#define	UHF_PORT_REMOTE_WAKE_MASK	27
262f9f848faSopenharmony_ci#define	UHF_BH_PORT_RESET	28
263f9f848faSopenharmony_ci#define	UHF_C_BH_PORT_RESET	29
264f9f848faSopenharmony_ci#define	UHF_FORCE_LINKPM_ACCEPT	30
265f9f848faSopenharmony_ci
266f9f848faSopenharmony_ci/* SuperSpeed suspend support */
267f9f848faSopenharmony_ci#define	USB_INTERFACE_FUNC_SUSPEND 0
268f9f848faSopenharmony_ci#define	USB_INTERFACE_FUNC_SUSPEND_LP	(1 << 8)
269f9f848faSopenharmony_ci#define	USB_INTERFACE_FUNC_SUSPEND_RW	(1 << 9)
270f9f848faSopenharmony_ci
271f9f848faSopenharmony_cistruct usb_descriptor {
272f9f848faSopenharmony_ci	uByte	bLength;
273f9f848faSopenharmony_ci	uByte	bDescriptorType;
274f9f848faSopenharmony_ci	uByte	bDescriptorSubtype;
275f9f848faSopenharmony_ci} __packed;
276f9f848faSopenharmony_citypedef struct usb_descriptor usb_descriptor_t;
277f9f848faSopenharmony_ci
278f9f848faSopenharmony_cistruct usb_device_descriptor {
279f9f848faSopenharmony_ci	uByte	bLength;
280f9f848faSopenharmony_ci	uByte	bDescriptorType;
281f9f848faSopenharmony_ci	uWord	bcdUSB;
282f9f848faSopenharmony_ci
283f9f848faSopenharmony_ci#define	UD_BCD_USB		0x0200
284f9f848faSopenharmony_ci#define	UD_USB_MPS		0x40
285f9f848faSopenharmony_ci
286f9f848faSopenharmony_ci	uByte	bDeviceClass;
287f9f848faSopenharmony_ci	uByte	bDeviceSubClass;
288f9f848faSopenharmony_ci	uByte	bDeviceProtocol;
289f9f848faSopenharmony_ci	uByte	bMaxPacketSize;
290f9f848faSopenharmony_ci	/* The fields below are not part of the initial descriptor. */
291f9f848faSopenharmony_ci	uWord	idVendor;
292f9f848faSopenharmony_ci	uWord	idProduct;
293f9f848faSopenharmony_ci	uWord	bcdDevice;
294f9f848faSopenharmony_ci	uByte	iManufacturer;
295f9f848faSopenharmony_ci	uByte	iProduct;
296f9f848faSopenharmony_ci	uByte	iSerialNumber;
297f9f848faSopenharmony_ci	uByte	bNumConfigurations;
298f9f848faSopenharmony_ci} __packed;
299f9f848faSopenharmony_citypedef struct usb_device_descriptor usb_device_descriptor_t;
300f9f848faSopenharmony_ci
301f9f848faSopenharmony_ci/* Binary Device Object Store (BOS) */
302f9f848faSopenharmony_cistruct usb_bos_descriptor {
303f9f848faSopenharmony_ci	uByte	bLength;
304f9f848faSopenharmony_ci	uByte	bDescriptorType;
305f9f848faSopenharmony_ci	uWord	wTotalLength;
306f9f848faSopenharmony_ci	uByte	bNumDeviceCaps;
307f9f848faSopenharmony_ci} __packed;
308f9f848faSopenharmony_citypedef struct usb_bos_descriptor usb_bos_descriptor_t;
309f9f848faSopenharmony_ci
310f9f848faSopenharmony_ci/* Binary Device Object Store Capability */
311f9f848faSopenharmony_cistruct usb_bos_cap_descriptor {
312f9f848faSopenharmony_ci	uByte	bLength;
313f9f848faSopenharmony_ci	uByte	bDescriptorType;
314f9f848faSopenharmony_ci	uByte	bDevCapabilityType;
315f9f848faSopenharmony_ci#define	USB_DEVCAP_RESERVED	0x00
316f9f848faSopenharmony_ci#define	USB_DEVCAP_WUSB		0x01
317f9f848faSopenharmony_ci#define	USB_DEVCAP_USB2EXT	0x02
318f9f848faSopenharmony_ci#define	USB_DEVCAP_SUPER_SPEED	0x03
319f9f848faSopenharmony_ci#define	USB_DEVCAP_CONTAINER_ID	0x04
320f9f848faSopenharmony_ci	/* data ... */
321f9f848faSopenharmony_ci} __packed;
322f9f848faSopenharmony_citypedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
323f9f848faSopenharmony_ci
324f9f848faSopenharmony_cistruct usb_devcap_usb2ext_descriptor {
325f9f848faSopenharmony_ci	uByte	bLength;
326f9f848faSopenharmony_ci	uByte	bDescriptorType;
327f9f848faSopenharmony_ci	uByte	bDevCapabilityType;
328f9f848faSopenharmony_ci	uDWord	bmAttributes;
329f9f848faSopenharmony_ci#define	USB_V2EXT_LPM (1U << 1)
330f9f848faSopenharmony_ci#define	USB_V2EXT_BESL_SUPPORTED (1U << 2)
331f9f848faSopenharmony_ci#define	USB_V2EXT_BESL_BASELINE_VALID (1U << 3)
332f9f848faSopenharmony_ci#define	USB_V2EXT_BESL_DEEP_VALID (1U << 4)
333f9f848faSopenharmony_ci#define	USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF)
334f9f848faSopenharmony_ci#define	USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF)
335f9f848faSopenharmony_ci} __packed;
336f9f848faSopenharmony_citypedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
337f9f848faSopenharmony_ci
338f9f848faSopenharmony_cistruct usb_devcap_ss_descriptor {
339f9f848faSopenharmony_ci	uByte	bLength;
340f9f848faSopenharmony_ci	uByte	bDescriptorType;
341f9f848faSopenharmony_ci	uByte	bDevCapabilityType;
342f9f848faSopenharmony_ci	uByte	bmAttributes;
343f9f848faSopenharmony_ci	uWord	wSpeedsSupported;
344f9f848faSopenharmony_ci	uByte	bFunctionalitySupport;
345f9f848faSopenharmony_ci	uByte	bU1DevExitLat;
346f9f848faSopenharmony_ci	uWord	wU2DevExitLat;
347f9f848faSopenharmony_ci} __packed;
348f9f848faSopenharmony_citypedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
349f9f848faSopenharmony_ci
350f9f848faSopenharmony_cistruct usb_devcap_container_id_descriptor {
351f9f848faSopenharmony_ci	uByte	bLength;
352f9f848faSopenharmony_ci	uByte	bDescriptorType;
353f9f848faSopenharmony_ci	uByte	bDevCapabilityType;
354f9f848faSopenharmony_ci	uByte	bReserved;
355f9f848faSopenharmony_ci	uByte	bContainerID;
356f9f848faSopenharmony_ci} __packed;
357f9f848faSopenharmony_citypedef struct usb_devcap_container_id_descriptor
358f9f848faSopenharmony_ci		usb_devcap_container_id_descriptor_t;
359f9f848faSopenharmony_ci
360f9f848faSopenharmony_ci/* Device class codes */
361f9f848faSopenharmony_ci#define	UDCLASS_IN_INTERFACE	0x00
362f9f848faSopenharmony_ci#define	UDCLASS_COMM		0x02
363f9f848faSopenharmony_ci#define	UDCLASS_HUB		0x09
364f9f848faSopenharmony_ci#define	UDSUBCLASS_HUB		0x00
365f9f848faSopenharmony_ci#define	UDPROTO_FSHUB		0x00
366f9f848faSopenharmony_ci#define	UDPROTO_HSHUBSTT	0x01
367f9f848faSopenharmony_ci#define	UDPROTO_HSHUBMTT	0x02
368f9f848faSopenharmony_ci#define	UDPROTO_SSHUB		0x03
369f9f848faSopenharmony_ci#define	UDCLASS_DIAGNOSTIC	0xdc
370f9f848faSopenharmony_ci#define	UDCLASS_WIRELESS	0xe0
371f9f848faSopenharmony_ci#define	UDSUBCLASS_RF		0x01
372f9f848faSopenharmony_ci#define	UDPROTO_BLUETOOTH	0x01
373f9f848faSopenharmony_ci#define	UDCLASS_MISC		0xef
374f9f848faSopenharmony_ci#define	UDCLASS_VENDOR		0xff
375f9f848faSopenharmony_ci
376f9f848faSopenharmony_ci
377f9f848faSopenharmony_ci#define	USB_CONFIG_DESC_SIZE		9
378f9f848faSopenharmony_cistruct usb_config_descriptor {
379f9f848faSopenharmony_ci	uByte	bLength;
380f9f848faSopenharmony_ci	uByte	bDescriptorType;
381f9f848faSopenharmony_ci	uWord	wTotalLength;
382f9f848faSopenharmony_ci	uByte	bNumInterface;
383f9f848faSopenharmony_ci	uByte	bConfigurationValue;
384f9f848faSopenharmony_ci#define	USB_UNCONFIG_NO 0
385f9f848faSopenharmony_ci	uByte	iConfiguration;
386f9f848faSopenharmony_ci	uByte	bmAttributes;
387f9f848faSopenharmony_ci#define	UC_BUS_POWERED		0x80
388f9f848faSopenharmony_ci#define	UC_SELF_POWERED		0x40
389f9f848faSopenharmony_ci#define	UC_REMOTE_WAKEUP	0x20
390f9f848faSopenharmony_ci	uByte	bMaxPower;		/* max current in 2 mA units */
391f9f848faSopenharmony_ci#define	UC_POWER_FACTOR 2
392f9f848faSopenharmony_ci} __packed;
393f9f848faSopenharmony_citypedef struct usb_config_descriptor usb_config_descriptor_t;
394f9f848faSopenharmony_ci
395f9f848faSopenharmony_cistruct usb_interface_descriptor {
396f9f848faSopenharmony_ci	uByte	bLength;
397f9f848faSopenharmony_ci	uByte	bDescriptorType;
398f9f848faSopenharmony_ci	uByte	bInterfaceNumber;
399f9f848faSopenharmony_ci	uByte	bAlternateSetting;
400f9f848faSopenharmony_ci	uByte	bNumEndpoints;
401f9f848faSopenharmony_ci	uByte	bInterfaceClass;
402f9f848faSopenharmony_ci	uByte	bInterfaceSubClass;
403f9f848faSopenharmony_ci	uByte	bInterfaceProtocol;
404f9f848faSopenharmony_ci	uByte	iInterface;
405f9f848faSopenharmony_ci} __packed;
406f9f848faSopenharmony_citypedef struct usb_interface_descriptor usb_interface_descriptor_t;
407f9f848faSopenharmony_ci
408f9f848faSopenharmony_cistruct usb_interface_assoc_descriptor {
409f9f848faSopenharmony_ci	uByte	bLength;
410f9f848faSopenharmony_ci	uByte	bDescriptorType;
411f9f848faSopenharmony_ci	uByte	bFirstInterface;
412f9f848faSopenharmony_ci	uByte	bInterfaceCount;
413f9f848faSopenharmony_ci	uByte	bFunctionClass;
414f9f848faSopenharmony_ci	uByte	bFunctionSubClass;
415f9f848faSopenharmony_ci	uByte	bFunctionProtocol;
416f9f848faSopenharmony_ci	uByte	iFunction;
417f9f848faSopenharmony_ci} __packed;
418f9f848faSopenharmony_citypedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
419f9f848faSopenharmony_ci
420f9f848faSopenharmony_ci/* Interface class codes */
421f9f848faSopenharmony_ci#define	UICLASS_UNSPEC		0x00
422f9f848faSopenharmony_ci#define	UICLASS_AUDIO		0x01	/* audio */
423f9f848faSopenharmony_ci#define	UISUBCLASS_AUDIOCONTROL	1
424f9f848faSopenharmony_ci#define	UISUBCLASS_AUDIOSTREAM		2
425f9f848faSopenharmony_ci#define	UISUBCLASS_MIDISTREAM		3
426f9f848faSopenharmony_ci
427f9f848faSopenharmony_ci#define	UICLASS_CDC		0x02	/* communication */
428f9f848faSopenharmony_ci#define	UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
429f9f848faSopenharmony_ci#define	UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
430f9f848faSopenharmony_ci#define	UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
431f9f848faSopenharmony_ci#define	UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
432f9f848faSopenharmony_ci#define	UISUBCLASS_CAPI_CONTROLMODEL		5
433f9f848faSopenharmony_ci#define	UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
434f9f848faSopenharmony_ci#define	UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
435f9f848faSopenharmony_ci#define	UISUBCLASS_WIRELESS_HANDSET_CM 8
436f9f848faSopenharmony_ci#define	UISUBCLASS_DEVICE_MGMT 9
437f9f848faSopenharmony_ci#define	UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
438f9f848faSopenharmony_ci#define	UISUBCLASS_OBEX 11
439f9f848faSopenharmony_ci#define	UISUBCLASS_ETHERNET_EMULATION_MODEL 12
440f9f848faSopenharmony_ci#define	UISUBCLASS_NETWORK_CONTROL_MODEL 13
441f9f848faSopenharmony_ci
442f9f848faSopenharmony_ci#define	UIPROTO_CDC_NONE		0
443f9f848faSopenharmony_ci#define	UIPROTO_CDC_AT			1
444f9f848faSopenharmony_ci#define	UIPROTO_CDC_EEM			7
445f9f848faSopenharmony_ci
446f9f848faSopenharmony_ci#define	UICLASS_HID		0x03
447f9f848faSopenharmony_ci#define	UISUBCLASS_BOOT		1
448f9f848faSopenharmony_ci#define	UIPROTO_BOOT_KEYBOARD	1
449f9f848faSopenharmony_ci#define	UIPROTO_MOUSE		2
450f9f848faSopenharmony_ci
451f9f848faSopenharmony_ci#define	UICLASS_PHYSICAL	0x05
452f9f848faSopenharmony_ci#define	UICLASS_IMAGE		0x06
453f9f848faSopenharmony_ci#define	UISUBCLASS_SIC		1	/* still image class */
454f9f848faSopenharmony_ci#define	UICLASS_PRINTER		0x07
455f9f848faSopenharmony_ci#define	UISUBCLASS_PRINTER	1
456f9f848faSopenharmony_ci#define	UIPROTO_PRINTER_UNI	1
457f9f848faSopenharmony_ci#define	UIPROTO_PRINTER_BI	2
458f9f848faSopenharmony_ci#define	UIPROTO_PRINTER_1284	3
459f9f848faSopenharmony_ci
460f9f848faSopenharmony_ci#define	UICLASS_MASS		0x08
461f9f848faSopenharmony_ci#define	UISUBCLASS_RBC		1
462f9f848faSopenharmony_ci#define	UISUBCLASS_SFF8020I	2
463f9f848faSopenharmony_ci#define	UISUBCLASS_QIC157	3
464f9f848faSopenharmony_ci#define	UISUBCLASS_UFI		4
465f9f848faSopenharmony_ci#define	UISUBCLASS_SFF8070I	5
466f9f848faSopenharmony_ci#define	UISUBCLASS_SCSI		6
467f9f848faSopenharmony_ci#define	UIPROTO_MASS_CBI_I	0
468f9f848faSopenharmony_ci#define	UIPROTO_MASS_CBI	1
469f9f848faSopenharmony_ci#define	UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
470f9f848faSopenharmony_ci#define	UIPROTO_MASS_BULK	0x50	/* Bulk only */
471f9f848faSopenharmony_ci#define	UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
472f9f848faSopenharmony_ci
473f9f848faSopenharmony_ci#define	UICLASS_HUB		0x09
474f9f848faSopenharmony_ci#define	UISUBCLASS_HUB		0
475f9f848faSopenharmony_ci#define	UIPROTO_FSHUB		0
476f9f848faSopenharmony_ci#define	UIPROTO_HSHUBSTT	0	/* Yes, same as previous */
477f9f848faSopenharmony_ci#define	UIPROTO_HSHUBMTT	1
478f9f848faSopenharmony_ci
479f9f848faSopenharmony_ci#define	UICLASS_CDC_DATA	0x0a
480f9f848faSopenharmony_ci#define	UISUBCLASS_DATA		0x00
481f9f848faSopenharmony_ci#define	UIPROTO_DATA_ISDNBRI		0x30	/* Physical iface */
482f9f848faSopenharmony_ci#define	UIPROTO_DATA_HDLC		0x31	/* HDLC */
483f9f848faSopenharmony_ci#define	UIPROTO_DATA_TRANSPARENT	0x32	/* Transparent */
484f9f848faSopenharmony_ci#define	UIPROTO_DATA_Q921M		0x50	/* Management for Q921 */
485f9f848faSopenharmony_ci#define	UIPROTO_DATA_Q921		0x51	/* Data for Q921 */
486f9f848faSopenharmony_ci#define	UIPROTO_DATA_Q921TM		0x52	/* TEI multiplexer for Q921 */
487f9f848faSopenharmony_ci#define	UIPROTO_DATA_V42BIS		0x90	/* Data compression */
488f9f848faSopenharmony_ci#define	UIPROTO_DATA_Q931		0x91	/* Euro-ISDN */
489f9f848faSopenharmony_ci#define	UIPROTO_DATA_V120		0x92	/* V.24 rate adaption */
490f9f848faSopenharmony_ci#define	UIPROTO_DATA_CAPI		0x93	/* CAPI 2.0 commands */
491f9f848faSopenharmony_ci#define	UIPROTO_DATA_HOST_BASED		0xfd	/* Host based driver */
492f9f848faSopenharmony_ci#define	UIPROTO_DATA_PUF		0xfe	/* see Prot. Unit Func. Desc. */
493f9f848faSopenharmony_ci#define	UIPROTO_DATA_VENDOR		0xff	/* Vendor specific */
494f9f848faSopenharmony_ci#define	UIPROTO_DATA_NCM		0x01	/* Network Control Model */
495f9f848faSopenharmony_ci
496f9f848faSopenharmony_ci#define	UICLASS_SMARTCARD	0x0b
497f9f848faSopenharmony_ci#define	UICLASS_FIRM_UPD	0x0c
498f9f848faSopenharmony_ci#define	UICLASS_SECURITY	0x0d
499f9f848faSopenharmony_ci
500f9f848faSopenharmony_ci/* From USB Video Class Specification, 1.5, section A.1, A.2 & A.3 */
501f9f848faSopenharmony_ci#define	UICLASS_VIDEO		0x0e
502f9f848faSopenharmony_ci#define	UICLASS_VIDEO_CONTROL		0x01
503f9f848faSopenharmony_ci#define	UICLASS_VIDEO_STREAMING		0x02
504f9f848faSopenharmony_ci#define	UICLASS_VIDEO_INTERFACE_COLLECTION	0x03
505f9f848faSopenharmony_ci#define	UICLASS_VIDEO_PROTOCOL_UNDEFINED	0x0
506f9f848faSopenharmony_ci#define	UICLASS_VIDEO_PROTOCOL_15		0x1
507f9f848faSopenharmony_ci
508f9f848faSopenharmony_ci#define	UICLASS_DIAGNOSTIC	0xdc
509f9f848faSopenharmony_ci#define	UICLASS_WIRELESS	0xe0
510f9f848faSopenharmony_ci#define	UISUBCLASS_RF			0x01
511f9f848faSopenharmony_ci#define	UIPROTO_BLUETOOTH		0x01
512f9f848faSopenharmony_ci#define	UIPROTO_RNDIS			0x03
513f9f848faSopenharmony_ci
514f9f848faSopenharmony_ci#define	UICLASS_IAD		0xEF	/* Interface Association Descriptor */
515f9f848faSopenharmony_ci#define	UISUBCLASS_SYNC			0x01
516f9f848faSopenharmony_ci#define	UIPROTO_ACTIVESYNC		0x01
517f9f848faSopenharmony_ci
518f9f848faSopenharmony_ci#define	UICLASS_APPL_SPEC	0xfe
519f9f848faSopenharmony_ci#define	UISUBCLASS_FIRMWARE_DOWNLOAD	1
520f9f848faSopenharmony_ci#define	UISUBCLASS_IRDA			2
521f9f848faSopenharmony_ci#define	UIPROTO_IRDA			0
522f9f848faSopenharmony_ci
523f9f848faSopenharmony_ci#define	UICLASS_VENDOR		0xff
524f9f848faSopenharmony_ci#define	UISUBCLASS_XBOX360_CONTROLLER	0x5d
525f9f848faSopenharmony_ci#define	UISUBCLASS_VENDOR	0xff
526f9f848faSopenharmony_ci#define	UIPROTO_XBOX360_GAMEPAD	0x01
527f9f848faSopenharmony_ci
528f9f848faSopenharmony_cistruct usb_endpoint_descriptor {
529f9f848faSopenharmony_ci	uByte	bLength;
530f9f848faSopenharmony_ci	uByte	bDescriptorType;
531f9f848faSopenharmony_ci	uByte	bEndpointAddress;
532f9f848faSopenharmony_ci#define	UE_GET_DIR(a)	((a) & 0x80)
533f9f848faSopenharmony_ci#define	UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
534f9f848faSopenharmony_ci#define	UE_DIR_IN	0x80		/* IN-token endpoint, fixed */
535f9f848faSopenharmony_ci#define	UE_DIR_OUT	0x00		/* OUT-token endpoint, fixed */
536f9f848faSopenharmony_ci#define	UE_DIR_RX	0xfd		/* for internal use only! */
537f9f848faSopenharmony_ci#define	UE_DIR_TX	0xfe		/* for internal use only! */
538f9f848faSopenharmony_ci#define	UE_DIR_ANY	0xff		/* for internal use only! */
539f9f848faSopenharmony_ci#define	UE_ADDR		0x0f
540f9f848faSopenharmony_ci#define	UE_ADDR_ANY	0xff		/* for internal use only! */
541f9f848faSopenharmony_ci#define	UE_GET_ADDR(a)	((a) & UE_ADDR)
542f9f848faSopenharmony_ci	uByte	bmAttributes;
543f9f848faSopenharmony_ci#define	UE_XFERTYPE	0x03
544f9f848faSopenharmony_ci#define	UE_CONTROL	0x00
545f9f848faSopenharmony_ci#define	UE_ISOCHRONOUS	0x01
546f9f848faSopenharmony_ci#define	UE_BULK	0x02
547f9f848faSopenharmony_ci#define	UE_INTERRUPT	0x03
548f9f848faSopenharmony_ci#define	UE_BULK_INTR	0xfe		/* for internal use only! */
549f9f848faSopenharmony_ci#define	UE_TYPE_ANY	0xff		/* for internal use only! */
550f9f848faSopenharmony_ci#define	UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
551f9f848faSopenharmony_ci#define	UE_ISO_TYPE	0x0c
552f9f848faSopenharmony_ci#define	UE_ISO_ASYNC	0x04
553f9f848faSopenharmony_ci#define	UE_ISO_ADAPT	0x08
554f9f848faSopenharmony_ci#define	UE_ISO_SYNC	0x0c
555f9f848faSopenharmony_ci#define	UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
556f9f848faSopenharmony_ci#define	UE_ISO_USAGE	0x30
557f9f848faSopenharmony_ci#define	UE_ISO_USAGE_DATA	0x00
558f9f848faSopenharmony_ci#define	UE_ISO_USAGE_FEEDBACK	0x10
559f9f848faSopenharmony_ci#define	UE_ISO_USAGE_IMPLICT_FB	0x20
560f9f848faSopenharmony_ci#define	UE_GET_ISO_USAGE(a)	((a) & UE_ISO_USAGE)
561f9f848faSopenharmony_ci	uWord	wMaxPacketSize;
562f9f848faSopenharmony_ci#define	UE_ZERO_MPS 0xFFFF		/* for internal use only */
563f9f848faSopenharmony_ci#define	UE_GET_TRANS(a)	(((a) >> 11) & 0x3)
564f9f848faSopenharmony_ci#define	UE_GET_SIZE(a)	((a) & 0x7ff)
565f9f848faSopenharmony_ci	uByte	bInterval;
566f9f848faSopenharmony_ci} __packed;
567f9f848faSopenharmony_citypedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
568f9f848faSopenharmony_ci
569f9f848faSopenharmony_cistruct usb_endpoint_ss_comp_descriptor {
570f9f848faSopenharmony_ci	uByte	bLength;
571f9f848faSopenharmony_ci	uByte	bDescriptorType;
572f9f848faSopenharmony_ci	uByte	bMaxBurst;
573f9f848faSopenharmony_ci	uByte	bmAttributes;
574f9f848faSopenharmony_ci#define	UE_GET_BULK_STREAMS(x) ((x) & 0x0F)
575f9f848faSopenharmony_ci#define	UE_GET_SS_ISO_MULT(x) ((x) & 0x03)
576f9f848faSopenharmony_ci	uWord	wBytesPerInterval;
577f9f848faSopenharmony_ci} __packed;
578f9f848faSopenharmony_citypedef struct usb_endpoint_ss_comp_descriptor
579f9f848faSopenharmony_ci		usb_endpoint_ss_comp_descriptor_t;
580f9f848faSopenharmony_ci
581f9f848faSopenharmony_cistruct usb_string_descriptor {
582f9f848faSopenharmony_ci	uByte	bLength;
583f9f848faSopenharmony_ci	uByte	bDescriptorType;
584f9f848faSopenharmony_ci	uWord	bString[126];
585f9f848faSopenharmony_ci	uByte	bUnused;
586f9f848faSopenharmony_ci} __packed;
587f9f848faSopenharmony_citypedef struct usb_string_descriptor usb_string_descriptor_t;
588f9f848faSopenharmony_ci
589f9f848faSopenharmony_ci#define	USB_MAKE_STRING_DESC(m,name)	\
590f9f848faSopenharmony_cistatic const struct {			\
591f9f848faSopenharmony_ci  uByte bLength;			\
592f9f848faSopenharmony_ci  uByte bDescriptorType;		\
593f9f848faSopenharmony_ci  uByte bData[sizeof((uint8_t []){m})];	\
594f9f848faSopenharmony_ci} __packed name = {			\
595f9f848faSopenharmony_ci  .bLength = sizeof(name),		\
596f9f848faSopenharmony_ci  .bDescriptorType = UDESC_STRING,	\
597f9f848faSopenharmony_ci  .bData = { m },			\
598f9f848faSopenharmony_ci}
599f9f848faSopenharmony_ci
600f9f848faSopenharmony_cistruct usb_string_lang {
601f9f848faSopenharmony_ci	uByte bLength;
602f9f848faSopenharmony_ci	uByte bDescriptorType;
603f9f848faSopenharmony_ci	uByte bData[2];
604f9f848faSopenharmony_ci} __packed;
605f9f848faSopenharmony_citypedef struct usb_string_lang usb_string_lang_t;
606f9f848faSopenharmony_ci
607f9f848faSopenharmony_cistruct usb_hub_descriptor {
608f9f848faSopenharmony_ci	uByte	bDescLength;
609f9f848faSopenharmony_ci	uByte	bDescriptorType;
610f9f848faSopenharmony_ci	uByte	bNbrPorts;
611f9f848faSopenharmony_ci	uWord	wHubCharacteristics;
612f9f848faSopenharmony_ci#define	UHD_PWR			0x0003
613f9f848faSopenharmony_ci#define	UHD_PWR_GANGED		0x0000
614f9f848faSopenharmony_ci#define	UHD_PWR_INDIVIDUAL	0x0001
615f9f848faSopenharmony_ci#define	UHD_PWR_NO_SWITCH	0x0002
616f9f848faSopenharmony_ci#define	UHD_COMPOUND		0x0004
617f9f848faSopenharmony_ci#define	UHD_OC			0x0018
618f9f848faSopenharmony_ci#define	UHD_OC_GLOBAL		0x0000
619f9f848faSopenharmony_ci#define	UHD_OC_INDIVIDUAL	0x0008
620f9f848faSopenharmony_ci#define	UHD_OC_NONE		0x0010
621f9f848faSopenharmony_ci#define	UHD_TT_THINK		0x0060
622f9f848faSopenharmony_ci#define	UHD_TT_THINK_8		0x0000
623f9f848faSopenharmony_ci#define	UHD_TT_THINK_16		0x0020
624f9f848faSopenharmony_ci#define	UHD_TT_THINK_24		0x0040
625f9f848faSopenharmony_ci#define	UHD_TT_THINK_32		0x0060
626f9f848faSopenharmony_ci#define	UHD_PORT_IND		0x0080
627f9f848faSopenharmony_ci	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
628f9f848faSopenharmony_ci#define	UHD_PWRON_FACTOR 2
629f9f848faSopenharmony_ci	uByte	bHubContrCurrent;
630f9f848faSopenharmony_ci	uByte	DeviceRemovable[32];	/* max 255 ports */
631f9f848faSopenharmony_ci#define	UHD_NOT_REMOV(desc, i) \
632f9f848faSopenharmony_ci    (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
633f9f848faSopenharmony_ci	uByte	PortPowerCtrlMask[1];	/* deprecated */
634f9f848faSopenharmony_ci} __packed;
635f9f848faSopenharmony_citypedef struct usb_hub_descriptor usb_hub_descriptor_t;
636f9f848faSopenharmony_ci
637f9f848faSopenharmony_cistruct usb_hub_ss_descriptor {
638f9f848faSopenharmony_ci	uByte	bLength;
639f9f848faSopenharmony_ci	uByte	bDescriptorType;
640f9f848faSopenharmony_ci	uByte	bNbrPorts;
641f9f848faSopenharmony_ci	uWord	wHubCharacteristics;
642f9f848faSopenharmony_ci	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
643f9f848faSopenharmony_ci	uByte	bHubContrCurrent;
644f9f848faSopenharmony_ci	uByte	bHubHdrDecLat;
645f9f848faSopenharmony_ci	uWord	wHubDelay;
646f9f848faSopenharmony_ci	uByte	DeviceRemovable[32];	/* max 255 ports */
647f9f848faSopenharmony_ci} __packed;
648f9f848faSopenharmony_citypedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
649f9f848faSopenharmony_ci
650f9f848faSopenharmony_ci/* minimum HUB descriptor (8-ports maximum) */
651f9f848faSopenharmony_cistruct usb_hub_descriptor_min {
652f9f848faSopenharmony_ci	uByte	bDescLength;
653f9f848faSopenharmony_ci	uByte	bDescriptorType;
654f9f848faSopenharmony_ci	uByte	bNbrPorts;
655f9f848faSopenharmony_ci	uWord	wHubCharacteristics;
656f9f848faSopenharmony_ci	uByte	bPwrOn2PwrGood;
657f9f848faSopenharmony_ci	uByte	bHubContrCurrent;
658f9f848faSopenharmony_ci	uByte	DeviceRemovable[1];
659f9f848faSopenharmony_ci	uByte	PortPowerCtrlMask[1];
660f9f848faSopenharmony_ci} __packed;
661f9f848faSopenharmony_citypedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
662f9f848faSopenharmony_ci
663f9f848faSopenharmony_cistruct usb_device_qualifier {
664f9f848faSopenharmony_ci	uByte	bLength;
665f9f848faSopenharmony_ci	uByte	bDescriptorType;
666f9f848faSopenharmony_ci	uWord	bcdUSB;
667f9f848faSopenharmony_ci	uByte	bDeviceClass;
668f9f848faSopenharmony_ci	uByte	bDeviceSubClass;
669f9f848faSopenharmony_ci	uByte	bDeviceProtocol;
670f9f848faSopenharmony_ci	uByte	bMaxPacketSize0;
671f9f848faSopenharmony_ci	uByte	bNumConfigurations;
672f9f848faSopenharmony_ci	uByte	bReserved;
673f9f848faSopenharmony_ci} __packed;
674f9f848faSopenharmony_citypedef struct usb_device_qualifier usb_device_qualifier_t;
675f9f848faSopenharmony_ci
676f9f848faSopenharmony_cistruct usb_otg_descriptor {
677f9f848faSopenharmony_ci	uByte	bLength;
678f9f848faSopenharmony_ci	uByte	bDescriptorType;
679f9f848faSopenharmony_ci	uByte	bmAttributes;
680f9f848faSopenharmony_ci#define	UOTG_SRP	0x01
681f9f848faSopenharmony_ci#define	UOTG_HNP	0x02
682f9f848faSopenharmony_ci} __packed;
683f9f848faSopenharmony_citypedef struct usb_otg_descriptor usb_otg_descriptor_t;
684f9f848faSopenharmony_ci
685f9f848faSopenharmony_ci/* OTG feature selectors */
686f9f848faSopenharmony_ci#define	UOTG_B_HNP_ENABLE	3
687f9f848faSopenharmony_ci#define	UOTG_A_HNP_SUPPORT	4
688f9f848faSopenharmony_ci#define	UOTG_A_ALT_HNP_SUPPORT	5
689f9f848faSopenharmony_ci
690f9f848faSopenharmony_cistruct usb_status {
691f9f848faSopenharmony_ci	uWord	wStatus;
692f9f848faSopenharmony_ci/* Device status flags */
693f9f848faSopenharmony_ci#define	UDS_SELF_POWERED		0x0001
694f9f848faSopenharmony_ci#define	UDS_REMOTE_WAKEUP		0x0002
695f9f848faSopenharmony_ci/* Endpoint status flags */
696f9f848faSopenharmony_ci#define	UES_HALT			0x0001
697f9f848faSopenharmony_ci} __packed;
698f9f848faSopenharmony_citypedef struct usb_status usb_status_t;
699f9f848faSopenharmony_ci
700f9f848faSopenharmony_cistruct usb_hub_status {
701f9f848faSopenharmony_ci	uWord	wHubStatus;
702f9f848faSopenharmony_ci#define	UHS_LOCAL_POWER			0x0001
703f9f848faSopenharmony_ci#define	UHS_OVER_CURRENT		0x0002
704f9f848faSopenharmony_ci	uWord	wHubChange;
705f9f848faSopenharmony_ci} __packed;
706f9f848faSopenharmony_citypedef struct usb_hub_status usb_hub_status_t;
707f9f848faSopenharmony_ci
708f9f848faSopenharmony_cistruct usb_port_status {
709f9f848faSopenharmony_ci	uWord	wPortStatus;
710f9f848faSopenharmony_ci#define	UPS_CURRENT_CONNECT_STATUS	0x0001
711f9f848faSopenharmony_ci#define	UPS_PORT_ENABLED		0x0002
712f9f848faSopenharmony_ci#define	UPS_SUSPEND			0x0004
713f9f848faSopenharmony_ci#define	UPS_OVERCURRENT_INDICATOR	0x0008
714f9f848faSopenharmony_ci#define	UPS_RESET			0x0010
715f9f848faSopenharmony_ci#define	UPS_PORT_L1			0x0020	/* USB 2.0 only */
716f9f848faSopenharmony_ci/* The link-state bits are valid for Super-Speed USB HUBs */
717f9f848faSopenharmony_ci#define	UPS_PORT_LINK_STATE_GET(x)	(((x) >> 5) & 0xF)
718f9f848faSopenharmony_ci#define	UPS_PORT_LINK_STATE_SET(x)	(((x) & 0xF) << 5)
719f9f848faSopenharmony_ci#define	UPS_PORT_LS_U0		0x00
720f9f848faSopenharmony_ci#define	UPS_PORT_LS_U1		0x01
721f9f848faSopenharmony_ci#define	UPS_PORT_LS_U2		0x02
722f9f848faSopenharmony_ci#define	UPS_PORT_LS_U3		0x03
723f9f848faSopenharmony_ci#define	UPS_PORT_LS_SS_DIS	0x04
724f9f848faSopenharmony_ci#define	UPS_PORT_LS_RX_DET	0x05
725f9f848faSopenharmony_ci#define	UPS_PORT_LS_SS_INA	0x06
726f9f848faSopenharmony_ci#define	UPS_PORT_LS_POLL	0x07
727f9f848faSopenharmony_ci#define	UPS_PORT_LS_RECOVER	0x08
728f9f848faSopenharmony_ci#define	UPS_PORT_LS_HOT_RST	0x09
729f9f848faSopenharmony_ci#define	UPS_PORT_LS_COMP_MODE	0x0A
730f9f848faSopenharmony_ci#define	UPS_PORT_LS_LOOPBACK	0x0B
731f9f848faSopenharmony_ci#define	UPS_PORT_LS_RESUME	0x0F
732f9f848faSopenharmony_ci#define	UPS_PORT_POWER			0x0100
733f9f848faSopenharmony_ci#define	UPS_PORT_POWER_SS		0x0200	/* super-speed only */
734f9f848faSopenharmony_ci#define	UPS_LOW_SPEED			0x0200
735f9f848faSopenharmony_ci#define	UPS_HIGH_SPEED			0x0400
736f9f848faSopenharmony_ci#define	UPS_OTHER_SPEED			0x0600	/* currently FreeBSD specific */
737f9f848faSopenharmony_ci#define	UPS_PORT_TEST			0x0800
738f9f848faSopenharmony_ci#define	UPS_PORT_INDICATOR		0x1000
739f9f848faSopenharmony_ci#define	UPS_PORT_MODE_DEVICE		0x8000	/* currently FreeBSD specific */
740f9f848faSopenharmony_ci	uWord	wPortChange;
741f9f848faSopenharmony_ci#define	UPS_C_CONNECT_STATUS		0x0001
742f9f848faSopenharmony_ci#define	UPS_C_PORT_ENABLED		0x0002
743f9f848faSopenharmony_ci#define	UPS_C_SUSPEND			0x0004
744f9f848faSopenharmony_ci#define	UPS_C_OVERCURRENT_INDICATOR	0x0008
745f9f848faSopenharmony_ci#define	UPS_C_PORT_RESET		0x0010
746f9f848faSopenharmony_ci#define	UPS_C_PORT_L1			0x0020	/* USB 2.0 only */
747f9f848faSopenharmony_ci#define	UPS_C_BH_PORT_RESET		0x0020	/* USB 3.0 only */
748f9f848faSopenharmony_ci#define	UPS_C_PORT_LINK_STATE		0x0040
749f9f848faSopenharmony_ci#define	UPS_C_PORT_CONFIG_ERROR		0x0080
750f9f848faSopenharmony_ci} __packed;
751f9f848faSopenharmony_citypedef struct usb_port_status usb_port_status_t;
752f9f848faSopenharmony_ci
753f9f848faSopenharmony_ci/*
754f9f848faSopenharmony_ci * The "USB_SPEED" macros defines all the supported USB speeds.
755f9f848faSopenharmony_ci */
756f9f848faSopenharmony_cienum usb_dev_speed {
757f9f848faSopenharmony_ci	USB_SPEED_VARIABLE,
758f9f848faSopenharmony_ci	USB_SPEED_LOW,
759f9f848faSopenharmony_ci	USB_SPEED_FULL,
760f9f848faSopenharmony_ci	USB_SPEED_HIGH,
761f9f848faSopenharmony_ci	USB_SPEED_SUPER,
762f9f848faSopenharmony_ci};
763f9f848faSopenharmony_ci#define	USB_SPEED_MAX	(USB_SPEED_SUPER+1)
764f9f848faSopenharmony_ci
765f9f848faSopenharmony_ci/*
766f9f848faSopenharmony_ci * The "USB_REV" macros defines all the supported USB revisions.
767f9f848faSopenharmony_ci */
768f9f848faSopenharmony_cienum usb_revision {
769f9f848faSopenharmony_ci	USB_REV_UNKNOWN,
770f9f848faSopenharmony_ci	USB_REV_PRE_1_0,
771f9f848faSopenharmony_ci	USB_REV_1_0,
772f9f848faSopenharmony_ci	USB_REV_1_1,
773f9f848faSopenharmony_ci	USB_REV_2_0,
774f9f848faSopenharmony_ci	USB_REV_2_5,
775f9f848faSopenharmony_ci	USB_REV_3_0
776f9f848faSopenharmony_ci};
777f9f848faSopenharmony_ci#define	USB_REV_MAX	(USB_REV_3_0+1)
778f9f848faSopenharmony_ci
779f9f848faSopenharmony_ci/*
780f9f848faSopenharmony_ci * Supported host controller modes.
781f9f848faSopenharmony_ci */
782f9f848faSopenharmony_cienum usb_hc_mode {
783f9f848faSopenharmony_ci	USB_MODE_HOST,		/* initiates transfers */
784f9f848faSopenharmony_ci	USB_MODE_DEVICE,	/* bus transfer target */
785f9f848faSopenharmony_ci	USB_MODE_DUAL		/* can be host or device */
786f9f848faSopenharmony_ci};
787f9f848faSopenharmony_ci#define	USB_MODE_MAX	(USB_MODE_DUAL+1)
788f9f848faSopenharmony_ci
789f9f848faSopenharmony_ci/*
790f9f848faSopenharmony_ci * The "USB_STATE" enums define all the supported device states.
791f9f848faSopenharmony_ci */
792f9f848faSopenharmony_cienum usb_dev_state {
793f9f848faSopenharmony_ci	USB_STATE_DETACHED,
794f9f848faSopenharmony_ci	USB_STATE_ATTACHED,
795f9f848faSopenharmony_ci	USB_STATE_POWERED,
796f9f848faSopenharmony_ci	USB_STATE_ADDRESSED,
797f9f848faSopenharmony_ci	USB_STATE_CONFIGURED,
798f9f848faSopenharmony_ci};
799f9f848faSopenharmony_ci#define	USB_STATE_MAX	(USB_STATE_CONFIGURED+1)
800f9f848faSopenharmony_ci
801f9f848faSopenharmony_ci/*
802f9f848faSopenharmony_ci * The "USB_EP_MODE" macros define all the currently supported
803f9f848faSopenharmony_ci * endpoint modes.
804f9f848faSopenharmony_ci */
805f9f848faSopenharmony_cienum usb_ep_mode {
806f9f848faSopenharmony_ci	USB_EP_MODE_DEFAULT,
807f9f848faSopenharmony_ci	USB_EP_MODE_STREAMS,	/* USB3.0 specific */
808f9f848faSopenharmony_ci	USB_EP_MODE_HW_MASS_STORAGE,
809f9f848faSopenharmony_ci	USB_EP_MODE_HW_SERIAL,
810f9f848faSopenharmony_ci	USB_EP_MODE_HW_ETHERNET_CDC,
811f9f848faSopenharmony_ci	USB_EP_MODE_HW_ETHERNET_NCM,
812f9f848faSopenharmony_ci	USB_EP_MODE_MAX
813f9f848faSopenharmony_ci};
814f9f848faSopenharmony_ci#endif					/* _USB_STANDARD_H_ */
815