@@ -22,6 +22,9 @@ struct cros_typec_port {
22
22
struct typec_port * port ;
23
23
/* Initial capabilities for the port. */
24
24
struct typec_capability caps ;
25
+ struct typec_partner * partner ;
26
+ /* Port partner PD identity info. */
27
+ struct usb_pd_identity p_identity ;
25
28
};
26
29
27
30
/* Platform-specific data for the Chrome OS EC Type C controller. */
@@ -190,6 +193,30 @@ static int cros_typec_ec_command(struct cros_typec_data *typec,
190
193
return ret ;
191
194
}
192
195
196
+ static int cros_typec_add_partner (struct cros_typec_data * typec , int port_num ,
197
+ bool pd_en )
198
+ {
199
+ struct cros_typec_port * port = typec -> ports [port_num ];
200
+ struct typec_partner_desc p_desc = {
201
+ .usb_pd = pd_en ,
202
+ };
203
+ int ret = 0 ;
204
+
205
+ /*
206
+ * Fill an initial PD identity, which will then be updated with info
207
+ * from the EC.
208
+ */
209
+ p_desc .identity = & port -> p_identity ;
210
+
211
+ port -> partner = typec_register_partner (port -> port , & p_desc );
212
+ if (IS_ERR (port -> partner )) {
213
+ ret = PTR_ERR (port -> partner );
214
+ port -> partner = NULL ;
215
+ }
216
+
217
+ return ret ;
218
+ }
219
+
193
220
static void cros_typec_set_port_params_v0 (struct cros_typec_data * typec ,
194
221
int port_num , struct ec_response_usb_pd_control * resp )
195
222
{
@@ -212,6 +239,8 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
212
239
{
213
240
struct typec_port * port = typec -> ports [port_num ]-> port ;
214
241
enum typec_orientation polarity ;
242
+ bool pd_en ;
243
+ int ret ;
215
244
216
245
if (!(resp -> enabled & PD_CTRL_RESP_ENABLED_CONNECTED ))
217
246
polarity = TYPEC_ORIENTATION_NONE ;
@@ -226,6 +255,25 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
226
255
TYPEC_SOURCE : TYPEC_SINK );
227
256
typec_set_vconn_role (port , resp -> role & PD_CTRL_RESP_ROLE_VCONN ?
228
257
TYPEC_SOURCE : TYPEC_SINK );
258
+
259
+ /* Register/remove partners when a connect/disconnect occurs. */
260
+ if (resp -> enabled & PD_CTRL_RESP_ENABLED_CONNECTED ) {
261
+ if (typec -> ports [port_num ]-> partner )
262
+ return ;
263
+
264
+ pd_en = resp -> enabled & PD_CTRL_RESP_ENABLED_PD_CAPABLE ;
265
+ ret = cros_typec_add_partner (typec , port_num , pd_en );
266
+ if (!ret )
267
+ dev_warn (typec -> dev ,
268
+ "Failed to register partner on port: %d\n" ,
269
+ port_num );
270
+ } else {
271
+ if (!typec -> ports [port_num ]-> partner )
272
+ return ;
273
+
274
+ typec_unregister_partner (typec -> ports [port_num ]-> partner );
275
+ typec -> ports [port_num ]-> partner = NULL ;
276
+ }
229
277
}
230
278
231
279
static int cros_typec_port_update (struct cros_typec_data * typec , int port_num )
0 commit comments