~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/usb/role.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  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 usb_role_switch *sw,
 17                                      enum usb_role role);
 18 typedef enum usb_role (*usb_role_switch_get_t)(struct usb_role_switch *sw);
 19 
 20 /**
 21  * struct usb_role_switch_desc - USB Role Switch Descriptor
 22  * @fwnode: The device node to be associated with the role switch
 23  * @usb2_port: Optional reference to the host controller port device (USB2)
 24  * @usb3_port: Optional reference to the host controller port device (USB3)
 25  * @udc: Optional reference to the peripheral controller device
 26  * @set: Callback for setting the role
 27  * @get: Callback for getting the role (optional)
 28  * @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)
 31  *
 32  * @usb2_port and @usb3_port will point to the USB host port and @udc to the USB
 33  * device controller behind the USB connector with the role switch. If
 34  * @usb2_port, @usb3_port and @udc are included in the description, the
 35  * reference count for them should be incremented by the caller of
 36  * usb_role_switch_register() before registering the switch.
 37  */
 38 struct usb_role_switch_desc {
 39         struct fwnode_handle *fwnode;
 40         struct device *usb2_port;
 41         struct device *usb3_port;
 42         struct device *udc;
 43         usb_role_switch_set_t set;
 44         usb_role_switch_get_t get;
 45         bool allow_userspace_control;
 46         void *driver_data;
 47         const char *name;
 48 };
 49 
 50 
 51 #if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
 52 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role);
 53 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw);
 54 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);
 56 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);
 60 
 61 struct usb_role_switch *
 62 usb_role_switch_register(struct device *parent,
 63                          const struct usb_role_switch_desc *desc);
 64 void usb_role_switch_unregister(struct usb_role_switch *sw);
 65 
 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 const char *usb_role_string(enum usb_role role);
 69 #else
 70 static inline int usb_role_switch_set_role(struct usb_role_switch *sw,
 71                 enum usb_role role)
 72 {
 73         return 0;
 74 }
 75 
 76 static inline enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
 77 {
 78         return USB_ROLE_NONE;
 79 }
 80 
 81 static inline struct usb_role_switch *usb_role_switch_get(struct device *dev)
 82 {
 83         return ERR_PTR(-ENODEV);
 84 }
 85 
 86 static inline struct usb_role_switch *
 87 fwnode_usb_role_switch_get(struct fwnode_handle *node)
 88 {
 89         return ERR_PTR(-ENODEV);
 90 }
 91 
 92 static inline void usb_role_switch_put(struct usb_role_switch *sw) { }
 93 
 94 static inline struct usb_role_switch *
 95 usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode)
 96 {
 97         return NULL;
 98 }
 99 
100 static inline struct usb_role_switch *
101 usb_role_switch_register(struct device *parent,
102                          const struct usb_role_switch_desc *desc)
103 {
104         return ERR_PTR(-ENODEV);
105 }
106 
107 static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }
108 
109 static inline void
110 usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
111 {
112 }
113 
114 static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
115 {
116         return NULL;
117 }
118 
119 static inline const char *usb_role_string(enum usb_role role)
120 {
121         return "unknown";
122 }
123 
124 #endif
125 
126 #endif /* __LINUX_USB_ROLE_H */
127 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php