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 /* XXX: Once we have a header for USB Power Delivery, this belongs there */
9 #define ALTMODE_MAX_MODES 6
11 /* USB Type-C Specification releases */
12 #define USB_TYPEC_REV_1_0 0x100 /* 1.0 */
13 #define USB_TYPEC_REV_1_1 0x110 /* 1.1 */
14 #define USB_TYPEC_REV_1_2 0x120 /* 1.2 */
24 enum typec_port_type {
30 enum typec_plug_type {
38 enum typec_data_role {
48 enum typec_pwr_opmode {
55 enum typec_accessory {
57 TYPEC_ACCESSORY_AUDIO,
58 TYPEC_ACCESSORY_DEBUG,
61 #define TYPEC_MAX_ACCESSORY 3
63 enum typec_orientation {
64 TYPEC_ORIENTATION_NONE,
65 TYPEC_ORIENTATION_NORMAL,
66 TYPEC_ORIENTATION_REVERSE,
70 * struct usb_pd_identity - USB Power Delivery identity data
71 * @id_header: ID Header VDO
72 * @cert_stat: Cert Stat VDO
73 * @product: Product VDO
75 * USB power delivery Discover Identity command response data.
77 * REVISIT: This is USB Power Delivery specific information, so this structure
78 * probable belongs to USB Power Delivery header file once we have them.
80 struct usb_pd_identity {
86 int typec_partner_set_identity(struct typec_partner *partner);
87 int typec_cable_set_identity(struct typec_cable *cable);
90 * struct typec_mode_desc - Individual Mode of an Alternate Mode
91 * @index: Index of the Mode within the SVID
92 * @vdo: VDO returned by Discover Modes USB PD command
93 * @desc: Optional human readable description of the mode
94 * @roles: Only for ports. DRP if the mode is available in both roles
96 * Description of a mode of an Alternate Mode which a connector, cable plug or
97 * partner supports. Every mode will have it's own sysfs group. The details are
98 * the VDO returned by discover modes command, description for the mode and
99 * active flag telling has the mode being entered or not.
101 struct typec_mode_desc {
105 /* Only used with ports */
106 enum typec_port_type roles;
110 * struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor
111 * @svid: Standard or Vendor ID
112 * @n_modes: Number of modes
113 * @modes: Array of modes supported by the Alternate Mode
115 * Representation of an Alternate Mode that has SVID assigned by USB-IF. The
116 * array of modes will list the modes of a particular SVID that are supported by
117 * a connector, partner of a cable plug.
119 struct typec_altmode_desc {
122 struct typec_mode_desc modes[ALTMODE_MAX_MODES];
126 *typec_partner_register_altmode(struct typec_partner *partner,
127 const struct typec_altmode_desc *desc);
129 *typec_plug_register_altmode(struct typec_plug *plug,
130 const struct typec_altmode_desc *desc);
132 *typec_port_register_altmode(struct typec_port *port,
133 const struct typec_altmode_desc *desc);
134 void typec_unregister_altmode(struct typec_altmode *altmode);
136 struct typec_port *typec_altmode2port(struct typec_altmode *alt);
138 void typec_altmode_update_active(struct typec_altmode *alt, int mode,
141 enum typec_plug_index {
147 * struct typec_plug_desc - USB Type-C Cable Plug Descriptor
148 * @index: SOP Prime for the plug connected to DFP and SOP Double Prime for the
149 * plug connected to UFP
151 * Represents USB Type-C Cable Plug.
153 struct typec_plug_desc {
154 enum typec_plug_index index;
158 * struct typec_cable_desc - USB Type-C Cable Descriptor
159 * @type: The plug type from USB PD Cable VDO
160 * @active: Is the cable active or passive
161 * @identity: Result of Discover Identity command
163 * Represents USB Type-C Cable attached to USB Type-C port.
165 struct typec_cable_desc {
166 enum typec_plug_type type;
167 unsigned int active:1;
168 struct usb_pd_identity *identity;
172 * struct typec_partner_desc - USB Type-C Partner Descriptor
173 * @usb_pd: USB Power Delivery support
174 * @accessory: Audio, Debug or none.
175 * @identity: Discover Identity command data
177 * Details about a partner that is attached to USB Type-C port. If @identity
178 * member exists when partner is registered, a directory named "identity" is
179 * created to sysfs for the partner device.
181 struct typec_partner_desc {
182 unsigned int usb_pd:1;
183 enum typec_accessory accessory;
184 struct usb_pd_identity *identity;
188 * struct typec_capability - USB Type-C Port Capabilities
189 * @role: DFP (Host-only), UFP (Device-only) or DRP (Dual Role)
190 * @revision: USB Type-C Specification release. Binary coded decimal
191 * @pd_revision: USB Power Delivery Specification revision if supported
192 * @prefer_role: Initial role preference
193 * @accessory: Supported Accessory Modes
194 * @sw: Cable plug orientation switch
195 * @mux: Multiplexer switch for Alternate/Accessory Modes
196 * @fwnode: Optional fwnode of the port
197 * @try_role: Set data role preference for DRP port
198 * @dr_set: Set Data Role
199 * @pr_set: Set Power Role
200 * @vconn_set: Set VCONN Role
201 * @activate_mode: Enter/exit given Alternate Mode
202 * @port_type_set: Set port type
204 * Static capabilities of a single USB Type-C port.
206 struct typec_capability {
207 enum typec_port_type type;
208 u16 revision; /* 0120H = "1.2" */
209 u16 pd_revision; /* 0300H = "3.0" */
211 enum typec_accessory accessory[TYPEC_MAX_ACCESSORY];
213 struct typec_switch *sw;
214 struct typec_mux *mux;
215 struct fwnode_handle *fwnode;
217 int (*try_role)(const struct typec_capability *,
220 int (*dr_set)(const struct typec_capability *,
221 enum typec_data_role);
222 int (*pr_set)(const struct typec_capability *,
224 int (*vconn_set)(const struct typec_capability *,
227 int (*activate_mode)(const struct typec_capability *,
228 int mode, int activate);
229 int (*port_type_set)(const struct typec_capability *,
230 enum typec_port_type);
234 /* Specific to try_role(). Indicates the user want's to clear the preference. */
235 #define TYPEC_NO_PREFERRED_ROLE (-1)
237 struct typec_port *typec_register_port(struct device *parent,
238 const struct typec_capability *cap);
239 void typec_unregister_port(struct typec_port *port);
241 struct typec_partner *typec_register_partner(struct typec_port *port,
242 struct typec_partner_desc *desc);
243 void typec_unregister_partner(struct typec_partner *partner);
245 struct typec_cable *typec_register_cable(struct typec_port *port,
246 struct typec_cable_desc *desc);
247 void typec_unregister_cable(struct typec_cable *cable);
249 struct typec_plug *typec_register_plug(struct typec_cable *cable,
250 struct typec_plug_desc *desc);
251 void typec_unregister_plug(struct typec_plug *plug);
253 void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
254 void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
255 void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
256 void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
258 int typec_set_orientation(struct typec_port *port,
259 enum typec_orientation orientation);
260 int typec_set_mode(struct typec_port *port, int mode);
262 #endif /* __LINUX_USB_TYPEC_H */