otg.h 3.0 KB

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