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 /* OTG defines lots of enumeration states before device reset */ 14 #include <linux/usb/phy.h> !! 13 enum usb_otg_state { >> 14 OTG_STATE_UNDEFINED = 0, >> 15 >> 16 /* single-role peripheral, and dual-role default-b */ >> 17 OTG_STATE_B_IDLE, >> 18 OTG_STATE_B_SRP_INIT, >> 19 OTG_STATE_B_PERIPHERAL, >> 20 >> 21 /* extra dual-role default-b states */ >> 22 OTG_STATE_B_WAIT_ACON, >> 23 OTG_STATE_B_HOST, >> 24 >> 25 /* dual-role default-a */ >> 26 OTG_STATE_A_IDLE, >> 27 OTG_STATE_A_WAIT_VRISE, >> 28 OTG_STATE_A_WAIT_BCON, >> 29 OTG_STATE_A_HOST, >> 30 OTG_STATE_A_SUSPEND, >> 31 OTG_STATE_A_PERIPHERAL, >> 32 OTG_STATE_A_WAIT_VFALL, >> 33 OTG_STATE_A_VBUS_ERR, >> 34 }; >> 35 >> 36 /* >> 37 * the otg driver needs to interact with both device side and host side >> 38 * usb controllers. it decides which controller is active at a given >> 39 * moment, using the transceiver, ID signal, HNP and sometimes static >> 40 * configuration information (including "board isn't wired for otg"). >> 41 */ >> 42 struct otg_transceiver { >> 43 struct device *dev; >> 44 const char *label; 15 45 16 struct usb_otg { << 17 u8 default_a; 46 u8 default_a; >> 47 enum usb_otg_state state; 18 48 19 struct phy *phy; << 20 /* old usb_phy interface */ << 21 struct usb_phy *usb_phy; << 22 struct usb_bus *host; 49 struct usb_bus *host; 23 struct usb_gadget *gadget; 50 struct usb_gadget *gadget; 24 51 25 enum usb_otg_state state; !! 52 /* to pass extra port status to the root hub */ >> 53 u16 port_status; >> 54 u16 port_change; 26 55 27 /* bind/unbind the host controller */ 56 /* bind/unbind the host controller */ 28 int (*set_host)(struct usb_otg *ot !! 57 int (*set_host)(struct otg_transceiver *otg, >> 58 struct usb_bus *host); 29 59 30 /* bind/unbind the peripheral controll 60 /* bind/unbind the peripheral controller */ 31 int (*set_peripheral)(struct usb_o !! 61 int (*set_peripheral)(struct otg_transceiver *otg, 32 struct !! 62 struct usb_gadget *gadget); 33 63 34 /* effective for A-peripheral, ignored !! 64 /* effective for B devices, ignored for A-peripheral */ 35 int (*set_vbus)(struct usb_otg *ot !! 65 int (*set_power)(struct otg_transceiver *otg, >> 66 unsigned mA); >> 67 >> 68 /* for non-OTG B devices: set transceiver into suspend mode */ >> 69 int (*set_suspend)(struct otg_transceiver *otg, >> 70 int suspend); 36 71 37 /* for B devices only: start session 72 /* for B devices only: start session with A-Host */ 38 int (*start_srp)(struct usb_otg *o !! 73 int (*start_srp)(struct otg_transceiver *otg); 39 74 40 /* start or continue HNP role switch * 75 /* start or continue HNP role switch */ 41 int (*start_hnp)(struct usb_otg *o !! 76 int (*start_hnp)(struct otg_transceiver *otg); 42 77 43 }; 78 }; 44 79 45 /** << 46 * struct usb_otg_caps - describes the otg cap << 47 * @otg_rev: The OTG revision number the devic << 48 * in binary-coded decimal (i.e. << 49 * @hnp_support: Indicates if the device suppo << 50 * @srp_support: Indicates if the device suppo << 51 * @adp_support: Indicates if the device suppo << 52 */ << 53 struct usb_otg_caps { << 54 u16 otg_rev; << 55 bool hnp_support; << 56 bool srp_support; << 57 bool adp_support; << 58 }; << 59 80 60 extern const char *usb_otg_state_string(enum u !! 81 /* for board-specific init logic */ >> 82 extern int otg_set_transceiver(struct otg_transceiver *); 61 83 62 /* Context: can sleep */ !! 84 /* sometimes transceivers are accessed only through e.g. ULPI */ 63 static inline int !! 85 extern void usb_nop_xceiv_register(void); 64 otg_start_hnp(struct usb_otg *otg) !! 86 extern void usb_nop_xceiv_unregister(void); 65 { << 66 if (otg && otg->start_hnp) << 67 return otg->start_hnp(otg); << 68 87 69 return -ENOTSUPP; !! 88 70 } !! 89 /* for usb host and peripheral controller drivers */ >> 90 extern struct otg_transceiver *otg_get_transceiver(void); >> 91 extern void otg_put_transceiver(struct otg_transceiver *); 71 92 72 /* Context: can sleep */ 93 /* Context: can sleep */ 73 static inline int 94 static inline int 74 otg_set_vbus(struct usb_otg *otg, bool enabled !! 95 otg_start_hnp(struct otg_transceiver *otg) 75 { 96 { 76 if (otg && otg->set_vbus) !! 97 return otg->start_hnp(otg); 77 return otg->set_vbus(otg, enab << 78 << 79 return -ENOTSUPP; << 80 } 98 } 81 99 >> 100 82 /* for HCDs */ 101 /* for HCDs */ 83 static inline int 102 static inline int 84 otg_set_host(struct usb_otg *otg, struct usb_b !! 103 otg_set_host(struct otg_transceiver *otg, struct usb_bus *host) 85 { 104 { 86 if (otg && otg->set_host) !! 105 return otg->set_host(otg, host); 87 return otg->set_host(otg, host << 88 << 89 return -ENOTSUPP; << 90 } 106 } 91 107 >> 108 92 /* for usb peripheral controller drivers */ 109 /* for usb peripheral controller drivers */ 93 110 94 /* Context: can sleep */ 111 /* Context: can sleep */ 95 static inline int 112 static inline int 96 otg_set_peripheral(struct usb_otg *otg, struct !! 113 otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph) 97 { 114 { 98 if (otg && otg->set_peripheral) !! 115 return otg->set_peripheral(otg, periph); 99 return otg->set_peripheral(otg !! 116 } 100 117 101 return -ENOTSUPP; !! 118 static inline int >> 119 otg_set_power(struct otg_transceiver *otg, unsigned mA) >> 120 { >> 121 return otg->set_power(otg, mA); 102 } 122 } 103 123 >> 124 /* Context: can sleep */ 104 static inline int 125 static inline int 105 otg_start_srp(struct usb_otg *otg) !! 126 otg_set_suspend(struct otg_transceiver *otg, int suspend) 106 { 127 { 107 if (otg && otg->start_srp) !! 128 if (otg->set_suspend != NULL) 108 return otg->start_srp(otg); !! 129 return otg->set_suspend(otg, suspend); >> 130 else >> 131 return 0; >> 132 } 109 133 110 return -ENOTSUPP; !! 134 static inline int >> 135 otg_start_srp(struct otg_transceiver *otg) >> 136 { >> 137 return otg->start_srp(otg); 111 } 138 } 112 139 >> 140 113 /* for OTG controller drivers (and maybe other 141 /* for OTG controller drivers (and maybe other stuff) */ 114 extern int usb_bus_start_enum(struct usb_bus * 142 extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num); 115 << 116 enum usb_dr_mode { << 117 USB_DR_MODE_UNKNOWN, << 118 USB_DR_MODE_HOST, << 119 USB_DR_MODE_PERIPHERAL, << 120 USB_DR_MODE_OTG, << 121 }; << 122 << 123 /** << 124 * usb_get_dr_mode - Get dual role mode for gi << 125 * @dev: Pointer to the given device << 126 * << 127 * The function gets phy interface string from << 128 * and returns the corresponding enum usb_dr_m << 129 */ << 130 extern enum usb_dr_mode usb_get_dr_mode(struct << 131 extern enum usb_dr_mode usb_get_role_switch_de << 132 143 133 #endif /* __LINUX_USB_OTG_H */ 144 #endif /* __LINUX_USB_OTG_H */ 134 145
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.