otg.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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/notifier.h>
  11. /* OTG defines lots of enumeration states before device reset */
  12. enum usb_otg_state {
  13. OTG_STATE_UNDEFINED = 0,
  14. /* single-role peripheral, and dual-role default-b */
  15. OTG_STATE_B_IDLE,
  16. OTG_STATE_B_SRP_INIT,
  17. OTG_STATE_B_PERIPHERAL,
  18. /* extra dual-role default-b states */
  19. OTG_STATE_B_WAIT_ACON,
  20. OTG_STATE_B_HOST,
  21. /* dual-role default-a */
  22. OTG_STATE_A_IDLE,
  23. OTG_STATE_A_WAIT_VRISE,
  24. OTG_STATE_A_WAIT_BCON,
  25. OTG_STATE_A_HOST,
  26. OTG_STATE_A_SUSPEND,
  27. OTG_STATE_A_PERIPHERAL,
  28. OTG_STATE_A_WAIT_VFALL,
  29. OTG_STATE_A_VBUS_ERR,
  30. };
  31. enum usb_xceiv_events {
  32. USB_EVENT_NONE, /* no events or cable disconnected */
  33. USB_EVENT_VBUS, /* vbus valid event */
  34. USB_EVENT_ID, /* id was grounded */
  35. USB_EVENT_CHARGER, /* usb dedicated charger */
  36. USB_EVENT_ENUMERATED, /* gadget driver enumerated */
  37. };
  38. struct otg_transceiver;
  39. /* for transceivers connected thru an ULPI interface, the user must
  40. * provide access ops
  41. */
  42. struct otg_io_access_ops {
  43. int (*read)(struct otg_transceiver *otg, u32 reg);
  44. int (*write)(struct otg_transceiver *otg, u32 val, u32 reg);
  45. };
  46. /*
  47. * the otg driver needs to interact with both device side and host side
  48. * usb controllers. it decides which controller is active at a given
  49. * moment, using the transceiver, ID signal, HNP and sometimes static
  50. * configuration information (including "board isn't wired for otg").
  51. */
  52. struct otg_transceiver {
  53. struct device *dev;
  54. const char *label;
  55. unsigned int flags;
  56. u8 default_a;
  57. enum usb_otg_state state;
  58. struct usb_bus *host;
  59. struct usb_gadget *gadget;
  60. struct otg_io_access_ops *io_ops;
  61. void __iomem *io_priv;
  62. /* for notification of usb_xceiv_events */
  63. struct blocking_notifier_head notifier;
  64. /* to pass extra port status to the root hub */
  65. u16 port_status;
  66. u16 port_change;
  67. /* initialize/shutdown the OTG controller */
  68. int (*init)(struct otg_transceiver *otg);
  69. void (*shutdown)(struct otg_transceiver *otg);
  70. /* bind/unbind the host controller */
  71. int (*set_host)(struct otg_transceiver *otg,
  72. struct usb_bus *host);
  73. /* bind/unbind the peripheral controller */
  74. int (*set_peripheral)(struct otg_transceiver *otg,
  75. struct usb_gadget *gadget);
  76. /* effective for B devices, ignored for A-peripheral */
  77. int (*set_power)(struct otg_transceiver *otg,
  78. unsigned mA);
  79. /* effective for A-peripheral, ignored for B devices */
  80. int (*set_vbus)(struct otg_transceiver *otg,
  81. bool enabled);
  82. /* for non-OTG B devices: set transceiver into suspend mode */
  83. int (*set_suspend)(struct otg_transceiver *otg,
  84. int suspend);
  85. /* for B devices only: start session with A-Host */
  86. int (*start_srp)(struct otg_transceiver *otg);
  87. /* start or continue HNP role switch */
  88. int (*start_hnp)(struct otg_transceiver *otg);
  89. };
  90. /* for board-specific init logic */
  91. extern int otg_set_transceiver(struct otg_transceiver *);
  92. #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
  93. /* sometimes transceivers are accessed only through e.g. ULPI */
  94. extern void usb_nop_xceiv_register(void);
  95. extern void usb_nop_xceiv_unregister(void);
  96. #else
  97. static inline void usb_nop_xceiv_register(void)
  98. {
  99. }
  100. static inline void usb_nop_xceiv_unregister(void)
  101. {
  102. }
  103. #endif
  104. /* helpers for direct access thru low-level io interface */
  105. static inline int otg_io_read(struct otg_transceiver *otg, u32 reg)
  106. {
  107. if (otg->io_ops && otg->io_ops->read)
  108. return otg->io_ops->read(otg, reg);
  109. return -EINVAL;
  110. }
  111. static inline int otg_io_write(struct otg_transceiver *otg, u32 val, u32 reg)
  112. {
  113. if (otg->io_ops && otg->io_ops->write)
  114. return otg->io_ops->write(otg, val, reg);
  115. return -EINVAL;
  116. }
  117. static inline int
  118. otg_init(struct otg_transceiver *otg)
  119. {
  120. if (otg->init)
  121. return otg->init(otg);
  122. return 0;
  123. }
  124. static inline void
  125. otg_shutdown(struct otg_transceiver *otg)
  126. {
  127. if (otg->shutdown)
  128. otg->shutdown(otg);
  129. }
  130. /* for usb host and peripheral controller drivers */
  131. #ifdef CONFIG_USB_OTG_UTILS
  132. extern struct otg_transceiver *otg_get_transceiver(void);
  133. extern void otg_put_transceiver(struct otg_transceiver *);
  134. #else
  135. static inline struct otg_transceiver *otg_get_transceiver(void)
  136. {
  137. return NULL;
  138. }
  139. static inline void otg_put_transceiver(struct otg_transceiver *x)
  140. {
  141. }
  142. #endif
  143. /* Context: can sleep */
  144. static inline int
  145. otg_start_hnp(struct otg_transceiver *otg)
  146. {
  147. return otg->start_hnp(otg);
  148. }
  149. /* Context: can sleep */
  150. static inline int
  151. otg_set_vbus(struct otg_transceiver *otg, bool enabled)
  152. {
  153. return otg->set_vbus(otg, enabled);
  154. }
  155. /* for HCDs */
  156. static inline int
  157. otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
  158. {
  159. return otg->set_host(otg, host);
  160. }
  161. /* for usb peripheral controller drivers */
  162. /* Context: can sleep */
  163. static inline int
  164. otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph)
  165. {
  166. return otg->set_peripheral(otg, periph);
  167. }
  168. static inline int
  169. otg_set_power(struct otg_transceiver *otg, unsigned mA)
  170. {
  171. return otg->set_power(otg, mA);
  172. }
  173. /* Context: can sleep */
  174. static inline int
  175. otg_set_suspend(struct otg_transceiver *otg, int suspend)
  176. {
  177. if (otg->set_suspend != NULL)
  178. return otg->set_suspend(otg, suspend);
  179. else
  180. return 0;
  181. }
  182. static inline int
  183. otg_start_srp(struct otg_transceiver *otg)
  184. {
  185. return otg->start_srp(otg);
  186. }
  187. /* notifiers */
  188. static inline int
  189. otg_register_notifier(struct otg_transceiver *otg, struct notifier_block *nb)
  190. {
  191. return blocking_notifier_chain_register(&otg->notifier, nb);
  192. }
  193. static inline void
  194. otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb)
  195. {
  196. blocking_notifier_chain_unregister(&otg->notifier, nb);
  197. }
  198. /* for OTG controller drivers (and maybe other stuff) */
  199. extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
  200. #endif /* __LINUX_USB_OTG_H */