Skip to content

Commit 9d33ea3

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_typec: Register port partner
Register (and unregister) the port partner when a connect (and disconnect) is detected. Co-developed-by: Jon Flatley <[email protected]> Signed-off-by: Prashant Malani <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent 5fed73b commit 9d33ea3

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ struct cros_typec_port {
2222
struct typec_port *port;
2323
/* Initial capabilities for the port. */
2424
struct typec_capability caps;
25+
struct typec_partner *partner;
26+
/* Port partner PD identity info. */
27+
struct usb_pd_identity p_identity;
2528
};
2629

2730
/* 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,
190193
return ret;
191194
}
192195

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+
193220
static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
194221
int port_num, struct ec_response_usb_pd_control *resp)
195222
{
@@ -212,6 +239,8 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
212239
{
213240
struct typec_port *port = typec->ports[port_num]->port;
214241
enum typec_orientation polarity;
242+
bool pd_en;
243+
int ret;
215244

216245
if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED))
217246
polarity = TYPEC_ORIENTATION_NONE;
@@ -226,6 +255,25 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
226255
TYPEC_SOURCE : TYPEC_SINK);
227256
typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ?
228257
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+
}
229277
}
230278

231279
static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)

0 commit comments

Comments
 (0)