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 /* OTG defines lots of enumeration states before device reset */
14 OTG_STATE_UNDEFINED
= 0,
16 /* single-role peripheral, and dual-role default-b */
19 OTG_STATE_B_PERIPHERAL
,
21 /* extra dual-role default-b states */
22 OTG_STATE_B_WAIT_ACON
,
25 /* dual-role default-a */
27 OTG_STATE_A_WAIT_VRISE
,
28 OTG_STATE_A_WAIT_BCON
,
31 OTG_STATE_A_PERIPHERAL
,
32 OTG_STATE_A_WAIT_VFALL
,
36 #define USB_OTG_PULLUP_ID (1 << 0)
37 #define USB_OTG_PULLDOWN_DP (1 << 1)
38 #define USB_OTG_PULLDOWN_DM (1 << 2)
39 #define USB_OTG_EXT_VBUS_INDICATOR (1 << 3)
40 #define USB_OTG_DRV_VBUS (1 << 4)
41 #define USB_OTG_DRV_VBUS_EXT (1 << 5)
43 struct otg_transceiver
;
45 /* for transceivers connected thru an ULPI interface, the user must
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
);
54 * the otg driver needs to interact with both device side and host side
55 * usb controllers. it decides which controller is active at a given
56 * moment, using the transceiver, ID signal, HNP and sometimes static
57 * configuration information (including "board isn't wired for otg").
59 struct otg_transceiver
{
65 enum usb_otg_state state
;
68 struct usb_gadget
*gadget
;
70 struct otg_io_access_ops
*io_ops
;
71 void __iomem
*io_priv
;
73 /* to pass extra port status to the root hub */
77 /* initialize/shutdown the OTG controller */
78 int (*init
)(struct otg_transceiver
*otg
);
79 void (*shutdown
)(struct otg_transceiver
*otg
);
81 /* bind/unbind the host controller */
82 int (*set_host
)(struct otg_transceiver
*otg
,
83 struct usb_bus
*host
);
85 /* bind/unbind the peripheral controller */
86 int (*set_peripheral
)(struct otg_transceiver
*otg
,
87 struct usb_gadget
*gadget
);
89 /* effective for B devices, ignored for A-peripheral */
90 int (*set_power
)(struct otg_transceiver
*otg
,
93 /* effective for A-peripheral, ignored for B devices */
94 int (*set_vbus
)(struct otg_transceiver
*otg
,
97 /* for non-OTG B devices: set transceiver into suspend mode */
98 int (*set_suspend
)(struct otg_transceiver
*otg
,
101 /* for B devices only: start session with A-Host */
102 int (*start_srp
)(struct otg_transceiver
*otg
);
104 /* start or continue HNP role switch */
105 int (*start_hnp
)(struct otg_transceiver
*otg
);
110 /* for board-specific init logic */
111 extern int otg_set_transceiver(struct otg_transceiver
*);
113 /* sometimes transceivers are accessed only through e.g. ULPI */
114 extern void usb_nop_xceiv_register(void);
115 extern void usb_nop_xceiv_unregister(void);
117 /* helpers for direct access thru low-level io interface */
118 static inline int otg_io_read(struct otg_transceiver
*otg
, u32 reg
)
120 if (otg
->io_ops
&& otg
->io_ops
->read
)
121 return otg
->io_ops
->read(otg
, reg
);
126 static inline int otg_io_write(struct otg_transceiver
*otg
, u32 reg
, u32 val
)
128 if (otg
->io_ops
&& otg
->io_ops
->write
)
129 return otg
->io_ops
->write(otg
, reg
, val
);
135 otg_init(struct otg_transceiver
*otg
)
138 return otg
->init(otg
);
144 otg_shutdown(struct otg_transceiver
*otg
)
150 /* for usb host and peripheral controller drivers */
151 extern struct otg_transceiver
*otg_get_transceiver(void);
152 extern void otg_put_transceiver(struct otg_transceiver
*);
154 /* Context: can sleep */
156 otg_start_hnp(struct otg_transceiver
*otg
)
158 return otg
->start_hnp(otg
);
161 /* Context: can sleep */
163 otg_set_vbus(struct otg_transceiver
*otg
, bool enabled
)
165 return otg
->set_vbus(otg
, enabled
);
170 otg_set_host(struct otg_transceiver
*otg
, struct usb_bus
*host
)
172 return otg
->set_host(otg
, host
);
175 /* for usb peripheral controller drivers */
177 /* Context: can sleep */
179 otg_set_peripheral(struct otg_transceiver
*otg
, struct usb_gadget
*periph
)
181 return otg
->set_peripheral(otg
, periph
);
185 otg_set_power(struct otg_transceiver
*otg
, unsigned mA
)
187 return otg
->set_power(otg
, mA
);
190 /* Context: can sleep */
192 otg_set_suspend(struct otg_transceiver
*otg
, int suspend
)
194 if (otg
->set_suspend
!= NULL
)
195 return otg
->set_suspend(otg
, suspend
);
201 otg_start_srp(struct otg_transceiver
*otg
)
203 return otg
->start_srp(otg
);
207 /* for OTG controller drivers (and maybe other stuff) */
208 extern int usb_bus_start_enum(struct usb_bus
*bus
, unsigned port_num
);
210 #endif /* __LINUX_USB_OTG_H */