1
2
3 #ifndef __LINUX_USB_ROLE_H
4 #define __LINUX_USB_ROLE_H
5
6 #include <linux/device.h>
7
8 struct usb_role_switch;
9
10 enum usb_role {
11 USB_ROLE_NONE,
12 USB_ROLE_HOST,
13 USB_ROLE_DEVICE,
14 };
15
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);
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 struct usb_role_switch_desc {
36 struct fwnode_handle *fwnode;
37 struct device *usb2_port;
38 struct device *usb3_port;
39 struct device *udc;
40 usb_role_switch_set_t set;
41 usb_role_switch_get_t get;
42 bool allow_userspace_control;
43 };
44
45
46 #if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
47 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role);
48 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw);
49 struct usb_role_switch *usb_role_switch_get(struct device *dev);
50 struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *node);
51 void usb_role_switch_put(struct usb_role_switch *sw);
52
53 struct usb_role_switch *
54 usb_role_switch_register(struct device *parent,
55 const struct usb_role_switch_desc *desc);
56 void usb_role_switch_unregister(struct usb_role_switch *sw);
57 #else
58 static inline int usb_role_switch_set_role(struct usb_role_switch *sw,
59 enum usb_role role)
60 {
61 return 0;
62 }
63
64 static inline enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
65 {
66 return USB_ROLE_NONE;
67 }
68
69 static inline struct usb_role_switch *usb_role_switch_get(struct device *dev)
70 {
71 return ERR_PTR(-ENODEV);
72 }
73
74 static inline struct usb_role_switch *
75 fwnode_usb_role_switch_get(struct fwnode_handle *node)
76 {
77 return ERR_PTR(-ENODEV);
78 }
79
80 static inline void usb_role_switch_put(struct usb_role_switch *sw) { }
81
82 static inline struct usb_role_switch *
83 usb_role_switch_register(struct device *parent,
84 const struct usb_role_switch_desc *desc)
85 {
86 return ERR_PTR(-ENODEV);
87 }
88
89 static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }
90 #endif
91
92 #endif