1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef __LINUX_USB_TYPEC_H
4 #define __LINUX_USB_TYPEC_H
6 #include <linux/types.h>
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 */
24 enum typec_port_type {
30 enum typec_port_data {
36 enum typec_plug_type {
44 enum typec_data_role {
54 enum typec_pwr_opmode {
61 enum typec_accessory {
63 TYPEC_ACCESSORY_AUDIO,
64 TYPEC_ACCESSORY_DEBUG,
67 #define TYPEC_MAX_ACCESSORY 3
69 enum typec_orientation {
70 TYPEC_ORIENTATION_NONE,
71 TYPEC_ORIENTATION_NORMAL,
72 TYPEC_ORIENTATION_REVERSE,
76 * struct enter_usb_data - Enter_USB Message details
77 * @eudo: Enter_USB Data Object
78 * @active_link_training: Active Cable Plug Link Training
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
84 struct enter_usb_data {
86 unsigned char active_link_training:1;
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
96 * USB power delivery Discover Identity command response data.
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.
101 struct usb_pd_identity {
108 int typec_partner_set_identity(struct typec_partner *partner);
109 int typec_cable_set_identity(struct typec_cable *cable);
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
118 * Description of an Alternate Mode which a connector, cable plug or partner
121 struct typec_altmode_desc {
125 /* Only used with ports */
126 enum typec_port_data roles;
130 *typec_partner_register_altmode(struct typec_partner *partner,
131 const struct typec_altmode_desc *desc);
133 *typec_plug_register_altmode(struct typec_plug *plug,
134 const struct typec_altmode_desc *desc);
136 *typec_port_register_altmode(struct typec_port *port,
137 const struct typec_altmode_desc *desc);
138 void typec_unregister_altmode(struct typec_altmode *altmode);
140 struct typec_port *typec_altmode2port(struct typec_altmode *alt);
142 void typec_altmode_update_active(struct typec_altmode *alt, bool active);
144 enum typec_plug_index {
150 * struct typec_plug_desc - USB Type-C Cable Plug Descriptor
151 * @index: SOP Prime for the plug connected to DFP and SOP Double Prime for the
152 * plug connected to UFP
154 * Represents USB Type-C Cable Plug.
156 struct typec_plug_desc {
157 enum typec_plug_index index;
161 * struct typec_cable_desc - USB Type-C Cable Descriptor
162 * @type: The plug type from USB PD Cable VDO
163 * @active: Is the cable active or passive
164 * @identity: Result of Discover Identity command
166 * Represents USB Type-C Cable attached to USB Type-C port.
168 struct typec_cable_desc {
169 enum typec_plug_type type;
170 unsigned int active:1;
171 struct usb_pd_identity *identity;
175 * struct typec_partner_desc - USB Type-C Partner Descriptor
176 * @usb_pd: USB Power Delivery support
177 * @accessory: Audio, Debug or none.
178 * @identity: Discover Identity command data
180 * Details about a partner that is attached to USB Type-C port. If @identity
181 * member exists when partner is registered, a directory named "identity" is
182 * created to sysfs for the partner device.
184 struct typec_partner_desc {
185 unsigned int usb_pd:1;
186 enum typec_accessory accessory;
187 struct usb_pd_identity *identity;
191 * struct typec_operations - USB Type-C Port Operations
192 * @try_role: Set data role preference for DRP port
193 * @dr_set: Set Data Role
194 * @pr_set: Set Power Role
195 * @vconn_set: Source VCONN
196 * @port_type_set: Set port type
198 struct typec_operations {
199 int (*try_role)(struct typec_port *port, int role);
200 int (*dr_set)(struct typec_port *port, enum typec_data_role role);
201 int (*pr_set)(struct typec_port *port, enum typec_role role);
202 int (*vconn_set)(struct typec_port *port, enum typec_role role);
203 int (*port_type_set)(struct typec_port *port,
204 enum typec_port_type type);
208 * struct typec_capability - USB Type-C Port Capabilities
209 * @type: Supported power role of the port
210 * @data: Supported data role of the port
211 * @revision: USB Type-C Specification release. Binary coded decimal
212 * @pd_revision: USB Power Delivery Specification revision if supported
213 * @prefer_role: Initial role preference (DRP ports).
214 * @accessory: Supported Accessory Modes
215 * @fwnode: Optional fwnode of the port
216 * @driver_data: Private pointer for driver specific info
217 * @ops: Port operations vector
219 * Static capabilities of a single USB Type-C port.
221 struct typec_capability {
222 enum typec_port_type type;
223 enum typec_port_data data;
224 u16 revision; /* 0120H = "1.2" */
225 u16 pd_revision; /* 0300H = "3.0" */
227 enum typec_accessory accessory[TYPEC_MAX_ACCESSORY];
228 unsigned int orientation_aware:1;
230 struct fwnode_handle *fwnode;
233 const struct typec_operations *ops;
236 /* Specific to try_role(). Indicates the user want's to clear the preference. */
237 #define TYPEC_NO_PREFERRED_ROLE (-1)
239 struct typec_port *typec_register_port(struct device *parent,
240 const struct typec_capability *cap);
241 void typec_unregister_port(struct typec_port *port);
243 struct typec_partner *typec_register_partner(struct typec_port *port,
244 struct typec_partner_desc *desc);
245 void typec_unregister_partner(struct typec_partner *partner);
247 struct typec_cable *typec_register_cable(struct typec_port *port,
248 struct typec_cable_desc *desc);
249 void typec_unregister_cable(struct typec_cable *cable);
251 struct typec_cable *typec_cable_get(struct typec_port *port);
252 void typec_cable_put(struct typec_cable *cable);
253 int typec_cable_is_active(struct typec_cable *cable);
255 struct typec_plug *typec_register_plug(struct typec_cable *cable,
256 struct typec_plug_desc *desc);
257 void typec_unregister_plug(struct typec_plug *plug);
259 void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
260 void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
261 void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
262 void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
264 int typec_set_orientation(struct typec_port *port,
265 enum typec_orientation orientation);
266 enum typec_orientation typec_get_orientation(struct typec_port *port);
267 int typec_set_mode(struct typec_port *port, int mode);
269 void *typec_get_drvdata(struct typec_port *port);
271 int typec_find_pwr_opmode(const char *name);
272 int typec_find_orientation(const char *name);
273 int typec_find_port_power_role(const char *name);
274 int typec_find_power_role(const char *name);
275 int typec_find_port_data_role(const char *name);
276 #endif /* __LINUX_USB_TYPEC_H */