otg.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. /* OTG defines lots of enumeration states before device reset */
  11. enum usb_otg_state {
  12. OTG_STATE_UNDEFINED = 0,
  13. /* single-role peripheral, and dual-role default-b */
  14. OTG_STATE_B_IDLE,
  15. OTG_STATE_B_SRP_INIT,
  16. OTG_STATE_B_PERIPHERAL,
  17. /* extra dual-role default-b states */
  18. OTG_STATE_B_WAIT_ACON,
  19. OTG_STATE_B_HOST,
  20. /* dual-role default-a */
  21. OTG_STATE_A_IDLE,
  22. OTG_STATE_A_WAIT_VRISE,
  23. OTG_STATE_A_WAIT_BCON,
  24. OTG_STATE_A_HOST,
  25. OTG_STATE_A_SUSPEND,
  26. OTG_STATE_A_PERIPHERAL,
  27. OTG_STATE_A_WAIT_VFALL,
  28. OTG_STATE_A_VBUS_ERR,
  29. };
  30. /*
  31. * the otg driver needs to interact with both device side and host side
  32. * usb controllers. it decides which controller is active at a given
  33. * moment, using the transceiver, ID signal, HNP and sometimes static
  34. * configuration information (including "board isn't wired for otg").
  35. */
  36. struct otg_transceiver {
  37. struct device *dev;
  38. const char *label;
  39. u8 default_a;
  40. enum usb_otg_state state;
  41. struct usb_bus *host;
  42. struct usb_gadget *gadget;
  43. /* to pass extra port status to the root hub */
  44. u16 port_status;
  45. u16 port_change;
  46. /* bind/unbind the host controller */
  47. int (*set_host)(struct otg_transceiver *otg,
  48. struct usb_bus *host);
  49. /* bind/unbind the peripheral controller */
  50. int (*set_peripheral)(struct otg_transceiver *otg,
  51. struct usb_gadget *gadget);
  52. /* effective for B devices, ignored for A-peripheral */
  53. int (*set_power)(struct otg_transceiver *otg,
  54. unsigned mA);
  55. /* for non-OTG B devices: set transceiver into suspend mode */
  56. int (*set_suspend)(struct otg_transceiver *otg,
  57. int suspend);
  58. /* for B devices only: start session with A-Host */
  59. int (*start_srp)(struct otg_transceiver *otg);
  60. /* start or continue HNP role switch */
  61. int (*start_hnp)(struct otg_transceiver *otg);
  62. };
  63. /* for board-specific init logic */
  64. extern int otg_set_transceiver(struct otg_transceiver *);
  65. #ifdef CONFIG_NOP_USB_XCEIV
  66. extern void usb_nop_xceiv_register(void);
  67. extern void usb_nop_xceiv_unregister(void);
  68. #endif
  69. /* for usb host and peripheral controller drivers */
  70. extern struct otg_transceiver *otg_get_transceiver(void);
  71. extern void otg_put_transceiver(struct otg_transceiver *);
  72. /* Context: can sleep */
  73. static inline int
  74. otg_start_hnp(struct otg_transceiver *otg)
  75. {
  76. return otg->start_hnp(otg);
  77. }
  78. /* for HCDs */
  79. static inline int
  80. otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
  81. {
  82. return otg->set_host(otg, host);
  83. }
  84. /* for usb peripheral controller drivers */
  85. /* Context: can sleep */
  86. static inline int
  87. otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph)
  88. {
  89. return otg->set_peripheral(otg, periph);
  90. }
  91. static inline int
  92. otg_set_power(struct otg_transceiver *otg, unsigned mA)
  93. {
  94. return otg->set_power(otg, mA);
  95. }
  96. /* Context: can sleep */
  97. static inline int
  98. otg_set_suspend(struct otg_transceiver *otg, int suspend)
  99. {
  100. if (otg->set_suspend != NULL)
  101. return otg->set_suspend(otg, suspend);
  102. else
  103. return 0;
  104. }
  105. static inline int
  106. otg_start_srp(struct otg_transceiver *otg)
  107. {
  108. return otg->start_srp(otg);
  109. }
  110. /* for OTG controller drivers (and maybe other stuff) */
  111. extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
  112. #endif /* __LINUX_USB_OTG_H */