1 /* USB OTG (On The Go) defines */
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.
9 #ifndef __LINUX_USB_OTG_H
10 #define __LINUX_USB_OTG_H
12 #include <linux/notifier.h>
14 /* OTG defines lots of enumeration states before device reset */
16 OTG_STATE_UNDEFINED
= 0,
18 /* single-role peripheral, and dual-role default-b */
21 OTG_STATE_B_PERIPHERAL
,
23 /* extra dual-role default-b states */
24 OTG_STATE_B_WAIT_ACON
,
27 /* dual-role default-a */
29 OTG_STATE_A_WAIT_VRISE
,
30 OTG_STATE_A_WAIT_BCON
,
33 OTG_STATE_A_PERIPHERAL
,
34 OTG_STATE_A_WAIT_VFALL
,
38 enum usb_xceiv_events
{
39 USB_EVENT_NONE
, /* no events or cable disconnected */
40 USB_EVENT_VBUS
, /* vbus valid event */
41 USB_EVENT_ID
, /* id was grounded */
42 USB_EVENT_CHARGER
, /* usb dedicated charger */
43 USB_EVENT_ENUMERATED
, /* gadget driver enumerated */
46 struct otg_transceiver
;
48 /* for transceivers connected thru an ULPI interface, the user must
51 struct otg_io_access_ops
{
52 int (*read
)(struct otg_transceiver
*otg
, u32 reg
);
53 int (*write
)(struct otg_transceiver
*otg
, u32 val
, u32 reg
);
57 * the otg driver needs to interact with both device side and host side
58 * usb controllers. it decides which controller is active at a given
59 * moment, using the transceiver, ID signal, HNP and sometimes static
60 * configuration information (including "board isn't wired for otg").
62 struct otg_transceiver
{
68 enum usb_otg_state state
;
69 enum usb_xceiv_events last_event
;
72 struct usb_gadget
*gadget
;
74 struct otg_io_access_ops
*io_ops
;
75 void __iomem
*io_priv
;
77 /* for notification of usb_xceiv_events */
78 struct atomic_notifier_head notifier
;
80 /* to pass extra port status to the root hub */
84 /* initialize/shutdown the OTG controller */
85 int (*init
)(struct otg_transceiver
*otg
);
86 void (*shutdown
)(struct otg_transceiver
*otg
);
88 /* bind/unbind the host controller */
89 int (*set_host
)(struct otg_transceiver
*otg
,
90 struct usb_bus
*host
);
92 /* bind/unbind the peripheral controller */
93 int (*set_peripheral
)(struct otg_transceiver
*otg
,
94 struct usb_gadget
*gadget
);
96 /* effective for B devices, ignored for A-peripheral */
97 int (*set_power
)(struct otg_transceiver
*otg
,
100 /* effective for A-peripheral, ignored for B devices */
101 int (*set_vbus
)(struct otg_transceiver
*otg
,
104 /* for non-OTG B devices: set transceiver into suspend mode */
105 int (*set_suspend
)(struct otg_transceiver
*otg
,
108 /* for B devices only: start session with A-Host */
109 int (*start_srp
)(struct otg_transceiver
*otg
);
111 /* start or continue HNP role switch */
112 int (*start_hnp
)(struct otg_transceiver
*otg
);
117 /* for board-specific init logic */
118 extern int otg_set_transceiver(struct otg_transceiver
*);
120 #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
121 /* sometimes transceivers are accessed only through e.g. ULPI */
122 extern void usb_nop_xceiv_register(void);
123 extern void usb_nop_xceiv_unregister(void);
125 static inline void usb_nop_xceiv_register(void)
129 static inline void usb_nop_xceiv_unregister(void)
134 /* helpers for direct access thru low-level io interface */
135 static inline int otg_io_read(struct otg_transceiver
*otg
, u32 reg
)
137 if (otg
->io_ops
&& otg
->io_ops
->read
)
138 return otg
->io_ops
->read(otg
, reg
);
143 static inline int otg_io_write(struct otg_transceiver
*otg
, u32 val
, u32 reg
)
145 if (otg
->io_ops
&& otg
->io_ops
->write
)
146 return otg
->io_ops
->write(otg
, val
, reg
);
152 otg_init(struct otg_transceiver
*otg
)
155 return otg
->init(otg
);
161 otg_shutdown(struct otg_transceiver
*otg
)
167 /* for usb host and peripheral controller drivers */
168 #ifdef CONFIG_USB_OTG_UTILS
169 extern struct otg_transceiver
*otg_get_transceiver(void);
170 extern void otg_put_transceiver(struct otg_transceiver
*);
171 extern const char *otg_state_string(enum usb_otg_state state
);
173 static inline struct otg_transceiver
*otg_get_transceiver(void)
178 static inline void otg_put_transceiver(struct otg_transceiver
*x
)
182 static inline const char *otg_state_string(enum usb_otg_state state
)
188 /* Context: can sleep */
190 otg_start_hnp(struct otg_transceiver
*otg
)
192 return otg
->start_hnp(otg
);
195 /* Context: can sleep */
197 otg_set_vbus(struct otg_transceiver
*otg
, bool enabled
)
199 return otg
->set_vbus(otg
, enabled
);
204 otg_set_host(struct otg_transceiver
*otg
, struct usb_bus
*host
)
206 return otg
->set_host(otg
, host
);
209 /* for usb peripheral controller drivers */
211 /* Context: can sleep */
213 otg_set_peripheral(struct otg_transceiver
*otg
, struct usb_gadget
*periph
)
215 return otg
->set_peripheral(otg
, periph
);
219 otg_set_power(struct otg_transceiver
*otg
, unsigned mA
)
221 return otg
->set_power(otg
, mA
);
224 /* Context: can sleep */
226 otg_set_suspend(struct otg_transceiver
*otg
, int suspend
)
228 if (otg
->set_suspend
!= NULL
)
229 return otg
->set_suspend(otg
, suspend
);
235 otg_start_srp(struct otg_transceiver
*otg
)
237 return otg
->start_srp(otg
);
242 otg_register_notifier(struct otg_transceiver
*otg
, struct notifier_block
*nb
)
244 return atomic_notifier_chain_register(&otg
->notifier
, nb
);
248 otg_unregister_notifier(struct otg_transceiver
*otg
, struct notifier_block
*nb
)
250 atomic_notifier_chain_unregister(&otg
->notifier
, nb
);
253 /* for OTG controller drivers (and maybe other stuff) */
254 extern int usb_bus_start_enum(struct usb_bus
*bus
, unsigned port_num
);
256 #endif /* __LINUX_USB_OTG_H */