1 #ifndef __USB_COMPAT_H__
2 #define __USB_COMPAT_H__
3 
4 #include "usb.h"
5 
6 struct udevice;
7 
8 struct usb_hcd {
9 	void *hcd_priv;
10 };
11 
12 struct usb_host_endpoint {
13 	struct usb_endpoint_descriptor		desc;
14 	struct list_head urb_list;
15 	void *hcpriv;
16 };
17 
18 /*
19  * urb->transfer_flags:
20  *
21  * Note: URB_DIR_IN/OUT is automatically set in usb_submit_urb().
22  */
23 #define URB_SHORT_NOT_OK	0x0001	/* report short reads as errors */
24 #define URB_ZERO_PACKET		0x0040	/* Finish bulk OUT with short packet */
25 
26 struct urb;
27 
28 typedef void (*usb_complete_t)(struct urb *);
29 
30 struct urb {
31 	void *hcpriv;			/* private data for host controller */
32 	struct list_head urb_list;	/* list head for use by the urb's
33 					 * current owner */
34 	struct usb_device *dev;		/* (in) pointer to associated device */
35 	struct usb_host_endpoint *ep;	/* (internal) pointer to endpoint */
36 	unsigned int pipe;		/* (in) pipe information */
37 	int status;			/* (return) non-ISO status */
38 	unsigned int transfer_flags;	/* (in) URB_SHORT_NOT_OK | ...*/
39 	void *transfer_buffer;		/* (in) associated data buffer */
40 	dma_addr_t transfer_dma;	/* (in) dma addr for transfer_buffer */
41 	u32 transfer_buffer_length;	/* (in) data buffer length */
42 	u32 actual_length;		/* (return) actual transfer length */
43 	unsigned char *setup_packet;	/* (in) setup packet (control only) */
44 	int start_frame;		/* (modify) start frame (ISO) */
45 	usb_complete_t complete;	/* (in) completion routine */
46 };
47 
48 #define usb_hcd_link_urb_to_ep(hcd, urb)	({		\
49 	int ret = 0;						\
50 	list_add_tail(&urb->urb_list, &urb->ep->urb_list);	\
51 	ret; })
52 #define usb_hcd_unlink_urb_from_ep(hcd, urb)	list_del_init(&urb->urb_list)
53 #define usb_hcd_check_unlink_urb(hdc, urb, status)	0
54 
usb_hcd_giveback_urb(struct usb_hcd * hcd,struct urb * urb,int status)55 static inline void usb_hcd_giveback_urb(struct usb_hcd *hcd,
56 					struct urb *urb,
57 					int status)
58 {
59 	urb->status = status;
60 	if (urb->complete)
61 		urb->complete(urb);
62 }
63 
usb_hcd_unmap_urb_for_dma(struct usb_hcd * hcd,struct urb * urb)64 static inline int usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd,
65 					struct urb *urb)
66 {
67 	/* TODO: add cache invalidation here */
68 	return 0;
69 }
70 
71 /**
72  * usb_dev_get_parent() - Get the parent of a USB device
73  *
74  * @udev: USB struct containing information about the device
75  * @return associated device for which udev == dev_get_parent_priv(dev)
76  */
77 struct usb_device *usb_dev_get_parent(struct usb_device *udev);
78 
79 #endif /* __USB_COMPAT_H__ */
80