otg.h 5.9 KB

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