1 #ifndef __LINUX_CLASS_DUAL_ROLE_H__
2 #define __LINUX_CLASS_DUAL_ROLE_H__
4 #include <linux/workqueue.h>
5 #include <linux/errno.h>
6 #include <linux/types.h>
10 enum dual_role_supported_modes {
11 DUAL_ROLE_SUPPORTED_MODES_DFP_AND_UFP = 0,
12 DUAL_ROLE_SUPPORTED_MODES_DFP,
13 DUAL_ROLE_SUPPORTED_MODES_UFP,
14 /*The following should be the last element*/
15 DUAL_ROLE_PROP_SUPPORTED_MODES_TOTAL,
19 DUAL_ROLE_PROP_MODE_UFP = 0,
20 DUAL_ROLE_PROP_MODE_DFP,
21 DUAL_ROLE_PROP_MODE_NONE,
22 /*The following should be the last element*/
23 DUAL_ROLE_PROP_MODE_TOTAL,
27 DUAL_ROLE_PROP_PR_SRC = 0,
28 DUAL_ROLE_PROP_PR_SNK,
29 DUAL_ROLE_PROP_PR_NONE,
30 /*The following should be the last element*/
31 DUAL_ROLE_PROP_PR_TOTAL,
36 DUAL_ROLE_PROP_DR_HOST = 0,
37 DUAL_ROLE_PROP_DR_DEVICE,
38 DUAL_ROLE_PROP_DR_NONE,
39 /*The following should be the last element*/
40 DUAL_ROLE_PROP_DR_TOTAL,
44 DUAL_ROLE_PROP_VCONN_SUPPLY_NO = 0,
45 DUAL_ROLE_PROP_VCONN_SUPPLY_YES,
46 /*The following should be the last element*/
47 DUAL_ROLE_PROP_VCONN_SUPPLY_TOTAL,
50 enum dual_role_property {
51 DUAL_ROLE_PROP_SUPPORTED_MODES = 0,
55 DUAL_ROLE_PROP_VCONN_SUPPLY,
58 struct dual_role_phy_instance;
60 /* Description of typec port */
61 struct dual_role_phy_desc {
62 /* /sys/class/dual_role_usb/<name>/ */
64 enum dual_role_supported_modes supported_modes;
65 enum dual_role_property *properties;
66 size_t num_properties;
68 /* Callback for "cat /sys/class/dual_role_usb/<name>/<property>" */
69 int (*get_property)(struct dual_role_phy_instance *dual_role,
70 enum dual_role_property prop,
72 /* Callback for "echo <value> >
73 * /sys/class/dual_role_usb/<name>/<property>" */
74 int (*set_property)(struct dual_role_phy_instance *dual_role,
75 enum dual_role_property prop,
76 const unsigned int *val);
77 /* Decides whether userspace can change a specific property */
78 int (*property_is_writeable)(struct dual_role_phy_instance *dual_role,
79 enum dual_role_property prop);
82 struct dual_role_phy_instance {
83 const struct dual_role_phy_desc *desc;
85 /* Driver private data */
89 struct work_struct changed_work;
92 #if IS_ENABLED(CONFIG_DUAL_ROLE_USB_INTF)
93 extern void dual_role_instance_changed(struct dual_role_phy_instance
95 extern struct dual_role_phy_instance *__must_check
96 devm_dual_role_instance_register(struct device *parent,
97 const struct dual_role_phy_desc *desc);
98 extern void devm_dual_role_instance_unregister(struct device *dev,
99 struct dual_role_phy_instance
101 extern int dual_role_get_property(struct dual_role_phy_instance *dual_role,
102 enum dual_role_property prop,
104 extern int dual_role_set_property(struct dual_role_phy_instance *dual_role,
105 enum dual_role_property prop,
106 const unsigned int *val);
107 extern int dual_role_property_is_writeable(struct dual_role_phy_instance
109 enum dual_role_property prop);
110 extern void *dual_role_get_drvdata(struct dual_role_phy_instance *dual_role);
111 #else /* CONFIG_DUAL_ROLE_USB_INTF */
112 static void dual_role_instance_changed(struct dual_role_phy_instance
114 static struct dual_role_phy_instance *__must_check
115 devm_dual_role_instance_register(struct device *parent,
116 const struct dual_role_phy_desc *desc)
118 return ERR_PTR(-ENOSYS);
120 static void devm_dual_role_instance_unregister(struct device *dev,
121 struct dual_role_phy_instance
123 static void *dual_role_get_drvdata(struct dual_role_phy_instance *dual_role)
125 return ERR_PTR(-ENOSYS);
127 #endif /* CONFIG_DUAL_ROLE_USB_INTF */
128 #endif /* __LINUX_CLASS_DUAL_ROLE_H__ */