otg.h 2.1 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. extern const char *usb_otg_state_string(enum usb_otg_state state);
  29. /* Context: can sleep */
  30. static inline int
  31. otg_start_hnp(struct usb_otg *otg)
  32. {
  33. if (otg && otg->start_hnp)
  34. return otg->start_hnp(otg);
  35. return -ENOTSUPP;
  36. }
  37. /* Context: can sleep */
  38. static inline int
  39. otg_set_vbus(struct usb_otg *otg, bool enabled)
  40. {
  41. if (otg && otg->set_vbus)
  42. return otg->set_vbus(otg, enabled);
  43. return -ENOTSUPP;
  44. }
  45. /* for HCDs */
  46. static inline int
  47. otg_set_host(struct usb_otg *otg, struct usb_bus *host)
  48. {
  49. if (otg && otg->set_host)
  50. return otg->set_host(otg, host);
  51. return -ENOTSUPP;
  52. }
  53. /* for usb peripheral controller drivers */
  54. /* Context: can sleep */
  55. static inline int
  56. otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
  57. {
  58. if (otg && otg->set_peripheral)
  59. return otg->set_peripheral(otg, periph);
  60. return -ENOTSUPP;
  61. }
  62. static inline int
  63. otg_start_srp(struct usb_otg *otg)
  64. {
  65. if (otg && otg->start_srp)
  66. return otg->start_srp(otg);
  67. return -ENOTSUPP;
  68. }
  69. /* for OTG controller drivers (and maybe other stuff) */
  70. extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
  71. enum usb_dr_mode {
  72. USB_DR_MODE_UNKNOWN,
  73. USB_DR_MODE_HOST,
  74. USB_DR_MODE_PERIPHERAL,
  75. USB_DR_MODE_OTG,
  76. };
  77. #endif /* __LINUX_USB_OTG_H */