]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - include/linux/usb/otg.h
usb: Convert all users to new usb_phy
[mirror_ubuntu-focal-kernel.git] / include / linux / usb / otg.h
CommitLineData
41dceed5 1/* USB OTG (On The Go) defines */
1da177e4 2/*
dda43a0e 3 *
1da177e4
LT
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
dda43a0e
RD
9#ifndef __LINUX_USB_OTG_H
10#define __LINUX_USB_OTG_H
1da177e4 11
e9a20171
FB
12#include <linux/notifier.h>
13
1da177e4
LT
14/* OTG defines lots of enumeration states before device reset */
15enum usb_otg_state {
16 OTG_STATE_UNDEFINED = 0,
17
18 /* single-role peripheral, and dual-role default-b */
19 OTG_STATE_B_IDLE,
20 OTG_STATE_B_SRP_INIT,
21 OTG_STATE_B_PERIPHERAL,
22
23 /* extra dual-role default-b states */
24 OTG_STATE_B_WAIT_ACON,
25 OTG_STATE_B_HOST,
26
27 /* dual-role default-a */
28 OTG_STATE_A_IDLE,
29 OTG_STATE_A_WAIT_VRISE,
30 OTG_STATE_A_WAIT_BCON,
31 OTG_STATE_A_HOST,
32 OTG_STATE_A_SUSPEND,
33 OTG_STATE_A_PERIPHERAL,
34 OTG_STATE_A_WAIT_VFALL,
35 OTG_STATE_A_VBUS_ERR,
36};
37
de07e18c 38enum usb_phy_events {
e9a20171
FB
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 */
44};
45
86753811 46struct usb_phy;
91c8a5a9
DM
47
48/* for transceivers connected thru an ULPI interface, the user must
49 * provide access ops
50 */
7a8a3a9b 51struct usb_phy_io_ops {
86753811
HK
52 int (*read)(struct usb_phy *x, u32 reg);
53 int (*write)(struct usb_phy *x, u32 val, u32 reg);
91c8a5a9
DM
54};
55
7a8a3a9b
HK
56struct usb_otg {
57 u8 default_a;
58
59 struct usb_phy *phy;
60 struct usb_bus *host;
61 struct usb_gadget *gadget;
62
63 /* bind/unbind the host controller */
64 int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
65
66 /* bind/unbind the peripheral controller */
67 int (*set_peripheral)(struct usb_otg *otg,
68 struct usb_gadget *gadget);
69
70 /* effective for A-peripheral, ignored for B devices */
71 int (*set_vbus)(struct usb_otg *otg, bool enabled);
72
73 /* for B devices only: start session with A-Host */
74 int (*start_srp)(struct usb_otg *otg);
75
76 /* start or continue HNP role switch */
77 int (*start_hnp)(struct usb_otg *otg);
78
79};
80
1da177e4
LT
81/*
82 * the otg driver needs to interact with both device side and host side
83 * usb controllers. it decides which controller is active at a given
84 * moment, using the transceiver, ID signal, HNP and sometimes static
85 * configuration information (including "board isn't wired for otg").
86 */
86753811 87struct usb_phy {
1da177e4
LT
88 struct device *dev;
89 const char *label;
91c8a5a9 90 unsigned int flags;
1da177e4
LT
91
92 u8 default_a;
93 enum usb_otg_state state;
de07e18c 94 enum usb_phy_events last_event;
1da177e4 95
7a8a3a9b
HK
96 struct usb_otg *otg;
97
1da177e4
LT
98 struct usb_bus *host;
99 struct usb_gadget *gadget;
100
7a8a3a9b
HK
101 struct usb_phy_io_ops *io_ops;
102 void __iomem *io_priv;
91c8a5a9 103
de07e18c 104 /* for notification of usb_phy_events */
cccad6d4 105 struct atomic_notifier_head notifier;
e9a20171 106
1da177e4
LT
107 /* to pass extra port status to the root hub */
108 u16 port_status;
109 u16 port_change;
110
91c8a5a9 111 /* initialize/shutdown the OTG controller */
86753811
HK
112 int (*init)(struct usb_phy *x);
113 void (*shutdown)(struct usb_phy *x);
91c8a5a9 114
1da177e4 115 /* bind/unbind the host controller */
86753811 116 int (*set_host)(struct usb_phy *x,
1da177e4
LT
117 struct usb_bus *host);
118
119 /* bind/unbind the peripheral controller */
86753811 120 int (*set_peripheral)(struct usb_phy *x,
1da177e4
LT
121 struct usb_gadget *gadget);
122
123 /* effective for B devices, ignored for A-peripheral */
86753811 124 int (*set_power)(struct usb_phy *x,
1da177e4
LT
125 unsigned mA);
126
91c8a5a9 127 /* effective for A-peripheral, ignored for B devices */
86753811 128 int (*set_vbus)(struct usb_phy *x,
91c8a5a9
DM
129 bool enabled);
130
4e67185a 131 /* for non-OTG B devices: set transceiver into suspend mode */
86753811 132 int (*set_suspend)(struct usb_phy *x,
4e67185a
JY
133 int suspend);
134
1da177e4 135 /* for B devices only: start session with A-Host */
86753811 136 int (*start_srp)(struct usb_phy *x);
1da177e4
LT
137
138 /* start or continue HNP role switch */
86753811 139 int (*start_hnp)(struct usb_phy *x);
1da177e4
LT
140
141};
142
143
144/* for board-specific init logic */
7a8a3a9b 145extern int usb_set_transceiver(struct usb_phy *);
cc835e32 146
352a3378 147#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
cc835e32 148/* sometimes transceivers are accessed only through e.g. ULPI */
f6d92a05
AKG
149extern void usb_nop_xceiv_register(void);
150extern void usb_nop_xceiv_unregister(void);
224e1542
MM
151#else
152static inline void usb_nop_xceiv_register(void)
153{
154}
155
156static inline void usb_nop_xceiv_unregister(void)
157{
158}
159#endif
1da177e4 160
91c8a5a9 161/* helpers for direct access thru low-level io interface */
7a8a3a9b 162static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
91c8a5a9 163{
86753811
HK
164 if (x->io_ops && x->io_ops->read)
165 return x->io_ops->read(x, reg);
91c8a5a9
DM
166
167 return -EINVAL;
168}
169
7a8a3a9b 170static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
91c8a5a9 171{
86753811
HK
172 if (x->io_ops && x->io_ops->write)
173 return x->io_ops->write(x, val, reg);
91c8a5a9
DM
174
175 return -EINVAL;
176}
177
178static inline int
7a8a3a9b 179usb_phy_init(struct usb_phy *x)
91c8a5a9 180{
86753811
HK
181 if (x->init)
182 return x->init(x);
91c8a5a9
DM
183
184 return 0;
185}
186
187static inline void
7a8a3a9b 188usb_phy_shutdown(struct usb_phy *x)
91c8a5a9 189{
86753811
HK
190 if (x->shutdown)
191 x->shutdown(x);
91c8a5a9 192}
1da177e4
LT
193
194/* for usb host and peripheral controller drivers */
748eee09 195#ifdef CONFIG_USB_OTG_UTILS
7a8a3a9b
HK
196extern struct usb_phy *usb_get_transceiver(void);
197extern void usb_put_transceiver(struct usb_phy *);
3df00453 198extern const char *otg_state_string(enum usb_otg_state state);
748eee09 199#else
7a8a3a9b 200static inline struct usb_phy *usb_get_transceiver(void)
748eee09
GI
201{
202 return NULL;
203}
204
7a8a3a9b 205static inline void usb_put_transceiver(struct usb_phy *x)
748eee09
GI
206{
207}
3df00453
AG
208
209static inline const char *otg_state_string(enum usb_otg_state state)
210{
211 return NULL;
212}
748eee09 213#endif
1da177e4 214
c2344f13 215/* Context: can sleep */
1da177e4 216static inline int
86753811 217otg_start_hnp(struct usb_phy *x)
1da177e4 218{
7a8a3a9b
HK
219 if (x->otg && x->otg->start_hnp)
220 return x->otg->start_hnp(x->otg);
221
86753811 222 return x->start_hnp(x);
1da177e4
LT
223}
224
91c8a5a9
DM
225/* Context: can sleep */
226static inline int
86753811 227otg_set_vbus(struct usb_phy *x, bool enabled)
91c8a5a9 228{
7a8a3a9b
HK
229 if (x->otg && x->otg->set_vbus)
230 return x->otg->set_vbus(x->otg, enabled);
231
86753811 232 return x->set_vbus(x, enabled);
91c8a5a9 233}
1da177e4
LT
234
235/* for HCDs */
236static inline int
86753811 237otg_set_host(struct usb_phy *x, struct usb_bus *host)
1da177e4 238{
7a8a3a9b
HK
239 if (x->otg && x->otg->set_host)
240 return x->otg->set_host(x->otg, host);
241
86753811 242 return x->set_host(x, host);
1da177e4
LT
243}
244
1da177e4 245/* for usb peripheral controller drivers */
c2344f13
RJ
246
247/* Context: can sleep */
1da177e4 248static inline int
86753811 249otg_set_peripheral(struct usb_phy *x, struct usb_gadget *periph)
1da177e4 250{
7a8a3a9b
HK
251 if (x->otg && x->otg->set_peripheral)
252 return x->otg->set_peripheral(x->otg, periph);
253
86753811 254 return x->set_peripheral(x, periph);
1da177e4
LT
255}
256
257static inline int
7a8a3a9b 258usb_phy_set_power(struct usb_phy *x, unsigned mA)
1da177e4 259{
7a8a3a9b
HK
260 if (x && x->set_power)
261 return x->set_power(x, mA);
262 return 0;
1da177e4
LT
263}
264
c2344f13 265/* Context: can sleep */
4e67185a 266static inline int
7a8a3a9b 267usb_phy_set_suspend(struct usb_phy *x, int suspend)
4e67185a 268{
86753811
HK
269 if (x->set_suspend != NULL)
270 return x->set_suspend(x, suspend);
4e67185a
JY
271 else
272 return 0;
273}
274
1da177e4 275static inline int
86753811 276otg_start_srp(struct usb_phy *x)
1da177e4 277{
7a8a3a9b
HK
278 if (x->otg && x->otg->start_srp)
279 return x->otg->start_srp(x->otg);
280
86753811 281 return x->start_srp(x);
1da177e4
LT
282}
283
e9a20171
FB
284/* notifiers */
285static inline int
7a8a3a9b 286usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
e9a20171 287{
86753811 288 return atomic_notifier_chain_register(&x->notifier, nb);
e9a20171
FB
289}
290
291static inline void
7a8a3a9b 292usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
e9a20171 293{
86753811 294 atomic_notifier_chain_unregister(&x->notifier, nb);
e9a20171 295}
1da177e4
LT
296
297/* for OTG controller drivers (and maybe other stuff) */
298extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
dda43a0e 299
7a8a3a9b
HK
300/* Temporary aliases for transceiver functions */
301#define otg_set_transceiver(x) usb_set_transceiver(x)
302#define otg_get_transceiver() usb_get_transceiver()
303#define otg_put_transceiver(x) usb_put_transceiver(x)
304
305#define otg_io_read(x, a) usb_phy_io_read(x, a)
306#define otg_io_write(x, a, b) usb_phy_io_write(x, a, b)
307
308#define otg_init(x) usb_phy_init(x)
309#define otg_shutdown(x) usb_phy_shutdown(x)
310#define otg_set_power(x, a) usb_phy_set_power(x, a)
311#define otg_set_suspend(x, a) usb_phy_set_suspend(x, a)
312
313#define otg_register_notifier(x, a) usb_register_notifier(x, a)
314#define otg_unregister_notifier(x, a) usb_unregiser_notifier(x, a)
315
316#define otg_io_access_ops usb_phy_io_ops
317
dda43a0e 318#endif /* __LINUX_USB_OTG_H */