blob: 65a2b6afe02040a60d1a60eede7be97a9e60357d [file] [log] [blame]
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -08001/* USB OTG (On The Go) defines */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Robert P. J. Daydda43a02008-03-07 13:45:32 -05003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
Robert P. J. Daydda43a02008-03-07 13:45:32 -05009#ifndef __LINUX_USB_OTG_H
10#define __LINUX_USB_OTG_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Venu Byravarasude4217d2012-09-04 14:25:58 +053012#include <linux/usb/phy.h>
Felipe Balbie9a20172009-12-17 13:01:36 +020013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/* 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
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020038struct usb_otg {
39 u8 default_a;
40
41 struct usb_phy *phy;
42 struct usb_bus *host;
43 struct usb_gadget *gadget;
44
45 /* bind/unbind the host controller */
46 int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
47
48 /* bind/unbind the peripheral controller */
49 int (*set_peripheral)(struct usb_otg *otg,
50 struct usb_gadget *gadget);
51
52 /* effective for A-peripheral, ignored for B devices */
53 int (*set_vbus)(struct usb_otg *otg, bool enabled);
54
55 /* for B devices only: start session with A-Host */
56 int (*start_srp)(struct usb_otg *otg);
57
58 /* start or continue HNP role switch */
59 int (*start_hnp)(struct usb_otg *otg);
60
61};
62
Grazvydas Ignotas748eee02010-09-27 15:17:18 +030063#ifdef CONFIG_USB_OTG_UTILS
Anatolij Gustschin3df00452011-05-05 12:11:21 +020064extern const char *otg_state_string(enum usb_otg_state state);
Grazvydas Ignotas748eee02010-09-27 15:17:18 +030065#else
Anatolij Gustschin3df00452011-05-05 12:11:21 +020066static inline const char *otg_state_string(enum usb_otg_state state)
67{
68 return NULL;
69}
Grazvydas Ignotas748eee02010-09-27 15:17:18 +030070#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Robert Jarzmikc2344f12009-01-24 23:54:31 -080072/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020074otg_start_hnp(struct usb_otg *otg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020076 if (otg && otg->start_hnp)
77 return otg->start_hnp(otg);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020078
Heikki Krogerus136ced82012-02-13 13:24:19 +020079 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Daniel Mack91c8a5a2009-10-15 17:09:34 +030082/* Context: can sleep */
83static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020084otg_set_vbus(struct usb_otg *otg, bool enabled)
Daniel Mack91c8a5a2009-10-15 17:09:34 +030085{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020086 if (otg && otg->set_vbus)
87 return otg->set_vbus(otg, enabled);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020088
Heikki Krogerus136ced82012-02-13 13:24:19 +020089 return -ENOTSUPP;
Daniel Mack91c8a5a2009-10-15 17:09:34 +030090}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/* for HCDs */
93static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020094otg_set_host(struct usb_otg *otg, struct usb_bus *host)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020096 if (otg && otg->set_host)
97 return otg->set_host(otg, host);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020098
Heikki Krogerus136ced82012-02-13 13:24:19 +020099 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/* for usb peripheral controller drivers */
Robert Jarzmikc2344f12009-01-24 23:54:31 -0800103
104/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200106otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200108 if (otg && otg->set_peripheral)
109 return otg->set_peripheral(otg, periph);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +0200110
Heikki Krogerus136ced82012-02-13 13:24:19 +0200111 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
114static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200115otg_start_srp(struct usb_otg *otg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200117 if (otg && otg->start_srp)
118 return otg->start_srp(otg);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +0200119
Heikki Krogerus136ced82012-02-13 13:24:19 +0200120 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/* for OTG controller drivers (and maybe other stuff) */
124extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500125
126#endif /* __LINUX_USB_OTG_H */