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