1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* USB OTG (On The Go) defines */
3*4882a593Smuzhiyun /*
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * These APIs may be used between USB controllers. USB device drivers
6*4882a593Smuzhiyun * (for either host or peripheral roles) don't use these calls; they
7*4882a593Smuzhiyun * continue to use just usb_device and usb_gadget.
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef __LINUX_USB_OTG_H
11*4882a593Smuzhiyun #define __LINUX_USB_OTG_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/phy/phy.h>
14*4882a593Smuzhiyun #include <linux/usb/phy.h>
15*4882a593Smuzhiyun #include <linux/android_kabi.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun struct usb_otg {
18*4882a593Smuzhiyun u8 default_a;
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun struct phy *phy;
21*4882a593Smuzhiyun /* old usb_phy interface */
22*4882a593Smuzhiyun struct usb_phy *usb_phy;
23*4882a593Smuzhiyun struct usb_bus *host;
24*4882a593Smuzhiyun struct usb_gadget *gadget;
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun enum usb_otg_state state;
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /* bind/unbind the host controller */
29*4882a593Smuzhiyun int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun /* bind/unbind the peripheral controller */
32*4882a593Smuzhiyun int (*set_peripheral)(struct usb_otg *otg,
33*4882a593Smuzhiyun struct usb_gadget *gadget);
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun /* effective for A-peripheral, ignored for B devices */
36*4882a593Smuzhiyun int (*set_vbus)(struct usb_otg *otg, bool enabled);
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* for B devices only: start session with A-Host */
39*4882a593Smuzhiyun int (*start_srp)(struct usb_otg *otg);
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun /* start or continue HNP role switch */
42*4882a593Smuzhiyun int (*start_hnp)(struct usb_otg *otg);
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
45*4882a593Smuzhiyun };
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /**
48*4882a593Smuzhiyun * struct usb_otg_caps - describes the otg capabilities of the device
49*4882a593Smuzhiyun * @otg_rev: The OTG revision number the device is compliant with, it's
50*4882a593Smuzhiyun * in binary-coded decimal (i.e. 2.0 is 0200H).
51*4882a593Smuzhiyun * @hnp_support: Indicates if the device supports HNP.
52*4882a593Smuzhiyun * @srp_support: Indicates if the device supports SRP.
53*4882a593Smuzhiyun * @adp_support: Indicates if the device supports ADP.
54*4882a593Smuzhiyun */
55*4882a593Smuzhiyun struct usb_otg_caps {
56*4882a593Smuzhiyun u16 otg_rev;
57*4882a593Smuzhiyun bool hnp_support;
58*4882a593Smuzhiyun bool srp_support;
59*4882a593Smuzhiyun bool adp_support;
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun extern const char *usb_otg_state_string(enum usb_otg_state state);
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /* Context: can sleep */
65*4882a593Smuzhiyun static inline int
otg_start_hnp(struct usb_otg * otg)66*4882a593Smuzhiyun otg_start_hnp(struct usb_otg *otg)
67*4882a593Smuzhiyun {
68*4882a593Smuzhiyun if (otg && otg->start_hnp)
69*4882a593Smuzhiyun return otg->start_hnp(otg);
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun return -ENOTSUPP;
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /* Context: can sleep */
75*4882a593Smuzhiyun static inline int
otg_set_vbus(struct usb_otg * otg,bool enabled)76*4882a593Smuzhiyun otg_set_vbus(struct usb_otg *otg, bool enabled)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun if (otg && otg->set_vbus)
79*4882a593Smuzhiyun return otg->set_vbus(otg, enabled);
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun return -ENOTSUPP;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun /* for HCDs */
85*4882a593Smuzhiyun static inline int
otg_set_host(struct usb_otg * otg,struct usb_bus * host)86*4882a593Smuzhiyun otg_set_host(struct usb_otg *otg, struct usb_bus *host)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun if (otg && otg->set_host)
89*4882a593Smuzhiyun return otg->set_host(otg, host);
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun return -ENOTSUPP;
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun /* for usb peripheral controller drivers */
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun /* Context: can sleep */
97*4882a593Smuzhiyun static inline int
otg_set_peripheral(struct usb_otg * otg,struct usb_gadget * periph)98*4882a593Smuzhiyun otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun if (otg && otg->set_peripheral)
101*4882a593Smuzhiyun return otg->set_peripheral(otg, periph);
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun return -ENOTSUPP;
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun static inline int
otg_start_srp(struct usb_otg * otg)107*4882a593Smuzhiyun otg_start_srp(struct usb_otg *otg)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun if (otg && otg->start_srp)
110*4882a593Smuzhiyun return otg->start_srp(otg);
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun return -ENOTSUPP;
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /* for OTG controller drivers (and maybe other stuff) */
116*4882a593Smuzhiyun extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun enum usb_dr_mode {
119*4882a593Smuzhiyun USB_DR_MODE_UNKNOWN,
120*4882a593Smuzhiyun USB_DR_MODE_HOST,
121*4882a593Smuzhiyun USB_DR_MODE_PERIPHERAL,
122*4882a593Smuzhiyun USB_DR_MODE_OTG,
123*4882a593Smuzhiyun };
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /**
126*4882a593Smuzhiyun * usb_get_dr_mode - Get dual role mode for given device
127*4882a593Smuzhiyun * @dev: Pointer to the given device
128*4882a593Smuzhiyun *
129*4882a593Smuzhiyun * The function gets phy interface string from property 'dr_mode',
130*4882a593Smuzhiyun * and returns the correspondig enum usb_dr_mode
131*4882a593Smuzhiyun */
132*4882a593Smuzhiyun extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun #endif /* __LINUX_USB_OTG_H */
135