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