• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __LINUX_CLASS_DUAL_ROLE_H__
2 #define __LINUX_CLASS_DUAL_ROLE_H__
3 
4 #include <linux/workqueue.h>
5 #include <linux/errno.h>
6 #include <linux/types.h>
7 
8 struct device;
9 
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,
16 };
17 
18 enum {
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,
24 };
25 
26 enum {
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,
32 
33 };
34 
35 enum {
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,
41 };
42 
43 enum {
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,
48 };
49 
50 enum dual_role_property {
51 	DUAL_ROLE_PROP_SUPPORTED_MODES = 0,
52 	DUAL_ROLE_PROP_MODE,
53 	DUAL_ROLE_PROP_PR,
54 	DUAL_ROLE_PROP_DR,
55 	DUAL_ROLE_PROP_VCONN_SUPPLY,
56 };
57 
58 struct dual_role_phy_instance;
59 
60 /* Description of typec port */
61 struct dual_role_phy_desc {
62 	/* /sys/class/dual_role_usb/<name>/ */
63 	const char *name;
64 	enum dual_role_supported_modes supported_modes;
65 	enum dual_role_property *properties;
66 	size_t num_properties;
67 
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,
71 			     unsigned int *val);
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);
80 };
81 
82 struct dual_role_phy_instance {
83 	const struct dual_role_phy_desc *desc;
84 
85 	/* Driver private data */
86 	void *drv_data;
87 
88 	struct device dev;
89 	struct work_struct changed_work;
90 };
91 
92 #if IS_ENABLED(CONFIG_DUAL_ROLE_USB_INTF)
93 extern void dual_role_instance_changed(struct dual_role_phy_instance
94 				       *dual_role);
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
100 					       *dual_role);
101 extern int dual_role_get_property(struct dual_role_phy_instance *dual_role,
102 				  enum dual_role_property prop,
103 				  unsigned int *val);
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
108 					   *dual_role,
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 */
dual_role_instance_changed(struct dual_role_phy_instance * dual_role)112 static inline void dual_role_instance_changed(struct dual_role_phy_instance
113 				       *dual_role){}
114 static inline struct dual_role_phy_instance *__must_check
devm_dual_role_instance_register(struct device * parent,const struct dual_role_phy_desc * desc)115 devm_dual_role_instance_register(struct device *parent,
116 				 const struct dual_role_phy_desc *desc)
117 {
118 	return ERR_PTR(-ENOSYS);
119 }
devm_dual_role_instance_unregister(struct device * dev,struct dual_role_phy_instance * dual_role)120 static inline void devm_dual_role_instance_unregister(struct device *dev,
121 					       struct dual_role_phy_instance
122 					       *dual_role){}
dual_role_get_drvdata(struct dual_role_phy_instance * dual_role)123 static inline void *dual_role_get_drvdata(struct dual_role_phy_instance
124 		*dual_role)
125 {
126 	return ERR_PTR(-ENOSYS);
127 }
128 #endif /* CONFIG_DUAL_ROLE_USB_INTF */
129 #endif /* __LINUX_CLASS_DUAL_ROLE_H__ */
130