Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
otg.h
Go to the documentation of this file.
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 {
16 
17  struct usb_phy *phy;
18  struct usb_bus *host;
19  struct usb_gadget *gadget;
20 
21  /* bind/unbind the host controller */
22  int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
23 
24  /* bind/unbind the peripheral controller */
25  int (*set_peripheral)(struct usb_otg *otg,
26  struct usb_gadget *gadget);
27 
28  /* effective for A-peripheral, ignored for B devices */
29  int (*set_vbus)(struct usb_otg *otg, bool enabled);
30 
31  /* for B devices only: start session with A-Host */
32  int (*start_srp)(struct usb_otg *otg);
33 
34  /* start or continue HNP role switch */
35  int (*start_hnp)(struct usb_otg *otg);
36 
37 };
38 
39 #ifdef CONFIG_USB_OTG_UTILS
40 extern const char *otg_state_string(enum usb_otg_state state);
41 #else
42 static inline const char *otg_state_string(enum usb_otg_state state)
43 {
44  return NULL;
45 }
46 #endif
47 
48 /* Context: can sleep */
49 static inline int
50 otg_start_hnp(struct usb_otg *otg)
51 {
52  if (otg && otg->start_hnp)
53  return otg->start_hnp(otg);
54 
55  return -ENOTSUPP;
56 }
57 
58 /* Context: can sleep */
59 static inline int
60 otg_set_vbus(struct usb_otg *otg, bool enabled)
61 {
62  if (otg && otg->set_vbus)
63  return otg->set_vbus(otg, enabled);
64 
65  return -ENOTSUPP;
66 }
67 
68 /* for HCDs */
69 static inline int
70 otg_set_host(struct usb_otg *otg, struct usb_bus *host)
71 {
72  if (otg && otg->set_host)
73  return otg->set_host(otg, host);
74 
75  return -ENOTSUPP;
76 }
77 
78 /* for usb peripheral controller drivers */
79 
80 /* Context: can sleep */
81 static inline int
82 otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
83 {
84  if (otg && otg->set_peripheral)
85  return otg->set_peripheral(otg, periph);
86 
87  return -ENOTSUPP;
88 }
89 
90 static inline int
91 otg_start_srp(struct usb_otg *otg)
92 {
93  if (otg && otg->start_srp)
94  return otg->start_srp(otg);
95 
96  return -ENOTSUPP;
97 }
98 
99 /* for OTG controller drivers (and maybe other stuff) */
100 extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
101 
102 #endif /* __LINUX_USB_OTG_H */