otg.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* USB OTG (On The Go) defines */
  2. /*
  3. *
  4. * These APIs may be used between USB controllers. USB device drivers
  5. * (for either host or peripheral roles) don't use these calls; they
  6. * continue to use just usb_device and usb_gadget.
  7. */
  8. #ifndef __LINUX_USB_OTG_H
  9. #define __LINUX_USB_OTG_H
  10. #include <linux/phy/phy.h>
  11. #include <linux/usb/phy.h>
  12. struct usb_otg {
  13. u8 default_a;
  14. struct phy *phy;
  15. /* old usb_phy interface */
  16. struct usb_phy *usb_phy;
  17. struct usb_bus *host;
  18. struct usb_gadget *gadget;
  19. enum usb_otg_state state;
  20. /* bind/unbind the host controller */
  21. int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
  22. /* bind/unbind the peripheral controller */
  23. int (*set_peripheral)(struct usb_otg *otg,
  24. struct usb_gadget *gadget);
  25. /* effective for A-peripheral, ignored for B devices */
  26. int (*set_vbus)(struct usb_otg *otg, bool enabled);
  27. /* for B devices only: start session with A-Host */
  28. int (*start_srp)(struct usb_otg *otg);
  29. /* start or continue HNP role switch */
  30. int (*start_hnp)(struct usb_otg *otg);
  31. };
  32. /**
  33. * struct usb_otg_caps - describes the otg capabilities of the device
  34. * @otg_rev: The OTG revision number the device is compliant with, it's
  35. * in binary-coded decimal (i.e. 2.0 is 0200H).
  36. * @hnp_support: Indicates if the device supports HNP.
  37. * @srp_support: Indicates if the device supports SRP.
  38. * @adp_support: Indicates if the device supports ADP.
  39. */
  40. struct usb_otg_caps {
  41. u16 otg_rev;
  42. bool hnp_support;
  43. bool srp_support;
  44. bool adp_support;
  45. };
  46. extern const char *usb_otg_state_string(enum usb_otg_state state);
  47. /* Context: can sleep */
  48. static inline int
  49. otg_start_hnp(struct usb_otg *otg)
  50. {
  51. if (otg && otg->start_hnp)
  52. return otg->start_hnp(otg);
  53. return -ENOTSUPP;
  54. }
  55. /* Context: can sleep */
  56. static inline int
  57. otg_set_vbus(struct usb_otg *otg, bool enabled)
  58. {
  59. if (otg && otg->set_vbus)
  60. return otg->set_vbus(otg, enabled);
  61. return -ENOTSUPP;
  62. }
  63. /* for HCDs */
  64. static inline int
  65. otg_set_host(struct usb_otg *otg, struct usb_bus *host)
  66. {
  67. if (otg && otg->set_host)
  68. return otg->set_host(otg, host);
  69. return -ENOTSUPP;
  70. }
  71. /* for usb peripheral controller drivers */
  72. /* Context: can sleep */
  73. static inline int
  74. otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
  75. {
  76. if (otg && otg->set_peripheral)
  77. return otg->set_peripheral(otg, periph);
  78. return -ENOTSUPP;
  79. }
  80. static inline int
  81. otg_start_srp(struct usb_otg *otg)
  82. {
  83. if (otg && otg->start_srp)
  84. return otg->start_srp(otg);
  85. return -ENOTSUPP;
  86. }
  87. /* for OTG controller drivers (and maybe other stuff) */
  88. extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
  89. enum usb_dr_mode {
  90. USB_DR_MODE_UNKNOWN,
  91. USB_DR_MODE_HOST,
  92. USB_DR_MODE_PERIPHERAL,
  93. USB_DR_MODE_OTG,
  94. };
  95. /**
  96. * usb_get_dr_mode - Get dual role mode for given device
  97. * @dev: Pointer to the given device
  98. *
  99. * The function gets phy interface string from property 'dr_mode',
  100. * and returns the correspondig enum usb_dr_mode
  101. */
  102. extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
  103. #endif /* __LINUX_USB_OTG_H */