0001
0002
0003 #ifndef __LINUX_USB_ROLE_H
0004 #define __LINUX_USB_ROLE_H
0005
0006 #include <linux/device.h>
0007
0008 struct usb_role_switch;
0009
0010 enum usb_role {
0011 USB_ROLE_NONE,
0012 USB_ROLE_HOST,
0013 USB_ROLE_DEVICE,
0014 };
0015
0016 typedef int (*usb_role_switch_set_t)(struct usb_role_switch *sw,
0017 enum usb_role role);
0018 typedef enum usb_role (*usb_role_switch_get_t)(struct usb_role_switch *sw);
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 struct usb_role_switch_desc {
0039 struct fwnode_handle *fwnode;
0040 struct device *usb2_port;
0041 struct device *usb3_port;
0042 struct device *udc;
0043 usb_role_switch_set_t set;
0044 usb_role_switch_get_t get;
0045 bool allow_userspace_control;
0046 void *driver_data;
0047 const char *name;
0048 };
0049
0050
0051 #if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
0052 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role);
0053 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw);
0054 struct usb_role_switch *usb_role_switch_get(struct device *dev);
0055 struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *node);
0056 void usb_role_switch_put(struct usb_role_switch *sw);
0057
0058 struct usb_role_switch *
0059 usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode);
0060
0061 struct usb_role_switch *
0062 usb_role_switch_register(struct device *parent,
0063 const struct usb_role_switch_desc *desc);
0064 void usb_role_switch_unregister(struct usb_role_switch *sw);
0065
0066 void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data);
0067 void *usb_role_switch_get_drvdata(struct usb_role_switch *sw);
0068 const char *usb_role_string(enum usb_role role);
0069 #else
0070 static inline int usb_role_switch_set_role(struct usb_role_switch *sw,
0071 enum usb_role role)
0072 {
0073 return 0;
0074 }
0075
0076 static inline enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
0077 {
0078 return USB_ROLE_NONE;
0079 }
0080
0081 static inline struct usb_role_switch *usb_role_switch_get(struct device *dev)
0082 {
0083 return ERR_PTR(-ENODEV);
0084 }
0085
0086 static inline struct usb_role_switch *
0087 fwnode_usb_role_switch_get(struct fwnode_handle *node)
0088 {
0089 return ERR_PTR(-ENODEV);
0090 }
0091
0092 static inline void usb_role_switch_put(struct usb_role_switch *sw) { }
0093
0094 static inline struct usb_role_switch *
0095 usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode)
0096 {
0097 return NULL;
0098 }
0099
0100 static inline struct usb_role_switch *
0101 usb_role_switch_register(struct device *parent,
0102 const struct usb_role_switch_desc *desc)
0103 {
0104 return ERR_PTR(-ENODEV);
0105 }
0106
0107 static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }
0108
0109 static inline void
0110 usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
0111 {
0112 }
0113
0114 static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
0115 {
0116 return NULL;
0117 }
0118
0119 static inline const char *usb_role_string(enum usb_role role)
0120 {
0121 return "unknown";
0122 }
0123
0124 #endif
0125
0126 #endif