Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* USB OTG (On The Go) defines */
0003 /*
0004  *
0005  * These APIs may be used between USB controllers.  USB device drivers
0006  * (for either host or peripheral roles) don't use these calls; they
0007  * continue to use just usb_device and usb_gadget.
0008  */
0009 
0010 #ifndef __LINUX_USB_OTG_H
0011 #define __LINUX_USB_OTG_H
0012 
0013 #include <linux/phy/phy.h>
0014 #include <linux/usb/phy.h>
0015 
0016 struct usb_otg {
0017     u8          default_a;
0018 
0019     struct phy      *phy;
0020     /* old usb_phy interface */
0021     struct usb_phy      *usb_phy;
0022     struct usb_bus      *host;
0023     struct usb_gadget   *gadget;
0024 
0025     enum usb_otg_state  state;
0026 
0027     /* bind/unbind the host controller */
0028     int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
0029 
0030     /* bind/unbind the peripheral controller */
0031     int (*set_peripheral)(struct usb_otg *otg,
0032                     struct usb_gadget *gadget);
0033 
0034     /* effective for A-peripheral, ignored for B devices */
0035     int (*set_vbus)(struct usb_otg *otg, bool enabled);
0036 
0037     /* for B devices only:  start session with A-Host */
0038     int (*start_srp)(struct usb_otg *otg);
0039 
0040     /* start or continue HNP role switch */
0041     int (*start_hnp)(struct usb_otg *otg);
0042 
0043 };
0044 
0045 /**
0046  * struct usb_otg_caps - describes the otg capabilities of the device
0047  * @otg_rev: The OTG revision number the device is compliant with, it's
0048  *      in binary-coded decimal (i.e. 2.0 is 0200H).
0049  * @hnp_support: Indicates if the device supports HNP.
0050  * @srp_support: Indicates if the device supports SRP.
0051  * @adp_support: Indicates if the device supports ADP.
0052  */
0053 struct usb_otg_caps {
0054     u16 otg_rev;
0055     bool hnp_support;
0056     bool srp_support;
0057     bool adp_support;
0058 };
0059 
0060 extern const char *usb_otg_state_string(enum usb_otg_state state);
0061 
0062 /* Context: can sleep */
0063 static inline int
0064 otg_start_hnp(struct usb_otg *otg)
0065 {
0066     if (otg && otg->start_hnp)
0067         return otg->start_hnp(otg);
0068 
0069     return -ENOTSUPP;
0070 }
0071 
0072 /* Context: can sleep */
0073 static inline int
0074 otg_set_vbus(struct usb_otg *otg, bool enabled)
0075 {
0076     if (otg && otg->set_vbus)
0077         return otg->set_vbus(otg, enabled);
0078 
0079     return -ENOTSUPP;
0080 }
0081 
0082 /* for HCDs */
0083 static inline int
0084 otg_set_host(struct usb_otg *otg, struct usb_bus *host)
0085 {
0086     if (otg && otg->set_host)
0087         return otg->set_host(otg, host);
0088 
0089     return -ENOTSUPP;
0090 }
0091 
0092 /* for usb peripheral controller drivers */
0093 
0094 /* Context: can sleep */
0095 static inline int
0096 otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
0097 {
0098     if (otg && otg->set_peripheral)
0099         return otg->set_peripheral(otg, periph);
0100 
0101     return -ENOTSUPP;
0102 }
0103 
0104 static inline int
0105 otg_start_srp(struct usb_otg *otg)
0106 {
0107     if (otg && otg->start_srp)
0108         return otg->start_srp(otg);
0109 
0110     return -ENOTSUPP;
0111 }
0112 
0113 /* for OTG controller drivers (and maybe other stuff) */
0114 extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
0115 
0116 enum usb_dr_mode {
0117     USB_DR_MODE_UNKNOWN,
0118     USB_DR_MODE_HOST,
0119     USB_DR_MODE_PERIPHERAL,
0120     USB_DR_MODE_OTG,
0121 };
0122 
0123 /**
0124  * usb_get_dr_mode - Get dual role mode for given device
0125  * @dev: Pointer to the given device
0126  *
0127  * The function gets phy interface string from property 'dr_mode',
0128  * and returns the corresponding enum usb_dr_mode
0129  */
0130 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
0131 extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev);
0132 
0133 #endif /* __LINUX_USB_OTG_H */