otg.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #define USB_OTG_PULLUP_ID (1 << 0)
  31. #define USB_OTG_PULLDOWN_DP (1 << 1)
  32. #define USB_OTG_PULLDOWN_DM (1 << 2)
  33. #define USB_OTG_EXT_VBUS_INDICATOR (1 << 3)
  34. #define USB_OTG_DRV_VBUS (1 << 4)
  35. #define USB_OTG_DRV_VBUS_EXT (1 << 5)
  36. struct otg_transceiver;
  37. /* for transceivers connected thru an ULPI interface, the user must
  38. * provide access ops
  39. */
  40. struct otg_io_access_ops {
  41. int (*read)(struct otg_transceiver *otg, u32 reg);
  42. int (*write)(struct otg_transceiver *otg, u32 val, u32 reg);
  43. };
  44. /*
  45. * the otg driver needs to interact with both device side and host side
  46. * usb controllers. it decides which controller is active at a given
  47. * moment, using the transceiver, ID signal, HNP and sometimes static
  48. * configuration information (including "board isn't wired for otg").
  49. */
  50. struct otg_transceiver {
  51. struct device *dev;
  52. const char *label;
  53. unsigned int flags;
  54. u8 default_a;
  55. enum usb_otg_state state;
  56. struct usb_bus *host;
  57. struct usb_gadget *gadget;
  58. struct otg_io_access_ops *io_ops;
  59. void __iomem *io_priv;
  60. /* to pass extra port status to the root hub */
  61. u16 port_status;
  62. u16 port_change;
  63. /* initialize/shutdown the OTG controller */
  64. int (*init)(struct otg_transceiver *otg);
  65. void (*shutdown)(struct otg_transceiver *otg);
  66. /* bind/unbind the host controller */
  67. int (*set_host)(struct otg_transceiver *otg,
  68. struct usb_bus *host);
  69. /* bind/unbind the peripheral controller */
  70. int (*set_peripheral)(struct otg_transceiver *otg,
  71. struct usb_gadget *gadget);
  72. /* effective for B devices, ignored for A-peripheral */
  73. int (*set_power)(struct otg_transceiver *otg,
  74. unsigned mA);
  75. /* effective for A-peripheral, ignored for B devices */
  76. int (*set_vbus)(struct otg_transceiver *otg,
  77. bool enabled);
  78. /* for non-OTG B devices: set transceiver into suspend mode */
  79. int (*set_suspend)(struct otg_transceiver *otg,
  80. int suspend);
  81. /* for B devices only: start session with A-Host */
  82. int (*start_srp)(struct otg_transceiver *otg);
  83. /* start or continue HNP role switch */
  84. int (*start_hnp)(struct otg_transceiver *otg);
  85. };
  86. /* for board-specific init logic */
  87. extern int otg_set_transceiver(struct otg_transceiver *);
  88. /* sometimes transceivers are accessed only through e.g. ULPI */
  89. extern void usb_nop_xceiv_register(void);
  90. extern void usb_nop_xceiv_unregister(void);
  91. /* helpers for direct access thru low-level io interface */
  92. static inline int otg_io_read(struct otg_transceiver *otg, u32 reg)
  93. {
  94. if (otg->io_ops && otg->io_ops->read)
  95. return otg->io_ops->read(otg, reg);
  96. return -EINVAL;
  97. }
  98. static inline int otg_io_write(struct otg_transceiver *otg, u32 reg, u32 val)
  99. {
  100. if (otg->io_ops && otg->io_ops->write)
  101. return otg->io_ops->write(otg, reg, val);
  102. return -EINVAL;
  103. }
  104. static inline int
  105. otg_init(struct otg_transceiver *otg)
  106. {
  107. if (otg->init)
  108. return otg->init(otg);
  109. return 0;
  110. }
  111. static inline void
  112. otg_shutdown(struct otg_transceiver *otg)
  113. {
  114. if (otg->shutdown)
  115. otg->shutdown(otg);
  116. }
  117. /* for usb host and peripheral controller drivers */
  118. extern struct otg_transceiver *otg_get_transceiver(void);
  119. extern void otg_put_transceiver(struct otg_transceiver *);
  120. /* Context: can sleep */
  121. static inline int
  122. otg_start_hnp(struct otg_transceiver *otg)
  123. {
  124. return otg->start_hnp(otg);
  125. }
  126. /* Context: can sleep */
  127. static inline int
  128. otg_set_vbus(struct otg_transceiver *otg, bool enabled)
  129. {
  130. return otg->set_vbus(otg, enabled);
  131. }
  132. /* for HCDs */
  133. static inline int
  134. otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
  135. {
  136. return otg->set_host(otg, host);
  137. }
  138. /* for usb peripheral controller drivers */
  139. /* Context: can sleep */
  140. static inline int
  141. otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph)
  142. {
  143. return otg->set_peripheral(otg, periph);
  144. }
  145. static inline int
  146. otg_set_power(struct otg_transceiver *otg, unsigned mA)
  147. {
  148. return otg->set_power(otg, mA);
  149. }
  150. /* Context: can sleep */
  151. static inline int
  152. otg_set_suspend(struct otg_transceiver *otg, int suspend)
  153. {
  154. if (otg->set_suspend != NULL)
  155. return otg->set_suspend(otg, suspend);
  156. else
  157. return 0;
  158. }
  159. static inline int
  160. otg_start_srp(struct otg_transceiver *otg)
  161. {
  162. return otg->start_srp(otg);
  163. }
  164. /* for OTG controller drivers (and maybe other stuff) */
  165. extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
  166. #endif /* __LINUX_USB_OTG_H */