1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#ifndef __LINUX_CLASS_DUAL_ROLE_H__
#define __LINUX_CLASS_DUAL_ROLE_H__
#include <linux/workqueue.h>
#include <linux/errno.h>
#include <linux/types.h>
struct device;
enum dual_role_supported_modes {
DUAL_ROLE_SUPPORTED_MODES_DFP_AND_UFP = 0,
DUAL_ROLE_SUPPORTED_MODES_DFP,
DUAL_ROLE_SUPPORTED_MODES_UFP,
/*The following should be the last element*/
DUAL_ROLE_PROP_SUPPORTED_MODES_TOTAL,
};
enum {
DUAL_ROLE_PROP_MODE_UFP = 0,
DUAL_ROLE_PROP_MODE_DFP,
DUAL_ROLE_PROP_MODE_NONE,
/*The following should be the last element*/
DUAL_ROLE_PROP_MODE_TOTAL,
};
enum {
DUAL_ROLE_PROP_PR_SRC = 0,
DUAL_ROLE_PROP_PR_SNK,
DUAL_ROLE_PROP_PR_NONE,
/*The following should be the last element*/
DUAL_ROLE_PROP_PR_TOTAL,
};
enum {
DUAL_ROLE_PROP_DR_HOST = 0,
DUAL_ROLE_PROP_DR_DEVICE,
DUAL_ROLE_PROP_DR_NONE,
/*The following should be the last element*/
DUAL_ROLE_PROP_DR_TOTAL,
};
enum {
DUAL_ROLE_PROP_VCONN_SUPPLY_NO = 0,
DUAL_ROLE_PROP_VCONN_SUPPLY_YES,
/*The following should be the last element*/
DUAL_ROLE_PROP_VCONN_SUPPLY_TOTAL,
};
enum dual_role_property {
DUAL_ROLE_PROP_SUPPORTED_MODES = 0,
DUAL_ROLE_PROP_MODE,
DUAL_ROLE_PROP_PR,
DUAL_ROLE_PROP_DR,
DUAL_ROLE_PROP_VCONN_SUPPLY,
};
struct dual_role_phy_instance;
/* Description of typec port */
struct dual_role_phy_desc {
/* /sys/class/dual_role_usb/<name>/ */
const char *name;
enum dual_role_supported_modes supported_modes;
enum dual_role_property *properties;
size_t num_properties;
/* Callback for "cat /sys/class/dual_role_usb/<name>/<property>" */
int (*get_property)(struct dual_role_phy_instance *dual_role,
enum dual_role_property prop,
unsigned int *val);
/* Callback for "echo <value> >
* /sys/class/dual_role_usb/<name>/<property>" */
int (*set_property)(struct dual_role_phy_instance *dual_role,
enum dual_role_property prop,
const unsigned int *val);
/* Decides whether userspace can change a specific property */
int (*property_is_writeable)(struct dual_role_phy_instance *dual_role,
enum dual_role_property prop);
};
struct dual_role_phy_instance {
const struct dual_role_phy_desc *desc;
/* Driver private data */
void *drv_data;
struct device dev;
struct work_struct changed_work;
};
#if IS_ENABLED(CONFIG_DUAL_ROLE_USB_INTF)
extern void dual_role_instance_changed(struct dual_role_phy_instance
*dual_role);
extern struct dual_role_phy_instance *__must_check
devm_dual_role_instance_register(struct device *parent,
const struct dual_role_phy_desc *desc);
extern void devm_dual_role_instance_unregister(struct device *dev,
struct dual_role_phy_instance
*dual_role);
extern int dual_role_get_property(struct dual_role_phy_instance *dual_role,
enum dual_role_property prop,
unsigned int *val);
extern int dual_role_set_property(struct dual_role_phy_instance *dual_role,
enum dual_role_property prop,
const unsigned int *val);
extern int dual_role_property_is_writeable(struct dual_role_phy_instance
*dual_role,
enum dual_role_property prop);
extern void *dual_role_get_drvdata(struct dual_role_phy_instance *dual_role);
#else /* CONFIG_DUAL_ROLE_USB_INTF */
static void dual_role_instance_changed(struct dual_role_phy_instance
*dual_role){}
static struct dual_role_phy_instance *__must_check
devm_dual_role_instance_register(struct device *parent,
const struct dual_role_phy_desc *desc)
{
return ERR_PTR(-ENOSYS);
}
static void devm_dual_role_instance_unregister(struct device *dev,
struct dual_role_phy_instance
*dual_role){}
static void *dual_role_get_drvdata(struct dual_role_phy_instance *dual_role)
{
return ERR_PTR(-ENOSYS);
}
#endif /* CONFIG_DUAL_ROLE_USB_INTF */
#endif /* __LINUX_CLASS_DUAL_ROLE_H__ */
|