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