]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/usb/otg.h
usb: move the OTG state from the USB PHY to the OTG structure
[karo-tx-linux.git] / include / linux / usb / otg.h
1 /* USB OTG (On The Go) defines */
2 /*
3  *
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
9 #ifndef __LINUX_USB_OTG_H
10 #define __LINUX_USB_OTG_H
11
12 #include <linux/usb/phy.h>
13
14 struct usb_otg {
15         u8                      default_a;
16
17         struct usb_phy          *phy;
18         struct usb_bus          *host;
19         struct usb_gadget       *gadget;
20
21         enum usb_otg_state      state;
22
23         /* bind/unbind the host controller */
24         int     (*set_host)(struct usb_otg *otg, struct usb_bus *host);
25
26         /* bind/unbind the peripheral controller */
27         int     (*set_peripheral)(struct usb_otg *otg,
28                                         struct usb_gadget *gadget);
29
30         /* effective for A-peripheral, ignored for B devices */
31         int     (*set_vbus)(struct usb_otg *otg, bool enabled);
32
33         /* for B devices only:  start session with A-Host */
34         int     (*start_srp)(struct usb_otg *otg);
35
36         /* start or continue HNP role switch */
37         int     (*start_hnp)(struct usb_otg *otg);
38
39 };
40
41 extern const char *usb_otg_state_string(enum usb_otg_state state);
42
43 /* Context: can sleep */
44 static inline int
45 otg_start_hnp(struct usb_otg *otg)
46 {
47         if (otg && otg->start_hnp)
48                 return otg->start_hnp(otg);
49
50         return -ENOTSUPP;
51 }
52
53 /* Context: can sleep */
54 static inline int
55 otg_set_vbus(struct usb_otg *otg, bool enabled)
56 {
57         if (otg && otg->set_vbus)
58                 return otg->set_vbus(otg, enabled);
59
60         return -ENOTSUPP;
61 }
62
63 /* for HCDs */
64 static inline int
65 otg_set_host(struct usb_otg *otg, struct usb_bus *host)
66 {
67         if (otg && otg->set_host)
68                 return otg->set_host(otg, host);
69
70         return -ENOTSUPP;
71 }
72
73 /* for usb peripheral controller drivers */
74
75 /* Context: can sleep */
76 static inline int
77 otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
78 {
79         if (otg && otg->set_peripheral)
80                 return otg->set_peripheral(otg, periph);
81
82         return -ENOTSUPP;
83 }
84
85 static inline int
86 otg_start_srp(struct usb_otg *otg)
87 {
88         if (otg && otg->start_srp)
89                 return otg->start_srp(otg);
90
91         return -ENOTSUPP;
92 }
93
94 /* for OTG controller drivers (and maybe other stuff) */
95 extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
96
97 enum usb_dr_mode {
98         USB_DR_MODE_UNKNOWN,
99         USB_DR_MODE_HOST,
100         USB_DR_MODE_PERIPHERAL,
101         USB_DR_MODE_OTG,
102 };
103
104 #endif /* __LINUX_USB_OTG_H */