xref: /openbmc/u-boot/include/usb.h (revision 51ab142b8b546d5e627b2c8c36d0adae222565f7)
1012771d8Swdenk /*
2012771d8Swdenk  * (C) Copyright 2001
3012771d8Swdenk  * Denis Peter, MPL AG Switzerland
4012771d8Swdenk  *
5012771d8Swdenk  * See file CREDITS for list of people who contributed to this
6012771d8Swdenk  * project.
7012771d8Swdenk  *
8012771d8Swdenk  * This program is free software; you can redistribute it and/or
9012771d8Swdenk  * modify it under the terms of the GNU General Public License as
10012771d8Swdenk  * published by the Free Software Foundation; either version 2 of
11012771d8Swdenk  * the License, or (at your option) any later version.
12012771d8Swdenk  *
13012771d8Swdenk  * This program is distributed in the hope that it will be useful,
14012771d8Swdenk  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15012771d8Swdenk  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
16012771d8Swdenk  * GNU General Public License for more details.
17012771d8Swdenk  *
18012771d8Swdenk  * You should have received a copy of the GNU General Public License
19012771d8Swdenk  * along with this program; if not, write to the Free Software
20012771d8Swdenk  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21012771d8Swdenk  * MA 02111-1307 USA
22012771d8Swdenk  *
23012771d8Swdenk  * Note: Part of this code has been derived from linux
24012771d8Swdenk  *
25012771d8Swdenk  */
26012771d8Swdenk #ifndef _USB_H_
27012771d8Swdenk #define _USB_H_
28012771d8Swdenk 
29012771d8Swdenk #include <usb_defs.h>
30012771d8Swdenk 
31012771d8Swdenk /* Everything is aribtrary */
32012771d8Swdenk #define USB_ALTSETTINGALLOC		4
33012771d8Swdenk #define USB_MAXALTSETTING		128	/* Hard limit */
34012771d8Swdenk 
35012771d8Swdenk #define USB_MAX_DEVICE			32
36012771d8Swdenk #define USB_MAXCONFIG			8
37012771d8Swdenk #define USB_MAXINTERFACES		8
38012771d8Swdenk #define USB_MAXENDPOINTS		16
39012771d8Swdenk #define USB_MAXCHILDREN			8	/* This is arbitrary */
40012771d8Swdenk #define USB_MAX_HUB			16
41012771d8Swdenk 
42012771d8Swdenk #define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
43012771d8Swdenk 
44012771d8Swdenk /* String descriptor */
45012771d8Swdenk struct usb_string_descriptor {
46012771d8Swdenk 	unsigned char	bLength;
47012771d8Swdenk 	unsigned char	bDescriptorType;
48012771d8Swdenk 	unsigned short	wData[1];
49012771d8Swdenk } __attribute__ ((packed));
50012771d8Swdenk 
51012771d8Swdenk /* device request (setup) */
52012771d8Swdenk struct devrequest {
53012771d8Swdenk 	unsigned char	requesttype;
54012771d8Swdenk 	unsigned char	request;
55012771d8Swdenk 	unsigned short	value;
56012771d8Swdenk 	unsigned short	index;
57012771d8Swdenk 	unsigned short	length;
58012771d8Swdenk } __attribute__ ((packed));
59012771d8Swdenk 
60012771d8Swdenk /* All standard descriptors have these 2 fields in common */
61012771d8Swdenk struct usb_descriptor_header {
62012771d8Swdenk 	unsigned char	bLength;
63012771d8Swdenk 	unsigned char	bDescriptorType;
64012771d8Swdenk } __attribute__ ((packed));
65012771d8Swdenk 
66012771d8Swdenk /* Device descriptor */
67012771d8Swdenk struct usb_device_descriptor {
68012771d8Swdenk 	unsigned char	bLength;
69012771d8Swdenk 	unsigned char	bDescriptorType;
70012771d8Swdenk 	unsigned short	bcdUSB;
71012771d8Swdenk 	unsigned char	bDeviceClass;
72012771d8Swdenk 	unsigned char	bDeviceSubClass;
73012771d8Swdenk 	unsigned char	bDeviceProtocol;
74012771d8Swdenk 	unsigned char	bMaxPacketSize0;
75012771d8Swdenk 	unsigned short	idVendor;
76012771d8Swdenk 	unsigned short	idProduct;
77012771d8Swdenk 	unsigned short	bcdDevice;
78012771d8Swdenk 	unsigned char	iManufacturer;
79012771d8Swdenk 	unsigned char	iProduct;
80012771d8Swdenk 	unsigned char	iSerialNumber;
81012771d8Swdenk 	unsigned char	bNumConfigurations;
82012771d8Swdenk } __attribute__ ((packed));
83012771d8Swdenk 
84012771d8Swdenk /* Endpoint descriptor */
85012771d8Swdenk struct usb_endpoint_descriptor {
86012771d8Swdenk 	unsigned char	bLength;
87012771d8Swdenk 	unsigned char	bDescriptorType;
88012771d8Swdenk 	unsigned char	bEndpointAddress;
89012771d8Swdenk 	unsigned char	bmAttributes;
90012771d8Swdenk 	unsigned short	wMaxPacketSize;
91012771d8Swdenk 	unsigned char	bInterval;
92012771d8Swdenk 	unsigned char	bRefresh;
93012771d8Swdenk 	unsigned char	bSynchAddress;
94d2776827SStefan Althoefer } __attribute__ ((packed)) __attribute__ ((aligned(2)));
95de39f8c1SMichael Trimarchi 
96012771d8Swdenk /* Interface descriptor */
97012771d8Swdenk struct usb_interface_descriptor {
98012771d8Swdenk 	unsigned char	bLength;
99012771d8Swdenk 	unsigned char	bDescriptorType;
100012771d8Swdenk 	unsigned char	bInterfaceNumber;
101012771d8Swdenk 	unsigned char	bAlternateSetting;
102012771d8Swdenk 	unsigned char	bNumEndpoints;
103012771d8Swdenk 	unsigned char	bInterfaceClass;
104012771d8Swdenk 	unsigned char	bInterfaceSubClass;
105012771d8Swdenk 	unsigned char	bInterfaceProtocol;
106012771d8Swdenk 	unsigned char	iInterface;
107012771d8Swdenk 
108012771d8Swdenk 	unsigned char	no_of_ep;
1097455af41SBartlomiej Sieka 	unsigned char	num_altsetting;
110012771d8Swdenk 	unsigned char	act_altsetting;
111de39f8c1SMichael Trimarchi 
112012771d8Swdenk 	struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
113012771d8Swdenk } __attribute__ ((packed));
114012771d8Swdenk 
115012771d8Swdenk 
116012771d8Swdenk /* Configuration descriptor information.. */
117012771d8Swdenk struct usb_config_descriptor {
118012771d8Swdenk 	unsigned char	bLength;
119012771d8Swdenk 	unsigned char	bDescriptorType;
120012771d8Swdenk 	unsigned short	wTotalLength;
121012771d8Swdenk 	unsigned char	bNumInterfaces;
122012771d8Swdenk 	unsigned char	bConfigurationValue;
123012771d8Swdenk 	unsigned char	iConfiguration;
124012771d8Swdenk 	unsigned char	bmAttributes;
125012771d8Swdenk 	unsigned char	MaxPower;
126012771d8Swdenk 
127012771d8Swdenk 	unsigned char	no_of_if;	/* number of interfaces */
128012771d8Swdenk 	struct usb_interface_descriptor if_desc[USB_MAXINTERFACES];
129012771d8Swdenk } __attribute__ ((packed));
130012771d8Swdenk 
13148867208SRemy Bohmer enum {
13248867208SRemy Bohmer 	/* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
13348867208SRemy Bohmer 	PACKET_SIZE_8   = 0,
13448867208SRemy Bohmer 	PACKET_SIZE_16  = 1,
13548867208SRemy Bohmer 	PACKET_SIZE_32  = 2,
13648867208SRemy Bohmer 	PACKET_SIZE_64  = 3,
13748867208SRemy Bohmer };
138012771d8Swdenk 
139012771d8Swdenk struct usb_device {
140012771d8Swdenk 	int	devnum;			/* Device number on USB bus */
1413e126484SMichael Trimarchi 	int	speed;			/* full/low/high */
142012771d8Swdenk 	char	mf[32];			/* manufacturer */
143012771d8Swdenk 	char	prod[32];		/* product */
144012771d8Swdenk 	char	serial[32];		/* serial number */
145012771d8Swdenk 
14648867208SRemy Bohmer 	/* Maximum packet size; one of: PACKET_SIZE_* */
14748867208SRemy Bohmer 	int maxpacketsize;
14848867208SRemy Bohmer 	/* one bit for each endpoint ([0] = IN, [1] = OUT) */
14948867208SRemy Bohmer 	unsigned int toggle[2];
150de39f8c1SMichael Trimarchi 	/* endpoint halts; one bit per endpoint # & direction;
151de39f8c1SMichael Trimarchi 	 * [0] = IN, [1] = OUT
152de39f8c1SMichael Trimarchi 	 */
15348867208SRemy Bohmer 	unsigned int halted[2];
154012771d8Swdenk 	int epmaxpacketin[16];		/* INput endpoint specific maximums */
155012771d8Swdenk 	int epmaxpacketout[16];		/* OUTput endpoint specific maximums */
156012771d8Swdenk 
157012771d8Swdenk 	int configno;			/* selected config number */
158012771d8Swdenk 	struct usb_device_descriptor descriptor; /* Device Descriptor */
159012771d8Swdenk 	struct usb_config_descriptor config; /* config descriptor */
160012771d8Swdenk 
161012771d8Swdenk 	int have_langid;		/* whether string_langid is valid yet */
162012771d8Swdenk 	int string_langid;		/* language ID for strings */
163012771d8Swdenk 	int (*irq_handle)(struct usb_device *dev);
164012771d8Swdenk 	unsigned long irq_status;
165012771d8Swdenk 	int irq_act_len;		/* transfered bytes */
166012771d8Swdenk 	void *privptr;
167012771d8Swdenk 	/*
168012771d8Swdenk 	 * Child devices -  if this is a hub device
169012771d8Swdenk 	 * Each instance needs its own set of data structures.
170012771d8Swdenk 	 */
171012771d8Swdenk 	unsigned long status;
172012771d8Swdenk 	int act_len;			/* transfered bytes */
173012771d8Swdenk 	int maxchild;			/* Number of ports if hub */
1743e126484SMichael Trimarchi 	int portnr;
175012771d8Swdenk 	struct usb_device *parent;
176012771d8Swdenk 	struct usb_device *children[USB_MAXCHILDREN];
177012771d8Swdenk };
178012771d8Swdenk 
179012771d8Swdenk /**********************************************************************
180012771d8Swdenk  * this is how the lowlevel part communicate with the outer world
181012771d8Swdenk  */
182012771d8Swdenk 
183822af351SRodolfo Giometti #if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || \
184*51ab142bSmichael 	defined(CONFIG_USB_EHCI) || defined(CONFIG_USB_OHCI_NEW) || \
1853e126484SMichael Trimarchi 	defined(CONFIG_USB_SL811HS) || defined(CONFIG_USB_ISP116X_HCD) || \
1863e126484SMichael Trimarchi 	defined(CONFIG_USB_R8A66597_HCD)
187822af351SRodolfo Giometti 
188012771d8Swdenk int usb_lowlevel_init(void);
189012771d8Swdenk int usb_lowlevel_stop(void);
190de39f8c1SMichael Trimarchi int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
191de39f8c1SMichael Trimarchi 			void *buffer, int transfer_len);
192012771d8Swdenk int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
193012771d8Swdenk 			int transfer_len, struct devrequest *setup);
194012771d8Swdenk int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
195012771d8Swdenk 			int transfer_len, int interval);
196fdcfaa1bSZhang Wei void usb_event_poll(void);
197012771d8Swdenk 
198012771d8Swdenk /* Defines */
199012771d8Swdenk #define USB_UHCI_VEND_ID	0x8086
200012771d8Swdenk #define USB_UHCI_DEV_ID		0x7112
201012771d8Swdenk 
202012771d8Swdenk #else
203012771d8Swdenk #error USB Lowlevel not defined
204012771d8Swdenk #endif
205012771d8Swdenk 
206012771d8Swdenk #ifdef CONFIG_USB_STORAGE
207012771d8Swdenk 
208012771d8Swdenk #define USB_MAX_STOR_DEV 5
209012771d8Swdenk block_dev_desc_t *usb_stor_get_dev(int index);
210012771d8Swdenk int usb_stor_scan(int mode);
211e813eae3SAnatolij Gustschin int usb_stor_info(void);
212012771d8Swdenk 
213012771d8Swdenk #endif
214012771d8Swdenk 
215012771d8Swdenk #ifdef CONFIG_USB_KEYBOARD
216012771d8Swdenk 
217012771d8Swdenk int drv_usb_kbd_init(void);
218012771d8Swdenk int usb_kbd_deregister(void);
219012771d8Swdenk 
220012771d8Swdenk #endif
221012771d8Swdenk /* routines */
222012771d8Swdenk int usb_init(void); /* initialize the USB Controller */
223012771d8Swdenk int usb_stop(void); /* stop the USB Controller */
224012771d8Swdenk 
225012771d8Swdenk 
226012771d8Swdenk int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
227de39f8c1SMichael Trimarchi int usb_set_idle(struct usb_device *dev, int ifnum, int duration,
228de39f8c1SMichael Trimarchi 			int report_id);
229012771d8Swdenk struct usb_device *usb_get_dev_index(int index);
230012771d8Swdenk int usb_control_msg(struct usb_device *dev, unsigned int pipe,
231012771d8Swdenk 			unsigned char request, unsigned char requesttype,
232012771d8Swdenk 			unsigned short value, unsigned short index,
233012771d8Swdenk 			void *data, unsigned short size, int timeout);
234012771d8Swdenk int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
235012771d8Swdenk 			void *data, int len, int *actual_length, int timeout);
236012771d8Swdenk int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
237012771d8Swdenk 			void *buffer, int transfer_len, int interval);
238012771d8Swdenk void usb_disable_asynch(int disable);
239012771d8Swdenk int usb_maxpacket(struct usb_device *dev, unsigned long pipe);
240de39f8c1SMichael Trimarchi inline void wait_ms(unsigned long ms);
241de39f8c1SMichael Trimarchi int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer,
242de39f8c1SMichael Trimarchi 				int cfgno);
243de39f8c1SMichael Trimarchi int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
244de39f8c1SMichael Trimarchi 			unsigned char id, void *buf, int size);
245012771d8Swdenk int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
246de39f8c1SMichael Trimarchi 			unsigned char type, unsigned char id, void *buf,
247de39f8c1SMichael Trimarchi 			int size);
248012771d8Swdenk int usb_clear_halt(struct usb_device *dev, int pipe);
249012771d8Swdenk int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
250012771d8Swdenk int usb_set_interface(struct usb_device *dev, int interface, int alternate);
251012771d8Swdenk 
252012771d8Swdenk /* big endian -> little endian conversion */
253149dded2Swdenk /* some CPUs are already little endian e.g. the ARM920T */
254ae3b770eSMarkus Klotzbuecher #define __swap_16(x) \
2553f85ce27Swdenk 	({ unsigned short x_ = (unsigned short)x; \
2563f85ce27Swdenk 	 (unsigned short)( \
2573f85ce27Swdenk 		((x_ & 0x00FFU) << 8) | ((x_ & 0xFF00U) >> 8)); \
2583f85ce27Swdenk 	})
259ae3b770eSMarkus Klotzbuecher #define __swap_32(x) \
2603f85ce27Swdenk 	({ unsigned long x_ = (unsigned long)x; \
2613f85ce27Swdenk 	 (unsigned long)( \
2623f85ce27Swdenk 		((x_ & 0x000000FFUL) << 24) | \
2633f85ce27Swdenk 		((x_ & 0x0000FF00UL) <<	 8) | \
2643f85ce27Swdenk 		((x_ & 0x00FF0000UL) >>	 8) | \
2653f85ce27Swdenk 		((x_ & 0xFF000000UL) >> 24)); \
2663f85ce27Swdenk 	})
267ae3b770eSMarkus Klotzbuecher 
268ae3b770eSMarkus Klotzbuecher #ifdef LITTLEENDIAN
269ae3b770eSMarkus Klotzbuecher # define swap_16(x) (x)
270ae3b770eSMarkus Klotzbuecher # define swap_32(x) (x)
271ae3b770eSMarkus Klotzbuecher #else
272ae3b770eSMarkus Klotzbuecher # define swap_16(x) __swap_16(x)
273ae3b770eSMarkus Klotzbuecher # define swap_32(x) __swap_32(x)
274149dded2Swdenk #endif /* LITTLEENDIAN */
275012771d8Swdenk 
276012771d8Swdenk /*
277012771d8Swdenk  * Calling this entity a "pipe" is glorifying it. A USB pipe
278012771d8Swdenk  * is something embarrassingly simple: it basically consists
279012771d8Swdenk  * of the following information:
280012771d8Swdenk  *  - device number (7 bits)
281012771d8Swdenk  *  - endpoint number (4 bits)
282012771d8Swdenk  *  - current Data0/1 state (1 bit)
283012771d8Swdenk  *  - direction (1 bit)
2843e126484SMichael Trimarchi  *  - speed (2 bits)
285012771d8Swdenk  *  - max packet size (2 bits: 8, 16, 32 or 64)
286012771d8Swdenk  *  - pipe type (2 bits: control, interrupt, bulk, isochronous)
287012771d8Swdenk  *
288012771d8Swdenk  * That's 18 bits. Really. Nothing more. And the USB people have
289012771d8Swdenk  * documented these eighteen bits as some kind of glorious
290012771d8Swdenk  * virtual data structure.
291012771d8Swdenk  *
292012771d8Swdenk  * Let's not fall in that trap. We'll just encode it as a simple
293012771d8Swdenk  * unsigned int. The encoding is:
294012771d8Swdenk  *
295012771d8Swdenk  *  - max size:		bits 0-1	(00 = 8, 01 = 16, 10 = 32, 11 = 64)
296de39f8c1SMichael Trimarchi  *  - direction:	bit 7		(0 = Host-to-Device [Out],
297de39f8c1SMichael Trimarchi  *					(1 = Device-to-Host [In])
298012771d8Swdenk  *  - device:		bits 8-14
299012771d8Swdenk  *  - endpoint:		bits 15-18
300012771d8Swdenk  *  - Data0/1:		bit 19
3013e126484SMichael Trimarchi  *  - speed:		bit 26		(0 = Full, 1 = Low Speed, 2 = High)
302de39f8c1SMichael Trimarchi  *  - pipe type:	bits 30-31	(00 = isochronous, 01 = interrupt,
303de39f8c1SMichael Trimarchi  *					 10 = control, 11 = bulk)
304012771d8Swdenk  *
305012771d8Swdenk  * Why? Because it's arbitrary, and whatever encoding we select is really
306012771d8Swdenk  * up to us. This one happens to share a lot of bit positions with the UHCI
307012771d8Swdenk  * specification, so that much of the uhci driver can just mask the bits
308012771d8Swdenk  * appropriately.
309012771d8Swdenk  */
310012771d8Swdenk /* Create various pipes... */
311012771d8Swdenk #define create_pipe(dev,endpoint) \
312de39f8c1SMichael Trimarchi 		(((dev)->devnum << 8) | (endpoint << 15) | \
3133e126484SMichael Trimarchi 		((dev)->speed << 26) | (dev)->maxpacketsize)
3143e126484SMichael Trimarchi #define default_pipe(dev) ((dev)->speed << 26)
315012771d8Swdenk 
316de39f8c1SMichael Trimarchi #define usb_sndctrlpipe(dev, endpoint)	((PIPE_CONTROL << 30) | \
317de39f8c1SMichael Trimarchi 					 create_pipe(dev, endpoint))
318de39f8c1SMichael Trimarchi #define usb_rcvctrlpipe(dev, endpoint)	((PIPE_CONTROL << 30) | \
319de39f8c1SMichael Trimarchi 					 create_pipe(dev, endpoint) | \
320de39f8c1SMichael Trimarchi 					 USB_DIR_IN)
321de39f8c1SMichael Trimarchi #define usb_sndisocpipe(dev, endpoint)	((PIPE_ISOCHRONOUS << 30) | \
322de39f8c1SMichael Trimarchi 					 create_pipe(dev, endpoint))
323de39f8c1SMichael Trimarchi #define usb_rcvisocpipe(dev, endpoint)	((PIPE_ISOCHRONOUS << 30) | \
324de39f8c1SMichael Trimarchi 					 create_pipe(dev, endpoint) | \
325de39f8c1SMichael Trimarchi 					 USB_DIR_IN)
326de39f8c1SMichael Trimarchi #define usb_sndbulkpipe(dev, endpoint)	((PIPE_BULK << 30) | \
327de39f8c1SMichael Trimarchi 					 create_pipe(dev, endpoint))
328de39f8c1SMichael Trimarchi #define usb_rcvbulkpipe(dev, endpoint)	((PIPE_BULK << 30) | \
329de39f8c1SMichael Trimarchi 					 create_pipe(dev, endpoint) | \
330de39f8c1SMichael Trimarchi 					 USB_DIR_IN)
331de39f8c1SMichael Trimarchi #define usb_sndintpipe(dev, endpoint)	((PIPE_INTERRUPT << 30) | \
332de39f8c1SMichael Trimarchi 					 create_pipe(dev, endpoint))
333de39f8c1SMichael Trimarchi #define usb_rcvintpipe(dev, endpoint)	((PIPE_INTERRUPT << 30) | \
334de39f8c1SMichael Trimarchi 					 create_pipe(dev, endpoint) | \
335de39f8c1SMichael Trimarchi 					 USB_DIR_IN)
336de39f8c1SMichael Trimarchi #define usb_snddefctrl(dev)		((PIPE_CONTROL << 30) | \
337de39f8c1SMichael Trimarchi 					 default_pipe(dev))
338de39f8c1SMichael Trimarchi #define usb_rcvdefctrl(dev)		((PIPE_CONTROL << 30) | \
339de39f8c1SMichael Trimarchi 					 default_pipe(dev) | \
340de39f8c1SMichael Trimarchi 					 USB_DIR_IN)
341012771d8Swdenk 
342012771d8Swdenk /* The D0/D1 toggle bits */
343012771d8Swdenk #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
344012771d8Swdenk #define usb_dotoggle(dev, ep, out)  ((dev)->toggle[out] ^= (1 << ep))
345de39f8c1SMichael Trimarchi #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
346de39f8c1SMichael Trimarchi 						((dev)->toggle[out] & \
347de39f8c1SMichael Trimarchi 						 ~(1 << ep)) | ((bit) << ep))
348012771d8Swdenk 
349012771d8Swdenk /* Endpoint halt control/status */
350012771d8Swdenk #define usb_endpoint_out(ep_dir)	(((ep_dir >> 7) & 1) ^ 1)
351012771d8Swdenk #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
352012771d8Swdenk #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
353012771d8Swdenk #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
354012771d8Swdenk 
355de39f8c1SMichael Trimarchi #define usb_packetid(pipe)	(((pipe) & USB_DIR_IN) ? USB_PID_IN : \
356de39f8c1SMichael Trimarchi 				 USB_PID_OUT)
357012771d8Swdenk 
358012771d8Swdenk #define usb_pipeout(pipe)	((((pipe) >> 7) & 1) ^ 1)
359012771d8Swdenk #define usb_pipein(pipe)	(((pipe) >> 7) & 1)
360012771d8Swdenk #define usb_pipedevice(pipe)	(((pipe) >> 8) & 0x7f)
361012771d8Swdenk #define usb_pipe_endpdev(pipe)	(((pipe) >> 8) & 0x7ff)
362012771d8Swdenk #define usb_pipeendpoint(pipe)	(((pipe) >> 15) & 0xf)
363012771d8Swdenk #define usb_pipedata(pipe)	(((pipe) >> 19) & 1)
3643e126484SMichael Trimarchi #define usb_pipespeed(pipe)	(((pipe) >> 26) & 3)
3653e126484SMichael Trimarchi #define usb_pipeslow(pipe)	(usb_pipespeed(pipe) == USB_SPEED_LOW)
366012771d8Swdenk #define usb_pipetype(pipe)	(((pipe) >> 30) & 3)
367012771d8Swdenk #define usb_pipeisoc(pipe)	(usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
368012771d8Swdenk #define usb_pipeint(pipe)	(usb_pipetype((pipe)) == PIPE_INTERRUPT)
369012771d8Swdenk #define usb_pipecontrol(pipe)	(usb_pipetype((pipe)) == PIPE_CONTROL)
370012771d8Swdenk #define usb_pipebulk(pipe)	(usb_pipetype((pipe)) == PIPE_BULK)
371012771d8Swdenk 
372012771d8Swdenk 
373012771d8Swdenk /*************************************************************************
374012771d8Swdenk  * Hub Stuff
375012771d8Swdenk  */
376012771d8Swdenk struct usb_port_status {
377012771d8Swdenk 	unsigned short wPortStatus;
378012771d8Swdenk 	unsigned short wPortChange;
379012771d8Swdenk } __attribute__ ((packed));
380012771d8Swdenk 
381012771d8Swdenk struct usb_hub_status {
382012771d8Swdenk 	unsigned short wHubStatus;
383012771d8Swdenk 	unsigned short wHubChange;
384012771d8Swdenk } __attribute__ ((packed));
385012771d8Swdenk 
386012771d8Swdenk 
387012771d8Swdenk /* Hub descriptor */
388012771d8Swdenk struct usb_hub_descriptor {
389012771d8Swdenk 	unsigned char  bLength;
390012771d8Swdenk 	unsigned char  bDescriptorType;
391012771d8Swdenk 	unsigned char  bNbrPorts;
392012771d8Swdenk 	unsigned short wHubCharacteristics;
393012771d8Swdenk 	unsigned char  bPwrOn2PwrGood;
394012771d8Swdenk 	unsigned char  bHubContrCurrent;
395012771d8Swdenk 	unsigned char  DeviceRemovable[(USB_MAXCHILDREN+1+7)/8];
396012771d8Swdenk 	unsigned char  PortPowerCtrlMask[(USB_MAXCHILDREN+1+7)/8];
397012771d8Swdenk 	/* DeviceRemovable and PortPwrCtrlMask want to be variable-length
398012771d8Swdenk 	   bitmaps that hold max 255 entries. (bit0 is ignored) */
399012771d8Swdenk } __attribute__ ((packed));
400012771d8Swdenk 
401012771d8Swdenk 
402012771d8Swdenk struct usb_hub_device {
403012771d8Swdenk 	struct usb_device *pusb_dev;
404012771d8Swdenk 	struct usb_hub_descriptor desc;
405012771d8Swdenk };
406012771d8Swdenk 
407012771d8Swdenk #endif /*_USB_H_ */
408