Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
fab92884 HK |
2 | |
3 | #ifndef __LINUX_USB_TYPEC_H | |
4 | #define __LINUX_USB_TYPEC_H | |
5 | ||
6 | #include <linux/types.h> | |
7 | ||
fab92884 HK |
8 | /* USB Type-C Specification releases */ |
9 | #define USB_TYPEC_REV_1_0 0x100 /* 1.0 */ | |
10 | #define USB_TYPEC_REV_1_1 0x110 /* 1.1 */ | |
11 | #define USB_TYPEC_REV_1_2 0x120 /* 1.2 */ | |
0ac53493 HK |
12 | #define USB_TYPEC_REV_1_3 0x130 /* 1.3 */ |
13 | #define USB_TYPEC_REV_1_4 0x140 /* 1.4 */ | |
14 | #define USB_TYPEC_REV_2_0 0x200 /* 2.0 */ | |
fab92884 | 15 | |
fab92884 HK |
16 | struct typec_partner; |
17 | struct typec_cable; | |
18 | struct typec_plug; | |
19 | struct typec_port; | |
20 | ||
21 | struct fwnode_handle; | |
8a37d87d | 22 | struct device; |
fab92884 HK |
23 | |
24 | enum typec_port_type { | |
ceeb1625 HK |
25 | TYPEC_PORT_SRC, |
26 | TYPEC_PORT_SNK, | |
27 | TYPEC_PORT_DRP, | |
28 | }; | |
29 | ||
30 | enum typec_port_data { | |
fab92884 HK |
31 | TYPEC_PORT_DFP, |
32 | TYPEC_PORT_UFP, | |
ceeb1625 | 33 | TYPEC_PORT_DRD, |
fab92884 HK |
34 | }; |
35 | ||
36 | enum typec_plug_type { | |
37 | USB_PLUG_NONE, | |
38 | USB_PLUG_TYPE_A, | |
39 | USB_PLUG_TYPE_B, | |
40 | USB_PLUG_TYPE_C, | |
41 | USB_PLUG_CAPTIVE, | |
42 | }; | |
43 | ||
44 | enum typec_data_role { | |
45 | TYPEC_DEVICE, | |
46 | TYPEC_HOST, | |
47 | }; | |
48 | ||
49 | enum typec_role { | |
50 | TYPEC_SINK, | |
51 | TYPEC_SOURCE, | |
52 | }; | |
53 | ||
54 | enum typec_pwr_opmode { | |
55 | TYPEC_PWR_MODE_USB, | |
56 | TYPEC_PWR_MODE_1_5A, | |
57 | TYPEC_PWR_MODE_3_0A, | |
58 | TYPEC_PWR_MODE_PD, | |
59 | }; | |
60 | ||
61 | enum typec_accessory { | |
62 | TYPEC_ACCESSORY_NONE, | |
63 | TYPEC_ACCESSORY_AUDIO, | |
64 | TYPEC_ACCESSORY_DEBUG, | |
65 | }; | |
66 | ||
67 | #define TYPEC_MAX_ACCESSORY 3 | |
68 | ||
bdecb33a HK |
69 | enum typec_orientation { |
70 | TYPEC_ORIENTATION_NONE, | |
71 | TYPEC_ORIENTATION_NORMAL, | |
72 | TYPEC_ORIENTATION_REVERSE, | |
73 | }; | |
74 | ||
fab92884 HK |
75 | /* |
76 | * struct usb_pd_identity - USB Power Delivery identity data | |
77 | * @id_header: ID Header VDO | |
78 | * @cert_stat: Cert Stat VDO | |
79 | * @product: Product VDO | |
f6c56ca9 | 80 | * @vdo: Product Type Specific VDOs |
fab92884 HK |
81 | * |
82 | * USB power delivery Discover Identity command response data. | |
83 | * | |
84 | * REVISIT: This is USB Power Delivery specific information, so this structure | |
85 | * probable belongs to USB Power Delivery header file once we have them. | |
86 | */ | |
87 | struct usb_pd_identity { | |
88 | u32 id_header; | |
89 | u32 cert_stat; | |
90 | u32 product; | |
f6c56ca9 | 91 | u32 vdo[3]; |
fab92884 HK |
92 | }; |
93 | ||
94 | int typec_partner_set_identity(struct typec_partner *partner); | |
95 | int typec_cable_set_identity(struct typec_cable *cable); | |
96 | ||
97 | /* | |
4ab8c18d HK |
98 | * struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor |
99 | * @svid: Standard or Vendor ID | |
100 | * @mode: Index of the Mode | |
fab92884 | 101 | * @vdo: VDO returned by Discover Modes USB PD command |
fab92884 HK |
102 | * @roles: Only for ports. DRP if the mode is available in both roles |
103 | * | |
4ab8c18d HK |
104 | * Description of an Alternate Mode which a connector, cable plug or partner |
105 | * supports. | |
fab92884 | 106 | */ |
4ab8c18d HK |
107 | struct typec_altmode_desc { |
108 | u16 svid; | |
109 | u8 mode; | |
fab92884 | 110 | u32 vdo; |
fab92884 | 111 | /* Only used with ports */ |
8a37d87d | 112 | enum typec_port_data roles; |
fab92884 HK |
113 | }; |
114 | ||
fab92884 HK |
115 | struct typec_altmode |
116 | *typec_partner_register_altmode(struct typec_partner *partner, | |
a86c309e | 117 | const struct typec_altmode_desc *desc); |
fab92884 HK |
118 | struct typec_altmode |
119 | *typec_plug_register_altmode(struct typec_plug *plug, | |
a86c309e | 120 | const struct typec_altmode_desc *desc); |
fab92884 HK |
121 | struct typec_altmode |
122 | *typec_port_register_altmode(struct typec_port *port, | |
a86c309e | 123 | const struct typec_altmode_desc *desc); |
fab92884 HK |
124 | void typec_unregister_altmode(struct typec_altmode *altmode); |
125 | ||
126 | struct typec_port *typec_altmode2port(struct typec_altmode *alt); | |
127 | ||
4ab8c18d | 128 | void typec_altmode_update_active(struct typec_altmode *alt, bool active); |
fab92884 HK |
129 | |
130 | enum typec_plug_index { | |
131 | TYPEC_PLUG_SOP_P, | |
132 | TYPEC_PLUG_SOP_PP, | |
133 | }; | |
134 | ||
135 | /* | |
136 | * struct typec_plug_desc - USB Type-C Cable Plug Descriptor | |
137 | * @index: SOP Prime for the plug connected to DFP and SOP Double Prime for the | |
138 | * plug connected to UFP | |
139 | * | |
140 | * Represents USB Type-C Cable Plug. | |
141 | */ | |
142 | struct typec_plug_desc { | |
143 | enum typec_plug_index index; | |
144 | }; | |
145 | ||
146 | /* | |
147 | * struct typec_cable_desc - USB Type-C Cable Descriptor | |
148 | * @type: The plug type from USB PD Cable VDO | |
149 | * @active: Is the cable active or passive | |
150 | * @identity: Result of Discover Identity command | |
151 | * | |
152 | * Represents USB Type-C Cable attached to USB Type-C port. | |
153 | */ | |
154 | struct typec_cable_desc { | |
155 | enum typec_plug_type type; | |
156 | unsigned int active:1; | |
157 | struct usb_pd_identity *identity; | |
158 | }; | |
159 | ||
160 | /* | |
161 | * struct typec_partner_desc - USB Type-C Partner Descriptor | |
162 | * @usb_pd: USB Power Delivery support | |
163 | * @accessory: Audio, Debug or none. | |
164 | * @identity: Discover Identity command data | |
165 | * | |
166 | * Details about a partner that is attached to USB Type-C port. If @identity | |
167 | * member exists when partner is registered, a directory named "identity" is | |
168 | * created to sysfs for the partner device. | |
169 | */ | |
170 | struct typec_partner_desc { | |
171 | unsigned int usb_pd:1; | |
172 | enum typec_accessory accessory; | |
173 | struct usb_pd_identity *identity; | |
174 | }; | |
175 | ||
46310e4d HK |
176 | /** |
177 | * struct typec_operations - USB Type-C Port Operations | |
178 | * @try_role: Set data role preference for DRP port | |
179 | * @dr_set: Set Data Role | |
180 | * @pr_set: Set Power Role | |
181 | * @vconn_set: Source VCONN | |
182 | * @port_type_set: Set port type | |
183 | */ | |
184 | struct typec_operations { | |
185 | int (*try_role)(struct typec_port *port, int role); | |
186 | int (*dr_set)(struct typec_port *port, enum typec_data_role role); | |
187 | int (*pr_set)(struct typec_port *port, enum typec_role role); | |
188 | int (*vconn_set)(struct typec_port *port, enum typec_role role); | |
189 | int (*port_type_set)(struct typec_port *port, | |
190 | enum typec_port_type type); | |
191 | }; | |
192 | ||
fab92884 HK |
193 | /* |
194 | * struct typec_capability - USB Type-C Port Capabilities | |
ceeb1625 HK |
195 | * @type: Supported power role of the port |
196 | * @data: Supported data role of the port | |
fab92884 HK |
197 | * @revision: USB Type-C Specification release. Binary coded decimal |
198 | * @pd_revision: USB Power Delivery Specification revision if supported | |
ceeb1625 | 199 | * @prefer_role: Initial role preference (DRP ports). |
fab92884 HK |
200 | * @accessory: Supported Accessory Modes |
201 | * @fwnode: Optional fwnode of the port | |
8c127a42 | 202 | * @driver_data: Private pointer for driver specific info |
46310e4d | 203 | * @ops: Port operations vector |
fab92884 HK |
204 | * |
205 | * Static capabilities of a single USB Type-C port. | |
206 | */ | |
207 | struct typec_capability { | |
208 | enum typec_port_type type; | |
ceeb1625 | 209 | enum typec_port_data data; |
fab92884 HK |
210 | u16 revision; /* 0120H = "1.2" */ |
211 | u16 pd_revision; /* 0300H = "3.0" */ | |
212 | int prefer_role; | |
213 | enum typec_accessory accessory[TYPEC_MAX_ACCESSORY]; | |
75f81a7f | 214 | unsigned int orientation_aware:1; |
fab92884 HK |
215 | |
216 | struct fwnode_handle *fwnode; | |
8c127a42 | 217 | void *driver_data; |
fab92884 | 218 | |
46310e4d | 219 | const struct typec_operations *ops; |
fab92884 HK |
220 | }; |
221 | ||
222 | /* Specific to try_role(). Indicates the user want's to clear the preference. */ | |
223 | #define TYPEC_NO_PREFERRED_ROLE (-1) | |
224 | ||
225 | struct typec_port *typec_register_port(struct device *parent, | |
226 | const struct typec_capability *cap); | |
227 | void typec_unregister_port(struct typec_port *port); | |
228 | ||
229 | struct typec_partner *typec_register_partner(struct typec_port *port, | |
230 | struct typec_partner_desc *desc); | |
231 | void typec_unregister_partner(struct typec_partner *partner); | |
232 | ||
233 | struct typec_cable *typec_register_cable(struct typec_port *port, | |
234 | struct typec_cable_desc *desc); | |
235 | void typec_unregister_cable(struct typec_cable *cable); | |
236 | ||
b66b40ee HK |
237 | struct typec_cable *typec_cable_get(struct typec_port *port); |
238 | void typec_cable_put(struct typec_cable *cable); | |
239 | int typec_cable_is_active(struct typec_cable *cable); | |
240 | ||
fab92884 HK |
241 | struct typec_plug *typec_register_plug(struct typec_cable *cable, |
242 | struct typec_plug_desc *desc); | |
243 | void typec_unregister_plug(struct typec_plug *plug); | |
244 | ||
245 | void typec_set_data_role(struct typec_port *port, enum typec_data_role role); | |
246 | void typec_set_pwr_role(struct typec_port *port, enum typec_role role); | |
247 | void typec_set_vconn_role(struct typec_port *port, enum typec_role role); | |
248 | void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode); | |
249 | ||
bdecb33a HK |
250 | int typec_set_orientation(struct typec_port *port, |
251 | enum typec_orientation orientation); | |
aaf3f4e9 | 252 | enum typec_orientation typec_get_orientation(struct typec_port *port); |
bdecb33a HK |
253 | int typec_set_mode(struct typec_port *port, int mode); |
254 | ||
8c127a42 HK |
255 | void *typec_get_drvdata(struct typec_port *port); |
256 | ||
9c90e024 LJ |
257 | int typec_find_port_power_role(const char *name); |
258 | int typec_find_power_role(const char *name); | |
259 | int typec_find_port_data_role(const char *name); | |
fab92884 | 260 | #endif /* __LINUX_USB_TYPEC_H */ |