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#define USB_TYPEC_REV_1_3 0x130
13#define USB_TYPEC_REV_1_4 0x140
14#define USB_TYPEC_REV_2_0 0x200
15
16struct typec_partner;
17struct typec_cable;
18struct typec_plug;
19struct typec_port;
20struct typec_altmode_ops;
21
22struct fwnode_handle;
23struct device;
24
25enum typec_port_type {
26 TYPEC_PORT_SRC,
27 TYPEC_PORT_SNK,
28 TYPEC_PORT_DRP,
29};
30
31enum typec_port_data {
32 TYPEC_PORT_DFP,
33 TYPEC_PORT_UFP,
34 TYPEC_PORT_DRD,
35};
36
37enum typec_plug_type {
38 USB_PLUG_NONE,
39 USB_PLUG_TYPE_A,
40 USB_PLUG_TYPE_B,
41 USB_PLUG_TYPE_C,
42 USB_PLUG_CAPTIVE,
43};
44
45enum typec_data_role {
46 TYPEC_DEVICE,
47 TYPEC_HOST,
48};
49
50enum typec_role {
51 TYPEC_SINK,
52 TYPEC_SOURCE,
53};
54
55enum typec_pwr_opmode {
56 TYPEC_PWR_MODE_USB,
57 TYPEC_PWR_MODE_1_5A,
58 TYPEC_PWR_MODE_3_0A,
59 TYPEC_PWR_MODE_PD,
60};
61
62enum typec_accessory {
63 TYPEC_ACCESSORY_NONE,
64 TYPEC_ACCESSORY_AUDIO,
65 TYPEC_ACCESSORY_DEBUG,
66};
67
68#define TYPEC_MAX_ACCESSORY 3
69
70enum typec_orientation {
71 TYPEC_ORIENTATION_NONE,
72 TYPEC_ORIENTATION_NORMAL,
73 TYPEC_ORIENTATION_REVERSE,
74};
75
76
77
78
79
80
81
82
83
84
85struct enter_usb_data {
86 u32 eudo;
87 unsigned char active_link_training:1;
88};
89
90
91
92
93
94
95
96
97
98
99
100
101
102struct usb_pd_identity {
103 u32 id_header;
104 u32 cert_stat;
105 u32 product;
106 u32 vdo[3];
107};
108
109int typec_partner_set_identity(struct typec_partner *partner);
110int typec_cable_set_identity(struct typec_cable *cable);
111
112
113
114
115
116
117
118
119
120
121
122struct typec_altmode_desc {
123 u16 svid;
124 u8 mode;
125 u32 vdo;
126
127 enum typec_port_data roles;
128};
129
130void typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision);
131int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmodes);
132struct typec_altmode
133*typec_partner_register_altmode(struct typec_partner *partner,
134 const struct typec_altmode_desc *desc);
135int typec_plug_set_num_altmodes(struct typec_plug *plug, int num_altmodes);
136struct typec_altmode
137*typec_plug_register_altmode(struct typec_plug *plug,
138 const struct typec_altmode_desc *desc);
139struct typec_altmode
140*typec_port_register_altmode(struct typec_port *port,
141 const struct typec_altmode_desc *desc);
142
143void typec_port_register_altmodes(struct typec_port *port,
144 const struct typec_altmode_ops *ops, void *drvdata,
145 struct typec_altmode **altmodes, size_t n);
146
147void typec_unregister_altmode(struct typec_altmode *altmode);
148
149struct typec_port *typec_altmode2port(struct typec_altmode *alt);
150
151void typec_altmode_update_active(struct typec_altmode *alt, bool active);
152
153enum typec_plug_index {
154 TYPEC_PLUG_SOP_P,
155 TYPEC_PLUG_SOP_PP,
156};
157
158
159
160
161
162
163
164
165struct typec_plug_desc {
166 enum typec_plug_index index;
167};
168
169
170
171
172
173
174
175
176
177
178struct typec_cable_desc {
179 enum typec_plug_type type;
180 unsigned int active:1;
181 struct usb_pd_identity *identity;
182 u16 pd_revision;
183
184};
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202struct typec_partner_desc {
203 unsigned int usb_pd:1;
204 enum typec_accessory accessory;
205 struct usb_pd_identity *identity;
206 u16 pd_revision;
207};
208
209
210
211
212
213
214
215
216
217struct typec_operations {
218 int (*try_role)(struct typec_port *port, int role);
219 int (*dr_set)(struct typec_port *port, enum typec_data_role role);
220 int (*pr_set)(struct typec_port *port, enum typec_role role);
221 int (*vconn_set)(struct typec_port *port, enum typec_role role);
222 int (*port_type_set)(struct typec_port *port,
223 enum typec_port_type type);
224};
225
226enum usb_pd_svdm_ver {
227 SVDM_VER_1_0 = 0,
228 SVDM_VER_2_0 = 1,
229 SVDM_VER_MAX = SVDM_VER_2_0,
230};
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247struct typec_capability {
248 enum typec_port_type type;
249 enum typec_port_data data;
250 u16 revision;
251 u16 pd_revision;
252 enum usb_pd_svdm_ver svdm_version;
253 int prefer_role;
254 enum typec_accessory accessory[TYPEC_MAX_ACCESSORY];
255 unsigned int orientation_aware:1;
256
257 struct fwnode_handle *fwnode;
258 void *driver_data;
259
260 const struct typec_operations *ops;
261};
262
263
264#define TYPEC_NO_PREFERRED_ROLE (-1)
265
266struct typec_port *typec_register_port(struct device *parent,
267 const struct typec_capability *cap);
268void typec_unregister_port(struct typec_port *port);
269
270struct typec_partner *typec_register_partner(struct typec_port *port,
271 struct typec_partner_desc *desc);
272void typec_unregister_partner(struct typec_partner *partner);
273
274struct typec_cable *typec_register_cable(struct typec_port *port,
275 struct typec_cable_desc *desc);
276void typec_unregister_cable(struct typec_cable *cable);
277
278struct typec_cable *typec_cable_get(struct typec_port *port);
279void typec_cable_put(struct typec_cable *cable);
280int typec_cable_is_active(struct typec_cable *cable);
281
282struct typec_plug *typec_register_plug(struct typec_cable *cable,
283 struct typec_plug_desc *desc);
284void typec_unregister_plug(struct typec_plug *plug);
285
286void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
287void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
288void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
289void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
290
291int typec_set_orientation(struct typec_port *port,
292 enum typec_orientation orientation);
293enum typec_orientation typec_get_orientation(struct typec_port *port);
294int typec_set_mode(struct typec_port *port, int mode);
295
296void *typec_get_drvdata(struct typec_port *port);
297
298int typec_find_pwr_opmode(const char *name);
299int typec_find_orientation(const char *name);
300int typec_find_port_power_role(const char *name);
301int typec_find_power_role(const char *name);
302int typec_find_port_data_role(const char *name);
303
304void typec_partner_set_svdm_version(struct typec_partner *partner,
305 enum usb_pd_svdm_ver svdm_version);
306int typec_get_negotiated_svdm_version(struct typec_port *port);
307
308#if IS_REACHABLE(CONFIG_TYPEC)
309int typec_link_port(struct device *port);
310void typec_unlink_port(struct device *port);
311#else
312static inline int typec_link_port(struct device *port)
313{
314 return 0;
315}
316
317static inline void typec_unlink_port(struct device *port) { }
318#endif
319
320#endif
321