1
2
3#ifndef __LINUX_USB_TYPEC_H
4#define __LINUX_USB_TYPEC_H
5
6#include <linux/types.h>
7
8
9#define USB_TYPEC_REV_1_0 0x100
10#define USB_TYPEC_REV_1_1 0x110
11#define USB_TYPEC_REV_1_2 0x120
12
13struct typec_partner;
14struct typec_cable;
15struct typec_plug;
16struct typec_port;
17
18struct fwnode_handle;
19struct device;
20
21enum typec_port_type {
22 TYPEC_PORT_SRC,
23 TYPEC_PORT_SNK,
24 TYPEC_PORT_DRP,
25};
26
27enum typec_port_data {
28 TYPEC_PORT_DFP,
29 TYPEC_PORT_UFP,
30 TYPEC_PORT_DRD,
31};
32
33enum typec_plug_type {
34 USB_PLUG_NONE,
35 USB_PLUG_TYPE_A,
36 USB_PLUG_TYPE_B,
37 USB_PLUG_TYPE_C,
38 USB_PLUG_CAPTIVE,
39};
40
41enum typec_data_role {
42 TYPEC_DEVICE,
43 TYPEC_HOST,
44};
45
46enum typec_role {
47 TYPEC_SINK,
48 TYPEC_SOURCE,
49};
50
51enum typec_pwr_opmode {
52 TYPEC_PWR_MODE_USB,
53 TYPEC_PWR_MODE_1_5A,
54 TYPEC_PWR_MODE_3_0A,
55 TYPEC_PWR_MODE_PD,
56};
57
58enum typec_accessory {
59 TYPEC_ACCESSORY_NONE,
60 TYPEC_ACCESSORY_AUDIO,
61 TYPEC_ACCESSORY_DEBUG,
62};
63
64#define TYPEC_MAX_ACCESSORY 3
65
66enum typec_orientation {
67 TYPEC_ORIENTATION_NONE,
68 TYPEC_ORIENTATION_NORMAL,
69 TYPEC_ORIENTATION_REVERSE,
70};
71
72
73
74
75
76
77
78
79
80
81
82
83struct usb_pd_identity {
84 u32 id_header;
85 u32 cert_stat;
86 u32 product;
87};
88
89int typec_partner_set_identity(struct typec_partner *partner);
90int typec_cable_set_identity(struct typec_cable *cable);
91
92
93
94
95
96
97
98
99
100
101
102struct typec_altmode_desc {
103 u16 svid;
104 u8 mode;
105 u32 vdo;
106
107 enum typec_port_data roles;
108};
109
110struct typec_altmode
111*typec_partner_register_altmode(struct typec_partner *partner,
112 const struct typec_altmode_desc *desc);
113struct typec_altmode
114*typec_plug_register_altmode(struct typec_plug *plug,
115 const struct typec_altmode_desc *desc);
116struct typec_altmode
117*typec_port_register_altmode(struct typec_port *port,
118 const struct typec_altmode_desc *desc);
119void typec_unregister_altmode(struct typec_altmode *altmode);
120
121struct typec_port *typec_altmode2port(struct typec_altmode *alt);
122
123void typec_altmode_update_active(struct typec_altmode *alt, bool active);
124
125enum typec_plug_index {
126 TYPEC_PLUG_SOP_P,
127 TYPEC_PLUG_SOP_PP,
128};
129
130
131
132
133
134
135
136
137struct typec_plug_desc {
138 enum typec_plug_index index;
139};
140
141
142
143
144
145
146
147
148
149struct typec_cable_desc {
150 enum typec_plug_type type;
151 unsigned int active:1;
152 struct usb_pd_identity *identity;
153};
154
155
156
157
158
159
160
161
162
163
164
165struct typec_partner_desc {
166 unsigned int usb_pd:1;
167 enum typec_accessory accessory;
168 struct usb_pd_identity *identity;
169};
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190struct typec_capability {
191 enum typec_port_type type;
192 enum typec_port_data data;
193 u16 revision;
194 u16 pd_revision;
195 int prefer_role;
196 enum typec_accessory accessory[TYPEC_MAX_ACCESSORY];
197
198 struct typec_switch *sw;
199 struct typec_mux *mux;
200 struct fwnode_handle *fwnode;
201
202 int (*try_role)(const struct typec_capability *,
203 int role);
204
205 int (*dr_set)(const struct typec_capability *,
206 enum typec_data_role);
207 int (*pr_set)(const struct typec_capability *,
208 enum typec_role);
209 int (*vconn_set)(const struct typec_capability *,
210 enum typec_role);
211 int (*port_type_set)(const struct typec_capability *,
212 enum typec_port_type);
213};
214
215
216#define TYPEC_NO_PREFERRED_ROLE (-1)
217
218struct typec_port *typec_register_port(struct device *parent,
219 const struct typec_capability *cap);
220void typec_unregister_port(struct typec_port *port);
221
222struct typec_partner *typec_register_partner(struct typec_port *port,
223 struct typec_partner_desc *desc);
224void typec_unregister_partner(struct typec_partner *partner);
225
226struct typec_cable *typec_register_cable(struct typec_port *port,
227 struct typec_cable_desc *desc);
228void typec_unregister_cable(struct typec_cable *cable);
229
230struct typec_plug *typec_register_plug(struct typec_cable *cable,
231 struct typec_plug_desc *desc);
232void typec_unregister_plug(struct typec_plug *plug);
233
234void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
235void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
236void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
237void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
238
239int typec_set_orientation(struct typec_port *port,
240 enum typec_orientation orientation);
241enum typec_orientation typec_get_orientation(struct typec_port *port);
242int typec_set_mode(struct typec_port *port, int mode);
243
244int typec_find_port_power_role(const char *name);
245int typec_find_power_role(const char *name);
246int typec_find_port_data_role(const char *name);
247#endif
248