Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef __LINUX_USB_TYPEC_H
4#define __LINUX_USB_TYPEC_H
5
6#include <linux/types.h>
7
8/* USB Type-C Specification releases */
9#define USB_TYPEC_REV_1_0 0x100 /* 1.0 */
10#define USB_TYPEC_REV_1_1 0x110 /* 1.1 */
11#define USB_TYPEC_REV_1_2 0x120 /* 1.2 */
12#define USB_TYPEC_REV_1_3 0x130 /* 1.3 */
13#define USB_TYPEC_REV_1_4 0x140 /* 1.4 */
14#define USB_TYPEC_REV_2_0 0x200 /* 2.0 */
15
16struct typec_partner;
17struct typec_cable;
18struct typec_plug;
19struct typec_port;
20
21struct fwnode_handle;
22struct device;
23
24enum typec_port_type {
25 TYPEC_PORT_SRC,
26 TYPEC_PORT_SNK,
27 TYPEC_PORT_DRP,
28};
29
30enum typec_port_data {
31 TYPEC_PORT_DFP,
32 TYPEC_PORT_UFP,
33 TYPEC_PORT_DRD,
34};
35
36enum typec_plug_type {
37 USB_PLUG_NONE,
38 USB_PLUG_TYPE_A,
39 USB_PLUG_TYPE_B,
40 USB_PLUG_TYPE_C,
41 USB_PLUG_CAPTIVE,
42};
43
44enum typec_data_role {
45 TYPEC_DEVICE,
46 TYPEC_HOST,
47};
48
49enum typec_role {
50 TYPEC_SINK,
51 TYPEC_SOURCE,
52};
53
54enum typec_pwr_opmode {
55 TYPEC_PWR_MODE_USB,
56 TYPEC_PWR_MODE_1_5A,
57 TYPEC_PWR_MODE_3_0A,
58 TYPEC_PWR_MODE_PD,
59};
60
61enum typec_accessory {
62 TYPEC_ACCESSORY_NONE,
63 TYPEC_ACCESSORY_AUDIO,
64 TYPEC_ACCESSORY_DEBUG,
65};
66
67#define TYPEC_MAX_ACCESSORY 3
68
69enum typec_orientation {
70 TYPEC_ORIENTATION_NONE,
71 TYPEC_ORIENTATION_NORMAL,
72 TYPEC_ORIENTATION_REVERSE,
73};
74
75/*
76 * struct enter_usb_data - Enter_USB Message details
77 * @eudo: Enter_USB Data Object
78 * @active_link_training: Active Cable Plug Link Training
79 *
80 * @active_link_training is a flag that should be set with uni-directional SBRX
81 * communication, and left 0 with passive cables and with bi-directional SBRX
82 * communication.
83 */
84struct enter_usb_data {
85 u32 eudo;
86 unsigned char active_link_training:1;
87};
88
89/*
90 * struct usb_pd_identity - USB Power Delivery identity data
91 * @id_header: ID Header VDO
92 * @cert_stat: Cert Stat VDO
93 * @product: Product VDO
94 * @vdo: Product Type Specific VDOs
95 *
96 * USB power delivery Discover Identity command response data.
97 *
98 * REVISIT: This is USB Power Delivery specific information, so this structure
99 * probable belongs to USB Power Delivery header file once we have them.
100 */
101struct usb_pd_identity {
102 u32 id_header;
103 u32 cert_stat;
104 u32 product;
105 u32 vdo[3];
106};
107
108int typec_partner_set_identity(struct typec_partner *partner);
109int typec_cable_set_identity(struct typec_cable *cable);
110
111/*
112 * struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor
113 * @svid: Standard or Vendor ID
114 * @mode: Index of the Mode
115 * @vdo: VDO returned by Discover Modes USB PD command
116 * @roles: Only for ports. DRP if the mode is available in both roles
117 *
118 * Description of an Alternate Mode which a connector, cable plug or partner
119 * supports.
120 */
121struct typec_altmode_desc {
122 u16 svid;
123 u8 mode;
124 u32 vdo;
125 /* Only used with ports */
126 enum typec_port_data roles;
127};
128
129void typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision);
130int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmodes);
131struct typec_altmode
132*typec_partner_register_altmode(struct typec_partner *partner,
133 const struct typec_altmode_desc *desc);
134int typec_plug_set_num_altmodes(struct typec_plug *plug, int num_altmodes);
135struct typec_altmode
136*typec_plug_register_altmode(struct typec_plug *plug,
137 const struct typec_altmode_desc *desc);
138struct typec_altmode
139*typec_port_register_altmode(struct typec_port *port,
140 const struct typec_altmode_desc *desc);
141void typec_unregister_altmode(struct typec_altmode *altmode);
142
143struct typec_port *typec_altmode2port(struct typec_altmode *alt);
144
145void typec_altmode_update_active(struct typec_altmode *alt, bool active);
146
147enum typec_plug_index {
148 TYPEC_PLUG_SOP_P,
149 TYPEC_PLUG_SOP_PP,
150};
151
152/*
153 * struct typec_plug_desc - USB Type-C Cable Plug Descriptor
154 * @index: SOP Prime for the plug connected to DFP and SOP Double Prime for the
155 * plug connected to UFP
156 *
157 * Represents USB Type-C Cable Plug.
158 */
159struct typec_plug_desc {
160 enum typec_plug_index index;
161};
162
163/*
164 * struct typec_cable_desc - USB Type-C Cable Descriptor
165 * @type: The plug type from USB PD Cable VDO
166 * @active: Is the cable active or passive
167 * @identity: Result of Discover Identity command
168 * @pd_revision: USB Power Delivery Specification revision if supported
169 *
170 * Represents USB Type-C Cable attached to USB Type-C port.
171 */
172struct typec_cable_desc {
173 enum typec_plug_type type;
174 unsigned int active:1;
175 struct usb_pd_identity *identity;
176 u16 pd_revision; /* 0300H = "3.0" */
177
178};
179
180/*
181 * struct typec_partner_desc - USB Type-C Partner Descriptor
182 * @usb_pd: USB Power Delivery support
183 * @accessory: Audio, Debug or none.
184 * @identity: Discover Identity command data
185 * @pd_revision: USB Power Delivery Specification Revision if supported
186 *
187 * Details about a partner that is attached to USB Type-C port. If @identity
188 * member exists when partner is registered, a directory named "identity" is
189 * created to sysfs for the partner device.
190 *
191 * @pd_revision is based on the setting of the "Specification Revision" field
192 * in the message header on the initial "Source Capabilities" message received
193 * from the partner, or a "Request" message received from the partner, depending
194 * on whether our port is a Sink or a Source.
195 */
196struct typec_partner_desc {
197 unsigned int usb_pd:1;
198 enum typec_accessory accessory;
199 struct usb_pd_identity *identity;
200 u16 pd_revision; /* 0300H = "3.0" */
201};
202
203/**
204 * struct typec_operations - USB Type-C Port Operations
205 * @try_role: Set data role preference for DRP port
206 * @dr_set: Set Data Role
207 * @pr_set: Set Power Role
208 * @vconn_set: Source VCONN
209 * @port_type_set: Set port type
210 */
211struct typec_operations {
212 int (*try_role)(struct typec_port *port, int role);
213 int (*dr_set)(struct typec_port *port, enum typec_data_role role);
214 int (*pr_set)(struct typec_port *port, enum typec_role role);
215 int (*vconn_set)(struct typec_port *port, enum typec_role role);
216 int (*port_type_set)(struct typec_port *port,
217 enum typec_port_type type);
218};
219
220enum usb_pd_svdm_ver {
221 SVDM_VER_1_0 = 0,
222 SVDM_VER_2_0 = 1,
223 SVDM_VER_MAX = SVDM_VER_2_0,
224};
225
226/*
227 * struct typec_capability - USB Type-C Port Capabilities
228 * @type: Supported power role of the port
229 * @data: Supported data role of the port
230 * @revision: USB Type-C Specification release. Binary coded decimal
231 * @pd_revision: USB Power Delivery Specification revision if supported
232 * @svdm_version: USB PD Structured VDM version if supported
233 * @prefer_role: Initial role preference (DRP ports).
234 * @accessory: Supported Accessory Modes
235 * @fwnode: Optional fwnode of the port
236 * @driver_data: Private pointer for driver specific info
237 * @ops: Port operations vector
238 *
239 * Static capabilities of a single USB Type-C port.
240 */
241struct typec_capability {
242 enum typec_port_type type;
243 enum typec_port_data data;
244 u16 revision; /* 0120H = "1.2" */
245 u16 pd_revision; /* 0300H = "3.0" */
246 enum usb_pd_svdm_ver svdm_version;
247 int prefer_role;
248 enum typec_accessory accessory[TYPEC_MAX_ACCESSORY];
249 unsigned int orientation_aware:1;
250
251 struct fwnode_handle *fwnode;
252 void *driver_data;
253
254 const struct typec_operations *ops;
255};
256
257/* Specific to try_role(). Indicates the user want's to clear the preference. */
258#define TYPEC_NO_PREFERRED_ROLE (-1)
259
260struct typec_port *typec_register_port(struct device *parent,
261 const struct typec_capability *cap);
262void typec_unregister_port(struct typec_port *port);
263
264struct typec_partner *typec_register_partner(struct typec_port *port,
265 struct typec_partner_desc *desc);
266void typec_unregister_partner(struct typec_partner *partner);
267
268struct typec_cable *typec_register_cable(struct typec_port *port,
269 struct typec_cable_desc *desc);
270void typec_unregister_cable(struct typec_cable *cable);
271
272struct typec_cable *typec_cable_get(struct typec_port *port);
273void typec_cable_put(struct typec_cable *cable);
274int typec_cable_is_active(struct typec_cable *cable);
275
276struct typec_plug *typec_register_plug(struct typec_cable *cable,
277 struct typec_plug_desc *desc);
278void typec_unregister_plug(struct typec_plug *plug);
279
280void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
281void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
282void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
283void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
284
285int typec_set_orientation(struct typec_port *port,
286 enum typec_orientation orientation);
287enum typec_orientation typec_get_orientation(struct typec_port *port);
288int typec_set_mode(struct typec_port *port, int mode);
289
290void *typec_get_drvdata(struct typec_port *port);
291
292int typec_find_pwr_opmode(const char *name);
293int typec_find_orientation(const char *name);
294int typec_find_port_power_role(const char *name);
295int typec_find_power_role(const char *name);
296int typec_find_port_data_role(const char *name);
297
298void typec_partner_set_svdm_version(struct typec_partner *partner,
299 enum usb_pd_svdm_ver svdm_version);
300int typec_get_negotiated_svdm_version(struct typec_port *port);
301#endif /* __LINUX_USB_TYPEC_H */