usb-compat.h 3.0 KB

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