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