hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/include/linux/usb/role.h
....@@ -13,17 +13,21 @@
1313 USB_ROLE_DEVICE,
1414 };
1515
16
-typedef int (*usb_role_switch_set_t)(struct device *dev, enum usb_role role);
17
-typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev);
16
+typedef int (*usb_role_switch_set_t)(struct usb_role_switch *sw,
17
+ enum usb_role role);
18
+typedef enum usb_role (*usb_role_switch_get_t)(struct usb_role_switch *sw);
1819
1920 /**
2021 * struct usb_role_switch_desc - USB Role Switch Descriptor
22
+ * @fwnode: The device node to be associated with the role switch
2123 * @usb2_port: Optional reference to the host controller port device (USB2)
2224 * @usb3_port: Optional reference to the host controller port device (USB3)
2325 * @udc: Optional reference to the peripheral controller device
2426 * @set: Callback for setting the role
2527 * @get: Callback for getting the role (optional)
2628 * @allow_userspace_control: If true userspace may change the role through sysfs
29
+ * @driver_data: Private data pointer
30
+ * @name: Name for the switch (optional)
2731 *
2832 * @usb2_port and @usb3_port will point to the USB host port and @udc to the USB
2933 * device controller behind the USB connector with the role switch. If
....@@ -32,22 +36,85 @@
3236 * usb_role_switch_register() before registering the switch.
3337 */
3438 struct usb_role_switch_desc {
39
+ struct fwnode_handle *fwnode;
3540 struct device *usb2_port;
3641 struct device *usb3_port;
3742 struct device *udc;
3843 usb_role_switch_set_t set;
3944 usb_role_switch_get_t get;
4045 bool allow_userspace_control;
46
+ void *driver_data;
47
+ const char *name;
4148 };
4249
50
+
51
+#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
4352 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role);
4453 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw);
4554 struct usb_role_switch *usb_role_switch_get(struct device *dev);
55
+struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *node);
4656 void usb_role_switch_put(struct usb_role_switch *sw);
57
+
58
+struct usb_role_switch *
59
+usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode);
4760
4861 struct usb_role_switch *
4962 usb_role_switch_register(struct device *parent,
5063 const struct usb_role_switch_desc *desc);
5164 void usb_role_switch_unregister(struct usb_role_switch *sw);
5265
66
+void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data);
67
+void *usb_role_switch_get_drvdata(struct usb_role_switch *sw);
68
+#else
69
+static inline int usb_role_switch_set_role(struct usb_role_switch *sw,
70
+ enum usb_role role)
71
+{
72
+ return 0;
73
+}
74
+
75
+static inline enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
76
+{
77
+ return USB_ROLE_NONE;
78
+}
79
+
80
+static inline struct usb_role_switch *usb_role_switch_get(struct device *dev)
81
+{
82
+ return ERR_PTR(-ENODEV);
83
+}
84
+
85
+static inline struct usb_role_switch *
86
+fwnode_usb_role_switch_get(struct fwnode_handle *node)
87
+{
88
+ return ERR_PTR(-ENODEV);
89
+}
90
+
91
+static inline void usb_role_switch_put(struct usb_role_switch *sw) { }
92
+
93
+static inline struct usb_role_switch *
94
+usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode)
95
+{
96
+ return NULL;
97
+}
98
+
99
+static inline struct usb_role_switch *
100
+usb_role_switch_register(struct device *parent,
101
+ const struct usb_role_switch_desc *desc)
102
+{
103
+ return ERR_PTR(-ENODEV);
104
+}
105
+
106
+static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }
107
+
108
+static inline void
109
+usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
110
+{
111
+}
112
+
113
+static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
114
+{
115
+ return NULL;
116
+}
117
+
118
+#endif
119
+
53120 #endif /* __LINUX_USB_ROLE_H */