Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2077649ybb; Thu, 9 Apr 2020 14:48:37 -0700 (PDT) X-Google-Smtp-Source: APiQypKblqGZxWEMEzejFQXj/f47cZ9AEohILfYVyBtQ7l7tOcp+gq15eK1gzWPkFKomU9e3GnO7 X-Received: by 2002:ac8:6890:: with SMTP id m16mr1563196qtq.5.1586468917113; Thu, 09 Apr 2020 14:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586468917; cv=none; d=google.com; s=arc-20160816; b=cz6y7jCW1H8evzuiCzrrko/I0hMIu3tn0vQ66Se5AfFx6ZlvU5abF8KV5vXcE/VphR YZJwp9HEI8k3umrm1T02RDDBIxOH0l1HdAGfNdK3V2mM0k7HKQ3dGcHAGTYaU9uKpieW iu7eemGJx+BUrj2J4voWWGM8Vb8eUmXsH3AI5BwyK35xgXKfV563txKfmKwgZjGRnnia kNqeW9RRnRyEjgK+TGZBjnb4CzPmE5B9to1+bzO0nt02Nq/RbBrBk6Aun0byJAmdpWIK K4geSi7+mTZId3Ec/WRFR2a4qfeslJ+xoegEGIYpNtfnvI95uJ5ck4+09MoRlWS6Qmp6 +Igg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=QsWXdcpSclvMh5A5GbMf+ij64oERilgYD2tFESvJ8sw=; b=chKiLCQ/nerbkDwPiAkm3hvA70MfoZEwQlnMF5YdLIl383iaaEhdnk086lhw1VxgfW VbbcPFc4tQdQrDx1/EQ0gQK3Xc9A9vHPil63VgOahq1HjAqA0acw0aGlrGThvuwEC3A/ CUcq8kWrBnNYbYcLQw5ws4IyxIVPULYODkE5U4305/oITASumwuQDFpRRiKxbGRoFWnk RVEzRZVM+RkmMneJ2frENoP5vRFQ4plT1tZSCQWd6sddUycwtFil1oIx2p54OhcP731z cYw+wdSkcUhvsPmTNQLX83w5xnfwjXreroaJfPG3kpC00zmVNxJk8jAMhCR6hFXmsX5l rWFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b11si2060922qvt.124.2020.04.09.14.48.21; Thu, 09 Apr 2020 14:48:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbgDIVko (ORCPT + 99 others); Thu, 9 Apr 2020 17:40:44 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:42244 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbgDIVko (ORCPT ); Thu, 9 Apr 2020 17:40:44 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 287EA297BA7 Subject: Re: [PATCH 3/3] platform/chrome: typec: Register port partner To: Prashant Malani , linux-kernel@vger.kernel.org Cc: heikki.krogerus@linux.intel.com, Jon Flatley , Benson Leung , Guenter Roeck References: <20200407010940.155490-1-pmalani@chromium.org> <20200407010940.155490-4-pmalani@chromium.org> From: Enric Balletbo i Serra Message-ID: <6ad18c9b-6c51-e08a-fb45-d97c9722a693@collabora.com> Date: Thu, 9 Apr 2020 23:40:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200407010940.155490-4-pmalani@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Prashant, Thank you for your patch. On 7/4/20 3:09, Prashant Malani wrote: > Register (and unregister) the port partner when a connect (and > disconnect) is detected. > > Co-developed-by: Jon Flatley > Signed-off-by: Prashant Malani > --- > drivers/platform/chrome/cros_ec_typec.c | 47 +++++++++++++++++++++++++ > 1 file changed, 47 insertions(+) > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c > index 1955e1dfebc6d..e7d4d6ccccca6 100644 > --- a/drivers/platform/chrome/cros_ec_typec.c > +++ b/drivers/platform/chrome/cros_ec_typec.c > @@ -22,6 +22,9 @@ struct cros_typec_port { > struct typec_port *port; > /* Initial capabilities for the port. */ > struct typec_capability caps; > + struct typec_partner *partner; > + /* Port partner PD identity info. */ > + struct usb_pd_identity p_identity; > }; > > /* Platform-specific data for the Chrome OS EC Type C controller. */ > @@ -191,6 +194,29 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, > return ret; > } > > +static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num, > + bool pd_en) > +{ > + struct cros_typec_port *port = typec->ports[port_num]; > + struct typec_partner_desc p_desc = { > + .usb_pd = pd_en, > + }; > + > + /* > + * Fill an initial PD identity, which will then be updated with info > + * from the EC. > + */ > + p_desc.identity = &port->p_identity; > + > + port->partner = typec_register_partner(port->port, &p_desc); > + if (IS_ERR_OR_NULL(port->partner)) { > + port->partner = NULL; > + return PTR_ERR(port->partner); This is always returning PTR_ERR(NULL) that yields 0, that's not what you want. A static checker warning will be triggered. > + } > + > + return 0; > +} > + > static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, > int port_num, struct ec_response_usb_pd_control *resp) > { > @@ -213,6 +239,8 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, > { > struct typec_port *port = typec->ports[port_num]->port; > enum typec_orientation polarity; > + bool pd_en; > + int ret; > > if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) > polarity = TYPEC_ORIENTATION_NONE; > @@ -227,6 +255,25 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, > TYPEC_SOURCE : TYPEC_SINK); > typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ? > TYPEC_SOURCE : TYPEC_SINK); > + > + /* Register/remove partners when a connect/disconnect occurs. */ > + if (resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED) { > + if (typec->ports[port_num]->partner) > + return; > + > + pd_en = resp->enabled & PD_CTRL_RESP_ENABLED_PD_CAPABLE; > + ret = cros_typec_add_partner(typec, port_num, pd_en); > + if (!ret) > + dev_warn(typec->dev, > + "Failed to register partner on port: %d\n", > + port_num); > + } else { > + if (!typec->ports[port_num]->partner) > + return; > + > + typec_unregister_partner(typec->ports[port_num]->partner); > + typec->ports[port_num]->partner = NULL; > + } > } > > static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) >