Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp125729pja; Thu, 9 Apr 2020 15:54:02 -0700 (PDT) X-Google-Smtp-Source: APiQypJmyx7/sv9NAUYBBb6FmT65nCQa9lV2ZtP6yeJ3YJMuZP46QLh4oUI/tvKtHveFnCx5BW7E X-Received: by 2002:ac8:23ed:: with SMTP id r42mr1816555qtr.372.1586472841958; Thu, 09 Apr 2020 15:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586472841; cv=none; d=google.com; s=arc-20160816; b=VX1nswbbp5iSjCFPfPYN0ea17WN17iRQO9V0qhxqrUC/3LuCsxBeK3Z4kjOBa7cLIo A8mvF3czR962dJHY1NZU713pCpojPXqilxGgT0X+7xaYbfStpE2UqllzjTxAjcTfTQWH Y0wMm1eZMt+UVsjIQ1OGuSIwkse8wYGdj4ab81kv8joK4MxR5QHaN1SwYeWiqWgfklue 8BwVvFbrRhjNc2ShrSWrJMKei6cSV9/yLxRzTE+q/AT52Ee85zb9uLJmFv3CMptLDwiG EQdRaooqe1PkYuf5ebUht2S5zzi/cL59dvX98mgjiaFvMGVNQfwh7Q3x/D5iz1kCSVCx qk1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=fZdRvWn8lvqjQXOzNVwZx+IIgNLFHEqUPhHnxLXTuMs=; b=xQMVskXuFsVtl9LU5T/KRunNmgWCXUzTU4u6+5ncqXOVz23YSwJv8B3rkiL05SeLED 9bIloNOo+/YQQTd9VgbiC7IGQeHef469lDUMrs9Mb0sQgoSlPPaT6AJ+GDU7dSYd91ed AFzr0lsWihhjorfEb8hNdjMEdFz742L+35mhGObfPoveANRzoV+sj0S1CWYdt/nrD077 7wkjUuWW6VMvwga5mvN9JZOnKNGK7oDPl6TGGxhwrzuePkru8iGjK06lxPSHtIqof6uR gIu10mKfNwKg4irLbvonmIQ9We50jroLAozbpq06IxAMjZKCYzSf0lyiBHYyjvCxYmpF O0Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=b0OwPxXt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w29si104941qtk.157.2020.04.09.15.53.41; Thu, 09 Apr 2020 15:54:01 -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; dkim=pass header.i=@chromium.org header.s=google header.b=b0OwPxXt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbgDIWlB (ORCPT + 99 others); Thu, 9 Apr 2020 18:41:01 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40605 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbgDIWlA (ORCPT ); Thu, 9 Apr 2020 18:41:00 -0400 Received: by mail-pg1-f194.google.com with SMTP id c5so160695pgi.7 for ; Thu, 09 Apr 2020 15:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fZdRvWn8lvqjQXOzNVwZx+IIgNLFHEqUPhHnxLXTuMs=; b=b0OwPxXtSVwr9ydvocYKeylG2JO/6QFhFZVwHwUwJ24NfO2B7hP7Ky4APrE5Tm6Ewq xlqJLyChsB7pDNYHivew4bgeq1UAW3xd5LWc3REmNdgHrNtXgNYGQkf1rL/Ruq8DenDe C05sPsgUM5E51XoVY8wXuJJX2FOxT3Ny7yq5k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fZdRvWn8lvqjQXOzNVwZx+IIgNLFHEqUPhHnxLXTuMs=; b=gUuUagVQwajE2mDhefLtmmm7CnwAsAlqvLDHMGygpWaOQA6KfYnP6/4lhoCWyxfvlo 7ebLp6H5fe0ctRBJYFkd7oey7xJiy0jrk1+6KX87PVWdYKbCw/q4CtkylQkGzZ7Gkpm5 ORnTan7tu5RvM06Woy1hUXNx36tGimz+mcZwXpxTWObGXZ0E+tRBk4Xqux4oijIizAy0 uq3pSZydDd/MBNwvVkM7tolIO0fZ7YJ3zi9iez5VPn1vXHfkSgGmSzayKOKZ/8yDcHFF Fmad4gsHgDSL7q5sBh7m6Y02dwQfBSc9YfOQRja+wKZ6UkDpSU6mpJ7MjDvK3bavoqRC OM4w== X-Gm-Message-State: AGi0PuY18kq1vsR2FFiBrtFxvhQsm+pA/HCdI5dmrK5JFymg1E0DIa3/ 7Wej3/V5dCb3rNZALu8r80Iz9g== X-Received: by 2002:aa7:96f6:: with SMTP id i22mr1953906pfq.137.1586472059786; Thu, 09 Apr 2020 15:40:59 -0700 (PDT) Received: from google.com ([2620:15c:202:201:476b:691:abc3:38db]) by smtp.gmail.com with ESMTPSA id z190sm124336pgz.73.2020.04.09.15.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2020 15:40:59 -0700 (PDT) Date: Thu, 9 Apr 2020 15:40:58 -0700 From: Prashant Malani To: Enric Balletbo i Serra Cc: linux-kernel@vger.kernel.org, heikki.krogerus@linux.intel.com, Jon Flatley , Benson Leung , Guenter Roeck Subject: Re: [PATCH 3/3] platform/chrome: typec: Register port partner Message-ID: <20200409224058.GC15090@google.com> References: <20200407010940.155490-1-pmalani@chromium.org> <20200407010940.155490-4-pmalani@chromium.org> <6ad18c9b-6c51-e08a-fb45-d97c9722a693@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6ad18c9b-6c51-e08a-fb45-d97c9722a693@collabora.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Enric, Thanks as always. Response inline: On Thu, Apr 09, 2020 at 11:40:39PM +0200, Enric Balletbo i Serra wrote: > 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. > Got it. I will use a "ret" variable. > > > + } > > + > > + 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) > >