blob: edc51be4a77c6d80b3ef5643ed4b4fb883368517 [file] [log] [blame]
Heikki Krogerusfde0aa62018-03-20 15:57:04 +03001// 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
8struct usb_role_switch;
9
10enum usb_role {
11 USB_ROLE_NONE,
12 USB_ROLE_HOST,
13 USB_ROLE_DEVICE,
14};
15
16typedef int (*usb_role_switch_set_t)(struct device *dev, enum usb_role role);
17typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev);
18
19/**
20 * struct usb_role_switch_desc - USB Role Switch Descriptor
21 * @usb2_port: Optional reference to the host controller port device (USB2)
22 * @usb3_port: Optional reference to the host controller port device (USB3)
23 * @udc: Optional reference to the peripheral controller device
24 * @set: Callback for setting the role
25 * @get: Callback for getting the role (optional)
26 * @allow_userspace_control: If true userspace may change the role through sysfs
27 *
28 * @usb2_port and @usb3_port will point to the USB host port and @udc to the USB
29 * device controller behind the USB connector with the role switch. If
30 * @usb2_port, @usb3_port and @udc are included in the description, the
31 * reference count for them should be incremented by the caller of
32 * usb_role_switch_register() before registering the switch.
33 */
34struct usb_role_switch_desc {
35 struct device *usb2_port;
36 struct device *usb3_port;
37 struct device *udc;
38 usb_role_switch_set_t set;
39 usb_role_switch_get_t get;
40 bool allow_userspace_control;
41};
42
43int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role);
44enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw);
45struct usb_role_switch *usb_role_switch_get(struct device *dev);
46void usb_role_switch_put(struct usb_role_switch *sw);
47
48struct usb_role_switch *
49usb_role_switch_register(struct device *parent,
50 const struct usb_role_switch_desc *desc);
51void usb_role_switch_unregister(struct usb_role_switch *sw);
52
53#endif /* __LINUX_USB_ROLE_H */