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 
9 struct typec_mux;
10 struct typec_switch;
11 
12 struct typec_plug {
13 	struct device			dev;
14 	enum typec_plug_index		index;
15 	struct ida			mode_ids;
16 	int				num_altmodes;
17 };
18 
19 struct typec_cable {
20 	struct device			dev;
21 	enum typec_plug_type		type;
22 	struct usb_pd_identity		*identity;
23 	unsigned int			active:1;
24 	u16				pd_revision; /* 0300H = "3.0" */
25 };
26 
27 struct typec_partner {
28 	struct device			dev;
29 	unsigned int			usb_pd:1;
30 	struct usb_pd_identity		*identity;
31 	enum typec_accessory		accessory;
32 	struct ida			mode_ids;
33 	int				num_altmodes;
34 	u16				pd_revision; /* 0300H = "3.0" */
35 	enum usb_pd_svdm_ver		svdm_version;
36 
37 	struct usb_power_delivery	*pd;
38 };
39 
40 struct typec_port {
41 	unsigned int			id;
42 	struct device			dev;
43 	struct ida			mode_ids;
44 
45 	struct usb_power_delivery	*pd;
46 
47 	int				prefer_role;
48 	enum typec_data_role		data_role;
49 	enum typec_role			pwr_role;
50 	enum typec_role			vconn_role;
51 	enum typec_pwr_opmode		pwr_opmode;
52 	enum typec_port_type		port_type;
53 	struct mutex			port_type_lock;
54 
55 	enum typec_orientation		orientation;
56 	struct typec_switch		*sw;
57 	struct typec_mux		*mux;
58 	struct typec_retimer		*retimer;
59 
60 	const struct typec_capability	*cap;
61 	const struct typec_operations   *ops;
62 };
63 
64 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
65 #define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
66 #define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
67 #define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
68 
69 extern const struct device_type typec_partner_dev_type;
70 extern const struct device_type typec_cable_dev_type;
71 extern const struct device_type typec_plug_dev_type;
72 extern const struct device_type typec_port_dev_type;
73 
74 #define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type)
75 #define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type)
76 #define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type)
77 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type)
78 
79 extern struct class typec_mux_class;
80 extern struct class retimer_class;
81 extern struct class typec_class;
82 
83 #if defined(CONFIG_ACPI)
84 int typec_link_ports(struct typec_port *connector);
85 void typec_unlink_ports(struct typec_port *connector);
86 #else
typec_link_ports(struct typec_port * connector)87 static inline int typec_link_ports(struct typec_port *connector) { return 0; }
typec_unlink_ports(struct typec_port * connector)88 static inline void typec_unlink_ports(struct typec_port *connector) { }
89 #endif
90 
91 #endif /* __USB_TYPEC_CLASS__ */
92