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 usb_pd_identity - USB Power Delivery identity data
77 * @id_header: ID Header VDO
78 * @cert_stat: Cert Stat VDO
79 * @product: Product VDO
80 * @vdo: Product Type Specific VDOs
82 * USB power delivery Discover Identity command response data.
84 * REVISIT: This is USB Power Delivery specific information, so this structure
85 * probable belongs to USB Power Delivery header file once we have them.
87 struct usb_pd_identity {
94 int typec_partner_set_identity(struct typec_partner *partner);
95 int typec_cable_set_identity(struct typec_cable *cable);
98 * struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor
99 * @svid: Standard or Vendor ID
100 * @mode: Index of the Mode
101 * @vdo: VDO returned by Discover Modes USB PD command
102 * @roles: Only for ports. DRP if the mode is available in both roles
104 * Description of an Alternate Mode which a connector, cable plug or partner
107 struct typec_altmode_desc {
111 /* Only used with ports */
112 enum typec_port_data roles;
116 *typec_partner_register_altmode(struct typec_partner *partner,
117 const struct typec_altmode_desc *desc);
119 *typec_plug_register_altmode(struct typec_plug *plug,
120 const struct typec_altmode_desc *desc);
122 *typec_port_register_altmode(struct typec_port *port,
123 const struct typec_altmode_desc *desc);
124 void typec_unregister_altmode(struct typec_altmode *altmode);
126 struct typec_port *typec_altmode2port(struct typec_altmode *alt);
128 void typec_altmode_update_active(struct typec_altmode *alt, bool active);
130 enum typec_plug_index {
136 * struct typec_plug_desc - USB Type-C Cable Plug Descriptor
137 * @index: SOP Prime for the plug connected to DFP and SOP Double Prime for the
138 * plug connected to UFP
140 * Represents USB Type-C Cable Plug.
142 struct typec_plug_desc {
143 enum typec_plug_index index;
147 * struct typec_cable_desc - USB Type-C Cable Descriptor
148 * @type: The plug type from USB PD Cable VDO
149 * @active: Is the cable active or passive
150 * @identity: Result of Discover Identity command
152 * Represents USB Type-C Cable attached to USB Type-C port.
154 struct typec_cable_desc {
155 enum typec_plug_type type;
156 unsigned int active:1;
157 struct usb_pd_identity *identity;
161 * struct typec_partner_desc - USB Type-C Partner Descriptor
162 * @usb_pd: USB Power Delivery support
163 * @accessory: Audio, Debug or none.
164 * @identity: Discover Identity command data
166 * Details about a partner that is attached to USB Type-C port. If @identity
167 * member exists when partner is registered, a directory named "identity" is
168 * created to sysfs for the partner device.
170 struct typec_partner_desc {
171 unsigned int usb_pd:1;
172 enum typec_accessory accessory;
173 struct usb_pd_identity *identity;
177 * struct typec_operations - USB Type-C Port Operations
178 * @try_role: Set data role preference for DRP port
179 * @dr_set: Set Data Role
180 * @pr_set: Set Power Role
181 * @vconn_set: Source VCONN
182 * @port_type_set: Set port type
184 struct typec_operations {
185 int (*try_role)(struct typec_port *port, int role);
186 int (*dr_set)(struct typec_port *port, enum typec_data_role role);
187 int (*pr_set)(struct typec_port *port, enum typec_role role);
188 int (*vconn_set)(struct typec_port *port, enum typec_role role);
189 int (*port_type_set)(struct typec_port *port,
190 enum typec_port_type type);
194 * struct typec_capability - USB Type-C Port Capabilities
195 * @type: Supported power role of the port
196 * @data: Supported data role of the port
197 * @revision: USB Type-C Specification release. Binary coded decimal
198 * @pd_revision: USB Power Delivery Specification revision if supported
199 * @prefer_role: Initial role preference (DRP ports).
200 * @accessory: Supported Accessory Modes
201 * @fwnode: Optional fwnode of the port
202 * @driver_data: Private pointer for driver specific info
203 * @ops: Port operations vector
205 * Static capabilities of a single USB Type-C port.
207 struct typec_capability {
208 enum typec_port_type type;
209 enum typec_port_data data;
210 u16 revision; /* 0120H = "1.2" */
211 u16 pd_revision; /* 0300H = "3.0" */
213 enum typec_accessory accessory[TYPEC_MAX_ACCESSORY];
215 struct fwnode_handle *fwnode;
218 const struct typec_operations *ops;
221 /* Specific to try_role(). Indicates the user want's to clear the preference. */
222 #define TYPEC_NO_PREFERRED_ROLE (-1)
224 struct typec_port *typec_register_port(struct device *parent,
225 const struct typec_capability *cap);
226 void typec_unregister_port(struct typec_port *port);
228 struct typec_partner *typec_register_partner(struct typec_port *port,
229 struct typec_partner_desc *desc);
230 void typec_unregister_partner(struct typec_partner *partner);
232 struct typec_cable *typec_register_cable(struct typec_port *port,
233 struct typec_cable_desc *desc);
234 void typec_unregister_cable(struct typec_cable *cable);
236 struct typec_cable *typec_cable_get(struct typec_port *port);
237 void typec_cable_put(struct typec_cable *cable);
238 int typec_cable_is_active(struct typec_cable *cable);
240 struct typec_plug *typec_register_plug(struct typec_cable *cable,
241 struct typec_plug_desc *desc);
242 void typec_unregister_plug(struct typec_plug *plug);
244 void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
245 void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
246 void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
247 void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
249 int typec_set_orientation(struct typec_port *port,
250 enum typec_orientation orientation);
251 enum typec_orientation typec_get_orientation(struct typec_port *port);
252 int typec_set_mode(struct typec_port *port, int mode);
254 void *typec_get_drvdata(struct typec_port *port);
256 int typec_find_port_power_role(const char *name);
257 int typec_find_power_role(const char *name);
258 int typec_find_port_data_role(const char *name);
259 #endif /* __LINUX_USB_TYPEC_H */