]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - include/linux/usb/otg.h
usb: phy: isp1301: Remove unused static array and define
[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
662dca54
KVA
46/* associate a type with PHY */
47enum usb_phy_type {
48 USB_PHY_TYPE_UNDEFINED,
49 USB_PHY_TYPE_USB2,
50 USB_PHY_TYPE_USB3,
51};
52
86753811 53struct usb_phy;
91c8a5a9
DM
54
55/* for transceivers connected thru an ULPI interface, the user must
56 * provide access ops
57 */
7a8a3a9b 58struct usb_phy_io_ops {
86753811
HK
59 int (*read)(struct usb_phy *x, u32 reg);
60 int (*write)(struct usb_phy *x, u32 val, u32 reg);
91c8a5a9
DM
61};
62
7a8a3a9b
HK
63struct usb_otg {
64 u8 default_a;
65
66 struct usb_phy *phy;
67 struct usb_bus *host;
68 struct usb_gadget *gadget;
69
70 /* bind/unbind the host controller */
71 int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
72
73 /* bind/unbind the peripheral controller */
74 int (*set_peripheral)(struct usb_otg *otg,
75 struct usb_gadget *gadget);
76
77 /* effective for A-peripheral, ignored for B devices */
78 int (*set_vbus)(struct usb_otg *otg, bool enabled);
79
80 /* for B devices only: start session with A-Host */
81 int (*start_srp)(struct usb_otg *otg);
82
83 /* start or continue HNP role switch */
84 int (*start_hnp)(struct usb_otg *otg);
85
86};
87
1da177e4
LT
88/*
89 * the otg driver needs to interact with both device side and host side
90 * usb controllers. it decides which controller is active at a given
91 * moment, using the transceiver, ID signal, HNP and sometimes static
92 * configuration information (including "board isn't wired for otg").
93 */
86753811 94struct usb_phy {
1da177e4
LT
95 struct device *dev;
96 const char *label;
91c8a5a9 97 unsigned int flags;
1da177e4 98
662dca54 99 enum usb_phy_type type;
1da177e4 100 enum usb_otg_state state;
de07e18c 101 enum usb_phy_events last_event;
1da177e4 102
7a8a3a9b
HK
103 struct usb_otg *otg;
104
bf070bc1 105 struct device *io_dev;
7a8a3a9b
HK
106 struct usb_phy_io_ops *io_ops;
107 void __iomem *io_priv;
91c8a5a9 108
de07e18c 109 /* for notification of usb_phy_events */
cccad6d4 110 struct atomic_notifier_head notifier;
e9a20171 111
1da177e4
LT
112 /* to pass extra port status to the root hub */
113 u16 port_status;
114 u16 port_change;
115
662dca54
KVA
116 /* to support controllers that have multiple transceivers */
117 struct list_head head;
118
91c8a5a9 119 /* initialize/shutdown the OTG controller */
86753811
HK
120 int (*init)(struct usb_phy *x);
121 void (*shutdown)(struct usb_phy *x);
91c8a5a9 122
1da177e4 123 /* effective for B devices, ignored for A-peripheral */
86753811 124 int (*set_power)(struct usb_phy *x,
1da177e4
LT
125 unsigned mA);
126
4e67185a 127 /* for non-OTG B devices: set transceiver into suspend mode */
86753811 128 int (*set_suspend)(struct usb_phy *x,
4e67185a
JY
129 int suspend);
130
526c5138
RZ
131 /* notify phy connect status change */
132 int (*notify_connect)(struct usb_phy *x, int port);
133 int (*notify_disconnect)(struct usb_phy *x, int port);
1da177e4
LT
134};
135
136
137/* for board-specific init logic */
662dca54
KVA
138extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
139extern void usb_remove_phy(struct usb_phy *);
cc835e32 140
91c8a5a9 141/* helpers for direct access thru low-level io interface */
7a8a3a9b 142static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
91c8a5a9 143{
86753811
HK
144 if (x->io_ops && x->io_ops->read)
145 return x->io_ops->read(x, reg);
91c8a5a9
DM
146
147 return -EINVAL;
148}
149
7a8a3a9b 150static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
91c8a5a9 151{
86753811
HK
152 if (x->io_ops && x->io_ops->write)
153 return x->io_ops->write(x, val, reg);
91c8a5a9
DM
154
155 return -EINVAL;
156}
157
158static inline int
7a8a3a9b 159usb_phy_init(struct usb_phy *x)
91c8a5a9 160{
86753811
HK
161 if (x->init)
162 return x->init(x);
91c8a5a9
DM
163
164 return 0;
165}
166
167static inline void
7a8a3a9b 168usb_phy_shutdown(struct usb_phy *x)
91c8a5a9 169{
86753811
HK
170 if (x->shutdown)
171 x->shutdown(x);
91c8a5a9 172}
1da177e4
LT
173
174/* for usb host and peripheral controller drivers */
748eee09 175#ifdef CONFIG_USB_OTG_UTILS
662dca54 176extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
410219dc
KVA
177extern struct usb_phy *devm_usb_get_phy(struct device *dev,
178 enum usb_phy_type type);
721002ec 179extern void usb_put_phy(struct usb_phy *);
410219dc 180extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
3df00453 181extern const char *otg_state_string(enum usb_otg_state state);
748eee09 182#else
662dca54 183static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
748eee09
GI
184{
185 return NULL;
186}
187
410219dc
KVA
188static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
189 enum usb_phy_type type)
190{
191 return NULL;
192}
193
721002ec 194static inline void usb_put_phy(struct usb_phy *x)
410219dc
KVA
195{
196}
197
198static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
748eee09
GI
199{
200}
3df00453
AG
201
202static inline const char *otg_state_string(enum usb_otg_state state)
203{
204 return NULL;
205}
748eee09 206#endif
1da177e4 207
c2344f13 208/* Context: can sleep */
1da177e4 209static inline int
6e13c650 210otg_start_hnp(struct usb_otg *otg)
1da177e4 211{
6e13c650
HK
212 if (otg && otg->start_hnp)
213 return otg->start_hnp(otg);
7a8a3a9b 214
136ced89 215 return -ENOTSUPP;
1da177e4
LT
216}
217
91c8a5a9
DM
218/* Context: can sleep */
219static inline int
6e13c650 220otg_set_vbus(struct usb_otg *otg, bool enabled)
91c8a5a9 221{
6e13c650
HK
222 if (otg && otg->set_vbus)
223 return otg->set_vbus(otg, enabled);
7a8a3a9b 224
136ced89 225 return -ENOTSUPP;
91c8a5a9 226}
1da177e4
LT
227
228/* for HCDs */
229static inline int
6e13c650 230otg_set_host(struct usb_otg *otg, struct usb_bus *host)
1da177e4 231{
6e13c650
HK
232 if (otg && otg->set_host)
233 return otg->set_host(otg, host);
7a8a3a9b 234
136ced89 235 return -ENOTSUPP;
1da177e4
LT
236}
237
1da177e4 238/* for usb peripheral controller drivers */
c2344f13
RJ
239
240/* Context: can sleep */
1da177e4 241static inline int
6e13c650 242otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
1da177e4 243{
6e13c650
HK
244 if (otg && otg->set_peripheral)
245 return otg->set_peripheral(otg, periph);
7a8a3a9b 246
136ced89 247 return -ENOTSUPP;
1da177e4
LT
248}
249
250static inline int
7a8a3a9b 251usb_phy_set_power(struct usb_phy *x, unsigned mA)
1da177e4 252{
7a8a3a9b
HK
253 if (x && x->set_power)
254 return x->set_power(x, mA);
255 return 0;
1da177e4
LT
256}
257
c2344f13 258/* Context: can sleep */
4e67185a 259static inline int
7a8a3a9b 260usb_phy_set_suspend(struct usb_phy *x, int suspend)
4e67185a 261{
86753811
HK
262 if (x->set_suspend != NULL)
263 return x->set_suspend(x, suspend);
4e67185a
JY
264 else
265 return 0;
266}
267
526c5138
RZ
268static inline int
269usb_phy_notify_connect(struct usb_phy *x, int port)
270{
271 if (x->notify_connect)
272 return x->notify_connect(x, port);
273 else
274 return 0;
275}
276
277static inline int
278usb_phy_notify_disconnect(struct usb_phy *x, int port)
279{
280 if (x->notify_disconnect)
281 return x->notify_disconnect(x, port);
282 else
283 return 0;
284}
285
1da177e4 286static inline int
6e13c650 287otg_start_srp(struct usb_otg *otg)
1da177e4 288{
6e13c650
HK
289 if (otg && otg->start_srp)
290 return otg->start_srp(otg);
7a8a3a9b 291
136ced89 292 return -ENOTSUPP;
1da177e4
LT
293}
294
e9a20171
FB
295/* notifiers */
296static inline int
7a8a3a9b 297usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
e9a20171 298{
86753811 299 return atomic_notifier_chain_register(&x->notifier, nb);
e9a20171
FB
300}
301
302static inline void
7a8a3a9b 303usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
e9a20171 304{
86753811 305 atomic_notifier_chain_unregister(&x->notifier, nb);
e9a20171 306}
1da177e4
LT
307
308/* for OTG controller drivers (and maybe other stuff) */
309extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
dda43a0e 310
662dca54
KVA
311static inline const char *usb_phy_type_string(enum usb_phy_type type)
312{
313 switch (type) {
314 case USB_PHY_TYPE_USB2:
315 return "USB2 PHY";
316 case USB_PHY_TYPE_USB3:
317 return "USB3 PHY";
318 default:
319 return "UNKNOWN PHY TYPE";
320 }
321}
dda43a0e 322#endif /* __LINUX_USB_OTG_H */