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 #include <linux/android_kabi.h>
9
10 struct typec_mux;
11 struct typec_switch;
12 struct usb_device;
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 ANDROID_KABI_RESERVE(1);
20 };
21
22 struct typec_cable {
23 struct device dev;
24 enum typec_plug_type type;
25 struct usb_pd_identity *identity;
26 unsigned int active:1;
27 u16 pd_revision; /* 0300H = "3.0" */
28 enum usb_pd_svdm_ver svdm_version;
29 ANDROID_KABI_RESERVE(1);
30 };
31
32 struct typec_partner {
33 struct device dev;
34 unsigned int usb_pd:1;
35 struct usb_pd_identity *identity;
36 enum typec_accessory accessory;
37 struct ida mode_ids;
38 int num_altmodes;
39 u16 pd_revision; /* 0300H = "3.0" */
40 enum usb_pd_svdm_ver svdm_version;
41
42 struct usb_power_delivery *pd;
43
44 void (*attach)(struct typec_partner *partner, struct device *dev);
45 void (*deattach)(struct typec_partner *partner, struct device *dev);
46 ANDROID_KABI_RESERVE(1);
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 struct mutex port_type_lock;
63
64 enum typec_orientation orientation;
65 struct typec_switch *sw;
66 struct typec_mux *mux;
67 struct typec_retimer *retimer;
68
69 const struct typec_capability *cap;
70 const struct typec_operations *ops;
71
72 struct typec_connector con;
73
74 /*
75 * REVISIT: Only USB devices for now. If there are others, these need to
76 * be converted into a list.
77 *
78 * NOTE: These may be registered first before the typec_partner, so they
79 * will always have to be kept here instead of struct typec_partner.
80 */
81 struct device *usb2_dev;
82 struct device *usb3_dev;
83 ANDROID_KABI_RESERVE(1);
84 };
85
86 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
87 #define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
88 #define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
89 #define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
90
91 extern const struct device_type typec_partner_dev_type;
92 extern const struct device_type typec_cable_dev_type;
93 extern const struct device_type typec_plug_dev_type;
94 extern const struct device_type typec_port_dev_type;
95
96 #define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type)
97 #define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type)
98 #define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type)
99 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type)
100
101 extern const struct class typec_mux_class;
102 extern const struct class retimer_class;
103 extern const struct class typec_class;
104
105 #if defined(CONFIG_ACPI)
106 int typec_link_ports(struct typec_port *connector);
107 void typec_unlink_ports(struct typec_port *connector);
108 #else
typec_link_ports(struct typec_port * connector)109 static inline int typec_link_ports(struct typec_port *connector) { return 0; }
typec_unlink_ports(struct typec_port * connector)110 static inline void typec_unlink_ports(struct typec_port *connector) { }
111 #endif
112
113 #endif /* __USB_TYPEC_CLASS__ */
114