1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef __USB_TYPEC_CLASS__
4#define __USB_TYPEC_CLASS__
5
6#include <linux/device.h>
7#include <linux/usb/typec.h>
8
9struct typec_mux;
10struct typec_switch;
11struct usb_device;
12
13struct typec_plug {
14	struct device			dev;
15	enum typec_plug_index		index;
16	struct ida			mode_ids;
17	int				num_altmodes;
18};
19
20struct typec_cable {
21	struct device			dev;
22	enum typec_plug_type		type;
23	struct usb_pd_identity		*identity;
24	unsigned int			active:1;
25	u16				pd_revision; /* 0300H = "3.0" */
26	enum usb_pd_svdm_ver		svdm_version;
27};
28
29struct typec_partner {
30	struct device			dev;
31	unsigned int			usb_pd:1;
32	struct usb_pd_identity		*identity;
33	enum typec_accessory		accessory;
34	struct ida			mode_ids;
35	int				num_altmodes;
36	u16				pd_revision; /* 0300H = "3.0" */
37	enum usb_pd_svdm_ver		svdm_version;
38
39	struct usb_power_delivery	*pd;
40
41	void (*attach)(struct typec_partner *partner, struct device *dev);
42	void (*deattach)(struct typec_partner *partner, struct device *dev);
43};
44
45struct typec_port {
46	unsigned int			id;
47	struct device			dev;
48	struct ida			mode_ids;
49
50	struct usb_power_delivery	*pd;
51
52	int				prefer_role;
53	enum typec_data_role		data_role;
54	enum typec_role			pwr_role;
55	enum typec_role			vconn_role;
56	enum typec_pwr_opmode		pwr_opmode;
57	enum typec_port_type		port_type;
58	struct mutex			port_type_lock;
59
60	enum typec_orientation		orientation;
61	struct typec_switch		*sw;
62	struct typec_mux		*mux;
63	struct typec_retimer		*retimer;
64
65	const struct typec_capability	*cap;
66	const struct typec_operations   *ops;
67
68	struct typec_connector		con;
69
70	/*
71	 * REVISIT: Only USB devices for now. If there are others, these need to
72	 * be converted into a list.
73	 *
74	 * NOTE: These may be registered first before the typec_partner, so they
75	 * will always have to be kept here instead of struct typec_partner.
76	 */
77	struct device			*usb2_dev;
78	struct device			*usb3_dev;
79};
80
81#define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
82#define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
83#define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
84#define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
85
86extern const struct device_type typec_partner_dev_type;
87extern const struct device_type typec_cable_dev_type;
88extern const struct device_type typec_plug_dev_type;
89extern const struct device_type typec_port_dev_type;
90
91#define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type)
92#define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type)
93#define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type)
94#define is_typec_port(dev) ((dev)->type == &typec_port_dev_type)
95
96extern const struct class typec_mux_class;
97extern const struct class retimer_class;
98extern const struct class typec_class;
99
100#if defined(CONFIG_ACPI)
101int typec_link_ports(struct typec_port *connector);
102void typec_unlink_ports(struct typec_port *connector);
103#else
104static inline int typec_link_ports(struct typec_port *connector) { return 0; }
105static inline void typec_unlink_ports(struct typec_port *connector) { }
106#endif
107
108#endif /* __USB_TYPEC_CLASS__ */
109