otg.h 3.1 KB

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