otg.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/usb/phy.h>
  11. struct usb_otg {
  12. u8 default_a;
  13. struct usb_phy *phy;
  14. struct usb_bus *host;
  15. struct usb_gadget *gadget;
  16. /* bind/unbind the host controller */
  17. int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
  18. /* bind/unbind the peripheral controller */
  19. int (*set_peripheral)(struct usb_otg *otg,
  20. struct usb_gadget *gadget);
  21. /* effective for A-peripheral, ignored for B devices */
  22. int (*set_vbus)(struct usb_otg *otg, bool enabled);
  23. /* for B devices only: start session with A-Host */
  24. int (*start_srp)(struct usb_otg *otg);
  25. /* start or continue HNP role switch */
  26. int (*start_hnp)(struct usb_otg *otg);
  27. };
  28. #ifdef CONFIG_USB_OTG_UTILS
  29. extern const char *otg_state_string(enum usb_otg_state state);
  30. #else
  31. static inline const char *otg_state_string(enum usb_otg_state state)
  32. {
  33. return NULL;
  34. }
  35. #endif
  36. /* Context: can sleep */
  37. static inline int
  38. otg_start_hnp(struct usb_otg *otg)
  39. {
  40. if (otg && otg->start_hnp)
  41. return otg->start_hnp(otg);
  42. return -ENOTSUPP;
  43. }
  44. /* Context: can sleep */
  45. static inline int
  46. otg_set_vbus(struct usb_otg *otg, bool enabled)
  47. {
  48. if (otg && otg->set_vbus)
  49. return otg->set_vbus(otg, enabled);
  50. return -ENOTSUPP;
  51. }
  52. /* for HCDs */
  53. static inline int
  54. otg_set_host(struct usb_otg *otg, struct usb_bus *host)
  55. {
  56. if (otg && otg->set_host)
  57. return otg->set_host(otg, host);
  58. return -ENOTSUPP;
  59. }
  60. /* for usb peripheral controller drivers */
  61. /* Context: can sleep */
  62. static inline int
  63. otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
  64. {
  65. if (otg && otg->set_peripheral)
  66. return otg->set_peripheral(otg, periph);
  67. return -ENOTSUPP;
  68. }
  69. static inline int
  70. otg_start_srp(struct usb_otg *otg)
  71. {
  72. if (otg && otg->start_srp)
  73. return otg->start_srp(otg);
  74. return -ENOTSUPP;
  75. }
  76. /* for OTG controller drivers (and maybe other stuff) */
  77. extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
  78. #endif /* __LINUX_USB_OTG_H */