xref: /linux-6.15/include/linux/usb/typec.h (revision 183b194d)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2fab92884SHeikki Krogerus 
3fab92884SHeikki Krogerus #ifndef __LINUX_USB_TYPEC_H
4fab92884SHeikki Krogerus #define __LINUX_USB_TYPEC_H
5fab92884SHeikki Krogerus 
6fab92884SHeikki Krogerus #include <linux/types.h>
7fab92884SHeikki Krogerus 
8fab92884SHeikki Krogerus /* USB Type-C Specification releases */
9fab92884SHeikki Krogerus #define USB_TYPEC_REV_1_0	0x100 /* 1.0 */
10fab92884SHeikki Krogerus #define USB_TYPEC_REV_1_1	0x110 /* 1.1 */
11fab92884SHeikki Krogerus #define USB_TYPEC_REV_1_2	0x120 /* 1.2 */
120ac53493SHeikki Krogerus #define USB_TYPEC_REV_1_3	0x130 /* 1.3 */
130ac53493SHeikki Krogerus #define USB_TYPEC_REV_1_4	0x140 /* 1.4 */
140ac53493SHeikki Krogerus #define USB_TYPEC_REV_2_0	0x200 /* 2.0 */
15fab92884SHeikki Krogerus 
16fab92884SHeikki Krogerus struct typec_partner;
17fab92884SHeikki Krogerus struct typec_cable;
18fab92884SHeikki Krogerus struct typec_plug;
19fab92884SHeikki Krogerus struct typec_port;
207b458a4cSHans de Goede struct typec_altmode_ops;
217494d4bcSRD Babiera struct typec_cable_ops;
22fab92884SHeikki Krogerus 
23fab92884SHeikki Krogerus struct fwnode_handle;
248a37d87dSHeikki Krogerus struct device;
25fab92884SHeikki Krogerus 
26a7cff92fSHeikki Krogerus struct usb_power_delivery;
2703239981SPrashant Malani struct usb_power_delivery_desc;
28a7cff92fSHeikki Krogerus 
29fab92884SHeikki Krogerus enum typec_port_type {
30ceeb1625SHeikki Krogerus 	TYPEC_PORT_SRC,
31ceeb1625SHeikki Krogerus 	TYPEC_PORT_SNK,
32ceeb1625SHeikki Krogerus 	TYPEC_PORT_DRP,
33ceeb1625SHeikki Krogerus };
34ceeb1625SHeikki Krogerus 
35ceeb1625SHeikki Krogerus enum typec_port_data {
36fab92884SHeikki Krogerus 	TYPEC_PORT_DFP,
37fab92884SHeikki Krogerus 	TYPEC_PORT_UFP,
38ceeb1625SHeikki Krogerus 	TYPEC_PORT_DRD,
39fab92884SHeikki Krogerus };
40fab92884SHeikki Krogerus 
41fab92884SHeikki Krogerus enum typec_plug_type {
42fab92884SHeikki Krogerus 	USB_PLUG_NONE,
43fab92884SHeikki Krogerus 	USB_PLUG_TYPE_A,
44fab92884SHeikki Krogerus 	USB_PLUG_TYPE_B,
45fab92884SHeikki Krogerus 	USB_PLUG_TYPE_C,
46fab92884SHeikki Krogerus 	USB_PLUG_CAPTIVE,
47fab92884SHeikki Krogerus };
48fab92884SHeikki Krogerus 
49fab92884SHeikki Krogerus enum typec_data_role {
50fab92884SHeikki Krogerus 	TYPEC_DEVICE,
51fab92884SHeikki Krogerus 	TYPEC_HOST,
52fab92884SHeikki Krogerus };
53fab92884SHeikki Krogerus 
54fab92884SHeikki Krogerus enum typec_role {
55fab92884SHeikki Krogerus 	TYPEC_SINK,
56fab92884SHeikki Krogerus 	TYPEC_SOURCE,
57fab92884SHeikki Krogerus };
58fab92884SHeikki Krogerus 
is_sink(enum typec_role role)59662a6010SHeikki Krogerus static inline int is_sink(enum typec_role role)
60662a6010SHeikki Krogerus {
61662a6010SHeikki Krogerus 	return role == TYPEC_SINK;
62662a6010SHeikki Krogerus }
63662a6010SHeikki Krogerus 
is_source(enum typec_role role)64662a6010SHeikki Krogerus static inline int is_source(enum typec_role role)
65662a6010SHeikki Krogerus {
66662a6010SHeikki Krogerus 	return role == TYPEC_SOURCE;
67662a6010SHeikki Krogerus }
68662a6010SHeikki Krogerus 
69fab92884SHeikki Krogerus enum typec_pwr_opmode {
70fab92884SHeikki Krogerus 	TYPEC_PWR_MODE_USB,
71fab92884SHeikki Krogerus 	TYPEC_PWR_MODE_1_5A,
72fab92884SHeikki Krogerus 	TYPEC_PWR_MODE_3_0A,
73fab92884SHeikki Krogerus 	TYPEC_PWR_MODE_PD,
74fab92884SHeikki Krogerus };
75fab92884SHeikki Krogerus 
76fab92884SHeikki Krogerus enum typec_accessory {
77fab92884SHeikki Krogerus 	TYPEC_ACCESSORY_NONE,
78fab92884SHeikki Krogerus 	TYPEC_ACCESSORY_AUDIO,
79fab92884SHeikki Krogerus 	TYPEC_ACCESSORY_DEBUG,
80fab92884SHeikki Krogerus };
81fab92884SHeikki Krogerus 
82fab92884SHeikki Krogerus #define TYPEC_MAX_ACCESSORY	3
83fab92884SHeikki Krogerus 
84bdecb33aSHeikki Krogerus enum typec_orientation {
85bdecb33aSHeikki Krogerus 	TYPEC_ORIENTATION_NONE,
86bdecb33aSHeikki Krogerus 	TYPEC_ORIENTATION_NORMAL,
87bdecb33aSHeikki Krogerus 	TYPEC_ORIENTATION_REVERSE,
88bdecb33aSHeikki Krogerus };
89bdecb33aSHeikki Krogerus 
908060bcb1SHeikki Krogerus enum usb_mode {
918060bcb1SHeikki Krogerus 	USB_MODE_NONE,
928060bcb1SHeikki Krogerus 	USB_MODE_USB2,
938060bcb1SHeikki Krogerus 	USB_MODE_USB3,
948060bcb1SHeikki Krogerus 	USB_MODE_USB4
958060bcb1SHeikki Krogerus };
968060bcb1SHeikki Krogerus 
978060bcb1SHeikki Krogerus #define USB_CAPABILITY_USB2	BIT(0)
988060bcb1SHeikki Krogerus #define USB_CAPABILITY_USB3	BIT(1)
998060bcb1SHeikki Krogerus #define USB_CAPABILITY_USB4	BIT(2)
1008060bcb1SHeikki Krogerus 
101fab92884SHeikki Krogerus /*
102ad8db94dSHeikki Krogerus  * struct enter_usb_data - Enter_USB Message details
103ad8db94dSHeikki Krogerus  * @eudo: Enter_USB Data Object
104ad8db94dSHeikki Krogerus  * @active_link_training: Active Cable Plug Link Training
105ad8db94dSHeikki Krogerus  *
106ad8db94dSHeikki Krogerus  * @active_link_training is a flag that should be set with uni-directional SBRX
107ad8db94dSHeikki Krogerus  * communication, and left 0 with passive cables and with bi-directional SBRX
108ad8db94dSHeikki Krogerus  * communication.
109ad8db94dSHeikki Krogerus  */
110ad8db94dSHeikki Krogerus struct enter_usb_data {
111ad8db94dSHeikki Krogerus 	u32			eudo;
112ad8db94dSHeikki Krogerus 	unsigned char		active_link_training:1;
113ad8db94dSHeikki Krogerus };
114ad8db94dSHeikki Krogerus 
115ad8db94dSHeikki Krogerus /*
116fab92884SHeikki Krogerus  * struct usb_pd_identity - USB Power Delivery identity data
117fab92884SHeikki Krogerus  * @id_header: ID Header VDO
118fab92884SHeikki Krogerus  * @cert_stat: Cert Stat VDO
119fab92884SHeikki Krogerus  * @product: Product VDO
120f6c56ca9SHeikki Krogerus  * @vdo: Product Type Specific VDOs
121fab92884SHeikki Krogerus  *
122fab92884SHeikki Krogerus  * USB power delivery Discover Identity command response data.
123fab92884SHeikki Krogerus  *
124fab92884SHeikki Krogerus  * REVISIT: This is USB Power Delivery specific information, so this structure
125fab92884SHeikki Krogerus  * probable belongs to USB Power Delivery header file once we have them.
126fab92884SHeikki Krogerus  */
127fab92884SHeikki Krogerus struct usb_pd_identity {
128fab92884SHeikki Krogerus 	u32			id_header;
129fab92884SHeikki Krogerus 	u32			cert_stat;
130fab92884SHeikki Krogerus 	u32			product;
131f6c56ca9SHeikki Krogerus 	u32			vdo[3];
132fab92884SHeikki Krogerus };
133fab92884SHeikki Krogerus 
134fab92884SHeikki Krogerus int typec_partner_set_identity(struct typec_partner *partner);
135fab92884SHeikki Krogerus int typec_cable_set_identity(struct typec_cable *cable);
136fab92884SHeikki Krogerus 
137fab92884SHeikki Krogerus /*
138fab92884SHeikki Krogerus  * struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor
139fab92884SHeikki Krogerus  * @svid: Standard or Vendor ID
1404ab8c18dSHeikki Krogerus  * @mode: Index of the Mode
1414ab8c18dSHeikki Krogerus  * @vdo: VDO returned by Discover Modes USB PD command
1424ab8c18dSHeikki Krogerus  * @roles: Only for ports. DRP if the mode is available in both roles
143*183b194dSAbhishek Pandit-Subedi  * @inactive: Only for ports. Make this port inactive (default is active).
144fab92884SHeikki Krogerus  *
1454ab8c18dSHeikki Krogerus  * Description of an Alternate Mode which a connector, cable plug or partner
1464ab8c18dSHeikki Krogerus  * supports.
147fab92884SHeikki Krogerus  */
148fab92884SHeikki Krogerus struct typec_altmode_desc {
149fab92884SHeikki Krogerus 	u16			svid;
1504ab8c18dSHeikki Krogerus 	u8			mode;
1514ab8c18dSHeikki Krogerus 	u32			vdo;
1524ab8c18dSHeikki Krogerus 	/* Only used with ports */
1538a37d87dSHeikki Krogerus 	enum typec_port_data	roles;
154*183b194dSAbhishek Pandit-Subedi 	bool			inactive;
155fab92884SHeikki Krogerus };
156fab92884SHeikki Krogerus 
15732e9b48dSKyle Tso void typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision);
158a0ccdc4aSPrashant Malani int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmodes);
159fab92884SHeikki Krogerus struct typec_altmode
160fab92884SHeikki Krogerus *typec_partner_register_altmode(struct typec_partner *partner,
161a86c309eSMats Karrman 				const struct typec_altmode_desc *desc);
162e1e52361SPrashant Malani int typec_plug_set_num_altmodes(struct typec_plug *plug, int num_altmodes);
163fab92884SHeikki Krogerus struct typec_altmode
164fab92884SHeikki Krogerus *typec_plug_register_altmode(struct typec_plug *plug,
165a86c309eSMats Karrman 			     const struct typec_altmode_desc *desc);
166fab92884SHeikki Krogerus struct typec_altmode
167fab92884SHeikki Krogerus *typec_port_register_altmode(struct typec_port *port,
168a86c309eSMats Karrman 			     const struct typec_altmode_desc *desc);
1697b458a4cSHans de Goede 
1707b458a4cSHans de Goede void typec_port_register_altmodes(struct typec_port *port,
1717b458a4cSHans de Goede 	const struct typec_altmode_ops *ops, void *drvdata,
1727b458a4cSHans de Goede 	struct typec_altmode **altmodes, size_t n);
1737b458a4cSHans de Goede 
1747494d4bcSRD Babiera void typec_port_register_cable_ops(struct typec_altmode **altmodes, int max_altmodes,
1757494d4bcSRD Babiera 				   const struct typec_cable_ops *ops);
1767494d4bcSRD Babiera 
177fab92884SHeikki Krogerus void typec_unregister_altmode(struct typec_altmode *altmode);
178fab92884SHeikki Krogerus 
179fab92884SHeikki Krogerus struct typec_port *typec_altmode2port(struct typec_altmode *alt);
180fab92884SHeikki Krogerus 
1814ab8c18dSHeikki Krogerus void typec_altmode_update_active(struct typec_altmode *alt, bool active);
182fab92884SHeikki Krogerus 
183fe8db0bbSAbhishek Pandit-Subedi void typec_altmode_set_ops(struct typec_altmode *alt,
184fe8db0bbSAbhishek Pandit-Subedi 			   const struct typec_altmode_ops *ops);
185fe8db0bbSAbhishek Pandit-Subedi 
186fab92884SHeikki Krogerus enum typec_plug_index {
187fab92884SHeikki Krogerus 	TYPEC_PLUG_SOP_P,
188fab92884SHeikki Krogerus 	TYPEC_PLUG_SOP_PP,
189fab92884SHeikki Krogerus };
190fab92884SHeikki Krogerus 
191fab92884SHeikki Krogerus /*
192fab92884SHeikki Krogerus  * struct typec_plug_desc - USB Type-C Cable Plug Descriptor
193fab92884SHeikki Krogerus  * @index: SOP Prime for the plug connected to DFP and SOP Double Prime for the
194fab92884SHeikki Krogerus  *         plug connected to UFP
195fab92884SHeikki Krogerus  *
196fab92884SHeikki Krogerus  * Represents USB Type-C Cable Plug.
197fab92884SHeikki Krogerus  */
198fab92884SHeikki Krogerus struct typec_plug_desc {
199fab92884SHeikki Krogerus 	enum typec_plug_index	index;
200fab92884SHeikki Krogerus };
201fab92884SHeikki Krogerus 
202fab92884SHeikki Krogerus /*
203fab92884SHeikki Krogerus  * struct typec_cable_desc - USB Type-C Cable Descriptor
204fab92884SHeikki Krogerus  * @type: The plug type from USB PD Cable VDO
205fab92884SHeikki Krogerus  * @active: Is the cable active or passive
206fab92884SHeikki Krogerus  * @identity: Result of Discover Identity command
207f5030e25SBenson Leung  * @pd_revision: USB Power Delivery Specification revision if supported
208fab92884SHeikki Krogerus  *
209fab92884SHeikki Krogerus  * Represents USB Type-C Cable attached to USB Type-C port.
210fab92884SHeikki Krogerus  */
211fab92884SHeikki Krogerus struct typec_cable_desc {
212fab92884SHeikki Krogerus 	enum typec_plug_type	type;
213fab92884SHeikki Krogerus 	unsigned int		active:1;
214fab92884SHeikki Krogerus 	struct usb_pd_identity	*identity;
215f5030e25SBenson Leung 	u16			pd_revision; /* 0300H = "3.0" */
216f5030e25SBenson Leung 
217fab92884SHeikki Krogerus };
218fab92884SHeikki Krogerus 
219fab92884SHeikki Krogerus /*
220fab92884SHeikki Krogerus  * struct typec_partner_desc - USB Type-C Partner Descriptor
221fab92884SHeikki Krogerus  * @usb_pd: USB Power Delivery support
222fab92884SHeikki Krogerus  * @accessory: Audio, Debug or none.
223fab92884SHeikki Krogerus  * @identity: Discover Identity command data
224f5030e25SBenson Leung  * @pd_revision: USB Power Delivery Specification Revision if supported
2252140a952SHeikki Krogerus  * @usb_capability: Supported USB Modes
22659de2a56SHeikki Krogerus  * @attach: Notification about attached USB device
22759de2a56SHeikki Krogerus  * @deattach: Notification about removed USB device
228fab92884SHeikki Krogerus  *
229fab92884SHeikki Krogerus  * Details about a partner that is attached to USB Type-C port. If @identity
230fab92884SHeikki Krogerus  * member exists when partner is registered, a directory named "identity" is
231fab92884SHeikki Krogerus  * created to sysfs for the partner device.
232f5030e25SBenson Leung  *
233f5030e25SBenson Leung  * @pd_revision is based on the setting of the "Specification Revision" field
234f5030e25SBenson Leung  * in the message header on the initial "Source Capabilities" message received
235f5030e25SBenson Leung  * from the partner, or a "Request" message received from the partner, depending
236f5030e25SBenson Leung  * on whether our port is a Sink or a Source.
237fab92884SHeikki Krogerus  */
238fab92884SHeikki Krogerus struct typec_partner_desc {
239fab92884SHeikki Krogerus 	unsigned int		usb_pd:1;
240fab92884SHeikki Krogerus 	enum typec_accessory	accessory;
241fab92884SHeikki Krogerus 	struct usb_pd_identity	*identity;
242f5030e25SBenson Leung 	u16			pd_revision; /* 0300H = "3.0" */
2432140a952SHeikki Krogerus 	u8			usb_capability;
24459de2a56SHeikki Krogerus 
24559de2a56SHeikki Krogerus 	void (*attach)(struct typec_partner *partner, struct device *dev);
24659de2a56SHeikki Krogerus 	void (*deattach)(struct typec_partner *partner, struct device *dev);
247fab92884SHeikki Krogerus };
248fab92884SHeikki Krogerus 
24946310e4dSHeikki Krogerus /**
25046310e4dSHeikki Krogerus  * struct typec_operations - USB Type-C Port Operations
25146310e4dSHeikki Krogerus  * @try_role: Set data role preference for DRP port
25246310e4dSHeikki Krogerus  * @dr_set: Set Data Role
25346310e4dSHeikki Krogerus  * @pr_set: Set Power Role
25446310e4dSHeikki Krogerus  * @vconn_set: Source VCONN
25546310e4dSHeikki Krogerus  * @port_type_set: Set port type
256a7cff92fSHeikki Krogerus  * @pd_get: Get available USB Power Delivery Capabilities.
257a7cff92fSHeikki Krogerus  * @pd_set: Set USB Power Delivery Capabilities.
2588060bcb1SHeikki Krogerus  * @default_usb_mode_set: USB Mode to be used by default with Enter_USB Message
2592140a952SHeikki Krogerus  * @enter_usb_mode: Change the active USB Mode
26046310e4dSHeikki Krogerus  */
26146310e4dSHeikki Krogerus struct typec_operations {
26246310e4dSHeikki Krogerus 	int (*try_role)(struct typec_port *port, int role);
26346310e4dSHeikki Krogerus 	int (*dr_set)(struct typec_port *port, enum typec_data_role role);
26446310e4dSHeikki Krogerus 	int (*pr_set)(struct typec_port *port, enum typec_role role);
26546310e4dSHeikki Krogerus 	int (*vconn_set)(struct typec_port *port, enum typec_role role);
26646310e4dSHeikki Krogerus 	int (*port_type_set)(struct typec_port *port,
26746310e4dSHeikki Krogerus 			     enum typec_port_type type);
268a7cff92fSHeikki Krogerus 	struct usb_power_delivery **(*pd_get)(struct typec_port *port);
269a7cff92fSHeikki Krogerus 	int (*pd_set)(struct typec_port *port, struct usb_power_delivery *pd);
2708060bcb1SHeikki Krogerus 	int (*default_usb_mode_set)(struct typec_port *port, enum usb_mode mode);
2712140a952SHeikki Krogerus 	int (*enter_usb_mode)(struct typec_port *port, enum usb_mode mode);
27246310e4dSHeikki Krogerus };
27346310e4dSHeikki Krogerus 
2743c5960c0SKyle Tso enum usb_pd_svdm_ver {
2753c5960c0SKyle Tso 	SVDM_VER_1_0 = 0,
2763c5960c0SKyle Tso 	SVDM_VER_2_0 = 1,
2773c5960c0SKyle Tso 	SVDM_VER_MAX = SVDM_VER_2_0,
2783c5960c0SKyle Tso };
2793c5960c0SKyle Tso 
280fab92884SHeikki Krogerus /*
281fab92884SHeikki Krogerus  * struct typec_capability - USB Type-C Port Capabilities
282ceeb1625SHeikki Krogerus  * @type: Supported power role of the port
283ceeb1625SHeikki Krogerus  * @data: Supported data role of the port
284fab92884SHeikki Krogerus  * @revision: USB Type-C Specification release. Binary coded decimal
285fab92884SHeikki Krogerus  * @pd_revision: USB Power Delivery Specification revision if supported
2863c5960c0SKyle Tso  * @svdm_version: USB PD Structured VDM version if supported
287ceeb1625SHeikki Krogerus  * @prefer_role: Initial role preference (DRP ports).
288fab92884SHeikki Krogerus  * @accessory: Supported Accessory Modes
2898060bcb1SHeikki Krogerus  * @usb_capability: Supported USB Modes
290fab92884SHeikki Krogerus  * @fwnode: Optional fwnode of the port
2918c127a42SHeikki Krogerus  * @driver_data: Private pointer for driver specific info
292a7cff92fSHeikki Krogerus  * @pd: Optional USB Power Delivery Support
29346310e4dSHeikki Krogerus  * @ops: Port operations vector
294fab92884SHeikki Krogerus  *
295fab92884SHeikki Krogerus  * Static capabilities of a single USB Type-C port.
296fab92884SHeikki Krogerus  */
297fab92884SHeikki Krogerus struct typec_capability {
298fab92884SHeikki Krogerus 	enum typec_port_type	type;
299ceeb1625SHeikki Krogerus 	enum typec_port_data	data;
300fab92884SHeikki Krogerus 	u16			revision; /* 0120H = "1.2" */
301fab92884SHeikki Krogerus 	u16			pd_revision; /* 0300H = "3.0" */
3023c5960c0SKyle Tso 	enum usb_pd_svdm_ver	svdm_version;
303fab92884SHeikki Krogerus 	int			prefer_role;
304fab92884SHeikki Krogerus 	enum typec_accessory	accessory[TYPEC_MAX_ACCESSORY];
30575f81a7fSBadhri Jagan Sridharan 	unsigned int		orientation_aware:1;
3068060bcb1SHeikki Krogerus 	u8			usb_capability;
307fab92884SHeikki Krogerus 
308fab92884SHeikki Krogerus 	struct fwnode_handle	*fwnode;
3098c127a42SHeikki Krogerus 	void			*driver_data;
310fab92884SHeikki Krogerus 
311a7cff92fSHeikki Krogerus 	struct usb_power_delivery *pd;
312a7cff92fSHeikki Krogerus 
31346310e4dSHeikki Krogerus 	const struct typec_operations	*ops;
314fab92884SHeikki Krogerus };
315fab92884SHeikki Krogerus 
316fab92884SHeikki Krogerus /* Specific to try_role(). Indicates the user want's to clear the preference. */
317fab92884SHeikki Krogerus #define TYPEC_NO_PREFERRED_ROLE	(-1)
318fab92884SHeikki Krogerus 
319fab92884SHeikki Krogerus struct typec_port *typec_register_port(struct device *parent,
320fab92884SHeikki Krogerus 				       const struct typec_capability *cap);
321fab92884SHeikki Krogerus void typec_unregister_port(struct typec_port *port);
322fab92884SHeikki Krogerus 
323fab92884SHeikki Krogerus struct typec_partner *typec_register_partner(struct typec_port *port,
324fab92884SHeikki Krogerus 					     struct typec_partner_desc *desc);
325fab92884SHeikki Krogerus void typec_unregister_partner(struct typec_partner *partner);
326fab92884SHeikki Krogerus 
327fab92884SHeikki Krogerus struct typec_cable *typec_register_cable(struct typec_port *port,
328fab92884SHeikki Krogerus 					 struct typec_cable_desc *desc);
329fab92884SHeikki Krogerus void typec_unregister_cable(struct typec_cable *cable);
330fab92884SHeikki Krogerus 
331b66b40eeSHeikki Krogerus struct typec_cable *typec_cable_get(struct typec_port *port);
332b66b40eeSHeikki Krogerus void typec_cable_put(struct typec_cable *cable);
333b66b40eeSHeikki Krogerus int typec_cable_is_active(struct typec_cable *cable);
334b66b40eeSHeikki Krogerus 
335fab92884SHeikki Krogerus struct typec_plug *typec_register_plug(struct typec_cable *cable,
336fab92884SHeikki Krogerus 				       struct typec_plug_desc *desc);
337fab92884SHeikki Krogerus void typec_unregister_plug(struct typec_plug *plug);
338fab92884SHeikki Krogerus 
339fab92884SHeikki Krogerus void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
340fab92884SHeikki Krogerus void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
341fab92884SHeikki Krogerus void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
342fab92884SHeikki Krogerus void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
343fab92884SHeikki Krogerus 
344bdecb33aSHeikki Krogerus int typec_set_orientation(struct typec_port *port,
345bdecb33aSHeikki Krogerus 			  enum typec_orientation orientation);
346aaf3f4e9SHeikki Krogerus enum typec_orientation typec_get_orientation(struct typec_port *port);
347bdecb33aSHeikki Krogerus int typec_set_mode(struct typec_port *port, int mode);
348bdecb33aSHeikki Krogerus 
3498c127a42SHeikki Krogerus void *typec_get_drvdata(struct typec_port *port);
3508c127a42SHeikki Krogerus 
3512e7dfb0eSSamuel Holland int typec_get_fw_cap(struct typec_capability *cap,
3522e7dfb0eSSamuel Holland 		     struct fwnode_handle *fwnode);
3532e7dfb0eSSamuel Holland 
35412f3467bSAmelie Delaunay int typec_find_pwr_opmode(const char *name);
3558c49c9eeSHeikki Krogerus int typec_find_orientation(const char *name);
3569c90e024SLi Jun int typec_find_port_power_role(const char *name);
3579c90e024SLi Jun int typec_find_power_role(const char *name);
3589c90e024SLi Jun int typec_find_port_data_role(const char *name);
3593c5960c0SKyle Tso 
3603c5960c0SKyle Tso void typec_partner_set_svdm_version(struct typec_partner *partner,
3613c5960c0SKyle Tso 				    enum usb_pd_svdm_ver svdm_version);
3623c5960c0SKyle Tso int typec_get_negotiated_svdm_version(struct typec_port *port);
363ae196ddbSHeikki Krogerus 
364231b7318SRD Babiera int typec_get_cable_svdm_version(struct typec_port *port);
365231b7318SRD Babiera void typec_cable_set_svdm_version(struct typec_cable *cable, enum usb_pd_svdm_ver svdm_version);
366231b7318SRD Babiera 
36703239981SPrashant Malani struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner,
36803239981SPrashant Malani 							struct usb_power_delivery_desc *desc);
36903239981SPrashant Malani 
370a7cff92fSHeikki Krogerus int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd);
371a7cff92fSHeikki Krogerus int typec_partner_set_usb_power_delivery(struct typec_partner *partner,
372a7cff92fSHeikki Krogerus 					 struct usb_power_delivery *pd);
373a7cff92fSHeikki Krogerus 
3742140a952SHeikki Krogerus void typec_partner_set_usb_mode(struct typec_partner *partner, enum usb_mode usb_mode);
3758060bcb1SHeikki Krogerus void typec_port_set_usb_mode(struct typec_port *port, enum usb_mode mode);
3768060bcb1SHeikki Krogerus 
37759de2a56SHeikki Krogerus /**
37859de2a56SHeikki Krogerus  * struct typec_connector - Representation of Type-C port for external drivers
37959de2a56SHeikki Krogerus  * @attach: notification about device removal
38059de2a56SHeikki Krogerus  * @deattach: notification about device removal
38159de2a56SHeikki Krogerus  *
38259de2a56SHeikki Krogerus  * Drivers that control the USB and other ports (DisplayPorts, etc.), that are
38359de2a56SHeikki Krogerus  * connected to the Type-C connectors, can use these callbacks to inform the
38459de2a56SHeikki Krogerus  * Type-C connector class about connections and disconnections. That information
38559de2a56SHeikki Krogerus  * can then be used by the typec-port drivers to power on or off parts that are
38659de2a56SHeikki Krogerus  * needed or not needed - as an example, in USB mode if USB2 device is
38759de2a56SHeikki Krogerus  * enumerated, USB3 components (retimers, phys, and what have you) do not need
38859de2a56SHeikki Krogerus  * to be powered on.
38959de2a56SHeikki Krogerus  *
39059de2a56SHeikki Krogerus  * The attached (enumerated) devices will be liked with the typec-partner device.
39159de2a56SHeikki Krogerus  */
39259de2a56SHeikki Krogerus struct typec_connector {
39359de2a56SHeikki Krogerus 	void (*attach)(struct typec_connector *con, struct device *dev);
39459de2a56SHeikki Krogerus 	void (*deattach)(struct typec_connector *con, struct device *dev);
39559de2a56SHeikki Krogerus };
39659de2a56SHeikki Krogerus 
typec_attach(struct typec_connector * con,struct device * dev)39759de2a56SHeikki Krogerus static inline void typec_attach(struct typec_connector *con, struct device *dev)
39859de2a56SHeikki Krogerus {
39959de2a56SHeikki Krogerus 	if (con && con->attach)
40059de2a56SHeikki Krogerus 		con->attach(con, dev);
40159de2a56SHeikki Krogerus }
40259de2a56SHeikki Krogerus 
typec_deattach(struct typec_connector * con,struct device * dev)40359de2a56SHeikki Krogerus static inline void typec_deattach(struct typec_connector *con, struct device *dev)
40459de2a56SHeikki Krogerus {
40559de2a56SHeikki Krogerus 	if (con && con->deattach)
40659de2a56SHeikki Krogerus 		con->deattach(con, dev);
40759de2a56SHeikki Krogerus }
40859de2a56SHeikki Krogerus 
409fab92884SHeikki Krogerus #endif /* __LINUX_USB_TYPEC_H */
410