xref: /openbmc/u-boot/drivers/usb/musb-new/usb-compat.h (revision 67cf22cbdef8c62ffa28b4caf935825fe410c68d)
1eb81955bSIlya Yanok #ifndef __USB_COMPAT_H__
2eb81955bSIlya Yanok #define __USB_COMPAT_H__
3eb81955bSIlya Yanok 
4e740ca3cSHans de Goede #include <dm.h>
5eb81955bSIlya Yanok #include "usb.h"
6eb81955bSIlya Yanok 
7eb81955bSIlya Yanok struct usb_hcd {
8eb81955bSIlya Yanok 	void *hcd_priv;
9eb81955bSIlya Yanok };
10eb81955bSIlya Yanok 
11eb81955bSIlya Yanok struct usb_host_endpoint {
12eb81955bSIlya Yanok 	struct usb_endpoint_descriptor		desc;
13eb81955bSIlya Yanok 	struct list_head urb_list;
14eb81955bSIlya Yanok 	void *hcpriv;
15eb81955bSIlya Yanok };
16eb81955bSIlya Yanok 
17eb81955bSIlya Yanok /*
18eb81955bSIlya Yanok  * urb->transfer_flags:
19eb81955bSIlya Yanok  *
20eb81955bSIlya Yanok  * Note: URB_DIR_IN/OUT is automatically set in usb_submit_urb().
21eb81955bSIlya Yanok  */
22eb81955bSIlya Yanok #define URB_SHORT_NOT_OK	0x0001	/* report short reads as errors */
23eb81955bSIlya Yanok #define URB_ZERO_PACKET		0x0040	/* Finish bulk OUT with short packet */
24eb81955bSIlya Yanok 
25eb81955bSIlya Yanok struct urb;
26eb81955bSIlya Yanok 
27eb81955bSIlya Yanok typedef void (*usb_complete_t)(struct urb *);
28eb81955bSIlya Yanok 
29eb81955bSIlya Yanok struct urb {
30eb81955bSIlya Yanok 	void *hcpriv;			/* private data for host controller */
31eb81955bSIlya Yanok 	struct list_head urb_list;	/* list head for use by the urb's
32eb81955bSIlya Yanok 					 * current owner */
33eb81955bSIlya Yanok 	struct usb_device *dev;		/* (in) pointer to associated device */
34eb81955bSIlya Yanok 	struct usb_host_endpoint *ep;	/* (internal) pointer to endpoint */
35eb81955bSIlya Yanok 	unsigned int pipe;		/* (in) pipe information */
36eb81955bSIlya Yanok 	int status;			/* (return) non-ISO status */
37eb81955bSIlya Yanok 	unsigned int transfer_flags;	/* (in) URB_SHORT_NOT_OK | ...*/
38eb81955bSIlya Yanok 	void *transfer_buffer;		/* (in) associated data buffer */
39eb81955bSIlya Yanok 	dma_addr_t transfer_dma;	/* (in) dma addr for transfer_buffer */
40eb81955bSIlya Yanok 	u32 transfer_buffer_length;	/* (in) data buffer length */
41eb81955bSIlya Yanok 	u32 actual_length;		/* (return) actual transfer length */
42eb81955bSIlya Yanok 	unsigned char *setup_packet;	/* (in) setup packet (control only) */
43eb81955bSIlya Yanok 	int start_frame;		/* (modify) start frame (ISO) */
44eb81955bSIlya Yanok 	usb_complete_t complete;	/* (in) completion routine */
45eb81955bSIlya Yanok };
46eb81955bSIlya Yanok 
47eb81955bSIlya Yanok #define usb_hcd_link_urb_to_ep(hcd, urb)	({		\
48eb81955bSIlya Yanok 	int ret = 0;						\
49eb81955bSIlya Yanok 	list_add_tail(&urb->urb_list, &urb->ep->urb_list);	\
50eb81955bSIlya Yanok 	ret; })
51eb81955bSIlya Yanok #define usb_hcd_unlink_urb_from_ep(hcd, urb)	list_del_init(&urb->urb_list)
52b918a0c6SHans de Goede #define usb_hcd_check_unlink_urb(hdc, urb, status)	0
53eb81955bSIlya Yanok 
usb_hcd_giveback_urb(struct usb_hcd * hcd,struct urb * urb,int status)54eb81955bSIlya Yanok static inline void usb_hcd_giveback_urb(struct usb_hcd *hcd,
55eb81955bSIlya Yanok 					struct urb *urb,
56eb81955bSIlya Yanok 					int status)
57eb81955bSIlya Yanok {
58eb81955bSIlya Yanok 	urb->status = status;
59eb81955bSIlya Yanok 	if (urb->complete)
60eb81955bSIlya Yanok 		urb->complete(urb);
61eb81955bSIlya Yanok }
62eb81955bSIlya Yanok 
usb_hcd_unmap_urb_for_dma(struct usb_hcd * hcd,struct urb * urb)63eb81955bSIlya Yanok static inline int usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd,
64eb81955bSIlya Yanok 					struct urb *urb)
65eb81955bSIlya Yanok {
66eb81955bSIlya Yanok 	/* TODO: add cache invalidation here */
67eb81955bSIlya Yanok 	return 0;
68eb81955bSIlya Yanok }
69eb81955bSIlya Yanok 
70*fd09c205SSven Schwermer #if CONFIG_IS_ENABLED(DM_USB)
usb_dev_get_parent(struct usb_device * udev)71e740ca3cSHans de Goede static inline struct usb_device *usb_dev_get_parent(struct usb_device *udev)
72e740ca3cSHans de Goede {
73e740ca3cSHans de Goede 	struct udevice *parent = udev->dev->parent;
74e740ca3cSHans de Goede 
75e740ca3cSHans de Goede 	/*
76e740ca3cSHans de Goede 	 * When called from usb-uclass.c: usb_scan_device() udev->dev points
77e740ca3cSHans de Goede 	 * to the parent udevice, not the actual udevice belonging to the
78e740ca3cSHans de Goede 	 * udev as the device is not instantiated yet.
79e740ca3cSHans de Goede 	 *
80e740ca3cSHans de Goede 	 * If dev is an usb-bus, then we are called from usb_scan_device() for
81e740ca3cSHans de Goede 	 * an usb-device plugged directly into the root port, return NULL.
82e740ca3cSHans de Goede 	 */
83e740ca3cSHans de Goede 	if (device_get_uclass_id(udev->dev) == UCLASS_USB)
84e740ca3cSHans de Goede 		return NULL;
85e740ca3cSHans de Goede 
86e740ca3cSHans de Goede 	/*
87e740ca3cSHans de Goede 	 * If these 2 are not the same we are being called from
88e740ca3cSHans de Goede 	 * usb_scan_device() and udev itself is the parent.
89e740ca3cSHans de Goede 	 */
90bcbe3d15SSimon Glass 	if (dev_get_parent_priv(udev->dev) != udev)
91e740ca3cSHans de Goede 		return udev;
92e740ca3cSHans de Goede 
93e740ca3cSHans de Goede 	/* We are being called normally, use the parent pointer */
94e740ca3cSHans de Goede 	if (device_get_uclass_id(parent) == UCLASS_USB_HUB)
95bcbe3d15SSimon Glass 		return dev_get_parent_priv(parent);
96e740ca3cSHans de Goede 
97e740ca3cSHans de Goede 	return NULL;
98e740ca3cSHans de Goede }
99e740ca3cSHans de Goede #else
usb_dev_get_parent(struct usb_device * dev)100e740ca3cSHans de Goede static inline struct usb_device *usb_dev_get_parent(struct usb_device *dev)
101e740ca3cSHans de Goede {
102e740ca3cSHans de Goede 	return dev->parent;
103e740ca3cSHans de Goede }
104e740ca3cSHans de Goede #endif
105e740ca3cSHans de Goede 
106eb81955bSIlya Yanok #endif /* __USB_COMPAT_H__ */
107