otg.h 3.1 KB

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