xref: /OK3568_Linux_fs/u-boot/include/usb.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2001
3*4882a593Smuzhiyun  * Denis Peter, MPL AG Switzerland
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Adapted for U-Boot driver model
6*4882a593Smuzhiyun  * (C) Copyright 2015 Google, Inc
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
9*4882a593Smuzhiyun  * Note: Part of this code has been derived from linux
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun #ifndef _USB_H_
13*4882a593Smuzhiyun #define _USB_H_
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <fdtdec.h>
16*4882a593Smuzhiyun #include <usb_defs.h>
17*4882a593Smuzhiyun #include <linux/usb/ch9.h>
18*4882a593Smuzhiyun #include <asm/cache.h>
19*4882a593Smuzhiyun #include <part.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /*
22*4882a593Smuzhiyun  * The EHCI spec says that we must align to at least 32 bytes.  However,
23*4882a593Smuzhiyun  * some platforms require larger alignment.
24*4882a593Smuzhiyun  */
25*4882a593Smuzhiyun #if ARCH_DMA_MINALIGN > 32
26*4882a593Smuzhiyun #define USB_DMA_MINALIGN	ARCH_DMA_MINALIGN
27*4882a593Smuzhiyun #else
28*4882a593Smuzhiyun #define USB_DMA_MINALIGN	32
29*4882a593Smuzhiyun #endif
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* Everything is aribtrary */
32*4882a593Smuzhiyun #define USB_ALTSETTINGALLOC		4
33*4882a593Smuzhiyun #define USB_MAXALTSETTING		128	/* Hard limit */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #define USB_MAX_DEVICE			32
36*4882a593Smuzhiyun #define USB_MAXCONFIG			8
37*4882a593Smuzhiyun #define USB_MAXINTERFACES		8
38*4882a593Smuzhiyun #define USB_MAXENDPOINTS		16
39*4882a593Smuzhiyun #define USB_MAXCHILDREN			8	/* This is arbitrary */
40*4882a593Smuzhiyun #define USB_MAX_HUB			16
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /*
45*4882a593Smuzhiyun  * This is the timeout to allow for submitting an urb in ms. We allow more
46*4882a593Smuzhiyun  * time for a BULK device to react - some are slow.
47*4882a593Smuzhiyun  */
48*4882a593Smuzhiyun #define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000)
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /* device request (setup) */
51*4882a593Smuzhiyun struct devrequest {
52*4882a593Smuzhiyun 	__u8	requesttype;
53*4882a593Smuzhiyun 	__u8	request;
54*4882a593Smuzhiyun 	__le16	value;
55*4882a593Smuzhiyun 	__le16	index;
56*4882a593Smuzhiyun 	__le16	length;
57*4882a593Smuzhiyun } __attribute__ ((packed));
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /* Interface */
60*4882a593Smuzhiyun struct usb_interface {
61*4882a593Smuzhiyun 	struct usb_interface_descriptor desc;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	__u8	no_of_ep;
64*4882a593Smuzhiyun 	__u8	num_altsetting;
65*4882a593Smuzhiyun 	__u8	act_altsetting;
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
68*4882a593Smuzhiyun 	/*
69*4882a593Smuzhiyun 	 * Super Speed Device will have Super Speed Endpoint
70*4882a593Smuzhiyun 	 * Companion Descriptor  (section 9.6.7 of usb 3.0 spec)
71*4882a593Smuzhiyun 	 * Revision 1.0 June 6th 2011
72*4882a593Smuzhiyun 	 */
73*4882a593Smuzhiyun 	struct usb_ss_ep_comp_descriptor ss_ep_comp_desc[USB_MAXENDPOINTS];
74*4882a593Smuzhiyun } __attribute__ ((packed));
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun /* Configuration information.. */
77*4882a593Smuzhiyun struct usb_config {
78*4882a593Smuzhiyun 	struct usb_config_descriptor desc;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	__u8	no_of_if;	/* number of interfaces */
81*4882a593Smuzhiyun 	struct usb_interface if_desc[USB_MAXINTERFACES];
82*4882a593Smuzhiyun } __attribute__ ((packed));
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun enum {
85*4882a593Smuzhiyun 	/* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
86*4882a593Smuzhiyun 	PACKET_SIZE_8   = 0,
87*4882a593Smuzhiyun 	PACKET_SIZE_16  = 1,
88*4882a593Smuzhiyun 	PACKET_SIZE_32  = 2,
89*4882a593Smuzhiyun 	PACKET_SIZE_64  = 3,
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /**
93*4882a593Smuzhiyun  * struct usb_device - information about a USB device
94*4882a593Smuzhiyun  *
95*4882a593Smuzhiyun  * With driver model both UCLASS_USB (the USB controllers) and UCLASS_USB_HUB
96*4882a593Smuzhiyun  * (the hubs) have this as parent data. Hubs are children of controllers or
97*4882a593Smuzhiyun  * other hubs and there is always a single root hub for each controller.
98*4882a593Smuzhiyun  * Therefore struct usb_device can always be accessed with
99*4882a593Smuzhiyun  * dev_get_parent_priv(dev), where dev is a USB device.
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  * Pointers exist for obtaining both the device (could be any uclass) and
102*4882a593Smuzhiyun  * controller (UCLASS_USB) from this structure. The controller does not have
103*4882a593Smuzhiyun  * a struct usb_device since it is not a device.
104*4882a593Smuzhiyun  */
105*4882a593Smuzhiyun struct usb_device {
106*4882a593Smuzhiyun 	int	devnum;			/* Device number on USB bus */
107*4882a593Smuzhiyun 	int	speed;			/* full/low/high */
108*4882a593Smuzhiyun 	char	mf[32];			/* manufacturer */
109*4882a593Smuzhiyun 	char	prod[32];		/* product */
110*4882a593Smuzhiyun 	char	serial[32];		/* serial number */
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 	/* Maximum packet size; one of: PACKET_SIZE_* */
113*4882a593Smuzhiyun 	int maxpacketsize;
114*4882a593Smuzhiyun 	/* one bit for each endpoint ([0] = IN, [1] = OUT) */
115*4882a593Smuzhiyun 	unsigned int toggle[2];
116*4882a593Smuzhiyun 	/* endpoint halts; one bit per endpoint # & direction;
117*4882a593Smuzhiyun 	 * [0] = IN, [1] = OUT
118*4882a593Smuzhiyun 	 */
119*4882a593Smuzhiyun 	unsigned int halted[2];
120*4882a593Smuzhiyun 	int epmaxpacketin[16];		/* INput endpoint specific maximums */
121*4882a593Smuzhiyun 	int epmaxpacketout[16];		/* OUTput endpoint specific maximums */
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 	int configno;			/* selected config number */
124*4882a593Smuzhiyun 	/* Device Descriptor */
125*4882a593Smuzhiyun 	struct usb_device_descriptor descriptor
126*4882a593Smuzhiyun 		__attribute__((aligned(ARCH_DMA_MINALIGN)));
127*4882a593Smuzhiyun 	struct usb_config config; /* config descriptor */
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	int have_langid;		/* whether string_langid is valid yet */
130*4882a593Smuzhiyun 	int string_langid;		/* language ID for strings */
131*4882a593Smuzhiyun 	int (*irq_handle)(struct usb_device *dev);
132*4882a593Smuzhiyun 	unsigned long irq_status;
133*4882a593Smuzhiyun 	int irq_act_len;		/* transferred bytes */
134*4882a593Smuzhiyun 	void *privptr;
135*4882a593Smuzhiyun 	/*
136*4882a593Smuzhiyun 	 * Child devices -  if this is a hub device
137*4882a593Smuzhiyun 	 * Each instance needs its own set of data structures.
138*4882a593Smuzhiyun 	 */
139*4882a593Smuzhiyun 	unsigned long status;
140*4882a593Smuzhiyun 	unsigned long int_pending;	/* 1 bit per ep, used by int_queue */
141*4882a593Smuzhiyun 	int act_len;			/* transferred bytes */
142*4882a593Smuzhiyun 	int maxchild;			/* Number of ports if hub */
143*4882a593Smuzhiyun 	int portnr;			/* Port number, 1=first */
144*4882a593Smuzhiyun #if !CONFIG_IS_ENABLED(DM_USB)
145*4882a593Smuzhiyun 	/* parent hub, or NULL if this is the root hub */
146*4882a593Smuzhiyun 	struct usb_device *parent;
147*4882a593Smuzhiyun 	struct usb_device *children[USB_MAXCHILDREN];
148*4882a593Smuzhiyun 	void *controller;		/* hardware controller private data */
149*4882a593Smuzhiyun #endif
150*4882a593Smuzhiyun 	/* slot_id - for xHCI enabled devices */
151*4882a593Smuzhiyun 	unsigned int slot_id;
152*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(DM_USB)
153*4882a593Smuzhiyun 	struct udevice *dev;		/* Pointer to associated device */
154*4882a593Smuzhiyun 	struct udevice *controller_dev;	/* Pointer to associated controller */
155*4882a593Smuzhiyun #endif
156*4882a593Smuzhiyun };
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun struct int_queue;
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun /*
161*4882a593Smuzhiyun  * You can initialize platform's USB host or device
162*4882a593Smuzhiyun  * ports by passing this enum as an argument to
163*4882a593Smuzhiyun  * board_usb_init().
164*4882a593Smuzhiyun  */
165*4882a593Smuzhiyun enum usb_init_type {
166*4882a593Smuzhiyun 	USB_INIT_HOST,
167*4882a593Smuzhiyun 	USB_INIT_DEVICE
168*4882a593Smuzhiyun };
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun /**********************************************************************
171*4882a593Smuzhiyun  * this is how the lowlevel part communicate with the outer world
172*4882a593Smuzhiyun  */
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun int usb_lowlevel_init(int index, enum usb_init_type init, void **controller);
175*4882a593Smuzhiyun int usb_lowlevel_stop(int index);
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun #if defined(CONFIG_USB_MUSB_HOST) || CONFIG_IS_ENABLED(DM_USB)
178*4882a593Smuzhiyun int usb_reset_root_port(struct usb_device *dev);
179*4882a593Smuzhiyun #else
180*4882a593Smuzhiyun #define usb_reset_root_port(dev)
181*4882a593Smuzhiyun #endif
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
184*4882a593Smuzhiyun 			void *buffer, int transfer_len);
185*4882a593Smuzhiyun int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
186*4882a593Smuzhiyun 			int transfer_len, struct devrequest *setup);
187*4882a593Smuzhiyun int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
188*4882a593Smuzhiyun 			int transfer_len, int interval, bool nonblock);
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun #if defined CONFIG_USB_EHCI_HCD || defined CONFIG_USB_MUSB_HOST \
191*4882a593Smuzhiyun 	|| CONFIG_IS_ENABLED(DM_USB)
192*4882a593Smuzhiyun struct int_queue *create_int_queue(struct usb_device *dev, unsigned long pipe,
193*4882a593Smuzhiyun 	int queuesize, int elementsize, void *buffer, int interval);
194*4882a593Smuzhiyun int destroy_int_queue(struct usb_device *dev, struct int_queue *queue);
195*4882a593Smuzhiyun void *poll_int_queue(struct usb_device *dev, struct int_queue *queue);
196*4882a593Smuzhiyun #endif
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun /* Defines */
199*4882a593Smuzhiyun #define USB_UHCI_VEND_ID	0x8086
200*4882a593Smuzhiyun #define USB_UHCI_DEV_ID		0x7112
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun /*
203*4882a593Smuzhiyun  * PXA25x can only act as USB device. There are drivers
204*4882a593Smuzhiyun  * which works with USB CDC gadgets implementations.
205*4882a593Smuzhiyun  * Some of them have common routines which can be used
206*4882a593Smuzhiyun  * in boards init functions e.g. udc_disconnect() used for
207*4882a593Smuzhiyun  * forced device disconnection from host.
208*4882a593Smuzhiyun  */
209*4882a593Smuzhiyun extern void udc_disconnect(void);
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun /*
212*4882a593Smuzhiyun  * board-specific hardware initialization, called by
213*4882a593Smuzhiyun  * usb drivers and u-boot commands
214*4882a593Smuzhiyun  *
215*4882a593Smuzhiyun  * @param index USB controller number
216*4882a593Smuzhiyun  * @param init initializes controller as USB host or device
217*4882a593Smuzhiyun  */
218*4882a593Smuzhiyun int board_usb_init(int index, enum usb_init_type init);
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun /*
221*4882a593Smuzhiyun  * can be used to clean up after failed USB initialization attempt
222*4882a593Smuzhiyun  * vide: board_usb_init()
223*4882a593Smuzhiyun  *
224*4882a593Smuzhiyun  * @param index USB controller number for selective cleanup
225*4882a593Smuzhiyun  * @param init usb_init_type passed to board_usb_init()
226*4882a593Smuzhiyun  */
227*4882a593Smuzhiyun int board_usb_cleanup(int index, enum usb_init_type init);
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun #ifdef CONFIG_USB_STORAGE
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun #define USB_MAX_STOR_DEV 7
232*4882a593Smuzhiyun int usb_stor_scan(int mode);
233*4882a593Smuzhiyun int usb_stor_info(void);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun #endif
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun #ifdef CONFIG_USB_HOST_ETHER
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun #define USB_MAX_ETH_DEV 5
240*4882a593Smuzhiyun int usb_host_eth_scan(int mode);
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun #endif
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun #ifdef CONFIG_USB_KEYBOARD
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun int drv_usb_kbd_init(void);
247*4882a593Smuzhiyun int usb_kbd_deregister(int force);
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun #endif
250*4882a593Smuzhiyun /* routines */
251*4882a593Smuzhiyun int usb_init(void); /* initialize the USB Controller */
252*4882a593Smuzhiyun int usb_stop(void); /* stop the USB Controller */
253*4882a593Smuzhiyun int usb_detect_change(void); /* detect if a USB device has been (un)plugged */
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
257*4882a593Smuzhiyun int usb_set_idle(struct usb_device *dev, int ifnum, int duration,
258*4882a593Smuzhiyun 			int report_id);
259*4882a593Smuzhiyun int usb_control_msg(struct usb_device *dev, unsigned int pipe,
260*4882a593Smuzhiyun 			unsigned char request, unsigned char requesttype,
261*4882a593Smuzhiyun 			unsigned short value, unsigned short index,
262*4882a593Smuzhiyun 			void *data, unsigned short size, int timeout);
263*4882a593Smuzhiyun int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
264*4882a593Smuzhiyun 			void *data, int len, int *actual_length, int timeout);
265*4882a593Smuzhiyun int usb_int_msg(struct usb_device *dev, unsigned long pipe,
266*4882a593Smuzhiyun 		void *buffer, int transfer_len, int interval, bool nonblock);
267*4882a593Smuzhiyun int usb_disable_asynch(int disable);
268*4882a593Smuzhiyun int usb_maxpacket(struct usb_device *dev, unsigned long pipe);
269*4882a593Smuzhiyun int usb_get_configuration_no(struct usb_device *dev, int cfgno,
270*4882a593Smuzhiyun 			unsigned char *buffer, int length);
271*4882a593Smuzhiyun int usb_get_configuration_len(struct usb_device *dev, int cfgno);
272*4882a593Smuzhiyun int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
273*4882a593Smuzhiyun 			unsigned char id, void *buf, int size);
274*4882a593Smuzhiyun int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
275*4882a593Smuzhiyun 			unsigned char type, unsigned char id, void *buf,
276*4882a593Smuzhiyun 			int size);
277*4882a593Smuzhiyun int usb_clear_halt(struct usb_device *dev, int pipe);
278*4882a593Smuzhiyun int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
279*4882a593Smuzhiyun int usb_set_interface(struct usb_device *dev, int interface, int alternate);
280*4882a593Smuzhiyun int usb_get_port_status(struct usb_device *dev, int port, void *data);
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun /* big endian -> little endian conversion */
283*4882a593Smuzhiyun /* some CPUs are already little endian e.g. the ARM920T */
284*4882a593Smuzhiyun #define __swap_16(x) \
285*4882a593Smuzhiyun 	({ unsigned short x_ = (unsigned short)x; \
286*4882a593Smuzhiyun 	 (unsigned short)( \
287*4882a593Smuzhiyun 		((x_ & 0x00FFU) << 8) | ((x_ & 0xFF00U) >> 8)); \
288*4882a593Smuzhiyun 	})
289*4882a593Smuzhiyun #define __swap_32(x) \
290*4882a593Smuzhiyun 	({ unsigned long x_ = (unsigned long)x; \
291*4882a593Smuzhiyun 	 (unsigned long)( \
292*4882a593Smuzhiyun 		((x_ & 0x000000FFUL) << 24) | \
293*4882a593Smuzhiyun 		((x_ & 0x0000FF00UL) <<	 8) | \
294*4882a593Smuzhiyun 		((x_ & 0x00FF0000UL) >>	 8) | \
295*4882a593Smuzhiyun 		((x_ & 0xFF000000UL) >> 24)); \
296*4882a593Smuzhiyun 	})
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun #ifdef __LITTLE_ENDIAN
299*4882a593Smuzhiyun # define swap_16(x) (x)
300*4882a593Smuzhiyun # define swap_32(x) (x)
301*4882a593Smuzhiyun #else
302*4882a593Smuzhiyun # define swap_16(x) __swap_16(x)
303*4882a593Smuzhiyun # define swap_32(x) __swap_32(x)
304*4882a593Smuzhiyun #endif
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun /*
307*4882a593Smuzhiyun  * Calling this entity a "pipe" is glorifying it. A USB pipe
308*4882a593Smuzhiyun  * is something embarrassingly simple: it basically consists
309*4882a593Smuzhiyun  * of the following information:
310*4882a593Smuzhiyun  *  - device number (7 bits)
311*4882a593Smuzhiyun  *  - endpoint number (4 bits)
312*4882a593Smuzhiyun  *  - current Data0/1 state (1 bit)
313*4882a593Smuzhiyun  *  - direction (1 bit)
314*4882a593Smuzhiyun  *  - speed (2 bits)
315*4882a593Smuzhiyun  *  - max packet size (2 bits: 8, 16, 32 or 64)
316*4882a593Smuzhiyun  *  - pipe type (2 bits: control, interrupt, bulk, isochronous)
317*4882a593Smuzhiyun  *
318*4882a593Smuzhiyun  * That's 18 bits. Really. Nothing more. And the USB people have
319*4882a593Smuzhiyun  * documented these eighteen bits as some kind of glorious
320*4882a593Smuzhiyun  * virtual data structure.
321*4882a593Smuzhiyun  *
322*4882a593Smuzhiyun  * Let's not fall in that trap. We'll just encode it as a simple
323*4882a593Smuzhiyun  * unsigned int. The encoding is:
324*4882a593Smuzhiyun  *
325*4882a593Smuzhiyun  *  - max size:		bits 0-1	(00 = 8, 01 = 16, 10 = 32, 11 = 64)
326*4882a593Smuzhiyun  *  - direction:	bit 7		(0 = Host-to-Device [Out],
327*4882a593Smuzhiyun  *					(1 = Device-to-Host [In])
328*4882a593Smuzhiyun  *  - device:		bits 8-14
329*4882a593Smuzhiyun  *  - endpoint:		bits 15-18
330*4882a593Smuzhiyun  *  - Data0/1:		bit 19
331*4882a593Smuzhiyun  *  - pipe type:	bits 30-31	(00 = isochronous, 01 = interrupt,
332*4882a593Smuzhiyun  *					 10 = control, 11 = bulk)
333*4882a593Smuzhiyun  *
334*4882a593Smuzhiyun  * Why? Because it's arbitrary, and whatever encoding we select is really
335*4882a593Smuzhiyun  * up to us. This one happens to share a lot of bit positions with the UHCI
336*4882a593Smuzhiyun  * specification, so that much of the uhci driver can just mask the bits
337*4882a593Smuzhiyun  * appropriately.
338*4882a593Smuzhiyun  */
339*4882a593Smuzhiyun /* Create various pipes... */
340*4882a593Smuzhiyun #define create_pipe(dev,endpoint) \
341*4882a593Smuzhiyun 		(((dev)->devnum << 8) | ((endpoint) << 15) | \
342*4882a593Smuzhiyun 		(dev)->maxpacketsize)
343*4882a593Smuzhiyun #define default_pipe(dev) ((dev)->speed << 26)
344*4882a593Smuzhiyun 
345*4882a593Smuzhiyun #define usb_sndctrlpipe(dev, endpoint)	((PIPE_CONTROL << 30) | \
346*4882a593Smuzhiyun 					 create_pipe(dev, endpoint))
347*4882a593Smuzhiyun #define usb_rcvctrlpipe(dev, endpoint)	((PIPE_CONTROL << 30) | \
348*4882a593Smuzhiyun 					 create_pipe(dev, endpoint) | \
349*4882a593Smuzhiyun 					 USB_DIR_IN)
350*4882a593Smuzhiyun #define usb_sndisocpipe(dev, endpoint)	((PIPE_ISOCHRONOUS << 30) | \
351*4882a593Smuzhiyun 					 create_pipe(dev, endpoint))
352*4882a593Smuzhiyun #define usb_rcvisocpipe(dev, endpoint)	((PIPE_ISOCHRONOUS << 30) | \
353*4882a593Smuzhiyun 					 create_pipe(dev, endpoint) | \
354*4882a593Smuzhiyun 					 USB_DIR_IN)
355*4882a593Smuzhiyun #define usb_sndbulkpipe(dev, endpoint)	((PIPE_BULK << 30) | \
356*4882a593Smuzhiyun 					 create_pipe(dev, endpoint))
357*4882a593Smuzhiyun #define usb_rcvbulkpipe(dev, endpoint)	((PIPE_BULK << 30) | \
358*4882a593Smuzhiyun 					 create_pipe(dev, endpoint) | \
359*4882a593Smuzhiyun 					 USB_DIR_IN)
360*4882a593Smuzhiyun #define usb_sndintpipe(dev, endpoint)	((PIPE_INTERRUPT << 30) | \
361*4882a593Smuzhiyun 					 create_pipe(dev, endpoint))
362*4882a593Smuzhiyun #define usb_rcvintpipe(dev, endpoint)	((PIPE_INTERRUPT << 30) | \
363*4882a593Smuzhiyun 					 create_pipe(dev, endpoint) | \
364*4882a593Smuzhiyun 					 USB_DIR_IN)
365*4882a593Smuzhiyun #define usb_snddefctrl(dev)		((PIPE_CONTROL << 30) | \
366*4882a593Smuzhiyun 					 default_pipe(dev))
367*4882a593Smuzhiyun #define usb_rcvdefctrl(dev)		((PIPE_CONTROL << 30) | \
368*4882a593Smuzhiyun 					 default_pipe(dev) | \
369*4882a593Smuzhiyun 					 USB_DIR_IN)
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun /* The D0/D1 toggle bits */
372*4882a593Smuzhiyun #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
373*4882a593Smuzhiyun #define usb_dotoggle(dev, ep, out)  ((dev)->toggle[out] ^= (1 << ep))
374*4882a593Smuzhiyun #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
375*4882a593Smuzhiyun 						((dev)->toggle[out] & \
376*4882a593Smuzhiyun 						 ~(1 << ep)) | ((bit) << ep))
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun /* Endpoint halt control/status */
379*4882a593Smuzhiyun #define usb_endpoint_out(ep_dir)	(((ep_dir >> 7) & 1) ^ 1)
380*4882a593Smuzhiyun #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
381*4882a593Smuzhiyun #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
382*4882a593Smuzhiyun #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun #define usb_packetid(pipe)	(((pipe) & USB_DIR_IN) ? USB_PID_IN : \
385*4882a593Smuzhiyun 				 USB_PID_OUT)
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun #define usb_pipeout(pipe)	((((pipe) >> 7) & 1) ^ 1)
388*4882a593Smuzhiyun #define usb_pipein(pipe)	(((pipe) >> 7) & 1)
389*4882a593Smuzhiyun #define usb_pipedevice(pipe)	(((pipe) >> 8) & 0x7f)
390*4882a593Smuzhiyun #define usb_pipe_endpdev(pipe)	(((pipe) >> 8) & 0x7ff)
391*4882a593Smuzhiyun #define usb_pipeendpoint(pipe)	(((pipe) >> 15) & 0xf)
392*4882a593Smuzhiyun #define usb_pipedata(pipe)	(((pipe) >> 19) & 1)
393*4882a593Smuzhiyun #define usb_pipetype(pipe)	(((pipe) >> 30) & 3)
394*4882a593Smuzhiyun #define usb_pipeisoc(pipe)	(usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
395*4882a593Smuzhiyun #define usb_pipeint(pipe)	(usb_pipetype((pipe)) == PIPE_INTERRUPT)
396*4882a593Smuzhiyun #define usb_pipecontrol(pipe)	(usb_pipetype((pipe)) == PIPE_CONTROL)
397*4882a593Smuzhiyun #define usb_pipebulk(pipe)	(usb_pipetype((pipe)) == PIPE_BULK)
398*4882a593Smuzhiyun 
399*4882a593Smuzhiyun #define usb_pipe_ep_index(pipe)	\
400*4882a593Smuzhiyun 		usb_pipecontrol(pipe) ? (usb_pipeendpoint(pipe) * 2) : \
401*4882a593Smuzhiyun 				((usb_pipeendpoint(pipe) * 2) - \
402*4882a593Smuzhiyun 				 (usb_pipein(pipe) ? 0 : 1))
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun /**
405*4882a593Smuzhiyun  * struct usb_device_id - identifies USB devices for probing and hotplugging
406*4882a593Smuzhiyun  * @match_flags: Bit mask controlling which of the other fields are used to
407*4882a593Smuzhiyun  *	match against new devices. Any field except for driver_info may be
408*4882a593Smuzhiyun  *	used, although some only make sense in conjunction with other fields.
409*4882a593Smuzhiyun  *	This is usually set by a USB_DEVICE_*() macro, which sets all
410*4882a593Smuzhiyun  *	other fields in this structure except for driver_info.
411*4882a593Smuzhiyun  * @idVendor: USB vendor ID for a device; numbers are assigned
412*4882a593Smuzhiyun  *	by the USB forum to its members.
413*4882a593Smuzhiyun  * @idProduct: Vendor-assigned product ID.
414*4882a593Smuzhiyun  * @bcdDevice_lo: Low end of range of vendor-assigned product version numbers.
415*4882a593Smuzhiyun  *	This is also used to identify individual product versions, for
416*4882a593Smuzhiyun  *	a range consisting of a single device.
417*4882a593Smuzhiyun  * @bcdDevice_hi: High end of version number range.  The range of product
418*4882a593Smuzhiyun  *	versions is inclusive.
419*4882a593Smuzhiyun  * @bDeviceClass: Class of device; numbers are assigned
420*4882a593Smuzhiyun  *	by the USB forum.  Products may choose to implement classes,
421*4882a593Smuzhiyun  *	or be vendor-specific.  Device classes specify behavior of all
422*4882a593Smuzhiyun  *	the interfaces on a device.
423*4882a593Smuzhiyun  * @bDeviceSubClass: Subclass of device; associated with bDeviceClass.
424*4882a593Smuzhiyun  * @bDeviceProtocol: Protocol of device; associated with bDeviceClass.
425*4882a593Smuzhiyun  * @bInterfaceClass: Class of interface; numbers are assigned
426*4882a593Smuzhiyun  *	by the USB forum.  Products may choose to implement classes,
427*4882a593Smuzhiyun  *	or be vendor-specific.  Interface classes specify behavior only
428*4882a593Smuzhiyun  *	of a given interface; other interfaces may support other classes.
429*4882a593Smuzhiyun  * @bInterfaceSubClass: Subclass of interface; associated with bInterfaceClass.
430*4882a593Smuzhiyun  * @bInterfaceProtocol: Protocol of interface; associated with bInterfaceClass.
431*4882a593Smuzhiyun  * @bInterfaceNumber: Number of interface; composite devices may use
432*4882a593Smuzhiyun  *	fixed interface numbers to differentiate between vendor-specific
433*4882a593Smuzhiyun  *	interfaces.
434*4882a593Smuzhiyun  * @driver_info: Holds information used by the driver.  Usually it holds
435*4882a593Smuzhiyun  *	a pointer to a descriptor understood by the driver, or perhaps
436*4882a593Smuzhiyun  *	device flags.
437*4882a593Smuzhiyun  *
438*4882a593Smuzhiyun  * In most cases, drivers will create a table of device IDs by using
439*4882a593Smuzhiyun  * USB_DEVICE(), or similar macros designed for that purpose.
440*4882a593Smuzhiyun  * They will then export it to userspace using MODULE_DEVICE_TABLE(),
441*4882a593Smuzhiyun  * and provide it to the USB core through their usb_driver structure.
442*4882a593Smuzhiyun  *
443*4882a593Smuzhiyun  * See the usb_match_id() function for information about how matches are
444*4882a593Smuzhiyun  * performed.  Briefly, you will normally use one of several macros to help
445*4882a593Smuzhiyun  * construct these entries.  Each entry you provide will either identify
446*4882a593Smuzhiyun  * one or more specific products, or will identify a class of products
447*4882a593Smuzhiyun  * which have agreed to behave the same.  You should put the more specific
448*4882a593Smuzhiyun  * matches towards the beginning of your table, so that driver_info can
449*4882a593Smuzhiyun  * record quirks of specific products.
450*4882a593Smuzhiyun  */
451*4882a593Smuzhiyun struct usb_device_id {
452*4882a593Smuzhiyun 	/* which fields to match against? */
453*4882a593Smuzhiyun 	u16 match_flags;
454*4882a593Smuzhiyun 
455*4882a593Smuzhiyun 	/* Used for product specific matches; range is inclusive */
456*4882a593Smuzhiyun 	u16 idVendor;
457*4882a593Smuzhiyun 	u16 idProduct;
458*4882a593Smuzhiyun 	u16 bcdDevice_lo;
459*4882a593Smuzhiyun 	u16 bcdDevice_hi;
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun 	/* Used for device class matches */
462*4882a593Smuzhiyun 	u8 bDeviceClass;
463*4882a593Smuzhiyun 	u8 bDeviceSubClass;
464*4882a593Smuzhiyun 	u8 bDeviceProtocol;
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun 	/* Used for interface class matches */
467*4882a593Smuzhiyun 	u8 bInterfaceClass;
468*4882a593Smuzhiyun 	u8 bInterfaceSubClass;
469*4882a593Smuzhiyun 	u8 bInterfaceProtocol;
470*4882a593Smuzhiyun 
471*4882a593Smuzhiyun 	/* Used for vendor-specific interface matches */
472*4882a593Smuzhiyun 	u8 bInterfaceNumber;
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun 	/* not matched against */
475*4882a593Smuzhiyun 	ulong driver_info;
476*4882a593Smuzhiyun };
477*4882a593Smuzhiyun 
478*4882a593Smuzhiyun /* Some useful macros to use to create struct usb_device_id */
479*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_VENDOR		0x0001
480*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_PRODUCT		0x0002
481*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_DEV_LO		0x0004
482*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_DEV_HI		0x0008
483*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
484*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
485*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
486*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
487*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
488*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
489*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_INT_NUMBER		0x0400
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun /* Match anything, indicates this is a valid entry even if everything is 0 */
492*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_NONE		0x0800
493*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_ALL			0x07ff
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun /**
496*4882a593Smuzhiyun  * struct usb_driver_entry - Matches a driver to its usb_device_ids
497*4882a593Smuzhiyun  * @driver: Driver to use
498*4882a593Smuzhiyun  * @match: List of match records for this driver, terminated by {}
499*4882a593Smuzhiyun  */
500*4882a593Smuzhiyun struct usb_driver_entry {
501*4882a593Smuzhiyun 	struct driver *driver;
502*4882a593Smuzhiyun 	const struct usb_device_id *match;
503*4882a593Smuzhiyun };
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun #define USB_DEVICE_ID_MATCH_DEVICE \
506*4882a593Smuzhiyun 		(USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
507*4882a593Smuzhiyun 
508*4882a593Smuzhiyun /**
509*4882a593Smuzhiyun  * USB_DEVICE - macro used to describe a specific usb device
510*4882a593Smuzhiyun  * @vend: the 16 bit USB Vendor ID
511*4882a593Smuzhiyun  * @prod: the 16 bit USB Product ID
512*4882a593Smuzhiyun  *
513*4882a593Smuzhiyun  * This macro is used to create a struct usb_device_id that matches a
514*4882a593Smuzhiyun  * specific device.
515*4882a593Smuzhiyun  */
516*4882a593Smuzhiyun #define USB_DEVICE(vend, prod) \
517*4882a593Smuzhiyun 	.match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
518*4882a593Smuzhiyun 	.idVendor = (vend), \
519*4882a593Smuzhiyun 	.idProduct = (prod)
520*4882a593Smuzhiyun 
521*4882a593Smuzhiyun #define U_BOOT_USB_DEVICE(__name, __match) \
522*4882a593Smuzhiyun 	ll_entry_declare(struct usb_driver_entry, __name, usb_driver_entry) = {\
523*4882a593Smuzhiyun 		.driver = llsym(struct driver, __name, driver), \
524*4882a593Smuzhiyun 		.match = __match, \
525*4882a593Smuzhiyun 		}
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun /*************************************************************************
528*4882a593Smuzhiyun  * Hub Stuff
529*4882a593Smuzhiyun  */
530*4882a593Smuzhiyun struct usb_port_status {
531*4882a593Smuzhiyun 	unsigned short wPortStatus;
532*4882a593Smuzhiyun 	unsigned short wPortChange;
533*4882a593Smuzhiyun } __attribute__ ((packed));
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun struct usb_hub_status {
536*4882a593Smuzhiyun 	unsigned short wHubStatus;
537*4882a593Smuzhiyun 	unsigned short wHubChange;
538*4882a593Smuzhiyun } __attribute__ ((packed));
539*4882a593Smuzhiyun 
540*4882a593Smuzhiyun /*
541*4882a593Smuzhiyun  * Hub Device descriptor
542*4882a593Smuzhiyun  * USB Hub class device protocols
543*4882a593Smuzhiyun  */
544*4882a593Smuzhiyun #define USB_HUB_PR_FS		0 /* Full speed hub */
545*4882a593Smuzhiyun #define USB_HUB_PR_HS_NO_TT	0 /* Hi-speed hub without TT */
546*4882a593Smuzhiyun #define USB_HUB_PR_HS_SINGLE_TT	1 /* Hi-speed hub with single TT */
547*4882a593Smuzhiyun #define USB_HUB_PR_HS_MULTI_TT	2 /* Hi-speed hub with multiple TT */
548*4882a593Smuzhiyun #define USB_HUB_PR_SS		3 /* Super speed hub */
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun /* Transaction Translator Think Times, in bits */
551*4882a593Smuzhiyun #define HUB_TTTT_8_BITS		0x00
552*4882a593Smuzhiyun #define HUB_TTTT_16_BITS	0x20
553*4882a593Smuzhiyun #define HUB_TTTT_24_BITS	0x40
554*4882a593Smuzhiyun #define HUB_TTTT_32_BITS	0x60
555*4882a593Smuzhiyun 
556*4882a593Smuzhiyun /* Hub descriptor */
557*4882a593Smuzhiyun struct usb_hub_descriptor {
558*4882a593Smuzhiyun 	unsigned char  bLength;
559*4882a593Smuzhiyun 	unsigned char  bDescriptorType;
560*4882a593Smuzhiyun 	unsigned char  bNbrPorts;
561*4882a593Smuzhiyun 	unsigned short wHubCharacteristics;
562*4882a593Smuzhiyun 	unsigned char  bPwrOn2PwrGood;
563*4882a593Smuzhiyun 	unsigned char  bHubContrCurrent;
564*4882a593Smuzhiyun 	/* 2.0 and 3.0 hubs differ here */
565*4882a593Smuzhiyun 	union {
566*4882a593Smuzhiyun 		struct {
567*4882a593Smuzhiyun 			/* add 1 bit for hub status change; round to bytes */
568*4882a593Smuzhiyun 			__u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
569*4882a593Smuzhiyun 			__u8 PortPowerCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
570*4882a593Smuzhiyun 		} __attribute__ ((packed)) hs;
571*4882a593Smuzhiyun 
572*4882a593Smuzhiyun 		struct {
573*4882a593Smuzhiyun 			__u8 bHubHdrDecLat;
574*4882a593Smuzhiyun 			__le16 wHubDelay;
575*4882a593Smuzhiyun 			__le16 DeviceRemovable;
576*4882a593Smuzhiyun 		} __attribute__ ((packed)) ss;
577*4882a593Smuzhiyun 	} u;
578*4882a593Smuzhiyun } __attribute__ ((packed));
579*4882a593Smuzhiyun 
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun struct usb_hub_device {
582*4882a593Smuzhiyun 	struct usb_device *pusb_dev;
583*4882a593Smuzhiyun 	struct usb_hub_descriptor desc;
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun 	ulong connect_timeout;		/* Device connection timeout in ms */
586*4882a593Smuzhiyun 	ulong query_delay;		/* Device query delay in ms */
587*4882a593Smuzhiyun 	int overcurrent_count[USB_MAXCHILDREN];	/* Over-current counter */
588*4882a593Smuzhiyun 	int hub_depth;			/* USB 3.0 hub depth */
589*4882a593Smuzhiyun 	struct usb_tt tt;		/* Transaction Translator */
590*4882a593Smuzhiyun };
591*4882a593Smuzhiyun 
592*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(DM_USB)
593*4882a593Smuzhiyun /**
594*4882a593Smuzhiyun  * struct usb_platdata - Platform data about a USB controller
595*4882a593Smuzhiyun  *
596*4882a593Smuzhiyun  * Given a USB controller (UCLASS_USB) dev this is dev_get_platdata(dev)
597*4882a593Smuzhiyun  */
598*4882a593Smuzhiyun struct usb_platdata {
599*4882a593Smuzhiyun 	enum usb_init_type init_type;
600*4882a593Smuzhiyun };
601*4882a593Smuzhiyun 
602*4882a593Smuzhiyun /**
603*4882a593Smuzhiyun  * struct usb_dev_platdata - Platform data about a USB device
604*4882a593Smuzhiyun  *
605*4882a593Smuzhiyun  * Given a USB device dev this structure is dev_get_parent_platdata(dev).
606*4882a593Smuzhiyun  * This is used by sandbox to provide emulation data also.
607*4882a593Smuzhiyun  *
608*4882a593Smuzhiyun  * @id:		ID used to match this device
609*4882a593Smuzhiyun  * @devnum:	Device address on the USB bus
610*4882a593Smuzhiyun  * @udev:	usb-uclass internal use only do NOT use
611*4882a593Smuzhiyun  * @strings:	List of descriptor strings (for sandbox emulation purposes)
612*4882a593Smuzhiyun  * @desc_list:	List of descriptors (for sandbox emulation purposes)
613*4882a593Smuzhiyun  */
614*4882a593Smuzhiyun struct usb_dev_platdata {
615*4882a593Smuzhiyun 	struct usb_device_id id;
616*4882a593Smuzhiyun 	int devnum;
617*4882a593Smuzhiyun 	/*
618*4882a593Smuzhiyun 	 * This pointer is used to pass the usb_device used in usb_scan_device,
619*4882a593Smuzhiyun 	 * to get the usb descriptors before the driver is known, to the
620*4882a593Smuzhiyun 	 * actual udevice once the driver is known and the udevice is created.
621*4882a593Smuzhiyun 	 * This will be NULL except during probe, do NOT use.
622*4882a593Smuzhiyun 	 *
623*4882a593Smuzhiyun 	 * This should eventually go away.
624*4882a593Smuzhiyun 	 */
625*4882a593Smuzhiyun 	struct usb_device *udev;
626*4882a593Smuzhiyun #ifdef CONFIG_SANDBOX
627*4882a593Smuzhiyun 	struct usb_string *strings;
628*4882a593Smuzhiyun 	/* NULL-terminated list of descriptor pointers */
629*4882a593Smuzhiyun 	struct usb_generic_descriptor **desc_list;
630*4882a593Smuzhiyun #endif
631*4882a593Smuzhiyun 	int configno;
632*4882a593Smuzhiyun };
633*4882a593Smuzhiyun 
634*4882a593Smuzhiyun /**
635*4882a593Smuzhiyun  * struct usb_bus_priv - information about the USB controller
636*4882a593Smuzhiyun  *
637*4882a593Smuzhiyun  * Given a USB controller (UCLASS_USB) 'dev', this is
638*4882a593Smuzhiyun  * dev_get_uclass_priv(dev).
639*4882a593Smuzhiyun  *
640*4882a593Smuzhiyun  * @next_addr:	Next device address to allocate minus 1. Incremented by 1
641*4882a593Smuzhiyun  *		each time a new device address is set, so this holds the
642*4882a593Smuzhiyun  *		number of devices on the bus
643*4882a593Smuzhiyun  * @desc_before_addr:	true if we can read a device descriptor before it
644*4882a593Smuzhiyun  *		has been assigned an address. For XHCI this is not possible
645*4882a593Smuzhiyun  *		so this will be false.
646*4882a593Smuzhiyun  * @companion:  True if this is a companion controller to another USB
647*4882a593Smuzhiyun  *		controller
648*4882a593Smuzhiyun  */
649*4882a593Smuzhiyun struct usb_bus_priv {
650*4882a593Smuzhiyun 	int next_addr;
651*4882a593Smuzhiyun 	bool desc_before_addr;
652*4882a593Smuzhiyun 	bool companion;
653*4882a593Smuzhiyun };
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun /**
656*4882a593Smuzhiyun  * struct usb_emul_platdata - platform data about the USB emulator
657*4882a593Smuzhiyun  *
658*4882a593Smuzhiyun  * Given a USB emulator (UCLASS_USB_EMUL) 'dev', this is
659*4882a593Smuzhiyun  * dev_get_uclass_platdata(dev).
660*4882a593Smuzhiyun  *
661*4882a593Smuzhiyun  * @port1:	USB emulator device port number on the parent hub
662*4882a593Smuzhiyun  */
663*4882a593Smuzhiyun struct usb_emul_platdata {
664*4882a593Smuzhiyun 	int port1;	/* Port number (numbered from 1) */
665*4882a593Smuzhiyun };
666*4882a593Smuzhiyun 
667*4882a593Smuzhiyun /**
668*4882a593Smuzhiyun  * struct dm_usb_ops - USB controller operations
669*4882a593Smuzhiyun  *
670*4882a593Smuzhiyun  * This defines the operations supoorted on a USB controller. Common
671*4882a593Smuzhiyun  * arguments are:
672*4882a593Smuzhiyun  *
673*4882a593Smuzhiyun  * @bus:	USB bus (i.e. controller), which is in UCLASS_USB.
674*4882a593Smuzhiyun  * @udev:	USB device parent data. Controllers are not expected to need
675*4882a593Smuzhiyun  *		this, since the device address on the bus is encoded in @pipe.
676*4882a593Smuzhiyun  *		It is used for sandbox, and can be handy for debugging and
677*4882a593Smuzhiyun  *		logging.
678*4882a593Smuzhiyun  * @pipe:	An assortment of bitfields which provide address and packet
679*4882a593Smuzhiyun  *		type information. See create_pipe() above for encoding
680*4882a593Smuzhiyun  *		details
681*4882a593Smuzhiyun  * @buffer:	A buffer to use for sending/receiving. This should be
682*4882a593Smuzhiyun  *		DMA-aligned.
683*4882a593Smuzhiyun  * @length:	Buffer length in bytes
684*4882a593Smuzhiyun  */
685*4882a593Smuzhiyun struct dm_usb_ops {
686*4882a593Smuzhiyun 	/**
687*4882a593Smuzhiyun 	 * control() - Send a control message
688*4882a593Smuzhiyun 	 *
689*4882a593Smuzhiyun 	 * Most parameters are as above.
690*4882a593Smuzhiyun 	 *
691*4882a593Smuzhiyun 	 * @setup: Additional setup information required by the message
692*4882a593Smuzhiyun 	 */
693*4882a593Smuzhiyun 	int (*control)(struct udevice *bus, struct usb_device *udev,
694*4882a593Smuzhiyun 		       unsigned long pipe, void *buffer, int length,
695*4882a593Smuzhiyun 		       struct devrequest *setup);
696*4882a593Smuzhiyun 	/**
697*4882a593Smuzhiyun 	 * bulk() - Send a bulk message
698*4882a593Smuzhiyun 	 *
699*4882a593Smuzhiyun 	 * Parameters are as above.
700*4882a593Smuzhiyun 	 */
701*4882a593Smuzhiyun 	int (*bulk)(struct udevice *bus, struct usb_device *udev,
702*4882a593Smuzhiyun 		    unsigned long pipe, void *buffer, int length);
703*4882a593Smuzhiyun 	/**
704*4882a593Smuzhiyun 	 * interrupt() - Send an interrupt message
705*4882a593Smuzhiyun 	 *
706*4882a593Smuzhiyun 	 * Most parameters are as above.
707*4882a593Smuzhiyun 	 *
708*4882a593Smuzhiyun 	 * @interval: Interrupt interval
709*4882a593Smuzhiyun 	 */
710*4882a593Smuzhiyun 	int (*interrupt)(struct udevice *bus, struct usb_device *udev,
711*4882a593Smuzhiyun 			 unsigned long pipe, void *buffer, int length,
712*4882a593Smuzhiyun 			 int interval, bool nonblock);
713*4882a593Smuzhiyun 
714*4882a593Smuzhiyun 	/**
715*4882a593Smuzhiyun 	 * create_int_queue() - Create and queue interrupt packets
716*4882a593Smuzhiyun 	 *
717*4882a593Smuzhiyun 	 * Create and queue @queuesize number of interrupt usb packets of
718*4882a593Smuzhiyun 	 * @elementsize bytes each. @buffer must be atleast @queuesize *
719*4882a593Smuzhiyun 	 * @elementsize bytes.
720*4882a593Smuzhiyun 	 *
721*4882a593Smuzhiyun 	 * Note some controllers only support a queuesize of 1.
722*4882a593Smuzhiyun 	 *
723*4882a593Smuzhiyun 	 * @interval: Interrupt interval
724*4882a593Smuzhiyun 	 *
725*4882a593Smuzhiyun 	 * @return A pointer to the created interrupt queue or NULL on error
726*4882a593Smuzhiyun 	 */
727*4882a593Smuzhiyun 	struct int_queue * (*create_int_queue)(struct udevice *bus,
728*4882a593Smuzhiyun 				struct usb_device *udev, unsigned long pipe,
729*4882a593Smuzhiyun 				int queuesize, int elementsize, void *buffer,
730*4882a593Smuzhiyun 				int interval);
731*4882a593Smuzhiyun 
732*4882a593Smuzhiyun 	/**
733*4882a593Smuzhiyun 	 * poll_int_queue() - Poll an interrupt queue for completed packets
734*4882a593Smuzhiyun 	 *
735*4882a593Smuzhiyun 	 * Poll an interrupt queue for completed packets. The return value
736*4882a593Smuzhiyun 	 * points to the part of the buffer passed to create_int_queue()
737*4882a593Smuzhiyun 	 * corresponding to the completed packet.
738*4882a593Smuzhiyun 	 *
739*4882a593Smuzhiyun 	 * @queue: queue to poll
740*4882a593Smuzhiyun 	 *
741*4882a593Smuzhiyun 	 * @return Pointer to the data of the first completed packet, or
742*4882a593Smuzhiyun 	 *         NULL if no packets are ready
743*4882a593Smuzhiyun 	 */
744*4882a593Smuzhiyun 	void * (*poll_int_queue)(struct udevice *bus, struct usb_device *udev,
745*4882a593Smuzhiyun 				 struct int_queue *queue);
746*4882a593Smuzhiyun 
747*4882a593Smuzhiyun 	/**
748*4882a593Smuzhiyun 	 * destroy_int_queue() - Destroy an interrupt queue
749*4882a593Smuzhiyun 	 *
750*4882a593Smuzhiyun 	 * Destroy an interrupt queue created by create_int_queue().
751*4882a593Smuzhiyun 	 *
752*4882a593Smuzhiyun 	 * @queue: queue to poll
753*4882a593Smuzhiyun 	 *
754*4882a593Smuzhiyun 	 * @return 0 if OK, -ve on error
755*4882a593Smuzhiyun 	 */
756*4882a593Smuzhiyun 	int (*destroy_int_queue)(struct udevice *bus, struct usb_device *udev,
757*4882a593Smuzhiyun 				 struct int_queue *queue);
758*4882a593Smuzhiyun 
759*4882a593Smuzhiyun 	/**
760*4882a593Smuzhiyun 	 * alloc_device() - Allocate a new device context (XHCI)
761*4882a593Smuzhiyun 	 *
762*4882a593Smuzhiyun 	 * Before sending packets to a new device on an XHCI bus, a device
763*4882a593Smuzhiyun 	 * context must be created. If this method is not NULL it will be
764*4882a593Smuzhiyun 	 * called before the device is enumerated (even before its descriptor
765*4882a593Smuzhiyun 	 * is read). This should be NULL for EHCI, which does not need this.
766*4882a593Smuzhiyun 	 */
767*4882a593Smuzhiyun 	int (*alloc_device)(struct udevice *bus, struct usb_device *udev);
768*4882a593Smuzhiyun 
769*4882a593Smuzhiyun 	/**
770*4882a593Smuzhiyun 	 * reset_root_port() - Reset usb root port
771*4882a593Smuzhiyun 	 */
772*4882a593Smuzhiyun 	int (*reset_root_port)(struct udevice *bus, struct usb_device *udev);
773*4882a593Smuzhiyun 
774*4882a593Smuzhiyun 	/**
775*4882a593Smuzhiyun 	 * update_hub_device() - Update HCD's internal representation of hub
776*4882a593Smuzhiyun 	 *
777*4882a593Smuzhiyun 	 * After a hub descriptor is fetched, notify HCD so that its internal
778*4882a593Smuzhiyun 	 * representation of this hub can be updated (xHCI)
779*4882a593Smuzhiyun 	 */
780*4882a593Smuzhiyun 	int (*update_hub_device)(struct udevice *bus, struct usb_device *udev);
781*4882a593Smuzhiyun 
782*4882a593Smuzhiyun 	/**
783*4882a593Smuzhiyun 	 * get_max_xfer_size() - Get HCD's maximum transfer bytes
784*4882a593Smuzhiyun 	 *
785*4882a593Smuzhiyun 	 * The HCD may have limitation on the maximum bytes to be transferred
786*4882a593Smuzhiyun 	 * in a USB transfer. USB class driver needs to be aware of this.
787*4882a593Smuzhiyun 	 */
788*4882a593Smuzhiyun 	int (*get_max_xfer_size)(struct udevice *bus, size_t *size);
789*4882a593Smuzhiyun };
790*4882a593Smuzhiyun 
791*4882a593Smuzhiyun #define usb_get_ops(dev)	((struct dm_usb_ops *)(dev)->driver->ops)
792*4882a593Smuzhiyun #define usb_get_emul_ops(dev)	((struct dm_usb_ops *)(dev)->driver->ops)
793*4882a593Smuzhiyun 
794*4882a593Smuzhiyun /**
795*4882a593Smuzhiyun  * usb_get_dev_index() - look up a device index number
796*4882a593Smuzhiyun  *
797*4882a593Smuzhiyun  * Look up devices using their index number (starting at 0). This works since
798*4882a593Smuzhiyun  * in U-Boot device addresses are allocated starting at 1 with no gaps.
799*4882a593Smuzhiyun  *
800*4882a593Smuzhiyun  * TODO(sjg@chromium.org): Remove this function when usb_ether.c is modified
801*4882a593Smuzhiyun  * to work better with driver model.
802*4882a593Smuzhiyun  *
803*4882a593Smuzhiyun  * @bus:	USB bus to check
804*4882a593Smuzhiyun  * @index:	Index number of device to find (0=first). This is just the
805*4882a593Smuzhiyun  *		device address less 1.
806*4882a593Smuzhiyun  */
807*4882a593Smuzhiyun struct usb_device *usb_get_dev_index(struct udevice *bus, int index);
808*4882a593Smuzhiyun 
809*4882a593Smuzhiyun /**
810*4882a593Smuzhiyun  * usb_setup_device() - set up a device ready for use
811*4882a593Smuzhiyun  *
812*4882a593Smuzhiyun  * @dev:	USB device pointer. This need not be a real device - it is
813*4882a593Smuzhiyun  *		common for it to just be a local variable with its ->dev
814*4882a593Smuzhiyun  *		member (i.e. @dev->dev) set to the parent device and
815*4882a593Smuzhiyun  *		dev->portnr set to the port number on the hub (1=first)
816*4882a593Smuzhiyun  * @do_read:	true to read the device descriptor before an address is set
817*4882a593Smuzhiyun  *		(should be false for XHCI buses, true otherwise)
818*4882a593Smuzhiyun  * @parent:	Parent device (either UCLASS_USB or UCLASS_USB_HUB)
819*4882a593Smuzhiyun  * @return 0 if OK, -ve on error */
820*4882a593Smuzhiyun int usb_setup_device(struct usb_device *dev, bool do_read,
821*4882a593Smuzhiyun 		     struct usb_device *parent);
822*4882a593Smuzhiyun 
823*4882a593Smuzhiyun /**
824*4882a593Smuzhiyun  * usb_hub_is_root_hub() - Test whether a hub device is root hub or not
825*4882a593Smuzhiyun  *
826*4882a593Smuzhiyun  * @hub:	USB hub device to test
827*4882a593Smuzhiyun  * @return:	true if the hub device is root hub, false otherwise.
828*4882a593Smuzhiyun  */
829*4882a593Smuzhiyun bool usb_hub_is_root_hub(struct udevice *hub);
830*4882a593Smuzhiyun 
831*4882a593Smuzhiyun /**
832*4882a593Smuzhiyun  * usb_hub_scan() - Scan a hub and find its devices
833*4882a593Smuzhiyun  *
834*4882a593Smuzhiyun  * @hub:	Hub device to scan
835*4882a593Smuzhiyun  */
836*4882a593Smuzhiyun int usb_hub_scan(struct udevice *hub);
837*4882a593Smuzhiyun 
838*4882a593Smuzhiyun /**
839*4882a593Smuzhiyun  * usb_scan_device() - Scan a device on a bus
840*4882a593Smuzhiyun  *
841*4882a593Smuzhiyun  * Scan a device on a bus. It has already been detected and is ready to
842*4882a593Smuzhiyun  * be enumerated. This may be either the root hub (@parent is a bus) or a
843*4882a593Smuzhiyun  * normal device (@parent is a hub)
844*4882a593Smuzhiyun  *
845*4882a593Smuzhiyun  * @parent:	Parent device
846*4882a593Smuzhiyun  * @port:	Hub port number (numbered from 1)
847*4882a593Smuzhiyun  * @speed:	USB speed to use for this device
848*4882a593Smuzhiyun  * @devp:	Returns pointer to device if all is well
849*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
850*4882a593Smuzhiyun  */
851*4882a593Smuzhiyun int usb_scan_device(struct udevice *parent, int port,
852*4882a593Smuzhiyun 		    enum usb_device_speed speed, struct udevice **devp);
853*4882a593Smuzhiyun 
854*4882a593Smuzhiyun /**
855*4882a593Smuzhiyun  * usb_get_bus() - Find the bus for a device
856*4882a593Smuzhiyun  *
857*4882a593Smuzhiyun  * Search up through parents to find the bus this device is connected to. This
858*4882a593Smuzhiyun  * will be a device with uclass UCLASS_USB.
859*4882a593Smuzhiyun  *
860*4882a593Smuzhiyun  * @dev:	Device to check
861*4882a593Smuzhiyun  * @return The bus, or NULL if not found (this indicates a critical error in
862*4882a593Smuzhiyun  *	the USB stack
863*4882a593Smuzhiyun  */
864*4882a593Smuzhiyun struct udevice *usb_get_bus(struct udevice *dev);
865*4882a593Smuzhiyun 
866*4882a593Smuzhiyun /**
867*4882a593Smuzhiyun  * usb_select_config() - Set up a device ready for use
868*4882a593Smuzhiyun  *
869*4882a593Smuzhiyun  * This function assumes that the device already has an address and a driver
870*4882a593Smuzhiyun  * bound, and is ready to be set up.
871*4882a593Smuzhiyun  *
872*4882a593Smuzhiyun  * This re-reads the device and configuration descriptors and sets the
873*4882a593Smuzhiyun  * configuration
874*4882a593Smuzhiyun  *
875*4882a593Smuzhiyun  * @dev:	Device to set up
876*4882a593Smuzhiyun  */
877*4882a593Smuzhiyun int usb_select_config(struct usb_device *dev);
878*4882a593Smuzhiyun 
879*4882a593Smuzhiyun /**
880*4882a593Smuzhiyun  * usb_child_pre_probe() - Pre-probe function for USB devices
881*4882a593Smuzhiyun  *
882*4882a593Smuzhiyun  * This is called on all children of hubs and USB controllers (i.e. UCLASS_USB
883*4882a593Smuzhiyun  * and UCLASS_USB_HUB) when a new device is about to be probed. It sets up the
884*4882a593Smuzhiyun  * device from the saved platform data and calls usb_select_config() to
885*4882a593Smuzhiyun  * finish set up.
886*4882a593Smuzhiyun  *
887*4882a593Smuzhiyun  * Once this is done, the device's normal driver can take over, knowing the
888*4882a593Smuzhiyun  * device is accessible on the USB bus.
889*4882a593Smuzhiyun  *
890*4882a593Smuzhiyun  * This function is for use only by the internal USB stack.
891*4882a593Smuzhiyun  *
892*4882a593Smuzhiyun  * @dev:	Device to set up
893*4882a593Smuzhiyun  */
894*4882a593Smuzhiyun int usb_child_pre_probe(struct udevice *dev);
895*4882a593Smuzhiyun 
896*4882a593Smuzhiyun struct ehci_ctrl;
897*4882a593Smuzhiyun 
898*4882a593Smuzhiyun /**
899*4882a593Smuzhiyun  * usb_setup_ehci_gadget() - Set up a USB device as a gadget
900*4882a593Smuzhiyun  *
901*4882a593Smuzhiyun  * TODO(sjg@chromium.org): Tidy this up when USB gadgets can use driver model
902*4882a593Smuzhiyun  *
903*4882a593Smuzhiyun  * This provides a way to tell a controller to start up as a USB device
904*4882a593Smuzhiyun  * instead of as a host. It is untested.
905*4882a593Smuzhiyun  */
906*4882a593Smuzhiyun int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp);
907*4882a593Smuzhiyun 
908*4882a593Smuzhiyun /**
909*4882a593Smuzhiyun  * usb_stor_reset() - Prepare to scan USB storage devices
910*4882a593Smuzhiyun  *
911*4882a593Smuzhiyun  * Empty the list of USB storage devices in preparation for scanning them.
912*4882a593Smuzhiyun  * This must be called before a USB scan.
913*4882a593Smuzhiyun  */
914*4882a593Smuzhiyun void usb_stor_reset(void);
915*4882a593Smuzhiyun 
916*4882a593Smuzhiyun #else /* !CONFIG_IS_ENABLED(DM_USB) */
917*4882a593Smuzhiyun 
918*4882a593Smuzhiyun struct usb_device *usb_get_dev_index(int index);
919*4882a593Smuzhiyun 
920*4882a593Smuzhiyun #endif
921*4882a593Smuzhiyun 
922*4882a593Smuzhiyun bool usb_device_has_child_on_port(struct usb_device *parent, int port);
923*4882a593Smuzhiyun 
924*4882a593Smuzhiyun int usb_hub_probe(struct usb_device *dev, int ifnum);
925*4882a593Smuzhiyun void usb_hub_reset(void);
926*4882a593Smuzhiyun 
927*4882a593Smuzhiyun /*
928*4882a593Smuzhiyun  * usb_find_usb2_hub_address_port() - Get hub address and port for TT setting
929*4882a593Smuzhiyun  *
930*4882a593Smuzhiyun  * Searches for the first HS hub above the given device. If a
931*4882a593Smuzhiyun  * HS hub is found, the hub address and the port the device is
932*4882a593Smuzhiyun  * connected to is return, as required for SPLIT transactions
933*4882a593Smuzhiyun  *
934*4882a593Smuzhiyun  * @param: udev full speed or low speed device
935*4882a593Smuzhiyun  */
936*4882a593Smuzhiyun void usb_find_usb2_hub_address_port(struct usb_device *udev,
937*4882a593Smuzhiyun 				    uint8_t *hub_address, uint8_t *hub_port);
938*4882a593Smuzhiyun 
939*4882a593Smuzhiyun /**
940*4882a593Smuzhiyun  * usb_alloc_new_device() - Allocate a new device
941*4882a593Smuzhiyun  *
942*4882a593Smuzhiyun  * @devp: returns a pointer of a new device structure. With driver model this
943*4882a593Smuzhiyun  *		is a device pointer, but with legacy USB this pointer is
944*4882a593Smuzhiyun  *		driver-specific.
945*4882a593Smuzhiyun  * @return 0 if OK, -ENOSPC if we have found out of room for new devices
946*4882a593Smuzhiyun  */
947*4882a593Smuzhiyun int usb_alloc_new_device(struct udevice *controller, struct usb_device **devp);
948*4882a593Smuzhiyun 
949*4882a593Smuzhiyun /**
950*4882a593Smuzhiyun  * usb_free_device() - Free a partially-inited device
951*4882a593Smuzhiyun  *
952*4882a593Smuzhiyun  * This is an internal function. It is used to reverse the action of
953*4882a593Smuzhiyun  * usb_alloc_new_device() when we hit a problem during init.
954*4882a593Smuzhiyun  */
955*4882a593Smuzhiyun void usb_free_device(struct udevice *controller);
956*4882a593Smuzhiyun 
957*4882a593Smuzhiyun int usb_new_device(struct usb_device *dev);
958*4882a593Smuzhiyun 
959*4882a593Smuzhiyun int usb_alloc_device(struct usb_device *dev);
960*4882a593Smuzhiyun 
961*4882a593Smuzhiyun /**
962*4882a593Smuzhiyun  * usb_update_hub_device() - Update HCD's internal representation of hub
963*4882a593Smuzhiyun  *
964*4882a593Smuzhiyun  * After a hub descriptor is fetched, notify HCD so that its internal
965*4882a593Smuzhiyun  * representation of this hub can be updated.
966*4882a593Smuzhiyun  *
967*4882a593Smuzhiyun  * @dev:		Hub device
968*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
969*4882a593Smuzhiyun  */
970*4882a593Smuzhiyun int usb_update_hub_device(struct usb_device *dev);
971*4882a593Smuzhiyun 
972*4882a593Smuzhiyun /**
973*4882a593Smuzhiyun  * usb_get_max_xfer_size() - Get HCD's maximum transfer bytes
974*4882a593Smuzhiyun  *
975*4882a593Smuzhiyun  * The HCD may have limitation on the maximum bytes to be transferred
976*4882a593Smuzhiyun  * in a USB transfer. USB class driver needs to be aware of this.
977*4882a593Smuzhiyun  *
978*4882a593Smuzhiyun  * @dev:		USB device
979*4882a593Smuzhiyun  * @size:		maximum transfer bytes
980*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
981*4882a593Smuzhiyun  */
982*4882a593Smuzhiyun int usb_get_max_xfer_size(struct usb_device *dev, size_t *size);
983*4882a593Smuzhiyun 
984*4882a593Smuzhiyun /**
985*4882a593Smuzhiyun  * usb_emul_setup_device() - Set up a new USB device emulation
986*4882a593Smuzhiyun  *
987*4882a593Smuzhiyun  * This is normally called when a new emulation device is bound. It tells
988*4882a593Smuzhiyun  * the USB emulation uclass about the features of the emulator.
989*4882a593Smuzhiyun  *
990*4882a593Smuzhiyun  * @dev:		Emulation device
991*4882a593Smuzhiyun  * @strings:		List of USB string descriptors, terminated by a NULL
992*4882a593Smuzhiyun  *			entry
993*4882a593Smuzhiyun  * @desc_list:		List of points or USB descriptors, terminated by NULL.
994*4882a593Smuzhiyun  *			The first entry must be struct usb_device_descriptor,
995*4882a593Smuzhiyun  *			and others follow on after that.
996*4882a593Smuzhiyun  * @return 0 if OK, -ENOSYS if not implemented, other -ve on error
997*4882a593Smuzhiyun  */
998*4882a593Smuzhiyun int usb_emul_setup_device(struct udevice *dev, struct usb_string *strings,
999*4882a593Smuzhiyun 			  void **desc_list);
1000*4882a593Smuzhiyun 
1001*4882a593Smuzhiyun /**
1002*4882a593Smuzhiyun  * usb_emul_control() - Send a control packet to an emulator
1003*4882a593Smuzhiyun  *
1004*4882a593Smuzhiyun  * @emul:	Emulator device
1005*4882a593Smuzhiyun  * @udev:	USB device (which the emulator is causing to appear)
1006*4882a593Smuzhiyun  * See struct dm_usb_ops for details on other parameters
1007*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
1008*4882a593Smuzhiyun  */
1009*4882a593Smuzhiyun int usb_emul_control(struct udevice *emul, struct usb_device *udev,
1010*4882a593Smuzhiyun 		     unsigned long pipe, void *buffer, int length,
1011*4882a593Smuzhiyun 		     struct devrequest *setup);
1012*4882a593Smuzhiyun 
1013*4882a593Smuzhiyun /**
1014*4882a593Smuzhiyun  * usb_emul_bulk() - Send a bulk packet to an emulator
1015*4882a593Smuzhiyun  *
1016*4882a593Smuzhiyun  * @emul:	Emulator device
1017*4882a593Smuzhiyun  * @udev:	USB device (which the emulator is causing to appear)
1018*4882a593Smuzhiyun  * See struct dm_usb_ops for details on other parameters
1019*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
1020*4882a593Smuzhiyun  */
1021*4882a593Smuzhiyun int usb_emul_bulk(struct udevice *emul, struct usb_device *udev,
1022*4882a593Smuzhiyun 		  unsigned long pipe, void *buffer, int length);
1023*4882a593Smuzhiyun 
1024*4882a593Smuzhiyun /**
1025*4882a593Smuzhiyun  * usb_emul_int() - Send an interrupt packet to an emulator
1026*4882a593Smuzhiyun  *
1027*4882a593Smuzhiyun  * @emul:	Emulator device
1028*4882a593Smuzhiyun  * @udev:	USB device (which the emulator is causing to appear)
1029*4882a593Smuzhiyun  * See struct dm_usb_ops for details on other parameters
1030*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
1031*4882a593Smuzhiyun  */
1032*4882a593Smuzhiyun int usb_emul_int(struct udevice *emul, struct usb_device *udev,
1033*4882a593Smuzhiyun 		  unsigned long pipe, void *buffer, int length, int interval,
1034*4882a593Smuzhiyun 		  bool nonblock);
1035*4882a593Smuzhiyun 
1036*4882a593Smuzhiyun /**
1037*4882a593Smuzhiyun  * usb_emul_find() - Find an emulator for a particular device
1038*4882a593Smuzhiyun  *
1039*4882a593Smuzhiyun  * Check @pipe and @port1 to find a device number on bus @bus and return it.
1040*4882a593Smuzhiyun  *
1041*4882a593Smuzhiyun  * @bus:	USB bus (controller)
1042*4882a593Smuzhiyun  * @pipe:	Describes pipe being used, and includes the device number
1043*4882a593Smuzhiyun  * @port1:	Describes port number on the parent hub
1044*4882a593Smuzhiyun  * @emulp:	Returns pointer to emulator, or NULL if not found
1045*4882a593Smuzhiyun  * @return 0 if found, -ve on error
1046*4882a593Smuzhiyun  */
1047*4882a593Smuzhiyun int usb_emul_find(struct udevice *bus, ulong pipe, int port1,
1048*4882a593Smuzhiyun 		  struct udevice **emulp);
1049*4882a593Smuzhiyun 
1050*4882a593Smuzhiyun /**
1051*4882a593Smuzhiyun  * usb_emul_find_for_dev() - Find an emulator for a particular device
1052*4882a593Smuzhiyun  *
1053*4882a593Smuzhiyun  * @bus:	USB bus (controller)
1054*4882a593Smuzhiyun  * @dev:	USB device to check
1055*4882a593Smuzhiyun  * @emulp:	Returns pointer to emulator, or NULL if not found
1056*4882a593Smuzhiyun  * @return 0 if found, -ve on error
1057*4882a593Smuzhiyun  */
1058*4882a593Smuzhiyun int usb_emul_find_for_dev(struct udevice *dev, struct udevice **emulp);
1059*4882a593Smuzhiyun 
1060*4882a593Smuzhiyun /**
1061*4882a593Smuzhiyun  * usb_emul_find_descriptor() - Find a USB descriptor of a particular device
1062*4882a593Smuzhiyun  *
1063*4882a593Smuzhiyun  * @ptr:	a pointer to a list of USB descriptor pointers
1064*4882a593Smuzhiyun  * @type:	type of USB descriptor to find
1065*4882a593Smuzhiyun  * @index:	if @type is USB_DT_CONFIG, this is the configuration value
1066*4882a593Smuzhiyun  * @return a pointer to the USB descriptor found, NULL if not found
1067*4882a593Smuzhiyun  */
1068*4882a593Smuzhiyun struct usb_generic_descriptor **usb_emul_find_descriptor(
1069*4882a593Smuzhiyun 		struct usb_generic_descriptor **ptr, int type, int index);
1070*4882a593Smuzhiyun 
1071*4882a593Smuzhiyun /**
1072*4882a593Smuzhiyun  * usb_show_tree() - show the USB device tree
1073*4882a593Smuzhiyun  *
1074*4882a593Smuzhiyun  * This shows a list of active USB devices along with basic information about
1075*4882a593Smuzhiyun  * each.
1076*4882a593Smuzhiyun  */
1077*4882a593Smuzhiyun void usb_show_tree(void);
1078*4882a593Smuzhiyun 
1079*4882a593Smuzhiyun #endif /*_USB_H_ */
1080